From 3fec5989345c955aa482ea635506e65e1c8a5598 Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 25 Jan 2011 17:39:23 +0000 Subject: [PATCH] prepare the xspice cmpp processor for build in a separate directory --- ChangeLog | 11 +++++++++++ src/xspice/cmpp/cmpp.h | 1 + src/xspice/cmpp/pp_lst.c | 16 ++++++++-------- src/xspice/cmpp/pp_mod.c | 4 ++-- src/xspice/cmpp/read_ifs.c | 2 +- src/xspice/cmpp/util.c | 21 +++++++++++++++++++++ src/xspice/cmpp/writ_ifs.c | 2 +- 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c9d5ffc0..1acc2a84b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-01-25 Robert Larice + * src/xspice/cmpp/cmpp.h , + * src/xspice/cmpp/pp_lst.c , + * src/xspice/cmpp/pp_mod.c , + * src/xspice/cmpp/read_ifs.c , + * src/xspice/cmpp/util.c , + * src/xspice/cmpp/writ_ifs.c : + prepare the xspice cmpp processor for build in a separate directory + Two environment variables are introduced to augment the the hardwired + filenames with directory names + 2011-01-25 Robert Larice * src/frontend/Makefile.am , * src/spicelib/devices/adms/admst/ngspiceMakefile.am.xml diff --git a/src/xspice/cmpp/cmpp.h b/src/xspice/cmpp/cmpp.h index 925150716..594b22b33 100755 --- a/src/xspice/cmpp/cmpp.h +++ b/src/xspice/cmpp/cmpp.h @@ -285,3 +285,4 @@ Status_t read_ifs_file(char *filename, int mode, Ifs_Table_t *ifs_table); Status_t write_ifs_c_file(char *filename, Ifs_Table_t *ifs_table); +FILE *fopen_with_path(const char *path, const char *mode); diff --git a/src/xspice/cmpp/pp_lst.c b/src/xspice/cmpp/pp_lst.c index 91a80a629..a76f39f17 100755 --- a/src/xspice/cmpp/pp_lst.c +++ b/src/xspice/cmpp/pp_lst.c @@ -238,7 +238,7 @@ static Status_t read_modpath( *num_models = 0; /* Open the model pathname file */ - fp = fopen(filename, "r"); + fp = fopen_with_path(filename, "r"); if(fp == NULL) { sprintf(msg, "ERROR - File not found: %s", filename); @@ -358,7 +358,7 @@ static Status_t read_udnpath( *num_nodes = 0; /* Open the node pathname file */ - fp = fopen(filename, "r"); + fp = fopen_with_path(filename, "r"); /* For backward compatibility, return with WARNING only if file not found */ if(fp == NULL) { @@ -787,7 +787,7 @@ static Status_t write_CMextrn( /* Open the file to be written */ - fp = fopen("cmextrn.h", "w"); + fp = fopen_with_path("cmextrn.h", "w"); if(fp == NULL) { print_error("ERROR - Problems opening CMextrn.h for write"); return(ERROR); @@ -827,7 +827,7 @@ static Status_t write_CMinfo( /* Open the file to be written */ - fp = fopen("cminfo.h", "w"); + fp = fopen_with_path("cminfo.h", "w"); if(fp == NULL) { print_error("ERROR - Problems opening CMinfo.h for write"); return(ERROR); @@ -871,7 +871,7 @@ static Status_t write_UDNextrn( /* Open the file to be written */ - fp = fopen("udnextrn.h", "w"); + fp = fopen_with_path("udnextrn.h", "w"); if(fp == NULL) { print_error("ERROR - Problems opening UDNextrn.h for write"); return(ERROR); @@ -913,7 +913,7 @@ static Status_t write_UDNinfo( /* Open the file to be written */ - fp = fopen("udninfo.h", "w"); + fp = fopen_with_path("udninfo.h", "w"); if(fp == NULL) { print_error("ERROR - Problems opening UDNinfo.h for write"); return(ERROR); @@ -952,7 +952,7 @@ static Status_t write_objects_inc( /* Open the file to be written */ - fp = fopen("objects.inc", "w"); + fp = fopen_with_path("objects.inc", "w"); if(fp == NULL) { print_error("ERROR - Problems opening objects.inc file for write"); return(ERROR); @@ -1005,7 +1005,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(path, "r"); + fp = fopen_with_path(path, "r"); if(fp == NULL) return(ERROR); diff --git a/src/xspice/cmpp/pp_mod.c b/src/xspice/cmpp/pp_mod.c index 1019ed7a1..150966c08 100755 --- a/src/xspice/cmpp/pp_mod.c +++ b/src/xspice/cmpp/pp_mod.c @@ -128,7 +128,7 @@ void preprocess_mod_file ( exit(1); } - mod_yyin = fopen (filename, "r"); + mod_yyin = fopen_with_path (filename, "r"); if (mod_yyin == NULL) { sprintf(error_str, "ERROR - Could not open input .mod file: %s", filename); @@ -139,7 +139,7 @@ void preprocess_mod_file ( current_filename = filename; change_extension (filename, "c", output_filename); - mod_yyout = fopen (output_filename, "w"); + mod_yyout = fopen_with_path (output_filename, "w"); if (mod_yyout == NULL) { sprintf(error_str, "ERROR - Could not open output .c: %s", diff --git a/src/xspice/cmpp/read_ifs.c b/src/xspice/cmpp/read_ifs.c index 87786f95c..dc11fec0e 100755 --- a/src/xspice/cmpp/read_ifs.c +++ b/src/xspice/cmpp/read_ifs.c @@ -102,7 +102,7 @@ Status_t read_ifs_file( /* Open the ifs file for read access */ - fp = fopen(filename, "r"); + fp = fopen_with_path(filename, "r"); if(fp == NULL) { perror (prog_name); diff --git a/src/xspice/cmpp/util.c b/src/xspice/cmpp/util.c index e092ceef3..a335ade8c 100755 --- a/src/xspice/cmpp/util.c +++ b/src/xspice/cmpp/util.c @@ -41,6 +41,7 @@ NON-STANDARD FEATURES #include "cmpp.h" #include #include +#include #include @@ -83,3 +84,23 @@ void str_to_lower(char *s) } +FILE *fopen_with_path(const char *path, const char *mode) +{ + char buf[MAX_PATH_LEN+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; + } else { + path = NULL; + } + } + } + + return fopen(path, mode); +} diff --git a/src/xspice/cmpp/writ_ifs.c b/src/xspice/cmpp/writ_ifs.c index 3e444846c..b7df48380 100755 --- a/src/xspice/cmpp/writ_ifs.c +++ b/src/xspice/cmpp/writ_ifs.c @@ -120,7 +120,7 @@ Status_t write_ifs_c_file( /* Open the ifspec.c file for write access */ - fp = fopen(filename, "w"); + fp = fopen_with_path(filename, "w"); if(fp == NULL) { sprintf(msg, "ERROR - Can't create file: %s", filename);