Rewrite cmpp

This commit is contained in:
Jim Monte 2020-04-25 19:26:20 +02:00 committed by Holger Vogt
parent 84b5e6b671
commit 00fa875b9e
5 changed files with 89 additions and 390 deletions

View File

@ -17,15 +17,11 @@ cmpp_SOURCES = main.c cmpp.h file_buffer.c file_buffer.h\
mod_lex.l mod_yacc.y mod_yacc_y.h
if WINGUI
cmpp_LDADD = -lshlwapi
cmpp_LDADD = -lShlwapi
endif
if WINCONSOLE
cmpp_LDADD = -lshlwapi
endif
if SHWIN
cmpp_LDADD = -lshlwapi
cmpp_LDADD = -lShlwapi
endif
mod_lex.c : mod_lex.l

View File

@ -14,21 +14,12 @@
static int fb_fill(FILEBUF *p_fb);
static int fbget_quoted_unescaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fbget_quoted_unescaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static size_t fb_make_space_at_end(FILEBUF *p_fb);
static int fbget_quoted_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fbget_quoted_escaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
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 fbget_quoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fbget_quoted_escaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fbget_unquoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fb_skip_to_eol(FILEBUF *p_fb);
static int fb_skip_whitespace(FILEBUF *p_fb);
@ -147,12 +138,7 @@ int fbclose(FILEBUF *p_fb)
*
* Parameters
* p_fb: FILEBUF pointer initialized using fbopen()
* n_type_wanted: number of desired type conversions for data from highest
* 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
* p_fbstr: Address of an FBSTRING structure to receive the data
*
* Return codes
* +1: EOF reached
@ -180,9 +166,7 @@ int fbclose(FILEBUF *p_fb)
* 0: Normal
* -1: Error
*/
int fbget(FILEBUF *p_fb,
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
int fbget(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Test for existing EOF */
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 */
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 */
return fbget_unquoted_string(p_fb, n_type_wanted, p_type_wanted,
p_type_found, p_fbobj);
return fbget_unquoted_string(p_fb, p_fbstr);
} /* 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
* 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. */
static int fbget_quoted_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fbget_quoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Advance past the opening quote to the true start of the string */
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
* string "" can be written here */
*(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 */
} /* 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
* 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 */
/* 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 */
int fbget_quoted_unescaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
int fbget_quoted_unescaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Step through characters until end or escape */
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 */
*(p_fb->p_obj_end = p_data_cur) = '\0';
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 */
/* After an escape, data must be moved to fill in the gap
* left by the escape character */
p_fb->p_data_cur = p_data_cur; /* Reprocess the escape */
return fbget_quoted_escaped_string(p_fb,
p_type_found, p_fbobj);
return fbget_quoted_escaped_string(p_fb, p_fbstr);
}
/* Else the character is part of the quoted string */
} /* 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
* the buffer where the read would have gone. */
*(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_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
* entry */
static int fbget_quoted_escaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fbget_quoted_escaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Step through characters until end */
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 */
p_fb->p_data_cur = p_data_src + 1;
*(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 */
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
* avoid the moves */
if (!f_escape_in_progress) {
return fbget_quoted_unescaped_string(p_fb, p_type_found,
p_fbobj);
return fbget_quoted_unescaped_string(p_fb, p_fbstr);
}
/* 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
* the buffer where the read would have gone. */
*(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_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 */
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 fbget_unquoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Save the start of the string as the current position */
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_data_cur = p_data_cur + 1; /* 1st char past string */
p_fb->f_skip_to_eol = map_cur < 0;
return fb_return_obj(p_fb, n_type_wanted, p_type_wanted,
p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
/* Else more of the string */
} /* 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
* the buffer where the read would have gone. */
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
return fb_return_obj(p_fb, n_type_wanted, p_type_wanted,
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_end = p_fb->p_data_end;
@ -482,7 +456,7 @@ static size_t fb_make_space_at_end(FILEBUF *p_fb)
/* Shift data in use to the front of the buffer if not already */
if (p_dst != p_src) { /* object is not at start of buffer */
const size_t n = p_fb->p_data_end - p_src;
const size_t n = (size_t) (p_fb->p_data_end - p_src);
if (n > 0) { /* Will be 0 if skipping whitespace and comments */
(void) memmove(p_dst, p_src, n);
}
@ -528,7 +502,7 @@ static size_t fb_make_space_at_end(FILEBUF *p_fb)
}
}
return p_fb->p_buf_end - p_fb->p_data_end;
return (size_t) (p_fb->p_buf_end - p_fb->p_data_end);
} /* end of function fb_make_space_at_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 */
static int fb_return_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
const char *p_data_start =
p_fbobj->str_value.sz = p_fb->p_obj_start;
p_fbobj->str_value.n_char = p_fb->p_obj_end - p_data_start;
*p_type_found = BUF_TYPE_STRING;
const char *p_data_start = p_fbstr->sz = p_fb->p_obj_start;
p_fbstr->n_char = (size_t) (p_fb->p_obj_end - p_data_start);
return 0;
} /* end of function fb_return_string */

View File

@ -10,14 +10,6 @@ typedef struct Filebuf_len_str {
char *sz; /* Start of string */
} 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 */
typedef struct Filebuf {
FILE *fp; /* handle to file */
@ -50,8 +42,7 @@ typedef enum FBtype {
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,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
int fbget(FILEBUF *p_fb, FBSTRING *p_fbstr);
int fbclose(FILEBUF *fbp);

View File

@ -67,14 +67,12 @@ typedef struct {
char *path_name; /* Pathname read from model path file */
char *spice_name; /* Name of model from ifspec.ifs */
char *cfunc_name; /* Name of C fcn from ifspec.ifs */
unsigned int version; /* version of the code model */
} Model_Info_t;
typedef struct {
char *path_name; /* Pathname read from udn path file */
char *node_name; /* Name of node type */
unsigned int version; /* version of the code model */
} 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 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_CMinfo2(int num_models, Model_Info_t *model_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_UDNinfo2(int num_nodes, Node_Info_t *node_info);
static int write_objects_inc(int num_models, Model_Info_t *model_info,
int num_nodes, Node_Info_t *node_info);
static int read_udn_type_name(const char *path, char **node_name);
@ -192,10 +188,6 @@ void preprocess_lst_files(void)
if(status != 0) {
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 */
status = write_UDNextrn(num_nodes, node_info);
@ -208,10 +200,6 @@ void preprocess_lst_files(void)
if(status != 0) {
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 */
/* user-defined node functions with the simulator */
@ -223,10 +211,10 @@ void preprocess_lst_files(void)
/* Free allocations */
if (model_info != (Model_Info_t *) NULL) {
free_model_info(num_models, model_info);
free_model_info((int) num_models, model_info);
}
if (node_info != (Node_Info_t *) NULL) {
free_node_info(num_nodes, node_info);
free_node_info((int) num_nodes, node_info);
}
} /* end of function preprocess_lst_files */
@ -249,40 +237,10 @@ int output_paths_from_lst_file(const char *filename)
goto EXITPOINT;
}
bool f_have_path = false; /* do not have a path to store */
FBTYPE fbtype;
FBOBJ fbobj;
FBSTRING fbstr;
for ( ; ; ) { /* Read items until end of file */
/* Get the next path if not found yet */
if (!f_have_path) {
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);
const int rc = fbget(fbp, &fbstr);
if (rc != 0) {
if (rc == -1) { /* Error */
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 */
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
f_have_path = false;
}
else { /* it was a string, so it is the next path */
f_have_path = true;
/* Remove trailing slash if appended to path */
trim_slash(&fbstr.n_char, fbstr.sz);
/* 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", 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 */
EXITPOINT:
@ -377,27 +337,23 @@ static int read_modpath(
}
n_model_info_alloc = N_MODEL_INIT;
bool f_have_path = false; /* do not have a path to store */
FBTYPE fbtype;
FBOBJ fbobj;
FBSTRING fbstr;
for ( ; ; ) { /* Read items until end of file */
/* Get the next path if not found yet */
if (!f_have_path) {
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 */
const int rc = fbget(fbp, &fbstr);
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);
}
/* Remove trailing slash if appended to path */
trim_slash(&fbstr.n_char, fbstr.sz);
/* Enlarge model array if full */
if (n_model_info_alloc == n_model_info) {
@ -417,44 +373,18 @@ static int read_modpath(
n_model_info;
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");
xrc = -1;
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->cfunc_name = (char *) NULL;
/* Must set before returning due to EOF. */
p_model_info_cur->version = 1;
++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 */
EXITPOINT:
@ -472,12 +402,12 @@ EXITPOINT:
/* If error, free model info */
if (xrc != 0) {
free_model_info(n_model_info, p_model_info);
free_model_info((int) n_model_info, p_model_info);
n_model_info = 0;
p_model_info = (Model_Info_t *) NULL;
}
*p_num_model_info = n_model_info;
*p_num_model_info = (int) n_model_info;
*pp_model_info = p_model_info;
return xrc;
@ -552,29 +482,24 @@ static int read_udnpath(
}
n_node_info_alloc = N_NODE_INIT;
bool f_have_path = false; /* do not have a path to store */
FBTYPE fbtype;
FBOBJ fbobj;
FBSTRING fbstr;
for ( ; ; ) { /* Read items until end of file */
/* Get the next path if not found yet */
if (!f_have_path) {
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);
}
const int rc = fbget(fbp, &fbstr);
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(&fbstr.n_char, fbstr.sz);
/* Enlarge node array if full */
if (n_node_info_alloc == n_node_info) {
@ -594,44 +519,14 @@ static int read_udnpath(
n_node_info;
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");
xrc = -1;
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;
/* 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 */
EXITPOINT:
@ -649,12 +544,12 @@ EXITPOINT:
/* If error, free node info */
if (xrc != 0) {
free_node_info(n_node_info, p_node_info);
free_node_info((int) n_node_info, p_node_info);
n_node_info = 0;
p_node_info = (Node_Info_t *) NULL;
}
*p_num_node_info = n_node_info;
*p_num_node_info = (int) n_node_info;
*pp_node_info = p_node_info;
return xrc;
@ -946,8 +841,8 @@ static int check_uniqueness(
}
/* Sizes of models and nodes */
const unsigned int n_model = (unsigned int) numSPICEmodels + num_models;
const unsigned int n_node = (unsigned int) numUDNidentifiers + num_nodes;
const unsigned int n_model = (unsigned int) (numSPICEmodels + num_models);
const unsigned int n_node = (unsigned int) (numUDNidentifiers + num_nodes);
const unsigned int n_ks = n_model > n_node ? n_model : n_node;
/* Allocate structure to compare */
@ -995,8 +890,8 @@ static int check_uniqueness(
}
/* Test for duplicates */
f_have_duplicate |= test_for_duplicates(num_models, p_ks,
&report_error_function_name);
f_have_duplicate |= test_for_duplicates((unsigned int) num_models,
p_ks, &report_error_function_name);
}
}
@ -1230,10 +1125,7 @@ static int write_CMinfo(
/* 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 == 1) {
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
}
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
}
/* 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 */
for(i = 0; i < num_nodes; 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);
}
}
/* 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);
}
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
}
/* Close the file and return */
@ -1589,14 +1394,14 @@ static int read_udn_type_name(
c = fgetc(fp);
if(c == '"') {
found = true;
if (i >= sizeof name) {
if (i >= (int) sizeof name) {
print_error("name too long");
exit(1);
}
name[i] = '\0';
}
else if(c != EOF) {
if (i > sizeof name) {
if (i > (int) sizeof name) {
print_error("name too long");
exit(1);
}

View File

@ -1220,7 +1220,7 @@ static char *value_to_str(Data_Type_t type, Value_t value)
/* be careful, the string could conceivably be very long... */
str_len = (int) strlen(value.svalue);
if ((str_len + BASE_STR_LEN) > max_len) {
size_t n_byte_alloc = max_len + str_len + 1;
size_t n_byte_alloc = (size_t) (max_len + str_len + 1);
void * const p = realloc(str, n_byte_alloc);
if (p == NULL) {
(void) fprintf(stderr, "Unable to resize string "