From 1f5de325120fdc38079b9ecdc6437246c7a589e8 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 18 Jan 2014 19:10:29 +0100 Subject: [PATCH] global variable Infile_Path, which contains the input netlist file path --- src/frontend/inp.c | 11 +++++++++-- src/include/ngspice/ngspice.h | 1 + src/main.c | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 789d0a4b4..8fd0b0a48 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -1146,7 +1146,7 @@ com_source(wordlist *wl) FILE *fp, *tp; char buf[BSIZE_SP]; bool inter; - char *tempfile = NULL; + char *tempfile = NULL, *firstfile; wordlist *owl = wl; size_t n; @@ -1154,6 +1154,8 @@ com_source(wordlist *wl) inter = cp_interactive; cp_interactive = FALSE; + firstfile = wl->wl_word; + if (wl->wl_next) { /* There are several files -- put them into a temp file */ tempfile = smktemp("sp"); @@ -1189,8 +1191,13 @@ com_source(wordlist *wl) /* Don't print the title if this is a spice initialisation file. */ if (ft_nutmeg || substring(INITSTR, owl->wl_word) || substring(ALT_INITSTR, owl->wl_word)) inp_spsource(fp, TRUE, tempfile ? NULL : wl->wl_word, FALSE); - else + else { + /* Save path name for use in XSPICE fopen_with_path() */ + if (Infile_Path) + tfree(Infile_Path); + Infile_Path = ngdirname(firstfile); inp_spsource(fp, FALSE, tempfile ? NULL : wl->wl_word, FALSE); + } cp_interactive = inter; if (tempfile) diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index 36e0ff302..dd0f3f69f 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -245,6 +245,7 @@ extern char *Spice_Path; extern char *Help_Path; extern char *Lib_Path; extern char *Inp_Path; +extern char *Infile_Path; #ifdef TCL_MODULE diff --git a/src/main.c b/src/main.c index 0ea88cdc5..1f79e02f8 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,7 @@ #include "spicelib/analysis/analysis.h" #include "misc/ivars.h" #include "misc/misc_time.h" +#include "misc/util.h" #if defined(HAS_WINGUI) || defined(_MSC_VER) || defined(__MINGW32__) # include "misc/mktemp.h" @@ -113,6 +114,8 @@ char *errRtn; /* name of the routine declaring error */ char *errMsg = NULL; /* descriptive message about what went wrong */ char *cp_program; /* program name 'ngspice' */ +char *Infile_Path = NULL; /* Path to netlist input file */ + /* Globals definitions for Machine Accuracy Limits * (needed by CIDER) @@ -1217,6 +1220,9 @@ main(int argc, char **argv) while (optind < argc) { char *arg = argv[optind++]; FILE *tp; + /* Copy the the path of the first filename only */ + if (!Infile_Path) + Infile_Path = ngdirname(arg); /* Copy all the arguments into the temporary file */ tp = fopen(arg, "r");