prepare the xspice cmpp processor for build in a separate directory

This commit is contained in:
rlar 2011-01-25 17:39:23 +00:00
parent d0392a026b
commit 3fec598934
7 changed files with 45 additions and 12 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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",

View File

@ -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);

View File

@ -41,6 +41,7 @@ NON-STANDARD FEATURES
#include "cmpp.h"
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@ -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);
}

View File

@ -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);