void nutcom_source(wordlist *wl) { FILE *fp, *tp; char buf[BSIZE_SP]; //bool inter; int inter; char *tempfile = NULL; wordlist *owl = wl; size_t n; inter = cp_interactive; cp_interactive = FALSE; if (wl->wl_next) { /* There are several files -- put them into a temp file... */ tempfile = smktemp("sp"); if ((fp = inp_pathopen(tempfile, "w+")) == NULL) { perror(tempfile); cp_interactive = TRUE; return; } while (wl) { if ((tp = inp_pathopen(wl->wl_word, "r")) == NULL) { perror(wl->wl_word); (void) fclose(fp); cp_interactive = TRUE; (void) unlink(tempfile); return; } while ((n = fread(buf, 1, BSIZE_SP, tp)) > 0) (void) fwrite(buf, 1, n, fp); (void) fclose(tp); wl = wl->wl_next; } (void) fseek(fp, 0L, SEEK_SET); } else { fp = inp_pathopen(wl->wl_word, "r"); } if (fp == NULL) { perror(wl->wl_word); cp_interactive = TRUE; return; } /* Don't print the title if this is a .spiceinit file. */ if (ft_nutmeg || substring(INITSTR, owl->wl_word) || substring(ALT_INITSTR, owl->wl_word)) { inp_nutsource(fp, TRUE, tempfile ? NULL : wl->wl_word); } else { inp_nutsource(fp, FALSE, tempfile ? NULL : wl->wl_word); } cp_interactive = inter; if (tempfile) (void) unlink(tempfile); }
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); }
bool cp_oddcomm(char *s, wordlist *wl) { FILE *fp; char buf[BSIZE_SP]; wordlist ww; if ((fp = inp_pathopen(s, "r"))) { (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, ")"); com_set(cp_lexer(buf)); inp_source(s); cp_remvar("argc"); cp_remvar("argv"); return (TRUE); } else if (wl && eq(wl->wl_word, "=")) { ww.wl_next = wl; wl->wl_prev = &ww; ww.wl_prev = NULL; ww.wl_word = s; com_let(&ww); return (TRUE); } else return (FALSE); }