From c4e2e82d427323c20c477563ed4ca723260d3f43 Mon Sep 17 00:00:00 2001 From: arno Date: Thu, 25 May 2000 20:25:40 +0000 Subject: [PATCH] * ifeval.c ifnewuid.c inp.h inp2b.c inp2c.c inp2d.c inp2e.c inp2f.c inp2g.c inp2h.c inp2i.c inp2j.c inp2k.c inp2l.c inp2m.c inp2o.c inp2q.c inp2r.c inp2s.c inp2t.c inp2u.c inp2v.c inp2w.c inp2z.c inpaname.c inpapnam.c inpcfix.c inpdomod.c inpdpar.c inperrc.c inperror.c inpeval.c inpfindl.c inpgmod.c inpgstr.c inpgtitl.c inpgtok.c inpgval.c inpkmods.c inplist.c inplkmod.c inpmkmod.c inpmktmp.c inppas1.c inppas2.c inppname.c inpptree.c inpsymt.c inptyplk.c ptfuncs.c: Cosmetic updates. * sperror.c: Removed clutter and MALLOC() call. * Makefile.am inp2dot.c inpdoopt.c: Paolo commented out all of inpdoopt.c, I removed it from the repository. Updated inp2dot.c and Makefile.am as well. --- src/circuit/Makefile.am | 1 - src/circuit/ifeval.c | 80 +-- src/circuit/ifnewuid.c | 97 ++-- src/circuit/inp.h | 2 - src/circuit/inp2b.c | 59 +- src/circuit/inp2c.c | 133 ++--- src/circuit/inp2d.c | 104 ++-- src/circuit/inp2dot.c | 1058 +++++++++++++++++----------------- src/circuit/inp2e.c | 89 ++- src/circuit/inp2f.c | 75 ++- src/circuit/inp2g.c | 89 ++- src/circuit/inp2h.c | 75 ++- src/circuit/inp2i.c | 69 ++- src/circuit/inp2j.c | 121 ++-- src/circuit/inp2k.c | 59 +- src/circuit/inp2l.c | 69 ++- src/circuit/inp2m.c | 147 +++-- src/circuit/inp2o.c | 126 ++-- src/circuit/inp2q.c | 134 ++--- src/circuit/inp2r.c | 149 ++--- src/circuit/inp2s.c | 120 ++-- src/circuit/inp2t.c | 81 ++- src/circuit/inp2u.c | 106 ++-- src/circuit/inp2v.c | 73 ++- src/circuit/inp2w.c | 108 ++-- src/circuit/inp2z.c | 116 ++-- src/circuit/inpaname.c | 66 ++- src/circuit/inpapnam.c | 20 +- src/circuit/inpcfix.c | 13 +- src/circuit/inpdomod.c | 439 +++++++------- src/circuit/inpdoopt.c | 84 --- src/circuit/inpdpar.c | 84 +-- src/circuit/inperrc.c | 35 +- src/circuit/inperror.c | 10 +- src/circuit/inpeval.c | 293 +++++----- src/circuit/inpfindl.c | 85 +-- src/circuit/inpgmod.c | 161 +++--- src/circuit/inpgstr.c | 107 ++-- src/circuit/inpgtitl.c | 11 +- src/circuit/inpgtok.c | 212 ++++--- src/circuit/inpgval.c | 93 +-- src/circuit/inpkmods.c | 18 +- src/circuit/inplist.c | 52 +- src/circuit/inplkmod.c | 16 +- src/circuit/inpmkmod.c | 20 +- src/circuit/inpmktmp.c | 16 +- src/circuit/inppas1.c | 17 +- src/circuit/inppas2.c | 223 ++++---- src/circuit/inppname.c | 43 +- src/circuit/inpptree.c | 1208 ++++++++++++++++++++------------------- src/circuit/inpsymt.c | 371 ++++++------ src/circuit/inptyplk.c | 14 +- src/circuit/ptfuncs.c | 105 ++-- src/circuit/sperror.c | 202 +++---- 54 files changed, 3703 insertions(+), 3655 deletions(-) delete mode 100644 src/circuit/inpdoopt.c diff --git a/src/circuit/Makefile.am b/src/circuit/Makefile.am index 41630a607..61da8e94f 100644 --- a/src/circuit/Makefile.am +++ b/src/circuit/Makefile.am @@ -31,7 +31,6 @@ libinp_a_SOURCES = \ inpapnam.c \ inpcfix.c \ inpdomod.c \ - inpdoopt.c \ inpdpar.c \ inperrc.c \ inperror.c \ diff --git a/src/circuit/ifeval.c b/src/circuit/ifeval.c index 54aa5b008..73f796c68 100644 --- a/src/circuit/ifeval.c +++ b/src/circuit/ifeval.c @@ -17,15 +17,17 @@ Author: 1985 Thomas L. Quarles extern double PTfudge_factor; -static int PTeval(INPparseNode *tree, double gmin, double *res, double *vals); +static int PTeval(INPparseNode * tree, double gmin, double *res, + double *vals); int -IFeval(IFparseTree *tree, double gmin, double *result, double *vals, double *derivs) +IFeval(IFparseTree * tree, double gmin, double *result, double *vals, + double *derivs) { int i, err; - INPparseTree *myTree = (INPparseTree*) tree;; + INPparseTree *myTree = (INPparseTree *) tree;; /* INPptPrint("calling PTeval, tree = ", myTree); @@ -35,11 +37,11 @@ printf("\tvar%d = %lg\n", i, vals[i]); */ if ((err = PTeval(myTree->tree, gmin, result, vals)) != OK) - return (err); + return (err); for (i = 0; i < myTree->p.numVars; i++) - if ((err = PTeval(myTree->derivs[i], gmin, &derivs[i], vals)) != OK) - return (err); + if ((err = PTeval(myTree->derivs[i], gmin, &derivs[i], vals)) != + OK) return (err); /* printf("results: function = %lg\n", *result); @@ -51,7 +53,7 @@ printf("\td / d var%d = %lg\n", i, derivs[i]); } static int -PTeval(INPparseNode *tree, double gmin, double *res, double *vals) +PTeval(INPparseNode * tree, double gmin, double *res, double *vals) { double r1, r2; int err; @@ -59,50 +61,48 @@ PTeval(INPparseNode *tree, double gmin, double *res, double *vals) PTfudge_factor = gmin; switch (tree->type) { case PT_CONSTANT: - *res = tree->constant; - break; + *res = tree->constant; + break; case PT_VAR: - *res = vals[tree->valueIndex]; - break; - + *res = vals[tree->valueIndex]; + break; + case PT_FUNCTION: - err = PTeval(tree->left, gmin, &r1, vals); - if (err != OK) - return (err); - *res = (*tree->function)(r1); - if (*res == HUGE) { - fprintf(stderr, "Error: %g out of range for %s\n", - r1, tree->funcname); - return (E_PARMVAL); - } - break; + err = PTeval(tree->left, gmin, &r1, vals); + if (err != OK) + return (err); + *res = (*tree->function) (r1); + if (*res == HUGE) { + fprintf(stderr, "Error: %g out of range for %s\n", + r1, tree->funcname); + return (E_PARMVAL); + } + break; case PT_PLUS: case PT_MINUS: case PT_TIMES: case PT_DIVIDE: case PT_POWER: - err = PTeval(tree->left, gmin, &r1, vals); - if (err != OK) - return (err); - err = PTeval(tree->right, gmin, &r2, vals); - if (err != OK) - return (err); - *res = (*tree->function)(r1, r2); - if (*res == HUGE) { - fprintf(stderr, "Error: %g, %g out of range for %s\n", - r1, r2, tree->funcname); - return (E_PARMVAL); - } - break; - + err = PTeval(tree->left, gmin, &r1, vals); + if (err != OK) + return (err); + err = PTeval(tree->right, gmin, &r2, vals); + if (err != OK) + return (err); + *res = (*tree->function) (r1, r2); + if (*res == HUGE) { + fprintf(stderr, "Error: %g, %g out of range for %s\n", + r1, r2, tree->funcname); + return (E_PARMVAL); + } + break; + default: - fprintf(stderr, "Internal Error: bad node type %d\n", - tree->type); - return (E_PANIC); + fprintf(stderr, "Internal Error: bad node type %d\n", tree->type); + return (E_PANIC); } return (OK); } - diff --git a/src/circuit/ifnewuid.c b/src/circuit/ifnewuid.c index 366775126..08465f21e 100644 --- a/src/circuit/ifnewuid.c +++ b/src/circuit/ifnewuid.c @@ -14,69 +14,72 @@ Author: 1988 Thomas L. Quarles int -IFnewUid(void *ckt, IFuid *newuid, IFuid olduid, char *suffix, int type, void **nodedata) +IFnewUid(void *ckt, IFuid * newuid, IFuid olduid, char *suffix, int type, + void **nodedata) { char *newname; int error; - if(olduid) { - newname=(char *) - MALLOC(sizeof(char)*(strlen(suffix)+strlen((char*)olduid)+2)); - /* 2 = '#' + '\0' */ - sprintf(newname,"%s#%s",(char*)olduid,suffix); + if (olduid) { + newname = (char *) + MALLOC(sizeof(char) * + (strlen(suffix) + strlen((char *) olduid) + 2)); + /* 2 = '#' + '\0' */ + sprintf(newname, "%s#%s", (char *) olduid, suffix); } else { - newname=(char *)MALLOC(sizeof(char)* - (strlen(suffix)+1)); /* 1 = '\0' */ - sprintf(newname,"%s",suffix); + newname = (char *) MALLOC(sizeof(char) * (strlen(suffix) + 1)); /* 1 = '\0' */ + sprintf(newname, "%s", suffix); } - switch(type) { - case UID_ANALYSIS: - case UID_TASK: - case UID_INSTANCE: - case UID_OTHER: - case UID_MODEL: - error = INPinsert(&newname, - (INPtables *)ft_curckt->ci_symtab); - if(error && error != E_EXISTS) return(error); - *newuid = (IFuid) newname; - break; + switch (type) { + case UID_ANALYSIS: + case UID_TASK: + case UID_INSTANCE: + case UID_OTHER: + case UID_MODEL: + error = INPinsert(&newname, (INPtables *) ft_curckt->ci_symtab); + if (error && error != E_EXISTS) + return (error); + *newuid = (IFuid) newname; + break; - case UID_SIGNAL: - error = INPmkTerm(ckt,&newname, - (INPtables *)ft_curckt->ci_symtab,nodedata); - if(error && error != E_EXISTS) return(error); - *newuid = (IFuid) newname; - break; + case UID_SIGNAL: + error = INPmkTerm(ckt, &newname, + (INPtables *) ft_curckt->ci_symtab, nodedata); + if (error && error != E_EXISTS) + return (error); + *newuid = (IFuid) newname; + break; - default: - return(E_BADPARM); + default: + return (E_BADPARM); } - return(OK); + return (OK); } -int -IFdelUid(void *ckt, IFuid uid, int type) +int IFdelUid(void *ckt, IFuid uid, int type) { int error; - switch(type) { - case UID_ANALYSIS: - case UID_TASK: - case UID_INSTANCE: - case UID_OTHER: - case UID_MODEL: - error = INPremove(uid, (INPtables *)ft_curckt->ci_symtab); - if(error && error != E_EXISTS) return(error); - break; + switch (type) { + case UID_ANALYSIS: + case UID_TASK: + case UID_INSTANCE: + case UID_OTHER: + case UID_MODEL: + error = INPremove(uid, (INPtables *) ft_curckt->ci_symtab); + if (error && error != E_EXISTS) + return (error); + break; - case UID_SIGNAL: - error = INPremTerm(uid, (INPtables *)ft_curckt->ci_symtab); - if(error && error != E_EXISTS) return(error); - break; + case UID_SIGNAL: + error = INPremTerm(uid, (INPtables *) ft_curckt->ci_symtab); + if (error && error != E_EXISTS) + return (error); + break; - default: - return(E_BADPARM); + default: + return (E_BADPARM); } - return(OK); + return (OK); } diff --git a/src/circuit/inp.h b/src/circuit/inp.h index 0edacf41c..9d17b7bda 100644 --- a/src/circuit/inp.h +++ b/src/circuit/inp.h @@ -122,6 +122,4 @@ double PTuminus(double arg); /* sperror.c */ -char * SPerror(int type); - #endif diff --git a/src/circuit/inp2b.c b/src/circuit/inp2b.c index df61af1dd..967393ebd 100644 --- a/src/circuit/inp2b.c +++ b/src/circuit/inp2b.c @@ -11,49 +11,48 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2B(void *ckt, INPtables *tab, card *current) +void INP2B(void *ckt, INPtables * tab, card * current) { /* Bname [V=expr] [I=expr] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model name */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model name */ /* Arbitrary source. */ type = INPtypelook("ASRC"); if (type < 0) { - LITERR("Device type Asource not supported by this binary\n") - return; + LITERR("Device type Asource not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); - INPgetTok(&line,&nname1,1); - error = INPtermInsert(ckt,&nname1,tab,&node1); + INPgetTok(&line, &nname1, 1); + error = INPtermInsert(ckt, &nname1, tab, &node1); - INPgetTok(&line,&nname2,1); - error = INPtermInsert(ckt,&nname2,tab,&node2); + INPgetTok(&line, &nname2, 1); + error = INPtermInsert(ckt, &nname2, tab, &node2); - if(!tab->defBmod) { - /* create default B model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"B",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defBmod),uid)) + if (!tab->defBmod) { + /* create default B model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "B", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defBmod), uid)) } - IFC(newInstance,(ckt,tab->defBmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) + IFC(newInstance, (ckt, tab->defBmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) } diff --git a/src/circuit/inp2c.c b/src/circuit/inp2c.c index e5ba57c40..d0327b4c0 100644 --- a/src/circuit/inp2c.c +++ b/src/circuit/inp2c.c @@ -11,81 +11,82 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2C(void *ckt, INPtables *tab, card *current) +void INP2C(void *ckt, INPtables * tab, card * current) { /* parse a capacitor card */ /* Cname [IC=] */ -int mytype; /* the type we determine resistors are */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *model; /* the name of the resistor's model */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -double val; /* temp to held resistance */ -int error; /* error code temporary */ -INPmodel *thismodel; /* pointer to model structure describing our model */ -void *mdfast; /* pointer to the actual model */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default cap model */ + int mytype; /* the type we determine resistors are */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *model; /* the name of the resistor's model */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + double val; /* temp to held resistance */ + int error; /* error code temporary */ + INPmodel *thismodel; /* pointer to model structure describing our model */ + void *mdfast; /* pointer to the actual model */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default cap model */ mytype = INPtypelook("Capacitor"); - if(mytype < 0 ) { - LITERR("Device type Capacitor not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type Capacitor not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - val = INPevaluate(&line,&error,1); - if(error == 0) { /* Looks like a number */ - type = mytype; - ptemp.rValue = val; - if(!tab->defCmod) { - IFnewUid(ckt,&uid,(IFuid)NULL,"C",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defCmod),uid)) - } - IFC(newInstance,(ckt,tab->defCmod,&fast,name)) - GCA(INPpName,("capacitance",&ptemp,ckt,type,fast)) - } else { /* looks like character strings */ - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - thismodel = (INPmodel *)NULL; - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = thismodel->INPmodfast; - } else { - type = mytype; - if(!tab->defCmod) { - IFnewUid(ckt,&uid,(IFuid)NULL,"C",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defCmod),uid)) - } - mdfast = tab->defCmod; - } - IFC(newInstance,(ckt,mdfast,&fast,name)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + val = INPevaluate(&line, &error, 1); + if (error == 0) { /* Looks like a number */ + type = mytype; + ptemp.rValue = val; + if (!tab->defCmod) { + IFnewUid(ckt, &uid, (IFuid) NULL, "C", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defCmod), uid)) + } + IFC(newInstance, (ckt, tab->defCmod, &fast, name)) + GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast)) + } else { /* looks like character strings */ + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + thismodel = (INPmodel *) NULL; + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = thismodel->INPmodfast; + } else { + type = mytype; + if (!tab->defCmod) { + IFnewUid(ckt, &uid, (IFuid) NULL, "C", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defCmod), uid)) + } + mdfast = tab->defCmod; + } + IFC(newInstance, (ckt, mdfast, &fast, name)) } - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("capacitance",&ptemp,ckt,type,fast)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("capacitance", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2d.c b/src/circuit/inp2d.c index ace8c2343..a62944501 100644 --- a/src/circuit/inp2d.c +++ b/src/circuit/inp2d.c @@ -11,67 +11,67 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2D(void *ckt, INPtables *tab, card *current) +void INP2D(void *ckt, INPtables * tab, card * current) { /* Dname [] [OFF] [IC=] */ -int mytype; /* the type we looked up */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* the name of the model */ -INPmodel *thismodel; /* pointer to model description for user's model */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid of default model */ + int mytype; /* the type we looked up */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* the name of the model */ + INPmodel *thismodel; /* pointer to model description for user's model */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid of default model */ mytype = INPtypelook("Diode"); - if(mytype < 0 ) { - LITERR("Device type Diode not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type Diode not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = (thismodel->INPmodfast); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = (thismodel->INPmodfast); } else { - type = mytype; - if(!tab->defDmod) { - /* create default D model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"D",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defDmod),uid)) - } - mdfast = tab->defDmod; + type = mytype; + if (!tab->defDmod) { + /* create default D model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "D", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defDmod), uid)) + } + mdfast = tab->defDmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("area",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("area", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2dot.c b/src/circuit/inp2dot.c index 45e946c7b..f4da71ec9 100644 --- a/src/circuit/inp2dot.c +++ b/src/circuit/inp2dot.c @@ -11,130 +11,132 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" + int INP2dot(void *ckt, INPtables *tab, card *current, void *task, void *gnode) { /* . Many possibilities */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *point; -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -IFvalue ptemp; /* a value structure to package resistance into */ -IFvalue *parm; /* a pointer to a value struct for function returns */ -IFparm *prm; /* pointer to parameter to search through array */ -char *token; /* a token from the line */ -int which; /* which analysis we are performing */ -int found; -int i; /* generic loop variable */ -void *foo; /* pointer to analysis */ -int length; /* length of a name */ -char *steptype; /* ac analysis, type of stepping function */ -double dtemp; /* random double precision temporary */ -char *word; /* something to stick a word of input into */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *point; + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + IFvalue ptemp; /* a value structure to package resistance into */ + IFvalue *parm; /* a pointer to a value struct for function returns */ + IFparm *prm; /* pointer to parameter to search through array */ + char *token; /* a token from the line */ + int which; /* which analysis we are performing */ + int found; + int i; /* generic loop variable */ + void *foo; /* pointer to analysis */ + int length; /* length of a name */ + char *steptype; /* ac analysis, type of stepping function */ + double dtemp; /* random double precision temporary */ + char *word; /* something to stick a word of input into */ line = current->line; - INPgetTok(&line,&token,1); - if (strcmp(token,".model")==0) { - /* don't have to do anything, since models were all done in - * pass 1 - */ - return(0); - } else if ((strcmp(token,".width") == 0) || - strcmp(token,".print") == 0 || - strcmp(token,".plot") == 0) { - /* obsolete - ignore */ - LITERR(" Warning: obsolete control card - ignored \n") - return(0); - } else if ( (strcmp(token,".temp")==0)){ - /* .temp temp1 temp2 temp3 temp4 ..... */ - /* not yet implemented - warn & ignore */ - LITERR(" Warning: .TEMP card obsolete - use .options TEMP and TNOM\n") - return(0); - } else if ( (strcmp(token,".op")==0)){ - /* .op */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"OP")==0) { - which=i; - break; - } - } - if(which == -1) { - LITERR("DC operating point analysis unsupported\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"Operating Point",&foo, task)) - return(0); - } else if ( (strcmp(token,".nodeset")==0)){ - /* .nodeset */ - which = -1; - for(prm=ft_sim->nodeParms; - prmnodeParms+ft_sim->numNodeParms;prm++) { - if(strcmp(prm->keyword,"nodeset")==0) { - which=prm->id; - break; - } - } - if(which == -1) { - LITERR("nodeset unknown to simulator. \n") - return(0); - } - for(;;) { /* loop until we run out of data */ - INPgetTok(&line,&name,1); - /* check to see if in the form V(xxx) and grab the xxx */ - if( *name == (char)NULL) break; /* end of line */ - length = strlen(name); - if( (*name == 'V' || *(name) == 'v') && (length == 1)){ - /* looks like V - must be V(xx) - get xx now*/ - INPgetTok(&line,&name,1); - INPtermInsert(ckt,&name,tab,&node1); - ptemp.rValue = INPevaluate(&line,&error,1); - IFC(setNodeParm,(ckt,node1,which,&ptemp,(IFvalue*)NULL)) - continue; - } - LITERR(" Error: .nodeset syntax error.\n") - break; - } - return(0); - } else if ( (strcmp(token,".disto")==0)){ - /* .disto {DEC OCT LIN} NP FSTART FSTOP */ + INPgetTok(&line, &token, 1); + if (strcmp(token, ".model") == 0) { + /* don't have to do anything, since models were all done in + * pass 1 */ + return (0); + } else if ((strcmp(token, ".width") == 0) || + strcmp(token, ".print") == 0 || strcmp(token, ".plot") == 0) { + /* obsolete - ignore */ + LITERR(" Warning: obsolete control card - ignored \n"); + return (0); + } else if ((strcmp(token, ".temp") == 0)) { + /* .temp temp1 temp2 temp3 temp4 ..... */ + /* not yet implemented - warn & ignore */ + LITERR(" Warning: .TEMP card obsolete - use .options TEMP and TNOM\n"); + return (0); + } else if ((strcmp(token, ".op") == 0)) { + /* .op */ which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"DISTO")==0) { - which=i; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "OP") == 0) { + which = i; break; } } - if(which == -1) { - LITERR("Small signal distortion analysis unsupported.\n") - return(0); + if (which == -1) { + LITERR("DC operating point analysis unsupported\n"); + return (0); } - IFC(newAnalysis,(ckt,which,"Distortion Analysis",&foo, task)) - INPgetTok(&line,&steptype,1); /* get DEC, OCT, or LIN */ - ptemp.iValue=1; - GCA(INPapName,(ckt,which,foo,steptype,&ptemp)) - parm=INPgetValue(ckt,&line,IF_INTEGER,tab);/* number of points*/ - GCA(INPapName,(ckt,which,foo,"numsteps",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* fstart */ - GCA(INPapName,(ckt,which,foo,"start",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* fstop */ - GCA(INPapName,(ckt,which,foo,"stop",parm)) - if(*line) { - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* f1phase */ - GCA(INPapName,(ckt,which,foo,"f2overf1",parm)) - } - return(0); - } else if ( (strcmp(token,".noise")==0)){ - /* .noise V(OUTPUT,REF) SRC {DEC OCT LIN} NP FSTART FSTOP */ + IFC(newAnalysis, (ckt, which, "Operating Point", &foo, task)) + return (0); + } else if ((strcmp(token, ".nodeset") == 0)) { + /* .nodeset */ which = -1; - for (i=0; inumAnalyses; i++) { + for (prm = ft_sim->nodeParms; + prm < ft_sim->nodeParms + ft_sim->numNodeParms; prm++) { + if (strcmp(prm->keyword, "nodeset") == 0) { + which = prm->id; + break; + } + } + if (which == -1) { + LITERR("nodeset unknown to simulator. \n"); + return (0); + } + for (;;) { + /* loop until we run out of data */ + INPgetTok(&line, &name, 1); + /* check to see if in the form V(xxx) and grab the xxx */ + if (*name == (char) NULL) + break; /* end of line */ + length = strlen(name); + if ((*name == 'V' || *(name) == 'v') && (length == 1)) { + /* looks like V - must be V(xx) - get xx now */ + INPgetTok(&line, &name, 1); + INPtermInsert(ckt, &name, tab, &node1); + ptemp.rValue = INPevaluate(&line, &error, 1); + IFC(setNodeParm, + (ckt, node1, which, &ptemp, + (IFvalue *) NULL)) continue; + } + LITERR(" Error: .nodeset syntax error.\n"); + break; + } + return (0); + } else if ((strcmp(token, ".disto") == 0)) { + /* .disto {DEC OCT LIN} NP FSTART FSTOP */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "DISTO") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("Small signal distortion analysis unsupported.\n"); + return (0); + } + IFC(newAnalysis, (ckt, which, "Distortion Analysis", &foo, task)) + INPgetTok(&line, &steptype, 1); /* get DEC, OCT, or LIN */ + ptemp.iValue = 1; + GCA(INPapName, (ckt, which, foo, steptype, &ptemp)) + parm = INPgetValue(ckt, &line, IF_INTEGER, tab); /* number of points */ + GCA(INPapName, (ckt, which, foo, "numsteps", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstart */ + GCA(INPapName, (ckt, which, foo, "start", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstop */ + GCA(INPapName, (ckt, which, foo, "stop", parm)) + if (*line) { + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* f1phase */ + GCA(INPapName, (ckt, which, foo, "f2overf1", parm)) + } + return (0); + } else if ((strcmp(token, ".noise") == 0)) { + /* .noise V(OUTPUT,REF) SRC {DEC OCT LIN} NP FSTART FSTOP */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { if (strcmp(ft_sim->analyses[i]->name, "NOISE") == 0) { which = i; break; @@ -142,465 +144,471 @@ char *word; /* something to stick a word of input into */ } if (which == -1) { LITERR("Noise analysis unsupported.\n"); - return(0); + return (0); } - IFC(newAnalysis, (ckt,which,"Noise Analysis",&foo,task)) - INPgetTok(&line,&name,1); + IFC(newAnalysis, (ckt, which, "Noise Analysis", &foo, task)) + INPgetTok(&line, &name, 1); - /* Make sure the ".noise" command is followed by */ + /* Make sure the ".noise" command is followed by */ /* V(xxxx). If it is, extract 'xxxx'. If not, report an error. */ if (name != NULL) { length = strlen(name); if (((*name == 'V') || (*name == 'v')) && (length == 1)) { - INPgetTok(&line,&nname1,0); - INPtermInsert(ckt,&nname1,tab,&node1); - ptemp.nValue=(IFnode)node1; - GCA(INPapName,(ckt,which,foo,"output",&ptemp)) + INPgetTok(&line, &nname1, 0); + INPtermInsert(ckt, &nname1, tab, &node1); + ptemp.nValue = (IFnode) node1; + GCA(INPapName, (ckt, which, foo, "output", &ptemp)) - if (*line != /* match ( */ ')') { - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - ptemp.nValue=(IFnode)node2; + if (*line != /* match ( */ ')') { + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + ptemp.nValue = (IFnode) node2; } else { - ptemp.nValue=(IFnode)gnode; + ptemp.nValue = (IFnode) gnode; } - GCA(INPapName,(ckt,which,foo,"outputref",&ptemp)) + GCA(INPapName, (ckt, which, foo, "outputref", &ptemp)) - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - ptemp.uValue=name; - GCA(INPapName,(ckt,which,foo,"input",&ptemp)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + ptemp.uValue = name; + GCA(INPapName, (ckt, which, foo, "input", &ptemp)) - INPgetTok(&line,&steptype,1); + INPgetTok(&line, &steptype, 1); ptemp.iValue = 1; - error=INPapName(ckt,which,foo,steptype,&ptemp); + error = INPapName(ckt, which, foo, steptype, &ptemp); if (error) - current->error = INPerrCat(current->error,INPerror(error)); - parm = INPgetValue(ckt,&line,IF_INTEGER,tab); - error = INPapName(ckt,which,foo,"numsteps",parm); + current->error = + INPerrCat(current->error, INPerror(error)); + parm = INPgetValue(ckt, &line, IF_INTEGER, tab); + error = INPapName(ckt, which, foo, "numsteps", parm); if (error) - current->error = INPerrCat(current->error,INPerror(error)); - parm = INPgetValue(ckt,&line,IF_REAL,tab); - error = INPapName(ckt,which,foo,"start",parm); + current->error = + INPerrCat(current->error, INPerror(error)); + parm = INPgetValue(ckt, &line, IF_REAL, tab); + error = INPapName(ckt, which, foo, "start", parm); if (error) - current->error = INPerrCat(current->error,INPerror(error)); - parm = INPgetValue(ckt,&line,IF_REAL,tab); - error = INPapName(ckt,which,foo,"stop",parm); + current->error = + INPerrCat(current->error, INPerror(error)); + parm = INPgetValue(ckt, &line, IF_REAL, tab); + error = INPapName(ckt, which, foo, "stop", parm); if (error) - current->error = INPerrCat(current->error,INPerror(error)); + current->error = + INPerrCat(current->error, INPerror(error)); /* now see if "ptspersum" has been specified by the user */ - for (found=0, point=line; (!found) && (*point != '\0'); - found = ((*point != ' ') && (*(point++) != '\t'))); + for (found = 0, point = line; (!found) && (*point != '\0'); + found = ((*point != ' ') && (*(point++) != '\t'))); if (found) { - parm = INPgetValue(ckt,&line,IF_INTEGER,tab); - error = INPapName(ckt,which,foo,"ptspersum",parm); + parm = INPgetValue(ckt, &line, IF_INTEGER, tab); + error = INPapName(ckt, which, foo, "ptspersum", parm); if (error) current->error = - INPerrCat(current->error,INPerror(error)); + INPerrCat(current->error, INPerror(error)); } else { ptemp.iValue = 0; - error = INPapName(ckt,which,foo,"ptspersum",&ptemp); - if (error) current->error = - INPerrCat(current->error,INPerror(error)); + error = + INPapName(ckt, which, foo, "ptspersum", &ptemp); + if (error) + current->error = + INPerrCat(current->error, INPerror(error)); } } else - LITERR( -"bad syntax [.noise v(OUT) SRC {DEC OCT LIN} NP FSTART FSTOP ]\n"); + LITERR("bad syntax [.noise v(OUT) SRC {DEC OCT LIN} NP FSTART FSTOP ]\n"); + } else { + LITERR("bad syntax [.noise v(OUT) SRC {DEC OCT LIN} NP FSTART FSTOP ]\n"); } - else { - LITERR( -"bad syntax [.noise v(OUT) SRC {DEC OCT LIN} NP FSTART FSTOP ]\n"); + return (0); + } else if ((strcmp(token, ".four") == 0) + || (strcmp(token, ".fourier") == 0)) { + /* .four */ + /* not implemented - warn & ignore */ + LITERR("Use fourier command to obtain fourier analysis\n"); + return (0); + } else if ((strcmp(token, ".ic") == 0)) { + /* .ic */ + which = -1; + for (prm = ft_sim->nodeParms; + prm < ft_sim->nodeParms + ft_sim->numNodeParms; prm++) { + if (strcmp(prm->keyword, "ic") == 0) { + which = prm->id; + break; + } } - return(0); - } else if ( (strcmp(token,".four")==0) || (strcmp(token,".fourier")==0) ){ - /* .four */ - /* not implemented - warn & ignore */ - LITERR("Use fourier command to obtain fourier analysis\n") - return(0); - } else if ( (strcmp(token,".ic")==0)){ - /* .ic */ - which = -1; - for(prm=ft_sim->nodeParms; - prmnodeParms+ft_sim->numNodeParms;prm++) { - if(strcmp(prm->keyword,"ic")==0) { - which=prm->id; - break; - } - } - if(which==-1) { - LITERR("ic unknown to simulator. \n") - return(0); - } - for(;;) { /* loop until we run out of data */ - INPgetTok(&line,&name,1); - /* check to see if in the form V(xxx) and grab the xxx */ - if( *name == 0) break; /* end of line */ - length = strlen(name); - if( (*name == 'V' || *(name) == 'v') && (length == 1)){ - /* looks like V - must be V(xx) - get xx now*/ - INPgetTok(&line,&name,1); - INPtermInsert(ckt,&name,tab,&node1); - ptemp.rValue = INPevaluate(&line,&error,1); - IFC(setNodeParm,(ckt,node1,which,&ptemp,(IFvalue*)NULL)) - continue; - } - LITERR(" Error: .ic syntax error.\n") - break; - } - return(0); - } else if ( (strcmp(token,".ac")==0)){ - /* .ac {DEC OCT LIN} NP FSTART FSTOP */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"AC")==0) { - which=i; - break; - } - } - if(which == -1) { - LITERR("AC small signal analysis unsupported.\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"AC Analysis",&foo, task)) - INPgetTok(&line,&steptype,1); /* get DEC, OCT, or LIN */ - ptemp.iValue=1; - GCA(INPapName,(ckt,which,foo,steptype,&ptemp)) - parm=INPgetValue(ckt,&line,IF_INTEGER,tab);/* number of points*/ - GCA(INPapName,(ckt,which,foo,"numsteps",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* fstart */ - GCA(INPapName,(ckt,which,foo,"start",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* fstop */ - GCA(INPapName,(ckt,which,foo,"stop",parm)) - return(0); - } else if ( (strcmp(token,".pz")==0)){ - /* .pz nodeI nodeG nodeJ nodeK {V I} {POL ZER PZ} */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"PZ")==0) { - which=i; - break; - } - } - if(which == -1) { - LITERR("Pole-zero analysis unsupported.\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"Pole-Zero Analysis",&foo, task)) - parm = INPgetValue(ckt,&line,IF_NODE,tab); - GCA(INPapName,(ckt,which,foo,"nodei",parm)) - parm = INPgetValue(ckt,&line,IF_NODE,tab); - GCA(INPapName,(ckt,which,foo,"nodeg",parm)) - parm = INPgetValue(ckt,&line,IF_NODE,tab); - GCA(INPapName,(ckt,which,foo,"nodej",parm)) - parm = INPgetValue(ckt,&line,IF_NODE,tab); - GCA(INPapName,(ckt,which,foo,"nodek",parm)) - INPgetTok(&line,&steptype,1); /* get V or I */ - ptemp.iValue=1; - GCA(INPapName,(ckt,which,foo,steptype,&ptemp)) - INPgetTok(&line,&steptype,1); /* get POL, ZER, or PZ */ - ptemp.iValue=1; - GCA(INPapName,(ckt,which,foo,steptype,&ptemp)) - return(0); - } else if ( (strcmp(token,".dc")==0)){ - /* .dc SRC1NAME Vstart1 Vstop1 Vinc1 [SRC2NAME Vstart2 */ - /* Vstop2 Vinc2 */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"DC")==0) { - which=i; - break; - } - } - if(which==-1) { - LITERR("DC transfer curve analysis unsupported\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"DC transfer characteristic",&foo, task)) - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - ptemp.uValue=name; - GCA(INPapName,(ckt,which,foo,"name1",&ptemp)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* vstart1 */ - GCA(INPapName,(ckt,which,foo,"start1",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* vstop1 */ - GCA(INPapName,(ckt,which,foo,"stop1",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* vinc1 */ - GCA(INPapName,(ckt,which,foo,"step1",parm)) - if(*line) { - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - ptemp.uValue=name; - GCA(INPapName,(ckt,which,foo,"name2",&ptemp)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* vstart1 */ - GCA(INPapName,(ckt,which,foo,"start2",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* vstop1 */ - GCA(INPapName,(ckt,which,foo,"stop2",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* vinc1 */ - GCA(INPapName,(ckt,which,foo,"step2",parm)) - } - return(0); - } else if ( (strcmp(token,".tf")==0)){ - /* .tf v( node1, node2 ) src */ - /* .tf vsrc2 src */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"TF")==0) { - which=i; - break; - } - } - if(which==-1) { - LITERR("Transfer Function analysis unsupported.\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"Transfer Function",&foo,task)) - INPgetTok(&line,&name,0); - /* name is now either V or I or a serious error */ - if(*name == 'v' && strlen(name)==1) { - if(*line != '(' /* match) */ ) { - /* error, bad input format */ - } - INPgetTok(&line,&nname1,0); - INPtermInsert(ckt,&nname1,tab,&node1); - ptemp.nValue=(IFnode)node1; - GCA(INPapName,(ckt,which,foo,"outpos",&ptemp)) - if(*line != /* match ( */ ')') { - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - ptemp.nValue=(IFnode)node2; - GCA(INPapName,(ckt,which,foo,"outneg",&ptemp)) - ptemp.sValue = (char *) - MALLOC(sizeof(char)*(5+strlen(nname1)+strlen(nname2))); - (void)sprintf(ptemp.sValue,"V(%s,%s)",nname1,nname2); - GCA(INPapName,(ckt,which,foo,"outname",&ptemp)) - } else { - ptemp.nValue=(IFnode)gnode; - GCA(INPapName,(ckt,which,foo,"outneg",&ptemp)) - ptemp.sValue = (char *)MALLOC(sizeof(char)*(4+strlen(nname1))); - (void)sprintf(ptemp.sValue,"V(%s)",nname1); - GCA(INPapName,(ckt,which,foo,"outname",&ptemp)) - } - } else if(*name == 'i' && strlen(name)==1) { - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - ptemp.uValue=name; - GCA(INPapName,(ckt,which,foo,"outsrc",&ptemp)) - } else { - LITERR("Syntax error: voltage or current expected.\n") + if (which == -1) { + LITERR("ic unknown to simulator. \n"); + return (0); + } + for (;;) { /* loop until we run out of data */ + INPgetTok(&line, &name, 1); + /* check to see if in the form V(xxx) and grab the xxx */ + if (*name == 0) + break; /* end of line */ + length = strlen(name); + if ((*name == 'V' || *(name) == 'v') && (length == 1)) { + /* looks like V - must be V(xx) - get xx now */ + INPgetTok(&line, &name, 1); + INPtermInsert(ckt, &name, tab, &node1); + ptemp.rValue = INPevaluate(&line, &error, 1); + IFC(setNodeParm, + (ckt, node1, which, &ptemp, + (IFvalue *) NULL)) continue; + } + LITERR(" Error: .ic syntax error.\n"); + break; + } + return (0); + } else if ((strcmp(token, ".ac") == 0)) { + /* .ac {DEC OCT LIN} NP FSTART FSTOP */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "AC") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("AC small signal analysis unsupported.\n"); + return (0); + } + IFC(newAnalysis, (ckt, which, "AC Analysis", &foo, task)) + INPgetTok(&line, &steptype, 1); /* get DEC, OCT, or LIN */ + ptemp.iValue = 1; + GCA(INPapName, (ckt, which, foo, steptype, &ptemp)) + parm = INPgetValue(ckt, &line, IF_INTEGER, tab); /* number of points */ + GCA(INPapName, (ckt, which, foo, "numsteps", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstart */ + GCA(INPapName, (ckt, which, foo, "start", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstop */ + GCA(INPapName, (ckt, which, foo, "stop", parm)) + return (0); + } else if ((strcmp(token, ".pz") == 0)) { + /* .pz nodeI nodeG nodeJ nodeK {V I} {POL ZER PZ} */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "PZ") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("Pole-zero analysis unsupported.\n"); + return (0); + } + IFC(newAnalysis, (ckt, which, "Pole-Zero Analysis", &foo, task)) + parm = INPgetValue(ckt, &line, IF_NODE, tab); + GCA(INPapName, (ckt, which, foo, "nodei", parm)) + parm = INPgetValue(ckt, &line, IF_NODE, tab); + GCA(INPapName, (ckt, which, foo, "nodeg", parm)) + parm = INPgetValue(ckt, &line, IF_NODE, tab); + GCA(INPapName, (ckt, which, foo, "nodej", parm)) + parm = INPgetValue(ckt, &line, IF_NODE, tab); + GCA(INPapName, (ckt, which, foo, "nodek", parm)) + INPgetTok(&line, &steptype, 1); /* get V or I */ + ptemp.iValue = 1; + GCA(INPapName, (ckt, which, foo, steptype, &ptemp)) + INPgetTok(&line, &steptype, 1); /* get POL, ZER, or PZ */ + ptemp.iValue = 1; + GCA(INPapName, (ckt, which, foo, steptype, &ptemp)) + return (0); + } else if ((strcmp(token, ".dc") == 0)) { + /* .dc SRC1NAME Vstart1 Vstop1 Vinc1 [SRC2NAME Vstart2 */ + /* Vstop2 Vinc2 */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "DC") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("DC transfer curve analysis unsupported\n"); + return (0); + } + IFC(newAnalysis, + (ckt, which, "DC transfer characteristic", &foo, + task)) INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + ptemp.uValue = name; + GCA(INPapName, (ckt, which, foo, "name1", &ptemp)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* vstart1 */ + GCA(INPapName, (ckt, which, foo, "start1", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* vstop1 */ + GCA(INPapName, (ckt, which, foo, "stop1", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* vinc1 */ + GCA(INPapName, (ckt, which, foo, "step1", parm)) + if (*line) { + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + ptemp.uValue = name; + GCA(INPapName, (ckt, which, foo, "name2", &ptemp)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* vstart1 */ + GCA(INPapName, (ckt, which, foo, "start2", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* vstop1 */ + GCA(INPapName, (ckt, which, foo, "stop2", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* vinc1 */ + GCA(INPapName, (ckt, which, foo, "step2", parm)) + } + return (0); + } else if ((strcmp(token, ".tf") == 0)) { + /* .tf v( node1, node2 ) src */ + /* .tf vsrc2 src */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "TF") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("Transfer Function analysis unsupported.\n"); + return (0); + } + IFC(newAnalysis, (ckt, which, "Transfer Function", &foo, task)) + INPgetTok(&line, &name, 0); + /* name is now either V or I or a serious error */ + if (*name == 'v' && strlen(name) == 1) { + if (*line != '(' /* match) */ ) { + /* error, bad input format */ + } + INPgetTok(&line, &nname1, 0); + INPtermInsert(ckt, &nname1, tab, &node1); + ptemp.nValue = (IFnode) node1; + GCA(INPapName, (ckt, which, foo, "outpos", &ptemp)) + if (*line != /* match ( */ ')') { + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + ptemp.nValue = (IFnode) node2; + GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)) + ptemp.sValue = (char *) + MALLOC(sizeof(char) * + (5 + strlen(nname1) + strlen(nname2))); + (void) sprintf(ptemp.sValue, "V(%s,%s)", nname1, nname2); + GCA(INPapName, (ckt, which, foo, "outname", &ptemp)) + } else { + ptemp.nValue = (IFnode) gnode; + GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)) + ptemp.sValue = + (char *) MALLOC(sizeof(char) * (4 + strlen(nname1))); + (void) sprintf(ptemp.sValue, "V(%s)", nname1); + GCA(INPapName, (ckt, which, foo, "outname", &ptemp)) + } + } else if (*name == 'i' && strlen(name) == 1) { + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + ptemp.uValue = name; + GCA(INPapName, (ckt, which, foo, "outsrc", &ptemp)) + } else { + LITERR("Syntax error: voltage or current expected.\n"); return 0; } - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - ptemp.uValue=name; - GCA(INPapName,(ckt,which,foo,"insrc",&ptemp)) - return(0); - } else if ( (strcmp(token,".tran")==0)){ - /* .tran Tstep Tstop > */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"TRAN")==0) { - which=i; - break; - } - } - if(which == -1) { - LITERR("Transient analysis unsupported.\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"Transient Analysis",&foo, task)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* Tstep */ - GCA(INPapName,(ckt,which,foo,"tstep",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* Tstop */ - GCA(INPapName,(ckt,which,foo,"tstop",parm)) - if(*line) { - dtemp = INPevaluate(&line,&error,1); /* tstart? */ - if(error==0) { - ptemp.rValue=dtemp; - GCA(INPapName,(ckt,which,foo,"tstart",&ptemp)) - dtemp = INPevaluate(&line,&error,1); /* tmax? */ - if(error==0) { - ptemp.rValue=dtemp; - GCA(INPapName,(ckt,which,foo,"tmax",&ptemp)) - } - } - } - if(*line) { - INPgetTok(&line,&word,1); /* uic? */ - if(strcmp(word,"uic")==0) { - ptemp.iValue=1; - GCA(INPapName,(ckt,which,foo,"uic",&ptemp)) - } else { - LITERR(" Error: unknown parameter on .tran - ignored\n") - } - } - return(0); - } else if ( (strcmp(token,".subckt")==0) || - (strcmp(token,".ends")==0) ){ - /* not yet implemented - warn & ignore */ - LITERR(" Warning: Subcircuits not yet implemented - ignored \n") - return(0); - } else if ( (strcmp(token,".end")==0)){ - /* .end - end of input */ - /* not allowed to pay attention to additional input - return */ - return(1); - /*NOTREACHED*/ -/* MW. .options is handled before - this is not needed - } else if ( (strcmp(token,".options")==0) || - (strcmp(token,".option")==0) || - (strcmp(token,".opt")==0) ){ - * .option - specify program options - rather complicated / - * use a subroutine to handle all of them to keep this / - * subroutine managable / - INPdoOpts(ckt,ft_curckt->ci_curOpt,current,tab); - return(0); -INPdoOpts is never called (I hope) */ - - - } else if (strcmp(token, ".sens") == 0) { - which = -1; /* Bug fix from Glao Dezai */ - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"SENS")==0) { - which=i; - break; - } - } - if(which==-1) { - LITERR("Sensitivity unsupported.\n") - return(0); - } - - IFC(newAnalysis,(ckt,which,"Sensitivity Analysis",&foo, task)) - - /* Format is: - * .sens - * + [ac [dec|lin|oct] | dc ] - */ - - /* Get the output voltage or current */ - INPgetTok(&line,&name,0); - /* name is now either V or I or a serious error */ - if (*name == 'v' && strlen(name) == 1) { - if (*line != '(' /* match) */) { - LITERR("Syntax error: '(' expected after 'v'\n"); - return 0; - } - INPgetTok(&line, &nname1, 0); - INPtermInsert(ckt, &nname1, tab, &node1); - ptemp.nValue=(IFnode)node1; - GCA(INPapName,(ckt,which,foo,"outpos",&ptemp)) - - if(*line != /* match ( */ ')') { - INPgetTok(&line, &nname2, 1); - INPtermInsert(ckt, &nname2, tab, &node2); - ptemp.nValue = (IFnode)node2; - GCA(INPapName,(ckt,which,foo,"outneg",&ptemp)) - ptemp.sValue = (char *) - MALLOC(sizeof(char)*(5+strlen(nname1)+strlen(nname2))); - (void)sprintf(ptemp.sValue,"V(%s,%s)",nname1,nname2); - GCA(INPapName,(ckt,which,foo,"outname",&ptemp)) - } else { - ptemp.nValue=(IFnode)gnode; - GCA(INPapName,(ckt,which,foo,"outneg",&ptemp)) - ptemp.sValue = (char *)MALLOC(sizeof(char)*(4+strlen(nname1))); - (void)sprintf(ptemp.sValue,"V(%s)",nname1); - GCA(INPapName,(ckt,which,foo,"outname",&ptemp)) - } - } else if (*name == 'i' && strlen(name) == 1) { - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - ptemp.uValue=name; - GCA(INPapName,(ckt,which,foo,"outsrc",&ptemp)) - } else { - LITERR("Syntax error: voltage or current expected.\n") - return 0; + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + ptemp.uValue = name; + GCA(INPapName, (ckt, which, foo, "insrc", &ptemp)) + return (0); + } else if ((strcmp(token, ".tran") == 0)) { + /* .tran Tstep Tstop > */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "TRAN") == 0) { + which = i; + break; + } } - - INPgetTok(&line,&name,1); - if (name && !strcmp(name, "pct")) { + if (which == -1) { + LITERR("Transient analysis unsupported.\n"); + return (0); + } + IFC(newAnalysis, (ckt, which, "Transient Analysis", &foo, task)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* Tstep */ + GCA(INPapName, (ckt, which, foo, "tstep", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* Tstop */ + GCA(INPapName, (ckt, which, foo, "tstop", parm)) + if (*line) { + dtemp = INPevaluate(&line, &error, 1); /* tstart? */ + if (error == 0) { + ptemp.rValue = dtemp; + GCA(INPapName, (ckt, which, foo, "tstart", &ptemp)) + dtemp = INPevaluate(&line, &error, 1); /* tmax? */ + if (error == 0) { + ptemp.rValue = dtemp; + GCA(INPapName, (ckt, which, foo, "tmax", &ptemp)) + } + } + } + if (*line) { + INPgetTok(&line, &word, 1); /* uic? */ + if (strcmp(word, "uic") == 0) { ptemp.iValue = 1; - GCA(INPapName,(ckt,which,foo,"pct",&ptemp)) - INPgetTok(&line,&name,1); + GCA(INPapName, (ckt, which, foo, "uic", &ptemp)) + } else { + LITERR(" Error: unknown parameter on .tran - ignored\n"); + } + } + return (0); + } else if ((strcmp(token, ".subckt") == 0) || + (strcmp(token, ".ends") == 0)) { + /* not yet implemented - warn & ignore */ + LITERR(" Warning: Subcircuits not yet implemented - ignored \n"); + return (0); + } else if ((strcmp(token, ".end") == 0)) { + /* .end - end of input */ + /* not allowed to pay attention to additional input - return */ + return (1); + } else if (strcmp(token, ".sens") == 0) { + which = -1; /* Bug fix from Glao Dezai */ + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "SENS") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("Sensitivity unsupported.\n"); + return (0); + } + + IFC(newAnalysis, (ckt, which, "Sensitivity Analysis", &foo, task)) + + /* Format is: + * .sens + * + [ac [dec|lin|oct] | dc ] + */ + /* Get the output voltage or current */ + INPgetTok(&line, &name, 0); + /* name is now either V or I or a serious error */ + if (*name == 'v' && strlen(name) == 1) { + if (*line != '(' /* match) */ ) { + LITERR("Syntax error: '(' expected after 'v'\n"); + return 0; + } + INPgetTok(&line, &nname1, 0); + INPtermInsert(ckt, &nname1, tab, &node1); + ptemp.nValue = (IFnode) node1; + GCA(INPapName, (ckt, which, foo, "outpos", &ptemp)) + + if (*line != /* match ( */ ')') { + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + ptemp.nValue = (IFnode) node2; + GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)) + ptemp.sValue = (char *) + MALLOC(sizeof(char) * + (5 + strlen(nname1) + strlen(nname2))); + (void) sprintf(ptemp.sValue, "V(%s,%s)", nname1, nname2); + GCA(INPapName, (ckt, which, foo, "outname", &ptemp)) + } else { + ptemp.nValue = (IFnode) gnode; + GCA(INPapName, (ckt, which, foo, "outneg", &ptemp)) + ptemp.sValue = + (char *) MALLOC(sizeof(char) * (4 + strlen(nname1))); + (void) sprintf(ptemp.sValue, "V(%s)", nname1); + GCA(INPapName, (ckt, which, foo, "outname", &ptemp)) + } + } else if (*name == 'i' && strlen(name) == 1) { + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + ptemp.uValue = name; + GCA(INPapName, (ckt, which, foo, "outsrc", &ptemp)) + } else { + LITERR("Syntax error: voltage or current expected.\n"); + return 0; + } + + INPgetTok(&line, &name, 1); + if (name && !strcmp(name, "pct")) { + ptemp.iValue = 1; + GCA(INPapName, (ckt, which, foo, "pct", &ptemp)) + INPgetTok(&line, &name, 1); } if (name && !strcmp(name, "ac")) { - INPgetTok(&line,&steptype,1); /* get DEC, OCT, or LIN */ - ptemp.iValue=1; - GCA(INPapName,(ckt,which,foo,steptype,&ptemp)) - parm=INPgetValue(ckt,&line,IF_INTEGER,tab);/* number of points*/ - GCA(INPapName,(ckt,which,foo,"numsteps",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* fstart */ - GCA(INPapName,(ckt,which,foo,"start",parm)) - parm = INPgetValue(ckt,&line,IF_REAL,tab); /* fstop */ - GCA(INPapName,(ckt,which,foo,"stop",parm)) - return(0); + INPgetTok(&line, &steptype, 1); /* get DEC, OCT, or LIN */ + ptemp.iValue = 1; + GCA(INPapName, (ckt, which, foo, steptype, &ptemp)) + parm = INPgetValue(ckt, &line, IF_INTEGER, tab); /* number of points */ + GCA(INPapName, (ckt, which, foo, "numsteps", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstart */ + GCA(INPapName, (ckt, which, foo, "start", parm)) + parm = INPgetValue(ckt, &line, IF_REAL, tab); /* fstop */ + GCA(INPapName, (ckt, which, foo, "stop", parm)) + return (0); } else if (name && *name && strcmp(name, "dc")) { - /* Bad flag */ - LITERR("Syntax error: 'ac' or 'dc' expected.\n") - return 0; + /* Bad flag */ + LITERR("Syntax error: 'ac' or 'dc' expected.\n"); + return 0; } - return(0); + return (0); } #ifdef WANT_SENSE2 - else if ( (strcmp(token,".sens2")==0)) { - /* .sens {AC} {DC} {TRAN} [dev=nnn parm=nnn]* */ - which = -1; - for(i=0;inumAnalyses;i++) { - if(strcmp(ft_sim->analyses[i]->name,"SENS2")==0) { - which=i; - break; - } - } - if(which == -1) { - LITERR("Sensitivity-2 analysis unsupported\n") - return(0); - } - IFC(newAnalysis,(ckt,which,"Sensitivity-2 Analysis",&foo, task)) - while(*line) { /* read the entire line */ - INPgetTok(&line,&token,1); - for(i=0;ianalyses[which]->numParms;i++) { - /* find the parameter */ - if(0==strcmp(token , - ft_sim->analyses[which]->analysisParms[i]. - keyword) ){ - /* found it, analysis which, parameter i */ - if(ft_sim->analyses[which]->analysisParms[i]. - dataType & IF_FLAG) { - /* one of the keywords! */ - ptemp.iValue = 1; - error = (*(ft_sim->setAnalysisParm))(ckt, - foo, ft_sim->analyses[which]-> - analysisParms[i].id,&ptemp,(IFvalue*)NULL); - if(error) current->error = INPerrCat( - current->error, INPerror(error)); - } else { - parm = INPgetValue(ckt,&line,ft_sim-> - analyses[which]->analysisParms[i]. - dataType,tab); - error = (*(ft_sim->setAnalysisParm))(ckt, - foo, ft_sim->analyses[which]-> - analysisParms[i].id,parm,(IFvalue*)NULL); - if(error) current->error = INPerrCat( - current->error, INPerror(error)); - - } - break; - } - } - if(i==ft_sim->analyses[which]->numParms) { - /* didn't find it! */ - LITERR(" Error: unknown parameter on .sens-ignored \n") - } - } - return(0); + else if ((strcmp(token, ".sens2") == 0)) { + /* .sens {AC} {DC} {TRAN} [dev=nnn parm=nnn]* */ + which = -1; + for (i = 0; i < ft_sim->numAnalyses; i++) { + if (strcmp(ft_sim->analyses[i]->name, "SENS2") == 0) { + which = i; + break; + } + } + if (which == -1) { + LITERR("Sensitivity-2 analysis unsupported\n"); + return (0); + } + IFC(newAnalysis, + (ckt, which, "Sensitivity-2 Analysis", &foo, task)) while (*line) { /* read the entire line */ + INPgetTok(&line, &token, 1); + for (i = 0; i < ft_sim->analyses[which]->numParms; i++) { + /* find the parameter */ + if (0 == strcmp(token, + ft_sim->analyses[which]-> + analysisParms[i].keyword)) { + /* found it, analysis which, parameter i */ + if (ft_sim->analyses[which]-> + analysisParms[i].dataType & IF_FLAG) { + /* one of the keywords! */ + ptemp.iValue = 1; + error = (*(ft_sim->setAnalysisParm)) ( + ckt, foo, + ft_sim->analyses[which]->analysisParms[i].id, + &ptemp, (IFvalue *) NULL); + if (error) + current->error = + INPerrCat(current->error, INPerror(error)); + } else { + parm = + INPgetValue(ckt, &line, + ft_sim->analyses[which]-> + analysisParms[i].dataType, tab); + error = + (*(ft_sim->setAnalysisParm)) (ckt, foo, + ft_sim-> + analyses + [which]->analysisParms + [i].id, parm, + (IFvalue *) + NULL); + if (error) + current->error = + INPerrCat(current->error, INPerror(error)); + + } + break; + } + } + if (i == ft_sim->analyses[which]->numParms) { + /* didn't find it! */ + LITERR(" Error: unknown parameter on .sens-ignored \n"); + } + } + return (0); } #endif - else if ( (strcmp(token,".probe")==0)) { + else if ((strcmp(token, ".probe") == 0)) { /* Maybe generate a "probe" format file in the future. */ return 0; } - LITERR(" unimplemented control card - error \n") - return(0); + LITERR(" unimplemented control card - error \n"); + return (0); } diff --git a/src/circuit/inp2e.c b/src/circuit/inp2e.c index 0346060f6..b442c7ef6 100644 --- a/src/circuit/inp2e.c +++ b/src/circuit/inp2e.c @@ -11,59 +11,58 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2E(void *ckt, INPtables *tab, card *current) +void INP2E(void *ckt, INPtables * tab, card * current) { /* Ename */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ type = INPtypelook("VCVS"); - if(type < 0 ) { - LITERR("Device type VCVS not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type VCVS not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&nname4,1); - INPtermInsert(ckt,&nname4,tab,&node4); - if(!tab->defEmod) { - /* create default E model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"E",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defEmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &nname4, 1); + INPtermInsert(ckt, &nname4, tab, &node4); + if (!tab->defEmod) { + /* create default E model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "E", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defEmod), uid)) } - IFC(newInstance,(ckt,tab->defEmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("gain",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defEmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("gain", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2f.c b/src/circuit/inp2f.c index ff398b236..0e3d8af18 100644 --- a/src/circuit/inp2f.c +++ b/src/circuit/inp2f.c @@ -11,52 +11,51 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2F(void *ckt, INPtables *tab, card *current) +void INP2F(void *ckt, INPtables * tab, card * current) { /* Fname */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -IFvalue *parm; /* a pointer to a value structure to pick things up into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + IFvalue *parm; /* a pointer to a value structure to pick things up into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ type = INPtypelook("CCCS"); - if(type < 0 ) { - LITERR("Device type CCCS not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type CCCS not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - if(!tab->defFmod) { - /* create default F model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"F",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defFmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + if (!tab->defFmod) { + /* create default F model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "F", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defFmod), uid)) } - IFC(newInstance,(ckt,tab->defFmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - parm=INPgetValue(ckt,&line,IF_INSTANCE,tab); - GCA(INPpName,("control",parm,ckt,type,fast)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("gain",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defFmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + parm = INPgetValue(ckt, &line, IF_INSTANCE, tab); + GCA(INPpName, ("control", parm, ckt, type, fast)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("gain", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2g.c b/src/circuit/inp2g.c index 6943c1c62..6cd733200 100644 --- a/src/circuit/inp2g.c +++ b/src/circuit/inp2g.c @@ -11,59 +11,58 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2G(void *ckt, INPtables *tab, card *current) +void INP2G(void *ckt, INPtables * tab, card * current) { /* Gname */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid of default model to be created */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid of default model to be created */ type = INPtypelook("VCCS"); - if(type < 0 ) { - LITERR("Device type VCCS not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type VCCS not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&nname4,1); - INPtermInsert(ckt,&nname4,tab,&node4); - if(!tab->defGmod) { - /* create default G model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"G",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defGmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &nname4, 1); + INPtermInsert(ckt, &nname4, tab, &node4); + if (!tab->defGmod) { + /* create default G model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "G", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defGmod), uid)) } - IFC(newInstance,(ckt,tab->defGmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("gain",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defGmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("gain", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2h.c b/src/circuit/inp2h.c index 658907107..d99b5c798 100644 --- a/src/circuit/inp2h.c +++ b/src/circuit/inp2h.c @@ -11,52 +11,51 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2H(void *ckt, INPtables *tab, card *current) +void INP2H(void *ckt, INPtables * tab, card * current) { /* Hname */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -IFvalue *parm; /* pointer to a value structure for functions which return one*/ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model to be created */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + IFvalue *parm; /* pointer to a value structure for functions which return one */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model to be created */ type = INPtypelook("CCVS"); - if(type < 0 ) { - LITERR("Device type CCVS not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type CCVS not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - if(!tab->defHmod) { - /* create default H model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"H",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defHmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + if (!tab->defHmod) { + /* create default H model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "H", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defHmod), uid)) } - IFC(newInstance,(ckt,tab->defHmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - parm=INPgetValue(ckt,&line,IF_INSTANCE,tab); - GCA(INPpName,("control",parm,ckt,type,fast)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("gain",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defHmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + parm = INPgetValue(ckt, &line, IF_INSTANCE, tab); + GCA(INPpName, ("control", parm, ckt, type, fast)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("gain", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2i.c b/src/circuit/inp2i.c index fc426d029..e27daa3a2 100644 --- a/src/circuit/inp2i.c +++ b/src/circuit/inp2i.c @@ -11,50 +11,49 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2I(void *ckt, INPtables *tab, card *current) +void INP2I(void *ckt, INPtables * tab, card * current) { /* Iname [ [DC] ] [AC [ [ ] ] ] * [] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ type = INPtypelook("Isource"); - if(type < 0 ) { - LITERR("Device type Isource not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type Isource not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - if(!tab->defImod) { - /* create default I model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"I",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defImod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + if (!tab->defImod) { + /* create default I model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "I", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defImod), uid)) } - IFC(newInstance,(ckt,tab->defImod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("dc",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defImod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("dc", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2j.c b/src/circuit/inp2j.c index 089b82ffd..111963ae7 100644 --- a/src/circuit/inp2j.c +++ b/src/circuit/inp2j.c @@ -11,74 +11,73 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2J(void *ckt, INPtables *tab, card *current) +void INP2J(void *ckt, INPtables * tab, card * current) { /* Jname [] [OFF] [IC=,] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* the name of the model */ -INPmodel *thismodel; /* pointer to model description for user's model */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid of default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* the name of the model */ + INPmodel *thismodel; /* pointer to model description for user's model */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid of default model */ line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - thismodel = (INPmodel *)NULL; - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if (thismodel->INPmodType != INPtypelook("JFET") - && thismodel->INPmodType != INPtypelook("JFET2") - ) - { - LITERR("incorrect model type") - return; - } - type = thismodel->INPmodType; - mdfast = (thismodel->INPmodfast); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + thismodel = (INPmodel *) NULL; + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (thismodel->INPmodType != INPtypelook("JFET") + && thismodel->INPmodType != INPtypelook("JFET2") + ) { + LITERR("incorrect model type"); + return; + } + type = thismodel->INPmodType; + mdfast = (thismodel->INPmodfast); } else { - type = INPtypelook("JFET"); - if(type < 0 ) { - LITERR("Device type JFET not supported by this binary\n") - return; - } - if(!tab->defJmod) { - /* create default J model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"J",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defJmod),uid)) - } - mdfast = tab->defJmod; + type = INPtypelook("JFET"); + if (type < 0) { + LITERR("Device type JFET not supported by this binary\n"); + return; + } + if (!tab->defJmod) { + /* create default J model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "J", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defJmod), uid)) + } + mdfast = tab->defJmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("area",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("area", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2k.c b/src/circuit/inp2k.c index 7614955f3..4ffac0447 100644 --- a/src/circuit/inp2k.c +++ b/src/circuit/inp2k.c @@ -11,46 +11,45 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2K(void *ckt, INPtables *tab, card *current) +void INP2K(void *ckt, INPtables * tab, card * current) { /* Kname Lname Lname */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -IFvalue *parm; /* ptr to a value structure for function return values */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + IFvalue *parm; /* ptr to a value structure for function return values */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ line = current->line; type = INPtypelook("mutual"); - if(type < 0 ) { - LITERR("Device type mutual not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type mutual not supported by this binary\n"); + return; } - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - if(!tab->defKmod) { - /* create deafult K model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"K",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defKmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + if (!tab->defKmod) { + /* create deafult K model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "K", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defKmod), uid)) } - IFC(newInstance,(ckt,tab->defKmod,&fast,name)) + IFC(newInstance, (ckt, tab->defKmod, &fast, name)) - parm = INPgetValue(ckt,&line,IF_INSTANCE,tab); - GCA(INPpName,("inductor1",parm,ckt,type,fast)) - parm = INPgetValue(ckt,&line,IF_INSTANCE,tab); - GCA(INPpName,("inductor2",parm,ckt,type,fast)) + parm = INPgetValue(ckt, &line, IF_INSTANCE, tab); + GCA(INPpName, ("inductor1", parm, ckt, type, fast)) + parm = INPgetValue(ckt, &line, IF_INSTANCE, tab); + GCA(INPpName, ("inductor2", parm, ckt, type, fast)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("coefficient",&ptemp,ckt,type,fast)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("coefficient", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2l.c b/src/circuit/inp2l.c index d2282dba5..b17362c72 100644 --- a/src/circuit/inp2l.c +++ b/src/circuit/inp2l.c @@ -11,49 +11,48 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2L(void *ckt, INPtables *tab, card *current) +void INP2L(void *ckt, INPtables * tab, card * current) { /* parse an inductor card */ /* Lname [IC=] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ type = INPtypelook("Inductor"); - if(type < 0 ) { - LITERR("Device type Inductor not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type Inductor not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - if(!tab->defLmod) { - /* create default L model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"L",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defLmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + if (!tab->defLmod) { + /* create default L model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "L", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defLmod), uid)) } - IFC(newInstance,(ckt,tab->defLmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("inductance",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defLmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("inductance", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2m.c b/src/circuit/inp2m.c index d0b203f74..d3cb1efdd 100644 --- a/src/circuit/inp2m.c +++ b/src/circuit/inp2m.c @@ -11,8 +11,7 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2M(void *ckt, INPtables *tab, card *current) +void INP2M(void *ckt, INPtables * tab, card * current) { /* Mname [L=] @@ -21,81 +20,81 @@ INP2M(void *ckt, INPtables *tab, card *current) * [IC=,,] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* the name of the model */ -INPmodel *thismodel; /* pointer to model description for user's model */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* the name of the model */ + INPmodel *thismodel; /* pointer to model description for user's model */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid for default model */ line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&nname4,1); - INPtermInsert(ckt,&nname4,tab,&node4); - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - thismodel = (INPmodel *)NULL; - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if (thismodel->INPmodType != INPtypelook("Mos1") - && thismodel->INPmodType != INPtypelook("Mos2") - && thismodel->INPmodType != INPtypelook("Mos3") - && thismodel->INPmodType != INPtypelook("Mos5") - && thismodel->INPmodType != INPtypelook("Mos6") - && thismodel->INPmodType != INPtypelook("Mos8") - && thismodel->INPmodType != INPtypelook("BSIM1") - && thismodel->INPmodType != INPtypelook("BSIM2") - && thismodel->INPmodType != INPtypelook("BSIM3") - && thismodel->INPmodType != INPtypelook("BSIM4") - && thismodel->INPmodType != INPtypelook("BSIM3V1") - && thismodel->INPmodType != INPtypelook("BSIM3V2") - ) - { - LITERR("incorrect model type") - return; - } - type = thismodel->INPmodType; - mdfast = (thismodel->INPmodfast); - } else { - type = INPtypelook("Mos1"); - if(type < 0 ) { - LITERR("Device type MOS1 not supported by this binary\n") + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &nname4, 1); + INPtermInsert(ckt, &nname4, tab, &node4); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + thismodel = (INPmodel *) NULL; + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (thismodel->INPmodType != INPtypelook("Mos1") + && thismodel->INPmodType != INPtypelook("Mos2") + && thismodel->INPmodType != INPtypelook("Mos3") + && thismodel->INPmodType != INPtypelook("Mos5") + && thismodel->INPmodType != INPtypelook("Mos6") + && thismodel->INPmodType != INPtypelook("Mos8") + && thismodel->INPmodType != INPtypelook("BSIM1") + && thismodel->INPmodType != INPtypelook("BSIM2") + && thismodel->INPmodType != INPtypelook("BSIM3") + && thismodel->INPmodType != INPtypelook("BSIM4") + && thismodel->INPmodType != INPtypelook("BSIM3V1") + && thismodel->INPmodType != INPtypelook("BSIM3V2") + ) { + LITERR("incorrect model type"); return; } - if(!tab->defMmod) { - /* create default M model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"M",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defMmod),uid)) - } - mdfast = tab->defMmod; - } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - LITERR(" error: no unlabeled parameter permitted on mosfet\n") + type = thismodel->INPmodType; + mdfast = (thismodel->INPmodfast); + } else { + type = INPtypelook("Mos1"); + if (type < 0) { + LITERR("Device type MOS1 not supported by this binary\n"); + return; + } + if (!tab->defMmod) { + /* create default M model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "M", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defMmod), uid)) + } + mdfast = tab->defMmod; } + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + LITERR(" error: no unlabeled parameter permitted on mosfet\n"); + } } diff --git a/src/circuit/inp2o.c b/src/circuit/inp2o.c index cb6bc1210..91ad16ed0 100644 --- a/src/circuit/inp2o.c +++ b/src/circuit/inp2o.c @@ -12,80 +12,80 @@ Author: 1990 Jaijeet S. Roychowdhury #include "inp.h" -void -INP2O(void *ckt, INPtables *tab, card *current) +void INP2O(void *ckt, INPtables * tab, card * current) { /* Oname [IC=,,,] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* the name of the model */ -INPmodel *thismodel; /* pointer to model description for user's model */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* the name of the model */ + INPmodel *thismodel; /* pointer to model description for user's model */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid for default model */ type = INPtypelook("LTRA"); - if(type < 0 ) { - LITERR("Device type LossyXmissionLine not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type LossyXmissionLine not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&nname4,1); - INPtermInsert(ckt,&nname4,tab,&node4); - INPgetTok(&line,&model,1); - if( INPlookMod(model) ) { - /* do nothing for now */ - /* no action required */ + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &nname4, 1); + INPtermInsert(ckt, &nname4, tab, &node4); + INPgetTok(&line, &model, 1); + if (INPlookMod(model)) { + /* do nothing for now */ + /* no action required */ } else { - /* - nname4 = model; - INPtermInsert(ckt,&nname4,tab,&node4); - INPgetTok(&line,&model,1); - */ + /* + nname4 = model; + INPtermInsert(ckt,&nname4,tab,&node4); + INPgetTok(&line,&model,1); + */ } - INPinsert(&model,tab); - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(type != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - mdfast = (thismodel->INPmodfast); + INPinsert(&model, tab); + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (type != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + mdfast = (thismodel->INPmodfast); } else { - if(!tab->defOmod) { - /* create default O model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"O",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defOmod),uid)) - } - mdfast = tab->defOmod; + if (!tab->defOmod) { + /* create default O model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "O", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defOmod), uid)) + } + mdfast = tab->defOmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) } diff --git a/src/circuit/inp2q.c b/src/circuit/inp2q.c index 1992854e1..896754508 100644 --- a/src/circuit/inp2q.c +++ b/src/circuit/inp2q.c @@ -11,85 +11,85 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2Q(void *ckt, INPtables *tab, card *current, void *gnode) +void INP2Q(void *ckt, INPtables * tab, card * current, void *gnode) { /* Qname [] [] [OFF] * [IC=,] */ -int mytype; /* the type we looked up */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* the name of the model */ -INPmodel *thismodel; /* pointer to model description for user's model */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid of default model */ + int mytype; /* the type we looked up */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* the name of the model */ + INPmodel *thismodel; /* pointer to model description for user's model */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid of default model */ mytype = INPtypelook("BJT"); - if(mytype < 0 ) { - LITERR("Device type BJT not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type BJT not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&model,1); - if( INPlookMod(model) ) { - /* do nothing for now */ - node4 = gnode; - /* no action required */ + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &model, 1); + if (INPlookMod(model)) { + /* do nothing for now */ + node4 = gnode; + /* no action required */ } else { - nname4 = model; - INPtermInsert(ckt,&nname4,tab,&node4); - INPgetTok(&line,&model,1); + nname4 = model; + INPtermInsert(ckt, &nname4, tab, &node4); + INPgetTok(&line, &model, 1); } - INPinsert(&model,tab); - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = (thismodel->INPmodfast); + INPinsert(&model, tab); + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = (thismodel->INPmodfast); } else { - type = mytype; - if(!tab->defQmod) { - /* create default Q model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"Q",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defQmod),uid)) - } - mdfast = tab->defQmod; + type = mytype; + if (!tab->defQmod) { + /* create default Q model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "Q", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defQmod), uid)) + } + mdfast = tab->defQmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("area",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("area", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2r.c b/src/circuit/inp2r.c index 8fdc81a2f..359de9f67 100644 --- a/src/circuit/inp2r.c +++ b/src/circuit/inp2r.c @@ -15,100 +15,101 @@ Remarks: This code is based on a version written by Serban Popescu which #include "fteext.h" #include "inp.h" -void -INP2R(void *ckt, INPtables *tab, card *current) +void INP2R(void *ckt, INPtables * tab, card * current) { /* parse a resistor card */ /* Rname [][][w=][l=][ac=] */ -int mytype; /* the type we determine resistors are */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *saveline; /* ... just in case we need to go back... */ -char *name; /* the resistor's name */ -char *model; /* the name of the resistor's model */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -double val; /* temp to held resistance */ -int error; /* error code temporary */ -int error1; /* secondary error code temporary */ -INPmodel *thismodel; /* pointer to model structure describing our model */ -void *mdfast=NULL; /* pointer to the actual model */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int mytype; /* the type we determine resistors are */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *saveline; /* ... just in case we need to go back... */ + char *name; /* the resistor's name */ + char *model; /* the name of the resistor's model */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + double val; /* temp to held resistance */ + int error; /* error code temporary */ + int error1; /* secondary error code temporary */ + INPmodel *thismodel; /* pointer to model structure describing our model */ + void *mdfast = NULL; /* pointer to the actual model */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ mytype = INPtypelook("Resistor"); - if(mytype < 0 ) { - LITERR("Device type Resistor not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type Resistor not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - val = INPevaluate(&line,&error1,1); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + val = INPevaluate(&line, &error1, 1); /* either not a number -> model, or * follows a number, so must be a model name * -> MUST be a model name (or null) */ - saveline = line; /* save then old pointer */ + saveline = line; /* save then old pointer */ - INPgetTok(&line,&model,1); - -if(*model) { /* token isn't null */ - if( INPlookMod(model) ) { /* If this is a valid model connect it */ - INPinsert(&model,tab); - thismodel = (INPmodel *)NULL; - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } + INPgetTok(&line, &model, 1); + + if (*model) { /* token isn't null */ + if (INPlookMod(model)) { /* If this is a valid model connect it */ + INPinsert(&model, tab); + thismodel = (INPmodel *) NULL; + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } mdfast = thismodel->INPmodfast; type = thismodel->INPmodType; - } - - } else { /* It is not a model */ - line = saveline; /* go back */ - type = mytype; - if(!tab->defRmod) { /* create default R model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"R",UID_MODEL,(void **)NULL); - IFC(newModel, (ckt,type,&(tab->defRmod),uid)) - } - mdfast = tab->defRmod; - } - IFC(newInstance,(ckt,mdfast,&fast,name)) - } else { /* The token is null and a default model will be created */ - type = mytype; - if(!tab->defRmod) { - /* create default R model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"R",UID_MODEL,(void **)NULL); - IFC(newModel, (ckt,type,&(tab->defRmod),uid)) - } - IFC(newInstance,(ckt,tab->defRmod,&fast,name)) + } + + } else { /* It is not a model */ + line = saveline; /* go back */ + type = mytype; + if (!tab->defRmod) { /* create default R model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "R", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defRmod), uid)) + } + mdfast = tab->defRmod; + } + IFC(newInstance, (ckt, mdfast, &fast, name)) + } else { /* The token is null and a default model will be created */ + type = mytype; + if (!tab->defRmod) { + /* create default R model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "R", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defRmod), uid)) + } + IFC(newInstance, (ckt, tab->defRmod, &fast, name)) } - if(error1 == 0) { /* got a resistance above */ - ptemp.rValue = val; - GCA(INPpName,("resistance",&ptemp,ckt,type,fast)) + if (error1 == 0) { /* got a resistance above */ + ptemp.rValue = val; + GCA(INPpName, ("resistance", &ptemp, ckt, type, fast)) } - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("resistance",&ptemp,ckt,type,fast)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("resistance", &ptemp, ckt, type, fast)) } return; } diff --git a/src/circuit/inp2s.c b/src/circuit/inp2s.c index 406df4329..ec37b770f 100644 --- a/src/circuit/inp2s.c +++ b/src/circuit/inp2s.c @@ -11,76 +11,76 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2S(void *ckt, INPtables *tab, card *current) +void INP2S(void *ckt, INPtables * tab, card * current) { /* Sname [] [IC] */ /* VOLTAGE CONTROLLED SWITCH */ -int mytype; /* the type we determine resistors are */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *model; /* the name of the resistor's model */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -INPmodel *thismodel; /* pointer to model structure describing our model */ -void *mdfast; /* pointer to the actual model */ -void *fast; /* pointer to the actual instance */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid of default model */ + int mytype; /* the type we determine resistors are */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *model; /* the name of the resistor's model */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + INPmodel *thismodel; /* pointer to model structure describing our model */ + void *mdfast; /* pointer to the actual model */ + void *fast; /* pointer to the actual instance */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid of default model */ mytype = INPtypelook("Switch"); - if(mytype < 0 ) { - LITERR("Device type Switch not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type Switch not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&nname4,1); - INPtermInsert(ckt,&nname4,tab,&node4); - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = (thismodel->INPmodfast); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &nname4, 1); + INPtermInsert(ckt, &nname4, tab, &node4); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = (thismodel->INPmodfast); } else { - type = mytype; - if(!tab->defSmod) { - /* create deafult S model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"S",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defSmod),uid)) - } - mdfast = tab->defSmod; + type = mytype; + if (!tab->defSmod) { + /* create deafult S model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "S", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defSmod), uid)) + } + mdfast = tab->defSmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - /* ignore a number */ + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + /* ignore a number */ } } diff --git a/src/circuit/inp2t.c b/src/circuit/inp2t.c index 05b619ffd..a1c08ce34 100644 --- a/src/circuit/inp2t.c +++ b/src/circuit/inp2t.c @@ -11,56 +11,55 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2T(void *ckt, INPtables *tab, card *current) +void INP2T(void *ckt, INPtables * tab, card * current) { /* Tname [TD=] * [F= [NL=]][IC=,,,] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -char *nname4; /* the fourth node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -void *node4; /* the fourth node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + char *nname4; /* the fourth node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + void *node4; /* the fourth node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ type = INPtypelook("Tranline"); - if(type < 0 ) { - LITERR("Device type Tranline not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type Tranline not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&nname4,1); - INPtermInsert(ckt,&nname4,tab,&node4); - if(!tab->defTmod) { - /* create deafult T model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"T",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defTmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &nname4, 1); + INPtermInsert(ckt, &nname4, tab, &node4); + if (!tab->defTmod) { + /* create deafult T model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "T", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defTmod), uid)) } - IFC(newInstance,(ckt,tab->defTmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - IFC(bindNode,(ckt,fast,4,node4)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) + IFC(newInstance, (ckt, tab->defTmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + IFC(bindNode, (ckt, fast, 4, node4)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) } diff --git a/src/circuit/inp2u.c b/src/circuit/inp2u.c index 18b1afc72..5a4336226 100644 --- a/src/circuit/inp2u.c +++ b/src/circuit/inp2u.c @@ -11,67 +11,67 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2U(void *ckt, INPtables *tab, card *current) +void INP2U(void *ckt, INPtables * tab, card * current) { /* Uname [l=] [n=] */ -int mytype; /* the type my lookup says URC is */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* name of the model */ -INPmodel *thismodel; /* pointer to our model descriptor */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid for default model */ + int mytype; /* the type my lookup says URC is */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* name of the model */ + INPmodel *thismodel; /* pointer to our model descriptor */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid for default model */ mytype = INPtypelook("URC"); - if(mytype < 0 ) { - LITERR("Device type URC not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type URC not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = (thismodel->INPmodfast); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = (thismodel->INPmodfast); } else { - type = mytype; - if(!tab->defUmod) { - /* create deafult U model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"U",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defUmod),uid)) - } - mdfast = tab->defUmod; + type = mytype; + if (!tab->defUmod) { + /* create deafult U model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "U", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defUmod), uid)) + } + mdfast = tab->defUmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) } diff --git a/src/circuit/inp2v.c b/src/circuit/inp2v.c index 7a0a42cb7..6ee71cb4d 100644 --- a/src/circuit/inp2v.c +++ b/src/circuit/inp2v.c @@ -11,50 +11,49 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2V(void *ckt, INPtables *tab, card *current) +void INP2V(void *ckt, INPtables * tab, card * current) { - /* Vname [ [DC] ] [AC [ [ ] ] ] - * [] */ + /* Vname [ [DC] ] [AC [ [ ] ] ] + * [] */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ type = INPtypelook("Vsource"); - if(type < 0 ) { - LITERR("Device type Vsource not supported by this binary\n") - return; + if (type < 0) { + LITERR("Device type Vsource not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - if(!tab->defVmod) { - /* create default V model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"V",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defVmod),uid)) + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + if (!tab->defVmod) { + /* create default V model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "V", UID_MODEL, (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defVmod), uid)) } - IFC(newInstance,(ckt,tab->defVmod,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("dc",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, tab->defVmod, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("dc", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inp2w.c b/src/circuit/inp2w.c index 01bdb62e1..53cccff49 100644 --- a/src/circuit/inp2w.c +++ b/src/circuit/inp2w.c @@ -11,73 +11,73 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2W(void *ckt, INPtables *tab, card *current) +void INP2W(void *ckt, INPtables * tab, card * current) { /* Wname [] [IC] */ /* CURRENT CONTROLLED SWITCH */ -int mytype; /* the type we determine resistors are */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *model; /* the name of the resistor's model */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -int error; /* error code temporary */ -INPmodel *thismodel; /* pointer to model structure describing our model */ -void *mdfast; /* pointer to the actual model */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -IFvalue *parm; /* pointer to a value structure for functions to return */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -IFuid uid; /* uid for default model */ + int mytype; /* the type we determine resistors are */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *model; /* the name of the resistor's model */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + int error; /* error code temporary */ + INPmodel *thismodel; /* pointer to model structure describing our model */ + void *mdfast; /* pointer to the actual model */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + IFvalue *parm; /* pointer to a value structure for functions to return */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + IFuid uid; /* uid for default model */ mytype = INPtypelook("CSwitch"); - if(mytype < 0 ) { - LITERR("Device type CSwitch not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type CSwitch not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - parm=INPgetValue(ckt,&line,IF_INSTANCE,tab); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + parm = INPgetValue(ckt, &line, IF_INSTANCE, tab); ptemp.uValue = parm->uValue; - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = (thismodel->INPmodfast); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = (thismodel->INPmodfast); } else { - type = mytype; - if(!tab->defWmod) { - /* create deafult W model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"W",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defWmod),uid)) - } - mdfast = tab->defWmod; + type = mytype; + if (!tab->defWmod) { + /* create deafult W model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "W", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defWmod), uid)) + } + mdfast = tab->defWmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) + IFC(newInstance, (ckt, mdfast, &fast, name)) - GCA(INPpName,("control",&ptemp,ckt,type,fast)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - /* ignore a number */ + GCA(INPpName, ("control", &ptemp, ckt, type, fast)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + /* ignore a number */ } } diff --git a/src/circuit/inp2z.c b/src/circuit/inp2z.c index 0db46a852..d04928a3c 100644 --- a/src/circuit/inp2z.c +++ b/src/circuit/inp2z.c @@ -11,73 +11,73 @@ Author: 1988 Thomas L. Quarles #include "fteext.h" #include "inp.h" -void -INP2Z(void *ckt, INPtables *tab, card *current) +void INP2Z(void *ckt, INPtables * tab, card * current) { /* Zname [] [OFF] [IC=,] */ -int mytype; /* the type we looked up */ -int type; /* the type the model says it is */ -char *line; /* the part of the current line left to parse */ -char *name; /* the resistor's name */ -char *nname1; /* the first node's name */ -char *nname2; /* the second node's name */ -char *nname3; /* the third node's name */ -void *node1; /* the first node's node pointer */ -void *node2; /* the second node's node pointer */ -void *node3; /* the third node's node pointer */ -int error; /* error code temporary */ -void *fast; /* pointer to the actual instance */ -IFvalue ptemp; /* a value structure to package resistance into */ -int waslead; /* flag to indicate that funny unlabeled number was found */ -double leadval; /* actual value of unlabeled number */ -char *model; /* the name of the model */ -INPmodel *thismodel; /* pointer to model description for user's model */ -void *mdfast; /* pointer to the actual model */ -IFuid uid; /* uid for default model */ + int mytype; /* the type we looked up */ + int type; /* the type the model says it is */ + char *line; /* the part of the current line left to parse */ + char *name; /* the resistor's name */ + char *nname1; /* the first node's name */ + char *nname2; /* the second node's name */ + char *nname3; /* the third node's name */ + void *node1; /* the first node's node pointer */ + void *node2; /* the second node's node pointer */ + void *node3; /* the third node's node pointer */ + int error; /* error code temporary */ + void *fast; /* pointer to the actual instance */ + IFvalue ptemp; /* a value structure to package resistance into */ + int waslead; /* flag to indicate that funny unlabeled number was found */ + double leadval; /* actual value of unlabeled number */ + char *model; /* the name of the model */ + INPmodel *thismodel; /* pointer to model description for user's model */ + void *mdfast; /* pointer to the actual model */ + IFuid uid; /* uid for default model */ mytype = INPtypelook("MES"); - if(mytype < 0 ) { - LITERR("Device type MES not supported by this binary\n") - return; + if (mytype < 0) { + LITERR("Device type MES not supported by this binary\n"); + return; } line = current->line; - INPgetTok(&line,&name,1); - INPinsert(&name,tab); - INPgetTok(&line,&nname1,1); - INPtermInsert(ckt,&nname1,tab,&node1); - INPgetTok(&line,&nname2,1); - INPtermInsert(ckt,&nname2,tab,&node2); - INPgetTok(&line,&nname3,1); - INPtermInsert(ckt,&nname3,tab,&node3); - INPgetTok(&line,&model,1); - INPinsert(&model,tab); - thismodel = (INPmodel *)NULL; - current->error = INPgetMod(ckt,model,&thismodel,tab); - if(thismodel != NULL) { - if(mytype != thismodel->INPmodType) { - LITERR("incorrect model type") - return; - } - type = mytype; - mdfast = (thismodel->INPmodfast); + INPgetTok(&line, &name, 1); + INPinsert(&name, tab); + INPgetTok(&line, &nname1, 1); + INPtermInsert(ckt, &nname1, tab, &node1); + INPgetTok(&line, &nname2, 1); + INPtermInsert(ckt, &nname2, tab, &node2); + INPgetTok(&line, &nname3, 1); + INPtermInsert(ckt, &nname3, tab, &node3); + INPgetTok(&line, &model, 1); + INPinsert(&model, tab); + thismodel = (INPmodel *) NULL; + current->error = INPgetMod(ckt, model, &thismodel, tab); + if (thismodel != NULL) { + if (mytype != thismodel->INPmodType) { + LITERR("incorrect model type"); + return; + } + type = mytype; + mdfast = (thismodel->INPmodfast); } else { - type = mytype; - if(!tab->defZmod) { - /* create default Z model */ - IFnewUid(ckt,&uid,(IFuid)NULL,"Z",UID_MODEL,(void**)NULL); - IFC(newModel,(ckt,type,&(tab->defZmod),uid)) - } - mdfast = tab->defZmod; + type = mytype; + if (!tab->defZmod) { + /* create default Z model */ + IFnewUid(ckt, &uid, (IFuid) NULL, "Z", UID_MODEL, + (void **) NULL); + IFC(newModel, (ckt, type, &(tab->defZmod), uid)) + } + mdfast = tab->defZmod; } - IFC(newInstance,(ckt,mdfast,&fast,name)) - IFC(bindNode,(ckt,fast,1,node1)) - IFC(bindNode,(ckt,fast,2,node2)) - IFC(bindNode,(ckt,fast,3,node3)) - PARSECALL((&line,ckt,type,fast,&leadval,&waslead,tab)) - if(waslead) { - ptemp.rValue = leadval; - GCA(INPpName,("area",&ptemp,ckt,type,fast)) + IFC(newInstance, (ckt, mdfast, &fast, name)) + IFC(bindNode, (ckt, fast, 1, node1)) + IFC(bindNode, (ckt, fast, 2, node2)) + IFC(bindNode, (ckt, fast, 3, node3)) + PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab)) + if (waslead) { + ptemp.rValue = leadval; + GCA(INPpName, ("area", &ptemp, ckt, type, fast)) } } diff --git a/src/circuit/inpaname.c b/src/circuit/inpaname.c index a461a7cac..21db422d7 100644 --- a/src/circuit/inpaname.c +++ b/src/circuit/inpaname.c @@ -20,19 +20,19 @@ Author: 1985 Thomas L. Quarles #include "inp.h" int -INPaName(char *parm, IFvalue *val, void *ckt, int *dev, char *devnam, void **fast, IFsimulator *sim, int *dataType, IFvalue *selector) - /* the name of the parameter to set */ - /* the parameter union containing the value to set */ - /* the circuit this device is a member of */ - /* the device type code to the device being parsed */ - /* the name of the device */ - /* direct pointer to device being parsed */ - /* the simulator data structure */ - /* the datatype of the returned value structure */ - /* data sub-selector for questions */ - +INPaName(char *parm, IFvalue * val, void *ckt, int *dev, char *devnam, + void **fast, IFsimulator * sim, int *dataType, IFvalue * selector) + /* the name of the parameter to set */ + /* the parameter union containing the value to set */ + /* the circuit this device is a member of */ + /* the device type code to the device being parsed */ + /* the name of the device */ + /* direct pointer to device being parsed */ + /* the simulator data structure */ + /* the datatype of the returned value structure */ + /* data sub-selector for questions */ { - int error; /* int to store evaluate error return codes in */ + int error; /* int to store evaluate error return codes in */ int i; /* find the instance - don't know about model, so use null there, @@ -40,29 +40,33 @@ INPaName(char *parm, IFvalue *val, void *ckt, int *dev, char *devnam, void **fas * (name, type, direct pointer) - the type and direct pointer * WILL be set on return unless error is not OK */ - error = (*(sim->findInstance))(ckt,dev,fast,devnam,(void *)NULL, - (char *)NULL); - if(error) return(error); + error = (*(sim->findInstance)) (ckt, dev, fast, devnam, (void *) NULL, + (char *) NULL); + if (error) + return (error); /* now find the parameter - hunt through the parameter tables for * this device type and look for a name match of an 'ask'able * parameter. */ - for(i=0;i<(*(*(sim->devices)[*dev]).numInstanceParms);i++) { - if(strcmp(parm, - ((*(sim->devices)[*dev]).instanceParms[i].keyword))==0 && - (((*(sim->devices)[*dev]).instanceParms[i].dataType)&IF_ASK)) { - /* found it, so we ask the question using the device info we got - * above and put the results in the IFvalue structure our caller - * gave us originally - */ - error = (*(sim->askInstanceQuest))(ckt,*fast, - (*(sim->devices)[*dev]).instanceParms[i].id,val, - selector); - if(dataType) *dataType = - (*(sim->devices)[*dev]).instanceParms[i].dataType; - return(error); - } + for (i = 0; i < (*(*(sim->devices)[*dev]).numInstanceParms); i++) { + if (strcmp(parm, + ((*(sim->devices)[*dev]).instanceParms[i].keyword)) == 0 + && (((*(sim->devices)[*dev]).instanceParms[i].dataType) & + IF_ASK)) { + /* found it, so we ask the question using the device info we got + * above and put the results in the IFvalue structure our caller + * gave us originally + */ + error = (*(sim->askInstanceQuest)) (ckt, *fast, + (*(sim->devices)[*dev]). + instanceParms[i].id, val, + selector); + if (dataType) + *dataType = + (*(sim->devices)[*dev]).instanceParms[i].dataType; + return (error); + } } - return(E_BADPARM); + return (E_BADPARM); } diff --git a/src/circuit/inpapnam.c b/src/circuit/inpapnam.c index 88a53cd87..7789d7b96 100644 --- a/src/circuit/inpapnam.c +++ b/src/circuit/inpapnam.c @@ -12,19 +12,23 @@ Author: 1985 Thomas L. Quarles #include "inp.h" int -INPapName(void *ckt, int type, void *analPtr, char *parmname, IFvalue *value) +INPapName(void *ckt, int type, void *analPtr, char *parmname, + IFvalue * value) { int i; if (parmname && ft_sim->analyses[type]) { - for(i=0;ianalyses[type]->numParms;i++) + for (i = 0; i < ft_sim->analyses[type]->numParms; i++) if (strcmp(parmname, - ft_sim->analyses[type]->analysisParms[i].keyword) == 0) - { - return (*(ft_sim->setAnalysisParm))(ckt, analPtr, - ft_sim->analyses[type]->analysisParms[i].id, - value, (IFvalue*)NULL); + ft_sim->analyses[type]->analysisParms[i].keyword) == + 0) { + return (*(ft_sim->setAnalysisParm)) (ckt, analPtr, + ft_sim-> + analyses[type]-> + analysisParms[i].id, + value, + (IFvalue *) NULL); } } - return(E_BADPARM); + return (E_BADPARM); } diff --git a/src/circuit/inpcfix.c b/src/circuit/inpcfix.c index a0969b1bd..d83f56582 100644 --- a/src/circuit/inpcfix.c +++ b/src/circuit/inpcfix.c @@ -12,14 +12,13 @@ Author: 1985 Thomas L. Quarles #include "inp.h" -void -INPcaseFix(register char *string) +void INPcaseFix(register char *string) { - while(*string) { - if(isupper(*string)) { - *string = tolower(*string); - } - string++; + while (*string) { + if (isupper(*string)) { + *string = tolower(*string); + } + string++; } } diff --git a/src/circuit/inpdomod.c b/src/circuit/inpdomod.c index f5bbc41e0..8db3fe9da 100644 --- a/src/circuit/inpdomod.c +++ b/src/circuit/inpdomod.c @@ -10,218 +10,251 @@ Author: 1985 Thomas L. Quarles #include "inp.h" -char * -INPdomodel(void *ckt, card *image, INPtables *tab) +char *INPdomodel(void *ckt, card * image, INPtables * tab) { char *modname; - int type=-1; + int type = -1; int lev; char *typename; - char *err = (char *)NULL; + char *err = (char *) NULL; char *line; line = image->line; - INPgetTok(&line,&modname,1); /* throw away '.model' */ - INPgetTok(&line,&modname,1); - INPinsert(&modname,tab); - INPgetTok(&line,&typename,1); - if( (strcmp(typename,"npn") == 0)||(strcmp(typename,"pnp")==0) ) { - type = INPtypelook("BJT"); - if(type < 0) { - err = INPmkTemp("Device type BJT not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"d") == 0) { - type = INPtypelook("Diode"); - if(type < 0) { - err = INPmkTemp("Device type Diode not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if( (strcmp(typename,"njf") == 0) || (strcmp(typename,"pjf") == 0)){ - err = INPfindLev(line,&lev); - switch(lev) { - case 0: - case 1: - type = INPtypelook("JFET"); - if(type < 0) { - err = INPmkTemp( - "Device type JFET not available in this binary\n"); - } - break; - case 2: - type = INPtypelook("JFET2"); - if(type < 0) { - err = INPmkTemp( - "Device type JFET2 not available in this binary\n"); - } - break; - default: /* placeholder; use level 3 for the next model */ - err = INPmkTemp( - "Only JFET device levels 1-2 are supported in this binary\n"); - break; - } - INPmakeMod(modname,type,image); - } else if( (strcmp(typename,"nmf") == 0) || (strcmp(typename,"pmf")==0) ) { - type = INPtypelook("MES"); - if(type < 0) { - err = INPmkTemp("Device type MES not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"urc") == 0) { - type = INPtypelook("URC"); - if(type < 0) { - err = INPmkTemp("Device type URC not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if( (strcmp(typename,"nmos")==0) || (strcmp(typename,"pmos")==0) ) { - err = INPfindLev(line,&lev); - switch(lev) { - case 0: - case 1: - type = INPtypelook("Mos1"); - if(type < 0) { - err = INPmkTemp( - "Device type MOS1 not available in this binary\n"); - } - break; - case 2: - type = INPtypelook("Mos2"); - if(type < 0) { - err = INPmkTemp( - "Device type MOS2 not available in this binary\n"); - } - break; - case 3: - type = INPtypelook("Mos3"); - if(type < 0) { - err = INPmkTemp( - "Device type MOS3 not available in this binary\n"); - } - break; - case 4: - type = INPtypelook("BSIM1"); - if(type < 0) { - err = INPmkTemp( - "Device type BSIM1 not available in this binary\n"); - } - break; - case 5: - type = INPtypelook("BSIM2"); - if(type < 0) { - err = INPmkTemp( - "Device type BSIM2 not available in this binary\n"); - } - break; - case 6: - type = INPtypelook("Mos6"); - if(type < 0) { - err = INPmkTemp( - "Device type MOS6 not available in this binary\n"); - } - break; - case 7: - type = INPtypelook("MOS7"); - if(type < 0) { - err = INPmkTemp( - "Device type MOS7 not available in this binary\n"); - } - break; - case 8: - type = INPtypelook("BSIM3"); - if(type < 0) { - err = INPmkTemp( - "Device type BSIM3 not available in this binary\n"); - } - break; - case 9: - type = INPtypelook("BSIMsoi"); - if(type < 0) { - err = INPmkTemp( - "Device type BSIMsoi not available in this binary\n"); - } - break; - case 14: - type = INPtypelook("BSIM4"); - if(type < 0) { - err = INPmkTemp( - "Device type BSIM4 not available in this binary\n"); } - break; - case 15: - type = INPtypelook("BSIM5"); - if(type < 0) { - err = INPmkTemp( - "Placeholder: Device type BSIM5 not available in this binary\n"); - } - break; - case 16: - type = INPtypelook("BSIM6"); - if(type < 0) { - err = INPmkTemp( - "Placeholder: Device type BSIM6 not available in this binary\n"); - } - break; + INPgetTok(&line, &modname, 1); /* throw away '.model' */ + INPgetTok(&line, &modname, 1); + INPinsert(&modname, tab); + INPgetTok(&line, &typename, 1); + if ((strcmp(typename, "npn") == 0) || (strcmp(typename, "pnp") == 0)) { + type = INPtypelook("BJT"); + if (type < 0) { + err = + INPmkTemp + ("Device type BJT not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "d") == 0) { + type = INPtypelook("Diode"); + if (type < 0) { + err = + INPmkTemp + ("Device type Diode not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if ((strcmp(typename, "njf") == 0) + || (strcmp(typename, "pjf") == 0)) { + err = INPfindLev(line, &lev); + switch (lev) { + case 0: + case 1: + type = INPtypelook("JFET"); + if (type < 0) { + err = + INPmkTemp + ("Device type JFET not available in this binary\n"); + } + break; + case 2: + type = INPtypelook("JFET2"); + if (type < 0) { + err = + INPmkTemp + ("Device type JFET2 not available in this binary\n"); + } + break; + default: /* placeholder; use level 3 for the next model */ + err = + INPmkTemp + ("Only JFET device levels 1-2 are supported in this binary\n"); + break; + } + INPmakeMod(modname, type, image); + } else if ((strcmp(typename, "nmf") == 0) + || (strcmp(typename, "pmf") == 0)) { + type = INPtypelook("MES"); + if (type < 0) { + err = + INPmkTemp + ("Device type MES not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "urc") == 0) { + type = INPtypelook("URC"); + if (type < 0) { + err = + INPmkTemp + ("Device type URC not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if ((strcmp(typename, "nmos") == 0) + || (strcmp(typename, "pmos") == 0)) { + err = INPfindLev(line, &lev); + switch (lev) { + case 0: + case 1: + type = INPtypelook("Mos1"); + if (type < 0) { + err = + INPmkTemp + ("Device type MOS1 not available in this binary\n"); + } + break; + case 2: + type = INPtypelook("Mos2"); + if (type < 0) { + err = + INPmkTemp + ("Device type MOS2 not available in this binary\n"); + } + break; + case 3: + type = INPtypelook("Mos3"); + if (type < 0) { + err = + INPmkTemp + ("Device type MOS3 not available in this binary\n"); + } + break; + case 4: + type = INPtypelook("BSIM1"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIM1 not available in this binary\n"); + } + break; + case 5: + type = INPtypelook("BSIM2"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIM2 not available in this binary\n"); + } + break; + case 6: + type = INPtypelook("Mos6"); + if (type < 0) { + err = + INPmkTemp + ("Device type MOS6 not available in this binary\n"); + } + break; + case 7: + type = INPtypelook("MOS7"); + if (type < 0) { + err = + INPmkTemp + ("Device type MOS7 not available in this binary\n"); + } + break; + case 8: + type = INPtypelook("BSIM3"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIM3 not available in this binary\n"); + } + break; + case 9: + type = INPtypelook("BSIMsoi"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIMsoi not available in this binary\n"); + } + break; + case 14: + type = INPtypelook("BSIM4"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIM4 not available in this binary\n");} + break; + case 15: + type = INPtypelook("BSIM5"); + if (type < 0) { + err = + INPmkTemp + ("Placeholder: Device type BSIM5 not available in this binary\n"); + } + break; + case 16: + type = INPtypelook("BSIM6"); + if (type < 0) { + err = + INPmkTemp + ("Placeholder: Device type BSIM6 not available in this binary\n"); + } + break; case 49: - type = INPtypelook("BSIM3V1"); - if (type < 0) { - err = INPmkTemp( - "Device type BSIM3V1 not available in this binary\n"); - } - break; - - - case 50: - type = INPtypelook("BSIM3V2"); - if(type < 0) { - err = INPmkTemp( - "Device type BSIM3V2 not available in this binary\n"); - } - break; - default: /* placeholder; use level xxx for the next model */ - err = INPmkTemp( - "Only MOS device levels 1-6,8,14 are supported in this binary\n"); - break; - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"r") == 0) { - type = INPtypelook("Resistor"); - if(type < 0) { - err = INPmkTemp( - "Device type Resistor not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"c") == 0) { - type = INPtypelook("Capacitor"); - if(type < 0) { - err = INPmkTemp( - "Device type Capacitor not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"sw") == 0) { - type = INPtypelook("Switch"); - if(type < 0) { - err = INPmkTemp( - "Device type Switch not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"csw") == 0) { - type = INPtypelook("CSwitch"); - if(type < 0) { - err = INPmkTemp( - "Device type CSwitch not available in this binary\n"); - } - INPmakeMod(modname,type,image); - } else if(strcmp(typename,"ltra") == 0) { - type = INPtypelook("LTRA"); - if(type < 0) { - err = INPmkTemp( - "Device type LTRA not available in this binary\n"); - } - INPmakeMod(modname,type,image); + type = INPtypelook("BSIM3V1"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIM3V1 not available in this binary\n"); + } + break; + + + case 50: + type = INPtypelook("BSIM3V2"); + if (type < 0) { + err = + INPmkTemp + ("Device type BSIM3V2 not available in this binary\n"); + } + break; + default: /* placeholder; use level xxx for the next model */ + err = + INPmkTemp + ("Only MOS device levels 1-6,8,14 are supported in this binary\n"); + break; + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "r") == 0) { + type = INPtypelook("Resistor"); + if (type < 0) { + err = + INPmkTemp + ("Device type Resistor not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "c") == 0) { + type = INPtypelook("Capacitor"); + if (type < 0) { + err = + INPmkTemp + ("Device type Capacitor not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "sw") == 0) { + type = INPtypelook("Switch"); + if (type < 0) { + err = + INPmkTemp + ("Device type Switch not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "csw") == 0) { + type = INPtypelook("CSwitch"); + if (type < 0) { + err = + INPmkTemp + ("Device type CSwitch not available in this binary\n"); + } + INPmakeMod(modname, type, image); + } else if (strcmp(typename, "ltra") == 0) { + type = INPtypelook("LTRA"); + if (type < 0) { + err = + INPmkTemp + ("Device type LTRA not available in this binary\n"); + } + INPmakeMod(modname, type, image); } else { - type = -1; - err = (char *)MALLOC(35 + strlen(typename)); - (void)sprintf(err,"unknown model type %s - ignored\n",typename); + type = -1; + err = (char *) MALLOC(35 + strlen(typename)); + (void) sprintf(err, "unknown model type %s - ignored\n", typename); } - return(err); + return (err); } diff --git a/src/circuit/inpdoopt.c b/src/circuit/inpdoopt.c deleted file mode 100644 index 9058994e3..000000000 --- a/src/circuit/inpdoopt.c +++ /dev/null @@ -1,84 +0,0 @@ -/********** -Copyright 1990 Regents of the University of California. All rights reserved. -Author: 1985 Thomas L. Quarles -**********/ - - /* INPdoOpts(ckt,option card) - * parse the options off of the given option card and add them to - * the given circuit - */ - -#include "ngspice.h" -#include -#include "inpdefs.h" -#include "ifsim.h" -#include "cpdefs.h" -#include "fteext.h" -#include "inp.h" - -/* MW. this is never called - look at inp2dot.c -void -INPdoOpts(void *ckt, void *anal, card *optCard, INPtables *tab) -{ - char *line; - char *token; - char *errmsg; - IFvalue *val; - int error; - int i; - int which; - IFanalysis *prm=NULL; - - which = -1; - i=0; - for(i=0;inumAnalyses;i++) { - prm = ft_sim->analyses[i]; - if(strcmp(prm->name,"options")==0) { - which = i; - break; - } - i++; - } - if(which == -1) { - optCard->error = INPerrCat(optCard->error,INPmkTemp( - "errr: analysis options table not found\n")); - return; - } - line = optCard->line; - INPgetTok(&line,&token,1); * throw away '.option' * - while (*line) { - INPgetTok(&line,&token,1); - for(i=0;inumParms;i++) { - if(strcmp(token,prm->analysisParms[i].keyword) == 0) { - if(!(prm->analysisParms[i].dataType & IF_UNIMP_MASK)) { - errmsg = (char *)MALLOC((45+strlen(token)) * sizeof(char)); - (void) sprintf(errmsg, - " Warning: %s not yet implemented - ignored \n",token); - optCard->error = INPerrCat(optCard->error,errmsg); - val = INPgetValue(ckt,&line, - prm->analysisParms[i].dataType, tab); - break; - } - if(prm->analysisParms[i].dataType & IF_SET) { - val = INPgetValue(ckt,&line, - prm->analysisParms[i].dataType&IF_VARTYPES, tab); - error = (*(ft_sim->setAnalysisParm))(ckt,anal, - prm->analysisParms[i].id,val,(IFvalue*)NULL); - if(error) { - errmsg =(char *)MALLOC((35+strlen(token))*sizeof(char)); - (void) sprintf(errmsg, - "Warning: can't set optione %s\n", token); - optCard->error = INPerrCat(optCard->error, errmsg); - } - break; - } - } - } - if(i == prm->numParms) { - errmsg = (char *)MALLOC(100 * sizeof(char)); - (void) strcpy(errmsg," Error: unknown option - ignored\n"); - optCard->error = INPerrCat(optCard->error,errmsg); - } - } -} -*/ diff --git a/src/circuit/inpdpar.c b/src/circuit/inpdpar.c index 0d8def06c..1b6d0cf35 100644 --- a/src/circuit/inpdpar.c +++ b/src/circuit/inpdpar.c @@ -20,18 +20,16 @@ Author: 1985 Thomas L. Quarles #include "fteext.h" #include "inp.h" -char * -INPdevParse(char **line, void *ckt, int dev, void *fast, double *leading, int *waslead, INPtables *tab) - /* the line to parse */ - /* the circuit this device is a member of */ - /* the device type code to the device being parsed */ - /* direct pointer to device being parsed */ - /* the optional leading numeric parameter */ - /* flag - 1 if leading double given, 0 otherwise */ - - +char *INPdevParse(char **line, void *ckt, int dev, void *fast, + double *leading, int *waslead, INPtables * tab) + /* the line to parse */ + /* the circuit this device is a member of */ + /* the device type code to the device being parsed */ + /* direct pointer to device being parsed */ + /* the optional leading numeric parameter */ + /* flag - 1 if leading double given, 0 otherwise */ { - int error; /* int to store evaluate error return codes in */ + int error; /* int to store evaluate error return codes in */ char *parm; char *errbuf; int i; @@ -39,36 +37,44 @@ INPdevParse(char **line, void *ckt, int dev, void *fast, double *leading, int *w /* check for leading value */ *waslead = 0; - *leading = INPevaluate(line,&error,1); - if(error == 0) { /* found a good leading number */ - *waslead = 1; - } else *leading=0.0; + *leading = INPevaluate(line, &error, 1); + if (error == 0) { /* found a good leading number */ + *waslead = 1; + } else + *leading = 0.0; while (**line != (char) 0) { - error = INPgetTok(line,&parm,1); + error = INPgetTok(line, &parm, 1); if (!*parm) continue; - if(error) return(INPerror(error)); - for(i=0;i<(*(*(ft_sim->devices)[dev]).numInstanceParms);i++) { - if(strcmp(parm, - ((*(ft_sim->devices)[dev]).instanceParms[i].keyword)) ==0) { - val = INPgetValue(ckt,line, - ((*(ft_sim->devices)[dev]).instanceParms[i].dataType), - tab); - if (!val) - return (INPerror(E_PARMVAL)); - error = (*(ft_sim->setInstanceParm))(ckt,fast, - (*(ft_sim->devices)[dev]).instanceParms[i].id, - val,(IFvalue*)NULL); - if(error) return(INPerror(error)); - break; - } - } - if(i==(*(*(ft_sim->devices)[dev]).numInstanceParms)) { - errbuf = MALLOC(strlen(parm)+25); - (void)sprintf(errbuf," unknown parameter (%s) \n",parm); - return(errbuf); - } - FREE(parm); + if (error) + return (INPerror(error)); + for (i = 0; i < (*(*(ft_sim->devices)[dev]).numInstanceParms); i++) { + if (strcmp(parm, + ((*(ft_sim->devices)[dev]).instanceParms[i]. + keyword)) == 0) { + val = + INPgetValue(ckt, line, + ((*(ft_sim->devices)[dev]). + instanceParms[i].dataType), tab); + if (!val) + return (INPerror(E_PARMVAL)); + error = (*(ft_sim->setInstanceParm)) (ckt, fast, + (*(ft_sim->devices) + [dev]). + instanceParms[i].id, + val, + (IFvalue *) NULL); + if (error) + return (INPerror(error)); + break; + } + } + if (i == (*(*(ft_sim->devices)[dev]).numInstanceParms)) { + errbuf = MALLOC(strlen(parm) + 25); + (void) sprintf(errbuf, " unknown parameter (%s) \n", parm); + return (errbuf); + } + FREE(parm); } - return((char *)NULL); + return ((char *) NULL); } diff --git a/src/circuit/inperrc.c b/src/circuit/inperrc.c index 44d8b559e..e2459d45a 100644 --- a/src/circuit/inperrc.c +++ b/src/circuit/inperrc.c @@ -11,24 +11,25 @@ Author: 1985 Thomas L. Quarles #include "inp.h" -char * -INPerrCat(char *a, char *b) +char *INPerrCat(char *a, char *b) { - if(a != (char *)NULL) { - if(b == (char *)NULL) { /* a valid, b null, return a */ - return(a); - } else { /* both valid - hard work...*/ - register char *errtmp; - errtmp = (char *)MALLOC( (strlen(a) + strlen(b)+2)*sizeof(char)); - (void) strcpy(errtmp,a); - (void) strcat(errtmp,"\n"); - (void) strcat(errtmp,b); - FREE(a); - FREE(b); - return(errtmp); - } - } else { /* a null, so return b */ - return(b); + if (a != (char *) NULL) { + if (b == (char *) NULL) { /* a valid, b null, return a */ + return (a); + } else { /* both valid - hard work... */ + register char *errtmp; + errtmp = + (char *) MALLOC((strlen(a) + strlen(b) + 2) * + sizeof(char)); + (void) strcpy(errtmp, a); + (void) strcat(errtmp, "\n"); + (void) strcat(errtmp, b); + FREE(a); + FREE(b); + return (errtmp); + } + } else { /* a null, so return b */ + return (b); } } diff --git a/src/circuit/inperror.c b/src/circuit/inperror.c index 265415b8c..995381447 100644 --- a/src/circuit/inperror.c +++ b/src/circuit/inperror.c @@ -15,8 +15,7 @@ Author: 1985 Thomas L. Quarles #include "sperror.h" #include "inp.h" -char * -INPerror(int type) +char *INPerror(int type) { char *val; char ebuf[513]; @@ -24,9 +23,9 @@ INPerror(int type) val = SPerror(type); if (!val) - return(val); + return (val); - if(errRtn) + if (errRtn) sprintf(ebuf, "%s detected in routine \"%s\"\n", val, errRtn); else sprintf(ebuf, "%s\n", val); @@ -36,6 +35,5 @@ INPerror(int type) if (val) strcpy(val, ebuf); - return(val); + return (val); } - diff --git a/src/circuit/inpeval.c b/src/circuit/inpeval.c index 1f72902cb..2c055719e 100644 --- a/src/circuit/inpeval.c +++ b/src/circuit/inpeval.c @@ -9,164 +9,197 @@ Author: 1985 Thomas L. Quarles #include "inpdefs.h" #include "inp.h" -double -INPevaluate(char **line, int *error, int gobble) - /* non-zero to gobble rest of token, zero to leave it alone */ +double INPevaluate(char **line, int *error, int gobble) + /* non-zero to gobble rest of token, zero to leave it alone */ { - char * token; - char * here; + char *token; + char *here; double mantis; int expo1; int expo2; int sign; int expsgn; - char * tmpline; + char *tmpline; /* setup */ tmpline = *line; - if(gobble) { - *error = INPgetUTok(line,&token,1); - if(*error) return((double)0.0); + if (gobble) { + *error = INPgetUTok(line, &token, 1); + if (*error) + return ((double) 0.0); } else { - token = *line; - *error = 0; + token = *line; + *error = 0; } - mantis=0; - expo1=0; - expo2=0; - sign=1; - expsgn=1; + mantis = 0; + expo1 = 0; + expo2 = 0; + sign = 1; + expsgn = 1; /* loop through all of the input token */ here = token; - if(*here == '+') here++; /* plus, so do nothing except skip it */ - if(*here == '-') { /* minus, so skip it, and change sign */ - here++; - sign = -1; + if (*here == '+') + here++; /* plus, so do nothing except skip it */ + if (*here == '-') { /* minus, so skip it, and change sign */ + here++; + sign = -1; } - if( (*here == 0) || ((!(isdigit(*here))) && (*here != '.'))) { - /* number looks like just a sign! */ - *error = 1; - /* back out the 'gettok' operation */ - *line = tmpline; - if(gobble) { FREE(token); }else{ *line=here;} - return(0); + if ((*here == 0) || ((!(isdigit(*here))) && (*here != '.'))) { + /* number looks like just a sign! */ + *error = 1; + /* back out the 'gettok' operation */ + *line = tmpline; + if (gobble) { + FREE(token); + } else { + *line = here; + } + return (0); } - while(isdigit(*here)) { - /* digit, so accumulate it. */ - mantis=10*mantis+*here-'0'; - here++; + while (isdigit(*here)) { + /* digit, so accumulate it. */ + mantis = 10 * mantis + *here - '0'; + here++; } - if(*here == 0) { - /* reached the end of token - done. */ - if(gobble) { FREE(token); }else{ *line=here;} - return ((double)mantis*sign); + if (*here == 0) { + /* reached the end of token - done. */ + if (gobble) { + FREE(token); + } else { + *line = here; + } + return ((double) mantis * sign); } - if(*here == ':') { + if (*here == ':') { /* hack for subcircuit node numbering */ *error = 1; *line = tmpline; return 0.0; } /* after decimal point! */ - if(*here == '.') { - /* found a decimal point! */ - here++; /* skip to next character */ - if(*here == 0) { - /* number ends in the decimal point */ - if(gobble) { FREE(token); }else{ *line=here;} - return ((double)mantis*sign); - } - while(isdigit(*here)) { - /* digit, so accumulate it. */ - mantis=10*mantis+*here - '0'; - expo1=expo1-1; - if(*here == 0) { - /* reached the end of token - done. */ - if(gobble) { FREE(token); }else{ *line=here;} - return (mantis*sign*pow(10.,(double)expo1)); - } - here++; - } + if (*here == '.') { + /* found a decimal point! */ + here++; /* skip to next character */ + if (*here == 0) { + /* number ends in the decimal point */ + if (gobble) { + FREE(token); + } else { + *line = here; + } + return ((double) mantis * sign); + } + while (isdigit(*here)) { + /* digit, so accumulate it. */ + mantis = 10 * mantis + *here - '0'; + expo1 = expo1 - 1; + if (*here == 0) { + /* reached the end of token - done. */ + if (gobble) { + FREE(token); + } else { + *line = here; + } + return (mantis * sign * pow(10., (double) expo1)); + } + here++; + } } /* now look for "E","e",etc to indicate an exponent */ - if((*here == 'E') || (*here == 'e') || (*here == 'D') || (*here == 'd') ) { - /* have an exponent, so skip the e */ - here++; - /* now look for exponent sign */ - if(*here == '+') here++; /* just skip + */ - if(*here == '-') { - here++; /* skip over minus sign */ - expsgn = -1; /* and make a negative exponent */ - /* now look for the digits of the exponent */ - } - while (isdigit(*here)) { - expo2=10*expo2+*here - '0'; - here++; - } + if ((*here == 'E') || (*here == 'e') || (*here == 'D') + || (*here == 'd')) { + /* have an exponent, so skip the e */ + here++; + /* now look for exponent sign */ + if (*here == '+') + here++; /* just skip + */ + if (*here == '-') { + here++; /* skip over minus sign */ + expsgn = -1; /* and make a negative exponent */ + /* now look for the digits of the exponent */ + } + while (isdigit(*here)) { + expo2 = 10 * expo2 + *here - '0'; + here++; + } } /* now we have all of the numeric part of the number, time to * look for the scale factor (alphabetic) */ - switch(*here) { - case 't': - case 'T': - expo1=expo1+12; - break; - case 'g': - case 'G': - expo1=expo1+9; - break; - case 'k': - case 'K': - expo1=expo1+3; - break; - case 'u': - case 'U': - expo1=expo1-6; - break; - case 'n': - case 'N': - expo1=expo1-9; - break; - case 'p': - case 'P': - expo1=expo1-12; - break; - case 'f': - case 'F': - expo1=expo1-15; - break; - case 'm': - case 'M': - { - /* special case for m - may be m or mil or meg */ - if(*(here+1) != 0 && *(here+2) != 0) { - /* at least 2 characters, so check them. */ - if((*(here+1) == 'E') || (*(here+1) == 'e')) { - if((*(here+2) == 'G') || (*(here+2) == 'g')) { - expo1=expo1+6; - if(gobble) { FREE(token); }else{ *line=here;} - return (sign*mantis* - pow((double)10,(double)(expo1+expsgn*expo2))); - } - } - else if ((*(here+1) == 'I') || (*(here+1) == 'i')) { - if( (*(here+2) == 'L') || (*(here+2) == 'l')) { - expo1=expo1-6; - mantis=mantis*25.4; - if(gobble) { FREE(token); }else{ *line=here;} - return (sign*mantis* - pow((double)10,(double)(expo1+expsgn*expo2))); - } - } - } - /* not either special case, so just m => 1e-3 */ - expo1=expo1-3; - } - break; - default: - break; + switch (*here) { + case 't': + case 'T': + expo1 = expo1 + 12; + break; + case 'g': + case 'G': + expo1 = expo1 + 9; + break; + case 'k': + case 'K': + expo1 = expo1 + 3; + break; + case 'u': + case 'U': + expo1 = expo1 - 6; + break; + case 'n': + case 'N': + expo1 = expo1 - 9; + break; + case 'p': + case 'P': + expo1 = expo1 - 12; + break; + case 'f': + case 'F': + expo1 = expo1 - 15; + break; + case 'm': + case 'M': + { + /* special case for m - may be m or mil or meg */ + if (*(here + 1) != 0 && *(here + 2) != 0) { + /* at least 2 characters, so check them. */ + if ((*(here + 1) == 'E') || (*(here + 1) == 'e')) { + if ((*(here + 2) == 'G') || (*(here + 2) == 'g')) { + expo1 = expo1 + 6; + if (gobble) { + FREE(token); + } else { + *line = here; + } + return (sign * mantis * + pow((double) 10, + (double) (expo1 + expsgn * expo2))); + } + } else if ((*(here + 1) == 'I') || (*(here + 1) == 'i')) { + if ((*(here + 2) == 'L') || (*(here + 2) == 'l')) { + expo1 = expo1 - 6; + mantis = mantis * 25.4; + if (gobble) { + FREE(token); + } else { + *line = here; + } + return (sign * mantis * + pow((double) 10, + (double) (expo1 + expsgn * expo2))); + } + } + } + /* not either special case, so just m => 1e-3 */ + expo1 = expo1 - 3; + } + break; + default: + break; } - if(gobble) { FREE(token); }else{ *line=here;} - return (sign*mantis*pow((double)10,(double)(expo1+expsgn*expo2))); + if (gobble) { + FREE(token); + } else { + *line = here; + } + return (sign * mantis * + pow((double) 10, (double) (expo1 + expsgn * expo2))); } diff --git a/src/circuit/inpfindl.c b/src/circuit/inpfindl.c index 02504b0e2..52aed3be5 100644 --- a/src/circuit/inpfindl.c +++ b/src/circuit/inpfindl.c @@ -16,52 +16,53 @@ Modified: 1999 Paolo Nenzi - Now we can use a two digits level code - #include "inpdefs.h" #include "inp.h" -char * -INPfindLev(char *line, int *level) +char *INPfindLev(char *line, int *level) { char *where; - + where = line; - - where=strstr(line, "level"); - - if (where!=NULL) { /* found a level keyword on the line */ - - where += 5; /* skip the level keyword */ - while( (*where == ' ') || (*where == '\t') || (*where == '=') || - (*where == ',') || (*where == '(') || (*where == ')') || - (*where == '+') ) { /* legal white space - ignore */ - where++; - } - - /* now the magic number */ - sscanf(where,"%2d",level); /* We get the level number */ - if (*level<0) { - *level=1; - printf("Illegal value for level.\n"); - printf("Level must be >0 (Setting level to 1)\n"); - return(INPmkTemp(" illegal (negative) argument to level parameter - level=1 assumed")); - } - - if (*level>99) { /* Limit to change in the future */ - *level=1; + + where = strstr(line, "level"); + + if (where != NULL) { /* found a level keyword on the line */ + + where += 5; /* skip the level keyword */ + while ((*where == ' ') || (*where == '\t') || (*where == '=') || + (*where == ',') || (*where == '(') || (*where == ')') || + (*where == '+')) { /* legal white space - ignore */ + where++; + } + + /* now the magic number */ + sscanf(where, "%2d", level); /* We get the level number */ + if (*level < 0) { + *level = 1; + printf("Illegal value for level.\n"); + printf("Level must be >0 (Setting level to 1)\n"); + return (INPmkTemp + (" illegal (negative) argument to level parameter - level=1 assumed")); + } + + if (*level > 99) { /* Limit to change in the future */ + *level = 1; printf("Illegal value for level.\n"); printf("Level must be <99 (Setting Level to 1)\n"); - return(INPmkTemp(" illegal (too high) argument to level parameter - level=1 assumed")); - } - - return((char *)NULL); - } - + return (INPmkTemp + (" illegal (too high) argument to level parameter - level=1 assumed")); + } + + return ((char *) NULL); + } + + + + else { /* no level on the line => default */ + *level = 1; + printf("Level not specified: Using level 1.\n"); + return ((char *) NULL); + } + + + - - else { /* no level on the line => default */ - *level = 1; - printf("Level not specified: Using level 1.\n"); - return((char *)NULL); - } - - - - } diff --git a/src/circuit/inpgmod.c b/src/circuit/inpgmod.c index 465142bd8..5631eeecb 100644 --- a/src/circuit/inpgmod.c +++ b/src/circuit/inpgmod.c @@ -13,86 +13,109 @@ Author: 1985 Thomas L. Quarles extern INPmodel *modtab; -char * -INPgetMod(void *ckt, char *name, INPmodel **model, INPtables *tab) +char *INPgetMod(void *ckt, char *name, INPmodel ** model, INPtables * tab) { INPmodel *modtmp; - IFvalue * val; + IFvalue *val; register int j; - char * line; + char *line; char *parm; char *err = NULL; char *temp; int error; - for (modtmp = modtab;modtmp != (INPmodel *)NULL;modtmp = - ((modtmp)->INPnextModel)) { - if (strcmp((modtmp)->INPmodName,name) == 0) { - /* found the model in question - now instantiate if necessary */ - /* and return an appropriate pointer to it */ - if(modtmp->INPmodType<0) { - /* illegal device type, so can't handle */ - *model = (INPmodel *)NULL; - err = (char *)MALLOC((35+strlen(name)) * sizeof(char)); - (void) sprintf(err, - "Unknown device type for model %s \n",name); - return(err); - } - if(! ((modtmp)->INPmodUsed )) { - /* not already defined, so create & give parameters */ - error = (*(ft_sim->newModel))( ckt,(modtmp)->INPmodType, - &((modtmp)->INPmodfast), (modtmp)->INPmodName); - if(error) return(INPerror(error)); - /* parameter isolation, identification, binding */ - line = ((modtmp)->INPmodLine)->line; - INPgetTok(&line,&parm,1); /* throw away '.model' */ - INPgetTok(&line,&parm,1); /* throw away 'modname' */ - while(*line != 0) { - INPgetTok(&line,&parm,1); + for (modtmp = modtab; modtmp != (INPmodel *) NULL; modtmp = + ((modtmp)->INPnextModel)) { + if (strcmp((modtmp)->INPmodName, name) == 0) { + /* found the model in question - now instantiate if necessary */ + /* and return an appropriate pointer to it */ + if (modtmp->INPmodType < 0) { + /* illegal device type, so can't handle */ + *model = (INPmodel *) NULL; + err = (char *) MALLOC((35 + strlen(name)) * sizeof(char)); + (void) sprintf(err, + "Unknown device type for model %s \n", + name); + return (err); + } + if (!((modtmp)->INPmodUsed)) { + /* not already defined, so create & give parameters */ + error = (*(ft_sim->newModel)) (ckt, (modtmp)->INPmodType, + &((modtmp)->INPmodfast), + (modtmp)->INPmodName); + if (error) + return (INPerror(error)); + /* parameter isolation, identification, binding */ + line = ((modtmp)->INPmodLine)->line; + INPgetTok(&line, &parm, 1); /* throw away '.model' */ + INPgetTok(&line, &parm, 1); /* throw away 'modname' */ + while (*line != 0) { + INPgetTok(&line, &parm, 1); if (!*parm) continue; - for(j=0;j<(*(*(ft_sim->devices)[(modtmp)->INPmodType]). - numModelParms); j++) { - if (strcmp(parm,((*(ft_sim->devices) [ (modtmp)-> - INPmodType ]).modelParms[j].keyword)) == 0) { - val = INPgetValue(ckt,&line, - ((*(ft_sim->devices)[(modtmp)-> - INPmodType ]).modelParms[j]. - dataType),tab); - error = (*(ft_sim->setModelParm))(ckt, - ((modtmp)->INPmodfast), - (*(ft_sim->devices)[(modtmp)->INPmodType ]). - modelParms[j].id,val,(IFvalue*)NULL); - if(error) return(INPerror(error)); - break; - } - } - if (strcmp(parm,"level")==0) { - /* just grab the level number and throw away */ - /* since we already have that info from pass1 */ - val = INPgetValue(ckt,&line,IF_REAL,tab); - } else if(j >= - (*(*(ft_sim->devices)[(modtmp)->INPmodType]). - numModelParms)) { - temp = (char *)MALLOC((40+strlen(parm)) * sizeof(char)); - (void)sprintf(temp, - "unrecognized parameter (%s) - ignored\n", parm); - err = INPerrCat(err,temp); - } - FREE(parm); - } - (modtmp)->INPmodUsed=1; - (modtmp)->INPmodLine->error = err; - } - *model = modtmp; - return((char *)NULL); - } + for (j = 0; + j < + (* + (*(ft_sim->devices) + [(modtmp)->INPmodType]).numModelParms); j++) { + if (strcmp + (parm, + ((*(ft_sim->devices)[(modtmp)->INPmodType]). + modelParms[j].keyword)) == 0) { + val = + INPgetValue(ckt, &line, + ((* + (ft_sim-> + devices)[ + (modtmp)->INPmodType]). + modelParms[j].dataType), tab); + error = + (*(ft_sim->setModelParm)) (ckt, + ((modtmp)-> + INPmodfast), + (* + (ft_sim-> + devices)[ + (modtmp)-> + INPmodType]).modelParms + [j].id, val, + (IFvalue *) + NULL); + if (error) + return (INPerror(error)); + break; + } + } + if (strcmp(parm, "level") == 0) { + /* just grab the level number and throw away */ + /* since we already have that info from pass1 */ + val = INPgetValue(ckt, &line, IF_REAL, tab); + } else if (j >= + (* + (*(ft_sim->devices) + [(modtmp)->INPmodType]).numModelParms)) { + temp = + (char *) MALLOC((40 + strlen(parm)) * + sizeof(char)); + (void) sprintf(temp, + "unrecognized parameter (%s) - ignored\n", + parm); + err = INPerrCat(err, temp); + } + FREE(parm); + } + (modtmp)->INPmodUsed = 1; + (modtmp)->INPmodLine->error = err; + } + *model = modtmp; + return ((char *) NULL); + } } /* didn't find model - ERROR - return model */ - *model = (INPmodel *)NULL; - err = (char *)MALLOC((60+strlen(name)) * sizeof(char)); + *model = (INPmodel *) NULL; + err = (char *) MALLOC((60 + strlen(name)) * sizeof(char)); (void) sprintf(err, - " unable to find definition of model %s - default assumed \n",name); - return(err); + " unable to find definition of model %s - default assumed \n", + name); + return (err); } - diff --git a/src/circuit/inpgstr.c b/src/circuit/inpgstr.c index f6208fd45..4081cb48b 100644 --- a/src/circuit/inpgstr.c +++ b/src/circuit/inpgstr.c @@ -13,61 +13,62 @@ Author: 1985 Thomas L. Quarles #include "inpdefs.h" #include "inp.h" -int -INPgetStr(char **line, char **token, int gobble) - /* eat non-whitespace trash AFTER token? */ +int INPgetStr(char **line, char **token, int gobble) + /* eat non-whitespace trash AFTER token? */ { - char *point; - char separator = '\0'; + char *point; + char separator = '\0'; - /* Scan along throwing away garbage characters. */ - for (point = *line; *point != '\0'; point++) { - if ( (*point == ' ') || - (*point == '\t') || - (*point == '=') || - (*point == '(') || - (*point == ')') || - (*point == ',') ) continue; - break; - } - if (*point == '"') { - separator = '"'; - point++; - } else if (*point == '\'') { - separator = '\''; - point++; - } - /* mark beginning of token */ - *line = point; - /* now find all good characters */ - for (point = *line; *point != '\0'; point++) { - if ( (*point == ' ') || - (*point == '\t') || - (*point == '=') || - (*point == '(') || - (*point == ')') || - (*point == ',') || - (*point == separator) ) break; - } + /* Scan along throwing away garbage characters. */ + for (point = *line; *point != '\0'; point++) { + if ((*point == ' ') || + (*point == '\t') || + (*point == '=') || + (*point == '(') || (*point == ')') || (*point == ',')) + continue; + break; + } + if (*point == '"') { + separator = '"'; + point++; + } else if (*point == '\'') { + separator = '\''; + point++; + } + /* mark beginning of token */ + *line = point; + /* now find all good characters */ + for (point = *line; *point != '\0'; point++) { + if ((*point == ' ') || + (*point == '\t') || + (*point == '=') || + (*point == '(') || + (*point == ')') || (*point == ',') || (*point == separator)) + break; + } - /* Create token */ - *token = (char *) MALLOC(1 + point - *line); - if (!*token) - return (E_NOMEM); - (void) strncpy(*token, *line, point - *line); - *(*token + (point - *line)) = '\0'; - *line = point; + /* Create token */ + *token = (char *) MALLOC(1 + point - *line); + if (!*token) + return (E_NOMEM); + (void) strncpy(*token, *line, point - *line); + *(*token + (point - *line)) = '\0'; + *line = point; - /* Gobble garbage to next token. */ - if (separator && **line == separator) { - (*line)++; /* Skip one closing separator */ - } - for (; **line != '\0'; (*line)++) { - if(**line == ' ') continue; - if(**line == '\t') continue; - if((**line == '=') && gobble) continue; - if((**line == ',') && gobble) continue; - break; - } - return (OK); + /* Gobble garbage to next token. */ + if (separator && **line == separator) { + (*line)++; /* Skip one closing separator */ + } + for (; **line != '\0'; (*line)++) { + if (**line == ' ') + continue; + if (**line == '\t') + continue; + if ((**line == '=') && gobble) + continue; + if ((**line == ',') && gobble) + continue; + break; + } + return (OK); } diff --git a/src/circuit/inpgtitl.c b/src/circuit/inpgtitl.c index ff5b679a7..5ae3cb913 100644 --- a/src/circuit/inpgtitl.c +++ b/src/circuit/inpgtitl.c @@ -16,14 +16,13 @@ Author: 1985 Thomas L. Quarles #include "fteext.h" #include "inp.h" -int -INPgetTitle(void **ckt, card **data) +int INPgetTitle(void **ckt, card ** data) { int error; - error = (*(ft_sim->newCircuit))(ckt); - if(error) return(error); + error = (*(ft_sim->newCircuit)) (ckt); + if (error) + return (error); *data = (*data)->nextcard; - return(OK); + return (OK); } - diff --git a/src/circuit/inpgtok.c b/src/circuit/inpgtok.c index b73ad06fc..c00ae28fe 100644 --- a/src/circuit/inpgtok.c +++ b/src/circuit/inpgtok.c @@ -18,87 +18,113 @@ Author: 1985 Thomas L. Quarles #include "inpdefs.h" #include "inp.h" -int -INPgetTok(char **line, char **token, int gobble) - /* eat non-whitespace trash AFTER token? */ +int INPgetTok(char **line, char **token, int gobble) + /* eat non-whitespace trash AFTER token? */ { - char * point; + char *point; int signstate; /* scan along throwing away garbage characters */ - for(point = *line;*point != '\0' ; point++ ) { - if(*point == ' ') continue; - if(*point == '\t') continue; - if(*point == '=') continue; - if(*point == '(') continue; - if(*point == ')') continue; - if(*point == ',') continue; - break; + for (point = *line; *point != '\0'; point++) { + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if (*point == '=') + continue; + if (*point == '(') + continue; + if (*point == ')') + continue; + if (*point == ',') + continue; + break; } /* mark beginning of token */ *line = point; /* now find all good characters */ signstate = 0; - for(point = *line;*point!='\0';point++) { - if(*point == ' ') break; - if(*point == '\t') break; - if(*point == '=') break; - if(*point == '(') break; - if(*point == ')') break; - if(*point == ',') break; - /* This is not complex enough to catch all errors, but it will get the "good" parses */ - if(*point == '+' && (signstate == 1 || signstate == 3)) break; - if(*point == '-' && (signstate == 1 || signstate == 3)) break; - if(*point == '*') break; - if(*point == '/') break; - if(*point == '^') break; - if (isdigit(*point) || *point == '.') { - if (signstate > 1) - signstate = 3; - else - signstate = 1; - } else if (tolower(*point) == 'e' && signstate == 1) - signstate = 2; - else - signstate = 3; + for (point = *line; *point != '\0'; point++) { + if (*point == ' ') + break; + if (*point == '\t') + break; + if (*point == '=') + break; + if (*point == '(') + break; + if (*point == ')') + break; + if (*point == ',') + break; + /* This is not complex enough to catch all errors, but it will get the "good" parses */ + if (*point == '+' && (signstate == 1 || signstate == 3)) + break; + if (*point == '-' && (signstate == 1 || signstate == 3)) + break; + if (*point == '*') + break; + if (*point == '/') + break; + if (*point == '^') + break; + if (isdigit(*point) || *point == '.') { + if (signstate > 1) + signstate = 3; + else + signstate = 1; + } else if (tolower(*point) == 'e' && signstate == 1) + signstate = 2; + else + signstate = 3; } if (point == *line && *point) /* Weird items, 1 char */ point++; - *token=(char *)MALLOC(1+point-*line); - if(!*token) return(E_NOMEM); - (void) strncpy(*token,*line,point-*line); - *(*token + (point-*line)) = '\0'; + *token = (char *) MALLOC(1 + point - *line); + if (!*token) + return (E_NOMEM); + (void) strncpy(*token, *line, point - *line); + *(*token + (point - *line)) = '\0'; *line = point; /* gobble garbage to next token */ - for( ;**line != '\0' ; (*line)++ ) { - if(**line == ' ') continue; - if(**line == '\t') continue; - if((**line == '=') && gobble) continue; - if((**line == ',') && gobble) continue; - break; + for (; **line != '\0'; (*line)++) { + if (**line == ' ') + continue; + if (**line == '\t') + continue; + if ((**line == '=') && gobble) + continue; + if ((**line == ',') && gobble) + continue; + break; } - /*printf("found token (%s) and rest of line (%s)\n",*token,*line);*/ - return(OK); + /*printf("found token (%s) and rest of line (%s)\n",*token,*line); */ + return (OK); } -int -INPgetUTok(char **line, char **token, int gobble) - - - /* eat non-whitespace trash AFTER token? */ +int INPgetUTok(char **line, char **token, int gobble) + + + /* eat non-whitespace trash AFTER token? */ { - char * point, separator; + char *point, separator; int signstate; /* scan along throwing away garbage characters */ - for(point = *line;*point != '\0' ; point++ ) { - if(*point == ' ') continue; - if(*point == '\t') continue; - if(*point == '=') continue; - if(*point == '(') continue; - if(*point == ')') continue; - if(*point == ',') continue; - break; + for (point = *line; *point != '\0'; point++) { + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if (*point == '=') + continue; + if (*point == '(') + continue; + if (*point == ')') + continue; + if (*point == ',') + continue; + break; } if (*point == '"') { separator = '"'; @@ -114,30 +140,41 @@ INPgetUTok(char **line, char **token, int gobble) /* now find all good characters */ signstate = 0; - for(point = *line;*point!='\0';point++) { + for (point = *line; *point != '\0'; point++) { if (separator) { if (*point == separator) break; else continue; } - if(*point == ' ') break; - if(*point == '\t') break; - if(*point == '=') break; - if(*point == '(') break; - if(*point == ')') break; - if(*point == ',') break; + if (*point == ' ') + break; + if (*point == '\t') + break; + if (*point == '=') + break; + if (*point == '(') + break; + if (*point == ')') + break; + if (*point == ',') + break; /* This is not complex enough to catch all errors, but it will get the "good" parses */ - if(*point == '+' && (signstate == 1 || signstate == 3)) break; - if(*point == '-') { - if (signstate == 1 || signstate == 3) break; + if (*point == '+' && (signstate == 1 || signstate == 3)) + break; + if (*point == '-') { + if (signstate == 1 || signstate == 3) + break; signstate += 1; continue; } - if(*point == '*') break; - if(*point == '/') break; - if(*point == '^') break; + if (*point == '*') + break; + if (*point == '/') + break; + if (*point == '^') + break; if (isdigit(*point) || *point == '.') { if (signstate > 1) signstate = 3; @@ -152,21 +189,26 @@ INPgetUTok(char **line, char **token, int gobble) point--; if (point == *line && *point) /* Weird items, 1 char */ point++; - *token=(char *)MALLOC(1+point-*line); - if(!*token) return(E_NOMEM); - (void) strncpy(*token,*line,point-*line); - *(*token + (point-*line)) = '\0'; + *token = (char *) MALLOC(1 + point - *line); + if (!*token) + return (E_NOMEM); + (void) strncpy(*token, *line, point - *line); + *(*token + (point - *line)) = '\0'; /* gobble garbage to next token */ - for( ;*point != '\0' ; point++ ) { + for (; *point != '\0'; point++) { if (*point == separator) continue; - if(*point == ' ') continue; - if(*point == '\t') continue; - if((*point == '=') && gobble) continue; - if((*point == ',') && gobble) continue; - break; + if (*point == ' ') + continue; + if (*point == '\t') + continue; + if ((*point == '=') && gobble) + continue; + if ((*point == ',') && gobble) + continue; + break; } *line = point; - /* printf("found token (%s) and rest of line (%s)\n",*token,*line); */ - return(OK); + /* printf("found token (%s) and rest of line (%s)\n",*token,*line); */ + return (OK); } diff --git a/src/circuit/inpgval.c b/src/circuit/inpgval.c index 31129be7c..4f043cb44 100644 --- a/src/circuit/inpgval.c +++ b/src/circuit/inpgval.c @@ -10,8 +10,7 @@ Author: 1985 Thomas L. Quarles #include "inpptree.h" #include "inp.h" -IFvalue * -INPgetValue(void *ckt, char **line, int type, INPtables *tab) +IFvalue *INPgetValue(void *ckt, char **line, int type, INPtables * tab) { double *list; int *ilist; @@ -23,56 +22,60 @@ INPgetValue(void *ckt, char **line, int type, INPtables *tab) /* make sure we get rid of extra bits in type */ type &= IF_VARTYPES; - if(type == IF_INTEGER) { - temp.iValue = INPevaluate(line,&error,1); - /*printf(" returning integer value %d\n",temp.iValue);*/ + if (type == IF_INTEGER) { + temp.iValue = INPevaluate(line, &error, 1); + /*printf(" returning integer value %d\n",temp.iValue); */ } else if (type == IF_REAL) { - temp.rValue = INPevaluate(line,&error,1); - /*printf(" returning real value %e\n",temp.rValue);*/ + temp.rValue = INPevaluate(line, &error, 1); + /*printf(" returning real value %e\n",temp.rValue); */ } else if (type == IF_REALVEC) { - temp.v.numValue = 0; - list = (double *)MALLOC(sizeof(double)); - tmp = INPevaluate(line,&error,1); - while (error == 0) { - /*printf(" returning vector value %g\n",tmp); */ - temp.v.numValue++; - list=(double *)REALLOC((char *)list,temp.v.numValue*sizeof(double)); - *(list+temp.v.numValue-1) = tmp; - tmp = INPevaluate(line,&error,1); - } - temp.v.vec.rVec=list; + temp.v.numValue = 0; + list = (double *) MALLOC(sizeof(double)); + tmp = INPevaluate(line, &error, 1); + while (error == 0) { + /*printf(" returning vector value %g\n",tmp); */ + temp.v.numValue++; + list = + (double *) REALLOC((char *) list, + temp.v.numValue * sizeof(double)); + *(list + temp.v.numValue - 1) = tmp; + tmp = INPevaluate(line, &error, 1); + } + temp.v.vec.rVec = list; } else if (type == IF_INTVEC) { - temp.v.numValue = 0; - ilist = (int *)MALLOC(sizeof(int)); - tmp = INPevaluate(line,&error,1); - while (error == 0) { - /*printf(" returning vector value %g\n",tmp); */ - temp.v.numValue++; - ilist=(int *)REALLOC((char *)ilist,temp.v.numValue*sizeof(int)); - *(ilist+temp.v.numValue-1) = tmp; - tmp = INPevaluate(line,&error,1); - } - temp.v.vec.iVec=ilist; + temp.v.numValue = 0; + ilist = (int *) MALLOC(sizeof(int)); + tmp = INPevaluate(line, &error, 1); + while (error == 0) { + /*printf(" returning vector value %g\n",tmp); */ + temp.v.numValue++; + ilist = + (int *) REALLOC((char *) ilist, + temp.v.numValue * sizeof(int)); + *(ilist + temp.v.numValue - 1) = tmp; + tmp = INPevaluate(line, &error, 1); + } + temp.v.vec.iVec = ilist; } else if (type == IF_FLAG) { - temp.iValue = 1; + temp.iValue = 1; } else if (type == IF_NODE) { - INPgetTok(line,&word,1); - INPtermInsert(ckt,&word,tab,&(temp.nValue)); + INPgetTok(line, &word, 1); + INPtermInsert(ckt, &word, tab, &(temp.nValue)); } else if (type == IF_INSTANCE) { - INPgetTok(line,&word,1); - INPinsert(&word,tab); - temp.nValue = word; + INPgetTok(line, &word, 1); + INPinsert(&word, tab); + temp.nValue = word; } else if (type == IF_STRING) { - INPgetStr(line,&word,1); - temp.sValue = word; + INPgetStr(line, &word, 1); + temp.sValue = word; } else if (type == IF_PARSETREE) { - INPgetTree(line, &pt, ckt, tab); - if (!pt) - return((IFvalue *)NULL); - temp.tValue = (IFparseTree *) pt; - /*INPptPrint("Parse tree is: ", temp.tValue);*/ - } else { /* don't know what type of parameter caller is talking about! */ - return((IFvalue *)NULL); + INPgetTree(line, &pt, ckt, tab); + if (!pt) + return ((IFvalue *) NULL); + temp.tValue = (IFparseTree *) pt; + /*INPptPrint("Parse tree is: ", temp.tValue); */ + } else { /* don't know what type of parameter caller is talking about! */ + return ((IFvalue *) NULL); } - return(&temp); + return (&temp); } diff --git a/src/circuit/inpkmods.c b/src/circuit/inpkmods.c index 8981bc840..e8e2319dd 100644 --- a/src/circuit/inpkmods.c +++ b/src/circuit/inpkmods.c @@ -13,18 +13,18 @@ Author: 1985 Thomas L. Quarles extern INPmodel *modtab; -void -INPkillMods(void) +void INPkillMods(void) { INPmodel *modtmp; INPmodel *prev = NULL; - for (modtmp = modtab;modtmp != (INPmodel *)NULL;modtmp = - modtmp->INPnextModel) { - if(prev) FREE(prev); - prev = modtmp; + for (modtmp = modtab; modtmp != (INPmodel *) NULL; modtmp = + modtmp->INPnextModel) { + if (prev) + FREE(prev); + prev = modtmp; } - if(prev) FREE(prev); - modtab = (INPmodel *)NULL; + if (prev) + FREE(prev); + modtab = (INPmodel *) NULL; } - diff --git a/src/circuit/inplist.c b/src/circuit/inplist.c index 87e4e0e89..f876842f9 100644 --- a/src/circuit/inplist.c +++ b/src/circuit/inplist.c @@ -17,38 +17,36 @@ Author: 1985 Thomas L. Quarles #include "inp.h" -void -INPlist(FILE *file, card *deck, int type) +void INPlist(FILE * file, card * deck, int type) { card *here; card *there; - if(type == LOGICAL) { - for(here = deck;here != NULL;here = here->nextcard) { - fprintf(file,"%6d : %s\n",here->linenum, here->line); - if(here->error != (char *)NULL) { - fprintf(file,"%s",here->error); - } - } + if (type == LOGICAL) { + for (here = deck; here != NULL; here = here->nextcard) { + fprintf(file, "%6d : %s\n", here->linenum, here->line); + if (here->error != (char *) NULL) { + fprintf(file, "%s", here->error); + } + } } else if (type == PHYSICAL) { - for(here = deck;here != NULL;here = here->nextcard) { - if(here->actualLine == (card *)NULL) { - fprintf(file,"%6d : %s\n",here->linenum,here->line); - if(here->error != (char *)NULL) { - fprintf(file,"%s",here->error); - } - } else { - for(there = here->actualLine;there != NULL; - there=there->nextcard) { - fprintf(file,"%6d : %s\n",there->linenum, there->line); - if(there->error != (char *)NULL) { - fprintf(file,"%s",there->error); - } - } - } - } + for (here = deck; here != NULL; here = here->nextcard) { + if (here->actualLine == (card *) NULL) { + fprintf(file, "%6d : %s\n", here->linenum, here->line); + if (here->error != (char *) NULL) { + fprintf(file, "%s", here->error); + } + } else { + for (there = here->actualLine; there != NULL; + there = there->nextcard) { + fprintf(file, "%6d : %s\n", there->linenum, + there->line); + if (there->error != (char *) NULL) { + fprintf(file, "%s", there->error); + } + } + } + } } } - - diff --git a/src/circuit/inplkmod.c b/src/circuit/inplkmod.c index 38bfb0d09..d1c534bab 100644 --- a/src/circuit/inplkmod.c +++ b/src/circuit/inplkmod.c @@ -14,18 +14,16 @@ Author: 1985 Thomas L. Quarles extern INPmodel *modtab; -int -INPlookMod(char *name) +int INPlookMod(char *name) { register INPmodel **i; - for (i = &modtab;*i != (INPmodel *)NULL;i = &((*i)->INPnextModel)) { - if (strcmp((*i)->INPmodName,name) == 0) { - /* found the model in question - return TRUE */ - return(1); - } + for (i = &modtab; *i != (INPmodel *) NULL; i = &((*i)->INPnextModel)) { + if (strcmp((*i)->INPmodName, name) == 0) { + /* found the model in question - return TRUE */ + return (1); + } } /* didn't find model - return FALSE */ - return(0); + return (0); } - diff --git a/src/circuit/inpmkmod.c b/src/circuit/inpmkmod.c index d6819b738..a9b9705d3 100644 --- a/src/circuit/inpmkmod.c +++ b/src/circuit/inpmkmod.c @@ -13,23 +13,23 @@ INPmodel *modtab; /* create/lookup a 'model' entry */ -int -INPmakeMod(char *token, int type, card *line) +int INPmakeMod(char *token, int type, card * line) { register INPmodel **i; - for (i = &modtab;*i != (INPmodel *)NULL;i = &((*i)->INPnextModel)) { - if (strcmp((*i)->INPmodName,token) == 0) { - return(OK); - } + for (i = &modtab; *i != (INPmodel *) NULL; i = &((*i)->INPnextModel)) { + if (strcmp((*i)->INPmodName, token) == 0) { + return (OK); + } } - *i = (INPmodel *)MALLOC(sizeof(INPmodel)); - if(*i==NULL) return(E_NOMEM); + *i = (INPmodel *) MALLOC(sizeof(INPmodel)); + if (*i == NULL) + return (E_NOMEM); (*i)->INPmodName = token; (*i)->INPmodType = type; - (*i)->INPnextModel = (INPmodel *)NULL; + (*i)->INPnextModel = (INPmodel *) NULL; (*i)->INPmodUsed = 0; (*i)->INPmodLine = line; (*i)->INPmodfast = NULL; - return(OK); + return (OK); } diff --git a/src/circuit/inpmktmp.c b/src/circuit/inpmktmp.c index b2c9e102b..1ed44d65e 100644 --- a/src/circuit/inpmktmp.c +++ b/src/circuit/inpmktmp.c @@ -11,15 +11,15 @@ Author: 1985 Thomas L. Quarles #include "inp.h" -char * -INPmkTemp(char *string) +char *INPmkTemp(char *string) { -int len; -char *temp; - + int len; + char *temp; + len = strlen(string); - temp = MALLOC(len+1); - if(temp!=(char *)NULL) (void)strcpy(temp,string); - return(temp); + temp = MALLOC(len + 1); + if (temp != (char *) NULL) + (void) strcpy(temp, string); + return (temp); } diff --git a/src/circuit/inppas1.c b/src/circuit/inppas1.c index 21115c9b2..596df381b 100644 --- a/src/circuit/inppas1.c +++ b/src/circuit/inppas1.c @@ -14,25 +14,24 @@ Author: 1985 Thomas L. Quarles * The first pass of the circuit parser just looks for '.model' lines */ -void -INPpas1(void *ckt, card *deck, INPtables *tab) +void INPpas1(void *ckt, card * deck, INPtables * tab) { card *current; - char *INPdomodel(void *ckt, card *image, INPtables *tab); + char *INPdomodel(void *ckt, card * image, INPtables * tab); char *temp, *thisline; - for(current = deck;current != NULL;current = current->nextcard) { - /* SPICE-2 keys off of the first character of the line */ + for (current = deck; current != NULL; current = current->nextcard) { + /* SPICE-2 keys off of the first character of the line */ thisline = current->line; while (*thisline && ((*thisline == ' ') || (*thisline == '\t'))) thisline++; if (*thisline == '.') { - if(strncmp(thisline,".model",6)==0) { - temp = INPdomodel(ckt,current,tab); - current->error = INPerrCat(current->error,temp); - } + if (strncmp(thisline, ".model", 6) == 0) { + temp = INPdomodel(ckt, current, tab); + current->error = INPerrCat(current->error, temp); + } } /* for now, we do nothing with the other cards - just diff --git a/src/circuit/inppas2.c b/src/circuit/inppas2.c index 62b0a7cfa..41bf7b52f 100644 --- a/src/circuit/inppas2.c +++ b/src/circuit/inppas2.c @@ -14,138 +14,143 @@ Author: 1985 Thomas L. Quarles * in pass1 and are ignored here. */ -void -INPpas2(void *ckt, card *data, INPtables *tab, void *task) +void INPpas2(void *ckt, card * data, INPtables * tab, void *task) { -card *current; -char c; -char * groundname="0"; -char * gname; -void *gnode; -int error; /* used by the macros defined above */ + card *current; + char c; + char *groundname = "0"; + char *gname; + void *gnode; + int error; /* used by the macros defined above */ - error = INPgetTok(&groundname,&gname,1); - if(error) data->error = INPerrCat(data->error,INPmkTemp( - "can't read internal ground node name!\n")); + error = INPgetTok(&groundname, &gname, 1); + if (error) + data->error = + INPerrCat(data->error, + INPmkTemp + ("can't read internal ground node name!\n")); - error = INPgndInsert(ckt,&gname,tab,&gnode); - if(error && error!=E_EXISTS)data->error = INPerrCat(data->error,INPmkTemp( - "can't insert internal ground node in symbol table!\n")); + error = INPgndInsert(ckt, &gname, tab, &gnode); + if (error && error != E_EXISTS) + data->error = + INPerrCat(data->error, + INPmkTemp + ("can't insert internal ground node in symbol table!\n")); - for(current = data; current != NULL; current = current->nextcard) { + for (current = data; current != NULL; current = current->nextcard) { - c = *(current->line); - c = islower(c) ? toupper(c) : c; + c = *(current->line); + c = islower(c) ? toupper(c) : c; - switch(c) { + switch (c) { - case ' ': /* blank line (space leading) */ - case '\t': /* blank line (tab leading) */ - break; - - case 'R': /* Rname [][][w=][l=] */ - INP2R(ckt,tab,current); - break; - case 'C': /* Cname [IC=] */ - INP2C(ckt,tab,current); - break; - case 'L': /* Lname [IC=] */ - INP2L(ckt,tab,current); - break; - case 'G': /* Gname */ - INP2G(ckt,tab,current); - break; - case 'E': /* Ename */ - INP2E(ckt,tab,current); - break; - case 'F': /* Fname */ - INP2F(ckt,tab,current); - break; - case 'H': /* Hname */ - INP2H(ckt,tab,current); - break; - case 'D': /* Dname [] [OFF] [IC=] */ - INP2D(ckt,tab,current); - break; - case 'J': /* Jname [] [OFF] - * [IC=,] */ - INP2J(ckt,tab,current); - break; - case 'Z': /* Zname [] [OFF] - * [IC=,] */ - INP2Z(ckt,tab,current); - break; - case 'M': /* Mname [L=] - * [W=] [AD=] [AS=] [PD=] - * [PS=] [NRD=] [NRS=] [OFF] - * [IC=,,] */ - INP2M(ckt,tab,current); - break; - - case 'O': /* Oname - * [IC=,,,] */ - INP2O(ckt,tab,current); + case ' ': /* blank line (space leading) */ + case '\t': /* blank line (tab leading) */ break; - case 'V': /* Vname [ [DC] ] [AC [ [ ] ] ] - * [] */ - INP2V(ckt,tab,current); - break; - case 'I': /* Iname [ [DC] ] [AC [ [ ] ] ] - * [] */ - INP2I(ckt,tab,current); - break; + case 'R': /* Rname [][][w=][l=] */ + INP2R(ckt, tab, current); + break; + case 'C': /* Cname [IC=] */ + INP2C(ckt, tab, current); + break; + case 'L': /* Lname [IC=] */ + INP2L(ckt, tab, current); + break; + case 'G': /* Gname */ + INP2G(ckt, tab, current); + break; + case 'E': /* Ename */ + INP2E(ckt, tab, current); + break; + case 'F': /* Fname */ + INP2F(ckt, tab, current); + break; + case 'H': /* Hname */ + INP2H(ckt, tab, current); + break; + case 'D': /* Dname [] [OFF] [IC=] */ + INP2D(ckt, tab, current); + break; + case 'J': /* Jname [] [OFF] + * [IC=,] */ + INP2J(ckt, tab, current); + break; + case 'Z': /* Zname [] [OFF] + * [IC=,] */ + INP2Z(ckt, tab, current); + break; + case 'M': /* Mname [L=] + * [W=] [AD=] [AS=] [PD=] + * [PS=] [NRD=] [NRS=] [OFF] + * [IC=,,] */ + INP2M(ckt, tab, current); + break; - case 'Q': /* Qname [] [] [OFF] - * [IC=,] */ - INP2Q(ckt,tab,current,gnode); - break; + case 'O': /* Oname + * [IC=,,,] */ + INP2O(ckt, tab, current); + break; - case 'T': /* Tname [TD=] - * [F= [NL=]][IC=,,,] */ - INP2T(ckt,tab,current); - break; + case 'V': /* Vname [ [DC] ] [AC [ [ ] ] ] + * [] */ + INP2V(ckt, tab, current); + break; + case 'I': /* Iname [ [DC] ] [AC [ [ ] ] ] + * [] */ + INP2I(ckt, tab, current); + break; - case 'S': /* Sname [] [IC] */ - INP2S(ckt,tab,current); - break; + case 'Q': /* Qname [] [] [OFF] + * [IC=,] */ + INP2Q(ckt, tab, current, gnode); + break; - case 'W': /* Wname [] [IC] */ - /* CURRENT CONTROLLED SWITCH */ - INP2W(ckt,tab,current); - break; + case 'T': /* Tname [TD=] + * [F= [NL=]][IC=,,,] */ + INP2T(ckt, tab, current); + break; - case 'U': /* Uname [l=] [n=] */ - INP2U(ckt,tab,current); - break; + case 'S': /* Sname [] [IC] */ + INP2S(ckt, tab, current); + break; - case 'K': /* Kname Lname Lname */ - INP2K(ckt,tab,current); - break; + case 'W': /* Wname [] [IC] */ + /* CURRENT CONTROLLED SWITCH */ + INP2W(ckt, tab, current); + break; - case '*': /* * - a comment - ignore */ - break; + case 'U': /* Uname [l=] [n=] */ + INP2U(ckt, tab, current); + break; - case 'B': /* Bname [V=expr] [I=expr] */ - /* Arbitrary source. */ - INP2B(ckt,tab,current); - break; + case 'K': /* Kname Lname Lname */ + INP2K(ckt, tab, current); + break; - case '.': /* . Many possibilities */ - if (INP2dot(ckt,tab,current,task,gnode)) goto end; - break; + case '*': /* * - a comment - ignore */ + break; + + case 'B': /* Bname [V=expr] [I=expr] */ + /* Arbitrary source. */ + INP2B(ckt, tab, current); + break; + + case '.': /* . Many possibilities */ + if (INP2dot(ckt, tab, current, task, gnode)) + goto end; + break; case 0: break; - default: - /* the un-implemented device */ - LITERR(" unknown device type - error \n") - break; - } + default: + /* the un-implemented device */ + LITERR(" unknown device type - error \n"); + break; + } } -end: + end: return; } - diff --git a/src/circuit/inppname.c b/src/circuit/inppname.c index 3b8e78c2a..e89bc38dc 100644 --- a/src/circuit/inppname.c +++ b/src/circuit/inppname.c @@ -17,29 +17,32 @@ Author: 1985 Thomas L. Quarles #include "iferrmsg.h" #include "inp.h" -int -INPpName(char *parm, IFvalue *val, void *ckt, int dev, void *fast) - /* the name of the parameter to set */ - /* the parameter union containing the value to set */ - /* the circuit this device is a member of */ - /* the device type code to the device being parsed */ - /* direct pointer to device being parsed */ - +int INPpName(char *parm, IFvalue * val, void *ckt, int dev, void *fast) + /* the name of the parameter to set */ + /* the parameter union containing the value to set */ + /* the circuit this device is a member of */ + /* the device type code to the device being parsed */ + /* direct pointer to device being parsed */ { - int error; /* int to store evaluate error return codes in */ + int error; /* int to store evaluate error return codes in */ int i; - for(i=0;i<(*(*(ft_sim->devices)[dev]).numInstanceParms);i++) { - if(strcmp(parm, - ((*(ft_sim->devices)[dev]).instanceParms[i].keyword))==0) { - error = (*(ft_sim->setInstanceParm))(ckt,fast, (*(ft_sim-> - devices)[dev]).instanceParms[i].id,val,(IFvalue*)NULL); - if(error) return(error); - break; - } + for (i = 0; i < (*(*(ft_sim->devices)[dev]).numInstanceParms); i++) { + if (strcmp(parm, + ((*(ft_sim->devices)[dev]).instanceParms[i].keyword)) == + 0) { + error = + (*(ft_sim->setInstanceParm)) (ckt, fast, + (*(ft_sim->devices)[dev]). + instanceParms[i].id, val, + (IFvalue *) NULL); + if (error) + return (error); + break; + } } - if(i==(*(*(ft_sim->devices)[dev]).numInstanceParms)) { - return(E_BADPARM); + if (i == (*(*(ft_sim->devices)[dev]).numInstanceParms)) { + return (E_BADPARM); } - return(OK); + return (OK); } diff --git a/src/circuit/inpptree.c b/src/circuit/inpptree.c index 83b8e014f..eead80869 100644 --- a/src/circuit/inpptree.c +++ b/src/circuit/inpptree.c @@ -12,18 +12,20 @@ Author: 1987 Wayne A. Christopher, U. C. Berkeley CAD Group #include "inpptree.h" #include "inp.h" -static INPparseNode * mkcon(double value); -static INPparseNode * mkb(int type, INPparseNode *left, INPparseNode *right); -static INPparseNode * mkf(int type, INPparseNode *arg); -static int PTcheck(INPparseNode *p); -static INPparseNode * PTparse(char **line); -static INPparseNode * makepnode(PTelement *elem); -static INPparseNode * mkbnode(int opnum, INPparseNode *arg1, INPparseNode *arg2); -static INPparseNode * mkfnode(char *fname, INPparseNode *arg); -static INPparseNode * mknnode(double number); -static INPparseNode * mksnode(char *string); -static INPparseNode * PTdifferentiate(INPparseNode *p, int varnum); -static PTelement * PTlexer(char **line); +static INPparseNode *mkcon(double value); +static INPparseNode *mkb(int type, INPparseNode * left, + INPparseNode * right); +static INPparseNode *mkf(int type, INPparseNode * arg); +static int PTcheck(INPparseNode * p); +static INPparseNode *PTparse(char **line); +static INPparseNode *makepnode(PTelement * elem); +static INPparseNode *mkbnode(int opnum, INPparseNode * arg1, + INPparseNode * arg2); +static INPparseNode *mkfnode(char *fname, INPparseNode * arg); +static INPparseNode *mknnode(double number); +static INPparseNode *mksnode(char *string); +static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum); +static PTelement *PTlexer(char **line); static IFvalue *values = NULL; static int *types; @@ -33,29 +35,30 @@ static INPtables *tables; -extern IFsimulator *ft_sim; /* XXX */ +extern IFsimulator *ft_sim; /* XXX */ /* Some tables that the parser uses. */ static struct op { int number; char *name; - double (*funcptr)(); -} ops[] = { - { PT_COMMA, ",", NULL } , - { PT_PLUS, "+", PTplus } , - { PT_MINUS, "-", PTminus } , - { PT_TIMES, "*", PTtimes } , - { PT_DIVIDE, "/", PTdivide } , - { PT_POWER, "^", PTpower } -} ; + double (*funcptr) (); +} ops[] = { + { + PT_COMMA, ",", NULL}, { + PT_PLUS, "+", PTplus}, { + PT_MINUS, "-", PTminus}, { + PT_TIMES, "*", PTtimes}, { + PT_DIVIDE, "/", PTdivide}, { + PT_POWER, "^", PTpower} +}; #define NUM_OPS (sizeof (ops) / sizeof (struct op)) static struct func { char *name; int number; - double (*funcptr)(); + double (*funcptr) (); } funcs[] = { { "abs", PTF_ABS, PTabs } , { "acos", PTF_ACOS, PTacos } , @@ -90,9 +93,10 @@ static struct constant { char *name; double value; } constants[] = { - { "e", M_E }, - { "pi", M_PI } -} ; + { + "e", M_E}, { + "pi", M_PI} +}; #define NUM_CONSTANTS (sizeof (constants) / sizeof (struct constant)) @@ -102,7 +106,7 @@ static struct constant { */ void -INPgetTree(char **line, INPparseTree **pt, void *ckt, INPtables *tab) +INPgetTree(char **line, INPparseTree ** pt, void *ckt, INPtables * tab) { INPparseNode *p; int i; @@ -117,11 +121,11 @@ INPgetTree(char **line, INPparseTree **pt, void *ckt, INPtables *tab) p = PTparse(line); if (!p || !PTcheck(p)) { - *pt = NULL; - return; + *pt = NULL; + return; } - (*pt) = (INPparseTree *) MALLOC(sizeof (INPparseTree)); + (*pt) = (INPparseTree *) MALLOC(sizeof(INPparseTree)); (*pt)->p.numVars = numvalues; (*pt)->p.varTypes = types; @@ -129,11 +133,11 @@ INPgetTree(char **line, INPparseTree **pt, void *ckt, INPtables *tab) (*pt)->p.IFeval = IFeval; (*pt)->tree = p; - (*pt)->derivs = (INPparseNode **) - MALLOC(numvalues * sizeof (INPparseNode *)); + (*pt)->derivs = (INPparseNode **) + MALLOC(numvalues * sizeof(INPparseNode *)); for (i = 0; i < numvalues; i++) - (*pt)->derivs[i] = PTdifferentiate(p, i); + (*pt)->derivs[i] = PTdifferentiate(p, i); return; } @@ -147,8 +151,7 @@ INPgetTree(char **line, INPparseTree **pt, void *ckt, INPtables *tab) *** trees. */ -static INPparseNode * -PTdifferentiate(INPparseNode *p, int varnum) +static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum) { INPparseNode *arg1, *arg2, *newp; @@ -156,182 +159,218 @@ PTdifferentiate(INPparseNode *p, int varnum) switch (p->type) { case PT_CONSTANT: - newp = mkcon((double) 0); - break; + newp = mkcon((double) 0); + break; case PT_VAR: - /* Is this the variable we're differentiating wrt? */ - if (p->valueIndex == varnum) - newp = mkcon((double) 1); - else - newp = mkcon((double) 0); - break; + /* Is this the variable we're differentiating wrt? */ + if (p->valueIndex == varnum) + newp = mkcon((double) 1); + else + newp = mkcon((double) 0); + break; case PT_PLUS: case PT_MINUS: - arg1 = PTdifferentiate(p->left, varnum); - arg2 = PTdifferentiate(p->right, varnum); - newp = mkb(p->type, arg1, arg2); - break; + arg1 = PTdifferentiate(p->left, varnum); + arg2 = PTdifferentiate(p->right, varnum); + newp = mkb(p->type, arg1, arg2); + break; case PT_TIMES: - /* d(a * b) = d(a) * b + d(b) * a */ - arg1 = PTdifferentiate(p->left, varnum); - arg2 = PTdifferentiate(p->right, varnum); + /* d(a * b) = d(a) * b + d(b) * a */ + arg1 = PTdifferentiate(p->left, varnum); + arg2 = PTdifferentiate(p->right, varnum); - newp = mkb(PT_PLUS, mkb(PT_TIMES, arg1, p->right), - mkb(PT_TIMES, p->left, arg2)); - break; + newp = mkb(PT_PLUS, mkb(PT_TIMES, arg1, p->right), + mkb(PT_TIMES, p->left, arg2)); + break; case PT_DIVIDE: - /* d(a / b) = (d(a) * b - d(b) * a) / b^2 */ - arg1 = PTdifferentiate(p->left, varnum); - arg2 = PTdifferentiate(p->right, varnum); + /* d(a / b) = (d(a) * b - d(b) * a) / b^2 */ + arg1 = PTdifferentiate(p->left, varnum); + arg2 = PTdifferentiate(p->right, varnum); - newp = mkb(PT_DIVIDE, mkb(PT_MINUS, mkb(PT_TIMES, arg1, - p->right), mkb(PT_TIMES, p->left, arg2)), - mkb(PT_POWER, p->right, mkcon((double) 2))); - break; + newp = mkb(PT_DIVIDE, mkb(PT_MINUS, mkb(PT_TIMES, arg1, + p->right), mkb(PT_TIMES, + p->left, + arg2)), + mkb(PT_POWER, p->right, mkcon((double) 2))); + break; case PT_POWER: - /* Two cases... If the power is a constant then we're cool. - * Otherwise we have to be tricky. - */ - if (p->right->type == PT_CONSTANT) { - arg1 = PTdifferentiate(p->left, varnum); + /* Two cases... If the power is a constant then we're cool. + * Otherwise we have to be tricky. + */ + if (p->right->type == PT_CONSTANT) { + arg1 = PTdifferentiate(p->left, varnum); - newp = mkb(PT_TIMES, mkb(PT_TIMES, - mkcon(p->right->constant), - mkb(PT_POWER, p->left, - mkcon(p->right->constant - 1))), - arg1); - } else { - /* This is complicated. f(x) ^ g(x) -> - * exp(y(x) * ln(f(x)) ... - */ - arg1 = PTdifferentiate(p->left, varnum); - arg2 = PTdifferentiate(p->right, varnum); - newp = mkb(PT_TIMES, mkf(PTF_EXP, mkb(PT_TIMES, - p->right, mkf(PTF_LN, p->left))), - mkb(PT_PLUS, mkb(PT_TIMES, p->right, - mkb(PT_DIVIDE, arg1, p->left)), - mkb(PT_TIMES, arg2, - mkf(PTF_LN, arg1)))); + newp = mkb(PT_TIMES, mkb(PT_TIMES, + mkcon(p->right->constant), + mkb(PT_POWER, p->left, + mkcon(p->right->constant - 1))), + arg1); + } else { + /* This is complicated. f(x) ^ g(x) -> + * exp(y(x) * ln(f(x)) ... + */ + arg1 = PTdifferentiate(p->left, varnum); + arg2 = PTdifferentiate(p->right, varnum); + newp = mkb(PT_TIMES, mkf(PTF_EXP, mkb(PT_TIMES, + p->right, mkf(PTF_LN, + p->left))), + mkb(PT_PLUS, + mkb(PT_TIMES, p->right, + mkb(PT_DIVIDE, arg1, p->left)), + mkb(PT_TIMES, arg2, mkf(PTF_LN, arg1)))); - } - break; + } + break; case PT_FUNCTION: - /* Many cases. Set arg1 to the derivative of the function, - * and arg2 to the derivative of the argument. - */ - switch (p->funcnum) { - case PTF_ABS: /* sgn(u) */ - /* arg1 = mkf(PTF_SGN, p->left, 0); */ - arg1 = mkf(PTF_SGN, p->left); - break; + /* Many cases. Set arg1 to the derivative of the function, + * and arg2 to the derivative of the argument. + */ + switch (p->funcnum) { + case PTF_ABS: /* sgn(u) */ + /* arg1 = mkf(PTF_SGN, p->left, 0); */ + arg1 = mkf(PTF_SGN, p->left); + break; - case PTF_SGN: - arg1 = mkcon((double) 0.0); - break; + case PTF_SGN: + arg1 = mkcon((double) 0.0); + break; - case PTF_ACOS: /* - 1 / sqrt(1 - u^2) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) -1), mkf(PTF_SQRT, - mkb(PT_MINUS, mkcon((double) 1), - mkb(PT_POWER, p->left, mkcon((double) - 2))))); - break; + case PTF_ACOS: /* - 1 / sqrt(1 - u^2) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) -1), mkf(PTF_SQRT, + mkb(PT_MINUS, + mkcon( + (double) + 1), + mkb(PT_POWER, + p->left, + mkcon( + (double) + 2))))); + break; - case PTF_ACOSH: /* 1 / sqrt(u^2 - 1) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkf(PTF_SQRT, - mkb(PT_MINUS, mkb(PT_POWER, p->left, - mkcon((double) 2)), - mkcon((double) 1)))); + case PTF_ACOSH: /* 1 / sqrt(u^2 - 1) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkf(PTF_SQRT, + mkb(PT_MINUS, + mkb(PT_POWER, + p->left, + mkcon( + (double) + 2)), + mkcon((double) + 1)))); - break; + break; - case PTF_ASIN: /* 1 / sqrt(1 - u^2) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkf(PTF_SQRT, - mkb(PT_MINUS, mkcon((double) 1), - mkb(PT_POWER, p->left, mkcon((double) - 2))))); - break; + case PTF_ASIN: /* 1 / sqrt(1 - u^2) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkf(PTF_SQRT, + mkb(PT_MINUS, + mkcon((double) + 1), + mkb(PT_POWER, + p->left, + mkcon( + (double) + 2))))); + break; - case PTF_ASINH: /* 1 / sqrt(u^2 + 1) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkf(PTF_SQRT, - mkb(PT_PLUS, mkb(PT_POWER, p->left, - mkcon((double) 2)), - mkcon((double) 1)))); - break; + case PTF_ASINH: /* 1 / sqrt(u^2 + 1) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkf(PTF_SQRT, + mkb(PT_PLUS, + mkb(PT_POWER, + p->left, + mkcon( + (double) + 2)), + mkcon((double) + 1)))); + break; - case PTF_ATAN: /* 1 / (1 + u^2) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_PLUS, - mkb(PT_POWER, p->left, mkcon((double) - 2)), mkcon((double) 1))); - break; + case PTF_ATAN: /* 1 / (1 + u^2) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_PLUS, + mkb(PT_POWER, + p->left, + mkcon((double) + 2)), + mkcon((double) + 1))); + break; - case PTF_ATANH: /* 1 / (1 - u^2) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_MINUS, - mkcon((double) 1), mkb(PT_POWER, - p->left, mkcon((double) 2)))); - break; + case PTF_ATANH: /* 1 / (1 - u^2) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_MINUS, + mkcon((double) 1), + mkb(PT_POWER, + p->left, + mkcon((double) + 2)))); + break; - case PTF_COS: /* - sin(u) */ - arg1 = mkf(PTF_UMINUS, mkf(PTF_SIN, p->left)); - break; + case PTF_COS: /* - sin(u) */ + arg1 = mkf(PTF_UMINUS, mkf(PTF_SIN, p->left)); + break; - case PTF_COSH: /* sinh(u) */ - arg1 = mkf(PTF_SINH, p->left); - break; + case PTF_COSH: /* sinh(u) */ + arg1 = mkf(PTF_SINH, p->left); + break; - case PTF_EXP: /* exp(u) */ - /* arg1 = mkf(PTF_EXP, p->left, 0); */ - arg1 = mkf(PTF_EXP, p->left); - break; + case PTF_EXP: /* exp(u) */ + /* arg1 = mkf(PTF_EXP, p->left, 0); */ + arg1 = mkf(PTF_EXP, p->left); + break; - case PTF_LN: /* 1 / u */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), p->left); - break; + case PTF_LN: /* 1 / u */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), p->left); + break; - case PTF_LOG: /* log(e) / u */ - arg1 = mkb(PT_DIVIDE, mkcon((double) M_LOG10E), p->left); - break; + case PTF_LOG: /* log(e) / u */ + arg1 = mkb(PT_DIVIDE, mkcon((double) M_LOG10E), p->left); + break; - case PTF_SIN: /* cos(u) */ - arg1 = mkf(PTF_COS, p->left); - break; + case PTF_SIN: /* cos(u) */ + arg1 = mkf(PTF_COS, p->left); + break; - case PTF_SINH: /* cosh(u) */ - arg1 = mkf(PTF_COSH, p->left); - break; + case PTF_SINH: /* cosh(u) */ + arg1 = mkf(PTF_COSH, p->left); + break; - case PTF_SQRT: /* 1 / (2 * sqrt(u)) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_TIMES, - mkcon((double) 2), mkf(PTF_SQRT, - p->left))); - break; + case PTF_SQRT: /* 1 / (2 * sqrt(u)) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_TIMES, + mkcon((double) 2), + mkf(PTF_SQRT, + p->left))); + break; - case PTF_TAN: /* 1 / (cos(u) ^ 2) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_POWER, - mkf(PTF_COS, p->left), mkcon((double) - 2))); - break; + case PTF_TAN: /* 1 / (cos(u) ^ 2) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_POWER, + mkf(PTF_COS, + p->left), + mkcon((double) + 2))); + break; - case PTF_TANH: /* 1 / (cosh(u) ^ 2) */ - arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_POWER, - mkf(PTF_COSH, p->left), mkcon((double) - 2))); - break; + case PTF_TANH: /* 1 / (cosh(u) ^ 2) */ + arg1 = mkb(PT_DIVIDE, mkcon((double) 1), mkb(PT_POWER, + mkf(PTF_COSH, + p->left), + mkcon((double) + 2))); + break; - case PTF_USTEP: - arg1 = mkcon((double) 0.0); - break; + case PTF_USTEP: + arg1 = mkcon((double) 0.0); + break; - case PTF_URAMP: + case PTF_URAMP: arg1 = mkf(PTF_USTEP, p->left); - break; + break; -/* MW. PTF_CIF for new cif function */ + /* MW. PTF_CIF for new cif function */ case PTF_USTEP2: arg1 = mkcon((double) 0.0); break; @@ -341,32 +380,31 @@ PTdifferentiate(INPparseNode *p, int varnum) break; default: - fprintf(stderr, "Internal Error: bad function # %d\n", - p->funcnum); - newp = NULL; - break; - } + fprintf(stderr, "Internal Error: bad function # %d\n", + p->funcnum); + newp = NULL; + break; + } - arg2 = PTdifferentiate(p->left, varnum); + arg2 = PTdifferentiate(p->left, varnum); - newp = mkb(PT_TIMES, arg1, arg2); + newp = mkb(PT_TIMES, arg1, arg2); - break; + break; default: - fprintf(stderr, "Internal error: bad node type %d\n", p->type); - newp = NULL; - break; + fprintf(stderr, "Internal error: bad node type %d\n", p->type); + newp = NULL; + break; } /* printf("result is: "); printTree(newp); printf("\n"); */ return (newp); } -static INPparseNode * -mkcon(double value) +static INPparseNode *mkcon(double value) { - INPparseNode *p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + INPparseNode *p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); p->type = PT_CONSTANT; p->constant = value; @@ -374,71 +412,71 @@ mkcon(double value) return (p); } -static INPparseNode * -mkb(int type, INPparseNode *left, INPparseNode *right) +static INPparseNode *mkb(int type, INPparseNode * left, + INPparseNode * right) { - INPparseNode *p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + INPparseNode *p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); int i; if ((right->type == PT_CONSTANT) && (left->type == PT_CONSTANT)) { - switch (type) { - case PT_TIMES: - return (mkcon(left->constant * right->constant)); + switch (type) { + case PT_TIMES: + return (mkcon(left->constant * right->constant)); - case PT_DIVIDE: - return (mkcon(left->constant / right->constant)); + case PT_DIVIDE: + return (mkcon(left->constant / right->constant)); - case PT_PLUS: - return (mkcon(left->constant + right->constant)); + case PT_PLUS: + return (mkcon(left->constant + right->constant)); - case PT_MINUS: - return (mkcon(left->constant - right->constant)); + case PT_MINUS: + return (mkcon(left->constant - right->constant)); - case PT_POWER: - return (mkcon(pow(left->constant, right->constant))); - } + case PT_POWER: + return (mkcon(pow(left->constant, right->constant))); + } } switch (type) { - case PT_TIMES: - if ((left->type == PT_CONSTANT) && (left->constant == 0)) - return (left); - else if ((right->type == PT_CONSTANT) && (right->constant == 0)) - return (right); - else if ((left->type == PT_CONSTANT) && (left->constant == 1)) - return (right); - else if ((right->type == PT_CONSTANT) && (right->constant == 1)) - return (left); - break; - - case PT_DIVIDE: - if ((left->type == PT_CONSTANT) && (left->constant == 0)) - return (left); - else if ((right->type == PT_CONSTANT) && (right->constant == 1)) - return (left); - break; + case PT_TIMES: + if ((left->type == PT_CONSTANT) && (left->constant == 0)) + return (left); + else if ((right->type == PT_CONSTANT) && (right->constant == 0)) + return (right); + else if ((left->type == PT_CONSTANT) && (left->constant == 1)) + return (right); + else if ((right->type == PT_CONSTANT) && (right->constant == 1)) + return (left); + break; - case PT_PLUS: - if ((left->type == PT_CONSTANT) && (left->constant == 0)) - return (right); - else if ((right->type == PT_CONSTANT) && (right->constant == 0)) - return (left); - break; + case PT_DIVIDE: + if ((left->type == PT_CONSTANT) && (left->constant == 0)) + return (left); + else if ((right->type == PT_CONSTANT) && (right->constant == 1)) + return (left); + break; - case PT_MINUS: - if ((right->type == PT_CONSTANT) && (right->constant == 0)) - return (left); - else if ((left->type == PT_CONSTANT) && (left->constant == 0)) - return (mkf(PTF_UMINUS, right)); - break; - - case PT_POWER: - if (right->type == PT_CONSTANT) { - if (right->constant == 0) - return (mkcon(1.0)); - else if (right->constant == 1) - return (left); - } - break; + case PT_PLUS: + if ((left->type == PT_CONSTANT) && (left->constant == 0)) + return (right); + else if ((right->type == PT_CONSTANT) && (right->constant == 0)) + return (left); + break; + + case PT_MINUS: + if ((right->type == PT_CONSTANT) && (right->constant == 0)) + return (left); + else if ((left->type == PT_CONSTANT) && (left->constant == 0)) + return (mkf(PTF_UMINUS, right)); + break; + + case PT_POWER: + if (right->type == PT_CONSTANT) { + if (right->constant == 0) + return (mkcon(1.0)); + else if (right->constant == 1) + return (left); + } + break; } p->type = type; @@ -446,11 +484,11 @@ mkb(int type, INPparseNode *left, INPparseNode *right) p->right = right; for (i = 0; i < NUM_OPS; i++) - if (ops[i].number == type) - break; + if (ops[i].number == type) + break; if (i == NUM_OPS) { - fprintf(stderr, "Internal Error: bad type %d\n", type); - return (NULL); + fprintf(stderr, "Internal Error: bad type %d\n", type); + return (NULL); } p->function = ops[i].funcptr; p->funcname = ops[i].name; @@ -458,24 +496,23 @@ mkb(int type, INPparseNode *left, INPparseNode *right) return (p); } -static INPparseNode * -mkf(int type, INPparseNode *arg) +static INPparseNode *mkf(int type, INPparseNode * arg) { - INPparseNode *p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + INPparseNode *p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); int i; double constval; for (i = 0; i < NUM_FUNCS; i++) - if (funcs[i].number == type) - break; + if (funcs[i].number == type) + break; if (i == NUM_FUNCS) { - fprintf(stderr, "Internal Error: bad type %d\n", type); - return (NULL); + fprintf(stderr, "Internal Error: bad type %d\n", type); + return (NULL); } if (arg->type == PT_CONSTANT) { - constval = ((*funcs[i].funcptr) (arg->constant)); - return (mkcon(constval)); + constval = ((*funcs[i].funcptr) (arg->constant)); + return (mkcon(constval)); } p->type = PT_FUNCTION; @@ -490,60 +527,58 @@ mkf(int type, INPparseNode *arg) /* Check for remaining PT_PLACEHOLDERs in the parse tree. Returns 1 if ok. */ -static int -PTcheck(INPparseNode *p) +static int PTcheck(INPparseNode * p) { switch (p->type) { case PT_PLACEHOLDER: - return (0); + return (0); case PT_CONSTANT: case PT_VAR: - return (1); + return (1); case PT_FUNCTION: - return (PTcheck(p->left)); + return (PTcheck(p->left)); case PT_PLUS: case PT_MINUS: case PT_TIMES: case PT_DIVIDE: case PT_POWER: - return (PTcheck(p->left) && PTcheck(p->right)); - + return (PTcheck(p->left) && PTcheck(p->right)); + default: - fprintf(stderr, "Internal error: bad node type %d\n", p->type); - return (0); + fprintf(stderr, "Internal error: bad node type %d\n", p->type); + return (0); } } /* The operator-precedence table for the parser. */ -#define G 1 /* Greater than. */ -#define L 2 /* Less than. */ -#define E 3 /* Equal. */ -#define R 4 /* Error. */ +#define G 1 /* Greater than. */ +#define L 2 /* Less than. */ +#define E 3 /* Equal. */ +#define R 4 /* Error. */ static char prectable[11][11] = { - /* $ + - * / ^ u- ( ) v , */ -/* $ */ { R, L, L, L, L, L, L, L, R, L, R }, -/* + */ { G, G, G, L, L, L, L, L, G, L, G }, -/* - */ { G, G, G, L, L, L, L, L, G, L, G }, -/* * */ { G, G, G, G, G, L, L, L, G, L, G }, -/* / */ { G, G, G, G, G, L, L, L, G, L, G }, -/* ^ */ { G, G, G, G, G, L, L, L, G, L, G }, -/* u-*/ { G, G, G, G, G, G, G, L, G, L, R }, -/* ( */ { R, L, L, L, L, L, L, L, E, L, L }, -/* ) */ { G, G, G, G, G, G, G, R, G, R, G }, -/* v */ { G, G, G, G, G, G, G, G, G, R, G }, -/* , */ { G, L, L, L, L, L, L, L, G, L, G } + /* $ + - * / ^ u- ( ) v , */ +/* $ */ {R, L, L, L, L, L, L, L, R, L, R}, +/* + */ {G, G, G, L, L, L, L, L, G, L, G}, +/* - */ {G, G, G, L, L, L, L, L, G, L, G}, +/* * */ {G, G, G, G, G, L, L, L, G, L, G}, +/* / */ {G, G, G, G, G, L, L, L, G, L, G}, +/* ^ */ {G, G, G, G, G, L, L, L, G, L, G}, +/* u-*/ {G, G, G, G, G, G, G, L, G, L, R}, +/* ( */ {R, L, L, L, L, L, L, L, E, L, L}, +/* ) */ {G, G, G, G, G, G, G, R, G, R, G}, +/* v */ {G, G, G, G, G, G, G, G, G, R, G}, +/* , */ {G, L, L, L, L, L, L, L, G, L, G} -} ; +}; /* Return an expr. */ -static INPparseNode * -PTparse(char **line) +static INPparseNode *PTparse(char **line) { PTelement stack[PT_STACKSIZE]; int sp = 0, st, i; @@ -554,99 +589,97 @@ PTparse(char **line) next = PTlexer(line); while ((sp > 1) || (next->token != TOK_END)) { - /* Find the top-most terminal. */ - i = sp; - do { - top = &stack[i--]; - } while (top->token == TOK_VALUE); + /* Find the top-most terminal. */ + i = sp; + do { + top = &stack[i--]; + } while (top->token == TOK_VALUE); - switch (prectable[top->token][next->token]) { - case L: - case E: - /* Push the token read. */ - if (sp == (PT_STACKSIZE - 1)) { - fprintf(stderr, "Error: stack overflow\n"); - return (NULL); - } - bcopy((char *) next, (char *) &stack[++sp], - sizeof (PTelement)); - next = PTlexer(line); - continue; + switch (prectable[top->token][next->token]) { + case L: + case E: + /* Push the token read. */ + if (sp == (PT_STACKSIZE - 1)) { + fprintf(stderr, "Error: stack overflow\n"); + return (NULL); + } + bcopy((char *) next, (char *) &stack[++sp], sizeof(PTelement)); + next = PTlexer(line); + continue; - case R: - fprintf(stderr, "Syntax error.\n"); - return (NULL); + case R: + fprintf(stderr, "Syntax error.\n"); + return (NULL); - case G: - /* Reduce. Make st and sp point to the elts on the - * stack at the end and beginning of the junk to - * reduce, then try and do some stuff. When scanning - * back for a <, ignore VALUES. - */ - st = sp; - if (stack[sp].token == TOK_VALUE) - sp--; - while (sp > 0) { - if (stack[sp - 1].token == TOK_VALUE) - i = 2; /* No 2 pnodes together... */ - else - i = 1; - if (prectable[stack[sp - i].token] - [stack[sp].token] == L) - break; - else - sp = sp - i; - } - if (stack[sp - 1].token == TOK_VALUE) - sp--; - /* Now try and see what we can make of this. - * The possibilities are: - node - * node op node - * ( node ) - * func ( node ) - * func ( node, node, node, ... ) <- new - * node - */ - if (st == sp) { - pn = makepnode(&stack[st]); - if (pn == NULL) - goto err; - } else if ((stack[sp].token == TOK_UMINUS) && - (st == sp + 1)) { - lpn = makepnode(&stack[st]); - if (lpn == NULL) - goto err; - pn = mkfnode("-", lpn); - } else if ((stack[sp].token == TOK_LPAREN) && - (stack[st].token == TOK_RPAREN)) { - pn = makepnode(&stack[sp + 1]); - if (pn == NULL) - goto err; - } else if ((stack[sp + 1].token == TOK_LPAREN) && - (stack[st].token == TOK_RPAREN)) { - lpn = makepnode(&stack[sp + 2]); - if ((lpn == NULL) || (stack[sp].type != TYP_STRING)) - goto err; - if (!(pn = mkfnode(stack[sp].value.string, lpn))) - return (NULL); - } else { /* node op node */ - lpn = makepnode(&stack[sp]); - rpn = makepnode(&stack[st]); - if ((lpn == NULL) || (rpn == NULL)) - goto err; - pn = mkbnode(stack[sp + 1].token, lpn, rpn); - } - stack[sp].token = TOK_VALUE; - stack[sp].type = TYP_PNODE; - stack[sp].value.pnode = pn; - continue; - } + case G: + /* Reduce. Make st and sp point to the elts on the + * stack at the end and beginning of the junk to + * reduce, then try and do some stuff. When scanning + * back for a <, ignore VALUES. + */ + st = sp; + if (stack[sp].token == TOK_VALUE) + sp--; + while (sp > 0) { + if (stack[sp - 1].token == TOK_VALUE) + i = 2; /* No 2 pnodes together... */ + else + i = 1; + if (prectable[stack[sp - i].token] + [stack[sp].token] == L) + break; + else + sp = sp - i; + } + if (stack[sp - 1].token == TOK_VALUE) + sp--; + /* Now try and see what we can make of this. + * The possibilities are: - node + * node op node + * ( node ) + * func ( node ) + * func ( node, node, node, ... ) <- new + * node + */ + if (st == sp) { + pn = makepnode(&stack[st]); + if (pn == NULL) + goto err; + } else if ((stack[sp].token == TOK_UMINUS) && (st == sp + 1)) { + lpn = makepnode(&stack[st]); + if (lpn == NULL) + goto err; + pn = mkfnode("-", lpn); + } else if ((stack[sp].token == TOK_LPAREN) && + (stack[st].token == TOK_RPAREN)) { + pn = makepnode(&stack[sp + 1]); + if (pn == NULL) + goto err; + } else if ((stack[sp + 1].token == TOK_LPAREN) && + (stack[st].token == TOK_RPAREN)) { + lpn = makepnode(&stack[sp + 2]); + if ((lpn == NULL) || (stack[sp].type != TYP_STRING)) + goto err; + if (!(pn = mkfnode(stack[sp].value.string, lpn))) + return (NULL); + } else { /* node op node */ + lpn = makepnode(&stack[sp]); + rpn = makepnode(&stack[st]); + if ((lpn == NULL) || (rpn == NULL)) + goto err; + pn = mkbnode(stack[sp + 1].token, lpn, rpn); + } + stack[sp].token = TOK_VALUE; + stack[sp].type = TYP_PNODE; + stack[sp].value.pnode = pn; + continue; + } } pn = makepnode(&stack[1]); if (pn) - return (pn); -err: + return (pn); + err: fprintf(stderr, "Syntax error.\n"); return (NULL); } @@ -656,46 +689,44 @@ err: * NULL. */ -static INPparseNode * -makepnode(PTelement *elem) +static INPparseNode *makepnode(PTelement * elem) { if (elem->token != TOK_VALUE) - return (NULL); + return (NULL); switch (elem->type) { case TYP_STRING: - return (mksnode(elem->value.string)); + return (mksnode(elem->value.string)); case TYP_NUM: - return (mknnode(elem->value.real)); + return (mknnode(elem->value.real)); case TYP_PNODE: - return (elem->value.pnode); + return (elem->value.pnode); default: - fprintf(stderr, "Internal Error: bad token type\n"); - return (NULL); - } + fprintf(stderr, "Internal Error: bad token type\n"); + return (NULL); + } } /* Binop node. */ -static INPparseNode * -mkbnode(int opnum, INPparseNode *arg1, INPparseNode *arg2) +static INPparseNode *mkbnode(int opnum, INPparseNode * arg1, + INPparseNode * arg2) { INPparseNode *p; int i; for (i = 0; i < NUM_OPS; i++) - if (ops[i].number == opnum) - break; + if (ops[i].number == opnum) + break; if (i == NUM_OPS) { - fprintf(stderr, "Internal Error: no such op num %d\n", - opnum); - return (NULL); + fprintf(stderr, "Internal Error: no such op num %d\n", opnum); + return (NULL); } - p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); p->type = opnum; p->funcname = ops[i].name; @@ -706,8 +737,7 @@ mkbnode(int opnum, INPparseNode *arg1, INPparseNode *arg2) return (p); } -static INPparseNode * -mkfnode(char *fname, INPparseNode *arg) +static INPparseNode *mkfnode(char *fname, INPparseNode * arg) { int i; INPparseNode *p; @@ -717,42 +747,43 @@ mkfnode(char *fname, INPparseNode *arg) /* Make sure the case is ok. */ (void) strcpy(buf, fname); for (s = buf; *s; s++) - if (isupper(*s)) - *s = tolower(*s); + if (isupper(*s)) + *s = tolower(*s); - p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); if (!strcmp(buf, "v")) { - name = MALLOC(128); - if (arg->type == PT_PLACEHOLDER) { - strcpy(name, arg->funcname); - } else if (arg->type == PT_CONSTANT) { - (void) sprintf(name, "%d", (int) arg->constant); - } else if (arg->type != PT_COMMA) { - fprintf(stderr, "Error: badly formed node voltage\n"); - return (NULL); - } + name = MALLOC(128); + if (arg->type == PT_PLACEHOLDER) { + strcpy(name, arg->funcname); + } else if (arg->type == PT_CONSTANT) { + (void) sprintf(name, "%d", (int) arg->constant); + } else if (arg->type != PT_COMMA) { + fprintf(stderr, "Error: badly formed node voltage\n"); + return (NULL); + } - if (arg->type == PT_COMMA) { + if (arg->type == PT_COMMA) { /* Change v(a,b) into v(a) - v(b) */ p = mkb(PT_MINUS, mkfnode(fname, arg->left), - mkfnode(fname, arg->right)); - } else { + mkfnode(fname, arg->right)); + } else { /* printf("getting a node called '%s'\n", name); */ INPtermInsert(circuit, &name, tables, &(temp.nValue)); for (i = 0; i < numvalues; i++) if ((types[i] == IF_NODE) && (values[i].nValue == - temp.nValue)) - break; + temp.nValue)) break; if (i == numvalues) { if (numvalues) { - values = (IFvalue *) - REALLOC((char *) values, (numvalues + 1) * sizeof (IFvalue)); - types = (int *) - REALLOC((char *) types, (numvalues + 1) * sizeof (int)); + values = (IFvalue *) + REALLOC((char *) values, + (numvalues + 1) * sizeof(IFvalue)); + types = (int *) + REALLOC((char *) types, + (numvalues + 1) * sizeof(int)); } else { - values = (IFvalue *) MALLOC(sizeof (IFvalue)); - types = (int *) MALLOC(sizeof (int)); + values = (IFvalue *) MALLOC(sizeof(IFvalue)); + types = (int *) MALLOC(sizeof(int)); } values[i] = temp; types[i] = IF_NODE; @@ -762,42 +793,42 @@ mkfnode(char *fname, INPparseNode *arg) p->type = PT_VAR; } } else if (!strcmp(buf, "i")) { - name = MALLOC(128); - if (arg->type == PT_PLACEHOLDER) - strcpy(name, arg->funcname); - else if (arg->type == PT_CONSTANT) - (void) sprintf(name, "%d", (int) arg->constant); - else { - fprintf(stderr, "Error: badly formed branch current\n"); - return (NULL); - } + name = MALLOC(128); + if (arg->type == PT_PLACEHOLDER) + strcpy(name, arg->funcname); + else if (arg->type == PT_CONSTANT) + (void) sprintf(name, "%d", (int) arg->constant); + else { + fprintf(stderr, "Error: badly formed branch current\n"); + return (NULL); + } /* printf("getting a device called '%s'\n", name); */ - INPinsert(&name, tables); - for (i = 0; i < numvalues; i++) - if ((types[i] == IF_INSTANCE) && (values[i].uValue == - temp.uValue)) - break; - if (i == numvalues) { - if (numvalues) { - values = (IFvalue *) - REALLOC((char *) values, (numvalues + 1) * sizeof (IFvalue)); - types = (int *) - REALLOC((char *) types, (numvalues + 1) * sizeof (int)); - } else { - values = (IFvalue *) MALLOC(sizeof (IFvalue)); - types = (int *) MALLOC(sizeof (int)); - } - values[i].uValue = (IFuid) name; - types[i] = IF_INSTANCE; - numvalues++; - } - p->valueIndex = i; - p->type = PT_VAR; + INPinsert(&name, tables); + for (i = 0; i < numvalues; i++) + if ((types[i] == IF_INSTANCE) && (values[i].uValue == + temp.uValue)) break; + if (i == numvalues) { + if (numvalues) { + values = (IFvalue *) + REALLOC((char *) values, + (numvalues + 1) * sizeof(IFvalue)); + types = (int *) + REALLOC((char *) types, (numvalues + 1) * sizeof(int)); + } else { + values = (IFvalue *) MALLOC(sizeof(IFvalue)); + types = (int *) MALLOC(sizeof(int)); + } + values[i].uValue = (IFuid) name; + types[i] = IF_INSTANCE; + numvalues++; + } + p->valueIndex = i; + p->type = PT_VAR; } else { for (i = 0; i < NUM_FUNCS; i++) if (!strcmp(funcs[i].name, buf)) break; - + if (i == NUM_FUNCS) { fprintf(stderr, "Error: no such function '%s'\n", buf); return (NULL); @@ -815,12 +846,11 @@ mkfnode(char *fname, INPparseNode *arg) /* Number node. */ -static INPparseNode * -mknnode(double number) +static INPparseNode *mknnode(double number) { struct INPparseNode *p; - p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); p->type = PT_CONSTANT; p->constant = number; @@ -830,8 +860,7 @@ mknnode(double number) /* String node. */ -static INPparseNode * -mksnode(char *string) +static INPparseNode *mksnode(char *string) { int i, j; char buf[128], *s; @@ -840,51 +869,51 @@ mksnode(char *string) /* Make sure the case is ok. */ (void) strcpy(buf, string); for (s = buf; *s; s++) - if (isupper(*s)) - *s = tolower(*s); + if (isupper(*s)) + *s = tolower(*s); - p = (INPparseNode *) MALLOC(sizeof (INPparseNode)); + p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); /* First see if it's something special. */ for (i = 0; i < ft_sim->numSpecSigs; i++) - if (!strcmp(ft_sim->specSigs[i], buf)) - break; + if (!strcmp(ft_sim->specSigs[i], buf)) + break; if (i < ft_sim->numSpecSigs) { - for (j = 0; j < numvalues; j++) - if ((types[j] == IF_STRING) && !strcmp(buf, - values[i].sValue)) - break; - if (j == numvalues) { - if (numvalues) { - values = (IFvalue *) - REALLOC((char *) values, (numvalues + 1) * sizeof (IFvalue)); - types = (int *) - REALLOC((char *) types, (numvalues + 1) * sizeof (int)); - } else { - values = (IFvalue *) MALLOC(sizeof (IFvalue)); - types = (int *) MALLOC(sizeof (int)); - } - values[i].sValue = MALLOC(strlen(buf) + 1); - strcpy(values[i].sValue, buf); - types[i] = IF_STRING; - numvalues++; - } - p->valueIndex = i; - p->type = PT_VAR; - return (p); + for (j = 0; j < numvalues; j++) + if ((types[j] == IF_STRING) && !strcmp(buf, values[i].sValue)) + break; + if (j == numvalues) { + if (numvalues) { + values = (IFvalue *) + REALLOC((char *) values, + (numvalues + 1) * sizeof(IFvalue)); + types = (int *) + REALLOC((char *) types, (numvalues + 1) * sizeof(int)); + } else { + values = (IFvalue *) MALLOC(sizeof(IFvalue)); + types = (int *) MALLOC(sizeof(int)); + } + values[i].sValue = MALLOC(strlen(buf) + 1); + strcpy(values[i].sValue, buf); + types[i] = IF_STRING; + numvalues++; + } + p->valueIndex = i; + p->type = PT_VAR; + return (p); } for (i = 0; i < NUM_CONSTANTS; i++) - if (!strcmp(constants[i].name, buf)) - break; - + if (!strcmp(constants[i].name, buf)) + break; + if (i == NUM_CONSTANTS) { - /* We'd better save this in case it's part of i(something). */ - p->type = PT_PLACEHOLDER; - p->funcname = string; + /* We'd better save this in case it's part of i(something). */ + p->type = PT_PLACEHOLDER; + p->funcname = string; } else { - p->type = PT_CONSTANT; - p->constant = constants[i].value; + p->type = PT_CONSTANT; + p->constant = constants[i].value; } return (p); @@ -892,8 +921,7 @@ mksnode(char *string) /* The lexical analysis routine. */ -static PTelement * -PTlexer(char **line) +static PTelement *PTlexer(char **line) { double td; int err; @@ -908,83 +936,83 @@ PTlexer(char **line) sbuf, lasttoken, lasttype); #endif while ((*sbuf == ' ') || (*sbuf == '\t') || (*sbuf == '=')) - sbuf++; + sbuf++; switch (*sbuf) { case '\0': - el.token = TOK_END; - break; + el.token = TOK_END; + break; case ',': el.token = TOK_COMMA; - sbuf++; + sbuf++; break; case '-': - if ((lasttoken == TOK_VALUE) || (lasttoken == TOK_RPAREN)) - el.token = TOK_MINUS; - else - el.token = TOK_UMINUS; - sbuf++; - break; + if ((lasttoken == TOK_VALUE) || (lasttoken == TOK_RPAREN)) + el.token = TOK_MINUS; + else + el.token = TOK_UMINUS; + sbuf++; + break; case '+': - el.token = TOK_PLUS; - sbuf++; - break; + el.token = TOK_PLUS; + sbuf++; + break; case '*': - el.token = TOK_TIMES; - sbuf++; - break; + el.token = TOK_TIMES; + sbuf++; + break; case '/': - el.token = TOK_DIVIDE; - sbuf++; - break; + el.token = TOK_DIVIDE; + sbuf++; + break; case '^': - el.token = TOK_POWER; - sbuf++; - break; + el.token = TOK_POWER; + sbuf++; + break; case '(': - if (((lasttoken == TOK_VALUE) && ((lasttype == TYP_NUM))) || - (lasttoken == TOK_RPAREN)) { - el.token = TOK_END; - } else { - el.token = TOK_LPAREN; - sbuf++; - } - break; + if (((lasttoken == TOK_VALUE) && ((lasttype == TYP_NUM))) || + (lasttoken == TOK_RPAREN)) { + el.token = TOK_END; + } else { + el.token = TOK_LPAREN; + sbuf++; + } + break; case ')': - el.token = TOK_RPAREN; - sbuf++; - break; - + el.token = TOK_RPAREN; + sbuf++; + break; + default: - if ((lasttoken == TOK_VALUE) || (lasttoken == TOK_RPAREN)) { - el.token = TOK_END; - break; - } + if ((lasttoken == TOK_VALUE) || (lasttoken == TOK_RPAREN)) { + el.token = TOK_END; + break; + } td = INPevaluate(&sbuf, &err, 1); - if (err == OK) { - el.token = TOK_VALUE; - el.type = TYP_NUM; - el.value.real = td; - } else { - el.token = TOK_VALUE; - el.type = TYP_STRING; - for (s = sbuf; *s; s++) - if (index(specials, *s)) - break; - el.value.string = MALLOC(s - sbuf + 1); - strncpy(el.value.string, sbuf, s - sbuf); - el.value.string[s - sbuf] = '\0'; - sbuf = s; - } + if (err == OK) { + el.token = TOK_VALUE; + el.type = TYP_NUM; + el.value.real = td; + } else { + el.token = TOK_VALUE; + el.type = TYP_STRING; + for (s = sbuf; *s; s++) + if (index(specials, *s)) + break; + el.value.string = MALLOC(s - sbuf + 1); + strncpy(el.value.string, sbuf, s - sbuf); + el.value.string[s - sbuf] = '\0'; + sbuf = s; + } } lasttoken = el.token; @@ -1003,10 +1031,9 @@ PTlexer(char **line) /* Debugging stuff. */ -void printTree(INPparseNode*); +void printTree(INPparseNode *); -void -INPptPrint(char *str, IFparseTree *ptree) +void INPptPrint(char *str, IFparseTree * ptree) { int i; @@ -1014,74 +1041,73 @@ INPptPrint(char *str, IFparseTree *ptree) printTree(((INPparseTree *) ptree)->tree); printf("\n"); for (i = 0; i < ptree->numVars; i++) { - printf("d / d v%d : ", i); - printTree(((INPparseTree *) ptree)->derivs[i]); - printf("\n"); + printf("d / d v%d : ", i); + printTree(((INPparseTree *) ptree)->derivs[i]); + printf("\n"); } return; } -void -printTree(INPparseNode *pt) +void printTree(INPparseNode * pt) { switch (pt->type) { - case PT_CONSTANT: - printf("%g", pt->constant); - break; + case PT_CONSTANT: + printf("%g", pt->constant); + break; - case PT_VAR: - printf("v%d", pt->valueIndex); - break; + case PT_VAR: + printf("v%d", pt->valueIndex); + break; - case PT_PLUS: - printf("("); - printTree(pt->left); - printf(") + ("); - printTree(pt->right); - printf(")"); - break; + case PT_PLUS: + printf("("); + printTree(pt->left); + printf(") + ("); + printTree(pt->right); + printf(")"); + break; - case PT_MINUS: - printf("("); - printTree(pt->left); - printf(") - ("); - printTree(pt->right); - printf(")"); - break; + case PT_MINUS: + printf("("); + printTree(pt->left); + printf(") - ("); + printTree(pt->right); + printf(")"); + break; - case PT_TIMES: - printf("("); - printTree(pt->left); - printf(") * ("); - printTree(pt->right); - printf(")"); - break; + case PT_TIMES: + printf("("); + printTree(pt->left); + printf(") * ("); + printTree(pt->right); + printf(")"); + break; - case PT_DIVIDE: - printf("("); - printTree(pt->left); - printf(") / ("); - printTree(pt->right); - printf(")"); - break; + case PT_DIVIDE: + printf("("); + printTree(pt->left); + printf(") / ("); + printTree(pt->right); + printf(")"); + break; - case PT_POWER: - printf("("); - printTree(pt->left); - printf(") ^ ("); - printTree(pt->right); - printf(")"); - break; + case PT_POWER: + printf("("); + printTree(pt->left); + printf(") ^ ("); + printTree(pt->right); + printf(")"); + break; - case PT_FUNCTION: - printf("%s (", pt->funcname); - printTree(pt->left); - printf(")"); - break; + case PT_FUNCTION: + printf("%s (", pt->funcname); + printTree(pt->left); + printf(")"); + break; - default: - printf("oops"); - break; + default: + printf("oops"); + break; } return; } diff --git a/src/circuit/inpsymt.c b/src/circuit/inpsymt.c index b228bd20c..1d4e093e3 100644 --- a/src/circuit/inpsymt.c +++ b/src/circuit/inpsymt.c @@ -10,7 +10,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group /* MW. Special INPinsertNofree for routines from spiceif.c and outif.c */ #include "ngspice.h" -#include /* Take this out soon. */ +#include /* Take this out soon. */ #include "ifsim.h" #include "iferrmsg.h" #include "inpdefs.h" @@ -23,52 +23,55 @@ static int hash(char *name, int tsize); /* Initialize the symbol tables. */ -INPtables * -INPtabInit(int numlines) +INPtables *INPtabInit(int numlines) { INPtables *tab; - tab = (INPtables *)tmalloc(sizeof(INPtables)); - tab->INPsymtab = (struct INPtab **) tmalloc((numlines / 4 + 1) * - sizeof (struct INPtab *)); - ZERO(tab->INPsymtab, (numlines / 4 + 1) * sizeof (struct INPtab *)); - tab->INPtermsymtab = (struct INPnTab **) tmalloc(numlines * - sizeof (struct INPnTab *)); - ZERO(tab->INPtermsymtab, numlines * sizeof (struct INPnTab *)); + tab = (INPtables *) tmalloc(sizeof(INPtables)); + tab->INPsymtab = (struct INPtab **) tmalloc((numlines / 4 + 1) * + sizeof(struct INPtab *)); + ZERO(tab->INPsymtab, (numlines / 4 + 1) * sizeof(struct INPtab *)); + tab->INPtermsymtab = (struct INPnTab **) tmalloc(numlines * + sizeof(struct INPnTab + *)); + ZERO(tab->INPtermsymtab, numlines * sizeof(struct INPnTab *)); tab->INPsize = numlines / 4 + 1; tab->INPtermsize = numlines; - return(tab); + return (tab); } /* insert 'token' into the terminal symbol table */ /* create a NEW NODE and return a pointer to it in *node */ -int -INPtermInsert(void *ckt, char **token, INPtables *tab, void **node) +int INPtermInsert(void *ckt, char **token, INPtables * tab, void **node) { - int key; - int error; - struct INPnTab *t; + int key; + int error; + struct INPnTab *t; - key = hash(*token, tab->INPtermsize); - for (t = tab->INPtermsymtab[key]; t; t = t->t_next) { - if (!strcmp(*token, t->t_ent)) { - FREE(*token); - *token = t->t_ent; - if(node) *node = t->t_node; - return(E_EXISTS); - } - } - t = (struct INPnTab *) tmalloc(sizeof (struct INPnTab)); - if(t == (struct INPnTab*)NULL) return(E_NOMEM); - ZERO(t,struct INPnTab); - error = (*(ft_sim->newNode))(ckt,&t->t_node,*token); - if(error) return(error); - if(node) *node = t->t_node; - t->t_ent = *token; - t->t_next = tab->INPtermsymtab[key]; - tab->INPtermsymtab[key] = t; - return(OK); + key = hash(*token, tab->INPtermsize); + for (t = tab->INPtermsymtab[key]; t; t = t->t_next) { + if (!strcmp(*token, t->t_ent)) { + FREE(*token); + *token = t->t_ent; + if (node) + *node = t->t_node; + return (E_EXISTS); + } + } + t = (struct INPnTab *) tmalloc(sizeof(struct INPnTab)); + if (t == (struct INPnTab *) NULL) + return (E_NOMEM); + ZERO(t, struct INPnTab); + error = (*(ft_sim->newNode)) (ckt, &t->t_node, *token); + if (error) + return (error); + if (node) + *node = t->t_node; + t->t_ent = *token; + t->t_next = tab->INPtermsymtab[key]; + tab->INPtermsymtab[key] = t; + return (OK); } @@ -76,205 +79,203 @@ INPtermInsert(void *ckt, char **token, INPtables *tab, void **node) /* USE node as the node pointer */ -int -INPmkTerm(void *ckt, char **token, INPtables *tab, void **node) +int INPmkTerm(void *ckt, char **token, INPtables * tab, void **node) { - int key; - struct INPnTab *t; + int key; + struct INPnTab *t; - key = hash(*token, tab->INPtermsize); - for (t = tab->INPtermsymtab[key]; t; t = t->t_next) { - if (!strcmp(*token, t->t_ent)) { - FREE(*token); - *token = t->t_ent; - if(node) *node = t->t_node; - return(E_EXISTS); - } - } - t = (struct INPnTab *) tmalloc(sizeof (struct INPnTab)); - if(t == (struct INPnTab*)NULL) return(E_NOMEM); - ZERO(t,struct INPnTab); - t->t_node = *node ; - t->t_ent = *token; - t->t_next = tab->INPtermsymtab[key]; - tab->INPtermsymtab[key] = t; - return(OK); + key = hash(*token, tab->INPtermsize); + for (t = tab->INPtermsymtab[key]; t; t = t->t_next) { + if (!strcmp(*token, t->t_ent)) { + FREE(*token); + *token = t->t_ent; + if (node) + *node = t->t_node; + return (E_EXISTS); + } + } + t = (struct INPnTab *) tmalloc(sizeof(struct INPnTab)); + if (t == (struct INPnTab *) NULL) + return (E_NOMEM); + ZERO(t, struct INPnTab); + t->t_node = *node; + t->t_ent = *token; + t->t_next = tab->INPtermsymtab[key]; + tab->INPtermsymtab[key] = t; + return (OK); } /* insert 'token' into the terminal symbol table as a name for ground*/ -int -INPgndInsert(void *ckt, char **token, INPtables *tab, void **node) +int INPgndInsert(void *ckt, char **token, INPtables * tab, void **node) { - int key; - int error; - struct INPnTab *t; + int key; + int error; + struct INPnTab *t; - key = hash(*token, tab->INPtermsize); - for (t = tab->INPtermsymtab[key]; t; t = t->t_next) { - if (!strcmp(*token, t->t_ent)) { - FREE(*token); - *token = t->t_ent; - if(node) *node = t->t_node; - return(E_EXISTS); - } - } - t = (struct INPnTab *) tmalloc(sizeof (struct INPnTab)); - if(t == (struct INPnTab*)NULL) return(E_NOMEM); - ZERO(t,struct INPnTab); - error = (*(ft_sim->groundNode))(ckt,&t->t_node,*token); - if(error) return(error); - if(node) *node = t->t_node; - t->t_ent = *token; - t->t_next = tab->INPtermsymtab[key]; - tab->INPtermsymtab[key] = t; - return(OK); + key = hash(*token, tab->INPtermsize); + for (t = tab->INPtermsymtab[key]; t; t = t->t_next) { + if (!strcmp(*token, t->t_ent)) { + FREE(*token); + *token = t->t_ent; + if (node) + *node = t->t_node; + return (E_EXISTS); + } + } + t = (struct INPnTab *) tmalloc(sizeof(struct INPnTab)); + if (t == (struct INPnTab *) NULL) + return (E_NOMEM); + ZERO(t, struct INPnTab); + error = (*(ft_sim->groundNode)) (ckt, &t->t_node, *token); + if (error) + return (error); + if (node) + *node = t->t_node; + t->t_ent = *token; + t->t_next = tab->INPtermsymtab[key]; + tab->INPtermsymtab[key] = t; + return (OK); } /* retrieve 'token' from the symbol table */ -int -INPretrieve(char **token, INPtables *tab) +int INPretrieve(char **token, INPtables * tab) { - struct INPtab *t; - int key; + struct INPtab *t; + int key; - key = hash(*token, tab->INPsize); - for (t = tab->INPsymtab[key]; t; t = t->t_next) - if (!strcmp(*token, t->t_ent)) { - *token = t->t_ent; - return(OK); - } - return(E_BADPARM); + key = hash(*token, tab->INPsize); + for (t = tab->INPsymtab[key]; t; t = t->t_next) + if (!strcmp(*token, t->t_ent)) { + *token = t->t_ent; + return (OK); + } + return (E_BADPARM); } /* insert 'token' into the symbol table */ -int -INPinsert(char **token, INPtables *tab) +int INPinsert(char **token, INPtables * tab) { - struct INPtab *t; - int key; + struct INPtab *t; + int key; - key = hash(*token, tab->INPsize); - for (t = tab->INPsymtab[key]; t; t = t->t_next) - if (!strcmp(*token, t->t_ent)) { - FREE(*token); - *token = t->t_ent; - return(E_EXISTS); - } - t = (struct INPtab *) tmalloc(sizeof (struct INPtab)); - if(t == (struct INPtab*)NULL) return(E_NOMEM); - ZERO(t,struct INPtab); - t->t_ent = *token; - t->t_next = tab->INPsymtab[key]; - tab->INPsymtab[key] = t; - return(OK); + key = hash(*token, tab->INPsize); + for (t = tab->INPsymtab[key]; t; t = t->t_next) + if (!strcmp(*token, t->t_ent)) { + FREE(*token); + *token = t->t_ent; + return (E_EXISTS); + } + t = (struct INPtab *) tmalloc(sizeof(struct INPtab)); + if (t == (struct INPtab *) NULL) + return (E_NOMEM); + ZERO(t, struct INPtab); + t->t_ent = *token; + t->t_next = tab->INPsymtab[key]; + tab->INPsymtab[key] = t; + return (OK); } /* MW. insert 'token' into the symbol table but no free() token pointer. * Calling routine should take care for this */ -int -INPinsertNofree(char **token, INPtables *tab) +int INPinsertNofree(char **token, INPtables * tab) { - struct INPtab *t; - int key; + struct INPtab *t; + int key; - key = hash(*token, tab->INPsize); - for (t = tab->INPsymtab[key]; t; t = t->t_next) - if (!strcmp(*token, t->t_ent)) { - - /* MW. We can't touch memory pointed by token now */ - *token = t->t_ent; - return(E_EXISTS); - } - t = (struct INPtab *) tmalloc(sizeof (struct INPtab)); - if(t == (struct INPtab*)NULL) return(E_NOMEM); - ZERO(t,struct INPtab); - t->t_ent = *token; - t->t_next = tab->INPsymtab[key]; - tab->INPsymtab[key] = t; - return(OK); + key = hash(*token, tab->INPsize); + for (t = tab->INPsymtab[key]; t; t = t->t_next) + if (!strcmp(*token, t->t_ent)) { + + /* MW. We can't touch memory pointed by token now */ + *token = t->t_ent; + return (E_EXISTS); + } + t = (struct INPtab *) tmalloc(sizeof(struct INPtab)); + if (t == (struct INPtab *) NULL) + return (E_NOMEM); + ZERO(t, struct INPtab); + t->t_ent = *token; + t->t_next = tab->INPsymtab[key]; + tab->INPsymtab[key] = t; + return (OK); } /* remove 'token' from the symbol table */ -int -INPremove(char *token, INPtables *tab) +int INPremove(char *token, INPtables * tab) { - struct INPtab *t, **prevp; - int key; - - key = hash(token, tab->INPsize); - prevp = &tab->INPsymtab[key]; - for (t = *prevp; t && token != t->t_ent; t = t->t_next) - prevp = &t->t_next; - if (!t) - return OK; - - *prevp = t->t_next; - tfree(t->t_ent); - tfree(t); + struct INPtab *t, **prevp; + int key; + key = hash(token, tab->INPsize); + prevp = &tab->INPsymtab[key]; + for (t = *prevp; t && token != t->t_ent; t = t->t_next) + prevp = &t->t_next; + if (!t) return OK; + + *prevp = t->t_next; + tfree(t->t_ent); + tfree(t); + + return OK; } /* remove 'token' from the symbol table */ -int -INPremTerm(char *token, INPtables *tab) +int INPremTerm(char *token, INPtables * tab) { - struct INPnTab *t, **prevp; - int key; - - key = hash(token, tab->INPtermsize); - prevp = &tab->INPtermsymtab[key]; - for (t = *prevp; t && token != t->t_ent; t = t->t_next) - prevp = &t->t_next; - if (!t) - return OK; - - *prevp = t->t_next; - tfree(t->t_ent); - tfree(t); + struct INPnTab *t, **prevp; + int key; + key = hash(token, tab->INPtermsize); + prevp = &tab->INPtermsymtab[key]; + for (t = *prevp; t && token != t->t_ent; t = t->t_next) + prevp = &t->t_next; + if (!t) return OK; + + *prevp = t->t_next; + tfree(t->t_ent); + tfree(t); + + return OK; } /* Free the space used by the symbol tables. */ -void -INPtabEnd(INPtables *tab) +void INPtabEnd(INPtables * tab) { - struct INPtab *t, *lt; - struct INPnTab *n, *ln; - int i; + struct INPtab *t, *lt; + struct INPnTab *n, *ln; + int i; - for (i = 0; i < tab->INPsize; i++) - for (t = tab->INPsymtab[i]; t; t = lt) { - lt = t->t_next; - FREE(t); /* But not t_ent ! */ - } - FREE(tab->INPsymtab); - for (i = 0; i < tab->INPtermsize; i++) - for (n = tab->INPtermsymtab[i]; n; n = ln) { - ln = n->t_next; - FREE(n); /* But not t_ent ! */ - } - FREE(tab->INPtermsymtab); - FREE(tab); - return; + for (i = 0; i < tab->INPsize; i++) + for (t = tab->INPsymtab[i]; t; t = lt) { + lt = t->t_next; + FREE(t); /* But not t_ent ! */ + } + FREE(tab->INPsymtab); + for (i = 0; i < tab->INPtermsize; i++) + for (n = tab->INPtermsymtab[i]; n; n = ln) { + ln = n->t_next; + FREE(n); /* But not t_ent ! */ + } + FREE(tab->INPtermsymtab); + FREE(tab); + return; } -static int -hash(char *name, int tsize) +static int hash(char *name, int tsize) { - char *s; - register int i = 0; + char *s; + register int i = 0; - for (s = name; *s; s++) - i += *s; - return (i % tsize); + for (s = name; *s; s++) + i += *s; + return (i % tsize); } - diff --git a/src/circuit/inptyplk.c b/src/circuit/inptyplk.c index 18d1dfb3b..13efc98c3 100644 --- a/src/circuit/inptyplk.c +++ b/src/circuit/inptyplk.c @@ -14,17 +14,15 @@ Author: 1985 Thomas L. Quarles #include "ifsim.h" #include "inp.h" -int -INPtypelook(char *type) +int INPtypelook(char *type) { int i; - for(i = 0; i < ft_sim->numDevices; i++) { - if(strcmp(type, (*(ft_sim->devices)[i]).name) == 0) { - /*found the device - return it */ - return i; - } + for (i = 0; i < ft_sim->numDevices; i++) { + if (strcmp(type, (*(ft_sim->devices)[i]).name) == 0) { + /*found the device - return it */ + return i; + } } return -1; } - diff --git a/src/circuit/ptfuncs.c b/src/circuit/ptfuncs.c index 69783bdcb..53e0d3185 100644 --- a/src/circuit/ptfuncs.c +++ b/src/circuit/ptfuncs.c @@ -21,44 +21,38 @@ Author: 1987 Wayne A. Christopher, U. C. Berkeley CAD Group #ifndef HAVE_ATANH extern double asinh(), acosh(), atanh(); -#endif +#endif double PTfudge_factor; #define MODULUS(NUM,LIMIT) ((NUM) - ((int) ((NUM) / (LIMIT))) * (LIMIT)) -double -PTabs(double arg) +double PTabs(double arg) { return arg >= 0.0 ? arg : -arg; } -double -PTsgn(double arg) +double PTsgn(double arg) { return arg > 0.0 ? 1.0 : arg < 0.0 ? -1.0 : 0.0; } -double -PTplus(double arg1, double arg2) +double PTplus(double arg1, double arg2) { return (arg1 + arg2); } -double -PTminus(double arg1, double arg2) +double PTminus(double arg1, double arg2) { return (arg1 - arg2); } -double -PTtimes(double arg1, double arg2) +double PTtimes(double arg1, double arg2) { return (arg1 * arg2); } -double -PTdivide(double arg1, double arg2) +double PTdivide(double arg1, double arg2) { if (arg2 >= 0.0) arg2 += PTfudge_factor; @@ -66,13 +60,12 @@ PTdivide(double arg1, double arg2) arg2 -= PTfudge_factor; if (arg2 == 0.0) - return (HUGE); + return (HUGE); return (arg1 / arg2); } -double -PTpower(double arg1, double arg2) +double PTpower(double arg1, double arg2) { if (arg1 < 0.0) { if (fabs(arg2 - ((int) arg2)) / (arg2 + 0.001) < 0.000001) { @@ -84,48 +77,42 @@ PTpower(double arg1, double arg2) return (pow(arg1, arg2)); } -double -PTacos(double arg) +double PTacos(double arg) { return (acos(arg)); } -double -PTacosh(double arg) +double PTacosh(double arg) { #ifdef HAVE_ACOSH return (acosh(arg)); #else if (arg < 1.0) arg = 1.0; - return (log(arg + sqrt(arg*arg-1.0))); -#endif + return (log(arg + sqrt(arg * arg - 1.0))); +#endif } -double -PTasin(double arg) +double PTasin(double arg) { return (asin(arg)); } -double -PTasinh(double arg) +double PTasinh(double arg) { #ifdef HAVE_ASINH return (asinh(arg)); #else return log(arg + sqrt(arg * arg + 1.0)); -#endif +#endif } -double -PTatan(double arg) +double PTatan(double arg) { return (atan(arg)); } -double -PTatanh(double arg) +double PTatanh(double arg) { #ifdef HAVE_ATANH return (atanh(arg)); @@ -135,22 +122,20 @@ PTatanh(double arg) else if (arg > 1.0) arg = 1.0 - PTfudge_factor - 1e-10; return (log((1.0 + arg) / (1.0 - arg)) / 2.0); -#endif +#endif } -double -PTustep(double arg) +double PTustep(double arg) { if (arg < 0.0) return 0.0; else if (arg > 0.0) return 1.0; else - return 0.5; /* Ick! */ + return 0.5; /* Ick! */ } -double -PTuramp(double arg) +double PTuramp(double arg) { if (arg < 0.0) return 0.0; @@ -158,87 +143,75 @@ PTuramp(double arg) return arg; } -double -PTcos(double arg) +double PTcos(double arg) { return (cos(MODULUS(arg, 2 * M_PI))); } -double -PTcosh(double arg) +double PTcosh(double arg) { return (cosh(arg)); } -double -PTexp(double arg) +double PTexp(double arg) { return (exp(arg)); } -double -PTln(double arg) +double PTln(double arg) { if (arg < 0.0) #ifdef EXPERIMENTAL_CODE - return (HUGE); -#else + return (HUGE); +#else arg = -arg; #endif return (log(arg)); } -double -PTlog(double arg) +double PTlog(double arg) { if (arg <= 0.0) #ifdef EXPERIMENTAL_CODE - return (HUGE); -#else + return (HUGE); +#else arg = -arg; #endif return (log10(arg)); } -double -PTsin(double arg) +double PTsin(double arg) { return (sin(MODULUS(arg, 2 * M_PI))); } -double -PTsinh(double arg) +double PTsinh(double arg) { return (sinh(arg)); } -double -PTsqrt(double arg) +double PTsqrt(double arg) { if (arg < 0.0) #ifdef EXPERIMENTAL_CODE - return (HUGE); + return (HUGE); #else arg = -arg; #endif return (sqrt(arg)); } -double -PTtan(double arg) +double PTtan(double arg) { return (tan(MODULUS(arg, M_PI))); } -double -PTtanh(double arg) +double PTtanh(double arg) { return (tanh(arg)); } -double -PTuminus(double arg) +double PTuminus(double arg) { - return (- arg); + return (-arg); } - diff --git a/src/circuit/sperror.c b/src/circuit/sperror.c index 1d66d68b7..bd731dedb 100644 --- a/src/circuit/sperror.c +++ b/src/circuit/sperror.c @@ -15,119 +15,105 @@ Author: 1985 Thomas L. Quarles #include "ifsim.h" #include "inp.h" -#define MSG(a) \ - msg = a; \ - break; - -static char *unknownError = "Unknown error code"; -static char *Pause = "Pause requested"; -static char *intern = "Impossible error - can't occur"; -static char *exists = "Device already exists, existing one being used"; -static char *nodev = "No such device"; -static char *noterm = "No such terminal on this device"; -static char *nomod = "No such model"; -static char *badparm = "No such parameter on this device"; -static char *nomem = "Out of Memory"; -static char *nodecon = "Node already connected; connection replaced"; -static char *unsupp = "operation not supported"; -static char *parmval = "parameter value out of range or the wrong type"; -static char *badmatrix = "Matrix can't be decomposed as is"; -static char *singular = "Matrix is singular"; -static char *iterlim = "Iteration limit reached"; -static char *order = "Unsupported integration order"; -static char *method = "Unsupported integration method"; -static char *timestep = "Timestep too small"; -static char *xmission = "transmission lines not supported by pole-zero"; -static char *toobig = "magnitude overflow"; -static char *isshort = "input or output shorted"; -static char *inisout = "transfer function is 1"; -static char *nodisto = "Distortion analysis not present"; -static char *nonoise = "Noise analysis not present"; -static char *noacinput = "AC input not found"; -static char *noanal = "No such analysis type"; -static char *nochange = "Unsupported action; no change made"; -static char *notfound = "Not found"; -static char *nof2src = "No F2 source for IM disto analysis"; -#ifdef PARALLEL_ARCH -static char *multierr = "Multiple errors detected by parallel machine"; -#endif /* PARALLEL_ARCH */ - -char * -SPerror(int type) +const char *SPerror(int type) { - char *val; char *msg; - switch(type) { - default: - MSG(unknownError) - case E_PAUSE: - MSG(Pause) - case OK: - return(NULL); - case E_INTERN: - MSG(intern) - case E_EXISTS: - MSG(exists) - case E_NODEV: - MSG(nodev) - case E_NOMOD: - MSG(nomod) - case E_NOTERM: - MSG(noterm) - case E_BADPARM: - MSG(badparm) - case E_NOMEM: - MSG(nomem) - case E_NODECON: - MSG(nodecon) - case E_UNSUPP: - MSG(unsupp) - case E_PARMVAL: - MSG(parmval) - case E_BADMATRIX: - MSG(badmatrix) - case E_SINGULAR: - MSG(singular) - case E_ITERLIM: - MSG(iterlim) - case E_ORDER: - MSG(order) - case E_METHOD: - MSG(method) - case E_TIMESTEP: - MSG(timestep) - case E_XMISSIONLINE: - MSG(xmission) - case E_MAGEXCEEDED: - MSG(toobig) - case E_SHORT: - MSG(isshort) - case E_INISOUT: - MSG(inisout) - case E_NODISTO: - MSG(nodisto) - case E_NONOISE: - MSG(nonoise) - case E_NOANAL: - MSG(noanal) - case E_NOCHANGE: - MSG(nochange) - case E_NOTFOUND: - MSG(notfound) - case E_NOACINPUT: - MSG(noacinput) - case E_NOF2SRC: - MSG(nof2src) + switch (type) { + case E_PAUSE: + msg = "pause requested"; + break; + case E_INTERN: + msg = "impossible error - can't occur"; + break; + case E_EXISTS: + msg = "device already exists, existing one being used"; + break; + case E_NODEV: + msg = "no such device"; + break; + case E_NOMOD: + msg = "no such model"; + break; + case E_NOTERM: + msg = "no such terminal on this device"; + break; + case E_BADPARM: + msg = "no such parameter on this device"; + break; + case E_NOMEM: + msg = "out of memory"; + break; + case E_NODECON: + msg = "node already connected; connection replaced"; + break; + case E_UNSUPP: + msg = "operation not supported"; + break; + case E_PARMVAL: + msg = "parameter value out of range or the wrong type"; + break; + case E_BADMATRIX: + msg = "matrix can't be decomposed as is"; + break; + case E_SINGULAR: + msg = "matrix is singular"; + break; + case E_ITERLIM: + msg = "iteration limit reached"; + break; + case E_ORDER: + msg = "unsupported integration order"; + break; + case E_METHOD: + msg = "unsupported integration method"; + break; + case E_TIMESTEP: + msg = "timestep too small"; + break; + case E_XMISSIONLINE: + msg = "transmission lines not supported by pole-zero"; + break; + case E_MAGEXCEEDED: + msg = "magnitude overflow"; + break; + case E_SHORT: + msg = "input or output shorted"; + break; + case E_INISOUT: + msg = "transfer function is 1"; + break; + case E_NODISTO: + msg = "distortion analysis not present"; + break; + case E_NONOISE: + msg = "noise analysis not present"; + break; + case E_NOANAL: + msg = "no such analysis type"; + break; + case E_NOCHANGE: + msg = "unsupported action; no change made"; + break; + case E_NOTFOUND: + msg = "not found"; + break; + case E_NOACINPUT: + msg = "ac input not found"; + break; + case E_NOF2SRC: + msg = "no F2 source for IM disto analysis"; + break; #ifdef PARALLEL_ARCH - case E_MULTIERR: - MSG(multierr) + case E_MULTIERR: + msg = "Multiple errors detected by parallel machine"; + break; #endif /* PARALLEL_ARCH */ + case OK: + return (NULL); + default: + msg = "Unknown error code"; } - val = MALLOC(strlen(msg) + 1); - if (val) { - (void) strcpy(val, msg); - } - return(val); + return msg; }