Jspice3
cktcrte.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  /* CKTcrtElement(ckt,type,inModPtr,inInstPtr,name,subname)
9  * Create a device of the specified type, with the given name, using
10  * the specified model in the named circuit.
11  */
12 
13 #include "spice.h"
14 #include <stdio.h>
15 #include "devdefs.h"
16 #include "sperror.h"
17 #include "util.h"
18 #include "cktext.h"
19 
20 
21 /*ARGSUSED*/
22 int
23 CKTcrtElt(ckt,inModPtr,inInstPtr,name)
24 
25 GENERIC *ckt;
26 GENERIC *inModPtr;
27 GENERIC **inInstPtr;
28 IFuid name;
29 {
30  GENinstance *instPtr = NULL;
31  GENmodel *modPtr=(GENmodel*)inModPtr;
32  extern SPICEdev *DEVices[];
33  int error;
34  int type;
35 
36  if ((GENmodel *)modPtr == (GENmodel*)NULL) return(E_NOMOD);
37  type = ((GENmodel*)modPtr)->GENmodType;
38  error =
39  CKTfndDev(ckt,&type,(GENERIC**)&instPtr,name,inModPtr,(char *)NULL);
40  if (error == OK) {
41  if (inInstPtr) *inInstPtr = (GENERIC *)instPtr;
42  return (E_EXISTS);
43  }
44  else if (error != E_NODEV) return (error);
45  instPtr = (GENinstance *)MALLOC(*DEVices[type]->DEVinstSize);
46  if (instPtr == (GENinstance *)NULL) return (E_NOMEM);
47  instPtr->GENname = name;
48  instPtr->GENmodPtr = modPtr;
49  instPtr->GENnextInstance = modPtr->GENinstances;
50  modPtr->GENinstances = instPtr;
51  if (inInstPtr != NULL) *inInstPtr = (GENERIC *)instPtr;
52  return (OK);
53 }
#define E_NODEV
Definition: iferrmsg.h:22
SPICEdev * DEVices[]
Definition: sconfig.c:109
struct sGENinstance * GENnextInstance
Definition: gendefs.h:26
#define E_EXISTS
Definition: iferrmsg.h:20
int CKTcrtElt(GENERIC *ckt, GENERIC *inModPtr, GENERIC **inInstPtr, IFuid name)
Definition: cktcrte.c:23
#define OK
Definition: iferrmsg.h:17
GENERIC * IFuid
Definition: ifsim.h:72
#define MALLOC(x)
Definition: util.h:9
#define NULL
Definition: spdefs.h:121
#define E_NOMEM
Definition: iferrmsg.h:27
#define E_NOMOD
Definition: iferrmsg.h:23
int type
Definition: cktdefs.h:56
int CKTfndDev()
struct sGENmodel * GENmodPtr
Definition: gendefs.h:25
GENinstance * GENinstances
Definition: gendefs.h:43
IFuid GENname
Definition: gendefs.h:28
char GENERIC
Definition: ifsim.h:27