/* Last edited on 2023-02-12 06:17:21 by stolfi */ bool_t cfp_skip_comment(FILE *rd); /* Skips blanks until a newline ('\012') or a '#' character. If the latter, skips any additional characters until the newline. Consumes the newline. Returns TRUE normally, FALSE if syntax error. */ void cfp_skip_comment_lines(FILE *rd) { while(1) { fget_skip_spaces(rd); if (fget_test_char(rd, '#')) { ungetc('#', rd); if (! cfp_skip_comment(rd)) { cfp_file_error(NULL, NORULE, "bad comment"); } fget_eol(rd); } else if (fget_test_char(rd, '\012')) { /* OK, continue */ } else { return; } } } bool_t cfp_skip_comment(FILE *rd) { int c; do { c = fgetc(rd); } while ((c=='\000') || (c==' ') || (c=='\011')); if (c == EOF) { return FALSE; } if (c == '#') { do { c = fgetc(rd); } while ((c != '\012') && (c != EOF)); if (c == EOF) { return FALSE; } } ungetc(c, rd); return (c == '\012'); }