Annotation of 43BSDTahoe/usr.bin/uucp/cfgets.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)cfgets.c   5.3 (Berkeley) 6/19/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: /*LINTLIBRARY*/
                     16: 
                     17: char *
                     18: cfgets(buf, siz, fil)
                     19: register char *buf;
                     20: int siz;
                     21: FILE *fil;
                     22: {
                     23:        register char *s;
                     24:        register i, c, len;
                     25:        char *fgets();
                     26: 
                     27:        for (i=0,s=buf; i = (fgets(s, siz-i, fil) != NULL); i = s - buf) {
                     28: 
                     29:                /* get last character of line */
                     30:                c = s[len = (strlen(s) - 1)];
                     31: 
                     32:                /* skip comments; make sure end of comment line seen */
                     33:                if (*s == COMMENT) {
                     34:                        while (c != EOLN && c != EOF)
                     35:                                c = getc(fil);
                     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:        
                     49:        return i ? buf : NULL;
                     50: }
                     51: 
                     52: #ifdef TEST
                     53: main()
                     54: {
                     55:        char buf[512];
                     56: 
                     57:        while (cfgets(buf, sizeof buf, stdin))
                     58:                fputs(buf, stdout);
                     59: }
                     60: #endif TEST

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.