Jspice3
cktfdev.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Thomas L. Quarles
5  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include <stdio.h>
10 #include <math.h>
11 #include "cktdefs.h"
12 #include "sperror.h"
13 #include "util.h"
14 #include "cktext.h"
15 
16 
17 int
18 CKTfndDev(Ckt,type,fast,name,modfast,modname)
19 
20 GENERIC *Ckt;
21 int *type;
22 GENERIC **fast;
23 IFuid name;
24 GENERIC *modfast;
25 IFuid modname;
26 {
27  CKTcircuit *ckt=(CKTcircuit *)Ckt;
28  GENinstance *here;
29  GENmodel *mods;
30 
31  if ((GENinstance **)fast != (GENinstance **)NULL &&
32  *(GENinstance **)fast != (GENinstance *)NULL) {
33  /* already have fast, so nothing much to do */
34  /* just get & set type */
35  if (type) *type = (*((GENinstance**)fast))->GENmodPtr->GENmodType;
36  return (OK);
37  }
38  if (modfast) {
39  /* have model, just need device */
40  mods = (GENmodel*)modfast;
41  for (here = mods->GENinstances; here != NULL;
42  here = here->GENnextInstance) {
43  if (here->GENname == name) {
44  if (fast != NULL) *(GENinstance **)fast = here;
45  if (type) *type = mods->GENmodType;
46  return (OK);
47  }
48  }
49  return(E_NODEV);
50  }
51  if (*type >= 0 && *type < DEVmaxnum) {
52  /* have device type, need to find model & device */
53  /* look through all models */
54  for (mods = (GENmodel *)ckt->CKThead[*type]; mods != NULL;
55  mods = mods->GENnextModel) {
56  /* and all instances */
57  if (modname == (char *)NULL || mods->GENmodName == modname) {
58  for (here = mods->GENinstances; here != NULL;
59  here = here->GENnextInstance) {
60  if (here->GENname == name) {
61  if (fast != 0) *(GENinstance **)fast = here;
62  return (OK);
63  }
64  }
65  if (mods->GENmodName == modname) {
66  return (E_NODEV);
67  }
68  }
69  }
70  return (E_NOMOD);
71  }
72  else if (*type == -1) {
73  /* look through all types (UGH - worst case - take forever) */
74  for (*type = 0; *type < DEVmaxnum; (*type)++) {
75  /* need to find model & device */
76  /* look through all models */
77  for (mods = (GENmodel *)ckt->CKThead[*type]; mods!=NULL;
78  mods = mods->GENnextModel) {
79  /* and all instances */
80  if (modname == (char *)NULL || mods->GENmodName == modname) {
81  for (here = mods->GENinstances; here != NULL;
82  here = here->GENnextInstance) {
83  if (here->GENname == name) {
84  if (fast != 0) *(GENinstance **)fast = here;
85  return (OK);
86  }
87  }
88  if (mods->GENmodName == modname) {
89  return (E_NODEV);
90  }
91  }
92  }
93  }
94  *type = -1;
95  return (E_NODEV);
96  }
97  else return (E_BADPARM);
98 }
#define E_NODEV
Definition: iferrmsg.h:22
struct sGENinstance * GENnextInstance
Definition: gendefs.h:26
#define E_BADPARM
Definition: iferrmsg.h:26
struct sGENmodel * GENnextModel
Definition: gendefs.h:41
#define OK
Definition: iferrmsg.h:17
GENERIC * IFuid
Definition: ifsim.h:72
#define NULL
Definition: spdefs.h:121
Definition: types.c:18
int CKTfndDev(GENERIC *Ckt, int *type, GENERIC **fast, IFuid name, GENERIC *modfast, IFuid modname)
Definition: cktfdev.c:18
#define E_NOMOD
Definition: iferrmsg.h:23
int GENmodType
Definition: gendefs.h:40
int type
Definition: cktdefs.h:56
return(True)
GENinstance * GENinstances
Definition: gendefs.h:43
GENmodel * CKThead[MAXNUMDEVS]
Definition: cktdefs.h:64
IFuid GENname
Definition: gendefs.h:28
int DEVmaxnum
Definition: sconfig.c:166
char GENERIC
Definition: ifsim.h:27
IFuid GENmodName
Definition: gendefs.h:45