📄 subckt.c
字号:
{ buf[i] = *src++; } buf[i] = '\0'; if ((which == 'v') || (which == 'V')) s = gettrans(buf); else s = NULL; if (s) { while (*s) *dst++ = *s++; } else { /* * i(vname) -> i(v:subckt:name) * i(v:other:name) -> i(v:subckt:other:name) */ if (buf[0] == 'v' || buf[0] == 'V') { *dst++ = buf[0]; *dst++ = ':'; i = 1; } else { i = 0; } for (s = scname; *s; ) *dst++ = *s++; *dst++ = ':'; for (s = buf + i; *s; ) *dst++ = *s++; } /* translate the reference node, as in the "2" in "v(4,2)" */ if ((which == 'v') || (which == 'V')) { while (*src && (isspace(*src) || *src == ',')) { src++; } if (*src && *src != ')') { for (i = 0; *src && !isspace(*src) && (*src != ')'); i++) buf[i] = *src++; buf[i] = '\0'; s = gettrans(buf); *dst++ = ','; if (s) { while (*s) *dst++ = *s++; } else { for (s = scname; *s; ) *dst++ = *s++; *dst++ = ':'; for (s = buf; *s; ) *dst++ = *s++; } } } } return;}static struct tab { char *t_old; char *t_new;} table[512]; /* That had better be enough. */static intsettrans(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_new == NULL) { return -1; /* Too few actual / too many formal */ } else if (table[i].t_old == NULL) { if (eq(table[i].t_new, subname)) break; else return 1; /* Too many actual / too few formal */ } } return 0;}static char *gettrans(name) char *name;{ int i; if (eq(name, "0")) return (name); 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; struct subs *sss; char *s, *t, buf[4 * BSIZE_SP]; wordlist *wl; int n, i; while (*name && isspace(*name)) name++; c = (isupper(*name) ? tolower(*name) : *name); (void) strncpy(buf, name, sizeof(buf)); 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;{ while (*s && isspace(*s)) 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[4 * BSIZE_SP]; 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)) { gotone = true; t = c->li_line; name = gettok(&t); buffer = tmalloc(strlen(name) + strlen(t) + strlen(subname) + 4); (void) sprintf(buffer, "%s ",name); name = gettok(&t); wlsub = alloc(struct wordlist); wlsub->wl_next = submod; if (submod) submod->wl_prev = wlsub; submod = wlsub; wlsub->wl_word = name; (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); (void) strcat(buffer, t); tfree(c->li_line); c->li_line = buffer; t = c->li_line; (void) gettok(&t); wl = alloc(struct wordlist); wl->wl_next = modnames; if (modnames) modnames->wl_prev = wl; modnames = wl; wl->wl_word = gettok(&t); } } return(gotone);}static voiddevmodtranslate(deck, subname) struct line *deck; char *subname;{ struct line *s; char *buffer, *name, *t, c; wordlist *wlsub; bool found; for (s = deck; s; s = s->li_next) { t = s->li_line; while (*t && isspace(*t)) t++; c = isupper(*t) ? tolower(*t) : *t; found = false; buffer = tmalloc(strlen(t) + strlen(subname) + 4); switch (c) { case 'r': case 'c': name = gettok(&t); (void) sprintf(buffer,"%s ",name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); if (*t) { name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); } found = false; if (*t) { name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); } (void) strcat(buffer, t); tfree(s->li_line); s->li_line = buffer; break; case 'd': name = gettok(&t); (void) sprintf(buffer,"%s ",name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); (void) strcat(buffer, t); tfree(s->li_line); s->li_line = buffer; break; case 'w': case 'u': case 'j': case 'z': name = gettok(&t); (void) sprintf(buffer,"%s ",name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); (void) strcat(buffer, t); tfree(s->li_line); s->li_line = buffer; break; case 'o': case 's': case 'm': name = gettok(&t); (void) sprintf(buffer,"%s ",name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); (void) strcat(buffer, t); tfree(s->li_line); s->li_line = buffer; break; case 'q': name = gettok(&t); (void) sprintf(buffer,"%s ",name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); (void) sprintf(buffer + strlen(buffer), "%s ", name); name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); found = false; if (*t) { name = gettok(&t); /* Now, is this a subcircuit model? */ for (wlsub = submod; wlsub; wlsub = wlsub->wl_next) { if (eq(name, wlsub->wl_word)) { (void) sprintf(buffer + strlen(buffer), "%s:%s ", subname, name); found = true; break; } } if (!found) (void) sprintf(buffer + strlen(buffer), "%s ", name); } (void) strcat(buffer, t); tfree(s->li_line); s->li_line = buffer; break; default: tfree(buffer); break; } } return;}/* This is a spice-dependent thing. It should probably go somewhere * else, but... Note that we pretend that dependent sources and mutual * inductors have more nodes than they really do... */intinp_numnodes(c) char c;{ if (isupper(c)) c = tolower(c); switch (c) { case ' ': case '\t': case '.': case 'x': case '*': return (0); case 'b': return (2); case 'c': return (2); case 'd': return (2); case 'e': return (4); case 'f': return (2); case 'g': return (4); case 'h': return (2); case 'i': return (2); case 'j': return (3); case 'k': return (0); case 'l': return (2); case 'm': return (4); case 'o': return (4); case 'q': return (4); case 'r': return (2); case 's': return (4); case 't': return (4); case 'u': return (3); case 'v': return (2); case 'w': return (3); case 'z': return (3); default: fprintf(cp_err, "Warning: unknown device type: %c\n", c); return (2); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -