1*48652Sbostic /*- 2*48652Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*48652Sbostic * All rights reserved. 4*48652Sbostic * 5*48652Sbostic * %sccs.include.proprietary.c% 6*48652Sbostic */ 7*48652Sbostic 813637Ssam #ifndef lint 9*48652Sbostic static char sccsid[] = "@(#)cfgets.c 5.4 (Berkeley) 04/24/91"; 10*48652Sbostic #endif /* not lint */ 1113637Ssam 1213637Ssam /* 1313637Ssam * get nonblank, non-comment, (possibly continued) line. Alan S. Watt 1413637Ssam */ 1513637Ssam 1613637Ssam #include <stdio.h> 1713637Ssam #define COMMENT '#' 1813637Ssam #define CONTINUE '\\' 1913637Ssam #define EOLN '\n' 2013637Ssam #define EOS '\0' 2113637Ssam 2223587Sbloom /*LINTLIBRARY*/ 2323587Sbloom 2413637Ssam char * 2517767Sralph cfgets(buf, siz, fil) 2613637Ssam register char *buf; 2713637Ssam int siz; 2813637Ssam FILE *fil; 2913637Ssam { 3013637Ssam register char *s; 3113637Ssam register i, c, len; 3213637Ssam char *fgets(); 3313637Ssam 3417767Sralph for (i=0,s=buf; i = (fgets(s, siz-i, fil) != NULL); i = s - buf) { 3513637Ssam 3613637Ssam /* get last character of line */ 3717767Sralph c = s[len = (strlen(s) - 1)]; 3813637Ssam 3913637Ssam /* skip comments; make sure end of comment line seen */ 4013637Ssam if (*s == COMMENT) { 4113637Ssam while (c != EOLN && c != EOF) 4217767Sralph c = getc(fil); 4313637Ssam *s = EOS; 4413637Ssam } 4513637Ssam 4613637Ssam /* skip blank lines */ 4713637Ssam else if (*s != EOLN) { 4813637Ssam s += len; 4913637Ssam 5013637Ssam /* continue lines ending with CONTINUE */ 5113637Ssam if (c != EOLN || *--s != CONTINUE) 5213637Ssam break; 5313637Ssam } 5413637Ssam } 5513637Ssam 5617767Sralph return i ? buf : NULL; 5713637Ssam } 5813637Ssam 5913637Ssam #ifdef TEST 6013637Ssam main() 6113637Ssam { 6213637Ssam char buf[512]; 6313637Ssam 6417767Sralph while (cfgets(buf, sizeof buf, stdin)) 6517767Sralph fputs(buf, stdout); 6613637Ssam } 6713637Ssam #endif TEST 68