diff --git a/src/include/ngspice/sharedspice.h b/src/include/ngspice/sharedspice.h index f97e0d8c6..ec2f8d2d5 100644 --- a/src/include/ngspice/sharedspice.h +++ b/src/include/ngspice/sharedspice.h @@ -3,12 +3,21 @@ /* Modified BSD license */ /* -Interface between a calling program (caller) and ngspice.dll (ngspice.so) +Interface between a calling program (caller) and ngspice.dll (libngspice.so) + ** ngSpice_nospinit(void) Set variable no_spinit, if reading the initialization file 'spinit' is not wanted. To be called before ngSpice_Init() +** +ngSpice_nospiceinit(void) +Set variable no_spiceinit, if reading the user defined initialization file +'.spiceinit' is not wanted. +To be called before ngSpice_Init(). +Use with care, as this removes the last chance to send preparative commands +before the netlist is loaded. Then use the the caller to send such commands. + ** ngSpice_Init(SendChar*, SendStat*, ControlledExit*, SendData*, SendInitData*, BGThreadRunning*, void*) @@ -453,6 +462,10 @@ NG_BOOL ngSpice_SetBkpt(double time); IMPEXP int ngSpice_nospinit(void); +/* Set variable no_spiceinit, if reading '.spiceinit' is not wanted. */ +IMPEXP +int ngSpice_nospiceinit(void); + #ifdef __cplusplus } #endif diff --git a/src/sharedspice.c b/src/sharedspice.c index a7d858414..ae2d48adf 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -814,6 +814,16 @@ ngSpice_nospinit(void) return 0; } +/* Set variable no_spiceinit, if reading '.spiceinit' is not wanted. */ +IMPEXP +int +ngSpice_nospiceinit(void) +{ + bool t = TRUE; + cp_vset("no_spicenit", CP_BOOL, &t); + return 0; +} + /* Initialise external voltage source and synchronization */ IMPEXP int @@ -968,55 +978,61 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi tfree(s); } #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 */ - 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; + /* 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. */ + if (!cp_getvar("no_spiceinit", CP_BOOL, NULL, 0)) { + 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; - } - if (read_initialisation_file("", ALT_INITSTR) != FALSE) { - break; - } + if (read_initialisation_file("", INITSTR) != FALSE) { + break; + } + if (read_initialisation_file("", ALT_INITSTR) != FALSE) { + break; + } - { - const char* const home = getenv("HOME"); - if (home) { - if (read_initialisation_file(home, INITSTR) != FALSE) { - break; - } - if (read_initialisation_file(home, ALT_INITSTR) != FALSE) { - break; + { + const char* const home = getenv("HOME"); + if (home) { + if (read_initialisation_file(home, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(home, ALT_INITSTR) != FALSE) { + break; + } } } - } - { - const char* const usr = getenv("USERPROFILE"); - if (usr) { - if (read_initialisation_file(usr, INITSTR) != FALSE) { - break; - } - if (read_initialisation_file(usr, ALT_INITSTR) != FALSE) { - break; + { + const char* const usr = getenv("USERPROFILE"); + if (usr) { + if (read_initialisation_file(usr, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(usr, ALT_INITSTR) != FALSE) { + break; + } } } - } - } while (0); /* end of case that init file is read */ + } while (0); /* end of case that init file is read */ + } + else { + fprintf(stdout, "Note: .spiceinit is ignored, because ngSpice_nospiceinit() has been called.\n"); + } #endif /* ~ HAVE_PWD_H */