/* data printout to file plotargs */ void com_write_simple(wordlist *wl) { char *fname = NULL; bool tempf = FALSE; if (wl) { fname = wl->wl_word; wl = wl->wl_next; } if (!wl) return; if (cieq(fname, "temp") || cieq(fname, "tmp")) { fname = smktemp("gp"); /* Is this the correct name ? */ tempf = TRUE; } (void) plotit(wl, fname, "writesimple"); /* Leave temp file sitting around so gnuplot can grab it from background. */ if (tempf) tfree(fname); }
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); }
int main(int ac, char **av) { char *sf, *af; char buf[BSIZE_SP]; char t, f; struct plot *pl; size_t n; char *infile = NULL; char *outfile = NULL; FILE *fp; cp_in = stdin; cp_out = stdout; cp_err = stderr; cp_curin = stdin; cp_curout = stdout; cp_curerr = stderr; switch (ac) { case 5: sf = av[2]; af = av[4]; f = *av[1]; t = *av[3]; break; case 3: f = *av[1]; t = *av[2]; /* This is a pain, but there is no choice */ sf = infile = smktemp("scin"); af = outfile = smktemp("scout"); if (!(fp = fopen(infile, "w"))) { perror(infile); exit(EXIT_BAD); } while ((n = fread(buf, 1, sizeof(buf), stdin)) != 0) (void) fwrite(buf, 1, n, fp); (void) fclose(fp); break; case 1: printf("Input file: "); (void) fflush(stdout); (void) fgets(buf, BSIZE_SP, stdin); sf = copy(buf); printf("Input type: "); (void) fflush(stdout); (void) fgets(buf, BSIZE_SP, stdin); f = buf[0]; printf("Output file: "); (void) fflush(stdout); (void) fgets(buf, BSIZE_SP, stdin); af = copy(buf); printf("Output type: "); (void) fflush(stdout); (void) fgets(buf, BSIZE_SP, stdin); t = buf[0]; break; default: fprintf(cp_err, "Usage: %s fromtype fromfile totype tofile,\n", cp_program); fprintf(cp_err, "\twhere types are o, b, or a\n"); fprintf(cp_err, "\tor, %s fromtype totype, used as a filter.\n", cp_program); exit(EXIT_BAD); } switch(f) { case 'o' : pl = oldread(sf); break; case 'b' : case 'a' : pl = raw_read(sf); break; default: fprintf(cp_err, "Types are o, a, or b\n"); exit(EXIT_BAD); } if (!pl) exit(EXIT_BAD); switch(t) { case 'o' : oldwrite(af, FALSE, pl); break; case 'b' : raw_write(af, pl, FALSE, TRUE); break; case 'a' : raw_write(af, pl, FALSE, FALSE); break; default: fprintf(cp_err, "Types are o, a, or b\n"); exit(EXIT_BAD); } if (ac == 3) { /* Gotta finish this stuff up */ if (!(fp = fopen(outfile, "r"))) { perror(outfile); exit(EXIT_BAD); } while ((n = fread(buf, 1, sizeof(buf), fp)) != 0) (void) fwrite(buf, 1, n, stdout); (void) fclose(fp); (void) unlink(infile); (void) unlink(outfile); } exit(EXIT_NORMAL); }