From 7f486febe9310578e55204b107400073798b6d0c Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 9 Oct 2022 10:11:23 +0200 Subject: [PATCH] Search for .spiceinit (or spice.rc) firstly in a user defined directory, when the directory path is set in the environmental variable SPICE_USERINIT_DIR. If not found then search in the current directory, then in HOME, then in USERPROFILE. --- src/main.c | 18 ++++++++++++++++-- src/sharedspice.c | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index b25ec98dd..fb019df77 100644 --- a/src/main.c +++ b/src/main.c @@ -1172,9 +1172,23 @@ int main(int argc, char **argv) else { if (readinit) { /* load user's initialisation file - try accessing the initialisation file in the current directory - if that fails try the alternate name */ + try accessing the initialisation file .spiceinit in a user provided + path read from environmental variable SPICE_USERINIT_DIR, + if that fails try the alternate name spice.rc, then look into + the current directory, then the HOME directory, then into USERPROFILE */ do { + { + const char* const userinit = getenv("SPICE_USERINIT_DIR"); + if (userinit) { + if (read_initialisation_file(userinit, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(userinit, ALT_INITSTR) != FALSE) { + break; + } + } + } + if (read_initialisation_file("", INITSTR) != FALSE) { break; } diff --git a/src/sharedspice.c b/src/sharedspice.c index bdf293362..7edb2d2bc 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -927,10 +927,23 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi } #else /* ~ HAVE_PWD_H */ /* load user's initialisation file - try accessing the initialisation file .spiceinit in the current directory - if that fails try the alternate name spice.rc, then look into the HOME - directory, then into USERPROFILE */ + try accessing the initialisation file .spiceinit in a user provided + path read from environmental variable SPICE_USERINIT_DIR, + if that fails try the alternate name spice.rc, then look into + the current directory, then the HOME directory, then into USERPROFILE */ do { + { + const char* const userinit = getenv("SPICE_USERINIT_DIR"); + if (userinit) { + if (read_initialisation_file(userinit, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(userinit, ALT_INITSTR) != FALSE) { + break; + } + } + } + if (read_initialisation_file("", INITSTR) != FALSE) { break; }