Jspice3
cktmcrt.c File Reference
#include "spice.h"
#include <stdio.h>
#include "devdefs.h"
#include "sperror.h"
#include "util.h"
#include "cktext.h"
Include dependency graph for cktmcrt.c:

Go to the source code of this file.

Functions

int CKTmodCrt (GENERIC *ckt, int type, GENERIC **modfast, IFuid name)
 

Function Documentation

int CKTmodCrt ( GENERIC ckt,
int  type,
GENERIC **  modfast,
IFuid  name 
)

Definition at line 22 of file cktmcrt.c.

28 {
29  extern SPICEdev *DEVices[];
30  GENmodel *mymodfast = NULL;
31  struct sCKTmodHead *mh;
32  int error;
33 
34  error = CKTfndMod(ckt,&type,(GENERIC**)&mymodfast,name);
35  if (error == E_NOMOD) {
36  mymodfast = (GENmodel *)MALLOC(*DEVices[type]->DEVmodSize);
37  if(mymodfast == (GENmodel *)NULL) return(E_NOMEM);
38  mymodfast->GENmodType = type;
39  mymodfast->GENmodName = name;
40  mymodfast->GENnextModel =
41  (GENmodel *)((CKTcircuit *)ckt)->CKThead[type];
42  ((CKTcircuit *)ckt)->CKThead[type] = (GENmodel *)mymodfast;
43  if (modfast) *modfast=(GENERIC *)mymodfast;
44 
45  for (mh = ((CKTcircuit *)ckt)->CKTheadList; mh != NULL;
46  mh = mh->next) {
47  if (mh->type == type) break;
48  }
49  if (mh == NULL) {
50  mh = (struct sCKTmodHead *) MALLOC(sizeof(struct sCKTmodHead));
51  if (mh == NULL)
52  return (E_NOMEM);
53  mh->type = type;
54  mh->next = ((CKTcircuit *)ckt)->CKTheadList;
55  ((CKTcircuit *)ckt)->CKTheadList = mh;
56  }
57  mh->head = (GENmodel *)mymodfast;
58 
59  return (OK);
60  }
61  else if (error == 0) {
62  if (modfast) *modfast = (GENERIC *)mymodfast;
63  return (E_EXISTS);
64  }
65  else {
66  return (error);
67  }
68  /*NOTREACHED*/
69 }
struct sCKTmodHead * next
Definition: cktdefs.h:58
SPICEdev * DEVices[]
Definition: sconfig.c:109
struct sGENmodel * GENnextModel
Definition: gendefs.h:41
#define E_EXISTS
Definition: iferrmsg.h:20
#define OK
Definition: iferrmsg.h:17
#define MALLOC(x)
Definition: util.h:9
#define NULL
Definition: spdefs.h:121
Definition: types.c:18
#define E_NOMEM
Definition: iferrmsg.h:27
#define E_NOMOD
Definition: iferrmsg.h:23
int CKTfndMod()
int GENmodType
Definition: gendefs.h:40
int type
Definition: cktdefs.h:56
GENmodel * head
Definition: cktdefs.h:57
char GENERIC
Definition: ifsim.h:27
IFuid GENmodName
Definition: gendefs.h:45