Undid versioning for code models and mutex protection for their memory allocations.
This commit is contained in:
parent
9ff5363ea8
commit
887b48b9d5
|
|
@ -77,25 +77,6 @@ struct coreInfo_t {
|
||||||
void * ((*dllitf_tmalloc)(size_t));
|
void * ((*dllitf_tmalloc)(size_t));
|
||||||
void * ((*dllitf_trealloc)(void *, size_t));
|
void * ((*dllitf_trealloc)(void *, size_t));
|
||||||
void ((*dllitf_txfree)(void *));
|
void ((*dllitf_txfree)(void *));
|
||||||
|
|
||||||
/*** VERSION 2 ADDITIONS ***/
|
|
||||||
const char *(*dllitf_ngspice_version)(void);
|
|
||||||
/* version string of ngspice using the cm */
|
|
||||||
void *(*dllitf_tmalloc_raw)(size_t size);
|
|
||||||
/* mutex-protected malloc() that will not
|
|
||||||
* cause program termination on failure */
|
|
||||||
void *(*dllitf_tcalloc_raw)(size_t num, size_t size);
|
|
||||||
/* mutex-protected calloc() that will not
|
|
||||||
* cause program termination on failure */
|
|
||||||
void *(*dllitf_trealloc_raw)(void *p, size_t size);
|
|
||||||
/* mutex-protected realloc() that will not
|
|
||||||
* cause program termination on failure */
|
|
||||||
char *(*dllitf_tstrdup)(const char *sz);
|
|
||||||
/* mutex-protected strdup() that WILL
|
|
||||||
* cause program termination on failure */
|
|
||||||
char *(*dllitf_tstrdup_raw)(const char *sz);
|
|
||||||
/* mutex-protected strdup() that will not
|
|
||||||
* cause program termination on failure */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct coreInfo_t coreInfo;
|
extern const struct coreInfo_t coreInfo;
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ inline char *ds_free_move(DSTRING *p_ds, unsigned int opt)
|
||||||
if (opt & DS_FREE_MOVE_OPT_FORCE_ALLOC) {
|
if (opt & DS_FREE_MOVE_OPT_FORCE_ALLOC) {
|
||||||
/* Allocate to minimum size */
|
/* Allocate to minimum size */
|
||||||
size_t n_byte_alloc = p_ds->length + 1;
|
size_t n_byte_alloc = p_ds->length + 1;
|
||||||
char * const p_ret = (char *) tmalloc_raw(n_byte_alloc);
|
char * const p_ret = (char *) malloc(n_byte_alloc);
|
||||||
if (p_ret == (char *) NULL) {
|
if (p_ret == (char *) NULL) {
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +206,7 @@ inline char *ds_free_move(DSTRING *p_ds, unsigned int opt)
|
||||||
if (opt & DS_FREE_MOVE_OPT_COMPACT) {
|
if (opt & DS_FREE_MOVE_OPT_COMPACT) {
|
||||||
/* Allocate to minimum size */
|
/* Allocate to minimum size */
|
||||||
size_t n_byte_alloc = p_ds->length + 1;
|
size_t n_byte_alloc = p_ds->length + 1;
|
||||||
char * const p_ret = (char *) trealloc_raw(p_buf_active, n_byte_alloc);
|
char * const p_ret = (char *) realloc(p_buf_active, n_byte_alloc);
|
||||||
if (p_ret == (char *) NULL) {
|
if (p_ret == (char *) NULL) {
|
||||||
/* Realloc to smaller size somehow failed! */
|
/* Realloc to smaller size somehow failed! */
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
|
|
|
||||||
|
|
@ -212,8 +212,7 @@ static int ds_reserve_internal(DSTRING *p_ds,
|
||||||
n_byte_alloc_min = n_byte_alloc_opt;
|
n_byte_alloc_min = n_byte_alloc_opt;
|
||||||
}
|
}
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
if ((p_buf_new = (char *) tmalloc_raw(
|
if ((p_buf_new = (char *) malloc(n_byte_alloc)) != (char *) NULL) {
|
||||||
n_byte_alloc)) != (char *) NULL) {
|
|
||||||
break; /* Allocated OK */
|
break; /* Allocated OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,7 +347,7 @@ int ds_compact(DSTRING *p_ds)
|
||||||
|
|
||||||
/* Else realloc the heap buffer */
|
/* Else realloc the heap buffer */
|
||||||
{
|
{
|
||||||
void * const p = trealloc_raw(p_ds->p_buf, n_byte_alloc_min);
|
void * const p = realloc(p_ds->p_buf, n_byte_alloc_min);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return DS_E_NO_MEMORY;
|
return DS_E_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,10 @@ funptr_t dlsym(void *, const char *);
|
||||||
char *dlerror(void);
|
char *dlerror(void);
|
||||||
#define FREE_DLERR_MSG(msg) free_dlerr_msg(msg)
|
#define FREE_DLERR_MSG(msg) free_dlerr_msg(msg)
|
||||||
static void free_dlerr_msg(char *msg);
|
static void free_dlerr_msg(char *msg);
|
||||||
#define RTLD_LAZY 1 /* lazy function call binding */
|
#define RTLD_LAZY 1 /* lazy function call binding */
|
||||||
#define RTLD_NOW 2 /* immediate function call binding */
|
#define RTLD_NOW 2 /* immediate function call binding */
|
||||||
#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible to other dlopen'ed objs */
|
#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible to other
|
||||||
|
* dlopen'ed objs */
|
||||||
#endif /* ifndef HAS_WINGUI */
|
#endif /* ifndef HAS_WINGUI */
|
||||||
|
|
||||||
#include "ngspice/dllitf.h" /* the coreInfo Structure*/
|
#include "ngspice/dllitf.h" /* the coreInfo Structure*/
|
||||||
|
|
@ -422,43 +423,26 @@ int load_opus(const char *name)
|
||||||
|
|
||||||
|
|
||||||
/* Get code models defined by the library */
|
/* Get code models defined by the library */
|
||||||
if ((fetch = dlsym(lib, "CMdevNum2")) != (funptr_t) NULL) {
|
if ((fetch = dlsym(lib, "CMdevNum")) != (funptr_t) NULL) {
|
||||||
/* Version 2 code models present */
|
|
||||||
num = *(*(int * (*)(void)) fetch)();
|
num = *(*(int * (*)(void)) fetch)();
|
||||||
fetch = dlsym(lib, "CMdevs2");
|
fetch = dlsym(lib, "CMdevs");
|
||||||
if (fetch != (funptr_t) NULL) {
|
if (fetch != (funptr_t) NULL) {
|
||||||
devs = (*(SPICEdev ** (*)(void)) fetch)();
|
devs = (*(SPICEdev ** (*)(void)) fetch)();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = dlerror();
|
msg = dlerror();
|
||||||
printf("Error getting the list of version 2 devices: %s\n",
|
printf("Error getting the list of devices: %s\n",
|
||||||
msg);
|
msg);
|
||||||
FREE_DLERR_MSG(msg);
|
FREE_DLERR_MSG(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* no version 2, so try version 1 */
|
else {
|
||||||
if ((fetch = dlsym(lib, "CMdevNum")) != (funptr_t) NULL) {
|
msg = dlerror();
|
||||||
num = *(*(int * (*)(void)) fetch)();
|
printf("Error finding the number of devices: %s\n", msg);
|
||||||
fetch = dlsym(lib, "CMdevs");
|
FREE_DLERR_MSG(msg);
|
||||||
if (fetch != (funptr_t) NULL) {
|
return 1;
|
||||||
devs = (*(SPICEdev ** (*)(void)) fetch)();
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg = dlerror();
|
|
||||||
printf("Error getting the list of version 1 devices: %s\n",
|
|
||||||
msg);
|
|
||||||
FREE_DLERR_MSG(msg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} /* end of case that got version 1 */
|
|
||||||
else { /* no version 2 or version 1 */
|
|
||||||
msg = dlerror();
|
|
||||||
printf("Error finding the number of devices: %s\n", msg);
|
|
||||||
FREE_DLERR_MSG(msg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} /* end of case of no version 2 */
|
|
||||||
|
|
||||||
add_device(num, devs, 1);
|
add_device(num, devs, 1);
|
||||||
|
|
||||||
|
|
@ -468,46 +452,26 @@ int load_opus(const char *name)
|
||||||
|
|
||||||
|
|
||||||
/* Get user-defined ndes defined by the library */
|
/* Get user-defined ndes defined by the library */
|
||||||
if ((fetch = dlsym(lib, "CMudnNum2")) != (funptr_t) NULL) {
|
if ((fetch = dlsym(lib, "CMudnNum")) != (funptr_t) NULL) {
|
||||||
/* Version 2 user-defined types present */
|
|
||||||
num = *(*(int * (*)(void)) fetch)();
|
num = *(*(int * (*)(void)) fetch)();
|
||||||
fetch = dlsym(lib, "CMudns2");
|
fetch = dlsym(lib, "CMudns");
|
||||||
if (fetch != (funptr_t) NULL) {
|
if (fetch != (funptr_t) NULL) {
|
||||||
udns = (*(Evt_Udn_Info_t ** (*)(void)) fetch)();
|
udns = (*(Evt_Udn_Info_t ** (*)(void)) fetch)();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = dlerror();
|
msg = dlerror();
|
||||||
printf("Error getting the list of version 2 "
|
printf("Error getting the list of user-defined types: %s\n",
|
||||||
"user-defined types: %s\n",
|
|
||||||
msg);
|
msg);
|
||||||
FREE_DLERR_MSG(msg);
|
FREE_DLERR_MSG(msg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* no version 2, so try version 1 */
|
else {
|
||||||
if ((fetch = dlsym(lib, "CMudnNum")) != (funptr_t) NULL) {
|
msg = dlerror();
|
||||||
num = *(*(int * (*)(void)) fetch)();
|
printf("Error finding the number of user-defined types: %s\n", msg);
|
||||||
fetch = dlsym(lib, "CMudns");
|
FREE_DLERR_MSG(msg);
|
||||||
if (fetch != (funptr_t) NULL) {
|
return 1;
|
||||||
udns = (*(Evt_Udn_Info_t ** (*)(void)) fetch)();
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg = dlerror();
|
|
||||||
printf("Error getting the list of version 1 "
|
|
||||||
"user-defined types: %s\n",
|
|
||||||
msg);
|
|
||||||
FREE_DLERR_MSG(msg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} /* end of case that got version 1 */
|
|
||||||
else { /* no version 2 or version 1 */
|
|
||||||
msg = dlerror();
|
|
||||||
printf("Error finding the number of "
|
|
||||||
"user-defined types: %s\n", msg);
|
|
||||||
FREE_DLERR_MSG(msg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} /* end of case of no version 2 */
|
|
||||||
|
|
||||||
add_udn(num, udns);
|
add_udn(num, udns);
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,4 @@ const struct coreInfo_t coreInfo =
|
||||||
&tmalloc,
|
&tmalloc,
|
||||||
&trealloc,
|
&trealloc,
|
||||||
&txfree,
|
&txfree,
|
||||||
/* Version 2 additions */
|
|
||||||
&get_ngspice_version,
|
|
||||||
&tmalloc_raw,
|
|
||||||
&tcalloc_raw,
|
|
||||||
&trealloc_raw,
|
|
||||||
&tstrdup,
|
|
||||||
&tstrdup_raw
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,12 @@
|
||||||
|
|
||||||
|
|
||||||
static int fb_fill(FILEBUF *p_fb);
|
static int fb_fill(FILEBUF *p_fb);
|
||||||
static int fbget_quoted_unescaped_string(FILEBUF *p_fb,
|
static int fbget_quoted_unescaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
|
||||||
static size_t fb_make_space_at_end(FILEBUF *p_fb);
|
static size_t fb_make_space_at_end(FILEBUF *p_fb);
|
||||||
static int fbget_quoted_string(FILEBUF *p_fb,
|
static int fbget_quoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
static int fbget_quoted_escaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
|
||||||
static int fbget_quoted_escaped_string(FILEBUF *p_fb,
|
static int fbget_unquoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
|
||||||
static int fbget_unquoted_string(FILEBUF *p_fb,
|
|
||||||
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
|
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
|
||||||
static int fb_return_obj(FILEBUF *p_fb,
|
|
||||||
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
|
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
|
||||||
static int fb_return_string(FILEBUF *p_fb,
|
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
|
||||||
static int fb_skip_to_eol(FILEBUF *p_fb);
|
static int fb_skip_to_eol(FILEBUF *p_fb);
|
||||||
static int fb_skip_whitespace(FILEBUF *p_fb);
|
static int fb_skip_whitespace(FILEBUF *p_fb);
|
||||||
|
|
||||||
|
|
@ -147,12 +138,7 @@ int fbclose(FILEBUF *p_fb)
|
||||||
*
|
*
|
||||||
* Parameters
|
* Parameters
|
||||||
* p_fb: FILEBUF pointer initialized using fbopen()
|
* p_fb: FILEBUF pointer initialized using fbopen()
|
||||||
* n_type_wanted: number of desired type conversions for data from highest
|
* p_fbstr: Address of an FBSTRING structure to receive the data
|
||||||
* priority to lowest.
|
|
||||||
* p_type_wanted: Desired type conversions for data from highest priority
|
|
||||||
* to lowest.
|
|
||||||
* p_type_found: Address to receive the type of the data obtained
|
|
||||||
* p_fbobj: Address of an FBOBJ structure to receive the data
|
|
||||||
*
|
*
|
||||||
* Return codes
|
* Return codes
|
||||||
* +1: EOF reached
|
* +1: EOF reached
|
||||||
|
|
@ -180,9 +166,7 @@ int fbclose(FILEBUF *p_fb)
|
||||||
* 0: Normal
|
* 0: Normal
|
||||||
* -1: Error
|
* -1: Error
|
||||||
*/
|
*/
|
||||||
int fbget(FILEBUF *p_fb,
|
int fbget(FILEBUF *p_fb, FBSTRING *p_fbstr)
|
||||||
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
|
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
{
|
||||||
/* Test for existing EOF */
|
/* Test for existing EOF */
|
||||||
if (p_fb->is_eof && p_fb->p_data_cur == p_fb->p_data_end) { /* no data */
|
if (p_fb->is_eof && p_fb->p_data_cur == p_fb->p_data_end) { /* no data */
|
||||||
|
|
@ -210,12 +194,11 @@ int fbget(FILEBUF *p_fb,
|
||||||
|
|
||||||
/* Current char exists and starts the item */
|
/* Current char exists and starts the item */
|
||||||
if (*p_fb->p_data_cur == '"') { /* quoted string */
|
if (*p_fb->p_data_cur == '"') { /* quoted string */
|
||||||
return fbget_quoted_string(p_fb, p_type_found, p_fbobj);
|
return fbget_quoted_string(p_fb, p_fbstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else unquoted string */
|
/* Else unquoted string */
|
||||||
return fbget_unquoted_string(p_fb, n_type_wanted, p_type_wanted,
|
return fbget_unquoted_string(p_fb, p_fbstr);
|
||||||
p_type_found, p_fbobj);
|
|
||||||
} /* end of function fbget */
|
} /* end of function fbget */
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -224,8 +207,7 @@ int fbget(FILEBUF *p_fb,
|
||||||
* to the quote starting the quoted string. On return it points to the first
|
* to the quote starting the quoted string. On return it points to the first
|
||||||
* character after the current item or equals p_fb->p_data_end if the
|
* character after the current item or equals p_fb->p_data_end if the
|
||||||
* current item extens to the end of the current data string. */
|
* current item extens to the end of the current data string. */
|
||||||
static int fbget_quoted_string(FILEBUF *p_fb,
|
static int fbget_quoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
{
|
||||||
/* Advance past the opening quote to the true start of the string */
|
/* Advance past the opening quote to the true start of the string */
|
||||||
if (++p_fb->p_data_cur == p_fb->p_data_end) {
|
if (++p_fb->p_data_cur == p_fb->p_data_end) {
|
||||||
|
|
@ -243,7 +225,7 @@ static int fbget_quoted_string(FILEBUF *p_fb,
|
||||||
* and the buffer has at leat 1 byte a NULL to create the
|
* and the buffer has at leat 1 byte a NULL to create the
|
||||||
* string "" can be written here */
|
* string "" can be written here */
|
||||||
*(p_fb->p_obj_end = p_fb->p_obj_start = p_fb->p_buf) = '\0';
|
*(p_fb->p_obj_end = p_fb->p_obj_start = p_fb->p_buf) = '\0';
|
||||||
return fb_return_string(p_fb, p_type_found, p_fbobj);
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
}
|
}
|
||||||
/* Else data is now available at p_fb->p_data_cur */
|
/* Else data is now available at p_fb->p_data_cur */
|
||||||
} /* end of case that at end of data from file */
|
} /* end of case that at end of data from file */
|
||||||
|
|
@ -253,15 +235,14 @@ static int fbget_quoted_string(FILEBUF *p_fb,
|
||||||
|
|
||||||
/* Continue processing as an unescaped string, unless the contrary
|
/* Continue processing as an unescaped string, unless the contrary
|
||||||
* is found to be true */
|
* is found to be true */
|
||||||
return fbget_quoted_unescaped_string(p_fb, p_type_found, p_fbobj);
|
return fbget_quoted_unescaped_string(p_fb, p_fbstr);
|
||||||
} /* end of function fbget_quoted_string */
|
} /* end of function fbget_quoted_string */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Get a quoted string with no escape. The start has already been set on
|
/* Get a quoted string with no escape. The start has already been set on
|
||||||
* entry. If an escape is found, processing continues as an escaped string */
|
* entry. If an escape is found, processing continues as an escaped string */
|
||||||
int fbget_quoted_unescaped_string(FILEBUF *p_fb,
|
int fbget_quoted_unescaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
{
|
||||||
/* Step through characters until end or escape */
|
/* Step through characters until end or escape */
|
||||||
char *p_data_cur = p_fb->p_data_cur;
|
char *p_data_cur = p_fb->p_data_cur;
|
||||||
|
|
@ -272,14 +253,13 @@ int fbget_quoted_unescaped_string(FILEBUF *p_fb,
|
||||||
if (ch_cur == '"') { /* Closing quote, so done */
|
if (ch_cur == '"') { /* Closing quote, so done */
|
||||||
*(p_fb->p_obj_end = p_data_cur) = '\0';
|
*(p_fb->p_obj_end = p_data_cur) = '\0';
|
||||||
p_fb->p_data_cur = p_data_cur + 1;
|
p_fb->p_data_cur = p_data_cur + 1;
|
||||||
return fb_return_string(p_fb, p_type_found, p_fbobj);
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
}
|
}
|
||||||
if (ch_cur == '\\') { /* Escape */
|
if (ch_cur == '\\') { /* Escape */
|
||||||
/* After an escape, data must be moved to fill in the gap
|
/* After an escape, data must be moved to fill in the gap
|
||||||
* left by the escape character */
|
* left by the escape character */
|
||||||
p_fb->p_data_cur = p_data_cur; /* Reprocess the escape */
|
p_fb->p_data_cur = p_data_cur; /* Reprocess the escape */
|
||||||
return fbget_quoted_escaped_string(p_fb,
|
return fbget_quoted_escaped_string(p_fb, p_fbstr);
|
||||||
p_type_found, p_fbobj);
|
|
||||||
}
|
}
|
||||||
/* Else the character is part of the quoted string */
|
/* Else the character is part of the quoted string */
|
||||||
} /* end of loop over current text */
|
} /* end of loop over current text */
|
||||||
|
|
@ -295,7 +275,7 @@ int fbget_quoted_unescaped_string(FILEBUF *p_fb,
|
||||||
* did not return -1, there is at least 1 byte at the end of
|
* did not return -1, there is at least 1 byte at the end of
|
||||||
* the buffer where the read would have gone. */
|
* the buffer where the read would have gone. */
|
||||||
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
|
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
|
||||||
return fb_return_string(p_fb, p_type_found, p_fbobj);
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
}
|
}
|
||||||
p_data_cur = p_fb->p_data_cur; /* Update after fill */
|
p_data_cur = p_fb->p_data_cur; /* Update after fill */
|
||||||
p_data_end = p_fb->p_data_end;
|
p_data_end = p_fb->p_data_end;
|
||||||
|
|
@ -306,8 +286,7 @@ int fbget_quoted_unescaped_string(FILEBUF *p_fb,
|
||||||
|
|
||||||
/* Get a quoted string with an escape. The start has already been set on
|
/* Get a quoted string with an escape. The start has already been set on
|
||||||
* entry */
|
* entry */
|
||||||
static int fbget_quoted_escaped_string(FILEBUF *p_fb,
|
static int fbget_quoted_escaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
{
|
||||||
/* Step through characters until end */
|
/* Step through characters until end */
|
||||||
char *p_data_src = p_fb->p_data_cur; /* at current char */
|
char *p_data_src = p_fb->p_data_cur; /* at current char */
|
||||||
|
|
@ -325,7 +304,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
|
||||||
if (ch_cur == '"') { /* Closing quote, so done */
|
if (ch_cur == '"') { /* Closing quote, so done */
|
||||||
p_fb->p_data_cur = p_data_src + 1;
|
p_fb->p_data_cur = p_data_src + 1;
|
||||||
*(p_fb->p_obj_end = p_data_dst) = '\0';
|
*(p_fb->p_obj_end = p_data_dst) = '\0';
|
||||||
return fb_return_string(p_fb, p_type_found, p_fbobj);
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
}
|
}
|
||||||
if (ch_cur == '\\') { /* Escape */
|
if (ch_cur == '\\') { /* Escape */
|
||||||
f_escape_in_progress = true;
|
f_escape_in_progress = true;
|
||||||
|
|
@ -344,8 +323,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
|
||||||
/* If no pending escape, can switch back to unescaped version and
|
/* If no pending escape, can switch back to unescaped version and
|
||||||
* avoid the moves */
|
* avoid the moves */
|
||||||
if (!f_escape_in_progress) {
|
if (!f_escape_in_progress) {
|
||||||
return fbget_quoted_unescaped_string(p_fb, p_type_found,
|
return fbget_quoted_unescaped_string(p_fb, p_fbstr);
|
||||||
p_fbobj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else escape must be processed, so continue with escaped version */
|
/* Else escape must be processed, so continue with escaped version */
|
||||||
|
|
@ -359,7 +337,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
|
||||||
* did not return -1, there is at least 1 byte at the end of
|
* did not return -1, there is at least 1 byte at the end of
|
||||||
* the buffer where the read would have gone. */
|
* the buffer where the read would have gone. */
|
||||||
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
|
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
|
||||||
return fb_return_string(p_fb, p_type_found, p_fbobj);
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
}
|
}
|
||||||
p_data_dst = p_data_src = p_fb->p_data_cur; /* Update after fill */
|
p_data_dst = p_data_src = p_fb->p_data_cur; /* Update after fill */
|
||||||
p_data_end = p_fb->p_data_end;
|
p_data_end = p_fb->p_data_end;
|
||||||
|
|
@ -369,9 +347,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
|
||||||
|
|
||||||
|
|
||||||
/* Get an unquoted string starting at the current position */
|
/* Get an unquoted string starting at the current position */
|
||||||
static int fbget_unquoted_string(FILEBUF *p_fb,
|
static int fbget_unquoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
|
||||||
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
|
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
{
|
||||||
/* Save the start of the string as the current position */
|
/* Save the start of the string as the current position */
|
||||||
p_fb->p_obj_start = p_fb->p_data_cur;
|
p_fb->p_obj_start = p_fb->p_data_cur;
|
||||||
|
|
@ -397,8 +373,7 @@ static int fbget_unquoted_string(FILEBUF *p_fb,
|
||||||
*(p_fb->p_obj_end = p_data_cur) = '\0';
|
*(p_fb->p_obj_end = p_data_cur) = '\0';
|
||||||
p_fb->p_data_cur = p_data_cur + 1; /* 1st char past string */
|
p_fb->p_data_cur = p_data_cur + 1; /* 1st char past string */
|
||||||
p_fb->f_skip_to_eol = map_cur < 0;
|
p_fb->f_skip_to_eol = map_cur < 0;
|
||||||
return fb_return_obj(p_fb, n_type_wanted, p_type_wanted,
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
p_type_found, p_fbobj);
|
|
||||||
}
|
}
|
||||||
/* Else more of the string */
|
/* Else more of the string */
|
||||||
} /* end of loop over current text */
|
} /* end of loop over current text */
|
||||||
|
|
@ -414,8 +389,7 @@ static int fbget_unquoted_string(FILEBUF *p_fb,
|
||||||
* did not return -1, there is at least 1 byte at the end of
|
* did not return -1, there is at least 1 byte at the end of
|
||||||
* the buffer where the read would have gone. */
|
* the buffer where the read would have gone. */
|
||||||
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
|
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
|
||||||
return fb_return_obj(p_fb, n_type_wanted, p_type_wanted,
|
return fb_return_string(p_fb, p_fbstr);
|
||||||
p_type_found, p_fbobj);
|
|
||||||
}
|
}
|
||||||
p_data_cur = p_fb->p_data_cur; /* Update after fill */
|
p_data_cur = p_fb->p_data_cur; /* Update after fill */
|
||||||
p_data_end = p_fb->p_data_end;
|
p_data_end = p_fb->p_data_end;
|
||||||
|
|
@ -619,78 +593,11 @@ static int fb_skip_to_eol(FILEBUF *p_fb)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Return the data found in the most preferred format possible */
|
|
||||||
static int fb_return_obj(FILEBUF *p_fb,
|
|
||||||
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
|
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
|
||||||
const char * const p_obj_start = p_fb->p_obj_start; /* data to convert */
|
|
||||||
const char * const p_obj_end = p_fb->p_obj_end;
|
|
||||||
|
|
||||||
/* Must test for null string separately since strto* does not set
|
|
||||||
* errno in this case. Aside from that, it can only be returned
|
|
||||||
* as a string anyhow. */
|
|
||||||
if (p_obj_start != p_obj_end) { /* have a string besides "" */
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; i < n_type_wanted; ++i) {
|
|
||||||
FBTYPE type_cur = p_type_wanted[i];
|
|
||||||
errno = 0;
|
|
||||||
if (type_cur == BUF_TYPE_ULONG) {
|
|
||||||
char *p_end;
|
|
||||||
unsigned long val = strtoul(p_obj_start, &p_end, 10);
|
|
||||||
/* Test for processing of full string. Note that checking
|
|
||||||
* for the end of the string rather than a NULL handles the
|
|
||||||
* case of an embedded NULL which the latter test would
|
|
||||||
* not */
|
|
||||||
if (errno == 0 && p_end == p_obj_end) {
|
|
||||||
*p_type_found = BUF_TYPE_ULONG;
|
|
||||||
p_fbobj->ulong_value = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type_cur == BUF_TYPE_LONG) {
|
|
||||||
char *p_end;
|
|
||||||
long val = strtol(p_obj_start, &p_end, 10);
|
|
||||||
if (errno == 0 && p_end == p_obj_end) {
|
|
||||||
*p_type_found = BUF_TYPE_LONG;
|
|
||||||
p_fbobj->long_value = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type_cur == BUF_TYPE_DOUBLE) {
|
|
||||||
char *p_end;
|
|
||||||
double val = strtod(p_obj_start, &p_end);
|
|
||||||
if (errno == 0 && p_end == p_obj_end) {
|
|
||||||
*p_type_found = BUF_TYPE_DOUBLE;
|
|
||||||
p_fbobj->dbl_value = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type_cur == BUF_TYPE_STRING) {
|
|
||||||
break; /* exit loop and use default return of string */
|
|
||||||
}
|
|
||||||
else { /* unknown type */
|
|
||||||
print_error("Unknown output data type %d is ignored.",
|
|
||||||
(int) type_cur);
|
|
||||||
}
|
|
||||||
} /* end of loop trying types */
|
|
||||||
} /* end of case that string is not "" */
|
|
||||||
|
|
||||||
/* If no rquested type was converted OK or string requested, return as
|
|
||||||
* a string */
|
|
||||||
return fb_return_string(p_fb, p_type_found, p_fbobj);
|
|
||||||
} /* end of function fb_return_obj */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Return string */
|
/* Return string */
|
||||||
static int fb_return_string(FILEBUF *p_fb,
|
static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj)
|
|
||||||
{
|
{
|
||||||
const char *p_data_start =
|
const char *p_data_start = p_fbstr->sz = p_fb->p_obj_start;
|
||||||
p_fbobj->str_value.sz = p_fb->p_obj_start;
|
p_fbstr->n_char = p_fb->p_obj_end - p_data_start;
|
||||||
p_fbobj->str_value.n_char = p_fb->p_obj_end - p_data_start;
|
|
||||||
*p_type_found = BUF_TYPE_STRING;
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* end of function fb_return_string */
|
} /* end of function fb_return_string */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,6 @@ typedef struct Filebuf_len_str {
|
||||||
char *sz; /* Start of string */
|
char *sz; /* Start of string */
|
||||||
} FBSTRING;
|
} FBSTRING;
|
||||||
|
|
||||||
/* Union for returned value */
|
|
||||||
typedef union Filebuf_obj {
|
|
||||||
FBSTRING str_value;
|
|
||||||
unsigned long ulong_value;
|
|
||||||
long long_value;
|
|
||||||
double dbl_value;
|
|
||||||
} FBOBJ;
|
|
||||||
|
|
||||||
/* Structure for getting file data */
|
/* Structure for getting file data */
|
||||||
typedef struct Filebuf {
|
typedef struct Filebuf {
|
||||||
FILE *fp; /* handle to file */
|
FILE *fp; /* handle to file */
|
||||||
|
|
@ -50,8 +42,7 @@ typedef enum FBtype {
|
||||||
|
|
||||||
|
|
||||||
FILEBUF *fbopen(const char *filename, size_t n_byte_buf_init);
|
FILEBUF *fbopen(const char *filename, size_t n_byte_buf_init);
|
||||||
int fbget(FILEBUF *p_fb, unsigned int n_type_wanted, FBTYPE *p_type_wanted,
|
int fbget(FILEBUF *p_fb, FBSTRING *p_fbstr);
|
||||||
FBTYPE *p_type_found, FBOBJ *p_fbobj);
|
|
||||||
int fbclose(FILEBUF *fbp);
|
int fbclose(FILEBUF *fbp);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,12 @@ typedef struct {
|
||||||
char *path_name; /* Pathname read from model path file */
|
char *path_name; /* Pathname read from model path file */
|
||||||
char *spice_name; /* Name of model from ifspec.ifs */
|
char *spice_name; /* Name of model from ifspec.ifs */
|
||||||
char *cfunc_name; /* Name of C fcn from ifspec.ifs */
|
char *cfunc_name; /* Name of C fcn from ifspec.ifs */
|
||||||
unsigned int version; /* version of the code model */
|
|
||||||
} Model_Info_t;
|
} Model_Info_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *path_name; /* Pathname read from udn path file */
|
char *path_name; /* Pathname read from udn path file */
|
||||||
char *node_name; /* Name of node type */
|
char *node_name; /* Name of node type */
|
||||||
unsigned int version; /* version of the code model */
|
|
||||||
} Node_Info_t;
|
} Node_Info_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -111,10 +109,8 @@ static bool test_for_duplicates(unsigned int n, struct Key_src *p_ks,
|
||||||
static inline void trim_slash(size_t *p_n, char *p);
|
static inline void trim_slash(size_t *p_n, char *p);
|
||||||
static int write_CMextrn(int num_models, Model_Info_t *model_info);
|
static int write_CMextrn(int num_models, Model_Info_t *model_info);
|
||||||
static int write_CMinfo(int num_models, Model_Info_t *model_info);
|
static int write_CMinfo(int num_models, Model_Info_t *model_info);
|
||||||
static int write_CMinfo2(int num_models, Model_Info_t *model_info);
|
|
||||||
static int write_UDNextrn(int num_nodes, Node_Info_t *node_info);
|
static int write_UDNextrn(int num_nodes, Node_Info_t *node_info);
|
||||||
static int write_UDNinfo(int num_nodes, Node_Info_t *node_info);
|
static int write_UDNinfo(int num_nodes, Node_Info_t *node_info);
|
||||||
static int write_UDNinfo2(int num_nodes, Node_Info_t *node_info);
|
|
||||||
static int write_objects_inc(int num_models, Model_Info_t *model_info,
|
static int write_objects_inc(int num_models, Model_Info_t *model_info,
|
||||||
int num_nodes, Node_Info_t *node_info);
|
int num_nodes, Node_Info_t *node_info);
|
||||||
static int read_udn_type_name(const char *path, char **node_name);
|
static int read_udn_type_name(const char *path, char **node_name);
|
||||||
|
|
@ -192,10 +188,6 @@ void preprocess_lst_files(void)
|
||||||
if(status != 0) {
|
if(status != 0) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
status = write_CMinfo2(num_models, model_info);
|
|
||||||
if(status != 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write out the UDNextrn.h file used to compile SPIinit.c */
|
/* Write out the UDNextrn.h file used to compile SPIinit.c */
|
||||||
status = write_UDNextrn(num_nodes, node_info);
|
status = write_UDNextrn(num_nodes, node_info);
|
||||||
|
|
@ -208,10 +200,6 @@ void preprocess_lst_files(void)
|
||||||
if(status != 0) {
|
if(status != 0) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
status = write_UDNinfo2(num_nodes, node_info);
|
|
||||||
if(status != 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write the make_include file used to link the models and */
|
/* Write the make_include file used to link the models and */
|
||||||
/* user-defined node functions with the simulator */
|
/* user-defined node functions with the simulator */
|
||||||
|
|
@ -249,40 +237,10 @@ int output_paths_from_lst_file(const char *filename)
|
||||||
goto EXITPOINT;
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool f_have_path = false; /* do not have a path to store */
|
FBSTRING fbstr;
|
||||||
FBTYPE fbtype;
|
|
||||||
FBOBJ fbobj;
|
|
||||||
for ( ; ; ) { /* Read items until end of file */
|
for ( ; ; ) { /* Read items until end of file */
|
||||||
/* Get the next path if not found yet */
|
/* Get the next path if not found yet */
|
||||||
if (!f_have_path) {
|
const int rc = fbget(fbp, &fbstr);
|
||||||
const int rc = fbget(fbp, 0, (FBTYPE *) NULL, &fbtype, &fbobj);
|
|
||||||
if (rc != 0) {
|
|
||||||
if (rc == -1) { /* Error */
|
|
||||||
print_error("ERROR - Unable to read item to buffer");
|
|
||||||
xrc = -1;
|
|
||||||
goto EXITPOINT;
|
|
||||||
}
|
|
||||||
else { /* +1 -- EOF */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} /* end of abnormal case */
|
|
||||||
|
|
||||||
/* Remove trailing slash if appended to path */
|
|
||||||
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Output the file that was found */
|
|
||||||
if (fprintf(stdout, "%s\n", fbobj.str_value.sz) < 0) {
|
|
||||||
print_error("ERROR - Unable to output path name to stdout: %s",
|
|
||||||
strerror(errno));
|
|
||||||
xrc = -1;
|
|
||||||
goto EXITPOINT;
|
|
||||||
}
|
|
||||||
++n_path; /* 1 more path printed OK */
|
|
||||||
|
|
||||||
/* Try getting a version. If found, it will be discarded */
|
|
||||||
FBTYPE type_wanted = BUF_TYPE_ULONG;
|
|
||||||
const int rc = fbget(fbp, 1, &type_wanted, &fbtype, &fbobj);
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
if (rc == -1) { /* Error */
|
if (rc == -1) { /* Error */
|
||||||
print_error("ERROR - Unable to read item to buffer");
|
print_error("ERROR - Unable to read item to buffer");
|
||||||
|
|
@ -294,15 +252,17 @@ int output_paths_from_lst_file(const char *filename)
|
||||||
}
|
}
|
||||||
} /* end of abnormal case */
|
} /* end of abnormal case */
|
||||||
|
|
||||||
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
|
/* Remove trailing slash if appended to path */
|
||||||
f_have_path = false;
|
trim_slash(&fbstr.n_char, fbstr.sz);
|
||||||
}
|
|
||||||
else { /* it was a string, so it is the next path */
|
|
||||||
f_have_path = true;
|
|
||||||
|
|
||||||
/* Remove trailing slash if appended to path */
|
/* Output the file that was found */
|
||||||
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
|
if (fprintf(stdout, "%s\n", fbstr.sz) < 0) {
|
||||||
|
print_error("ERROR - Unable to output path name to stdout: %s",
|
||||||
|
strerror(errno));
|
||||||
|
xrc = -1;
|
||||||
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
|
++n_path; /* 1 more path printed OK */
|
||||||
} /* end of loop reading items into buffer */
|
} /* end of loop reading items into buffer */
|
||||||
|
|
||||||
EXITPOINT:
|
EXITPOINT:
|
||||||
|
|
@ -377,27 +337,23 @@ static int read_modpath(
|
||||||
}
|
}
|
||||||
n_model_info_alloc = N_MODEL_INIT;
|
n_model_info_alloc = N_MODEL_INIT;
|
||||||
|
|
||||||
bool f_have_path = false; /* do not have a path to store */
|
FBSTRING fbstr;
|
||||||
FBTYPE fbtype;
|
|
||||||
FBOBJ fbobj;
|
|
||||||
for ( ; ; ) { /* Read items until end of file */
|
for ( ; ; ) { /* Read items until end of file */
|
||||||
/* Get the next path if not found yet */
|
/* Get the next path if not found yet */
|
||||||
if (!f_have_path) {
|
const int rc = fbget(fbp, &fbstr);
|
||||||
const int rc = fbget(fbp, 0, (FBTYPE *) NULL, &fbtype, &fbobj);
|
if (rc != 0) {
|
||||||
if (rc != 0) {
|
if (rc == -1) { /* Error */
|
||||||
if (rc == -1) { /* Error */
|
print_error("ERROR - Unable to read item to buffer");
|
||||||
print_error("ERROR - Unable to read item to buffer");
|
xrc = -1;
|
||||||
xrc = -1;
|
goto EXITPOINT;
|
||||||
goto EXITPOINT;
|
}
|
||||||
}
|
else { /* +1 -- EOF */
|
||||||
else { /* +1 -- EOF */
|
break;
|
||||||
break;
|
}
|
||||||
}
|
} /* end of abnormal case */
|
||||||
} /* end of abnormal case */
|
|
||||||
|
|
||||||
/* Remove trailing slash if appended to path */
|
/* Remove trailing slash if appended to path */
|
||||||
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
|
trim_slash(&fbstr.n_char, fbstr.sz);
|
||||||
}
|
|
||||||
|
|
||||||
/* Enlarge model array if full */
|
/* Enlarge model array if full */
|
||||||
if (n_model_info_alloc == n_model_info) {
|
if (n_model_info_alloc == n_model_info) {
|
||||||
|
|
@ -417,44 +373,18 @@ static int read_modpath(
|
||||||
n_model_info;
|
n_model_info;
|
||||||
|
|
||||||
if ((p_model_info_cur->path_name = (char *) malloc(
|
if ((p_model_info_cur->path_name = (char *) malloc(
|
||||||
fbobj.str_value.n_char + 1)) == (char *) NULL) {
|
fbstr.n_char + 1)) == (char *) NULL) {
|
||||||
print_error("ERROR - Unable to allocate path name");
|
print_error("ERROR - Unable to allocate path name");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
goto EXITPOINT;
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(p_model_info_cur->path_name, fbobj.str_value.sz);
|
strcpy(p_model_info_cur->path_name, fbstr.sz);
|
||||||
p_model_info_cur->spice_name = (char *) NULL;
|
p_model_info_cur->spice_name = (char *) NULL;
|
||||||
p_model_info_cur->cfunc_name = (char *) NULL;
|
p_model_info_cur->cfunc_name = (char *) NULL;
|
||||||
|
|
||||||
/* Must set before returning due to EOF. */
|
/* Must set before returning due to EOF. */
|
||||||
p_model_info_cur->version = 1;
|
|
||||||
++n_model_info;
|
++n_model_info;
|
||||||
|
|
||||||
/* Try getting a version */
|
|
||||||
FBTYPE type_wanted = BUF_TYPE_ULONG;
|
|
||||||
const int rc = fbget(fbp, 1, &type_wanted, &fbtype, &fbobj);
|
|
||||||
if (rc != 0) {
|
|
||||||
if (rc == -1) { /* Error */
|
|
||||||
print_error("ERROR - Unable to read item to buffer");
|
|
||||||
xrc = -1;
|
|
||||||
goto EXITPOINT;
|
|
||||||
}
|
|
||||||
else { /* +1 -- EOF */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} /* end of abnormal case */
|
|
||||||
|
|
||||||
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
|
|
||||||
f_have_path = false;
|
|
||||||
p_model_info_cur->version = (unsigned int) fbobj.ulong_value;
|
|
||||||
}
|
|
||||||
else { /* it was a string, so it is the next path */
|
|
||||||
f_have_path = true;
|
|
||||||
|
|
||||||
/* Remove trailing slash if appended to path */
|
|
||||||
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
|
|
||||||
}
|
|
||||||
} /* end of loop reading items into buffer */
|
} /* end of loop reading items into buffer */
|
||||||
|
|
||||||
EXITPOINT:
|
EXITPOINT:
|
||||||
|
|
@ -552,29 +482,24 @@ static int read_udnpath(
|
||||||
}
|
}
|
||||||
n_node_info_alloc = N_NODE_INIT;
|
n_node_info_alloc = N_NODE_INIT;
|
||||||
|
|
||||||
bool f_have_path = false; /* do not have a path to store */
|
FBSTRING fbstr;
|
||||||
FBTYPE fbtype;
|
|
||||||
FBOBJ fbobj;
|
|
||||||
|
|
||||||
for ( ; ; ) { /* Read items until end of file */
|
for ( ; ; ) { /* Read items until end of file */
|
||||||
/* Get the next path if not found yet */
|
/* Get the next path if not found yet */
|
||||||
if (!f_have_path) {
|
const int rc = fbget(fbp, &fbstr);
|
||||||
const int rc = fbget(fbp, 0, (FBTYPE *) NULL, &fbtype, &fbobj);
|
if (rc != 0) {
|
||||||
if (rc != 0) {
|
if (rc == -1) { /* Error */
|
||||||
if (rc == -1) { /* Error */
|
print_error("ERROR - Unable to read item to buffer");
|
||||||
print_error("ERROR - Unable to read item to buffer");
|
xrc = -1;
|
||||||
xrc = -1;
|
goto EXITPOINT;
|
||||||
goto EXITPOINT;
|
}
|
||||||
}
|
else { /* +1 -- EOF */
|
||||||
else { /* +1 -- EOF */
|
break;
|
||||||
break;
|
}
|
||||||
}
|
} /* end of abnormal case */
|
||||||
} /* end of abnormal case */
|
|
||||||
|
|
||||||
/* Remove trailing slash if appended to path */
|
|
||||||
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Remove trailing slash if appended to path */
|
||||||
|
trim_slash(&fbstr.n_char, fbstr.sz);
|
||||||
|
|
||||||
/* Enlarge node array if full */
|
/* Enlarge node array if full */
|
||||||
if (n_node_info_alloc == n_node_info) {
|
if (n_node_info_alloc == n_node_info) {
|
||||||
|
|
@ -594,44 +519,14 @@ static int read_udnpath(
|
||||||
n_node_info;
|
n_node_info;
|
||||||
|
|
||||||
if ((p_node_info_cur->path_name = (char *) malloc(
|
if ((p_node_info_cur->path_name = (char *) malloc(
|
||||||
fbobj.str_value.n_char + 1)) == (char *) NULL) {
|
fbstr.n_char + 1)) == (char *) NULL) {
|
||||||
print_error("ERROR - Unable to allocate path name");
|
print_error("ERROR - Unable to allocate path name");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
goto EXITPOINT;
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(p_node_info_cur->path_name, fbobj.str_value.sz);
|
strcpy(p_node_info_cur->path_name, fbstr.sz);
|
||||||
p_node_info_cur->node_name = NULL;
|
p_node_info_cur->node_name = NULL;
|
||||||
|
|
||||||
/* Must set before returning due to EOF. */
|
|
||||||
p_node_info_cur->version = 1;
|
|
||||||
++n_node_info;
|
|
||||||
|
|
||||||
/* Try getting a version */
|
|
||||||
FBTYPE type_wanted = BUF_TYPE_ULONG;
|
|
||||||
const int rc = fbget(fbp, 1, &type_wanted, &fbtype, &fbobj);
|
|
||||||
if (rc != 0) {
|
|
||||||
if (rc == -1) { /* Error */
|
|
||||||
print_error("ERROR - Unable to read item to buffer");
|
|
||||||
xrc = -1;
|
|
||||||
goto EXITPOINT;
|
|
||||||
}
|
|
||||||
else { /* +1 -- EOF */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} /* end of abnormal case */
|
|
||||||
|
|
||||||
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
|
|
||||||
f_have_path = false;
|
|
||||||
p_node_info_cur->version = (unsigned int) fbobj.ulong_value;
|
|
||||||
}
|
|
||||||
else { /* it was a string, so it is the next path */
|
|
||||||
f_have_path = true;
|
|
||||||
|
|
||||||
/* Remove trailing slash if appended to path */
|
|
||||||
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of loop reading items into buffer */
|
} /* end of loop reading items into buffer */
|
||||||
|
|
||||||
EXITPOINT:
|
EXITPOINT:
|
||||||
|
|
@ -1230,10 +1125,7 @@ static int write_CMinfo(
|
||||||
|
|
||||||
/* Write out the data */
|
/* Write out the data */
|
||||||
for(i = 0; i < num_models; i++) {
|
for(i = 0; i < num_models; i++) {
|
||||||
Model_Info_t *p_mi_cur = model_info + i;
|
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
|
||||||
if (p_mi_cur->version == 1) {
|
|
||||||
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the file and return */
|
/* Close the file and return */
|
||||||
|
|
@ -1249,49 +1141,6 @@ static int write_CMinfo(
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int write_CMinfo2(
|
|
||||||
int num_models, /* Number of model pathnames */
|
|
||||||
Model_Info_t *model_info /* Info about each model */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int i; /* A temporary counter */
|
|
||||||
FILE *fp; /* File pointer for writing CMinfo.h */
|
|
||||||
|
|
||||||
char *filename = (char *) NULL;
|
|
||||||
|
|
||||||
/* Open the file to be written */
|
|
||||||
if ((filename = gen_filename("cminfo2.h", "w")) == (char *) NULL) {
|
|
||||||
print_error("ERROR - Unable to build path to cminfo2.h");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fp = fopen(filename, "w");
|
|
||||||
if(fp == NULL) {
|
|
||||||
print_error("ERROR - Problems opening %s for write", filename);
|
|
||||||
free(filename);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write out the data */
|
|
||||||
for (i = 0; i < num_models; i++) {
|
|
||||||
Model_Info_t *p_mi_cur = model_info + i;
|
|
||||||
if (p_mi_cur->version <= 2) {
|
|
||||||
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the file and return */
|
|
||||||
if (fclose(fp) != 0) {
|
|
||||||
print_error("ERROR - Problems closing %s", filename);
|
|
||||||
free(filename);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(filename);
|
|
||||||
return 0;
|
|
||||||
} /* end of function write_CMinfo2 */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* *********************************************************************** */
|
/* *********************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1383,51 +1232,7 @@ static int write_UDNinfo(
|
||||||
/* Write out the data */
|
/* Write out the data */
|
||||||
for(i = 0; i < num_nodes; i++) {
|
for(i = 0; i < num_nodes; i++) {
|
||||||
Node_Info_t *p_ni_cur = node_info + i;
|
Node_Info_t *p_ni_cur = node_info + i;
|
||||||
if (p_ni_cur->version == 1) {
|
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
|
||||||
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the file and return */
|
|
||||||
if (fclose(fp) != 0) {
|
|
||||||
print_error("ERROR - Problems closing %s", filename);
|
|
||||||
free(filename);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(filename);
|
|
||||||
return 0;
|
|
||||||
} /* end of function write_UDNinfo */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int write_UDNinfo2(
|
|
||||||
int num_nodes, /* Number of node pathnames */
|
|
||||||
Node_Info_t *node_info /* Info about each node */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int i; /* A temporary counter */
|
|
||||||
FILE *fp; /* File pointer for writing UDNinfo.h */
|
|
||||||
|
|
||||||
char *filename = (char *) NULL;
|
|
||||||
|
|
||||||
/* Open the file to be written */
|
|
||||||
if ((filename = gen_filename("udninfo2.h", "w")) == (char *) NULL) {
|
|
||||||
print_error("ERROR - Unable to build path to udninfo2.h");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fp = fopen(filename, "w");
|
|
||||||
if(fp == NULL) {
|
|
||||||
print_error("ERROR - Problems opening %s for write", filename);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write out the data */
|
|
||||||
for(i = 0; i < num_nodes; i++) {
|
|
||||||
Node_Info_t *p_ni_cur = node_info + i;
|
|
||||||
if (p_ni_cur->version <= 2) {
|
|
||||||
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the file and return */
|
/* Close the file and return */
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,12 @@ NON-STANDARD FEATURES
|
||||||
#define DIR_PATHSEP "/"
|
#define DIR_PATHSEP "/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* For WIN32, make strdup become _strdup unless it is defined already,
|
||||||
|
* as it would be if CRT debugging is being used */
|
||||||
|
#if defined(_WIN32) && !defined(strdup)
|
||||||
|
#define strdup _strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
|
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
|
||||||
|
|
||||||
struct filesource_state {
|
struct filesource_state {
|
||||||
|
|
@ -167,7 +173,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
/*** allocate static storage for *loc ***/
|
/*** allocate static storage for *loc ***/
|
||||||
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
|
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
|
||||||
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate Local_Data_t "
|
cm_message_send("Unable to allocate Local_Data_t "
|
||||||
"in cm_filesource()");
|
"in cm_filesource()");
|
||||||
|
|
@ -175,14 +181,14 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate storage for internal state */
|
/* Allocate storage for internal state */
|
||||||
loc->timeinterval = (double *) tcalloc_raw(2, sizeof(double));
|
loc->timeinterval = (double *) calloc(2, sizeof(double));
|
||||||
loc->amplinterval = (double *) tcalloc_raw(2 * (size_t) size,
|
loc->amplinterval = (double *) calloc(2 * (size_t) size,
|
||||||
sizeof(double));
|
sizeof(double));
|
||||||
loc->state = (struct filesource_state *) tcalloc_raw(1,
|
loc->state = (struct filesource_state *) calloc(1,
|
||||||
sizeof(struct filesource_state)); /* calloc to null fp */
|
sizeof(struct filesource_state)); /* calloc to null fp */
|
||||||
loc->indata = (struct infiledata *) tmalloc_raw(
|
loc->indata = (struct infiledata *) malloc(
|
||||||
sizeof(struct infiledata));
|
sizeof(struct infiledata));
|
||||||
loc->indata->datavec = (double *) tmalloc_raw(sizeof(double) *
|
loc->indata->datavec = (double *) malloc(sizeof(double) *
|
||||||
stepsize * 1000);
|
stepsize * 1000);
|
||||||
|
|
||||||
/* Check allocations */
|
/* Check allocations */
|
||||||
|
|
@ -212,7 +218,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
||||||
lbuffer = getenv("NGSPICE_INPUT_DIR");
|
lbuffer = getenv("NGSPICE_INPUT_DIR");
|
||||||
if (lbuffer && *lbuffer) {
|
if (lbuffer && *lbuffer) {
|
||||||
char *p;
|
char *p;
|
||||||
if ((p = (char *) tmalloc_raw(strlen(lbuffer) +
|
if ((p = (char *) malloc(strlen(lbuffer) +
|
||||||
strlen(DIR_PATHSEP) + strlen(PARAM(file)) + 1)) ==
|
strlen(DIR_PATHSEP) + strlen(PARAM(file)) + 1)) ==
|
||||||
(char *) NULL) {
|
(char *) NULL) {
|
||||||
cm_message_send("Unable to allocate buffer "
|
cm_message_send("Unable to allocate buffer "
|
||||||
|
|
@ -243,7 +249,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
||||||
loc->state->atend = 1;
|
loc->state->atend = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((cpdel = cp = tstrdup_raw(line)) == (char *) NULL) {
|
if ((cpdel = cp = strdup(line)) == (char *) NULL) {
|
||||||
cm_message_send("Unable to duplicate string "
|
cm_message_send("Unable to duplicate string "
|
||||||
"cm_filesource()");
|
"cm_filesource()");
|
||||||
loc->state->atend = 1;
|
loc->state->atend = 1;
|
||||||
|
|
@ -276,7 +282,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
||||||
If not, add another 1000*size doubles */
|
If not, add another 1000*size doubles */
|
||||||
if (count > loc->indata->vecallocated - size) {
|
if (count > loc->indata->vecallocated - size) {
|
||||||
loc->indata->vecallocated += size * 1000;
|
loc->indata->vecallocated += size * 1000;
|
||||||
void * const p = trealloc_raw(loc->indata->datavec,
|
void * const p = realloc(loc->indata->datavec,
|
||||||
sizeof(double) * loc->indata->vecallocated);
|
sizeof(double) * loc->indata->vecallocated);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
cm_message_printf("cannot allocate enough memory");
|
cm_message_printf("cannot allocate enough memory");
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
#Directory Version
|
#Directory
|
||||||
climit 1
|
climit
|
||||||
divide 1
|
divide
|
||||||
d_dt 1
|
d_dt
|
||||||
gain 1
|
gain
|
||||||
hyst 1
|
hyst
|
||||||
ilimit 1
|
ilimit
|
||||||
int 1
|
int
|
||||||
limit 1
|
limit
|
||||||
mult 1
|
mult
|
||||||
multi_input_pwl 1
|
multi_input_pwl
|
||||||
oneshot 2
|
oneshot
|
||||||
pwl 2
|
pwl
|
||||||
sine 2
|
sine
|
||||||
slew 1
|
slew
|
||||||
square 1
|
square
|
||||||
summer 1
|
summer
|
||||||
s_xfer 2
|
s_xfer
|
||||||
triangle 1
|
triangle
|
||||||
file_source 2
|
file_source
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,7 @@ void cm_oneshot(ARGS) /* structure holding parms,
|
||||||
cm_analog_alloc(OUTPUT_OLD,sizeof(double));
|
cm_analog_alloc(OUTPUT_OLD,sizeof(double));
|
||||||
|
|
||||||
/*** allocate static storage for *loc ***/
|
/*** allocate static storage for *loc ***/
|
||||||
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
|
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
|
||||||
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate Local_Data_t "
|
cm_message_send("Unable to allocate Local_Data_t "
|
||||||
"in cm_oneshot()");
|
"in cm_oneshot()");
|
||||||
|
|
@ -262,13 +262,13 @@ void cm_oneshot(ARGS) /* structure holding parms,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate storage for breakpoint domain & pulse width values */
|
/* Allocate storage for breakpoint domain & pulse width values */
|
||||||
if ((x = loc->control = (double *) tcalloc_raw((size_t) cntl_size,
|
if ((x = loc->control = (double *) calloc((size_t) cntl_size,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_send(oneshot_allocation_error);
|
cm_message_send(oneshot_allocation_error);
|
||||||
cm_oneshot_callback(mif_private, MIF_CB_DESTROY);
|
cm_oneshot_callback(mif_private, MIF_CB_DESTROY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((y = loc->pw = (double *) tcalloc_raw((size_t) pw_size,
|
if ((y = loc->pw = (double *) calloc((size_t) pw_size,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_send(oneshot_allocation_error);
|
cm_message_send(oneshot_allocation_error);
|
||||||
cm_oneshot_callback(mif_private, MIF_CB_DESTROY);
|
cm_oneshot_callback(mif_private, MIF_CB_DESTROY);
|
||||||
|
|
|
||||||
|
|
@ -297,11 +297,11 @@ void cm_pwl(ARGS) /* structure holding parms,
|
||||||
if (INIT==1) { /* First pass...allocate storage for previous value... */
|
if (INIT==1) { /* First pass...allocate storage for previous value... */
|
||||||
|
|
||||||
/* Allocate storage for last_x_value */
|
/* Allocate storage for last_x_value */
|
||||||
last_x_value = (double *) (STATIC_VAR(last_x_value) = tmalloc_raw(
|
last_x_value = (double *) (STATIC_VAR(last_x_value) = malloc(
|
||||||
sizeof(double)));
|
sizeof(double)));
|
||||||
x = (double *) (STATIC_VAR(x) = tcalloc_raw((size_t) size,
|
x = (double *) (STATIC_VAR(x) = calloc((size_t) size,
|
||||||
sizeof(double)));
|
sizeof(double)));
|
||||||
y = (double *) (STATIC_VAR(y) = tcalloc_raw((size_t) size,
|
y = (double *) (STATIC_VAR(y) = calloc((size_t) size,
|
||||||
sizeof(double)));
|
sizeof(double)));
|
||||||
if (last_x_value == (double *) NULL ||
|
if (last_x_value == (double *) NULL ||
|
||||||
x == (double *) NULL || y == (double *) NULL) {
|
x == (double *) NULL || y == (double *) NULL) {
|
||||||
|
|
|
||||||
|
|
@ -275,20 +275,20 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
||||||
|
|
||||||
/* We have to allocate memory and use cm_analog_alloc, because the
|
/* We have to allocate memory and use cm_analog_alloc, because the
|
||||||
* ITP variables are not functional */
|
* ITP variables are not functional */
|
||||||
integrator = (double **) tcalloc_raw((size_t) den_size,
|
integrator = (double **) calloc((size_t) den_size,
|
||||||
sizeof(double *));
|
sizeof(double *));
|
||||||
old_integrator = (double **) tcalloc_raw((size_t) den_size,
|
old_integrator = (double **) calloc((size_t) den_size,
|
||||||
sizeof(double *));
|
sizeof(double *));
|
||||||
|
|
||||||
/* Allocate storage for coefficient values */
|
/* Allocate storage for coefficient values */
|
||||||
den_coefficient = (double **) tcalloc_raw((size_t) den_size,
|
den_coefficient = (double **) calloc((size_t) den_size,
|
||||||
sizeof(double *));
|
sizeof(double *));
|
||||||
old_den_coefficient = (double **) tcalloc_raw((size_t) den_size,
|
old_den_coefficient = (double **) calloc((size_t) den_size,
|
||||||
sizeof(double *));
|
sizeof(double *));
|
||||||
|
|
||||||
num_coefficient = (double **) tcalloc_raw((size_t) num_size,
|
num_coefficient = (double **) calloc((size_t) num_size,
|
||||||
sizeof(double *));
|
sizeof(double *));
|
||||||
old_num_coefficient = (double **) tcalloc_raw((size_t) num_size,
|
old_num_coefficient = (double **) calloc((size_t) num_size,
|
||||||
sizeof(double *));
|
sizeof(double *));
|
||||||
|
|
||||||
if (integrator == (double **) NULL ||
|
if (integrator == (double **) NULL ||
|
||||||
|
|
@ -324,7 +324,7 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
||||||
|
|
||||||
/* ITP_VAR_SIZE(den) = den_size; */
|
/* ITP_VAR_SIZE(den) = den_size; */
|
||||||
|
|
||||||
/* gain = (double *) tcalloc_raw(1, sizeof(double));
|
/* gain = (double *) calloc(1, sizeof(double));
|
||||||
ITP_VAR(total_gain) = gain;
|
ITP_VAR(total_gain) = gain;
|
||||||
ITP_VAR_SIZE(total_gain) = 1.0; */
|
ITP_VAR_SIZE(total_gain) = 1.0; */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ void cm_d_genlut(ARGS)
|
||||||
|
|
||||||
if (INIT) { /* initial pass */
|
if (INIT) { /* initial pass */
|
||||||
/* allocate storage for the lookup table */
|
/* allocate storage for the lookup table */
|
||||||
if ((lookup_table = (Digital_t *) (STATIC_VAR(locdata) = tcalloc_raw(
|
if ((lookup_table = (Digital_t *) (STATIC_VAR(locdata) = calloc(
|
||||||
(size_t) tablelen, sizeof(Digital_t)))) ==
|
(size_t) tablelen, sizeof(Digital_t)))) ==
|
||||||
(Digital_t *) NULL) {
|
(Digital_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate Digital_t structure "
|
cm_message_send("Unable to allocate Digital_t structure "
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ void cm_d_lut(ARGS)
|
||||||
if (INIT) { /* initial pass */
|
if (INIT) { /* initial pass */
|
||||||
/* allocate storage for the lookup table */
|
/* allocate storage for the lookup table */
|
||||||
if ((lookup_table = (Digital_State_t *) (STATIC_VAR (locdata) =
|
if ((lookup_table = (Digital_State_t *) (STATIC_VAR (locdata) =
|
||||||
tcalloc_raw((size_t) tablelen, sizeof(Digital_State_t)))) ==
|
calloc((size_t) tablelen, sizeof(Digital_State_t)))) ==
|
||||||
(Digital_State_t *) NULL) {
|
(Digital_State_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate Digital_t structure "
|
cm_message_send("Unable to allocate Digital_t structure "
|
||||||
"in cm_d_lut()");
|
"in cm_d_lut()");
|
||||||
|
|
|
||||||
|
|
@ -277,13 +277,13 @@ void cm_d_osc(ARGS)
|
||||||
|
|
||||||
/* Allocate storage for breakpoint domain & freq. range values */
|
/* Allocate storage for breakpoint domain & freq. range values */
|
||||||
|
|
||||||
x = (double *) tcalloc_raw((size_t) cntl_size, sizeof(double));
|
x = (double *) calloc((size_t) cntl_size, sizeof(double));
|
||||||
if (!x) {
|
if (!x) {
|
||||||
cm_message_send(d_osc_allocation_error);
|
cm_message_send(d_osc_allocation_error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
y = (double *) tcalloc_raw((size_t) freq_size, sizeof(double));
|
y = (double *) calloc((size_t) freq_size, sizeof(double));
|
||||||
if (!y) {
|
if (!y) {
|
||||||
cm_message_send(d_osc_allocation_error);
|
cm_message_send(d_osc_allocation_error);
|
||||||
txfree(x);
|
txfree(x);
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ static char *CNVgettok(char **s)
|
||||||
|
|
||||||
/* allocate space big enough for the whole string */
|
/* allocate space big enough for the whole string */
|
||||||
|
|
||||||
if ((buf = (char *) tmalloc_raw(strlen(*s) + 1)) == (char *) NULL) {
|
if ((buf = (char *) malloc(strlen(*s) + 1)) == (char *) NULL) {
|
||||||
cm_message_send("Unable to allocate buffer in CNVgettok()");
|
cm_message_send("Unable to allocate buffer in CNVgettok()");
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +213,7 @@ static char *CNVgettok(char **s)
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
char * const ret_str = (char *) tmalloc_raw(strlen(buf) + 1);
|
char * const ret_str = (char *) malloc(strlen(buf) + 1);
|
||||||
if (ret_str == (char *) NULL) {
|
if (ret_str == (char *) NULL) {
|
||||||
cm_message_send("Unable to allocate return buffer "
|
cm_message_send("Unable to allocate return buffer "
|
||||||
"in CNVgettok()");
|
"in CNVgettok()");
|
||||||
|
|
@ -751,7 +751,7 @@ static int cm_read_source(FILE *source, Local_Data_t *loc)
|
||||||
s = base_address;
|
s = base_address;
|
||||||
|
|
||||||
/* set storage space for bits in a row and set them to 0*/
|
/* set storage space for bits in a row and set them to 0*/
|
||||||
if ((loc->all_data[i] = (char *) tcalloc_raw(
|
if ((loc->all_data[i] = (char *) calloc(
|
||||||
(size_t) loc->width,
|
(size_t) loc->width,
|
||||||
sizeof(char))) == (char *) NULL) {
|
sizeof(char))) == (char *) NULL) {
|
||||||
cm_message_send("Unable to allocate buffer "
|
cm_message_send("Unable to allocate buffer "
|
||||||
|
|
@ -936,7 +936,7 @@ void cm_d_source(ARGS)
|
||||||
char *lbuffer, *p;
|
char *lbuffer, *p;
|
||||||
lbuffer = getenv("NGSPICE_INPUT_DIR");
|
lbuffer = getenv("NGSPICE_INPUT_DIR");
|
||||||
if (lbuffer && *lbuffer) {
|
if (lbuffer && *lbuffer) {
|
||||||
p = (char *) tmalloc_raw(strlen(lbuffer) +
|
p = (char *) malloc(strlen(lbuffer) +
|
||||||
strlen(DIR_PATHSEP) + strlen(PARAM(input_file)) + 1);
|
strlen(DIR_PATHSEP) + strlen(PARAM(input_file)) + 1);
|
||||||
if (p == (char *) NULL) {
|
if (p == (char *) NULL) {
|
||||||
cm_message_send("Unable to allocate buffer "
|
cm_message_send("Unable to allocate buffer "
|
||||||
|
|
@ -966,7 +966,7 @@ void cm_d_source(ARGS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** allocate static storage for *loc ***/
|
/*** allocate static storage for *loc ***/
|
||||||
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
|
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
|
||||||
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate buffer "
|
cm_message_send("Unable to allocate buffer "
|
||||||
"for building file name in cm_d_source()");
|
"for building file name in cm_d_source()");
|
||||||
|
|
@ -994,7 +994,7 @@ void cm_d_source(ARGS)
|
||||||
loc->width = PORT_SIZE(out);
|
loc->width = PORT_SIZE(out);
|
||||||
|
|
||||||
/*** allocate storage for **all_data, & *all_timepoints ***/
|
/*** allocate storage for **all_data, & *all_timepoints ***/
|
||||||
if ((loc->all_timepoints = (double *) tcalloc_raw((size_t) i,
|
if ((loc->all_timepoints = (double *) calloc((size_t) i,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_send("Unable to allocate all_timepoints "
|
cm_message_send("Unable to allocate all_timepoints "
|
||||||
"in cm_d_source()");
|
"in cm_d_source()");
|
||||||
|
|
@ -1002,7 +1002,7 @@ void cm_d_source(ARGS)
|
||||||
STATIC_VAR(locdata) = NULL;
|
STATIC_VAR(locdata) = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((loc->all_data = (char **) tcalloc_raw((size_t) i,
|
if ((loc->all_data = (char **) calloc((size_t) i,
|
||||||
sizeof(char *))) == (char **) NULL) {
|
sizeof(char *))) == (char **) NULL) {
|
||||||
cm_message_send("Unable to allocate all_data "
|
cm_message_send("Unable to allocate all_data "
|
||||||
"in cm_d_source()");
|
"in cm_d_source()");
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ static char *CNVgettok(char **s)
|
||||||
|
|
||||||
/* allocate space big enough for the whole string */
|
/* allocate space big enough for the whole string */
|
||||||
|
|
||||||
if ((buf = (char *) tmalloc_raw(strlen(*s) + 1)) == (char *) NULL) {
|
if ((buf = (char *) malloc(strlen(*s) + 1)) == (char *) NULL) {
|
||||||
cm_message_send("Unable to allocate buffer in CNVgettok()");
|
cm_message_send("Unable to allocate buffer in CNVgettok()");
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +255,7 @@ static char *CNVgettok(char **s)
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
char * const ret_str = (char *) tmalloc_raw(strlen(buf) + 1);
|
char * const ret_str = (char *) malloc(strlen(buf) + 1);
|
||||||
if (ret_str == (char *) NULL) {
|
if (ret_str == (char *) NULL) {
|
||||||
cm_message_send("Unable to allocate return buffer "
|
cm_message_send("Unable to allocate return buffer "
|
||||||
"in CNVgettok()");
|
"in CNVgettok()");
|
||||||
|
|
@ -1804,15 +1804,15 @@ void cm_d_state(ARGS)
|
||||||
|
|
||||||
|
|
||||||
/* assign storage for arrays to pointers in states table */
|
/* assign storage for arrays to pointers in states table */
|
||||||
states->state = (int *) tcalloc_raw(
|
states->state = (int *) calloc(
|
||||||
(size_t) (states->depth + 1), sizeof(int));
|
(size_t) (states->depth + 1), sizeof(int));
|
||||||
states->bits = (short *) tcalloc_raw(
|
states->bits = (short *) calloc(
|
||||||
(size_t) (states->num_outputs * states->depth / 4 + 1),
|
(size_t) (states->num_outputs * states->depth / 4 + 1),
|
||||||
sizeof(short));
|
sizeof(short));
|
||||||
states->inputs = (short *) tcalloc_raw(
|
states->inputs = (short *) calloc(
|
||||||
(size_t) (states->num_inputs * states->depth / 8 + 1),
|
(size_t) (states->num_inputs * states->depth / 8 + 1),
|
||||||
sizeof(short));
|
sizeof(short));
|
||||||
states->next_state = (int *) tcalloc_raw(
|
states->next_state = (int *) calloc(
|
||||||
(size_t) (states->depth + 1), sizeof(int));
|
(size_t) (states->depth + 1), sizeof(int));
|
||||||
if (states->state == (int *) NULL ||
|
if (states->state == (int *) NULL ||
|
||||||
states->bits == (short *) NULL ||
|
states->bits == (short *) NULL ||
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,29 @@
|
||||||
#Directory Version
|
#Directory
|
||||||
adc_bridge 1
|
adc_bridge
|
||||||
dac_bridge 1
|
dac_bridge
|
||||||
d_and 1
|
d_and
|
||||||
d_buffer 1
|
d_buffer
|
||||||
d_dff 1
|
d_dff
|
||||||
d_dlatch 1
|
d_dlatch
|
||||||
d_fdiv 1
|
d_fdiv
|
||||||
d_genlut 2
|
d_genlut
|
||||||
d_inverter 1
|
d_inverter
|
||||||
d_jkff 1
|
d_jkff
|
||||||
d_lut 2
|
d_lut
|
||||||
d_nand 1
|
d_nand
|
||||||
d_nor 1
|
d_nor
|
||||||
d_open_c 1
|
d_open_c
|
||||||
d_open_e 1
|
d_open_e
|
||||||
d_or 1
|
d_or
|
||||||
d_osc 2
|
d_osc
|
||||||
d_pulldown 1
|
d_pulldown
|
||||||
d_pullup 1
|
d_pullup
|
||||||
d_ram 1
|
d_ram
|
||||||
d_source 2
|
d_source
|
||||||
d_srff 1
|
d_srff
|
||||||
d_srlatch 1
|
d_srlatch
|
||||||
d_state 2
|
d_state
|
||||||
d_tff 1
|
d_tff
|
||||||
d_tristate 1
|
d_tristate
|
||||||
d_xnor 1
|
d_xnor
|
||||||
d_xor 1
|
d_xor
|
||||||
|
|
|
||||||
|
|
@ -32,26 +32,14 @@ const SPICEdev * const cmDEVices[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const SPICEdev * const cmDEVices2[] = {
|
|
||||||
#include "cminfo2.h"
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const int cmDEVicesCNT = sizeof(cmDEVices) / sizeof(SPICEdev *) - 1;
|
const int cmDEVicesCNT = sizeof(cmDEVices) / sizeof(SPICEdev *) - 1;
|
||||||
const int cmDEVicesCNT2 = sizeof(cmDEVices2) / sizeof(SPICEdev *) - 1;
|
|
||||||
|
|
||||||
const Evt_Udn_Info_t * const cmEVTudns[] = {
|
const Evt_Udn_Info_t * const cmEVTudns[] = {
|
||||||
#include "udninfo.h"
|
#include "udninfo.h"
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const Evt_Udn_Info_t * const cmEVTudns2[] = {
|
|
||||||
#include "udninfo2.h"
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
const int cmEVTudnCNT = sizeof(cmEVTudns) / sizeof(Evt_Udn_Info_t *) - 1;
|
const int cmEVTudnCNT = sizeof(cmEVTudns) / sizeof(Evt_Udn_Info_t *) - 1;
|
||||||
const int cmEVTudnCNT2 = sizeof(cmEVTudns2) / sizeof(Evt_Udn_Info_t *) - 1;
|
|
||||||
|
|
||||||
// Pointer to core info structure containing pointers to core functions.
|
// Pointer to core info structure containing pointers to core functions.
|
||||||
struct coreInfo_t *coreitf;
|
struct coreInfo_t *coreitf;
|
||||||
|
|
@ -91,40 +79,24 @@ CM_EXPORT void *CMdevs(void)
|
||||||
{
|
{
|
||||||
return (void *) cmDEVices;
|
return (void *) cmDEVices;
|
||||||
}
|
}
|
||||||
CM_EXPORT void *CMdevs2(void)
|
|
||||||
{
|
|
||||||
return (void *) cmDEVices2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This one returns the device count
|
// This one returns the device count
|
||||||
CM_EXPORT void *CMdevNum(void)
|
CM_EXPORT void *CMdevNum(void)
|
||||||
{
|
{
|
||||||
return (void *) &cmDEVicesCNT;
|
return (void *) &cmDEVicesCNT;
|
||||||
}
|
}
|
||||||
CM_EXPORT void *CMdevNum2(void)
|
|
||||||
{
|
|
||||||
return (void *) &cmDEVicesCNT2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This one returns the UDN table
|
// This one returns the UDN table
|
||||||
CM_EXPORT void *CMudns(void)
|
CM_EXPORT void *CMudns(void)
|
||||||
{
|
{
|
||||||
return (void *) cmEVTudns;
|
return (void *) cmEVTudns;
|
||||||
}
|
}
|
||||||
CM_EXPORT void *CMudns2(void)
|
|
||||||
{
|
|
||||||
return (void *) cmEVTudns2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This one returns the UDN count
|
// This one returns the UDN count
|
||||||
CM_EXPORT void *CMudnNum(void)
|
CM_EXPORT void *CMudnNum(void)
|
||||||
{
|
{
|
||||||
return (void *) &cmEVTudnCNT;
|
return (void *) &cmEVTudnCNT;
|
||||||
}
|
}
|
||||||
CM_EXPORT void *CMudnNum2(void)
|
|
||||||
{
|
|
||||||
return (void *) &cmEVTudnCNT2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This one returns the pointer to the pointer to the core interface structure
|
// This one returns the pointer to the pointer to the core interface structure
|
||||||
CM_EXPORT void *CMgetCoreItfPtr(void) {
|
CM_EXPORT void *CMgetCoreItfPtr(void) {
|
||||||
|
|
@ -526,11 +498,26 @@ cm_message_printf(const char *fmt, ...)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p == buf)
|
/* Allocate a larger buffer to prepare for another format attempt */
|
||||||
p = tmalloc((size_t) size * sizeof(char));
|
{
|
||||||
else
|
void *p_new;
|
||||||
p = trealloc(p, (size_t) size * sizeof(char));
|
if (p == buf) { /* was using buffer from stack */
|
||||||
}
|
p_new = malloc((size_t) size * sizeof(char));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p_new = realloc(p, (size_t) size * sizeof(char));
|
||||||
|
}
|
||||||
|
if (p_new == NULL) {
|
||||||
|
/* allocation failure, so just send the format string */
|
||||||
|
(void) cm_message_send(fmt);
|
||||||
|
if (p != buf) {
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
p = (char *) p_new; /* give new allocation to p */
|
||||||
|
}
|
||||||
|
} /* end of loop formatting message */
|
||||||
|
|
||||||
rv = cm_message_send(p);
|
rv = cm_message_send(p);
|
||||||
if (p != buf)
|
if (p != buf)
|
||||||
|
|
@ -542,48 +529,6 @@ cm_message_printf(const char *fmt, ...)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**** V E R S I O N 2 A D D I T I O N S ***/
|
|
||||||
/* Declared in cmproto.h */
|
|
||||||
const char *ngspice_version(void)
|
|
||||||
{
|
|
||||||
return (*coreitf->dllitf_ngspice_version)();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wrapper functions around interface function pointers that are used to get
|
|
||||||
* access to "raw" malloc(), calloc(), and realloc() under mutex protection
|
|
||||||
* when necessary */
|
|
||||||
/* Declared in cmproto.h */
|
|
||||||
void *tmalloc_raw(size_t s)
|
|
||||||
{
|
|
||||||
return (*coreitf->dllitf_tmalloc_raw)(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Declared in cmproto.h */
|
|
||||||
void *tcalloc_raw(size_t n, size_t s)
|
|
||||||
{
|
|
||||||
return (*coreitf->dllitf_tcalloc_raw)(n, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Declared in cmproto.h */
|
|
||||||
void *trealloc_raw(void *ptr, size_t s)
|
|
||||||
{
|
|
||||||
return (*coreitf->dllitf_trealloc_raw)(ptr, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Declared in cmproto.h */
|
|
||||||
char *tstrdup(const char *sz_in)
|
|
||||||
{
|
|
||||||
return (*coreitf->dllitf_tstrdup)(sz_in);
|
|
||||||
} /* end of function tstrdup */
|
|
||||||
|
|
||||||
/* Declared in cmproto.h */
|
|
||||||
char *tstrdup_raw(const char *sz_in)
|
|
||||||
{
|
|
||||||
return (*coreitf->dllitf_tstrdup_raw)(sz_in);
|
|
||||||
} /* end of function tstrdup_raw */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fopen_with_path()
|
fopen_with_path()
|
||||||
Opens an input file <infile>. Called from d_state, file_source, d_source.
|
Opens an input file <infile>. Called from d_state, file_source, d_source.
|
||||||
|
|
@ -592,8 +537,6 @@ Then searches for (and opens) <infile> an a sequence from
|
||||||
Infile_Path/<infile>
|
Infile_Path/<infile>
|
||||||
NGSPICE_INPUT_DIR/<infile>, where the path is given by the environmental variable
|
NGSPICE_INPUT_DIR/<infile>, where the path is given by the environmental variable
|
||||||
<infile>, where the path is the current directory
|
<infile>, where the path is the current directory
|
||||||
|
|
||||||
Requires version 2 due to DSTRING, which uses raw allocations.
|
|
||||||
*/
|
*/
|
||||||
#define DFLT_BUF_SIZE 256
|
#define DFLT_BUF_SIZE 256
|
||||||
/* Declared in cmproto.h */
|
/* Declared in cmproto.h */
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ void spice2poly (ARGS)
|
||||||
if(INIT) {
|
if(INIT) {
|
||||||
Mif_Inst_Var_Data_t *p = STATIC_VAR_INST(acgains);
|
Mif_Inst_Var_Data_t *p = STATIC_VAR_INST(acgains);
|
||||||
p -> size = num_inputs;
|
p -> size = num_inputs;
|
||||||
if ((p->element = (Mif_Value_t *) tmalloc_raw((size_t) num_inputs *
|
if ((p->element = (Mif_Value_t *) malloc((size_t) num_inputs *
|
||||||
sizeof(Mif_Value_t))) == (Mif_Value_t *) NULL) {
|
sizeof(Mif_Value_t))) == (Mif_Value_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate element array "
|
cm_message_send("Unable to allocate element array "
|
||||||
"in spice2poly()");
|
"in spice2poly()");
|
||||||
|
|
@ -139,7 +139,7 @@ void spice2poly (ARGS)
|
||||||
|
|
||||||
/* Get input values and coefficients to local storage for faster access */
|
/* Get input values and coefficients to local storage for faster access */
|
||||||
|
|
||||||
if ((in = (double *) tmalloc_raw((size_t) num_inputs *
|
if ((in = (double *) malloc((size_t) num_inputs *
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_send("Unable to allocate array for inputs "
|
cm_message_send("Unable to allocate array for inputs "
|
||||||
"in spice2poly()");
|
"in spice2poly()");
|
||||||
|
|
@ -150,7 +150,7 @@ void spice2poly (ARGS)
|
||||||
|
|
||||||
num_coefs = PARAM_SIZE(coef);
|
num_coefs = PARAM_SIZE(coef);
|
||||||
|
|
||||||
if ((coef = (double *) tmalloc_raw((size_t) num_coefs *
|
if ((coef = (double *) malloc((size_t) num_coefs *
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_send("Unable to allocate array for coef "
|
cm_message_send("Unable to allocate array for coef "
|
||||||
"in spice2poly()");
|
"in spice2poly()");
|
||||||
|
|
@ -161,7 +161,7 @@ void spice2poly (ARGS)
|
||||||
|
|
||||||
|
|
||||||
/* Allocate the array of exponents used in computing the poly terms */
|
/* Allocate the array of exponents used in computing the poly terms */
|
||||||
if ((exp = (int *) tmalloc_raw((size_t) num_inputs *
|
if ((exp = (int *) malloc((size_t) num_inputs *
|
||||||
sizeof(int))) == (int *) NULL) {
|
sizeof(int))) == (int *) NULL) {
|
||||||
cm_message_send("Unable to allocate array for exp "
|
cm_message_send("Unable to allocate array for exp "
|
||||||
"in spice2poly()");
|
"in spice2poly()");
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
#Directory Version
|
#Directory
|
||||||
icm_spice2poly 1
|
icm_spice2poly
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ sf_alloc(int n /* number of elements */,
|
||||||
|
|
||||||
/* Use calloc so that any internal allocations will be set to NULL to
|
/* Use calloc so that any internal allocations will be set to NULL to
|
||||||
* facilitate error recovery */
|
* facilitate error recovery */
|
||||||
if ((ptr = tcalloc_raw(n, size)) == NULL) {
|
if ((ptr = calloc(n, size)) == NULL) {
|
||||||
cm_message_printf("%s: cannot allocate %zd bytes : ",
|
cm_message_printf("%s: cannot allocate %zd bytes : ",
|
||||||
__FILE__, n * size);
|
__FILE__, n * size);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
#Directory version
|
#Directory
|
||||||
table2D 2
|
table2D
|
||||||
table3D 2
|
table3D
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ char *CNVgettok(char **s)
|
||||||
|
|
||||||
/* allocate space big enough for the whole string */
|
/* allocate space big enough for the whole string */
|
||||||
|
|
||||||
if ((buf = (char *) tmalloc_raw(strlen(*s) + 1)) == (char *) NULL) {
|
if ((buf = (char *) malloc(strlen(*s) + 1)) == (char *) NULL) {
|
||||||
cm_message_printf("cannot allocate buffer to tokenize");
|
cm_message_printf("cannot allocate buffer to tokenize");
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +74,7 @@ char *CNVgettok(char **s)
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
char * const ret_str = (char *) tmalloc_raw(strlen(buf) + 1);
|
char * const ret_str = (char *) malloc(strlen(buf) + 1);
|
||||||
if (ret_str == (char *) NULL) {
|
if (ret_str == (char *) NULL) {
|
||||||
return (char *) NULL;
|
return (char *) NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -303,7 +303,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
|
|
||||||
|
|
||||||
/* Allocate static storage for *loc */
|
/* Allocate static storage for *loc */
|
||||||
if ((loc = (Table2_Data_t *) tcalloc_raw(1,
|
if ((loc = (Table2_Data_t *) calloc(1,
|
||||||
sizeof(Table2_Data_t))) == (Table2_Data_t *) NULL) {
|
sizeof(Table2_Data_t))) == (Table2_Data_t *) NULL) {
|
||||||
cm_message_printf("cannot allocate memory for lookup table.");
|
cm_message_printf("cannot allocate memory for lookup table.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -319,7 +319,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
if (!fp) { /* Standard open attempt failed */
|
if (!fp) { /* Standard open attempt failed */
|
||||||
const char * const lbuffer = getenv("NGSPICE_INPUT_DIR");
|
const char * const lbuffer = getenv("NGSPICE_INPUT_DIR");
|
||||||
if (lbuffer && *lbuffer) {
|
if (lbuffer && *lbuffer) {
|
||||||
char * const p = (char *) tmalloc_raw(strlen(lbuffer) +
|
char * const p = (char *) malloc(strlen(lbuffer) +
|
||||||
strlen(DIR_PATHSEP) +
|
strlen(DIR_PATHSEP) +
|
||||||
strlen(filename) + 1);
|
strlen(filename) + 1);
|
||||||
if (p == (char *) NULL) {
|
if (p == (char *) NULL) {
|
||||||
|
|
@ -356,9 +356,9 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create string to hold the whole file */
|
/* create string to hold the whole file */
|
||||||
cFile = tcalloc_raw(lFileLen + 1, sizeof(char));
|
cFile = calloc(lFileLen + 1, sizeof(char));
|
||||||
/* create another string long enough for file manipulation */
|
/* create another string long enough for file manipulation */
|
||||||
cThisLine = tcalloc_raw(lFileLen + 1, sizeof(char));
|
cThisLine = calloc(lFileLen + 1, sizeof(char));
|
||||||
if (cFile == NULL || cThisLine == NULL) {
|
if (cFile == NULL || cThisLine == NULL) {
|
||||||
cm_message_printf("Insufficient memory to read file %s",
|
cm_message_printf("Insufficient memory to read file %s",
|
||||||
filename);
|
filename);
|
||||||
|
|
@ -419,7 +419,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
cnv_get_spice_value(cThisLinePtr, &tmp);
|
cnv_get_spice_value(cThisLinePtr, &tmp);
|
||||||
loc->ix = ix = (int) tmp;
|
loc->ix = ix = (int) tmp;
|
||||||
/* generate row data structure (x) */
|
/* generate row data structure (x) */
|
||||||
if ((loc->xcol = (double *) tcalloc_raw((size_t) ix,
|
if ((loc->xcol = (double *) calloc((size_t) ix,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate row structure.");
|
cm_message_printf("Unable to allocate row structure.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -430,7 +430,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
cnv_get_spice_value(cThisLinePtr, &tmp);
|
cnv_get_spice_value(cThisLinePtr, &tmp);
|
||||||
loc->iy = iy = (int) tmp;
|
loc->iy = iy = (int) tmp;
|
||||||
/* generate column data structure (y) */
|
/* generate column data structure (y) */
|
||||||
if ((loc->ycol = (double *) tcalloc_raw((size_t) iy,
|
if ((loc->ycol = (double *) calloc((size_t) iy,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate colum structure.");
|
cm_message_printf("Unable to allocate colum structure.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -500,7 +500,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
|
|
||||||
/* create table_data in memory */
|
/* create table_data in memory */
|
||||||
/* data [n2][n1] */
|
/* data [n2][n1] */
|
||||||
if ((loc->table = table_data = (double **) tcalloc_raw((size_t) iy,
|
if ((loc->table = table_data = (double **) calloc((size_t) iy,
|
||||||
sizeof(double *))) == (double **) NULL) {
|
sizeof(double *))) == (double **) NULL) {
|
||||||
cm_message_send("Unable to allocate data table.");
|
cm_message_send("Unable to allocate data table.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -510,7 +510,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < iy; i++) {
|
for (i = 0; i < iy; i++) {
|
||||||
if ((table_data[i] = (double *) tcalloc_raw((size_t) ix,
|
if ((table_data[i] = (double *) calloc((size_t) ix,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate data table "
|
cm_message_printf("Unable to allocate data table "
|
||||||
"row %d", i + 1);
|
"row %d", i + 1);
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
|
|
||||||
|
|
||||||
/* Allocate static storage for *loc */
|
/* Allocate static storage for *loc */
|
||||||
if ((loc = (Table3_Data_t *) tcalloc_raw(1,
|
if ((loc = (Table3_Data_t *) calloc(1,
|
||||||
sizeof(Table3_Data_t))) == (Table3_Data_t *) NULL) {
|
sizeof(Table3_Data_t))) == (Table3_Data_t *) NULL) {
|
||||||
cm_message_printf("cannot allocate memory for lookup table.");
|
cm_message_printf("cannot allocate memory for lookup table.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -347,7 +347,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
if (!fp) { /* Standard open attempt failed */
|
if (!fp) { /* Standard open attempt failed */
|
||||||
const char * const lbuffer = getenv("NGSPICE_INPUT_DIR");
|
const char * const lbuffer = getenv("NGSPICE_INPUT_DIR");
|
||||||
if (lbuffer && *lbuffer) {
|
if (lbuffer && *lbuffer) {
|
||||||
char * const p = (char *) tmalloc_raw(strlen(lbuffer) +
|
char * const p = (char *) malloc(strlen(lbuffer) +
|
||||||
strlen(DIR_PATHSEP) +
|
strlen(DIR_PATHSEP) +
|
||||||
strlen(filename) + 1);
|
strlen(filename) + 1);
|
||||||
if (p == (char *) NULL) {
|
if (p == (char *) NULL) {
|
||||||
|
|
@ -384,9 +384,9 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create string to hold the whole file */
|
/* create string to hold the whole file */
|
||||||
cFile = tcalloc_raw(lFileLen + 1, sizeof(char));
|
cFile = calloc(lFileLen + 1, sizeof(char));
|
||||||
/* create another string long enough for file manipulation */
|
/* create another string long enough for file manipulation */
|
||||||
cThisLine = tcalloc_raw(lFileLen + 1, sizeof(char));
|
cThisLine = calloc(lFileLen + 1, sizeof(char));
|
||||||
if (cFile == NULL || cThisLine == NULL) {
|
if (cFile == NULL || cThisLine == NULL) {
|
||||||
cm_message_printf("Insufficient memory to read file %s",
|
cm_message_printf("Insufficient memory to read file %s",
|
||||||
filename);
|
filename);
|
||||||
|
|
@ -447,7 +447,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
cnv_get_spice_value(cThisLinePtr, &tmp);
|
cnv_get_spice_value(cThisLinePtr, &tmp);
|
||||||
loc->ix = ix = (int) tmp;
|
loc->ix = ix = (int) tmp;
|
||||||
/* generate row data structure (x) */
|
/* generate row data structure (x) */
|
||||||
if ((loc->xcol = (double *) tcalloc_raw((size_t) ix,
|
if ((loc->xcol = (double *) calloc((size_t) ix,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate row structure.");
|
cm_message_printf("Unable to allocate row structure.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -458,7 +458,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
cnv_get_spice_value(cThisLinePtr, &tmp);
|
cnv_get_spice_value(cThisLinePtr, &tmp);
|
||||||
loc->iy = iy = (int) tmp;
|
loc->iy = iy = (int) tmp;
|
||||||
/* generate column data structure (y) */
|
/* generate column data structure (y) */
|
||||||
if ((loc->ycol = (double *) tcalloc_raw((size_t) iy,
|
if ((loc->ycol = (double *) calloc((size_t) iy,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate colum structure.");
|
cm_message_printf("Unable to allocate colum structure.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -469,7 +469,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
cnv_get_spice_value(cThisLinePtr, &tmp);
|
cnv_get_spice_value(cThisLinePtr, &tmp);
|
||||||
loc->iz = iz = (int) tmp;
|
loc->iz = iz = (int) tmp;
|
||||||
/* generate column data structure (z) */
|
/* generate column data structure (z) */
|
||||||
if ((loc->zcol = (double *) tcalloc_raw((size_t) iz,
|
if ((loc->zcol = (double *) calloc((size_t) iz,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate \"z\" structure.");
|
cm_message_printf("Unable to allocate \"z\" structure.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -558,7 +558,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
|
|
||||||
/* create table_data in memory */
|
/* create table_data in memory */
|
||||||
/* data [n3][n2][n1] */
|
/* data [n3][n2][n1] */
|
||||||
if ((loc->table = table_data = (double ***) tcalloc_raw((size_t) iz,
|
if ((loc->table = table_data = (double ***) calloc((size_t) iz,
|
||||||
sizeof(double **))) == (double ***) NULL) {
|
sizeof(double **))) == (double ***) NULL) {
|
||||||
cm_message_send("Unable to allocate data table.");
|
cm_message_send("Unable to allocate data table.");
|
||||||
xrc = -1;
|
xrc = -1;
|
||||||
|
|
@ -568,7 +568,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < iz; i++) {
|
for (i = 0; i < iz; i++) {
|
||||||
if ((table_data[i] = (double **) tcalloc_raw((size_t) iy,
|
if ((table_data[i] = (double **) calloc((size_t) iy,
|
||||||
sizeof(double *))) == (double **) NULL) {
|
sizeof(double *))) == (double **) NULL) {
|
||||||
cm_message_printf("Unable to allocate data table "
|
cm_message_printf("Unable to allocate data table "
|
||||||
"z=%d",
|
"z=%d",
|
||||||
|
|
@ -577,7 +577,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
|
||||||
goto EXITPOINT;
|
goto EXITPOINT;
|
||||||
}
|
}
|
||||||
for (j = 0; j < iy; j++) {
|
for (j = 0; j < iy; j++) {
|
||||||
if ((table_data[i][j] = (double *) tcalloc_raw((size_t) ix,
|
if ((table_data[i][j] = (double *) calloc((size_t) ix,
|
||||||
sizeof(double))) == (double *) NULL) {
|
sizeof(double))) == (double *) NULL) {
|
||||||
cm_message_printf("Unable to allocate data table "
|
cm_message_printf("Unable to allocate data table "
|
||||||
"z=%d y=%d",
|
"z=%d y=%d",
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
#Directory Version
|
#Directory
|
||||||
aswitch 1
|
aswitch
|
||||||
capacitor 1
|
capacitor
|
||||||
cmeter 1
|
cmeter
|
||||||
core 1
|
core
|
||||||
inductor 1
|
inductor
|
||||||
lcouple 1
|
lcouple
|
||||||
lmeter 1
|
lmeter
|
||||||
potentiometer 1
|
potentiometer
|
||||||
zener 2
|
zener
|
||||||
memristor 1
|
memristor
|
||||||
sidiode 1
|
sidiode
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ void cm_sidiode(ARGS) /* structure holding parms,
|
||||||
double grev, goff, gon, Va, Vb, Vc, Vd, hEpsilon, hRevepsilon;
|
double grev, goff, gon, Va, Vb, Vc, Vd, hEpsilon, hRevepsilon;
|
||||||
|
|
||||||
/* allocate static storage for *loc */
|
/* allocate static storage for *loc */
|
||||||
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
|
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
|
||||||
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
||||||
cm_message_send("Unable to allocate locdata in cm_sidiode().");
|
cm_message_send("Unable to allocate locdata in cm_sidiode().");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ void cm_zener(ARGS) /* structure holding parms,
|
||||||
|
|
||||||
/* Allocate storage for frequencies */
|
/* Allocate storage for frequencies */
|
||||||
if ((previous_voltage = (double *) (STATIC_VAR(previous_voltage) =
|
if ((previous_voltage = (double *) (STATIC_VAR(previous_voltage) =
|
||||||
tmalloc_raw(sizeof(double)))) == (double *) NULL) {
|
malloc(sizeof(double)))) == (double *) NULL) {
|
||||||
cm_message_send("Unable to allocate memory for previous "
|
cm_message_send("Unable to allocate memory for previous "
|
||||||
"voltage in cm_zener()");
|
"voltage in cm_zener()");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#Directory Version
|
#Directory
|
||||||
d_to_real 1
|
d_to_real
|
||||||
real_delay 1
|
real_delay
|
||||||
real_gain 1
|
real_gain
|
||||||
real_to_v 1
|
real_to_v
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue