1: #ifndef lint
   2: static char sccsid[] = "@(#)cfgets.c	5.1 (Berkeley) 7/2/83";
   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 = fgetc (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

Defined functions

main defined in line 51; never used

Defined variables

sccsid defined in line 2; never used

Defined macros

COMMENT defined in line 10; used 1 times
  • in line 31
CONTINUE defined in line 11; used 1 times
  • in line 42
EOLN defined in line 12; used 3 times
EOS defined in line 13; used 1 times
  • in line 34
Last modified: 1983-07-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 651
Valid CSS Valid XHTML 1.0 Strict