diff --git a/src/main.c b/src/main.c index b4c64daf1..d2a4c6735 100644 --- a/src/main.c +++ b/src/main.c @@ -1252,11 +1252,30 @@ int main(int argc, char **argv) else { if (readinit) { /* load user's initialisation file - 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 */ + try accessing the initialisation file .spiceinit + (If it fails, try the alternate name spice.rc): + - in the directory from where the netlist has been loaded + - in a user provided path read from environmental variable SPICE_USERINIT_DIR, + - in the current directory, + - in the the HOME directory, + - in the USERPROFILE directory. */ do { + { + if (optind <= argc) { + char* inpath = ngdirname(argv[optind]); + if (inpath) { + if (read_initialisation_file(inpath, INITSTR) != FALSE) { + FREE(inpath); + break; + } + if (read_initialisation_file(inpath, ALT_INITSTR) != FALSE) { + FREE(inpath); + break; + } + FREE(inpath); + } + } + } { const char* const userinit = getenv("SPICE_USERINIT_DIR"); if (userinit) { diff --git a/src/sharedspice.c b/src/sharedspice.c index a89faaa09..f48d96323 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -975,13 +975,26 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi } #else /* ~ HAVE_PWD_H */ /* load user's initialisation file - 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. - Don't read .spiceinit, if ngSpice_nospiceinit() has been called. */ + try accessing the initialisation file .spiceinit + (If it fails, try the alternate name spice.rc): + - in the directory Infile_Path received from the caller (sent before initialization) + - in a user provided path read from environmental variable SPICE_USERINIT_DIR, + - in the current directory, + - in the the HOME directory, + - in the USERPROFILE directory. + Don't read .spiceinit, if ngSpice_nospiceinit() has been called. */ if (!cp_getvar("no_spiceinit", CP_BOOL, NULL, 0)) { do { + { + if (Infile_Path) { + if (read_initialisation_file(Infile_Path, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(Infile_Path, ALT_INITSTR) != FALSE) { + break; + } + } + } { const char* const userinit = getenv("SPICE_USERINIT_DIR"); if (userinit) {