Commit | Line | Data |
---|---|---|
1fe1b36f | 1 | #ifndef lint |
b2c542c6 | 2 | static char sccsid[] = "@(#)cfgets.c 5.3 (Berkeley) %G%"; |
1fe1b36f SL |
3 | #endif |
4 | ||
5 | /* | |
6 | * get nonblank, non-comment, (possibly continued) line. Alan S. Watt | |
7 | */ | |
8 | ||
9 | #include <stdio.h> | |
10 | #define COMMENT '#' | |
11 | #define CONTINUE '\\' | |
12 | #define EOLN '\n' | |
13 | #define EOS '\0' | |
14 | ||
b2c542c6 JB |
15 | /*LINTLIBRARY*/ |
16 | ||
1fe1b36f | 17 | char * |
88db71e9 | 18 | cfgets(buf, siz, fil) |
1fe1b36f SL |
19 | register char *buf; |
20 | int siz; | |
21 | FILE *fil; | |
22 | { | |
23 | register char *s; | |
24 | register i, c, len; | |
25 | char *fgets(); | |
26 | ||
88db71e9 | 27 | for (i=0,s=buf; i = (fgets(s, siz-i, fil) != NULL); i = s - buf) { |
1fe1b36f SL |
28 | |
29 | /* get last character of line */ | |
88db71e9 | 30 | c = s[len = (strlen(s) - 1)]; |
1fe1b36f SL |
31 | |
32 | /* skip comments; make sure end of comment line seen */ | |
33 | if (*s == COMMENT) { | |
34 | while (c != EOLN && c != EOF) | |
88db71e9 | 35 | c = getc(fil); |
1fe1b36f SL |
36 | *s = EOS; |
37 | } | |
38 | ||
39 | /* skip blank lines */ | |
40 | else if (*s != EOLN) { | |
41 | s += len; | |
42 | ||
43 | /* continue lines ending with CONTINUE */ | |
44 | if (c != EOLN || *--s != CONTINUE) | |
45 | break; | |
46 | } | |
47 | } | |
48 | ||
88db71e9 | 49 | return i ? buf : NULL; |
1fe1b36f SL |
50 | } |
51 | ||
52 | #ifdef TEST | |
53 | main() | |
54 | { | |
55 | char buf[512]; | |
56 | ||
88db71e9 RC |
57 | while (cfgets(buf, sizeof buf, stdin)) |
58 | fputs(buf, stdout); | |
1fe1b36f SL |
59 | } |
60 | #endif TEST |