1 #ifndef lint 2 static char sccsid[] = "@(#)cfgets.c 5.2 (Berkeley) 01/22/85"; 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 15 char * 16 cfgets(buf, siz, fil) 17 register char *buf; 18 int siz; 19 FILE *fil; 20 { 21 register char *s; 22 register i, c, len; 23 char *fgets(); 24 25 for (i=0,s=buf; i = (fgets(s, siz-i, fil) != NULL); i = s - buf) { 26 27 /* get last character of line */ 28 c = s[len = (strlen(s) - 1)]; 29 30 /* skip comments; make sure end of comment line seen */ 31 if (*s == COMMENT) { 32 while (c != EOLN && c != EOF) 33 c = getc(fil); 34 *s = EOS; 35 } 36 37 /* skip blank lines */ 38 else if (*s != EOLN) { 39 s += len; 40 41 /* continue lines ending with CONTINUE */ 42 if (c != EOLN || *--s != CONTINUE) 43 break; 44 } 45 } 46 47 return i ? buf : NULL; 48 } 49 50 #ifdef TEST 51 main() 52 { 53 char buf[512]; 54 55 while (cfgets(buf, sizeof buf, stdin)) 56 fputs(buf, stdout); 57 } 58 #endif TEST 59