File path built more efficiently and now allows an arbitrary length. Prevented strdup() of NULL if path too long. Similarly prevented fopen with a NULL file name. Added function to determine Windows absolute paths properly. Fixed numerous issues that were caused by including Windows system header due to conflicting names. Generally a CMPP_ prefix was added as a "namespace". Also used the standard C bool type instead of defining one.

This commit is contained in:
Jim Monte 2019-12-23 22:40:56 -05:00 committed by Holger Vogt
parent affa528cb5
commit 344fa243bd
12 changed files with 397 additions and 382 deletions

View File

@ -16,6 +16,14 @@ cmpp_SOURCES = main.c cmpp.h \
ifs_lex.l ifs_yacc.y ifs_yacc_y.h \
mod_lex.l mod_yacc.y mod_yacc_y.h
if WINGUI
cmpp_LDADD = -lShlwapi
endif
if WINCONSOLE
cmpp_LDADD = -lShlwapi
endif
mod_lex.c : mod_lex.l
$(am__skiplex) $(LEXCOMPILE) -o $@ $<

View File

@ -38,6 +38,7 @@ NON-STANDARD FEATURES
============================================================================*/
#include <stdbool.h>
#include <stdio.h>
#define IFSPEC_FILENAME "ifspec.ifs"
@ -47,6 +48,7 @@ NON-STANDARD FEATURES
#ifdef _MSC_VER
#include <io.h>
#include <string.h>
#define strdup _strdup
#define unlink _unlink
#define isatty _isatty
@ -55,15 +57,6 @@ NON-STANDARD FEATURES
/* *********************************************************************** */
typedef enum {
OK, /* Returned with no error */
ERROR, /* Returned with error */
} Status_t;
#define GET_IFS_TABLE 0 /* Read the entire ifs table */
#define GET_IFS_NAME 1 /* Get the C function name out of the table only */
@ -76,24 +69,14 @@ typedef enum {
/* Structures used by parser to check for valid connections/parameters */
/* ******************************************************************** */
/*
* The boolean type
*/
typedef enum {
FALSE,
TRUE,
} Boolean_t;
/*
* The direction of a connector
*/
typedef enum {
IN,
OUT,
INOUT,
CMPP_IN,
CMPP_OUT,
CMPP_INOUT,
} Dir_t;
@ -122,14 +105,13 @@ typedef enum {
*/
typedef enum {
BOOLEAN,
INTEGER,
REAL,
COMPLEX,
STRING,
POINTER, /* NOTE: POINTER should not be used for Parameters - only
* Static_Vars - this is enforced by the cmpp.
*/
CMPP_BOOLEAN,
CMPP_INTEGER,
CMPP_REAL,
CMPP_COMPLEX,
CMPP_STRING,
CMPP_POINTER, /* NOTE: CMPP_POINTER should not be used for Parameters -
* only Static_Vars - this is enforced by the cmpp. */
} Data_Type_t;
@ -157,7 +139,7 @@ typedef struct {
typedef struct {
Boolean_t bvalue; /* For BOOLEAN parameters */
bool bvalue; /* For BOOLEAN parameters */
int ivalue; /* For INTEGER parameters */
double rvalue; /* For REAL parameters */
Complex_t cvalue; /* For COMPLEX parameters */
@ -198,14 +180,14 @@ typedef struct {
int num_allowed_types; /* The size of the allowed type arrays */
Port_Type_t *allowed_port_type; /* Array of allowed types */
char **allowed_type; /* Array of allowed types in string form */
Boolean_t is_array; /* True if connection is an array */
Boolean_t has_conn_ref; /* True if there is associated with an array conn */
bool is_array; /* True if connection is an array */
bool has_conn_ref; /* True if there is associated with an array conn */
int conn_ref; /* Subscript of the associated array conn */
Boolean_t has_lower_bound; /* True if there is an array size lower bound */
bool has_lower_bound; /* True if there is an array size lower bound */
int lower_bound; /* Array size lower bound */
Boolean_t has_upper_bound; /* True if there is an array size upper bound */
bool has_upper_bound; /* True if there is an array size upper bound */
int upper_bound; /* Array size upper bound */
Boolean_t null_allowed; /* True if null is allowed for this connection */
bool null_allowed; /* True if null is allowed for this connection */
} Conn_Info_t;
@ -221,20 +203,20 @@ typedef struct {
char *name; /* Name of this parameter */
char *description; /* Description of this parameter */
Data_Type_t type; /* Data type, e.g. REAL, INTEGER, ... */
Boolean_t has_default; /* True if there is a default value */
bool has_default; /* True if there is a default value */
Value_t default_value; /* The default value */
Boolean_t has_lower_limit; /* True if there is a lower limit */
bool has_lower_limit; /* True if there is a lower limit */
Value_t lower_limit; /* The lower limit for this parameter */
Boolean_t has_upper_limit; /* True if there is a upper limit */
bool has_upper_limit; /* True if there is a upper limit */
Value_t upper_limit; /* The upper limit for this parameter */
Boolean_t is_array; /* True if parameter is an array */
Boolean_t has_conn_ref; /* True if there is associated with an array conn */
bool is_array; /* True if parameter is an array */
bool has_conn_ref; /* True if there is associated with an array conn */
int conn_ref; /* Subscript of the associated array conn */
Boolean_t has_lower_bound; /* True if there is an array size lower bound */
bool has_lower_bound; /* True if there is an array size lower bound */
int lower_bound; /* Array size lower bound */
Boolean_t has_upper_bound; /* True if there is an array size upper bound */
bool has_upper_bound; /* True if there is an array size upper bound */
int upper_bound; /* Array size upper bound */
Boolean_t null_allowed; /* True if null is allowed for this parameter */
bool null_allowed; /* True if null is allowed for this parameter */
} Param_Info_t;
@ -248,7 +230,7 @@ typedef struct {
char *name; /* Name of this parameter */
char *description; /* Description of this parameter */
Data_Type_t type; /* Data type, e.g. REAL, INTEGER, ... */
Boolean_t is_array; /* True if parameter is an array */
bool is_array; /* True if parameter is an array */
} Inst_Var_Info_t;
@ -294,9 +276,9 @@ void print_error(const char *fmt, ...);
void str_to_lower(char *s);
Status_t read_ifs_file(const char *filename, int mode, Ifs_Table_t *ifs_table);
int read_ifs_file(const char *filename, int mode, Ifs_Table_t *ifs_table);
Status_t write_ifs_c_file(const char *filename, Ifs_Table_t *ifs_table);
int write_ifs_c_file(const char *filename, Ifs_Table_t *ifs_table);
FILE *fopen_cmpp(const char **path_p, const char *mode);

View File

@ -94,21 +94,21 @@ extern double yydval;
extern char *ifs_yytext;
extern int ifs_yylex(void);
Boolean_t parser_just_names;
static Boolean_t saw_model_name;
static Boolean_t saw_function_name;
bool parser_just_names;
static bool saw_model_name;
static bool saw_function_name;
static char *dtype_to_str[] = {
"BOOLEAN", "INTEGER", "REAL", "COMPLEX", "STRING", "POINTER"
};
static Boolean_t did_default_type;
static Boolean_t did_allowed_types;
static bool did_default_type;
static bool did_allowed_types;
static int num_items;
static int item;
static int item_offset;
static Boolean_t num_items_fixed;
static bool num_items_fixed;
Ifs_Table_t *parser_ifs_table;
#define TBL parser_ifs_table
@ -149,21 +149,21 @@ Context_t context;
#define ASSIGN_BOUNDS(struct_name, i) \
if (ITEM_BUF(i).range.is_named) {\
TBL->struct_name[i].has_conn_ref = TRUE;\
TBL->struct_name[i].has_conn_ref = true;\
TBL->struct_name[i].conn_ref = find_conn_ref (ITEM_BUF(i).range.u.name);\
} else {\
TBL->struct_name[i].has_conn_ref = FALSE;\
TBL->struct_name[i].has_conn_ref = false;\
TBL->struct_name[i].has_lower_bound =\
ITEM_BUF(i).range.u.bounds.lower.has_bound;\
TBL->struct_name[i].has_upper_bound =\
ITEM_BUF(i).range.u.bounds.upper.has_bound;\
if (TBL->struct_name[i].has_lower_bound) {\
assert (ITEM_BUF(i).range.u.bounds.lower.bound.kind == INTEGER);\
assert (ITEM_BUF(i).range.u.bounds.lower.bound.kind == CMPP_INTEGER);\
TBL->struct_name[i].lower_bound =\
ITEM_BUF(i).range.u.bounds.lower.bound.u.ivalue;\
}\
if (TBL->struct_name[i].has_upper_bound) {\
assert (ITEM_BUF(i).range.u.bounds.upper.bound.kind == INTEGER);\
assert (ITEM_BUF(i).range.u.bounds.upper.bound.kind == CMPP_INTEGER);\
TBL->struct_name[i].upper_bound =\
ITEM_BUF(i).range.u.bounds.upper.bound.u.ivalue;\
}\
@ -228,7 +228,7 @@ static void check_port_type_direction (Dir_t dir, Port_Type_t port_type)
*/
break;
case VSOURCE_CURRENT:
if (dir != IN) {
if (dir != CMPP_IN) {
yyerror ("Port type `vnam' is only valid for `in' ports");
ifs_num_errors++;
}
@ -237,7 +237,7 @@ static void check_port_type_direction (Dir_t dir, Port_Type_t port_type)
case DIFF_CONDUCTANCE:
case RESISTANCE:
case DIFF_RESISTANCE:
if (dir != INOUT) {
if (dir != CMPP_INOUT) {
yyerror ("Port types `g', `gd', `h', `hd' are only valid for `inout' ports");
ifs_num_errors++;
}
@ -250,7 +250,7 @@ static void check_port_type_direction (Dir_t dir, Port_Type_t port_type)
/*---------------------------------------------------------------------------*/
static void check_dtype_not_pointer (Data_Type_t dtype)
{
if (dtype == POINTER) {
if (dtype == CMPP_POINTER) {
yyerror("Invalid parameter type - POINTER type valid only for STATIC_VARs");
ifs_num_errors++;
}
@ -312,7 +312,7 @@ static void
assign_value (Data_Type_t type, Value_t *dest_value, My_Value_t src_value)
{
char str[200];
if ((type == REAL) && (src_value.kind == INTEGER)) {
if ((type == CMPP_REAL) && (src_value.kind == CMPP_INTEGER)) {
dest_value->rvalue = src_value.u.ivalue;
return;
} else if (type != src_value.kind) {
@ -323,19 +323,19 @@ assign_value (Data_Type_t type, Value_t *dest_value, My_Value_t src_value)
ifs_num_errors++;
}
switch (type) {
case BOOLEAN:
case CMPP_BOOLEAN:
dest_value->bvalue = src_value.u.bvalue;
break;
case INTEGER:
case CMPP_INTEGER:
dest_value->ivalue = src_value.u.ivalue;
break;
case REAL:
case CMPP_REAL:
dest_value->rvalue = src_value.u.rvalue;
break;
case COMPLEX:
case CMPP_COMPLEX:
dest_value->cvalue = src_value.u.cvalue;
break;
case STRING:
case CMPP_STRING:
dest_value->svalue = src_value.u.svalue;
break;
default:
@ -421,7 +421,7 @@ check_end_item_num (void)
}
} else {
num_items = item;
num_items_fixed = TRUE;
num_items_fixed = true;
switch (context.table) {
case TBL_NAME:
break;
@ -439,7 +439,7 @@ check_end_item_num (void)
item = item_offset;
}
#define INIT(n) item = (n); item_offset = (n); num_items = (n); num_items_fixed = FALSE
#define INIT(n) item = (n); item_offset = (n); num_items = (n); num_items_fixed = false
#define ITEM check_item_num()
#define END check_end_item_num()
@ -499,7 +499,7 @@ check_end_item_num (void)
%union {
Ctype_List_t *ctype_list;
Dir_t dir;
Boolean_t bool;
bool btype;
Range_t range;
Data_Type_t dtype;
My_Port_Type_t ctype;
@ -518,7 +518,7 @@ check_end_item_num (void)
%type <range> range int_range
%type <value> value number integer_value value_or_dash
%type <str> identifier string
%type <bool> bool
%type <btype> btype
%type <bound> int_or_dash number_or_dash
%type <ival> integer
%type <rval> real
@ -545,8 +545,8 @@ ifs_file : {TBL->num_conn = 0;
TBL->num_param = 0;
TBL->num_inst_var = 0;
saw_function_name = FALSE;
saw_model_name = FALSE;
saw_function_name = false;
saw_model_name = false;
alloced_size [TBL_PORT] = DEFAULT_SIZE_CONN;
alloced_size [TBL_PARAMETER] = DEFAULT_SIZE_PARAM;
@ -579,8 +579,8 @@ table : TOK_NAME_TABLE
name_table
| TOK_PORT_TABLE
{context.table = TBL_PORT;
did_default_type = FALSE;
did_allowed_types = FALSE;
did_default_type = false;
did_allowed_types = false;
INIT (TBL->num_conn);}
port_table
{TBL->num_conn = num_items;}
@ -602,11 +602,11 @@ name_table : /* empty */
name_table_item : TOK_C_FUNCTION_NAME identifier
{TBL->name.c_fcn_name =strdup (ifs_yytext);
saw_function_name = TRUE;
saw_function_name = true;
if (parser_just_names && saw_model_name) return 0;}
| TOK_SPICE_MODEL_NAME identifier
{TBL->name.model_name = strdup (ifs_yytext);
saw_model_name = TRUE;
saw_model_name = true;
if (parser_just_names && saw_function_name) return 0;}
| TOK_DESCRIPTION string
{TBL->name.description = strdup (ifs_yytext);}
@ -637,7 +637,7 @@ port_table_item : TOK_PORT_NAME list_of_ids
| TOK_DEFAULT_TYPE list_of_ctypes
{int i;
END;
did_default_type = TRUE;
did_default_type = true;
FOR_ITEM (i) {
TBL->conn[i].default_port_type =
ITEM_BUF(i).ctype.kind;
@ -649,7 +649,7 @@ port_table_item : TOK_PORT_NAME list_of_ids
| TOK_ALLOWED_TYPES list_of_ctype_lists
{int i;
END;
did_allowed_types = TRUE;
did_allowed_types = true;
FOR_ITEM (i) {
assign_ctype_list (&TBL->conn[i],
ITEM_BUF(i).ctype_list);
@ -661,7 +661,7 @@ port_table_item : TOK_PORT_NAME list_of_ids
{int i;
END;
FOR_ITEM (i) {
TBL->conn[i].is_array = ITEM_BUF(i).bool;
TBL->conn[i].is_array = ITEM_BUF(i).btype;
}}
| TOK_ARRAY_BOUNDS list_of_array_bounds
{int i;
@ -674,7 +674,7 @@ port_table_item : TOK_PORT_NAME list_of_ids
{int i;
END;
FOR_ITEM (i) {
TBL->conn[i].null_allowed = ITEM_BUF(i).bool;
TBL->conn[i].null_allowed = ITEM_BUF(i).btype;
}}
;
@ -725,7 +725,7 @@ parameter_table_item : TOK_PARAMETER_NAME list_of_ids
{int i;
END;
FOR_ITEM (i) {
TBL->param[i].is_array = ITEM_BUF(i).bool;
TBL->param[i].is_array = ITEM_BUF(i).btype;
}}
| TOK_ARRAY_BOUNDS list_of_array_bounds
{int i;
@ -737,7 +737,7 @@ parameter_table_item : TOK_PARAMETER_NAME list_of_ids
{int i;
END;
FOR_ITEM (i) {
TBL->param[i].null_allowed = ITEM_BUF(i).bool;
TBL->param[i].null_allowed = ITEM_BUF(i).btype;
}}
;
@ -767,7 +767,7 @@ static_var_table_item : TOK_STATIC_VAR_NAME list_of_ids
{int i;
END;
FOR_ITEM (i) {
TBL->inst_var[i].is_array = ITEM_BUF(i).bool;
TBL->inst_var[i].is_array = ITEM_BUF(i).btype;
}}
;
@ -781,7 +781,7 @@ list_of_array_bounds : /* empty */
BUF.range = $2;}
| list_of_array_bounds identifier
{ITEM;
BUF.range.is_named = TRUE;
BUF.range.is_named = true;
BUF.range.u.name = $2;}
;
@ -793,13 +793,13 @@ list_of_directions : /* empty */
| list_of_directions direction {ITEM; BUF.dir = $2;}
;
direction : TOK_DIR_IN {$$ = IN;}
| TOK_DIR_OUT {$$ = OUT;}
| TOK_DIR_INOUT {$$ = INOUT;}
direction : TOK_DIR_IN {$$ = CMPP_IN;}
| TOK_DIR_OUT {$$ = CMPP_OUT;}
| TOK_DIR_INOUT {$$ = CMPP_INOUT;}
;
list_of_bool : /* empty */
| list_of_bool bool {ITEM; BUF.bool = $2;}
| list_of_bool btype {ITEM; BUF.btype = $2;}
;
list_of_ctypes : /* empty */
@ -824,24 +824,24 @@ list_of_dtypes : /* empty */
| list_of_dtypes dtype {ITEM; BUF.dtype = $2;}
;
dtype : TOK_DTYPE_REAL {$$ = REAL;}
| TOK_DTYPE_INT {$$ = INTEGER;}
| TOK_DTYPE_BOOLEAN {$$ = BOOLEAN;}
| TOK_DTYPE_COMPLEX {$$ = COMPLEX;}
| TOK_DTYPE_STRING {$$ = STRING;}
| TOK_DTYPE_POINTER {$$ = POINTER;}
dtype : TOK_DTYPE_REAL {$$ = CMPP_REAL;}
| TOK_DTYPE_INT {$$ = CMPP_INTEGER;}
| TOK_DTYPE_BOOLEAN {$$ = CMPP_BOOLEAN;}
| TOK_DTYPE_COMPLEX {$$ = CMPP_COMPLEX;}
| TOK_DTYPE_STRING {$$ = CMPP_STRING;}
| TOK_DTYPE_POINTER {$$ = CMPP_POINTER;}
;
list_of_ranges : /* empty */
| list_of_ranges range {ITEM; BUF.range = $2;}
;
int_range : TOK_DASH {$$.is_named = FALSE;
$$.u.bounds.lower.has_bound = FALSE;
$$.u.bounds.upper.has_bound = FALSE;}
int_range : TOK_DASH {$$.is_named = false;
$$.u.bounds.lower.has_bound = false;
$$.u.bounds.upper.has_bound = false;}
| TOK_LBRACKET int_or_dash maybe_comma int_or_dash
TOK_RBRACKET
{$$.is_named = FALSE;
{$$.is_named = false;
$$.u.bounds.lower = $2;
$$.u.bounds.upper = $4;}
;
@ -850,23 +850,23 @@ maybe_comma : /* empty */
| TOK_COMMA
;
int_or_dash : TOK_DASH {$$.has_bound = FALSE;}
| integer_value {$$.has_bound = TRUE;
int_or_dash : TOK_DASH {$$.has_bound = false;}
| integer_value {$$.has_bound = true;
$$.bound = $1;}
;
range : TOK_DASH {$$.is_named = FALSE;
$$.u.bounds.lower.has_bound = FALSE;
$$.u.bounds.upper.has_bound = FALSE;}
range : TOK_DASH {$$.is_named = false;
$$.u.bounds.lower.has_bound = false;
$$.u.bounds.upper.has_bound = false;}
| TOK_LBRACKET number_or_dash maybe_comma
number_or_dash TOK_RBRACKET
{$$.is_named = FALSE;
{$$.is_named = false;
$$.u.bounds.lower = $2;
$$.u.bounds.upper = $4;}
;
number_or_dash : TOK_DASH {$$.has_bound = FALSE;}
| number {$$.has_bound = TRUE;
number_or_dash : TOK_DASH {$$.has_bound = false;}
| number {$$.has_bound = true;
$$.bound = $1;}
;
@ -874,18 +874,18 @@ list_of_values : /* empty */
| list_of_values value_or_dash {ITEM; BUF.value = $2;}
;
value_or_dash : TOK_DASH {$$.has_value = FALSE;}
value_or_dash : TOK_DASH {$$.has_value = false;}
| value
;
value : string {$$.has_value = TRUE;
$$.kind = STRING;
value : string {$$.has_value = true;
$$.kind = CMPP_STRING;
$$.u.svalue = $1;}
| bool {$$.has_value = TRUE;
$$.kind = BOOLEAN;
| btype {$$.has_value = true;
$$.kind = CMPP_BOOLEAN;
$$.u.bvalue = $1;}
| complex {$$.has_value = TRUE;
$$.kind = COMPLEX;
| complex {$$.has_value = true;
$$.kind = CMPP_COMPLEX;
$$.u.cvalue = $1;}
| number
;
@ -924,8 +924,8 @@ ctype_list : ctype
$1->next = $$;*/}
;
bool : TOK_BOOL_YES {$$ = TRUE;}
| TOK_BOOL_NO {$$ = FALSE;}
btype : TOK_BOOL_YES {$$ = true;}
| TOK_BOOL_NO {$$ = false;}
;
string : TOK_STRING_LITERAL {$$ = strdup(ifs_yytext);}
@ -934,14 +934,14 @@ string : TOK_STRING_LITERAL {$$ = strdup(ifs_yytext);}
identifier : TOK_IDENTIFIER {$$ = strdup(ifs_yytext);}
;
number : real {$$.has_value = TRUE;
$$.kind = REAL;
number : real {$$.has_value = true;
$$.kind = CMPP_REAL;
$$.u.rvalue = $1;}
| integer_value
;
integer_value : integer {$$.has_value = TRUE;
$$.kind = INTEGER;
integer_value : integer {$$.has_value = true;
$$.kind = CMPP_INTEGER;
$$.u.ivalue = $1;}
;

View File

@ -41,10 +41,10 @@ NON-STANDARD FEATURES
#include "cmpp.h"
typedef struct {
Boolean_t has_value;
bool has_value;
Data_Type_t kind;
union {
Boolean_t bvalue;
bool bvalue;
int ivalue;
double rvalue;
Complex_t cvalue;
@ -53,12 +53,12 @@ typedef struct {
} My_Value_t;
typedef struct {
Boolean_t has_bound;
bool has_bound;
My_Value_t bound;
} Bound_t;
typedef struct {
Boolean_t is_named;
bool is_named;
union {
char *name;
struct {

View File

@ -49,6 +49,7 @@ NON-STANDARD FEATURES
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "mod_yacc_y.h"
@ -147,22 +148,22 @@ static void put_type (FILE *fp, Data_Type_t type)
char ch = ' ';
switch (type) {
case INTEGER:
case CMPP_INTEGER:
ch = 'i';
break;
case REAL:
case CMPP_REAL:
ch = 'r';
break;
case COMPLEX:
case CMPP_COMPLEX:
ch = 'c';
break;
case BOOLEAN:
case CMPP_BOOLEAN:
ch = 'b';
break;
case STRING:
case CMPP_STRING:
ch = 's';
break;
case POINTER:
case CMPP_POINTER:
ch = 'p';
break;
}
@ -199,13 +200,13 @@ static void check_dir (int conn_number, Dir_t dir, char *context)
* an error.
*/
conn_dir = mod_ifs_table->conn[conn_number].direction;
if ((conn_dir != dir) && (conn_dir != INOUT)) {
if ((conn_dir != dir) && (conn_dir != CMPP_INOUT)) {
char error_str[200];
sprintf (error_str,
"Direction of port `%s' in %s() is not %s or INOUT",
mod_ifs_table->conn[conn_number].name, context,
(dir == IN) ? "IN" : "OUT");
(dir == CMPP_IN) ? "IN" : "OUT");
yyerror (error_str);
mod_num_errors++;
}
@ -213,8 +214,8 @@ static void check_dir (int conn_number, Dir_t dir, char *context)
}
/*---------------------------------------------------------------------------*/
static void check_subscript (Boolean_t formal, Boolean_t actual,
Boolean_t missing_actual_ok,
static void check_subscript (bool formal, bool actual,
bool missing_actual_ok,
char *context, char *id)
{
char error_str[200];
@ -237,7 +238,7 @@ static void check_subscript (Boolean_t formal, Boolean_t actual,
}
/*---------------------------------------------------------------------------*/
static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, Boolean_t do_subscript)
static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, bool do_subscript)
{
int i;
char error_str[200];
@ -248,7 +249,7 @@ static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, Boolean_t do_subscript)
if (0 == local_strcmpi (sub_id.id, mod_ifs_table->conn[i].name)) {
if (do_subscript) {
check_subscript (mod_ifs_table->conn[i].is_array,
sub_id.has_subscript, FALSE, "Port",
sub_id.has_subscript, false, "Port",
sub_id.id);
}
return i;
@ -260,7 +261,7 @@ static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, Boolean_t do_subscript)
if (0 == local_strcmpi (sub_id.id, mod_ifs_table->param[i].name)) {
if (do_subscript) {
check_subscript (mod_ifs_table->param[i].is_array,
sub_id.has_subscript, FALSE, "Parameter",
sub_id.has_subscript, false, "Parameter",
sub_id.id);
}
return i;
@ -272,7 +273,7 @@ static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, Boolean_t do_subscript)
if (0 == local_strcmpi (sub_id.id, mod_ifs_table->inst_var[i].name)) {
if (do_subscript) {
check_subscript (mod_ifs_table->inst_var[i].is_array,
sub_id.has_subscript, TRUE,
sub_id.has_subscript, true,
"Static Variable",
sub_id.id);
}
@ -297,13 +298,13 @@ static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, Boolean_t do_subscript)
/*---------------------------------------------------------------------------*/
static int valid_id (Sub_Id_t sub_id, Id_Kind_t kind)
{
return check_id (sub_id, kind, FALSE);
return check_id (sub_id, kind, false);
}
/*---------------------------------------------------------------------------*/
static int valid_subid (Sub_Id_t sub_id, Id_Kind_t kind)
{
return check_id (sub_id, kind, TRUE);
return check_id (sub_id, kind, true);
}
/*---------------------------------------------------------------------------*/
@ -467,16 +468,16 @@ macro : TOK_INIT
subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
int j = valid_subid ($5, CONN);
check_dir (i, OUT, "PARTIAL");
check_dir (j, IN, "PARTIAL");
check_dir (i, CMPP_OUT, "PARTIAL");
check_dir (j, CMPP_IN, "PARTIAL");
fprintf (mod_yyout, "mif_private->conn[%d]->port[%s]->partial[%d].port[%s]",
i, subscript($3), j, subscript($5));}
| TOK_AC_GAIN TOK_LPAREN subscriptable_id TOK_COMMA
subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
int j = valid_subid ($5, CONN);
check_dir (i, OUT, "AC_GAIN");
check_dir (j, IN, "AC_GAIN");
check_dir (i, CMPP_OUT, "AC_GAIN");
check_dir (j, CMPP_IN, "AC_GAIN");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->ac_gain[%d].port[%s]",
i, subscript($3), j, subscript($5));}
@ -502,19 +503,19 @@ macro : TOK_INIT
i);}
| TOK_OUTPUT_DELAY TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, OUT, "OUTPUT_DELAY");
check_dir (i, CMPP_OUT, "OUTPUT_DELAY");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->delay", i,
subscript($3));}
| TOK_CHANGED TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, OUT, "CHANGED");
check_dir (i, CMPP_OUT, "CHANGED");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->changed", i,
subscript($3));}
| TOK_INPUT TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, IN, "INPUT");
check_dir (i, CMPP_IN, "INPUT");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->input",
i, subscript($3));
@ -522,19 +523,19 @@ macro : TOK_INIT
mod_ifs_table->conn[i].allowed_port_type[0]);}
| TOK_INPUT_TYPE TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, IN, "INPUT_TYPE");
check_dir (i, CMPP_IN, "INPUT_TYPE");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->type_str",
i, subscript($3)); }
| TOK_OUTPUT_TYPE TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, OUT, "OUTPUT_TYPE");
check_dir (i, CMPP_OUT, "OUTPUT_TYPE");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->type_str",
i, subscript($3)); }
| TOK_INPUT_STRENGTH TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, IN, "INPUT_STRENGTH");
check_dir (i, CMPP_IN, "INPUT_STRENGTH");
fprintf (mod_yyout,
"((Digital_t*)(mif_private->conn[%d]->port[%s]->input",
i, subscript($3));
@ -543,7 +544,7 @@ macro : TOK_INIT
fprintf (mod_yyout, "))->strength");}
| TOK_INPUT_STATE TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, IN, "INPUT_STATE");
check_dir (i, CMPP_IN, "INPUT_STATE");
fprintf (mod_yyout,
"((Digital_t*)(mif_private->conn[%d]->port[%s]->input",
i, subscript($3));
@ -552,7 +553,7 @@ macro : TOK_INIT
fprintf (mod_yyout, "))->state");}
| TOK_OUTPUT TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, OUT, "OUTPUT");
check_dir (i, CMPP_OUT, "OUTPUT");
fprintf (mod_yyout,
"mif_private->conn[%d]->port[%s]->output",
i, subscript($3));
@ -560,7 +561,7 @@ macro : TOK_INIT
mod_ifs_table->conn[i].allowed_port_type[0]);}
| TOK_OUTPUT_STRENGTH TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, OUT, "OUTPUT_STRENGTH");
check_dir (i, CMPP_OUT, "OUTPUT_STRENGTH");
fprintf (mod_yyout,
"((Digital_t*)(mif_private->conn[%d]->port[%s]->output",
i, subscript($3));
@ -569,7 +570,7 @@ macro : TOK_INIT
fprintf (mod_yyout, "))->strength");}
| TOK_OUTPUT_STATE TOK_LPAREN subscriptable_id TOK_RPAREN
{int i = valid_subid ($3, CONN);
check_dir (i, OUT, "OUTPUT_STATE");
check_dir (i, CMPP_OUT, "OUTPUT_STATE");
fprintf (mod_yyout,
"((Digital_t*)(mif_private->conn[%d]->port[%s]->output",
i, subscript($3));
@ -601,12 +602,12 @@ macro : TOK_INIT
subscriptable_id : id
| id TOK_LBRACKET buffered_c_code TOK_RBRACKET
{$$ = $1;
$$.has_subscript = TRUE;
$$.has_subscript = true;
$$.subscript = $3;}
;
id : TOK_IDENTIFIER
{$$.has_subscript = FALSE;
{$$.has_subscript = false;
$$.id = strdup (mod_yytext);}
;

View File

@ -37,12 +37,13 @@ NON-STANDARD FEATURES
None.
============================================================================*/
#include <stdbool.h>
#include "cmpp.h"
typedef struct {
char *id;
Boolean_t has_subscript;
bool has_subscript;
char *subscript;
} Sub_Id_t;

View File

@ -68,13 +68,13 @@ void preprocess_ifs_file(void)
Ifs_Table_t ifs_table; /* Repository for info read from ifspec.ifs file */
Status_t status; /* Return status */
int status; /* Return status */
/* Read the entire ifspec.ifs file and load the data into ifs_table */
status = read_ifs_file(IFSPEC_FILENAME,GET_IFS_TABLE,&ifs_table);
if(status != OK) {
if(status != 0) {
exit(1);
}
@ -83,7 +83,7 @@ void preprocess_ifs_file(void)
status = write_ifs_c_file("ifspec.c",&ifs_table);
if(status != OK) {
if(status != 0) {
exit(1);
}
rem_ifs_table(&ifs_table);

View File

@ -63,15 +63,15 @@ 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 */
Boolean_t spice_unique; /* True if spice name unique */
Boolean_t cfunc_unique; /* True if C fcn name unique */
bool spice_unique; /* True if spice name unique */
bool cfunc_unique; /* True if C fcn name unique */
} Model_Info_t;
typedef struct {
char *path_name; /* Pathname read from udn path file */
char *node_name; /* Name of node type */
Boolean_t unique; /* True if node type name unique */
bool unique; /* True if node type name unique */
} Node_Info_t;
@ -79,19 +79,19 @@ typedef struct {
/* *********************************************************************** */
static Status_t read_modpath(int *num_models, Model_Info_t **model_info);
static Status_t read_udnpath(int *num_nodes, Node_Info_t **node_info);
static Status_t read_model_names(int num_models, Model_Info_t *model_info);
static Status_t read_node_names(int num_nodes, Node_Info_t *node_info);
static Status_t check_uniqueness(int num_models, Model_Info_t *model_info,
static int read_modpath(int *num_models, Model_Info_t **model_info);
static int read_udnpath(int *num_nodes, Node_Info_t **node_info);
static int read_model_names(int num_models, Model_Info_t *model_info);
static int read_node_names(int num_nodes, Node_Info_t *node_info);
static int check_uniqueness(int num_models, Model_Info_t *model_info,
int num_nodes, Node_Info_t *node_info);
static Status_t write_CMextrn(int num_models, Model_Info_t *model_info);
static Status_t write_CMinfo(int num_models, Model_Info_t *model_info);
static Status_t write_UDNextrn(int num_nodes, Node_Info_t *node_info);
static Status_t write_UDNinfo(int num_nodes, Node_Info_t *node_info);
static Status_t write_objects_inc(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_UDNextrn(int num_nodes, Node_Info_t *node_info);
static int write_UDNinfo(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 Status_t read_udn_type_name(const char *path, char **node_name);
static int read_udn_type_name(const char *path, char **node_name);
/* *********************************************************************** */
@ -119,7 +119,7 @@ into the simulator.
void preprocess_lst_files(void)
{
Status_t status; /* Return status */
int status; /* Return status */
Model_Info_t *model_info; /* Info about each model */
Node_Info_t *node_info; /* Info about each user-defined node type */
int num_models; /* The number of models */
@ -128,26 +128,26 @@ void preprocess_lst_files(void)
/* Get list of models from model pathname file */
status = read_modpath(&num_models, &model_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Get list of node types from udn pathname file */
status = read_udnpath(&num_nodes, &node_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Get the spice and C function names from the ifspec.ifs files */
status = read_model_names(num_models, model_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Get the user-defined node type names */
status = read_node_names(num_nodes, node_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
@ -155,33 +155,33 @@ void preprocess_lst_files(void)
/* Check to be sure the names are unique */
status = check_uniqueness(num_models, model_info,
num_nodes, node_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Write out the CMextrn.h file used to compile SPIinit.c */
status = write_CMextrn(num_models, model_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Write out the CMinfo.h file used to compile SPIinit.c */
status = write_CMinfo(num_models, model_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Write out the UDNextrn.h file used to compile SPIinit.c */
status = write_UDNextrn(num_nodes, node_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* Write out the UDNinfo.h file used to compile SPIinit.c */
status = write_UDNinfo(num_nodes, node_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
@ -190,7 +190,7 @@ void preprocess_lst_files(void)
/* user-defined node functions with the simulator */
status = write_objects_inc(num_models, model_info,
num_nodes, node_info);
if(status != OK) {
if(status != 0) {
exit(1);
}
/* remove model_info and node_info */
@ -219,7 +219,7 @@ processing.
*/
static Status_t read_modpath(
static int read_modpath(
int *num_models, /* Number of model pathnames found */
Model_Info_t **model_info /* Info about each model */
)
@ -243,9 +243,9 @@ static Status_t read_modpath(
/* Open the model pathname file */
fp = fopen_cmpp(&filename, "r");
if(fp == NULL) {
if (fp == NULL) {
print_error("ERROR - File not found: %s", filename);
return(ERROR);
return -1;
}
/* Read the pathnames from the file, one line at a time until EOF */
@ -260,7 +260,7 @@ static Status_t read_modpath(
if(len > MAX_PATH_LEN) {
print_error("ERROR - Line %d of %s exceeds %d characters",
line_num, filename, MAX_PATH_LEN);
return(ERROR);
return -1;
}
/* Strip white space including newline */
@ -289,7 +289,7 @@ static Status_t read_modpath(
if(len > (MAX_PATH_LEN - (MAX_FN_LEN + 1)) ) {
print_error("ERROR - Pathname on line %d of %s exceeds %d characters",
line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1)));
return(ERROR);
return -1;
}
/* Allocate and initialize a new model info structure */
@ -300,8 +300,8 @@ static Status_t read_modpath(
model[n].path_name = NULL;
model[n].spice_name = NULL;
model[n].cfunc_name = NULL;
model[n].spice_unique = TRUE;
model[n].cfunc_unique = TRUE;
model[n].spice_unique = true;
model[n].cfunc_unique = true;
/* Put pathname into info structure */
model[n].path_name = (char *) malloc((size_t) (len+1));
@ -318,11 +318,7 @@ static Status_t read_modpath(
*num_models = n;
*model_info = model;
if(filename)
free((char*)filename);
return(OK);
return 0;
}
@ -338,7 +334,7 @@ processing.
*/
static Status_t read_udnpath(
static int read_udnpath(
int *num_nodes, /* Number of node pathnames found */
Node_Info_t **node_info /* Info about each node */
)
@ -365,7 +361,7 @@ static Status_t read_udnpath(
/* For backward compatibility, return with WARNING only if file not found */
if(fp == NULL) {
print_error("WARNING - File not found: %s", filename);
return(OK);
return 0;
}
/* Read the pathnames from the file, one line at a time until EOF */
@ -380,7 +376,7 @@ static Status_t read_udnpath(
if(len > MAX_PATH_LEN) {
print_error("ERROR - Line %d of %s exceeds %d characters",
line_num, filename, MAX_PATH_LEN);
return(ERROR);
return -1;
}
/* Strip white space including newline */
@ -409,7 +405,7 @@ static Status_t read_udnpath(
if(len > (MAX_PATH_LEN - (MAX_FN_LEN + 1)) ) {
print_error("ERROR - Pathname on line %d of %s exceeds %d characters",
line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1)));
return(ERROR);
return -1;
}
/* Allocate and initialize a new node info structure */
@ -419,7 +415,7 @@ static Status_t read_udnpath(
node = (Node_Info_t *) realloc(node, (size_t) (n + 1) * sizeof(Node_Info_t));
node[n].path_name = NULL;
node[n].node_name = NULL;
node[n].unique = TRUE;
node[n].unique = true;
/* Put pathname into info structure */
node[n].path_name = (char *) malloc((size_t) (len+1));
@ -436,11 +432,7 @@ static Status_t read_udnpath(
*num_nodes = n;
*node_info = node;
if(filename)
free((char*)filename);
return(OK);
return 0;
}
@ -455,22 +447,22 @@ This function opens each of the models and gets the names of the model
and the C function into the internal model information structure.
*/
static Status_t read_model_names(
static int read_model_names(
int num_models, /* Number of model pathnames */
Model_Info_t *model_info /* Info about each model */
)
{
Boolean_t all_found; /* True if all ifspec files read */
bool all_found; /* True if all ifspec files read */
int i; /* A temporary counter */
char path[MAX_PATH_LEN+1]; /* full pathname to ifspec file */
Status_t status; /* Return status */
int status; /* Return status */
Ifs_Table_t ifs_table; /* Repository for info read from ifspec file */
/* For each model found in model pathname file, read the interface */
/* spec file to get the SPICE and C function names into model_info */
for(i = 0, all_found = TRUE; i < num_models; i++) {
for(i = 0, all_found = true; i < num_models; i++) {
/* Form the full pathname to the interface spec file */
strcpy(path, model_info[i].path_name);
@ -481,12 +473,12 @@ static Status_t read_model_names(
status = read_ifs_file(path, GET_IFS_NAME, &ifs_table);
/* Transfer the names into the model_info structure */
if(status == OK) {
model_info[i].spice_name = strdup(ifs_table.name.model_name);
model_info[i].cfunc_name = strdup(ifs_table.name.c_fcn_name);
if(status == 0) {
model_info[i].spice_name = ifs_table.name.model_name;
model_info[i].cfunc_name = ifs_table.name.c_fcn_name;
}
else {
all_found = FALSE;
all_found = false;
print_error("ERROR - Problems reading %s in directory %s",
IFSPEC_FILENAME, model_info[i].path_name);
}
@ -496,9 +488,9 @@ static Status_t read_model_names(
}
if(all_found)
return(OK);
return 0;
else
return(ERROR);
return -1;
}
@ -514,21 +506,21 @@ and gets the names of the node into the internal information structure.
*/
static Status_t read_node_names(
static int read_node_names(
int num_nodes, /* Number of node pathnames */
Node_Info_t *node_info /* Info about each node */
)
{
Boolean_t all_found; /* True if all files read OK */
bool all_found; /* True if all files read OK */
int i; /* A temporary counter */
char path[MAX_PATH_LEN+1]; /* full pathname to file */
Status_t status; /* Return status */
int status; /* Return status */
char *node_name; /* Name of node type read from file */
/* For each node found in node pathname file, read the udnfunc.c */
/* file to get the node type names into node_info */
for(i = 0, all_found = TRUE; i < num_nodes; i++) {
for(i = 0, all_found = true; i < num_nodes; i++) {
/* Form the full pathname to the interface spec file */
strcpy(path, node_info[i].path_name);
@ -539,20 +531,20 @@ static Status_t read_node_names(
status = read_udn_type_name(path, &node_name);
/* Transfer the names into the node_info structure */
if(status == OK) {
if(status == 0) {
node_info[i].node_name = node_name;
}
else {
all_found = FALSE;
all_found = false;
print_error("ERROR - Problems reading %s in directory %s",
UDNFUNC_FILENAME, node_info[i].path_name);
}
}
if(all_found)
return(OK);
return 0;
else
return(ERROR);
return -1;
}
@ -569,7 +561,7 @@ names are unique with respect to each other and to the models and
functions internal to SPICE 3C1.
*/
static Status_t check_uniqueness(
static int check_uniqueness(
int num_models, /* Number of model pathnames */
Model_Info_t *model_info, /* Info about each model */
int num_nodes, /* Number of node type pathnames */
@ -578,7 +570,7 @@ static Status_t check_uniqueness(
{
int i; /* A temporary counter */
int j; /* A temporary counter */
Boolean_t all_unique; /* true if names are unique */
bool all_unique; /* true if names are unique */
/* Define a list of model names used internally by XSPICE */
/* These names (except 'poly') are defined in src/sim/INP/INPdomodel.c and */
@ -627,19 +619,19 @@ static Status_t check_uniqueness(
/* Then, loop through all model names and report errors if same as SPICE */
/* model name or same as another model name in list */
for(i = 0, all_unique = TRUE; i < num_models; i++) {
for(i = 0, all_unique = true; i < num_models; i++) {
/* First check against list of SPICE internal names */
for(j = 0; j < numSPICEmodels; j++) {
if(strcmp(model_info[i].spice_name, SPICEmodel[j]) == 0) {
all_unique = FALSE;
all_unique = false;
print_error("ERROR - Model name '%s' is same as internal SPICE model name\n",
model_info[i].spice_name);
}
}
/* Skip if already seen once */
if(model_info[i].spice_unique == FALSE)
if(model_info[i].spice_unique == false)
continue;
/* Then check against other names in list */
@ -651,9 +643,9 @@ static Status_t check_uniqueness(
/* Compare the names */
if(strcmp(model_info[i].spice_name, model_info[j].spice_name) == 0) {
all_unique = FALSE;
model_info[i].spice_unique = FALSE;
model_info[j].spice_unique = FALSE;
all_unique = false;
model_info[i].spice_unique = false;
model_info[j].spice_unique = false;
print_error("ERROR - Model name '%s' in directory: %s",
model_info[i].spice_name,
model_info[i].path_name);
@ -670,7 +662,7 @@ static Status_t check_uniqueness(
for(i = 0; i < num_models; i++) {
/* Skip if already seen once */
if(model_info[i].cfunc_unique == FALSE)
if(model_info[i].cfunc_unique == false)
continue;
/* Check against other names in list only, not against SPICE identifiers */
@ -683,9 +675,9 @@ static Status_t check_uniqueness(
/* Compare the names */
if(strcmp(model_info[i].cfunc_name, model_info[j].cfunc_name) == 0) {
all_unique = FALSE;
model_info[i].cfunc_unique = FALSE;
model_info[j].cfunc_unique = FALSE;
all_unique = false;
model_info[i].cfunc_unique = false;
model_info[j].cfunc_unique = false;
print_error("ERROR - C function name '%s' in directory: %s",
model_info[i].cfunc_name,
model_info[i].path_name);
@ -705,14 +697,14 @@ static Status_t check_uniqueness(
/* First check against list of internal names */
for(j = 0; j < numUDNidentifiers; j++) {
if(strcmp(node_info[i].node_name, UDNidentifier[j]) == 0) {
all_unique = FALSE;
all_unique = false;
print_error("ERROR - Node type '%s' is same as internal node type\n",
node_info[i].node_name);
}
}
/* Skip if already seen once */
if(node_info[i].unique == FALSE)
if(node_info[i].unique == false)
continue;
/* Then check against other names in list */
@ -724,9 +716,9 @@ static Status_t check_uniqueness(
/* Compare the names */
if(strcmp(node_info[i].node_name, node_info[j].node_name) == 0) {
all_unique = FALSE;
node_info[i].unique = FALSE;
node_info[j].unique = FALSE;
all_unique = false;
node_info[i].unique = false;
node_info[j].unique = false;
print_error("ERROR - Node type '%s' in directory: %s",
node_info[i].node_name,
node_info[i].path_name);
@ -741,9 +733,9 @@ static Status_t check_uniqueness(
/* Return error status */
if(all_unique)
return(OK);
return 0;
else
return(ERROR);
return -1;
}
@ -761,7 +753,7 @@ mentioned in the include file to define the models known to the
simulator.
*/
static Status_t write_CMextrn(
static int write_CMextrn(
int num_models, /* Number of model pathnames */
Model_Info_t *model_info /* Info about each model */
)
@ -775,7 +767,7 @@ static Status_t write_CMextrn(
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
return -1;
}
/* Write out the data */
@ -785,9 +777,7 @@ static Status_t write_CMextrn(
/* Close the file and return */
fclose(fp);
if(filename)
free((char*)filename);
return(OK);
return 0;
}
@ -804,7 +794,7 @@ the include file to define the models known to the simulator.
*/
static Status_t write_CMinfo(
static int write_CMinfo(
int num_models, /* Number of model pathnames */
Model_Info_t *model_info /* Info about each model */
)
@ -818,7 +808,7 @@ static Status_t write_CMinfo(
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
return -1;
}
/* Write out the data */
@ -828,9 +818,7 @@ static Status_t write_CMinfo(
/* Close the file and return */
fclose(fp);
if(filename)
free((char*)filename);
return(OK);
return 0;
}
@ -851,7 +839,7 @@ simulator.
static Status_t write_UDNextrn(
static int write_UDNextrn(
int num_nodes, /* Number of node pathnames */
Node_Info_t *node_info /* Info about each node */
)
@ -865,7 +853,7 @@ static Status_t write_UDNextrn(
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
return -1;
}
/* Write out the data */
@ -875,9 +863,7 @@ static Status_t write_UDNextrn(
/* Close the file and return */
fclose(fp);
if(filename)
free((char*)filename);
return(OK);
return 0;
}
@ -896,7 +882,7 @@ simulator.
static Status_t write_UDNinfo(
static int write_UDNinfo(
int num_nodes, /* Number of node pathnames */
Node_Info_t *node_info /* Info about each node */
)
@ -910,7 +896,7 @@ static Status_t write_UDNinfo(
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
return -1;
}
/* Write out the data */
@ -919,10 +905,8 @@ static Status_t write_UDNinfo(
}
/* Close the file and return */
if(filename)
free((char*)filename);
fclose(fp);
return(OK);
return 0;
}
@ -936,7 +920,7 @@ the make utility to locate the object modules needed to link the
simulator with the code models and user-defined node types.
*/
static Status_t write_objects_inc(
static int write_objects_inc(
int num_models, /* Number of model pathnames */
Model_Info_t *model_info, /* Info about each model */
int num_nodes, /* Number of udn pathnames */
@ -952,7 +936,7 @@ static Status_t write_objects_inc(
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
return -1;
}
/* Write out the data */
@ -973,9 +957,7 @@ static Status_t write_objects_inc(
/* Close the file and return */
fclose(fp);
if(filename)
free((char*)filename);
return(OK);
return 0;
}
@ -988,14 +970,14 @@ is found, and then gets the name of the node type from the first
member of the structure.
*/
static Status_t read_udn_type_name(
static int read_udn_type_name(
const char *path, /* the path to the node definition file */
char **node_name /* the node type name found in the file */
)
{
FILE *fp; /* file pointer for opened file */
Boolean_t found; /* true if name found successfully */
Boolean_t in_struct; /* true if found struct with name */
bool found; /* true if name found successfully */
bool in_struct; /* true if found struct with name */
char name[MAX_NAME_LEN + 1]; /* temporary storage for name read */
int c; /* a character read from the file */
int i; /* a counter */
@ -1006,12 +988,12 @@ static Status_t read_udn_type_name(
fp = fopen_cmpp(&path, "r");
free((char*)path);
if(fp == NULL)
return(ERROR);
return -1;
/* Read the file until the definition of the Evt_Udn_Info_t struct */
/* is found, then get the name of the node type from the first */
/* member of the structure */
found = FALSE;
found = false;
do {
/* read the next character */
c = fgetc(fp);
@ -1036,11 +1018,11 @@ static Status_t read_udn_type_name(
break;
/* read until "Evt_Udn_Info_t" is encountered */
for(i = 0, in_struct = FALSE; ; i++) {
for(i = 0, in_struct = false; ; i++) {
if(c != struct_type[i])
break;
else if(i == (sizeof(struct_type) - 2)) {
in_struct = TRUE;
in_struct = true;
break;
}
else
@ -1056,7 +1038,7 @@ static Status_t read_udn_type_name(
do {
c = fgetc(fp);
if(c == '"') {
found = TRUE;
found = true;
name[i] = '\0';
}
else if(c != EOF)
@ -1074,11 +1056,11 @@ static Status_t read_udn_type_name(
if(found) {
*node_name = (char *) malloc(strlen(name) + 1);
strcpy(*node_name, name);
return(OK);
return 0;
}
else {
*node_name = NULL;
return(ERROR);
return -1;
}
}

View File

@ -113,7 +113,7 @@ void preprocess_mod_file (
Ifs_Table_t ifs_table; /* info read from ifspec.ifs file */
Status_t status; /* Return status */
int status; /* Return status */
const char *output_filename;
/*
@ -122,7 +122,7 @@ void preprocess_mod_file (
status = read_ifs_file (IFSPEC_FILENAME, GET_IFS_TABLE, &ifs_table);
if (status != OK) {
if (status != 0) {
exit(1);
}

View File

@ -59,11 +59,11 @@ extern int ifs_yylineno;
extern char *ifs_yytext;
extern Ifs_Table_t *parser_ifs_table;
extern Boolean_t parser_just_names;
extern bool parser_just_names;
extern int ifs_num_errors;
static Status_t read_ifs_table(FILE *fp, int mode, Ifs_Table_t *ifs_table);
static int read_ifs_table(FILE *fp, int mode, Ifs_Table_t *ifs_table);
const char *current_filename;
@ -89,7 +89,7 @@ from read_ifs_table(), the file is closed.
Status_t read_ifs_file(
int read_ifs_file(
const char *filename, /* File to read */
int mode, /* Get names only or get everything? */
Ifs_Table_t *ifs_table) /* Table to put info in */
@ -97,7 +97,7 @@ Status_t read_ifs_file(
FILE *fp; /* Ifs file pointer */
Status_t status; /* returned status from function */
int status; /* returned status from function */
/* Open the ifs file for read access */
@ -107,7 +107,7 @@ Status_t read_ifs_file(
if(fp == NULL) {
perror (prog_name);
print_error("ERROR - File not found: %s", filename);
return(ERROR);
return -1;
}
current_filename = filename;
@ -141,7 +141,7 @@ automatically generated by UNIX lex/yacc.
static Status_t read_ifs_table(
static int read_ifs_table(
FILE *fp, /* File to read from */
int mode, /* Get names only or get everything? */
Ifs_Table_t *ifs_table) /* Table to put info in */
@ -156,7 +156,7 @@ static Status_t read_ifs_table(
ifs_yylineno = 1;
ifs_yyin = fp;
parser_just_names = (mode == GET_IFS_NAME) ? TRUE : FALSE;
parser_just_names = (mode == GET_IFS_NAME) ? true : false;
parser_ifs_table = ifs_table;
ifs_num_errors = 0;
@ -164,10 +164,10 @@ static Status_t read_ifs_table(
if (ifs_yyparse() || (ifs_num_errors > 0)) {
print_error ("Error parsing interface specification file");
ifs_yyrestart(NULL);
return ERROR;
return -1;
}
ifs_yyrestart(NULL);
return OK;
return 0;
}
/*---------------------------------------------------------------------------*/

View File

@ -40,18 +40,35 @@ NON-STANDARD FEATURES
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32)
#include <shlwapi.h> /* for definition of PathIsRelativeA() */
#if defined(_MSC_VER)
#pragma comment(lib, "Shlwapi.lib")
#endif
#endif
#include "cmpp.h"
/* Using only Unix directory separator since it is used to build directory
* paths in include files that must work on any supported operating
* system */
#define DIR_TERM_UNIX '/'
/* *********************************************************************** */
char *prog_name;
inline static bool is_absolute_pathname(const char *path);
/* Initialize external variable prog_name with the name of the program.
* A copy is not made. */
void init_error(char *program_name)
@ -90,33 +107,68 @@ void str_to_lower(char *s)
/* If *path_p is relative, prefix with the CMPP output or input string
* build the path and open the file and return the path that was created. */
/* If *path_p is relative, prefix with the value of the CMPP output or
* input environment variable. Open the file and return the path that
* was used to open it. */
FILE *fopen_cmpp(const char **path_p, const char *mode)
{
const char *path = *path_p;
char *buf = (char *) NULL;
char buf[MAX_PATH_LEN + 1];
/* If absoulte path, prefix with CMPP_ODIR/CMPP_IDIR env value */
if (!is_absolute_pathname(path)) { /* relative path */
const char *e = getenv((*mode == 'w' || *mode == 'a') ?
"CMPP_ODIR" : "CMPP_IDIR");
if (e) { /* have env var */
const size_t len_prefix = strlen(e);
const size_t len_path = strlen(path);
const size_t n_char = len_prefix + len_path + 1;
if (path[0] != '/') {
const char *e = getenv((*mode == 'w') ? "CMPP_ODIR" : "CMPP_IDIR");
if (e) {
if (strlen(e) + 1 + strlen(path) < sizeof(buf)) {
strcpy(buf, e);
strcat(buf, "/");
strcat(buf, path);
path = buf;
/* Allocate buffer to build full file name */
if ((buf = (char *) malloc(n_char + 1)) == (char *) NULL) {
*path_p = (char *) NULL;
return (FILE *) NULL;
}
else {
path = NULL;
/* Build the full file name */
{
char *p_cur = buf;
(void) memcpy(p_cur, e, len_prefix);
p_cur += len_prefix;
*p_cur++ = DIR_TERM_UNIX;
(void) memcpy(p_cur, path, len_path + 1);
}
} /* end of case that env variable found */
} /* end of case that path is absolute */
/* If did not build full file name yet, copy the original
* name of the file */
if (buf == (char *) NULL) {
if ((buf = strdup(path)) == (char *) NULL) { /* failed */
*path_p = (char *) NULL;
return (FILE *) NULL;
}
}
*path_p = strdup(path);
return fopen(path, mode);
/* Return copy of file name and opened file */
*path_p = buf;
return fopen(buf, mode);
} /* end of function fopen_cmpp */
/* Returns true if path is an absolute path and false if it is a
* relative path. No check is done for the existance of the path. */
/*** NOTE: Same as in inpcom.c Currently the cmpp project is "isolated
* from others. It would be good to make into one function used in common */
inline static bool is_absolute_pathname(const char *path)
{
#ifdef _WIN32
return !PathIsRelativeA(path);
#else
return path[0] == DIR_TERM_UNIX;
#endif
} /* end of funciton is_absolute_pathname */

View File

@ -74,7 +74,7 @@ static char *value_to_str(Data_Type_t type, Value_t value);
static char *no_value_to_str(void);
static char *boolean_to_str(Boolean_t value);
static char *boolean_to_str(bool value);
static char *integer_to_str(int value);
@ -109,7 +109,7 @@ The output file is then closed.
Status_t write_ifs_c_file(
int write_ifs_c_file(
const char *filename, /* File to write to */
Ifs_Table_t *ifs_table) /* Table of Interface Specification data */
{
@ -123,7 +123,7 @@ Status_t write_ifs_c_file(
if(fp == NULL) {
print_error("ERROR - Can't create file: %s", filename);
return(ERROR);
return -1;
}
@ -155,12 +155,13 @@ Status_t write_ifs_c_file(
/* Close the ifspec.c file and return */
int_status = fclose(fp);
if(filename)
free((char*)filename);
if(int_status == 0)
return(OK);
else
return(ERROR);
if (int_status == 0) {
return 0;
}
else {
return -1;
}
}
@ -244,7 +245,7 @@ static void write_pTable(
int i;
char str[80];
Boolean_t is_array;
bool is_array;
Data_Type_t type;
@ -284,33 +285,33 @@ static void write_pTable(
strcpy(str,"");
if(is_array == TRUE) {
if(is_array == true) {
strcat(str,"(");
}
if(type == BOOLEAN) {
if(type == CMPP_BOOLEAN) {
strcat(str,"IF_FLAG"); /* There is no BOOLEAN in SPICE3 */
}
else if(type == INTEGER) {
else if(type == CMPP_INTEGER) {
strcat(str,"IF_INTEGER");
}
else if(type == REAL) {
else if(type == CMPP_REAL) {
strcat(str,"IF_REAL");
}
else if(type == COMPLEX) {
else if(type == CMPP_COMPLEX) {
strcat(str,"IF_COMPLEX");
}
else if(type == STRING) {
else if(type == CMPP_STRING) {
strcat(str,"IF_STRING");
}
else if(type == POINTER) {
else if(type == CMPP_POINTER) {
strcat(str,"IF_STRING");
}
else {
print_error("INTERNAL ERROR - write_pTable() - Impossible data type.");
}
if(is_array == TRUE) {
if(is_array == true) {
strcat(str,"|IF_VECTOR)");
}
@ -351,7 +352,7 @@ static void write_mPTable(
int i;
char str[80];
Boolean_t is_array;
bool is_array;
Data_Type_t type;
@ -391,30 +392,30 @@ static void write_mPTable(
strcpy(str,"");
if(is_array == TRUE) {
if(is_array == true) {
strcat(str,"(");
}
if(type == BOOLEAN) {
if(type == CMPP_BOOLEAN) {
strcat(str,"IF_FLAG"); /* There is no BOOLEAN in SPICE3 */
}
else if(type == INTEGER) {
else if(type == CMPP_INTEGER) {
strcat(str,"IF_INTEGER");
}
else if(type == REAL) {
else if(type == CMPP_REAL) {
strcat(str,"IF_REAL");
}
else if(type == COMPLEX) {
else if(type == CMPP_COMPLEX) {
strcat(str,"IF_COMPLEX");
}
else if(type == STRING) {
else if(type == CMPP_STRING) {
strcat(str,"IF_STRING");
}
else {
print_error("INTERNAL ERROR - write_mPTable() - Impossible data type.");
}
if(is_array == TRUE) {
if(is_array == true) {
strcat(str,"|IF_VECTOR)");
}
@ -541,26 +542,26 @@ static void write_conn_info(
str = boolean_to_str(ifs_table->conn[i].is_array);
fprintf(fp, " %s,\n", str);
if(ifs_table->conn[i].is_array == FALSE) {
if(ifs_table->conn[i].is_array == false) {
str = boolean_to_str(FALSE); /* has_lower_bound */
str = boolean_to_str(false); /* has_lower_bound */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* lower_bound */
fprintf(fp, " %s,\n", str);
str = boolean_to_str(FALSE); /* has_upper_bound */
str = boolean_to_str(false); /* has_upper_bound */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* upper_bound */
fprintf(fp, " %s,\n", str);
}
else { /* is_array == TRUE */
else { /* is_array == true */
str = boolean_to_str(ifs_table->conn[i].has_lower_bound);
fprintf(fp, " %s,\n", str);
if(ifs_table->conn[i].has_lower_bound == TRUE)
if(ifs_table->conn[i].has_lower_bound == true)
str = integer_to_str(ifs_table->conn[i].lower_bound);
else
str = integer_to_str(0);
@ -569,7 +570,7 @@ static void write_conn_info(
str = boolean_to_str(ifs_table->conn[i].has_upper_bound);
fprintf(fp, " %s,\n", str);
if(ifs_table->conn[i].has_upper_bound == TRUE)
if(ifs_table->conn[i].has_upper_bound == true)
str = integer_to_str(ifs_table->conn[i].upper_bound);
else
str = integer_to_str(0);
@ -648,7 +649,7 @@ static void write_param_info(
str = boolean_to_str(ifs_table->param[i].has_default);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].has_default == TRUE)
if(ifs_table->param[i].has_default == true)
str = value_to_str(ifs_table->param[i].type, ifs_table->param[i].default_value);
else
str = no_value_to_str();
@ -657,7 +658,7 @@ static void write_param_info(
str = boolean_to_str(ifs_table->param[i].has_lower_limit);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].has_lower_limit == TRUE)
if(ifs_table->param[i].has_lower_limit == true)
str = value_to_str(ifs_table->param[i].type, ifs_table->param[i].lower_limit);
else
str = no_value_to_str();
@ -666,7 +667,7 @@ static void write_param_info(
str = boolean_to_str(ifs_table->param[i].has_upper_limit);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].has_upper_limit == TRUE)
if(ifs_table->param[i].has_upper_limit == true)
str = value_to_str(ifs_table->param[i].type, ifs_table->param[i].upper_limit);
else
str = no_value_to_str();
@ -675,49 +676,49 @@ static void write_param_info(
str = boolean_to_str(ifs_table->param[i].is_array);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].is_array == FALSE) {
if(ifs_table->param[i].is_array == false) {
str = boolean_to_str(FALSE); /* has_conn_ref */
str = boolean_to_str(false); /* has_conn_ref */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* conn_ref */
fprintf(fp, " %s,\n", str);
str = boolean_to_str(FALSE); /* has_lower_bound */
str = boolean_to_str(false); /* has_lower_bound */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* lower_bound */
fprintf(fp, " %s,\n", str);
str = boolean_to_str(FALSE); /* has_upper_bound */
str = boolean_to_str(false); /* has_upper_bound */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* upper_bound */
fprintf(fp, " %s,\n", str);
}
else { /* is_array == TRUE */
else { /* is_array == true */
str = boolean_to_str(ifs_table->param[i].has_conn_ref);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].has_conn_ref == TRUE) {
if(ifs_table->param[i].has_conn_ref == true) {
str = integer_to_str(ifs_table->param[i].conn_ref);
fprintf(fp, " %s,\n", str);
str = boolean_to_str(FALSE); /* has_lower_bound */
str = boolean_to_str(false); /* has_lower_bound */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* lower_bound */
fprintf(fp, " %s,\n", str);
str = boolean_to_str(FALSE); /* has_upper_bound */
str = boolean_to_str(false); /* has_upper_bound */
fprintf(fp, " %s,\n", str);
str = integer_to_str(0); /* upper_bound */
fprintf(fp, " %s,\n", str);
}
else { /* has_conn_ref == FALSE */
else { /* has_conn_ref == false */
str = integer_to_str(0); /* conn_ref */
fprintf(fp, " %s,\n", str);
@ -725,7 +726,7 @@ static void write_param_info(
str = boolean_to_str(ifs_table->param[i].has_lower_bound);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].has_lower_bound == TRUE)
if(ifs_table->param[i].has_lower_bound == true)
str = integer_to_str(ifs_table->param[i].lower_bound);
else
str = integer_to_str(0);
@ -734,7 +735,7 @@ static void write_param_info(
str = boolean_to_str(ifs_table->param[i].has_upper_bound);
fprintf(fp, " %s,\n", str);
if(ifs_table->param[i].has_upper_bound == TRUE)
if(ifs_table->param[i].has_upper_bound == true)
str = integer_to_str(ifs_table->param[i].upper_bound);
else
str = integer_to_str(0);
@ -981,27 +982,27 @@ static char *data_type_to_str(Data_Type_t type)
switch(type) {
case BOOLEAN:
case CMPP_BOOLEAN:
strcpy(str,"MIF_BOOLEAN");
break;
case INTEGER:
case CMPP_INTEGER:
strcpy(str,"MIF_INTEGER");
break;
case REAL:
case CMPP_REAL:
strcpy(str,"MIF_REAL");
break;
case COMPLEX:
case CMPP_COMPLEX:
strcpy(str,"MIF_COMPLEX");
break;
case STRING:
case CMPP_STRING:
strcpy(str,"MIF_STRING");
break;
case POINTER:
case CMPP_POINTER:
strcpy(str,"MIF_STRING");
break;
@ -1151,15 +1152,15 @@ static char *dir_to_str(Dir_t dir)
switch(dir) {
case IN:
case CMPP_IN:
strcpy(str,"MIF_IN");
break;
case OUT:
case CMPP_OUT:
strcpy(str,"MIF_OUT");
break;
case INOUT:
case CMPP_INOUT:
strcpy(str,"MIF_INOUT");
break;
@ -1190,25 +1191,25 @@ static char *value_to_str(Data_Type_t type, Value_t value)
switch(type) {
case BOOLEAN:
case CMPP_BOOLEAN:
bool_str = boolean_to_str(value.bvalue);
sprintf(str, "{%s, 0, 0.0, {0.0, 0.0}, NULL}", bool_str);
break;
case INTEGER:
case CMPP_INTEGER:
sprintf(str, "{MIF_FALSE, %d, 0.0, {0.0, 0.0}, NULL}", value.ivalue);
break;
case REAL:
case CMPP_REAL:
sprintf(str, "{MIF_FALSE, 0, %e, {0.0, 0.0}, NULL}", value.rvalue);
break;
case COMPLEX:
case CMPP_COMPLEX:
sprintf(str, "{MIF_FALSE, 0, 0.0, {%e, %e}, NULL}",
value.cvalue.real, value.cvalue.imag);
break;
case STRING:
case CMPP_STRING:
/* be careful, the string could conceivably be very long... */
str_len = (int) strlen(value.svalue);
if((str_len + BASE_STR_LEN) > max_len) {
@ -1229,29 +1230,17 @@ static char *value_to_str(Data_Type_t type, Value_t value)
/* *********************************************************************** */
static char *boolean_to_str(Boolean_t value)
static char *boolean_to_str(bool value)
{
static char *str = NULL;
if(str == NULL)
if (str == NULL) {
str = (char *) malloc(BASE_STR_LEN+1);
switch(value) {
case TRUE:
strcpy(str,"MIF_TRUE");
break;
case FALSE:
strcpy(str,"MIF_FALSE");
break;
default:
print_error("INTERNAL ERROR - boolean_to_str() - Impossible boolean value.");
}
return(str);
strcpy(str, value ? "MIF_TRUE" : "MIF_FALSE");
return str;
}