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); }
int eval_expr (int Sharp, int Complain) { char c; char d; int rv; sharp = Sharp; complain = Complain; expr = read_expr_(); if (sharp) { c = getnonhspace(); d = '\n'; } else { c = getnonspace(); d = ')'; } if (c != d) { if (complain) { err_head(); fprintf(stderr, "expression syntax error -- junk after expression\n"); } while (Get() != d) ; } #ifdef DEBUG_EXPR if (debugging) { outputc('<'); dump_expr(expr); outputc('='); rv = exec_free(expr); outputd(rv); outputc('>'); } else { rv = exec_free(expr); } return (rv); #else return (exec_free(expr)); #endif }
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(); } }
EORB_CPP_node *read_expr_p (void) { char c; EORB_CPP_node *rv; sharp = 0; complain = 1; c = getnonspace(); if (c != '(') { Push(c); return (0); } rv = read_expr_(); c = getnonspace(); if (c != ')') { err_head(); fprintf(stderr, "junk after expression\n"); } return (rv); }
EORB_CPP_node *read_expr_ (void) { EORB_CPP_node *l; EORB_CPP_node *r; char c; #ifdef DEBUG_EXPR if (debugging) { outputs("~E"); } #endif l = read_expr_0(); while (1) { c = getnhsexpand(); switch (c) { case '\n': case ')': Push(c); return (l); break; case ',': r = read_expr_0(); l = newnode(l, c, r); break; default: err_head(); fprintf(stderr, "expression syntax error -- bad operator `%c'\n", c); return (l); break; } } }
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 }
extern void do_else (int sharp) { #ifdef DEBUG_IF if (debugging) { outputc('<'); outputc(sharp ? '#' : '@'); outputs("else: "); // fflush(outfile); } #endif if (n_skipped_ifs == 0) { if (ifstack) { #ifdef DEBUG_IF if (debugging) { outputs("top "); output_ifstate(ifstack->condstate); // fflush(outfile); } #endif switch (ifstack->condstate) { case IFSTATE_TRUE: ifstack->condstate = IFSTATE_STAYFALSE; break; case IFSTATE_FALSE: ifstack->condstate = IFSTATE_TRUE; break; } #ifdef DEBUG_IF if (debugging) { outputs(" now "); output_ifstate(ifstack->condstate); outputc('>'); // fflush(outfile); } #endif } else { #ifdef DEBUG_IF if (debugging) { outputs(" no if>"); // fflush(outfile); } #endif err_head(); fprintf(stderr, "if-less else\n"); } } else { #ifdef DEBUG_IF if (debugging) { outputs("in-false, forgetting>"); // fflush(outfile); } #endif } if (sharp) { flush_sharp_line(); } }
static void read_actuals (DEF * d) { int n; int i; int pc; char c; char last; char quote; int backslash; int comment; char *acc; n = d->nargs; actuals = (char **) os_malloc(n * sizeof(char *)); check_os_malloc(actuals); actlens = (int *) os_malloc(n * sizeof(int)); check_os_malloc(actlens); c = getnonspace(); if (c != '(') { err_head(); if (n == 0) { fprintf(stderr, "missing () on %s\n", d->name); } else { fprintf(stderr, "missing argument%s to %s\n", (n == 1) ? "" : "s", d->name); } for (i = 0;i < n;i++) { actuals[i] = copyofstr(""); check_os_malloc(actuals[i]); actlens[i] = 0; } Push(c); return ; } if (n == 0) { c = getnonspace(); if (c != ')') { err_head(); fprintf(stderr, "unwanted argument to %s\n", d->name); Push(c); } return ; } i = 0; while (1) { pc = 0; quote = 0; backslash = 0; comment = 0; c = 0; acc = init_accum(); while (1) { last = c; c = Get(); accum_char(acc, c); if (comment) { if ((last == '*') && (c == '/')) { comment = 0; } } else { if (backslash) { backslash = 0; } else if (quote && (c == quote)) { quote = 0; } else if (c == '\\') { backslash = 1; } else if (quote) {} else if ((last == '/') && (c == '*')) { comment = 1; } else if ((c == '\'') || (c == '"')) { quote = c; } else if (c == '(') { pc ++; } else if (c == ')') { if (pc > 0) { pc --; } else { accum_regret(acc); break; } } else if ((c == ',') && (pc == 0)) { accum_regret(acc); break; } } } if (i < n) { actuals[i] = accum_result(acc); actlens[i] = strlen(actuals[i]); i ++; } else if (i == n) { err_head(); fprintf(stderr, "too many arguments to %s\n", d->name); i ++; } if (c == ')') { break; } } if (i < n) { err_head(); fprintf(stderr, "too few arguments to %s\n", d->name); for (;i < n;i++) { actuals[i] = copyofstr(""); check_os_malloc(actuals[i]); actlens[i] = 0; } } }
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); }
static EORB_CPP_node *read_expr_11 (void) { char c; #ifdef DEBUG_EXPR if (debugging) { outputs("~E11:"); } #endif while (1) { c = getnhsexpand(); if (c == '(') { EORB_CPP_node *n; #ifdef DEBUG_EXPR if (debugging) { outputs("()"); } #endif n = read_expr_(); c = getnhsexpand(); if (c != ')') { err_head(); fprintf(stderr, "expression syntax error -- missing ) supplied\n"); Push(c); } #ifdef DEBUG_EXPR if (debugging) { outputs("~"); } #endif return (n); } else if (isdigit((int) c)) { int base; static char digits[] = "0123456789abcdefABCDEF"; static char values[] = "\0\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17\12\13\14\15\16\17"; char *d; int v; #ifdef DEBUG_EXPR if (debugging) { outputs("N"); } #endif base = 10; if (c == '0') { base = 8; c = Get(); if ((c == 'x') || (c == 'X')) { base = 16; c = Get(); } } v = 0; while (1) { d = strchr(digits, c); if (d == 0) { Push(c); #ifdef DEBUG_EXPR if (debugging) { outputd(v); outputs("~"); } #endif return (newleaf(v)); } else if (values[d -digits] >= base) { err_head(); fprintf(stderr, "warning: illegal %sdigit `%c'\n", (base == 16) ? "hex " : (base == 8) ? "octal " : "", c); } v = (v * base) + values[d - digits]; c = Get(); } } else if (c == '\'') { int i; int j; int n; i = 0; n = 0; while (1) { j = get_quote_char(); if (j < 0) { break; } i = (i << 8) | j; n ++; } if (n > 4) { err_head(); fprintf(stderr, "warning: too many characters in character constant\n"); } return (newleaf(i)); } else if ((c == '\n') && !sharp) {} else { char *id; if (complain) { err_head(); fprintf(stderr, "expression syntax error -- number expected\n"); } if (isbsymchar(c)) { Push(c); id = read_ident(); } else { id = 0; } #ifdef DEBUG_EXPR if (debugging) { outputs("0("); outputc(c); outputs(":"); outputs(id ? id : "(none)"); outputs(")~"); } #endif if (id) { os_free(id); } return (newleaf(0)); } } }
static int get_quote_char (void) { char c; char d; c = Get(); if (c == '\'') { return ( -1); } if (c == '\n') { err_head(); fprintf(stderr, "newline in character constant\n"); return ( -1); } if (c != '\\') { return (0xff&(int)c); } c = Get(); if ((c >= '0') && (c <= '7')) { d = c - '0'; c = Get(); if ((c >= '0') && (c <= '7')) { d = (d << 3) + c - '0'; c = Get(); if ((c >= '0') && (c <= '7')) { d = (d << 3) + c - '0'; } else { Push(c); } } else { Push(c); } return (0xff&(int)d); } switch (c) { case 'n': return ('\n'); break; case 'r': return ('\r'); break; case 'e': return ('\033'); break; case 'f': return ('\f'); break; case 't': return ('\t'); break; case 'b': return ('\b'); break; case 'v': return ('\v'); break; default: return (0xff&(int)c); break; } }