From 5daa676163b73049d60b31175159684c3d33a4bf Mon Sep 17 00:00:00 2001 From: rlar Date: Thu, 4 Jul 2013 19:08:35 +0200 Subject: [PATCH] CKTfndDev(), return the found instance instead of error code now if (fast != NULL) CKTfndDev(,,fast, ) is equivalent to *fast = CKTfndDev(,,fast, ) --- src/frontend/spiceif.c | 4 ++-- src/include/ngspice/cktdefs.h | 2 +- src/include/ngspice/ifsim.h | 2 +- src/spicelib/analysis/noisean.c | 4 ++-- src/spicelib/analysis/tfanal.c | 4 ++-- src/spicelib/devices/cktcrte.c | 2 +- src/spicelib/devices/cktfinddev.c | 8 ++++---- src/spicelib/devices/ind/mutsetup.c | 4 ++-- src/spicelib/parser/inpaname.c | 2 +- src/tclspice.c | 2 +- src/unsupported/snstart.c | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index 35ae3561c..2165cf623 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -615,7 +615,7 @@ finddev_special( int type = -1; // assert(third && *third == NULL); for all invocations - err = ft_sim->findInstance (ckt, &type, devptr, name); + *devptr = ft_sim->findInstance (ckt, &type, devptr, name); err = *devptr ? OK : E_NODEV; if (err == OK) { *device_or_model = 0; @@ -1218,7 +1218,7 @@ finddev(CKTcircuit *ckt, char *name, GENinstance **devptr, GENmodel **modptr) int type = -1; // assert(third && *third == NULL); for all invocations - err = ft_sim->findInstance (ckt, &type, devptr, name); + *devptr = ft_sim->findInstance (ckt, &type, devptr, name); err = *devptr ? OK : E_NODEV; if (err == OK) return (type); diff --git a/src/include/ngspice/cktdefs.h b/src/include/ngspice/cktdefs.h index 927fa9e3b..dbf70f556 100644 --- a/src/include/ngspice/cktdefs.h +++ b/src/include/ngspice/cktdefs.h @@ -319,7 +319,7 @@ extern void NDEVacct(CKTcircuit *ckt, FILE *file); extern void CKTncDump(CKTcircuit *); extern int CKTfndAnal(CKTcircuit *, int *, JOB **, IFuid , TSKtask *, IFuid); extern int CKTfndBranch(CKTcircuit *, IFuid); -extern int CKTfndDev(CKTcircuit *, int *, GENinstance **, IFuid); +extern GENinstance *CKTfndDev(CKTcircuit *, int *, GENinstance **, IFuid); extern int CKTfndMod(CKTcircuit *, int *, GENmodel **, IFuid); extern int CKTfndNode(CKTcircuit *, CKTnode **, IFuid); extern int CKTfndTask(CKTcircuit *, TSKtask **, IFuid ); diff --git a/src/include/ngspice/ifsim.h b/src/include/ngspice/ifsim.h index 10e831d55..2f58a7ca4 100644 --- a/src/include/ngspice/ifsim.h +++ b/src/include/ngspice/ifsim.h @@ -370,7 +370,7 @@ struct IFsimulator { /* set a parameter on an instance */ int (*askInstanceQuest) (CKTcircuit *, GENinstance *, int, IFvalue *, IFvalue *); /* ask a question about an instance */ - int (*findInstance) (CKTcircuit *, int *, GENinstance **, IFuid); + GENinstance *(*findInstance) (CKTcircuit *, int *, GENinstance **, IFuid); /* find a specific instance */ int (*deleteInstance) (CKTcircuit *, void *); /* delete an instance from the circuit */ diff --git a/src/spicelib/analysis/noisean.c b/src/spicelib/analysis/noisean.c index 515bc6426..f6af9d779 100644 --- a/src/spicelib/analysis/noisean.c +++ b/src/spicelib/analysis/noisean.c @@ -49,7 +49,7 @@ NOISEan (CKTcircuit *ckt, int restart) code = CKTtypelook("Vsource"); if (code != -1) { // assert(third && *third == NULL); - error = CKTfndDev(ckt, NULL, &inst, job->input); + inst = CKTfndDev(ckt, NULL, &inst, job->input); error = inst ? OK : E_NODEV; if (!error && !((VSRCinstance *)inst)->VSRCacGiven) { errMsg = TMALLOC(char, strlen(noacinput) + 1); @@ -61,7 +61,7 @@ NOISEan (CKTcircuit *ckt, int restart) code = CKTtypelook("Isource"); if (code != -1 && inst==NULL) { // assert(third && *third == NULL); - error = CKTfndDev(ckt, NULL, &inst, job->input); + inst = CKTfndDev(ckt, NULL, &inst, job->input); error = inst ? OK : E_NODEV; if (error) { /* XXX ??? */ diff --git a/src/spicelib/analysis/tfanal.c b/src/spicelib/analysis/tfanal.c index 4a811d8d0..810bd1f05 100644 --- a/src/spicelib/analysis/tfanal.c +++ b/src/spicelib/analysis/tfanal.c @@ -52,7 +52,7 @@ TFanal(CKTcircuit *ckt, int restart) Vtype = CKTtypelook("Vsource"); if(Itype != -1) { // assert(third && *third == NULL); - error = CKTfndDev(ckt, NULL, &ptr, job->TFinSrc); + ptr = CKTfndDev(ckt, NULL, &ptr, job->TFinSrc); error = ptr ? OK : E_NODEV; if(error ==0) { job->TFinIsI = 1; @@ -64,7 +64,7 @@ TFanal(CKTcircuit *ckt, int restart) if( (Vtype != -1) && (ptr==NULL) ) { // assert(third && *third == NULL); - error = CKTfndDev(ckt, NULL, &ptr, job->TFinSrc); + ptr = CKTfndDev(ckt, NULL, &ptr, job->TFinSrc); error = ptr ? OK : E_NODEV; job->TFinIsV = 1; job->TFinIsI = 0; diff --git a/src/spicelib/devices/cktcrte.c b/src/spicelib/devices/cktcrte.c index 9918a1eda..8ececf179 100644 --- a/src/spicelib/devices/cktcrte.c +++ b/src/spicelib/devices/cktcrte.c @@ -30,7 +30,7 @@ CKTcrtElt(CKTcircuit *ckt, GENmodel *modPtr, GENinstance **inInstPtr, IFuid name return E_NOMOD; // assert(third && *third == NULL); - error = CKTfndDev(ckt, NULL, &instPtr, name); + instPtr = CKTfndDev(ckt, NULL, &instPtr, name); error = instPtr ? OK : E_NODEV; if (error == OK) { diff --git a/src/spicelib/devices/cktfinddev.c b/src/spicelib/devices/cktfinddev.c index 2b4ceed48..2e44130a9 100644 --- a/src/spicelib/devices/cktfinddev.c +++ b/src/spicelib/devices/cktfinddev.c @@ -10,7 +10,7 @@ Author: 1985 Thomas L. Quarles #include "string.h" -int +GENinstance * CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name) { GENinstance *here; @@ -19,7 +19,7 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name) if (fast && *fast) { if (type) *type = (*fast)->GENmodPtr->GENmodType; - return OK; + return *fast; } here = nghash_find(ckt->DEVnameHash, name); @@ -32,8 +32,8 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name) if (type) *type = here->GENmodPtr->GENmodType; - return OK; + return here; } - return E_NODEV; + return NULL; } diff --git a/src/spicelib/devices/ind/mutsetup.c b/src/spicelib/devices/ind/mutsetup.c index 0c10e20b7..3d26d2147 100644 --- a/src/spicelib/devices/ind/mutsetup.c +++ b/src/spicelib/devices/ind/mutsetup.c @@ -44,7 +44,7 @@ MUTsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } // assert(third); - error = CKTfndDev(ckt, NULL, (GENinstance **) &(here->MUTind1), here->MUTindName1); + here->MUTind1 = (INDinstance *) CKTfndDev(ckt, NULL, (GENinstance **) &(here->MUTind1), here->MUTindName1); error = here->MUTind1 ? OK : E_NODEV; if(error) { IFuid namarray[2]; @@ -55,7 +55,7 @@ MUTsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) namarray); } // assert(third); - error = CKTfndDev(ckt, NULL, (GENinstance **) &(here->MUTind2), here->MUTindName2); + here->MUTind2 = (INDinstance *) CKTfndDev(ckt, NULL, (GENinstance **) &(here->MUTind2), here->MUTindName2); error = here->MUTind2 ? OK : E_NODEV; if(error) { IFuid namarray[2]; diff --git a/src/spicelib/parser/inpaname.c b/src/spicelib/parser/inpaname.c index 29cfedc9f..7e85cfa21 100644 --- a/src/spicelib/parser/inpaname.c +++ b/src/spicelib/parser/inpaname.c @@ -41,7 +41,7 @@ INPaName(char *parm, IFvalue * val, CKTcircuit *ckt, int *dev, char *devnam, * WILL be set on return unless error is not OK */ // assert(third) for all invocations - error = sim->findInstance (ckt, dev, fast, devnam); + *fast = sim->findInstance (ckt, dev, fast, devnam); error = *fast ? OK : E_NODEV; if (error) return (error); diff --git a/src/tclspice.c b/src/tclspice.c index 3157903ad..f6a514780 100644 --- a/src/tclspice.c +++ b/src/tclspice.c @@ -1395,7 +1395,7 @@ get_mod_param TCL_CMDPROCARGS(clientData, interp, argc, argv) /* get the unique IFuid for name (device/model) */ INPretrieve(&name, ft_curckt->ci_symtab); // assert(third && *third == NULL); - err = ft_sim->findInstance (ft_curckt->ci_ckt, &typecode, &devptr, name); + devptr = ft_sim->findInstance (ft_curckt->ci_ckt, &typecode, &devptr, name); err = devptr ? OK : E_NODEV; if (err != OK) { typecode = -1; diff --git a/src/unsupported/snstart.c b/src/unsupported/snstart.c index 0909f1d40..753fa83cb 100644 --- a/src/unsupported/snstart.c +++ b/src/unsupported/snstart.c @@ -43,7 +43,7 @@ SENstartup(CKTcircuit *ckt, int restart) fast = NULL; // assert(third && *third == NULL); - err = CKTfndDev(ckt, &type, &fast, ckt->CKTsenInfo->SENdevices[i]); + fast = CKTfndDev(ckt, &type, &fast, ckt->CKTsenInfo->SENdevices[i]); err = fast ? OK : E_NODEV; if (err != OK) return err;