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

📄 inp.c

📁 支持数字元件仿真的SPICE插件
💻 C
📖 第 1 页 / 共 3 页
字号:
/* RCS Info: $Revision: 1.4 $ on $Date: 91/12/19 16:57:59 $ *           $Source: //pepper/atesse_spice/spice3/FTE/RCS/inp.c,v $ * Copyright (c) 1985 Wayne A. Christopher * * Stuff for dealing with spice input decks and command scripts, and * the listing routines. */#include "prefix.h"#include "CPdefs.h"#include "FTEdefs.h"#include "FTEdata.h"#include "FTEinp.h"/* gtri - add - 12/12/90 - wbk - include new stuff */#include "IPCtiein.h"#include "util.h"#include "ENH.h"/* gtri - end - 12/12/90 */#include "suffix.h"static char *readline();static bool doedit();/* Read the entire input file and return  a pointer to the first line of  * the linked list of 'card' records in data. */voidinp_readall(fp, data)    FILE *fp;    struct line **data;{    struct line *cc, *end = NULL, *prev = NULL, *working, *newcard;    char *buffer, *s, *t;    int line = 1;    FILE *newfp;/* gtri - modify - 12/12/90 - wbk - read from mailbox if ipc enabled */    Ipc_Status_t    ipc_status;    char            ipc_buffer[1025];  /* Had better be big enough */    int             ipc_len;    while (1) {        /* If IPC is not enabled, do equivalent of what SPICE did before */        if(! g_ipc.enabled) {            buffer = readline(fp);            if(! buffer)                break;        }        else {        /* else, get the line from the ipc channel. */        /* We assume that newlines are not sent by the client */        /* so we add them here */            ipc_status = ipc_get_line(ipc_buffer, &ipc_len, IPC_WAIT);            if(ipc_status == IPC_STATUS_END_OF_DECK) {                buffer = NULL;                break;            }            else if(ipc_status == IPC_STATUS_OK) {                buffer = (void *) MALLOC(strlen(ipc_buffer) + 3);                strcpy(buffer, ipc_buffer);                strcat(buffer, "\n");            }            else {  /* No good way to report this so just die */                exit(1);            }        }/* gtri - end - 12/12/90 */        if (*buffer == '@')            break;        for (s = buffer; *s && (*s != '\n'); s++)            ;        if (!*s) {            fprintf(cp_err, "Warning: premature EOF...\n");        }        *s = '\0';      /* Zap the newline. */        if (prefix(".include", buffer)) {            for (s = buffer; *s && !isspace(*s); s++)                ;            while (isspace(*s))                s++;            if (!*s) {                fprintf(cp_err,                 "Error: .include filename missing\n");                continue;            }            for (t = s; *t && !isspace(*t); t++)                ;            *t = '\0';            if (*s == '~')                s = cp_tildexpand(s);            if (!(newfp = inp_pathopen(s, "r"))) {                perror(s);                continue;            }            inp_readall(newfp, &newcard);            (void) fclose(newfp);            /* Make the .include a comment... */            *buffer = '*';            if (end) {                end->li_next = alloc(line);                end = end->li_next;            } else {                end = cc = alloc(line);            }            end->li_line = copy(buffer);            end->li_linenum = line++;            end->li_next = newcard;            /* Renumber the cards... */            for (end = newcard; end->li_next; end = end->li_next)                end->li_linenum = line++;            /* Fix the buffer up a bit. */            (void) strncpy(buffer + 1, "end of:", 7);        }        if (end) {            end->li_next = alloc(line);            end = end->li_next;        } else {            end = cc = alloc(line);        }        end->li_line = buffer;        end->li_linenum = line++;    }    if (!end) { /* No stuff here... */        *data = NULL;        return;    }    /* Now make logical lines. */    working = cc->li_next;      /* Skip title. */    while (working) {        switch (*working->li_line) {            case '*':            case '\0':                prev = NULL;                working = working->li_next;                break;            case '+':                if (!prev) {                    working->li_error = copy(                    "Illegal continuation card: ignored.");                    working = working->li_next;                    break;                }                buffer = tmalloc(strlen(prev->li_line) +                         strlen(working->li_line) + 2);                (void) sprintf(buffer, "%s %s", prev->li_line,                        working->li_line + 1);                s = prev->li_line;                prev->li_line = buffer;                prev->li_next = working->li_next;                working->li_next = NULL;                if (prev->li_actual) {                    for (end = prev->li_actual;                        end->li_next; end = end->li_next)                        ;                    end->li_next = working;                    tfree(s);                } else {                    newcard = alloc(line);                    newcard->li_linenum = prev->li_linenum;                    newcard->li_line = s;                    newcard->li_next = working;                    prev->li_actual = newcard;                }                working = prev->li_next;                break;            default:                prev = working;                working = working->li_next;                break;        }    }    *data = cc;    return;}/* Do a listing. Use is listing [expanded] [logical] [physical] [deck] */voidcom_listing(wl)    wordlist *wl;{    int type = LS_LOGICAL;    bool expand = false;    char *s;    if (ft_curckt) {        while (wl) {            s = wl->wl_word;            switch (*s) {                case 'l':                case 'L':                    type = LS_LOGICAL;                    break;                case 'p':                case 'P':                    type = LS_PHYSICAL;                    break;                case 'd':                case 'D':                    type = LS_DECK;                    break;                case 'e':                case 'E':                    expand = true;                    break;                default:                    fprintf(cp_err,                    "Error: bad listing type %s\n", s);            }            wl = wl->wl_next;        }        if (type != LS_DECK)            fprintf(cp_out, "\t%s\n\n", ft_curckt->ci_name);        inp_list(cp_out, expand ? ft_curckt->ci_deck :                ft_curckt->ci_origdeck, ft_curckt->ci_options,                type);    } else        fprintf(cp_err, "Error: no circuit loaded.\n");    return;}static char *upper(string)    register char *string;{    static char buf[BSIZE];    register char *s;    s = buf;    while (*string) {#ifdef ASCIIQUOTE        /* Let's make this really idiot-proof. */        *s = strip(*string);        if ((*s < ' ') && (*s != '\t'))            *s = '_';   /* ? is bad since ? = help... */#endif        if (islower(*string))            *s = toupper(*string);        else            *s = *string;        string++;        s++;    }    *s = '\0';    return(buf);}/* Provide an input listing on the specified file of the given * card deck.  The listing should be of either LS_PHYSICAL or LS_LOGICAL * or LS_DECK lines as specified by the type parameter. */voidinp_list(file, deck, extras, type)    FILE *file;    struct line *deck, *extras;    int type;{    struct line *here;    struct line *there;    struct line *tmp, *next;    bool renumber;    bool useout = (file == cp_out);    int i = 1;/* gtri - wbk - 03/07/91 - Don't use 'more' type output if ipc enabled */    if(g_ipc.enabled) {        useout = FALSE;    }/* gtri - end - 03/07/91 */#ifdef notdef    /* splice extras into deck */    for (here = extras, extras = NULL, next = here->li_next;            here; here = next) {      for (there = deck; there; there = there->li_next) {    if (there->li_linenum < here->li_linenum &&        (!there->li_next ||        there->li_next->li_linenum > here->li_linenum)) {      tmp = there->li_next;      there->li_next = here;      here->li_next = tmp;      goto spliced;    }      }      /* left over */      if (extras) {    extras->li_next = here;      } else {    extras = here;      }      here->li_next = NULL;spliced: ;      /* dumb empty statement need */    }#endif    if (useout)        out_init();    (void) cp_getvar("renumber", VT_BOOL, (char *) &renumber);    if (type == LS_LOGICAL) {top1:       for (here = deck; here; here = here->li_next) {            if (renumber)                here->li_linenum = i;            i++;            if (ciprefix(".end", here->li_line) &&                    !isalpha(here->li_line[4]))                continue;            if (*here->li_line != '*') {                if (useout) {                    sprintf(out_pbuf, "%6d : %s\n",                            here->li_linenum,                            upper(here->li_line));            out_send(out_pbuf);/*                    out_printf("%6d : %s\n",                            here->li_linenum,                            upper(here->li_line)); */                } else                    fprintf(file, "%6d : %s\n",                            here->li_linenum,                            upper(here->li_line));                if (here->li_error) {                    if (useout) {                        out_printf("%s\n",                                here->li_error);                    } else                        fprintf(file, "%s\n",                            here->li_error, file);                }            }        }        if (extras) {            deck = extras;            extras = NULL;            goto top1;        }        if (useout) {/*            out_printf("%6d : .end\n", i); */            sprintf(out_pbuf, "%6d : .end\n", i);        out_send(out_pbuf);        } else            fprintf(file, "%6d : .end\n", i);    } else if ((type == LS_PHYSICAL) || (type == LS_DECK)) {top2:       for (here = deck; here; here = here->li_next) {            if ((here->li_actual == NULL) || (here == deck)) {                if (renumber)                    here->li_linenum = i;                i++;                if (ciprefix(".end", here->li_line) &&                        !isalpha(here->li_line[4]))                    continue;                if (type == LS_PHYSICAL) {                    if (useout) {

⌨️ 快捷键说明

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