1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 /* Reads a DELIMITER-separated field of any length from file STREAM.
26 *LINEPTR is a malloc'd string of size N; if *LINEPTR is NULL, it is
27 allocated. *LINEPTR is allocated/enlarged as necessary. Returns
28 -1 if at eof when entered; otherwise eof causes return of string
29 without a terminating DELIMITER. Normally DELIMITER is the last
30 character in *LINEPTR on return (besides the null character which
31 is always present). Returns number of characters read, including
32 terminating field delimiter if present. */
34 getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream)
36 /* Number of characters stored in *lineptr so far. */
39 /* Last character read. */
42 if (*lineptr == NULL || *n < 2)
44 *lineptr = xrealloc (*lineptr, 128);
58 *lineptr = xrealloc (*lineptr, *n);
60 (*lineptr)[len++] = c;
69 (*lineptr)[len] = '\0';