Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / sbr / RCS / vfgets.c,v
1 head    1.3;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.3
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.2;
12
13 1.2
14 date    92.01.31.21.58.55;      author jromine; state Exp;
15 branches;
16 next    1.1;
17
18 1.1
19 date    92.01.31.21.58.45;      author jromine; state Exp;
20 branches;
21 next    ;
22
23
24 desc
25 @@
26
27
28 1.3
29 log
30 @endif sugar
31 @
32 text
33 @/* vfgets.c - virtual fgets */
34 #ifndef       lint
35 static char ident[] = "@@(#)$Id: vfgets.c,v 1.2 1992/01/31 21:58:55 jromine Exp jromine $";
36 #endif  /*        lint */
37
38 #include "../h/mh.h"
39 #include <stdio.h>
40
41
42 #define QUOTE   '\\'
43
44
45 int     vfgets (in, bp)
46 register FILE *in;
47 register char  **bp;
48 {
49     register int    toggle;
50     register char  *cp,
51                    *dp,
52                    *ep,
53                    *fp;
54     static int  len = 0;
55     static char *pp = NULL;
56
57     if (pp == NULL)
58         if ((pp = malloc ((unsigned) (len = BUFSIZ))) == NULL)
59             adios (NULLCP, "unable to allocate string storage");
60
61     for (ep = (cp = pp) + len - 1;;) {
62         if (fgets (cp, ep - cp + 1, in) == NULL) {
63             if (cp != pp) {
64                 *bp = pp;
65                 return OK;
66             }
67             return (ferror (in) && !feof (in) ? NOTOK : DONE);
68         }
69
70         if ((dp = cp + strlen (cp) - 2) < cp || *dp != QUOTE) {
71 wrong_guess: ;
72             if (cp > ++dp)
73                 adios (NULLCP, "vfgets() botch -- you lose big");
74             if (*dp == '\n') {
75                 *bp = pp;
76                 return OK;
77             }
78             else
79                 cp = ++dp;
80         }
81         else {
82             for (fp = dp - 1, toggle = 0; fp >= cp; fp--)
83                 if (*fp != QUOTE)
84                     break;
85                 else
86                     toggle = !toggle;
87             if (toggle)
88                 goto wrong_guess;
89             if (*++dp == '\n')
90                 *--dp = 0, cp = dp;
91             else
92                 cp = ++dp;
93         }
94
95         if (cp >= ep) {
96             register int curlen = cp - pp;
97
98             if ((dp = realloc (pp, (unsigned) (len += BUFSIZ))) == NULL)
99                 adios (NULLCP, "unable to allocate string storage");
100             else
101                 cp = dp + curlen, ep = (pp = dp) + len - 1;
102         }
103     }
104 }
105 @
106
107
108 1.2
109 log
110 @kerberos
111 @
112 text
113 @d3 2
114 a4 2
115 static char ident[] = "@@(#)$Id$";
116 #endif        lint
117 @
118
119
120 1.1
121 log
122 @Initial revision
123 @
124 text
125 @d2 3
126 d58 1
127 a58 1
128                 *--dp = NULL, cp = dp;
129 @