⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
            (void) fclose(fp);            inp_source("spice.rc");        }    }#  endif /* ~ HAS_GETPW */    if (cmd_line_term) {	*cmd_line_term = term_1stch; /* XXX oh, gross!				      *	First char got squashed scanning the				      * command line				      */	cp_vset("term", VT_STRING, cmd_line_term);    }    if (!ft_batchmode) {	com_version(NULL);        DevInit( );	if (News_File && *News_File) {	    fp = fopen(cp_tildexpand(News_File), "r");	    if (fp) {		while (fgets(buf, BSIZE_SP, fp))		    fputs(buf, stdout);		(void) fclose(fp);	    }	}    }bot:    /* Pass 2 -- get the filenames. If we are spice, then this means     * build a circuit for this file. If this is in server mode, don't     * process any of these args.     */#  ifdef HAS_LONGJUMP    if (setjmp(jbuf) == 1)        goto evl;#  endif#endif /* ~ BATCH */    cp_interactive = false;    err = 0;#ifdef SIMULATOR    if (!ft_servermode && !ft_nutmeg) {        FILE *file = NULL, *tp = NULL;        char *tempfile = NULL, buf[BSIZE_SP], *smktemp();        for (tv = av + 1, i = 0; *tv; tv++)            if (**tv != Spice_OptChar)                i++;        if (i == 1) {            for (tv = av + 1, i = 0; *tv; tv++)                if (**tv != Spice_OptChar)                    break;            if (!(file = fopen(*tv, "r"))) {                perror(*tv);                i = 0;		if (ft_batchmode)		    shutdown(EXIT_BAD);            }        } else if (i) {            tempfile = smktemp("sp");            if (!(file = fopen(tempfile, "w+"))) {                perror(tempfile);                shutdown(EXIT_BAD);            }            for (tv = av + 1, i = 0; *tv; tv++)                if (**tv != Spice_OptChar) {                    if (!(tp = fopen(*tv, "r"))) {                        perror(*tv);			err = 1;                        break;                    }                    while ((i = fread(buf, 1, BSIZE_SP, tp)) > 0)                        (void) fwrite(buf, i, 1, file);                    (void) fclose(tp);                }            (void) fseek(file, (long) 0, 0);        }        if (file && (!err || !ft_batchmode)) {            inp_spsource(file, false, tempfile ? (char *) NULL : *tv);            gotone = true;        }#  ifdef HAS_UNLINK	if (tempfile)	    (void) unlink(tempfile);#  endif	if (ft_batchmode && err)	    shutdown(EXIT_BAD);    }#endif#ifndef BATCH    if (ft_nutmeg && gdata) {        /* Read in the rawfiles */        for (av++; *av; av++)            if (**av != Spice_OptChar) {                ft_loadfile(*av);                gotone = true;            }        if (!gotone)            ft_loadfile(ft_rawfile);    }#endif#ifdef SIMULATOR    if (!gotone && ft_batchmode && !ft_nutmeg)        inp_spsource(circuit_file, false, (char *) NULL);#  ifndef BATCHevl:    if (ft_batchmode) {        /* If we get back here in batch mode then something is         * wrong, so exit.         */        bool st = false;        (void) setjmp(jbuf);        if (st == true) {            shutdown(EXIT_BAD);	}        st = true;        if (ft_servermode) {            if (ft_curckt == NULL) {                fprintf(cp_err, "Error: no circuit loaded!\n");                shutdown(EXIT_BAD);            }            if (ft_dorun(""))		shutdown(EXIT_BAD);            shutdown(EXIT_NORMAL);        }        /* If -r is specified, then we don't bother with the dot         * cards. Otherwise, we use wrd_run, but we are careful         * not to save too much.         */        cp_interactive = false;        if (rflag) {	    ft_dotsaves();	    error2 = ft_dorun(ft_rawfile);	    if (ft_cktcoms(true) || error2)		shutdown(EXIT_BAD);        } else {            if (ft_savedotargs()) {		error2 = ft_dorun(NULL);		if (ft_cktcoms(false) || error2)		    shutdown(EXIT_BAD);	    } else {		fprintf(stderr,		    "Note: No \".plot\", \".print\", or \".fourier\" lines; no simulations run\n");		shutdown(EXIT_BAD);	    }        }    } else {        (void) setjmp(jbuf);        cp_interactive = true;	while (cp_evloop((char *) NULL) == 1) ;    }#  else /* if BATCH */    if (st == true) {	shutdown(EXIT_BAD);    }    st = true;    if (ft_servermode) {	if (ft_curckt == NULL) {	    fprintf(cp_err, "Error: no circuit loaded!\n");	    shutdown(EXIT_BAD);	}    }#    ifdef SPICE2    if (ft_savedotargs( )) {	error2 = ft_dorun(NULL);	if (ft_cktcoms(false) || error2)	    shutdown(EXIT_BAD);    } else {	fprintf(stderr,"Note: No \".plot\", \".print\", or \".fourier\" lines; no simulations run\n");	shutdown(EXIT_BAD);    }#    else    ft_dotsaves( );    error2 = ft_dorun(ft_rawfile);    if (ft_cktcoms(true) || error2)	shutdown(EXIT_BAD);#    endif#  endif#elseevl:    /* Nutmeg "main" */    (void) setjmp(jbuf);    cp_interactive = true;    while (cp_evloop((char *) NULL) == 1) ;#endif    shutdown(EXIT_NORMAL);}/* Shutdown gracefully. */intshutdown(exitval)int exitval;{#ifdef PARALLEL_ARCH    if (exitval == EXIT_BAD) {	Error("Fatal error in SPICE", -1);    } else {	PEND_();    }#endif /* PARALLEL_ARCH */    exit(exitval);}/* allocate space for global constants in 'CONST.h' */double CONSTroot2;double CONSTvt0;double CONSTKoverQ;double CONSTe;IFfrontEnd *SPfrontEnd = NULL;intSPIinit(frtEnd,description)    IFfrontEnd *frtEnd;    IFsimulator **description;{    SPfrontEnd = frtEnd;    *description = &SIMinfo;    CONSTroot2 = sqrt(2.);    CONSTvt0 = CONSTboltz * (27 /* deg c */ + CONSTCtoK ) / CHARGE;    CONSTKoverQ = CONSTboltz / CHARGE;    CONSTe = exp((double)1.0);    return(OK);}/* XXX SIMinit and SPIinit ?? */int SIMinit(frontEnd,simulator)    IFfrontEnd *frontEnd;    IFsimulator **simulator;{    return(SPIinit(frontEnd,simulator));}#ifdef BATCH/* * Incredibly Ugly *//* Now some misc junk that we need to fake */bool cp_nocc = true;bool cp_debug = false;int cp_maxhistlength = 0;char cp_chars[128];MFBHalt( ) { }#ifndef SPICE2/* ARGSUSED */ char *cp_tildexpand(s) char *s; { return (s); }/* ARGSUSED */ struct dvec *vec_fromplot(w, p) char *w; struct plot *p;        { return (NULL); }void vec_new() {}void plot_new() {}void plot_setcur() {}/* ARGSUSED */ struct plot *plot_alloc(name) char *name; { return (NULL); }struct plot *plot_cur = NULL;/* ARGSUSED */ void plot_docoms(wl) wordlist *wl; {}void out_init() {}voidout_printf(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10)    char *fmt, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9, *s10;{    printf(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);}/* ARGSUSED */ void out_send(s) char *s; {}char out_pbuf[1];/* ARGSUSED */ struct dvec *vec_get(word) char *word; { return (NULL); }#endif/* ARGSUSED */ int cp_usrset(v, i) struct variable *v; bool i; {return(US_OK);}void cp_pushcontrol() {}void cp_popcontrol() {}/* ARGSUSED */ void cp_addkword(class, word) int class; char *word; {}struct circ *ft_circuits = 0, *ft_curckt = 0;/* ARGSUSED */ char *cp_kwswitch(c, t) int c; char *t; { return (NULL); }/* ARGSUSED */ bool ft_bpcheck(r, i) struct plot *r; int i; { return (true); }/* ARGSUSED */ void cp_ccon(b) bool b; {}/* ARGSUSED */ wordlist *cp_cctowl(stuff) char *stuff; { return NULL; }int currentgraph = 0;/* ARGSUSED */ void Input(p, q) char *p, *q; {}/* ARGSUSED */ void DevSwitch(i) int i; {}/* ARGSUSED */ int *CopyGraph(i) int i; {}/* ARGSUSED */ void DestroyGraph(i) int i; {}/* ARGSUSED */ void NewViewport(i) int i; {}/* ARGSUSED */ void cp_remkword() { }/* ARGSUSED */ void cp_resetcontrol() { }bool gr_init() {}void gr_redraw() {}/* ARGSUSED */ void gr_iplot(pl) struct plot *pl; {}/* ARGSUSED */ void gr_end_iplot(pl) struct plot *pl; {}/* ARGSUSED */ void gr_pmsg(text, more) char *text; bool more; {}/* ARGSUSED */ void gr_clean(intr) bool intr; {}/* ARGSUSED */ int cp_evloop(string) char *string; { return (0); }void ft_graf() {}void ft_trquery() {}/* ARGSUSED */ void ft_newcirc(ckt) struct circ *ckt; {}void cp_doquit() { shutdown(0); }/* ARGSUSED */ void cp_usrvars(v1, v2) struct variable **v1, **v2; { return; }/* ARGSUSED */ struct variable * cp_enqvar(word) char *word; { return (NULL); }/* ARGSUSED */ void cp_ccom(w, b, e) wordlist *w; char *b; bool e; { return; }/* ARGSUSED */ void com_resume( ) { return; }/* ARGSUSED */ int if_sens_run( ) { return 0; }/* ARGSUSED */ int ft_xgraph( ) { return 0; }/* ARGSUSED */ int gr_resize( ) { return 0; }/* This is from options.c *//* Extract the .option cards from the deck... */struct line *inp_getopts(deck)    struct line *deck;{    struct line *last = NULL, *opts = NULL, *dd, *next = NULL;    for (dd = deck->li_next; dd; dd = next) {        next = dd->li_next;        if (ciprefix(".opt", dd->li_line)) {            inp_casefix(dd->li_line);            if (last)                last->li_next = dd->li_next;            else                deck->li_next = dd->li_next;            dd->li_next = opts;            opts = dd;        } else            last = dd;    }    return (opts);}#ifndef SPICE2/* This is from dotcards.c -- we don't want to include the whole file. */static wordlist *gettoks();/* Extract all the .save cards */voidft_dotsaves(){    wordlist *com, *wl = NULL;    char *s;    if (!ft_curckt) /* Shouldn't happen. */        return;    for (com = ft_curckt->ci_commands; com; com = com->wl_next) {        if (ciprefix(".save", com->wl_word)) {            s = com->wl_word;            (void) gettok(&s);            wl = wl_append(wl, gettoks(s));        }    }    com_save(wl);    return;}/* This is also from dotcards.c.  Stripped down version * for "rawfile only mode": execute .options acct and .options list, * and issue a warning message about any other output "dot" lines. */intft_cktcoms(terse)    bool terse;{    wordlist *coms, *command;    char *plottype, *s;    struct dvec *v;    static wordlist twl = { "col", NULL, NULL } ;    int i;    if (!ft_curckt)        return;    cp_interactive = false;    /* Circuit name */    fprintf(cp_out, "Circuit: %s\nDate: %s\n\n", ft_curckt->ci_name,            datestring());    fprintf(cp_out, "\n");    /* Listing if necessary... */    if (ft_listprint)        inp_list(cp_out, ft_curckt->ci_deck, ft_curckt->ci_options,                LS_DECK);    for (coms = ft_curckt->ci_commands; coms; coms = coms->wl_next) {	if (ciprefix(".print", s) || ciprefix(".plot", s) ||	    ciprefix(".four", s))	{	    fprintf(stderr,	    "Note: \".plot\", \".print\", and .\"fourier\" lines ignored\n");	    fprintf(stderr, "      (rawfile only)\n");	    break;	}    }    /* And finally the accounting info. */    if (ft_acctprint) {        static wordlist ww = { "everything", NULL, NULL } ;        com_rusage(&ww);    } else        com_rusage((wordlist *) NULL);    (void) putc('\n', cp_out);    return;bad:    fprintf(cp_err, "Internal Error: ft_cktcoms: bad commands\n");    return;}static wordlist *gettoks(s)    char *s;{    char *t, *r, buf[64];    wordlist *wl = NULL, *end = NULL;    bool iflag;    while (t = gettok(&s)) {        if (*t == '(' /* ) */) {            /* This is a (upper, lower) thing -- ignore. */            continue;        } else if (!index(t, '(' /*)*/ )) {            if (end) {                end->wl_next = alloc(struct wordlist);                end->wl_next->wl_prev = end;                end = end->wl_next;            } else                wl = end = alloc(struct wordlist);            end->wl_word = copy(t);        } else if (!index(t, ',')) {            iflag = ((*t == 'i') || (*t == 'I')) ? true : false;            while (*t != '(' /*)*/)                t++;            t++;            for (r = t; *r && *r != /*(*/ ')'; r++)                ;            *r = '\0';            if (end) {                end->wl_next = alloc(struct wordlist);                end->wl_next->wl_prev = end;                end = end->wl_next;            } else                wl = end = alloc(struct wordlist);            if (iflag) {                (void) sprintf(buf, "%s#branch", t);                t = buf;            }            end->wl_word = copy(t);        } else {            /* The painful case... */            while (*t != '(' /*)*/)                t++;            t++;            for (r = t; *r && *r != ','; r++)                ;            *r = '\0';            if (end) {                end->wl_next = alloc(struct wordlist);                end->wl_next->wl_prev = end;                end = end->wl_next;            } else                wl = end = alloc(struct wordlist);            end->wl_word = copy(t);            t = r + 1;            for (r = t; *r && *r != /*(*/ ')'; r++)                ;            *r = '\0';            if (end) {                end->wl_next = alloc(struct wordlist);                end->wl_next->wl_prev = end;                end = end->wl_next;            } else                wl = end = alloc(struct wordlist);            end->wl_word = copy(t);        }    }    return (wl);}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -