/* va: TODO: free control structure(s) before overwriting (memory leakage) */ int cp_evloop(char *string) { wordlist *wlist, *ww, *freewl; struct control *x; char *i; int nn; #define newblock \ do { \ cend[stackp]->co_children = TMALLOC(struct control, 1); \ ZERO(cend[stackp]->co_children, struct control); \ cend[stackp]->co_children->co_parent = cend[stackp]; \ cend[stackp] = cend[stackp]->co_children; \ cend[stackp]->co_type = CO_UNFILLED; \ } while(0) for (;;) { freewl = wlist = getcommand(string); if (wlist == NULL) { /* End of file or end of user input. */ if (cend[stackp] && cend[stackp]->co_parent && !string) { cp_resetcontrol(); continue; } else { return (0); } } if ((wlist->wl_word == NULL) || (*wlist->wl_word == '\0')) { /* User just typed return. */ wl_free(wlist); /* va, avoid memory leak */ if (string) { return (1); } else { cp_event--; continue; } } /* Just a check... */ for (ww = wlist; ww; ww = ww->wl_next) if (!ww->wl_word) { fprintf(cp_err, "cp_evloop: Internal Error: NULL word pointer\n"); continue; } /* Add this to the control structure list. If cend->co_type is * CO_UNFILLED, the last line was the beginning of a block, * and this is the unfilled first statement. */ /* va: TODO: free old structure and its content, before overwriting */ if (cend[stackp] && (cend[stackp]->co_type != CO_UNFILLED)) { cend[stackp]->co_next = TMALLOC(struct control, 1); ZERO(cend[stackp]->co_next, struct control); cend[stackp]->co_next->co_prev = cend[stackp]; cend[stackp]->co_next->co_parent = cend[stackp]->co_parent; cend[stackp] = cend[stackp]->co_next; } else if (!cend[stackp]) {
void plot_docoms(wordlist *wl) { bool inter; inter = cp_interactive; cp_interactive = FALSE; while (wl) { (void) cp_evloop(wl->wl_word); wl = wl->wl_next; } cp_resetcontrol(); cp_interactive = inter; }