From 348e3976e7123f092861ece7e790ec156fc45712 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 1 Dec 2012 22:39:21 +0100 Subject: [PATCH] cmpp, use for print_error() --- src/xspice/cmpp/cmpp.h | 8 ++- src/xspice/cmpp/pp_lst.c | 102 +++++++++++++------------------------ src/xspice/cmpp/pp_mod.c | 12 ++--- src/xspice/cmpp/read_ifs.c | 5 +- src/xspice/cmpp/util.c | 13 +++-- src/xspice/cmpp/writ_ifs.c | 4 +- 6 files changed, 58 insertions(+), 86 deletions(-) diff --git a/src/xspice/cmpp/cmpp.h b/src/xspice/cmpp/cmpp.h index 594b22b33..d75034a3a 100644 --- a/src/xspice/cmpp/cmpp.h +++ b/src/xspice/cmpp/cmpp.h @@ -276,7 +276,13 @@ void preprocess_mod_file(char *filename); void init_error (char *program_name); -void print_error(char *message); + +#ifdef __GNUC__ +void print_error(const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); +#else +void print_error(const char *fmt, ...); +#endif + void str_to_lower(char *s); diff --git a/src/xspice/cmpp/pp_lst.c b/src/xspice/cmpp/pp_lst.c index a76f39f17..9019c8582 100644 --- a/src/xspice/cmpp/pp_lst.c +++ b/src/xspice/cmpp/pp_lst.c @@ -221,7 +221,6 @@ static Status_t read_modpath( ) { FILE *fp; /* Model pathname file pointer */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ char path[MAX_PATH_LEN+2]; /* space to read pathnames into */ Model_Info_t *model = NULL; /* temporary pointer to model info */ @@ -241,8 +240,7 @@ static Status_t read_modpath( fp = fopen_with_path(filename, "r"); if(fp == NULL) { - sprintf(msg, "ERROR - File not found: %s", filename); - print_error(msg); + print_error("ERROR - File not found: %s", filename); return(ERROR); } @@ -256,9 +254,8 @@ static Status_t read_modpath( /* If line was too long for buffer, exit with error */ if(len > MAX_PATH_LEN) { - sprintf(msg, "ERROR - Line %d of %s exceeds %d characters", - line_num, filename, MAX_PATH_LEN); - print_error(msg); + print_error("ERROR - Line %d of %s exceeds %d characters", + line_num, filename, MAX_PATH_LEN); return(ERROR); } @@ -286,9 +283,8 @@ static Status_t read_modpath( /* Make sure pathname is short enough to add a filename at the end */ if(len > (MAX_PATH_LEN - (MAX_FN_LEN + 1)) ) { - sprintf(msg, "ERROR - Pathname on line %d of %s exceeds %d characters", - line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1))); - print_error(msg); + print_error("ERROR - Pathname on line %d of %s exceeds %d characters", + line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1))); return(ERROR); } @@ -341,7 +337,6 @@ static Status_t read_udnpath( ) { FILE *fp; /* Udn pathname file pointer */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ char path[MAX_PATH_LEN+2]; /* space to read pathnames into */ Node_Info_t *node = NULL; /* temporary pointer to node info */ @@ -362,8 +357,7 @@ static Status_t read_udnpath( /* For backward compatibility, return with WARNING only if file not found */ if(fp == NULL) { - sprintf(msg, "WARNING - File not found: %s", filename); - print_error(msg); + print_error("WARNING - File not found: %s", filename); return(OK); } @@ -377,9 +371,8 @@ static Status_t read_udnpath( /* If line was too long for buffer, exit with error */ if(len > MAX_PATH_LEN) { - sprintf(msg, "ERROR - Line %d of %s exceeds %d characters", - line_num, filename, MAX_PATH_LEN); - print_error(msg); + print_error("ERROR - Line %d of %s exceeds %d characters", + line_num, filename, MAX_PATH_LEN); return(ERROR); } @@ -407,9 +400,8 @@ static Status_t read_udnpath( /* Make sure pathname is short enough to add a filename at the end */ if(len > (MAX_PATH_LEN - (MAX_FN_LEN + 1)) ) { - sprintf(msg, "ERROR - Pathname on line %d of %s exceeds %d characters", - line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1))); - print_error(msg); + print_error("ERROR - Pathname on line %d of %s exceeds %d characters", + line_num, filename, (MAX_PATH_LEN - (MAX_FN_LEN + 1))); return(ERROR); } @@ -460,7 +452,6 @@ static Status_t read_model_names( { Boolean_t all_found; /* True if all ifspec files read */ int i; /* A temporary counter */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ char path[MAX_PATH_LEN+1]; /* full pathname to ifspec file */ Status_t status; /* Return status */ Ifs_Table_t ifs_table; /* Repository for info read from ifspec file */ @@ -486,9 +477,8 @@ static Status_t read_model_names( } else { all_found = FALSE; - sprintf(msg, "ERROR - Problems reading %s in directory %s", - IFSPEC_FILENAME, model_info[i].path_name); - print_error(msg); + print_error("ERROR - Problems reading %s in directory %s", + IFSPEC_FILENAME, model_info[i].path_name); } } @@ -518,7 +508,6 @@ static Status_t read_node_names( { Boolean_t all_found; /* True if all files read OK */ int i; /* A temporary counter */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ char path[MAX_PATH_LEN+1]; /* full pathname to file */ Status_t status; /* Return status */ char *node_name; /* Name of node type read from file */ @@ -542,9 +531,8 @@ static Status_t read_node_names( } else { all_found = FALSE; - sprintf(msg, "ERROR - Problems reading %s in directory %s", - UDNFUNC_FILENAME, node_info[i].path_name); - print_error(msg); + print_error("ERROR - Problems reading %s in directory %s", + UDNFUNC_FILENAME, node_info[i].path_name); } } @@ -577,7 +565,6 @@ static Status_t check_uniqueness( { int i; /* A temporary counter */ int j; /* A temporary counter */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ Boolean_t all_unique; /* true if names are unique */ /* Define a list of model names used internally by XSPICE */ @@ -633,10 +620,8 @@ static Status_t check_uniqueness( for(j = 0; j < numSPICEmodels; j++) { if(strcmp(model_info[i].spice_name, SPICEmodel[j]) == 0) { all_unique = FALSE; - sprintf(msg, - "ERROR - Model name '%s' is same as internal SPICE model name\n", - model_info[i].spice_name); - print_error(msg); + print_error("ERROR - Model name '%s' is same as internal SPICE model name\n", + model_info[i].spice_name); } } @@ -656,17 +641,13 @@ static Status_t check_uniqueness( all_unique = FALSE; model_info[i].spice_unique = FALSE; model_info[j].spice_unique = FALSE; - sprintf(msg, - "ERROR - Model name '%s' in directory: %s", - model_info[i].spice_name, - model_info[i].path_name); - print_error(msg); + print_error("ERROR - Model name '%s' in directory: %s", + model_info[i].spice_name, + model_info[i].path_name); print_error(" is same as"); - sprintf(msg, - " model name '%s' in directory: %s\n", - model_info[j].spice_name, - model_info[j].path_name); - print_error(msg); + print_error(" model name '%s' in directory: %s\n", + model_info[j].spice_name, + model_info[j].path_name); } } @@ -692,17 +673,13 @@ static Status_t check_uniqueness( all_unique = FALSE; model_info[i].cfunc_unique = FALSE; model_info[j].cfunc_unique = FALSE; - sprintf(msg, - "ERROR - C function name '%s' in directory: %s", - model_info[i].cfunc_name, - model_info[i].path_name); - print_error(msg); + print_error("ERROR - C function name '%s' in directory: %s", + model_info[i].cfunc_name, + model_info[i].path_name); print_error(" is same as"); - sprintf(msg, - " C function name '%s' in directory: %s\n", - model_info[j].cfunc_name, - model_info[j].path_name); - print_error(msg); + print_error(" C function name '%s' in directory: %s\n", + model_info[j].cfunc_name, + model_info[j].path_name); } } @@ -716,10 +693,8 @@ static Status_t check_uniqueness( for(j = 0; j < numUDNidentifiers; j++) { if(strcmp(node_info[i].node_name, UDNidentifier[j]) == 0) { all_unique = FALSE; - sprintf(msg, - "ERROR - Node type '%s' is same as internal node type\n", - node_info[i].node_name); - print_error(msg); + print_error("ERROR - Node type '%s' is same as internal node type\n", + node_info[i].node_name); } } @@ -739,17 +714,13 @@ static Status_t check_uniqueness( all_unique = FALSE; node_info[i].unique = FALSE; node_info[j].unique = FALSE; - sprintf(msg, - "ERROR - Node type '%s' in directory: %s", - node_info[i].node_name, - node_info[i].path_name); - print_error(msg); + print_error("ERROR - Node type '%s' in directory: %s", + node_info[i].node_name, + node_info[i].path_name); print_error(" is same as"); - sprintf(msg, - " node type '%s' in directory: %s\n", - node_info[j].node_name, - node_info[j].path_name); - print_error(msg); + print_error(" node type '%s' in directory: %s\n", + node_info[j].node_name, + node_info[j].path_name); } } } @@ -995,7 +966,6 @@ static Status_t read_udn_type_name( ) { FILE *fp; /* file pointer for opened file */ - /*char msg[MAX_PATH_LEN+257];*/ /* space for an error message */ Boolean_t found; /* true if name found successfully */ Boolean_t in_struct; /* true if found struct with name */ char name[MAX_NAME_LEN + 1]; /* temporary storage for name read */ diff --git a/src/xspice/cmpp/pp_mod.c b/src/xspice/cmpp/pp_mod.c index 0f9a1de44..5397830a4 100644 --- a/src/xspice/cmpp/pp_mod.c +++ b/src/xspice/cmpp/pp_mod.c @@ -115,7 +115,6 @@ void preprocess_mod_file ( Ifs_Table_t ifs_table; /* info read from ifspec.ifs file */ Status_t status; /* Return status */ - char error_str[200]; char output_filename[200]; /* @@ -130,9 +129,7 @@ void preprocess_mod_file ( mod_yyin = fopen_with_path (filename, "r"); if (mod_yyin == NULL) { - sprintf(error_str, "ERROR - Could not open input .mod file: %s", - filename); - print_error(error_str); + print_error("ERROR - Could not open input .mod file: %s", filename); exit(1); } @@ -142,9 +139,7 @@ void preprocess_mod_file ( mod_yyout = fopen_with_path (output_filename, "w"); if (mod_yyout == NULL) { - sprintf(error_str, "ERROR - Could not open output .c: %s", - output_filename); - print_error(error_str); + print_error("ERROR - Could not open output .c : %s", output_filename); exit(1); } @@ -160,8 +155,7 @@ void preprocess_mod_file ( mod_yylineno = 1; if (mod_yyparse() || (mod_num_errors > 0)) { - sprintf (error_str, "Error parsing .mod file: \"%s\"", filename); - print_error (error_str); + print_error("Error parsing .mod file: \"%s\"", filename); unlink (output_filename); exit (1); } diff --git a/src/xspice/cmpp/read_ifs.c b/src/xspice/cmpp/read_ifs.c index dc11fec0e..6994a7576 100644 --- a/src/xspice/cmpp/read_ifs.c +++ b/src/xspice/cmpp/read_ifs.c @@ -95,8 +95,6 @@ Status_t read_ifs_file( FILE *fp; /* Ifs file pointer */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ - Status_t status; /* returned status from function */ @@ -106,8 +104,7 @@ Status_t read_ifs_file( if(fp == NULL) { perror (prog_name); - sprintf(msg, "ERROR - File not found: %s", filename); - print_error(msg); + print_error("ERROR - File not found: %s", filename); return(ERROR); } diff --git a/src/xspice/cmpp/util.c b/src/xspice/cmpp/util.c index a335ade8c..35e94770f 100644 --- a/src/xspice/cmpp/util.c +++ b/src/xspice/cmpp/util.c @@ -42,6 +42,7 @@ NON-STANDARD FEATURES #include #include #include +#include #include @@ -62,10 +63,16 @@ void init_error (char *program_name) /* Print an error message to stderr */ -void print_error( - char *msg) /* The message to write */ +void print_error(const char *fmt, ...) { - fprintf(stderr, "%s: %s\n", prog_name, msg); + va_list ap; + va_start(ap, fmt); + + fprintf(stderr, "%s: ", prog_name); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + + va_end(ap); } diff --git a/src/xspice/cmpp/writ_ifs.c b/src/xspice/cmpp/writ_ifs.c index 2020db90e..3afd49902 100644 --- a/src/xspice/cmpp/writ_ifs.c +++ b/src/xspice/cmpp/writ_ifs.c @@ -114,7 +114,6 @@ Status_t write_ifs_c_file( Ifs_Table_t *ifs_table) /* Table of Interface Specification data */ { FILE *fp; /* File pointer */ - char msg[MAX_PATH_LEN+257]; /* space for an error message */ int int_status; /* returned status from fclose */ @@ -123,8 +122,7 @@ Status_t write_ifs_c_file( fp = fopen_with_path(filename, "w"); if(fp == NULL) { - sprintf(msg, "ERROR - Can't create file: %s", filename); - print_error(msg); + print_error("ERROR - Can't create file: %s", filename); return(ERROR); }