Since now ice100.c also uses getline, we'd better put getline in a
separate file. I found UrJTAG previous had getline.c and getdelim.c in
src/lib, but they were removed about 1 year ago. So I bring them back
with this patch. If no one objects, I will commit it in 24 hours.
Regards,
Jie
* src/global/parse.c (getline): Remove.
* src/cmd/cmd_bfin.c (cmd_bfin_run): Update comment.
* src/lib/getline.c: New file.
* src/lib/getdelim.c: New file.
* src/lib/Makefile.am (libjtaglib_la_SOURCES): Add getdelim.c and
getline.c.
* sysdep.h (getline): Declare.
* configure.ac: Check getdelim.
* po/POTFILES.in: Add src/lib/getdelim.c and src/lib/getline.c.
Index: src/global/parse.c
===================================================================
--- src/global/parse.c (revision 1970)
+++ src/global/parse.c (working copy)
@@ -171,47 +171,6 @@ urj_parse_line (urj_chain_t *chain, cons
return r;
}
-#ifndef HAVE_GETLINE
-#define MAXINPUTLINE 300 /* Maximum input line length */
-static ssize_t getline(char **line, size_t *len, FILE *f)
-{
- static int lnr;
- char *p;
-
- ++lnr;
- if (!*line)
- {
- *len = MAXINPUTLINE + 1;
- *line = malloc (*len);
- }
-
- if (fgets (*line, *len, f) == NULL)
- return -1;
-
- /* Clip any comments */
- p = strchr (*line, '#');
- if (p)
- {
- p[0] = '\n';
- p[1] = '\0';
- }
-
- /* Make sure the line wasn't clipped */
- p = strchr (*line, '\n');
- if (!p)
- {
- urj_warning ("line %d exceeds %zd characters, clipped\n", lnr, *len);
- while (1) {
- char c = fgetc (f);
- if (c == '\n' || c == EOF)
- break;
- }
- }
-
- return p - *line + 1;
-}
-#endif
-
int
urj_parse_stream (urj_chain_t *chain, FILE *f)
{
Index: src/cmd/cmd_bfin.c
===================================================================
--- src/cmd/cmd_bfin.c (revision 1970)
+++ src/cmd/cmd_bfin.c (working copy)
@@ -265,7 +265,7 @@ cmd_bfin_run (urj_chain_t *chain, char *
size_t t;
FILE *fp;
- /* 1024 should be plenty; MAXINPUTLINE is 100 in parse.c */
+ /* 1024 should be plenty. */
char insns_string[1024];
char *p = insns_string;
Index: src/lib/getline.c
===================================================================
--- src/lib/getline.c (revision 0)
+++ src/lib/getline.c (revision 0)
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003 ETC s.r.o.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by Marcel Telka <[email protected]>, 2003.
+ *
+ */
+
+#include <sysdep.h>
+
+#include <stdio.h>
+#include <unistd.h>
+
+#ifndef HAVE_GETLINE
+
+#ifndef HAVE_GETDELIM
+ssize_t getdelim (char **lineptr, size_t *n, int delimiter,
+ FILE *stream);
+#endif /* HAVE_GETDELIM */
+
+ssize_t
+getline (char **lineptr, size_t *n, FILE *stream)
+{
+ return getdelim (lineptr, n, '\n', stream);
+}
+
+#endif /* HAVE_GETLINE */
Index: src/lib/Makefile.am
===================================================================
--- src/lib/Makefile.am (revision 1970)
+++ src/lib/Makefile.am (working copy)
@@ -38,6 +38,8 @@ endif
libjtaglib_la_SOURCES = \
fclock.c \
hex.c \
+ getdelim.c \
+ getline.c \
usleep.c \
$(libiberty_sources)
Index: src/lib/getdelim.c
===================================================================
--- src/lib/getdelim.c (revision 0)
+++ src/lib/getdelim.c (revision 0)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003 ETC s.r.o.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by Marcel Telka <[email protected]>, 2003.
+ *
+ */
+
+#include <sysdep.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifndef HAVE_GETDELIM
+
+#define GETDELIM_BUFFER 128
+
+ssize_t
+getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream)
+{
+ char *p;
+ int c;
+ size_t len = 0;
+
+ if (!lineptr || !n || (!*lineptr && *n))
+ return -1;
+
+ /* allocate initial buffer */
+ if (!*lineptr || !*n)
+ {
+ char *np;
+ np = realloc (*lineptr, GETDELIM_BUFFER);
+ if (!np)
+ return -1;
+ *n = GETDELIM_BUFFER;
+ *lineptr = np;
+ }
+
+ p = *lineptr;
+
+ /* read characters from stream */
+ while ((c = fgetc (stream)) != EOF)
+ {
+ if (len >= *n)
+ {
+ char *np = realloc (*lineptr, *n * 2);
+ if (!np)
+ return -1;
+ p = np + (p - *lineptr);
+ *lineptr = np;
+ *n *= 2;
+ }
+ *p++ = (char) c;
+ len++;
+ if (delimiter == c)
+ break;
+ }
+
+ /* end of file without any bytes read */
+ if ((c == EOF) && (len == 0))
+ return -1;
+
+ /* trailing '\0' */
+ if (len >= *n)
+ {
+ char *np = realloc (*lineptr, *n + 1);
+ if (!np)
+ return -1;
+ p = np + (p - *lineptr);
+ *lineptr = np;
+ *n += 1;
+ }
+ *p = '\0';
+
+ return len;
+}
+
+#endif /* HAVE_GETDELIM */
Index: sysdep.h
===================================================================
--- sysdep.h (revision 1970)
+++ sysdep.h (working copy)
@@ -79,6 +79,12 @@ struct timespec { unsigned long tv_sec,
#define nanosleep(req, rem) usleep((req)->tv_sec * 1000 * 1000 + (req)->tv_nsec / 1000)
#endif
+#ifndef HAVE_GETLINE
+#include <unistd.h>
+#include <stdio.h>
+extern ssize_t getline(char **line, size_t *len, FILE *f);
+#endif
+
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
#endif /* SYSDEP_H */
Index: configure.ac
===================================================================
--- configure.ac (revision 1970)
+++ configure.ac (working copy)
@@ -123,6 +123,7 @@ fi
AC_CHECK_FUNCS(m4_flatten([
_sleep
+ getdelim
geteuid
getline
getuid
Index: po/POTFILES.in
===================================================================
--- po/POTFILES.in (revision 1970)
+++ po/POTFILES.in (working copy)
@@ -96,6 +96,8 @@ src/jim/intel_28f800b3.c
src/jim/some_cpu.c
src/jim/jim_tap.c
src/lib/fclock.c
+src/lib/getdelim.c
+src/lib/getline.c
src/part/bsbit.c
src/part/data_register.c
src/part/instruction.c
------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide. Store less, Store more with what you own, Move data to
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development