1 /* Correctly reads an arbitrarily size string.
3 Copyright (C) 1989 Free Software Foundation, Inc.
4 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
6 This file is part of GNU GPERF.
8 GNU GPERF is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
13 GNU GPERF is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU GPERF; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 /* Size of each chunk. */
26 #define CHUNK_SIZE BUFSIZ
28 /* Recursively fills up the buffer. */
34 char *buffered_malloc ();
36 register char *bufptr = buf;
40 while ((c = getchar ()) != EOF && c != '\n') /* fill the current buffer */
43 if (bufptr - buf >= CHUNK_SIZE) /* prepend remainder to ptr buffer */
45 if (ptr = readln_aux (chunks + 1))
47 for (; bufptr != buf; *--ptr = *--bufptr);
53 if (c == EOF && bufptr == buf)
56 c = (chunks * CHUNK_SIZE + bufptr - buf) + 1;
58 if (ptr = buffered_malloc (c))
61 for (*(ptr += (c - 1)) = '\0'; bufptr != buf; *--ptr = *--bufptr)
70 /* Returns the ``next'' line, ignoring comments beginning with '#'. */
75 if ((c = getchar ()) == '#')
77 while ((c = getchar ()) != '\n' && c != EOF)
80 return c != EOF ? read_line () : NULL;
85 return readln_aux (0);