21 static bool translate(
struct line*,
char*,
char*,
char*,
char*,
char*);
23 static bool settrans(
char*,
char*,
char*,
char*);
26 static void numrefs(
char*,
int*,
int*);
104 for (s = c->
li_line; *s && (*s !=
'('); s++)
107 while (s[0] && (s[1] !=
')')) {
118 for (s = c->
li_line; *s && !isspace(*s); s++)
123 while (s[0] && (s[1] !=
')')) {
141 fprintf(
cp_err,
"Error: unknown subckt: %s\n",
158 struct line *
c, *last, *lc, *lcc;
160 char *
s, *
t, *
tt, *scname, *subname;
161 int nest, numpasses =
MAXNEST, i;
166 struct subs *ts =
subs;
174 for (last = deck, lc =
NULL; last; ) {
176 fprintf(
cp_err,
"Error: misplaced %s card: %s\n",
sbend,
211 sss =
alloc(
struct subs);
223 while (isspace(s[i]))
227 while (s[i] && !isspace(s[i]))
249 for (sss = subs; sss; sss = sss->
su_next)
273 for (c = deck, lc =
NULL;
c; ) {
278 tmpscname = scname =
gettok(&s);
280 while ((*scname ==
' ') || (*scname ==
'\t') ||
286 while ((*s ==
' ') || (*s ==
'\t'))
288 while ((*s !=
' ') && (*s !=
'\t'))
291 for (sss = subs; sss; sss = sss->
su_next)
326 "Warning: empty subcircuit %s referenced, ignored\n",
377 }
while (numpasses-- && gotone);
380 fprintf(
cp_err,
"Error: infinite subckt recursion\n");
387 for (sss = subs; sss; sss =
subs) {
395 modnames = tmodnames;
411 char *formal, *actual, *scname, *subname, *instr;
414 char *buffer, *name, *
s, *
t, ch;
415 int nnodes, ndevs, i;
419 if (
settrans(formal, actual, subname, instr)) {
427 if (ch ==
'.' || ch ==
'*' || ch ==
'\0')
432 tmpname = name =
gettok(&s);
445 (void) sprintf(buffer,
"%c:%s:%s ", ch, scname, name);
447 (
void) sprintf(buffer,
"%c:%s ", ch, scname);
451 while (nnodes-- > 0) {
461 (void) sprintf(buffer + strlen(buffer),
"%s ", t);
463 (
void) sprintf(buffer + strlen(buffer),
464 "%s:%s ", scname, name);
467 while (ndevs-- > 0) {
468 tmpname = name =
gettok(&s);
479 (void) sprintf(buffer + strlen(buffer),
480 "%c:%s:%s ", ch, scname, name);
482 (
void) sprintf(buffer + strlen(buffer),
483 "%c:%s ", ch, scname);
489 finishLine(buffer + strlen(buffer), s, scname);
495 for (i = 0; i < 512; i++) {
524 if (((*src !=
'v') && (*src !=
'V') &&
525 (*src !=
'i') && (*src !=
'I')) ||
527 lastwasalpha = isalpha(*src);
531 for (s = src + 1; *s && isspace(*s); s++)
533 if (!*s || (*s !=
'(')) {
534 lastwasalpha = isalpha(*src);
539 which = *dst++ = *src;
542 while (isspace(*src))
545 *src && !isspace(*src) && *src !=
',' && (*src !=
')'); i++) {
550 if ((which ==
'v') || (which ==
'V'))
564 if (buf[0] ==
'v' || buf[0] ==
'V') {
572 for (s = scname; *s; )
575 for (s = buf + i; *s; )
581 if ((which ==
'v') || (which ==
'V')) {
582 while (*src && (isspace(*src) || *src ==
',')) {
585 if (*src && *src !=
')') {
586 for (i = 0; *src && !isspace(*src) && (*src !=
')'); i++)
596 for (s = scname; *s; )
612 char *formal, *actual, *subname, *instr;
621 fprintf(
cp_err,
"Error: too many params: %s\n", instr);
625 if (
eq(
table[i].t_new, subname))
628 fprintf(
cp_err,
"Error: too few params: %s\n", instr);
635 "Error: duplicate nodes given in subckt %s\n",subname);
671 return (
table[i].t_new);
688 while (*name && isspace(*name))
691 c = (isupper(*name) ? tolower(*name) : *name);
693 (void) strncpy(buf, name,
sizeof(buf));
699 while ((*s ==
' ') || (*s ==
'\t'))
701 while ((*s !=
' ') && (*s !=
'\t'))
704 for (sss = subs; sss; sss = sss->
su_next)
710 fprintf(
cp_err,
"Error: no such subcircuit: %s\n", s);
719 if (isalpha(c) && n == 0 && *devs == 0)
720 fprintf(
cp_err,
"Warning: unknown device key: %c\n", c);
726 for (s = buf, i = 0; *s && (i < n); i++)
733 fprintf(
cp_err,
"Error: too few nodes for %s\n", name);
739 for (wl = modnames; wl; wl = wl->
wl_next) {
759 char *buffer, *name, *
t;
769 buffer =
tmalloc(strlen(name) + strlen(t) +
770 strlen(subname) + 4);
771 (void) sprintf(buffer,
"%s ",name);
780 (void) sprintf(buffer + strlen(buffer),
"%s:%s ",
782 (void) strcat(buffer, t);
806 char *buffer, *name, *
t,
c;
807 int terms, devs, soft, hasmod;
809 for (s = deck; s; s = s->
li_next) {
811 while (*t && isspace(*t))
813 c = isupper(*t) ? tolower(*t) : *t;
819 buffer =
tmalloc(strlen(t) + strlen(subname) + 4);
825 copytok1(buffer + strlen(buffer),&t);
830 (void) strcat(buffer, t);
840 char **
t, *buffer, *subname;
846 if (**t ==
'\0')
return;
849 for (wlsub = submod; wlsub; wlsub = wlsub->
wl_next)
851 (void) sprintf(buffer + strlen(buffer),
"%s:%s ", subname, name);
856 (void) sprintf(buffer + strlen(buffer),
"%s ", name);
static struct subs * subs
static char buf[MAXPROMPT]
int copytok1(char *dst, char **s)
bool cp_getvar(char *n, int t, char *r)
static struct tab table[512]
struct line * inp_subcktexpand(struct line *deck)
struct line * inp_deckcopy()
static struct line * doit()
struct wordlist * wl_prev
static wordlist * modnames
static void devmodtranslate()
static bool modtranslate()
struct wordlist * wl_next