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.
This commit is contained in:
Holger Vogt 2022-10-09 10:11:23 +02:00
parent dcb3bf0f8b
commit 317e5a3d99
2 changed files with 32 additions and 5 deletions

View File

@ -1172,9 +1172,23 @@ int main(int argc, char **argv)
else { else {
if (readinit) { if (readinit) {
/* load user's initialisation file /* load user's initialisation file
try accessing the initialisation file in the current directory try accessing the initialisation file .spiceinit in a user provided
if that fails try the alternate name */ 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 { 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) { if (read_initialisation_file("", INITSTR) != FALSE) {
break; break;
} }

View File

@ -927,10 +927,23 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi
} }
#else /* ~ HAVE_PWD_H */ #else /* ~ HAVE_PWD_H */
/* load user's initialisation file /* load user's initialisation file
try accessing the initialisation file .spiceinit in the current directory try accessing the initialisation file .spiceinit in a user provided
if that fails try the alternate name spice.rc, then look into the HOME path read from environmental variable SPICE_USERINIT_DIR,
directory, then into USERPROFILE */ if that fails try the alternate name spice.rc, then look into
the current directory, then the HOME directory, then into USERPROFILE */
do { 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) { if (read_initialisation_file("", INITSTR) != FALSE) {
break; break;
} }