bool cp_oddcomm(char *s, wordlist *wl) { FILE *fp; if ((fp = inp_pathopen(s, "r")) != NULL) { char buf[BSIZE_SP]; wordlist *setarg; (void) fclose(fp); (void) sprintf(buf, "argc = %d argv = ( ", wl_length(wl)); while (wl) { (void) strcat(buf, wl->wl_word); (void) strcat(buf, " "); wl = wl->wl_next; } (void) strcat(buf, ")"); setarg = cp_lexer(buf); com_set(setarg); wl_free(setarg); inp_source(s); cp_remvar("argc"); cp_remvar("argv"); return (TRUE); } if (wl && eq(wl->wl_word, "=")) { wordlist *ww = wl_cons(copy(s), wl); com_let(ww); wl_delete_slice(ww, ww->wl_next); return (TRUE); } return (FALSE); }
/* Substitute variable name by its value and restore to wordlist */ wordlist * cp_variablesubst(wordlist *wlist) { wordlist *wl; for (wl = wlist; wl; wl = wl->wl_next) { char *s_dollar; int i = 0; while ((s_dollar = strchr(wl->wl_word + i, cp_dol)) != NULL) { int prefix_len = (int) (s_dollar - wl->wl_word); char *tail = span_var_expr(s_dollar + 1); char *var = copy_substring(s_dollar + 1, tail); wordlist *nwl = vareval(var); tfree(var); if (nwl) { char *x = nwl->wl_word; char *tail_ = copy(tail); nwl->wl_word = tprintf("%.*s%s", prefix_len, wl->wl_word, nwl->wl_word); free(x); if (wlist == wl) wlist = nwl; wl = wl_splice(wl, nwl); i = (int) strlen(wl->wl_word); x = wl->wl_word; wl->wl_word = tprintf("%s%s", wl->wl_word, tail_); free(x); free(tail_); } else if (prefix_len || *tail) { char *x = wl->wl_word; wl->wl_word = tprintf("%.*s%s", prefix_len, wl->wl_word, tail); i = prefix_len; free(x); } else { wordlist *next = wl->wl_next; if (wlist == wl) wlist = next; wl_delete_slice(wl, next); if (!next) return wlist; wl = next; i = 0; } } } return (wlist); }
static double * getlims(wordlist *wl, char *name, int number) { double *d; wordlist *beg, *wk; int n; if (number < 1) return NULL; beg = wl_find(name, wl->wl_next); if (!beg) return NULL; wk = beg->wl_next; d = TMALLOC(double, number); for (n = 0; n < number; n++) { char *ss; double *td; if (!wk) { fprintf(cp_err, "Syntax error: not enough parameters for \"%s\".\n", name); txfree(d); return NULL; } ss = wk->wl_word; td = ft_numparse(&ss, FALSE); if (!td) { fprintf(cp_err, "Syntax error: bad parameters for \"%s\".\n", name); txfree(d); return NULL; } d[n] = *td; wk = wk->wl_next; } wl_delete_slice(beg, wk); return d; }