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

📄 inp.c

📁 支持数字元件仿真的SPICE插件
💻 C
📖 第 1 页 / 共 3 页
字号:
                        sprintf(out_pbuf, "%6d : %s\n",                            here->li_linenum,                            upper(here->li_line));            out_send(out_pbuf);                    } else                        fprintf(file, "%6d : %s\n",                            here->li_linenum,                            upper(here->li_line));                } else {                    if (useout)                        out_printf("%s\n",                            upper(here->li_line));                    else                        fprintf(file, "%s\n",                            upper(here->li_line));                }                if (here->li_error && (type == LS_PHYSICAL)) {                    if (useout)                        out_printf("%s\n",                            here->li_error);                    else                        fprintf(file, "%s\n",                            here->li_error);                }            } else {                for (there = here->li_actual; there;                        there = there->li_next) {                    there->li_linenum = i++;                    if (ciprefix(".end", here->li_line) &&                            isalpha(here->li_line[4]))                        continue;                    if (type == LS_PHYSICAL) {                        if (useout) {                            sprintf("%6d : %s\n",                                out_pbuf,                                there->li_linenum,                                upper(there->li_line));                out_send(out_pbuf);                        } else                            fprintf(file, "%6d : %s\n",                                there->li_linenum,                                upper(there->li_line));                    } else {                        if (useout)                            out_printf("%s\n",                                upper(there->li_line));                        else                            fprintf(file, "%s\n",                                upper(there->li_line));                    }                    if (there->li_error &&                             (type == LS_PHYSICAL)) {                        if (useout)                            out_printf("%s\n",                            there->li_error);                        else                            fprintf(file, "%s\n",                            there->li_error);                    }                }                here->li_linenum = i;            }        }        if (extras) {            deck = extras;            extras = NULL;            goto top2;        }        if (type == LS_PHYSICAL) {            if (useout) {                sprintf(out_pbuf, "%6d : .END\n", i);            out_send(out_pbuf);            } else                fprintf(file, "%6d : .END\n", i);        } else {            if (useout)                out_printf(".END\n");            else                fprintf(file, ".END\n");        }    } else        fprintf(cp_err, "inp_list: Internal Error: bad type %d\n",                 type);    return;}voidinp_casefix(string)    register char *string;{    while (*string) {#ifdef ASCIIQUOTE        /* Let's make this really idiot-proof. */        *string = strip(*string);        if ((*string < ' ') && (*string != '\t'))            *string = '_';  /* ? is bad since ? = help... */#endif        if (isupper(*string))            *string = tolower(*string);        string++;    }    return;}/* The routine to source a spice input deck. We read the deck in, take out * the front-end commands, and create a CKT structure. Also we filter out * the following cards: .save, .width, .four, .print, and .plot, to perform * after the run is over. */voidinp_spsource(fp, comfile, filename)    FILE *fp;    bool comfile;    char *filename;{    struct line *deck, *dd, *ld;    struct line *realdeck, *options;    char *tt, name[BSIZE], *s, *t;    bool nosubckts, commands = false;    wordlist *wl = NULL, *end = NULL;    wordlist *controls = NULL;    FILE *lastin, *lastout, *lasterr;        inp_readall(fp, &deck);    if (!deck)        return;        if (!comfile)        options = inp_getopts(deck);    realdeck = inp_deckcopy(deck);    if (!comfile) {        /* Save the title before INPgetTitle gets it. */        tt = copy(deck->li_line);        if (!deck->li_next)            fprintf(cp_err, "Warning: no cards in deck...\n");    }    (void) fclose(fp);    /* Now save the IO context and start a new control set...  After     * we are done with the source we'll put the old file descriptors      * back.  I guess we could use a FILE stack, but since this routine     * is recursive anyway...     */    lastin = cp_curin;    lastout = cp_curout;    lasterr = cp_curerr;    cp_curin = cp_in;    cp_curout = cp_out;    cp_curerr = cp_err;    cp_pushcontrol();    /* We should now go through the deck and execute front-end      * commands and remove them. Front-end commands are enclosed by     * the cards .control and .endc, unless comfile     * is true, in which case every line must be a front-end command.     * There are too many problems with matching the first word on     * the line.     */    ld = deck;    if (comfile) {        /* This is easy. */        for (dd = deck; dd; dd = ld) {            ld = dd->li_next;            if ((dd->li_line[0] == '*') && (dd->li_line[1] != '#'))                continue;            if (!ciprefix(".control", dd->li_line) &&                    !ciprefix(".endc", dd->li_line))                if (dd->li_line[0] == '*')                    (void) cp_evloop(dd->li_line + 2);                else                    (void) cp_evloop(dd->li_line);            tfree(dd->li_line);            tfree(dd);        }       } else {        for (dd = deck->li_next; dd; dd = ld->li_next) {            if ((dd->li_line[0] == '*') &&                    (dd->li_line[1] != '#')) {                ld = dd;                continue;            }            (void) strncpy(name, dd->li_line, BSIZE);            for (s = name; *s && isspace(*s); s++)                ;            for (t = s; *t && !isspace(*t); t++)                ;            *t = '\0';            if (ciprefix(".control", dd->li_line)) {                ld->li_next = dd->li_next;                tfree(dd->li_line);                tfree(dd);                if (commands)                    fprintf(cp_err,                     "Warning: redundant .control card\n");                else                    commands = true;            } else if (ciprefix(".endc", dd->li_line)) {                ld->li_next = dd->li_next;                tfree(dd->li_line);                tfree(dd);                if (commands)                    commands = false;                else                    fprintf(cp_err,                     "Warning: misplaced .endc card\n");            } else if (commands || prefix("*#", dd->li_line)) {                wl = alloc(wordlist);                if (controls) {                    wl->wl_next = controls;                    controls->wl_prev = wl;                    controls = wl;                } else                    controls = wl;                if (prefix("*#", dd->li_line))                    wl->wl_word = copy(dd->li_line + 2);                else                    wl->wl_word = dd->li_line;                ld->li_next = dd->li_next;                tfree(dd);            } else if (!*dd->li_line) {                /* So blank lines in com files don't get                 * considered as circuits.                 */                ld->li_next = dd->li_next;                tfree(dd->li_line);                tfree(dd);            } else {                inp_casefix(s);                inp_casefix(dd->li_line);                if (eq(s, ".width") || ciprefix(".four", s) ||                        eq(s, ".plot") ||                         eq(s, ".print") ||                        eq(s, ".save")) {                    if (end) {                        end->wl_next = alloc(wordlist);                        end->wl_next->wl_prev = end;                        end = end->wl_next;                    } else                        wl = end = alloc(wordlist);                    end->wl_word = copy(dd->li_line);                    ld->li_next = dd->li_next;                    tfree(dd->li_line);                    tfree(dd);                } else                    ld = dd;            }        }        if (deck->li_next) {            /* There is something left after the controls. *//* gtri - wbk - Comment out printing of circuit title */            /* fprintf(cp_out, "\nCircuit: %s\n\n", tt);  *//* gtri - end - Comment out printing of circuit title *//* gtri - wbk - Translate all SPICE 2G6 polynomial type sources */            deck->li_next = ENHtranslate_poly(deck->li_next);/* gtri - end - Translate all SPICE 2G6 polynomial type sources */            /* Now expand subcircuit macros. Note that we have to              * fix the case before we do this but after we              * deal with the commands.             */            if (!cp_getvar("nosubckt", VT_BOOL, (char *)                     &nosubckts))                deck->li_next = inp_subcktexpand(deck->                        li_next);            deck->li_actual = realdeck;            inp_dodeck(deck, tt, wl, false, options, filename);        }        /* Now that the deck is loaded, do the commands... */        if (controls) {            for (end = wl = wl_reverse(controls); wl;                    wl = wl->wl_next)                (void) cp_evloop(wl->wl_word);            wl_free(end);        }    }    /* Now reset everything.  Pop the control stack, and fix up the IO     * as it was before the source.     */    cp_popcontrol();    cp_curin = lastin;    cp_curout = lastout;    cp_curerr = lasterr;    return;}/* This routine is cut in half here because com_rset has to do what follows * also. End is the list of commands we execute when the job is finished: * we only bother with this if we might be running in batch mode, since * it isn't much use otherwise. */voidinp_dodeck(deck, tt, end, reuse, options, filename)    struct line *deck;    char *tt;    wordlist *end;    bool reuse;    struct line *options;    char *filename;{    struct circ *ct;    struct line *dd;    char *ckt, *tab, *s;    struct variable *eev = NULL;    wordlist *wl;    bool noparse, ii;    /* First throw away any old error messages there might be and fix     * the case of the lines.     */    for (dd = deck; dd; dd = dd->li_next) {        if (dd->li_error) {            tfree(dd->li_error);            dd->li_error = NULL;        }    }    if (reuse) {        ct = ft_curckt;    } else {        if (ft_curckt) {            ft_curckt->ci_devices = cp_kwswitch(CT_DEVNAMES,                     (char *) NULL);            ft_curckt->ci_nodes = cp_kwswitch(CT_NODENAMES,                     (char *) NULL);        }        ft_curckt = ct = alloc(circ);    }    (void) cp_getvar("noparse", VT_BOOL, (char *) &noparse);    if (!noparse)        ckt = if_inpdeck(deck, &tab);    else        ckt = NULL;    out_init();/* gtri - modify - 12/12/90 - wbk - add setting of ipc syntax error flag */    for (dd = deck; dd; dd = dd->li_next)        if (dd->li_error) {            out_printf("Error on line %d : %s\n%s\n",                dd->li_linenum, dd->li_line, dd->li_error);            g_ipc.syntax_error = IPC_TRUE;        }/* gtri - end - 12/12/90 */    /* Add this circuit to the circuit list. If reuse is true then      * use the ft_curckt structure.     */    if (!reuse) {        for (dd = deck->li_next; dd; dd = dd->li_next)            if_setndnames(dd->li_line);        /* Be sure that ci_devices and ci_nodes are valid... */        ft_curckt->ci_devices = cp_kwswitch(CT_DEVNAMES,                 (char *) NULL);        (void) cp_kwswitch(CT_DEVNAMES, ft_curckt->ci_devices);        ft_curckt->ci_nodes = cp_kwswitch(CT_NODENAMES, (char *) NULL);        (void) cp_kwswitch(CT_NODENAMES, ft_curckt->ci_nodes);        ft_newcirc(ct);        /* ft_setccirc(); */ ft_curckt = ct;    }    ct->ci_name = tt;    ct->ci_deck = deck;    ct->ci_options = options;    if (deck->li_actual)

⌨️ 快捷键说明

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