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

📄 subckt.c

📁 支持数字元件仿真的SPICE插件
💻 C
📖 第 1 页 / 共 3 页
字号:
    for (c = deck; c; c = c->li_next) {        /* Rename the device. */        switch (*c->li_line) {        case '\0':        case '*':        case '.':            /* Nothing any good here. */            continue;/* gtri - add - wbk - 10/23/90 - process A devices specially *//* since they have a more involved and variable length node syntax */        case 'a':        case 'A':            /* translate the instance name according to normal rules */            buffer = tmalloc(10000);     /* XXXXX */            s = c->li_line;            name = MIFgettok(&s);            sprintf(buffer, "%s:%s ", name, scname);            /* Now translate the nodes, looking ahead one token to recognize */            /* when we reach the model name which should not be translated   */            /* here.                                                         */            next_name = MIFgettok(&s);            while(1) {                /* rotate the tokens and get the the next one */                name = next_name;                next_name = MIFgettok(&s);                /* if next token is NULL, name holds the model name, so exit */                if(next_name == NULL)                    break;                /* Process the token in name.  If it is special, then don't */                /* translate it.                                            */                switch(*name) {                case '[':                case ']':                case '~':                    sprintf(buffer + strlen(buffer), "%s ", name);                    break;                case '%':                    sprintf(buffer + strlen(buffer), "%%");                    /* don't translate the port type identifier */                    name = next_name;                    next_name = MIFgettok(&s);                    sprintf(buffer + strlen(buffer), "%s ", name);                    break;                default:                    /* must be a node name at this point, so translate it */                    t = gettrans(name);                    if (t)                        sprintf(buffer + strlen(buffer), "%s ", t);                    else                        sprintf(buffer + strlen(buffer), "%s:%s ", name, scname);                    break;                } /* switch */            } /* while */            /* copy in the last token, which is the model name */            if(name)                sprintf(buffer + strlen(buffer), "%s ", name);            /* Set s to null string for compatibility with code */            /* after switch statement                           */            s = "";            break;/* gtri - end - wbk - 10/23/90 */        default:                s = c->li_line;            name = gettok(&s);/* gtri - modify - wbk - 4/10/91 - change way pathnames are built *//* reverse order so that innermost name is now first *//*            ch = *name;            buffer = tmalloc(10000);            name++;            if (*name == ':')            name++;            if (*name)                (void) sprintf(buffer, "%c:%s:%s ", ch, scname,                    name);            else                (void) sprintf(buffer, "%c:%s ", ch, scname);*/            buffer = tmalloc(10000);    /* XXXXX */            (void) sprintf(buffer, "%s:%s ", name, scname);/* gtri - end - wbk - 4/10/91 - change way pathnames are built */            nnodes = numnodes(c->li_line);            while (nnodes-- > 0) {            name = gettok(&s);            if (name == NULL) {                fprintf(cp_err, "Warning: too few nodes: %s\n",                        c->li_line);                return;            }            t = gettrans(name);            if (t)                (void) sprintf(buffer + strlen(buffer), "%s ",                        t);            else/* gtri - modify - wbk - 4/10/91 - change way pathnames are built *//* reverse order so that innermost name is now first *//*                (void) sprintf(buffer + strlen(buffer),                        "%s:%s ", scname, name);*/                (void) sprintf(buffer + strlen(buffer),                        "%s:%s ", name, scname);/* gtri - end - wbk - 4/10/91 - change way pathnames are built */            }                nnodes = numdevs(c->li_line);            while (nnodes-- > 0) {            name = gettok(&s);            if (name == NULL) {                fprintf(cp_err, "Warning: too few devs: %s\n",                        c->li_line);                return;            }/* gtri - modify - wbk - 4/10/91 - change way pathnames are built *//* reverse order so that innermost name is now first *//*            ch = *name;            name++;            if (*name == ':')                name++;            if (*name)                (void) sprintf(buffer + strlen(buffer),                        "%c:%s:%s ", ch, scname, name);            else                (void) sprintf(buffer + strlen(buffer),                        "%c:%s ", ch, scname);*/            (void) sprintf(buffer + strlen(buffer),                    "%s:%s ", name, scname);/* gtri - end - wbk - 4/10/91 - change way pathnames are built */            }            /* Now scan through the line for v(something) and             * i(something)...             */            finishLine(buffer + strlen(buffer), s, scname);            s = "";        }            (void) strcat(buffer, s);        tfree(c->li_line);        c->li_line = copy(buffer);        tfree(buffer);    }    return;}static voidfinishLine(dst, src, scname)    char *dst;    char *src;    char *scname;{    char buf[BSIZE], which;    char *s;    int i;    while (*src) {        /* Find the next instance of "<non-alpha>[vi]<opt spaces>(" in         * this string.         */        if (((*src != 'v') && (*src != 'V') &&                (*src != 'i') && (*src != 'I')) ||                isalpha(src[-1])) {            *dst++ = *src++;            continue;        }        for (s = src + 1; *s && isspace(*s); s++)            ;        if (!*s || (*s != '(')) {            *dst++ = *src++;            continue;        }        which = *dst++ = *src;        src = s;        *dst++ = *src++;        while (isspace(*src))            src++;        for (i = 0; *src && !isspace(*src) && (*src != ')'); i++)            buf[i] = *src++;        buf[i] = '\0';printf("which = %c, buf = '%s'\n", which, buf);        if ((which == 'v') || (which == 'V'))            s = gettrans(buf);        else            s = NULL;        if (s) {            while (*s)                *dst++ = *s++;        } else {/* gtri - modify - wbk - 4/10/91 - change way pathnames are built *//* reverse order of building pathnames so innermost is always first *//*            for (s = scname; *s; )                *dst++ = *s++;            *dst++ = ':';            for (s = buf; *s; )                *dst++ = *s++;*/            for (s = buf; *s; )                *dst++ = *s++;            *dst++ = ':';            for (s = scname; *s; )                *dst++ = *s++;/* gtri - end - wbk - 4/10/91 - change way pathnames are built */        }    }    return;}static struct tab {    char *t_old;    char *t_new;} table[512];   /* That had better be enough. */static voidsettrans(formal, actual, subname)    char *formal, *actual, *subname;{    int i;    for (i = 0; ; i++) {        table[i].t_old = gettok(&formal);        table[i].t_new = gettok(&actual);        if ((table[i].t_old == NULL) && eq(table[i].t_new, subname))            break;        if ((table[i].t_old == NULL) || (table[i].t_new == NULL)) {            fprintf(cp_err,             "settrans: Internal Error: wrong number of params\n");            return;        }    }    return;}static char *gettrans(name)    char *name;{    int i;    if (eq(name, "0"))        return (name);/* gtri - wbk - 2/27/91 - don't translate the reserved word 'null' */    if (eq(name, "null"))        return (name);/* gtri - end */    for (i = 0; table[i].t_old; i++)        if (eq(table[i].t_old, name))            return (table[i].t_new);    return (NULL);}static intnumnodes(name)    char *name;{    char c = (isupper(*name) ? tolower(*name) : *name);    struct subs *sss;    char *s, *t, buf[BSIZE];    wordlist *wl;    int n, i;    (void) strncpy(buf, name, BSIZE);    s = buf;    if (c == 'x') {     /* Handle this ourselves. */        while(*s)            s++;        s--;        while ((*s == ' ') || (*s == '\t'))            *s-- = '\0';        while ((*s != ' ') && (*s != '\t'))            s--;        s++;        for (sss = subs; sss; sss = sss->su_next)            if (eq(sss->su_name, s))                break;        if (!sss) {            fprintf(cp_err, "Error: no such subcircuit: %s\n", s);            return (0);        }        return (sss->su_numargs);    }    n = inp_numnodes(c);    if (nobjthack || (c != 'q'))        return (n);    for (s = buf, i = 0; *s && (i < 4); i++)        (void) gettok(&s);    if (i == 3)        return (3);    else if (i < 4) {        fprintf(cp_err, "Error: too few nodes for BJT: %s\n", name);        return (0);    }    /* Now, is this a model? */    t = gettok(&s);    for (wl = modnames; wl; wl = wl->wl_next)        if (eq(t, wl->wl_word))            return (3);    return (4);}static int numdevs(s)    char *s;{    switch (*s) {        case 'K':        case 'k':        return (2);            case 'F':        case 'f':        case 'H':        case 'h':        return (1);            default:        return (0);    }}static boolmodtranslate(deck, subname)    struct line *deck;    char *subname;{    struct line *c;    char *buffer, *name, *t, model[BSIZE];    wordlist *wl, *wlsub;    bool gotone;    (void) strcpy(model, ".model");    gotone = false;    for (c = deck; c; c = c->li_next) {        if (prefix(model, c->li_line)) {

⌨️ 快捷键说明

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