Guard reading and executing spinit by variable no_spinit.

This commit is contained in:
Holger Vogt 2024-04-03 17:06:26 +02:00
parent 51ab1499ba
commit 8ec50d05ff
1 changed files with 51 additions and 43 deletions

View File

@ -265,63 +265,71 @@ ft_cpinit(void)
wl_free(wl); wl_free(wl);
} }
/* Now source the standard startup file spinit or tclspinit. */ /* Now source the standard startup file spinit or tclspinit
if no_spinit is not set . */
/* jump over leading spaces */ if (!cp_getvar("no_spinit", CP_BOOL, NULL, 0)) {
for (copys = s = cp_tildexpand(Lib_Path); copys && *copys; ) { /* jump over leading spaces */
s = skip_ws(s); for (copys = s = cp_tildexpand(Lib_Path); copys && *copys; ) {
/* copy s into buf until end of s, r is the actual position in buf */ s = skip_ws(s);
int ii; /* copy s into buf until end of s, r is the actual position in buf */
for (r = buf, ii = 0; *s; r++, s++, ii++) { int ii;
*r = *s; for (r = buf, ii = 0; *s; r++, s++, ii++) {
if (ii > 500) { *r = *s;
fprintf(stderr, "Warning: spinit path is too long.\n"); if (ii > 500) {
break; fprintf(stderr, "Warning: spinit path is too long.\n");
break;
}
} }
} tfree(copys);
tfree(copys); /* add a path separator to buf at actual position */
/* add a path separator to buf at actual position */ (void)strcpy(r, DIR_PATHSEP);
(void) strcpy(r, DIR_PATHSEP);
#ifdef TCL_MODULE #ifdef TCL_MODULE
/* add "tclspinit" to buf after actual position */ /* add "tclspinit" to buf after actual position */
(void) strcat(r, "tclspinit"); (void) strcat(r, "tclspinit");
#else #else
/* add "spinit" to buf after actual position */ /* add "spinit" to buf after actual position */
(void) strcat(r, "spinit"); (void)strcat(r, "spinit");
#endif #endif
if ((fp = fopen(buf, "r")) != NULL) { if ((fp = fopen(buf, "r")) != NULL) {
cp_interactive = FALSE; cp_interactive = FALSE;
inp_spsource(fp, TRUE, buf, FALSE); inp_spsource(fp, TRUE, buf, FALSE);
cp_interactive = TRUE; cp_interactive = TRUE;
found = TRUE; found = TRUE;
break; break;
#if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER) #if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER)
/* search in local directory where ngspice.exe resides */ /* search in local directory where ngspice.exe resides */
#if defined TCL_MODULE #if defined TCL_MODULE
} else if ((fp = fopen("./tclspinit", "r")) != NULL) { }
else if ((fp = fopen("./tclspinit", "r")) != NULL) {
#else #else
} else if ((fp = fopen("./spinit", "r")) != NULL) { }
else if ((fp = fopen("./spinit", "r")) != NULL) {
#endif #endif
cp_interactive = FALSE; cp_interactive = FALSE;
inp_spsource(fp, TRUE, buf, FALSE); inp_spsource(fp, TRUE, buf, FALSE);
cp_interactive = TRUE; cp_interactive = TRUE;
found = TRUE; found = TRUE;
break; break;
#endif
}
else if (ft_controldb) {
fprintf(cp_err, "Warning: can't open \"%s\".\n", buf);
}
}
if (!found) {
#if defined TCL_MODULE
fprintf(cp_err, "Warning: can't find the initialization file tclspinit.\n");
#else
fprintf(cp_err, "Warning: can't find the initialization file spinit.\n");
#endif #endif
} else if (ft_controldb) {
fprintf(cp_err, "Note: can't open \"%s\".\n", buf);
} }
} }
else {
if (!found) { fprintf(cp_out, "Note: Start without reading file 'spinit'.\n");
#if defined TCL_MODULE
fprintf(cp_err, "Note: can't find the initialization file tclspinit.\n");
#else
fprintf(cp_err, "Note: can't find the initialization file spinit.\n");
#endif
} }
} }