]>
diplodocus.org Git - nmh/blob - sbr/vfgets.c
1 /* vfgets.c -- virtual fgets
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
15 vfgets (FILE *in
, char **bp
)
18 char *cp
, *dp
, *ep
, *fp
;
20 static char *pp
= NULL
;
23 pp
= mh_xmalloc ((size_t) (len
= BUFSIZ
));
25 for (ep
= (cp
= pp
) + len
- 1;;) {
26 if (fgets (cp
, ep
- cp
+ 1, in
) == NULL
) {
31 return (ferror (in
) && !feof (in
) ? -1 : 1);
34 if ((dp
= cp
+ strlen (cp
) - 2) < cp
|| *dp
!= QUOTE
) {
37 adios (NULL
, "vfgets() botch -- you lose big");
44 for (fp
= dp
- 1, toggle
= 0; fp
>= cp
; fp
--) {
63 dp
= mh_xrealloc (pp
, (size_t) (len
+= BUFSIZ
));
65 ep
= (pp
= dp
) + len
- 1;