added depend label
[unix-history] / usr / src / usr.bin / uucp / libuu / cfgets.c
CommitLineData
1fe1b36f 1#ifndef lint
b2c542c6 2static 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 17char *
88db71e9 18cfgets(buf, siz, fil)
1fe1b36f
SL
19register char *buf;
20int siz;
21FILE *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
53main()
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