void eval_draw(void) { F = cadr(p1); T = caddr(p1); if (T == symbol(NIL)) { push(F); rewrite(); guess(); T = pop(); F = pop(); } push(get_binding(T)); push(get_arglist(T)); draw_main(); p2 = pop(); p1 = pop(); set_binding_and_arglist(T, p1, p2); // return value push(symbol(NIL)); }
void eval_product(void) { int i, j, k; // 1st arg (quoted) X = cadr(p1); if (!issymbol(X)) stop("product: 1st arg?"); // 2nd arg push(caddr(p1)); eval(); j = pop_integer(); if (j == (int) 0x80000000) stop("product: 2nd arg?"); // 3rd arg push(cadddr(p1)); eval(); k = pop_integer(); if (k == (int) 0x80000000) stop("product: 3rd arg?"); // 4th arg // fix p1 = cddddr(p1); p1 = car(p1); B = get_binding(X); A = get_arglist(X); push_integer(1); for (i = j; i <= k; i++) { push_integer(i); I = pop(); set_binding(X, I); push(p1); eval(); multiply(); } set_binding_and_arglist(X, B, A); }
/* EXPAND_HISTORY_MACROS -- Copy the input string to the output string, * replacing all occurrences of "^$" by the final argument the last command, * all occurrences of "^^" by the first argument of the last command, and * all occurrences of "^*" by the full argument list of the last command. * If the command block contains more than one line, we assume that the * argument list spans several lines. If this is not true, the expansion * will not be what the user wanted (but then they probably screwed up). * The function returns true if any macros were expanded. */ int expand_history_macros ( char *in_text, char *out_text ) { register char *ip, *op, *ap; char cmdblk[SZ_CMDBLK+1], *argp[100]; int nargs, nrep, argno, have_arg_strings=0; char *index(); /* Copy the command text. Fetch argument strings from history only * if a history macro is found. Otherwise the copy is very fast. */ for (ip=in_text, op=out_text; (*op = *ip) != EOS; ip++, op++) { if (*ip == '"') { /* span literal strings */ while (1) { *op++ = *ip++; if (*ip == '"' && *(ip+1) != '"') { *op = *ip; break; } } continue; } else if (*ip == HISTCHAR) { if (ip > in_text && *(ip-1) == '\\') { *(--op) = HISTCHAR; /* \^ */ continue; } else if (!isdigit(*(ip+1)) && index(ARGCHARS,*(ip+1)) == NULL) continue; /* Parse the argument list of the previous command if have not * already done so. */ if (!have_arg_strings++) { if (get_history (1, cmdblk, SZ_CMDBLK) == ERR) cl_error (E_UERR, "Nothing in history buffer"); nargs = get_arglist (cmdblk, argp); } /* Set up the substitution. */ switch (*(ip+1)) { case FIRSTARG: argno = 1; nrep = 1; break; case LASTARG: argno = nargs; nrep = 1; break; case ALLARGS: argno = 1; nrep = nargs; break; default: argno = *(ip+1) - '0'; nrep = 1; break; } /* Copy the arguments to the output command, overwriting the * history metacharacter (*op). */ while (--nrep >= 0 && argno <= nargs) { for (ap=argp[argno++]; (*op = *ap++); op++) ; if (nrep > 0) *op++ = ' '; } --op; /* leave pointing at last char output */ ip++; /* skip the macro type metacharacter */ } } return (have_arg_strings > 0); }