From e58de3187cb6dfcd8eb18c0048b5212fa2677466 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 18 Jan 2014 19:17:38 +0100 Subject: [PATCH] make use of Infile_Path in function open_with_path. We may now use the following sequence for a file search from a code model: Infile_Path/ NGSPICE_INPUT_DIR/, where the path is given by the environmental variable , where the path is the current directory --- src/xspice/icm/dlmain.c | 55 ++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/src/xspice/icm/dlmain.c b/src/xspice/icm/dlmain.c index 70c1b3776..47e2d1fd2 100644 --- a/src/xspice/icm/dlmain.c +++ b/src/xspice/icm/dlmain.c @@ -14,6 +14,10 @@ #include "cmextrn.h" #include "udnextrn.h" +#include +#include + + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Do not modify anything below this line @@ -356,6 +360,10 @@ Complex_t cm_complex_divide(Complex_t x, Complex_t y) { return (coreitf->dllitf_cm_complex_divide)(x,y); } +char * cm_get_path(void) { + return (coreitf->dllitf_cm_get_path)(); +} + FILE * cm_stream_out(void) { return (coreitf->dllitf_cm_stream_out)(); } @@ -396,28 +404,51 @@ void txfree(void *ptr) { (coreitf->dllitf_txfree)(ptr); } -#include -#include + +/* +fopen_with_path() +Opens an input file . Called from d_state, file_source, d_source. +Firstly retrieves the path Infile_Path of the ngspice input netlist. +Then searches for (and opens) an a sequence from +Infile_Path/ +NGSPICE_INPUT_DIR/, where the path is given by the environmental variable +, where the path is the current directory +*/ #define MAX_PATH_LEN 1024 FILE *fopen_with_path(const char *path, const char *mode) { char buf[MAX_PATH_LEN+1]; + FILE *fp; - if(path[0] != '/') { - const char *x = getenv("ngspice_vpath"); + if((path[0] != '/') && (path[1] != ':')) { +// const char *x = getenv("ngspice_vpath"); + const char *x = cm_get_path(); if(x) { - char *a; - strcpy(buf, x); - a = strrchr(buf, '/'); - if(a && a[1] == '\0') - a[0] = '\0'; + strncpy(buf, x, MAX_PATH_LEN); strcat(buf, "/"); strcat(buf, path); - path = buf; + fp = fopen(buf, mode); + if (fp) + return fp; + else { + char *y = getenv( "NGSPICE_INPUT_DIR" ); + if (y && *y) { + char *a; + strncpy(buf, y, MAX_PATH_LEN); + a = strrchr(buf, '/'); + if(a && a[1] == '\0') + a[0] = '\0'; + strcat(buf, "/"); + strcat(buf, path); + fp = fopen(buf, mode); + if (fp) + return fp; + } + } } } - - return fopen(path, mode); + fp = fopen(path, mode); + return fp; }