📄 inp.c
字号:
ct->ci_origdeck = deck->li_actual; else ct->ci_origdeck = ct->ci_deck; ct->ci_ckt = ckt; ct->ci_symtab = tab; ct->ci_inprogress = false; ct->ci_runonce = false; ct->ci_commands = end; if (filename) ct->ci_filename = copy(filename); else ct->ci_filename = NULL; if (!noparse) { for (; options; options = options->li_next) { for (s = options->li_line; *s && !isspace(*s); s++) ; ii = cp_interactive; cp_interactive = false; wl = cp_lexer(s); cp_interactive = ii; if (!wl || !wl->wl_word || !*wl->wl_word) continue; if (eev) eev->va_next = cp_setparse(wl); else ct->ci_vars = eev = cp_setparse(wl); while (eev->va_next) eev = eev->va_next; } for (eev = ct->ci_vars; eev; eev = eev->va_next) switch (eev->va_type) { case VT_BOOL: if_option(ct->ci_ckt, eev->va_name, eev->va_type, (char *) NULL); break; case VT_NUM: if_option(ct->ci_ckt, eev->va_name, eev->va_type, (char *) &eev->va_num); break; case VT_REAL: if_option(ct->ci_ckt, eev->va_name, eev->va_type, (char *) &eev->va_real); break; case VT_STRING: if_option(ct->ci_ckt, eev->va_name, eev->va_type, eev->va_string); break; } } cp_addkword(CT_CKTNAMES, tt); return;}/* Edit and re-load the current input deck. Note that if these commands are * used on a non-unix machine, they will leave spice.tmp junk files lying * around. */voidcom_edit(wl) wordlist *wl;{ char *filename; FILE *fp; bool inter, permfile; char buf[BSIZE]; inter = cp_interactive; cp_interactive = false; if (wl) { if (!doedit(wl->wl_word)) { cp_interactive = inter; return; } if (!(fp = inp_pathopen(wl->wl_word, "r"))) { perror(wl->wl_word); cp_interactive = inter; return; } inp_spsource(fp, false, wl->wl_word); } else { /* If there is no circuit yet, then create one... */ if (ft_curckt && ft_curckt->ci_filename) { filename = ft_curckt->ci_filename; permfile = true; } else {#ifdef UNIX filename = mktemp("/tmp/spXXXXXX");#else filename = "spice.tmp";#endif permfile = false; } if (ft_curckt && !ft_curckt->ci_filename) {#ifdef UNIX filename = mktemp("/tmp/spXXXXXX");#else filename = "spice.tmp";#endif permfile = false; } if (ft_curckt && !ft_curckt->ci_filename) { if (!(fp = fopen(filename, "w"))) { perror(filename); cp_interactive = inter; return; } inp_list(fp, ft_curckt->ci_deck, ft_curckt->ci_options, LS_DECK); fprintf(cp_err, "Warning: editing a temporary file -- circuit not saved\n"); (void) fclose(fp); } else if (!ft_curckt) { if (!(fp = fopen(filename, "w"))) { perror(filename); cp_interactive = inter; return; } fprintf(fp, "SPICE 3 test deck\n"); (void) fclose(fp); } if (!doedit(filename)) { cp_interactive = inter; return; }#ifdef notdef /* What do we do here?? */ /* Blow the old circuit away. */ if (ft_curckt) { /* Should free the old deck. */ ft_curckt->ci_deck = ft_curckt->ci_origdeck = ft_curckt->ci_options = NULL; ft_curckt->ci_commands = NULL; if_cktfree(ft_curckt->ci_ckt, ft_curckt->ci_symtab); if (ft_curckt == ft_circuits) { tfree(ft_curckt); ft_circuits = ft_curckt = ft_circuits->ci_next; } else { for (cc = ft_circuits; cc; cc = cc->ci_next) if (cc->ci_next == ft_curckt) { cc->ci_next = ft_curckt->ci_next; tfree(ft_curckt); ft_curckt = cc; break; } } }#endif if (!(fp = fopen(filename, "r"))) { perror(filename); cp_interactive = inter; return; } inp_spsource(fp, false, permfile ? filename : (char *) NULL); (void) fclose(fp);#ifdef UNIX if (ft_curckt && !ft_curckt->ci_filename) (void) unlink(filename);#endif } cp_interactive = inter; /* note: default is to run circuit after successful edit */ fprintf(cp_out, "run circuit? "); fflush(cp_out); (void) gets(buf); if (buf[0] != 'n') { fprintf(cp_out, "running circuit\n"); com_run(NULL); } return;}#ifndef DEF_EDITOR#define DEF_EDITOR "vi"#endifstatic booldoedit(filename) char *filename;{ char buf[BSIZE], buf2[BSIZE], *editor; if (cp_getvar("editor", VT_STRING, buf2)) { editor = buf2; } else { if (!(editor = getenv("EDITOR"))) editor = DEF_EDITOR; } (void) sprintf(buf, "%s %s", editor, filename); return (system(buf) ? false : true);}voidcom_source(wl) wordlist *wl;{ FILE *fp, *tp; char buf[BSIZE]; bool inter; char *tempfile = NULL; wordlist *owl = wl; int i; inter = cp_interactive; cp_interactive = false; if (wl->wl_next) { /* There are several files -- put them into a temp file... */#ifdef UNIX tempfile = mktemp("/tmp/spXXXXXX");#else tempfile = "spice.tmp";#endif if (!(fp = inp_pathopen(tempfile, "w+"))) { perror(tempfile); cp_interactive = true; return; } while (wl) { if (!(tp = inp_pathopen(wl->wl_word, "r"))) { perror(wl->wl_word); (void) fclose(fp); cp_interactive = true;#ifdef UNIX (void) unlink(tempfile);#endif return; } while ((i = fread(buf, 1, BSIZE, tp)) > 0) (void) fwrite(buf, 1, i, fp); (void) fclose(tp); wl = wl->wl_next; } (void) fseek(fp, (long) 0, 0); } 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(".spiceinit", owl->wl_word) || substring("spice.rc", owl->wl_word)) inp_spsource(fp, true, tempfile ? (char *) NULL : wl->wl_word); else inp_spsource(fp, false, tempfile ? (char *) NULL : wl->wl_word); cp_interactive = inter;#ifdef UNIX if (tempfile) (void) unlink(tempfile);#endif return;}/* Easy... */voidinp_source(file) char *file;{ static struct wordlist wl = { NULL, NULL, NULL } ; wl.wl_word = file; com_source(&wl); return;}/* This routine reads a line (of arbitrary length), up to a '\n' or 'EOF' * and returns a pointer to the resulting null terminated string. * The '\n' if found, is included in the returned string. * From: jason@ucbopal.BERKELEY.EDU (Jason Venner) * Newsgroups: net.sources */#define STRGROW 256static char *readline(fd) FILE *fd;{ int c; int memlen; char *strptr; int strlen; strptr = NULL; strlen = 0; memlen = STRGROW; strptr = tmalloc(memlen); memlen -= 1; /* Save constant -1's in while loop */ while((c = getc(fd)) != EOF) { strptr[strlen] = c; strlen++; if( strlen >= memlen ) { memlen += STRGROW; if( !(strptr = trealloc(strptr, memlen + 1))) { return (NULL); } } if (c == '\n') { break; } } if (!strlen) { free(strptr); return (NULL); } strptr[strlen] = '\0'; /* Trim the string */ strptr = trealloc(strptr, strlen + 1); return (strptr);}/* Look up the variable sourcepath and try everything in the list in order * if the file isn't in . and it isn't an abs path name. */#ifdef IBMPC#define SEPC '\\'#endif#ifdef UNIX#define SEPC '/'#endif#ifdef VMS#define SEPC ' '#endifFILE *inp_pathopen(name, mode) char *name, *mode;{ FILE *fp; char buf[BSIZE]; struct variable *v; /* If this is an abs pathname, or there is no sourcepath var, just * do an fopen. */#ifdef VMS if (index(name, ']') || !cp_getvar("sourcepath", VT_LIST, (char *) &v)) return (fopen(name, mode));#else if (index(name, SEPC) || !cp_getvar("sourcepath", VT_LIST, (char *) &v)) return (fopen(name, mode));#endif while (v) { switch (v->va_type) { case VT_STRING: cp_wstrip(v->va_string); (void) sprintf(buf, "%s%c%s", v->va_string, SEPC, name); break; case VT_NUM: (void) sprintf(buf, "%d%c%s", v->va_num, SEPC, name); break; case VT_REAL: /* This is foolish... */ (void) sprintf(buf, "%lg%c%s", v->va_real, SEPC, name); break; } if (fp = fopen(buf, mode)) return (fp); v = v->va_next; } return (NULL);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -