extern void do_endwhile(void) { if (in_false_if()) { do_endif(0); input_unmark(); #ifdef DEBUG_WHILE if (debugging) { outputs("//endwhile:"); outputd(curline()); outputs(","); outputs(curfile()); outputs("\\\\"); } #endif out_at(curline(), curfile()); } else { do_endif(0); input_recover(); input_mark(); do_if(0); } }
extern void do_pragma (void) { char c; if (in_false_if()) { while ((c = Get()) != '\n') ; } else { outputc('#'); outputc('p'); outputc('r'); outputc('a'); outputc('g'); outputc('m'); outputc('a'); outputc(' '); c = Get(); while ((c != '\n') && (c != -1)) { outputc(c); c = Get(); } } }
extern void do_set (void) { char *mac; char c; char temp[64]; mac = read_ident(); if (! mac) { err_head(); fprintf(stderr, "@set: missing/illegal macro name\n"); return ; } if (! in_false_if()) { char *cp; c = getnonspace(); if (c != '(') { err_head(); fprintf(stderr, "@set must have ()s\n"); Push(c); return ; } os_sprintf(temp, "%d", eval_expr(0, 1)); undef(mac); cp = copyofstr(temp); check_os_malloc(cp); define(mac, -1, (unsigned char *) cp, DEF_DEFINE); } os_free(mac); }
extern void do_undef (int sharp) { char *mac; if (! in_false_if()) { mac = read_ident(); if (! mac) { err_head(); fprintf(stderr, "missing/illegal macro name\n"); } else { undef (mac); } } if (sharp) { flush_sharp_line(); } }
void do_if (int sharp) { char c; char d; #ifdef DEBUG_IF if (debugging) { outputc('<'); outputc(sharp ? '#' : '@'); outputs("if: "); // fflush(outfile); } #endif if (in_false_if()) { n_skipped_ifs ++; #ifdef DEBUG_IF if (debugging) { outputs("in-false, skipped>"); // fflush(outfile); } #endif if (sharp) { d = '\0'; do { c = d; d = Get(); } while ((c == '\\') || (d != '\n')); } return ; } if (! sharp) { c = getnonspace(); if (c != '(') { err_head(); fprintf(stderr, "@if must have ()s\n"); Push(c); iffalse(); #ifdef DEBUG_IF if (debugging) { outputc('>'); // fflush(outfile); } #endif return ; } } if (eval_expr(sharp, 0)) { iftrue(); } else { iffalse(); } #ifdef DEBUG_IF if (debugging) { outputc('>'); // fflush(outfile); } #endif }
void do_ifndef (int sharp) { char *w; #ifdef DEBUG_IF if (debugging) { outputc('<'); outputc(sharp ? '#' : '@'); outputs("ifndef: "); // fflush(outfile); } #endif if (in_false_if()) { n_skipped_ifs ++; #ifdef DEBUG_IF if (debugging) { outputs("in-false, skipped>"); // fflush(outfile); } #endif } else { w = read_ident(); if (! w) { #ifdef DEBUG_IF if (debugging) { outputs("no ident "); // fflush(outfile); } #endif iftrue(); } else { #ifdef DEBUG_IF if (debugging) { outputs(w); outputc(' '); // fflush(outfile); } #endif if (find_def(w)) { iffalse(); } else { iftrue(); } os_free(w); } #ifdef DEBUG_IF if (debugging) { outputc('>'); // fflush(outfile); } #endif } if (sharp) { flush_sharp_line(); } }
int preprocess_getc(void) { int result = 0; int backslash = 0; do { int c; int haddigit; result = read_char(); if (result != 0) { break; } c = Get(); if (c == -1) { break; } if (backslash) { maybe_print(c); backslash = 0; continue; } if (!incldep && (isdigit((int) c) || (c == '.'))) { haddigit = 0; while (isdigit((int) c) || (c == '.')) { haddigit |= isdigit((int) c); maybe_print(c); c = Get(); if (c == -1) { return 0; } } if (haddigit && ((c == 'e') || (c == 'E'))) { maybe_print(c); c = Get(); if (c == -1) { return 0; } while (isdigit((int) c)) { maybe_print(c); c = Get(); if (c == -1) { return 0; } } } Push(c); continue; } if (quote) { if (c == '\\') { maybe_print(c); backslash = 1; continue; } else if ((c == quote) || (c == '\n')) { maybe_print(c); quote = 0; continue; } else { maybe_print(c); continue; } } if (c == '\\') /* this weirdness is Reiser semantics.... */ { backslash = 1; maybe_print(c); continue; } if ((c == '\'') || (c == '"')) { quote = c; maybe_print(c); } else if (linefirst && (c == '#')) { do_sharp(); } else if (do_at_ctrls && (c == '@')) { do_at(); } else if (! incldep) { if (isbsymchar(c) && !in_false_if()) { char *cp; DEF *d; cp = init_accum(); while (issymchar(c)) { accum_char(cp, c); c = Get(); if (c == -1) { return 0; } } Push(c); cp = accum_result(cp); #ifdef DEBUG_MAIN if (debugging) { outputs("<word:"); outputs(cp); outputs(">"); } #endif d = find_def(cp); if (d) { expand_def(d); } else { for (;*cp;cp++) { maybe_print(*cp); } } } else if (c == '/') { int d; d = Get(); if (d == -1) { return 0; } if (d == '*') { d = '\0'; if (keep_comments) { maybe_print('/'); maybe_print('*'); } do { c = d; d = Get(); if (d == -1) { return 0; } if ((d == '\n') || keep_comments) { maybe_print(d); } } while ((c != '*') || (d != '/')); } else if (d == '/') { if (keep_comments) { maybe_print('/'); maybe_print('/'); } do { c = Get(); if (c == -1) { return 0; } if ((c == '\n') || keep_comments) { maybe_print(c); } } while (c != '\n'); } else { Push(d); maybe_print(c); } } else { maybe_print(c); } } } while (result == 0); return result; }
extern void do_sharp (void) { char *w; char c; w = read_ctrl(); if (strcmp(w, "ifdef") == 0) { do_ifdef(1); } else if (strcmp(w, "ifndef") == 0) { do_ifndef(1); } else if (strcmp(w, "if") == 0) { do_if(1); } else if (strcmp(w, "else") == 0) { do_else(1); } else if (strcmp(w, "elif") == 0) { do_elif(1); } else if (strcmp(w, "endif") == 0) { do_endif(1); } else if (strcmp(w, "include") == 0) { do_include(1); } else if (strcmp(w, "define") == 0) { do_define(1, 0); } else if (strcmp(w, "undef") == 0) { do_undef(1); } else if (strcmp(w, "line") == 0) { do_line(); } else if (strcmp(w, "pragma") == 0) { do_pragma(); } else if (strcmp(w, "") == 0) {} else { int isnull; isnull = 0; if (strcmp(w, "") == 0) { c = Get(); if (c != '\n') { Push(c); } else { isnull = 1; } } if (!isnull && !in_false_if()) { err_head(); fprintf(stderr, "unknown control `%s'\n", w); flush_sharp_line(); } } maybe_print('\n'); os_free(w); }