cmpp, rewrite for proper report of error locations

This commit is contained in:
rlar 2012-12-01 22:46:53 +01:00
parent 348e3976e7
commit 6260fd16ec
6 changed files with 55 additions and 49 deletions

View File

@ -286,9 +286,9 @@ void print_error(const char *fmt, ...);
void str_to_lower(char *s);
Status_t read_ifs_file(char *filename, int mode, Ifs_Table_t *ifs_table);
Status_t read_ifs_file(const char *filename, int mode, Ifs_Table_t *ifs_table);
Status_t write_ifs_c_file(char *filename, Ifs_Table_t *ifs_table);
Status_t write_ifs_c_file(const char *filename, Ifs_Table_t *ifs_table);
FILE *fopen_with_path(const char *path, const char *mode);
FILE *fopen_cmpp(const char **path_p, const char *mode);

View File

@ -96,7 +96,7 @@ 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,
int num_nodes, Node_Info_t *node_info);
static Status_t read_udn_type_name(char *path, char **node_name);
static Status_t read_udn_type_name(const char *path, char **node_name);
/* *********************************************************************** */
@ -230,14 +230,14 @@ static Status_t read_modpath(
int len;
int line_num;
static char *filename = MODPATH_FILENAME;
const char *filename = MODPATH_FILENAME;
/* Initialize number of models to zero in case of error */
*num_models = 0;
/* Open the model pathname file */
fp = fopen_with_path(filename, "r");
fp = fopen_cmpp(&filename, "r");
if(fp == NULL) {
print_error("ERROR - File not found: %s", filename);
@ -346,14 +346,14 @@ static Status_t read_udnpath(
int len;
int line_num;
static char *filename = UDNPATH_FILENAME;
const char *filename = UDNPATH_FILENAME;
/* Initialize number of nodes to zero in case of error */
*num_nodes = 0;
/* Open the node pathname file */
fp = fopen_with_path(filename, "r");
fp = fopen_cmpp(&filename, "r");
/* For backward compatibility, return with WARNING only if file not found */
if(fp == NULL) {
@ -756,11 +756,12 @@ static Status_t write_CMextrn(
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing CMextrn.h */
const char *filename = "cmextrn.h";
/* Open the file to be written */
fp = fopen_with_path("cmextrn.h", "w");
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening CMextrn.h for write");
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
}
@ -796,11 +797,12 @@ static Status_t write_CMinfo(
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing CMinfo.h */
const char *filename = "cminfo.h";
/* Open the file to be written */
fp = fopen_with_path("cminfo.h", "w");
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening CMinfo.h for write");
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
}
@ -840,11 +842,12 @@ static Status_t write_UDNextrn(
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing UDNextrn.h */
const char *filename = "udnextrn.h";
/* Open the file to be written */
fp = fopen_with_path("udnextrn.h", "w");
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening UDNextrn.h for write");
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
}
@ -882,11 +885,12 @@ static Status_t write_UDNinfo(
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing UDNinfo.h */
const char *filename = "udninfo.h";
/* Open the file to be written */
fp = fopen_with_path("udninfo.h", "w");
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening UDNinfo.h for write");
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
}
@ -921,11 +925,12 @@ static Status_t write_objects_inc(
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing make_include */
const char *filename = "objects.inc";
/* Open the file to be written */
fp = fopen_with_path("objects.inc", "w");
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening objects.inc file for write");
print_error("ERROR - Problems opening %s for write", filename);
return(ERROR);
}
@ -961,7 +966,7 @@ member of the structure.
*/
static Status_t read_udn_type_name(
char *path, /* the path to the node definition file */
const char *path, /* the path to the node definition file */
char **node_name /* the node type name found in the file */
)
{
@ -975,7 +980,7 @@ static Status_t read_udn_type_name(
static char *struct_type = "Evt_Udn_Info_t";
/* Open the file from which the node type name will be read */
fp = fopen_with_path(path, "r");
fp = fopen_cmpp(&path, "r");
if(fp == NULL)
return(ERROR);

View File

@ -72,23 +72,20 @@ extern int mod_num_errors;
extern Ifs_Table_t *mod_ifs_table;
extern char *current_filename;
extern const char *current_filename;
extern char *prog_name;
/*---------------------------------------------------------------------------*/
static void change_extension (char *filename, char *ext, char *new_filename)
static char *change_extension (char *filename, char *ext)
{
int i = (int) strlen (filename);
strcpy (new_filename, filename);
char *p = strrchr(filename, '.');
size_t prefix_len = p ? (size_t) (p-filename+1) : strlen(filename);
char *new_filename = malloc(prefix_len + strlen(ext) + 1);
for (; i >= 0; i--) {
if (new_filename[i] == '.') {
new_filename[i+1] = '\0';
break;
}
}
strcat (new_filename, ext);
strncpy(new_filename, filename, prefix_len);
strcpy(new_filename+prefix_len, ext);
return new_filename;
}
/*---------------------------------------------------------------------------*/
@ -115,7 +112,7 @@ void preprocess_mod_file (
Ifs_Table_t ifs_table; /* info read from ifspec.ifs file */
Status_t status; /* Return status */
char output_filename[200];
const char *output_filename;
/*
* Read the entire ifspec.ifs file and load the data into ifs_table
@ -127,35 +124,35 @@ void preprocess_mod_file (
exit(1);
}
mod_yyin = fopen_with_path (filename, "r");
current_filename = filename;
mod_yyin = fopen_cmpp (&current_filename, "r");
if (mod_yyin == NULL) {
print_error("ERROR - Could not open input .mod file: %s", filename);
print_error("ERROR - Could not open input .mod file: %s", current_filename);
exit(1);
}
current_filename = filename;
change_extension (filename, "c", output_filename);
mod_yyout = fopen_with_path (output_filename, "w");
output_filename = change_extension (filename, "c");
mod_yyout = fopen_cmpp (&output_filename, "w");
if (mod_yyout == NULL) {
print_error("ERROR - Could not open output .c : %s", output_filename);
print_error("ERROR - Could not open output .c file: %s", output_filename);
exit(1);
}
mod_ifs_table = &ifs_table;
mod_num_errors = 0;
fprintf (mod_yyout, "#line 1 \"%s\"\n", filename);
fprintf (mod_yyout, "#line 1 \"%s\"\n", current_filename);
fprintf (mod_yyout, "#include \"ngspice/cm.h\"\n");
fprintf (mod_yyout, "extern void %s(Mif_Private_t *);\n",
ifs_table.name.c_fcn_name);
fprintf (mod_yyout, "#line 1 \"%s\"\n", filename);
fprintf (mod_yyout, "#line 1 \"%s\"\n", current_filename);
mod_yylineno = 1;
if (mod_yyparse() || (mod_num_errors > 0)) {
print_error("Error parsing .mod file: \"%s\"", filename);
print_error("Error parsing .mod file: \"%s\"", current_filename);
unlink (output_filename);
exit (1);
}

View File

@ -63,7 +63,7 @@ extern Boolean_t parser_just_names;
static Status_t read_ifs_table(FILE *fp, int mode, Ifs_Table_t *ifs_table);
char *current_filename;
const char *current_filename;
/* *********************************************************************** */
@ -88,7 +88,7 @@ from read_ifs_table(), the file is closed.
Status_t read_ifs_file(
char *filename, /* File to read */
const char *filename, /* File to read */
int mode, /* Get names only or get everything? */
Ifs_Table_t *ifs_table) /* Table to put info in */
{
@ -100,7 +100,7 @@ Status_t read_ifs_file(
/* Open the ifs file for read access */
fp = fopen_with_path(filename, "r");
fp = fopen_cmpp(&filename, "r");
if(fp == NULL) {
perror (prog_name);

View File

@ -91,8 +91,10 @@ void str_to_lower(char *s)
}
FILE *fopen_with_path(const char *path, const char *mode)
FILE *fopen_cmpp(const char **path_p, const char *mode)
{
const char *path = *path_p;
char buf[MAX_PATH_LEN+1];
if(path[0] != '/') {
@ -109,5 +111,7 @@ FILE *fopen_with_path(const char *path, const char *mode)
}
}
*path_p = strdup(path);
return fopen(path, mode);
}

View File

@ -110,7 +110,7 @@ The output file is then closed.
Status_t write_ifs_c_file(
char *filename, /* File to write to */
const char *filename, /* File to write to */
Ifs_Table_t *ifs_table) /* Table of Interface Specification data */
{
FILE *fp; /* File pointer */
@ -119,7 +119,7 @@ Status_t write_ifs_c_file(
/* Open the ifspec.c file for write access */
fp = fopen_with_path(filename, "w");
fp = fopen_cmpp(&filename, "w");
if(fp == NULL) {
print_error("ERROR - Can't create file: %s", filename);