static blob_list_ty * ifndef(blob_list_ty *blp, string_list_ty *ref) { blob_ty *arg; blob_list_ty *result; blob_ty *bp; arg = blp->list[0]; result = ifdef(blp, ref); bp = blob_alloc(str_from_c("[not"), arg->file_name, arg->line_number); blob_list_prepend(result, bp); bp = blob_alloc(str_from_c("]"), arg->file_name, arg->line_number); blob_list_append(result, bp); return result; }
void testmain(void) { print("macros"); special(); include(); predefined(); simple(); loop(); undef(); cond_incl(); const_expr(); defined(); ifdef(); funclike(); empty(); noarg(); line(); null(); counter(); gnuext(); }
yylex(void) { register int c; tbl *tp; begin: while ((c = input()) == ' ' || c == '\n' || c == '\t') ; yylval = c; switch (c) { case EOF: ERROR "unexpected end of input inside equation" WARNING; return(EOF); case '~': return(SPACE); case '^': return(THIN); /* case '\t': return(TAB); */ case '{': return('{'); case '}': return('}'); case '"': for (sp = 0; (c=input())!='"' && c != '\n'; ) { if (c == '\\') if ((c = input()) != '"') token[sp++] = '\\'; token[sp++] = c; if (sp >= SSIZE) ERROR "quoted string %.20s... too long", token FATAL; } token[sp] = '\0'; yylval = (int) &token[0]; if (c == '\n') ERROR "missing \" in %.20s", token WARNING; return(QTEXT); } if (!display && c == righteq) return(EOF); unput(c); getstr(token, SSIZE); dprintf(".\tlex token = |%s|\n", token); if ((tp = lookup(deftbl, token)) != NULL) { /* defined term */ c = input(); unput(c); if (c == '(') /* macro with args */ dodef(tp); else { /* no args */ unput(' '); pbstr(tp->cval); dprintf(".\tfound %s|=%s|\n", token, tp->cval); } goto begin; } if ((tp = lookup(keytbl, token)) == NULL) /* not a keyword */ return CONTIG; switch (tp->ival) { /* some kind of keyword */ case DEFINE: case TDEFINE: case NDEFINE: define(tp->ival); break; case IFDEF: ifdef(); break; case DELIM: delim(); break; case GSIZE: globsize(); break; case GFONT: globfont(); break; case INCLUDE: include(); break; case SPACE: space(); break; case DOTEQ: /* .EQ inside equation -- should warn if at bottom level */ break; case DOTEN: if (curfile == infile) return EOF; /* else ignore nested .EN */ break; default: return tp->ival; } goto begin; }
static void handle_ifnd(char *s) { ifdef(s,0); }
static void handle_ifd(char *s) { ifdef(s,1); }
static int getLine( char line[] ) /* * getLine obtains next line and decides whether it passes the * symbols tests. */ { char command[6]; char *statement; int m; int nc; int not; do { char head[4]; not = 0; nc = readLine( line ); if (nc < 0) break; strncpy( head, line, 3 ); head[3] = 0; if (strstrX( head, "#!" ) != NULL) { statement = strstrX( line, "#!" ) + 2; m = 0; while (*statement && !isspace(*statement) && m < 5) { command[m++] = toupper(*statement++); } command[m] = 0; if (!strcmp( command, "IF" )) { int r = ifdef( statement ); if (if_curl > MAXNEST) { fprintf( stderr, "Xfile -- exceeded nesting level at line #%d\n", lineno ); status = EXIT_FAILURE; } else { if_curl += 1; if_mask |= (1 << if_curl); if (r) { if_code |= (1 << if_curl); } } not = 1; } else if (!strcmp( command, "ELIF" )) { int r = ifdef( statement ); if (!if_curl) { fprintf( stderr, "Xfile -- IF statement missing at LINE #%d\n", lineno ); status = EXIT_FAILURE; } else { if (if_code & (1 << if_curl)) { if_done |= (1 << if_curl); if_code -= (1 << if_curl); } if (!(if_done & (1 << if_curl))) { if (r) if_code |= (1 << if_curl); } } not = 1; } else if (!strcmp( command, "ELSE" )) { if (!if_curl) { fprintf( stderr, "Xfile -- IF statement missing at LINE #%d\n", lineno ); status = EXIT_FAILURE; } else { if (if_else & (1 << if_curl)) { fprintf( stderr, "Xfile -- ELSE misplaced at line #%d\n", lineno ); status = EXIT_FAILURE; break; } else { if_else |= (1 << if_curl); } if (if_code & (1 << if_curl)) { if_done |= (1 << if_curl); if_code -= (1 << if_curl); } if (!(if_done & (1 << if_curl))) { if_code |= (1 << if_curl); } } not = 1; } else if (!strcmp( command, "ENDIF" )) { if (!if_curl) { fprintf( stderr, "Xfile -- IF statement missing at LINE #%d\n", lineno ); status = EXIT_FAILURE; } else { if (if_code & (1 << if_curl)) { if_done |= (1 << if_curl); if_code -= (1 << if_curl); } if_else = (if_else | (1 << if_curl)) - (1 << if_curl); if_done = (if_done | (1 << if_curl)) - (1 << if_curl); if_mask -= 1 << if_curl; if_curl -= 1; } not = 1; #if 0 /* * Sep 16, 1991: KGB, skip unknown directives. */ } else { fprintf( stderr, "Xfile -- unknown statement on line #%d\n", lineno ); status = EXIT_FAILURE; #endif } } if (status == EXIT_FAILURE) break; } while (not || (if_curl && if_code != if_mask)); return( nc ); }