📄 subckt.c
字号:
/* Process the token in name. If it is special, then don't */ /* translate it. */ switch(*name) { case '[': case ']': case '~': blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(name)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", name); break; case '%': blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+2)*sizeof(char)); sprintf(buffer + blen, "%%"); /* don't translate the port type identifier */ name = next_name; next_name = MIFgettok(&s); blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(name)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", name); break; default: /* must be a node name at this point, so translate it */ t = gettrans(name); if (t) { blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(t)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", t); } else { /* maschmann: changed order sprintf(buffer + strlen(buffer), "%s:%s ", name, scname); */ if(name[0]=='v' || name[0]=='V') { blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+5)*sizeof(char)); sprintf(buffer + blen, "v:%s:%s ", scname, name+1); } else { blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+3)*sizeof(char)); sprintf(buffer + blen, "%s:%s ", scname, name); } } break; } /* switch */ } /* while */ /* copy in the last token, which is the model name */ if(name) { blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(name)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", name); } /* Set s to null string for compatibility with code */ /* after switch statement */ s = ""; break;/* gtri - end - wbk - 10/23/90 */#endif/*================ case E, F, G, H ================*//* This section handles controlled sources and allows for SPICE2 POLY attributes. * This is a new section, added by SDB to handle POLYs in sources. Significant * changes were made in here. * 4.21.2003 -- SDB. mailto:sdb@cloud9.net */ case 'E': case 'e': case 'F': case 'f': case 'G': case 'g': case 'H': case 'h': s = c->li_line; /* s now holds the SPICE line */ t = name = gettok(&s); /* name points to the refdes */ if (!name) continue; if (!*name) { tfree(name); continue; } /* Here's where we translate the refdes to e.g. F:subcircuitname:57 * and stick the translated name into buffer. */ ch = *name; /* ch identifies the type of component */ name++; if (*name == ':') name++; /* now name point to the rest of the refdes */ if (*name) { buffer = (char *)tmalloc((strlen(scname)+strlen(name)+5)*sizeof(char)); sprintf(buffer, "%c:%s:%s ", ch, scname, /* F:subcircuitname:refdesname */ name); } else { buffer = (char *)tmalloc((strlen(scname)+4)*sizeof(char)); sprintf(buffer, "%c:%s ", ch, scname); /* F:subcircuitname */ } tfree(t); /* Next iterate over all nodes (netnames) found and translate them. */ nnodes = numnodes(c->li_line); while (nnodes-- > 0) { name = gettok_node(&s); if (name == NULL) { fprintf(cp_err, "Error: too few nodes: %s\n", c->li_line); goto quit; } /* call gettrans and see if netname was used in the invocation */ t = gettrans(name); if (t) { /* the netname was used during the invocation; print it into the buffer */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(t)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", t); } else { /* net netname was not used during the invocation; place a * translated name into the buffer. */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+3)*sizeof(char)); sprintf(buffer + blen, "%s:%s ", scname, name); } tfree(name); } /* while (nnodes-- . . . . */ /* Next we handle the POLY (if any) */ /* get next token */ t = s; next_name = (char *)gettok_noparens(&t); if ( (strcmp(next_name, "POLY") == 0) || (strcmp(next_name, "poly") == 0)) { /* found POLY . . . . */#ifdef TRACE /* SDB debug statement */ printf("In translate, looking at e, f, g, h found poly\n");#endif /* move pointer ahead of ( */ if( get_l_paren(&s) == 1 ) { fprintf(cp_err, "Error: no left paren after POLY %s\n", c->li_line); tfree(next_name); goto quit; } nametofree = gettok_noparens(&s); dim = atoi(nametofree); /* convert returned string to int */ tfree(nametofree); /* move pointer ahead of ) */ if( get_r_paren(&s) == 1 ) { fprintf(cp_err, "Error: no right paren after POLY %s\n", c->li_line); tfree(next_name); goto quit; } /* Write POLY(dim) into buffer */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+17)*sizeof(char)); sprintf(buffer + blen, "POLY( %d ) ", dim); } /* if ( (strcmp(next_name, "POLY") == 0) . . . */ else dim = 1; /* only one controlling source . . . */ tfree(next_name);/* Now translate the controlling source/nodes */ nnodes = dim * numdevs(c->li_line); while (nnodes-- > 0) { nametofree = name = gettok_node(&s); /* name points to the returned token */ if (name == NULL) { fprintf(cp_err, "Error: too few devs: %s\n", c->li_line); goto quit; } if ( (dev_type == 'f') || (dev_type == 'F') || (dev_type == 'h') || (dev_type == 'H') ) { /* Handle voltage source name */#ifdef TRACE /* SDB debug statement */ printf("In translate, found type f or h\n");#endif ch = *name; /* ch is the first char of the token. */ name++; if (*name == ':') name++; /* name now points to the remainder of the token */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+5)*sizeof(char)); sprintf(buffer + blen, "%c:%s:%s ", ch, scname, name); /* From Vsense and Urefdes creates V:Urefdes:sense */ } else { /* Handle netname */#ifdef TRACE /* SDB debug statement */ printf("In translate, found type e or g\n");#endif /* call gettrans and see if netname was used in the invocation */ t = gettrans(name); if (t) { /* the netname was used during the invocation; print it into the buffer */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(t)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", t); } else { /* net netname was not used during the invocation; place a * translated name into the buffer. */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+3)*sizeof(char)); sprintf(buffer + blen, "%s:%s ", scname, name); /* From netname and Urefdes creates Urefdes:netname */ } } tfree(nametofree); } /* while (nnodes--. . . . */ /* Now write out remainder of line (polynomial coeffs) */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(s)+strlen(scname)+1000)*sizeof(char)); finishLine(buffer + blen, s, scname); s = ""; break;/*================= Default case ===================*/ default: /* this section handles ordinary components */ s = c->li_line; nametofree = name = gettok_node(&s); /* changed to gettok_node to handle netlists with ( , ) */ if (!name) continue; if (!*name) { tfree(name); continue; }/* Here's where we translate the refdes to e.g. R:subcircuitname:57 * and stick the translated name into buffer. */ ch = *name; name++; if (*name == ':') name++; if (*name) { buffer = (char *)tmalloc((strlen(scname)+strlen(name)+5)*sizeof(char)); sprintf(buffer, "%c:%s:%s ", ch, scname, name); } else { buffer = (char *)tmalloc((strlen(scname)+4)*sizeof(char)); sprintf(buffer, "%c:%s ", ch, scname); } tfree(nametofree);/* Next iterate over all nodes (netnames) found and translate them. */ nnodes = numnodes(c->li_line); while (nnodes-- > 0) { name = gettok_node(&s); if (name == NULL ) { fprintf(cp_err, "Error: too few nodes: %s\n", c->li_line); goto quit; } /* call gettrans and see if netname was used in the invocation */ t = gettrans(name); if (t) { /* the netname was used during the invocation; print it into the buffer */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(t)+2)*sizeof(char)); sprintf(buffer + blen, "%s ", t); } else { /* net netname was not used during the invocation; place a * translated name into the buffer. */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+3)*sizeof(char)); sprintf(buffer + blen, "%s:%s ", scname, name); } tfree(name); } /* while (nnodes-- . . . . */ /* Now translate any devices (i.e. controlling sources). * This may be superfluous because we handle dependent * source devices above . . . . */ nnodes = numdevs(c->li_line); while (nnodes-- > 0) { t = name = gettok_node(&s); if (name == NULL) { fprintf(cp_err, "Error: too few devs: %s\n", c->li_line); goto quit; } ch = *name; name++; if (*name == ':') name++; if (*name) { blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+strlen(name)+5)*sizeof(char)); sprintf(buffer + blen, "%c:%s:%s ", ch, scname, name); } else { blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(scname)+4)*sizeof(char)); sprintf(buffer + blen, "%c:%s ", ch, scname); } tfree(t); } /* while (nnodes--. . . . */ /* Now we finish off the line. For most components (R, C, etc), * this involves adding the component value to the buffer. * We also scan through the line for v(something) and * i(something)... */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(s)+strlen(scname)+1000)*sizeof(char)); finishLine(buffer + blen, s, scname); s = ""; } /* switch(c->li_line . . . . */ blen = strlen(buffer); buffer = (char *)trealloc(buffer, (blen+strlen(s)+1)*sizeof(char)); strcat(buffer, s); tfree(c->li_line); c->li_line = copy(buffer);#ifdef TRACE /* SDB debug statement */ printf("In translate, translated line = %s \n", c->li_line);#endif tfree(buffer); } /* for (c = deck . . . . */ rtn = 1;quit: for (i = 0; ; i++) { if(!table[i].t_old && !table[i].t_new) break; FREE(table[i].t_old); FREE(table[i].t_new); } return rtn;}/*-------------------------------------------------------------------*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -