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); }
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); }
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 }
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 }
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; } } }
static EORB_CPP_node *read_expr_10 (void) { char c; char *w; EORB_CPP_node *n; #ifdef DEBUG_EXPR if (debugging) { outputs("~E10:"); } #endif while (1) { c = getnhsexpand(); switch (c) { case '-': case '~': case '!': #ifdef DEBUG_EXPR if (debugging) { outputc(c); } #endif n = read_expr_10(); #ifdef DEBUG_EXPR if (debugging) { outputs("~"); } #endif return (newnode(0, c, n)); break; case 'd': Push(c); input_mark(); w = read_ident(); if (strcmp(w, "defined") == 0) { c = getnonspace(); if (c == '(') { char *id; id = read_ident(); if (id) { c = getnonspace(); if (c == ')') { input_unmark(); #ifdef DEBUG_EXPR if (debugging) { outputs("ifdef"); } #endif return (newname(id)); } } } else if (isbsymchar(c)) { char *id; Push(c); id = read_ident(); if (id) { input_unmark(); #ifdef DEBUG_EXPR if (debugging) { outputs("ifdef"); } #endif return (newname(id)); } } } input_recover(); n = read_expr_11(); #ifdef DEBUG_EXPR if (debugging) { outputs("~"); } #endif return (n); break; default: Push(c); n = read_expr_11(); #ifdef DEBUG_EXPR if (debugging) { outputs("~"); } #endif return (n); break; } } }