main.c, emphasize the SETJMP wrapper in ngspice
This commit is contained in:
parent
d0012a124a
commit
0d1e66b7ed
191
src/main.c
191
src/main.c
|
|
@ -1122,140 +1122,143 @@ main(int argc, char **argv)
|
||||||
* build a circuit for this file. If this is in server mode, don't
|
* build a circuit for this file. If this is in server mode, don't
|
||||||
* process any of these args. */
|
* process any of these args. */
|
||||||
|
|
||||||
if (SETJMP(jbuf, 1))
|
if (SETJMP(jbuf, 1)) {
|
||||||
goto evl;
|
|
||||||
|
|
||||||
cp_interactive = FALSE;
|
fprintf(cp_err, "Warning: error executing during ngspice startup.\n");
|
||||||
err = 0;
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
cp_interactive = FALSE;
|
||||||
|
err = 0;
|
||||||
|
|
||||||
#ifdef FastRand
|
#ifdef FastRand
|
||||||
// initialization and seed for FastNorm Gaussian random generator
|
// initialization and seed for FastNorm Gaussian random generator
|
||||||
{
|
{
|
||||||
unsigned int rseed = 66;
|
unsigned int rseed = 66;
|
||||||
initnorm (0, 0);
|
initnorm (0, 0);
|
||||||
if (!cp_getvar("rndseed", CP_NUM, &rseed)) {
|
if (!cp_getvar("rndseed", CP_NUM, &rseed)) {
|
||||||
time_t acttime = time(NULL);
|
time_t acttime = time(NULL);
|
||||||
rseed = (unsigned int) acttime;
|
rseed = (unsigned int) acttime;
|
||||||
|
}
|
||||||
|
initnorm (rseed, 2);
|
||||||
|
fprintf (cp_out, "SoS %f, seed value: %ld\n", renormalize(), rseed);
|
||||||
}
|
}
|
||||||
initnorm (rseed, 2);
|
|
||||||
fprintf (cp_out, "SoS %f, seed value: %ld\n", renormalize(), rseed);
|
|
||||||
}
|
|
||||||
#elif defined (WaGauss)
|
#elif defined (WaGauss)
|
||||||
{
|
{
|
||||||
unsigned int rseed = 66;
|
unsigned int rseed = 66;
|
||||||
if (!cp_getvar("rndseed", CP_NUM, &rseed)) {
|
if (!cp_getvar("rndseed", CP_NUM, &rseed)) {
|
||||||
time_t acttime = time(NULL);
|
time_t acttime = time(NULL);
|
||||||
rseed = (unsigned int) acttime;
|
rseed = (unsigned int) acttime;
|
||||||
|
}
|
||||||
|
srand(rseed);
|
||||||
|
initw();
|
||||||
}
|
}
|
||||||
srand(rseed);
|
|
||||||
initw();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!ft_servermode && !ft_nutmeg) {
|
if (!ft_servermode && !ft_nutmeg) {
|
||||||
|
|
||||||
/* Concatenate all non-option arguments into a temporary file
|
/* Concatenate all non-option arguments into a temporary file
|
||||||
and load that file into the spice core.
|
and load that file into the spice core.
|
||||||
|
|
||||||
The original routine took a special path if there was only
|
The original routine took a special path if there was only
|
||||||
one non-option argument. In that case, it didn't create
|
one non-option argument. In that case, it didn't create
|
||||||
the temporary file but used the original file instead. The
|
the temporary file but used the original file instead. The
|
||||||
current algorithm is uniform at the expense of a little
|
current algorithm is uniform at the expense of a little
|
||||||
startup time. */
|
startup time. */
|
||||||
|
|
||||||
FILE *tempfile = tmpfile();
|
FILE *tempfile = tmpfile();
|
||||||
|
|
||||||
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
char *tpf = NULL; /* temporary file */
|
char *tpf = NULL; /* temporary file */
|
||||||
char *dname = NULL; /* input file*/
|
char *dname = NULL; /* input file*/
|
||||||
|
|
||||||
/* tmpfile() returns NULL, if in MS Windows as non admin user
|
/* tmpfile() returns NULL, if in MS Windows as non admin user
|
||||||
then we add a tempfile in the local directory */
|
then we add a tempfile in the local directory */
|
||||||
|
|
||||||
if (tempfile == NULL) {
|
|
||||||
tpf = smktemp("sp");
|
|
||||||
tempfile = fopen(tpf, "w+b");
|
|
||||||
if (tempfile == NULL) {
|
if (tempfile == NULL) {
|
||||||
fprintf(stderr, "Could not open a temporary file to save and use optional arguments.");
|
tpf = smktemp("sp");
|
||||||
sp_shutdown(EXIT_BAD);
|
tempfile = fopen(tpf, "w+b");
|
||||||
|
if (tempfile == NULL) {
|
||||||
|
fprintf(stderr, "Could not open a temporary file to save and use optional arguments.");
|
||||||
|
sp_shutdown(EXIT_BAD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!tempfile) {
|
if(!tempfile) {
|
||||||
perror("tmpfile()");
|
perror("tmpfile()");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
|
|
||||||
if (optind == argc && !istty)
|
|
||||||
append_to_stream(tempfile, stdin);
|
|
||||||
|
|
||||||
while (optind < argc) {
|
|
||||||
char *arg = argv[optind++];
|
|
||||||
FILE *tp;
|
|
||||||
|
|
||||||
/* Copy all the arguments into the temporary file */
|
|
||||||
tp = fopen(arg, "r");
|
|
||||||
if (!tp) {
|
|
||||||
char *lbuffer = getenv("NGSPICE_INPUT");
|
|
||||||
if (lbuffer && *lbuffer) {
|
|
||||||
char *p =
|
|
||||||
TMALLOC(char, strlen(lbuffer) + strlen(DIR_PATHSEP) + strlen(arg) + 1);
|
|
||||||
sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, arg);
|
|
||||||
tp = fopen(p, "r");
|
|
||||||
tfree(p);
|
|
||||||
}
|
|
||||||
if (!tp) {
|
|
||||||
perror(arg);
|
|
||||||
err = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optind == argc && !istty)
|
||||||
|
append_to_stream(tempfile, stdin);
|
||||||
|
|
||||||
|
while (optind < argc) {
|
||||||
|
char *arg = argv[optind++];
|
||||||
|
FILE *tp;
|
||||||
|
|
||||||
|
/* Copy all the arguments into the temporary file */
|
||||||
|
tp = fopen(arg, "r");
|
||||||
|
if (!tp) {
|
||||||
|
char *lbuffer = getenv("NGSPICE_INPUT");
|
||||||
|
if (lbuffer && *lbuffer) {
|
||||||
|
char *p =
|
||||||
|
TMALLOC(char, strlen(lbuffer) + strlen(DIR_PATHSEP) + strlen(arg) + 1);
|
||||||
|
sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, arg);
|
||||||
|
tp = fopen(p, "r");
|
||||||
|
tfree(p);
|
||||||
|
}
|
||||||
|
if (!tp) {
|
||||||
|
perror(arg);
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
/* Copy the input file name which otherwise will be lost due to the
|
/* Copy the input file name which otherwise will be lost due to the
|
||||||
temporary file */
|
temporary file */
|
||||||
dname = copy(arg);
|
dname = copy(arg);
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAS_WINDOWS)
|
#if defined(HAS_WINDOWS)
|
||||||
/* write source file name into source window */
|
/* write source file name into source window */
|
||||||
SetSource(dname);
|
SetSource(dname);
|
||||||
/* write source file name into a variable */
|
/* write source file name into a variable */
|
||||||
cp_vset("sourcefile", CP_STRING, dname);
|
cp_vset("sourcefile", CP_STRING, dname);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
append_to_stream(tempfile, tp);
|
append_to_stream(tempfile, tp);
|
||||||
fclose(tp);
|
fclose(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(tempfile, 0L, SEEK_SET);
|
fseek(tempfile, 0L, SEEK_SET);
|
||||||
|
|
||||||
if (tempfile && (!err || !ft_batchmode)) {
|
if (tempfile && (!err || !ft_batchmode)) {
|
||||||
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
/* Copy the input file name for adding another file search path */
|
/* Copy the input file name for adding another file search path */
|
||||||
inp_spsource(tempfile, FALSE, dname);
|
inp_spsource(tempfile, FALSE, dname);
|
||||||
tfree(dname);
|
tfree(dname);
|
||||||
#else
|
#else
|
||||||
inp_spsource(tempfile, FALSE, NULL);
|
inp_spsource(tempfile, FALSE, NULL);
|
||||||
#endif
|
#endif
|
||||||
gotone = TRUE;
|
gotone = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
if (tempfile && tpf && remove(tpf))
|
if (tempfile && tpf && remove(tpf))
|
||||||
perror("Could not delete temp file");
|
perror("Could not delete temp file");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ft_batchmode && err)
|
if (ft_batchmode && err)
|
||||||
sp_shutdown(EXIT_BAD);
|
sp_shutdown(EXIT_BAD);
|
||||||
|
|
||||||
} /* --- if (!ft_servermode && !ft_nutmeg) --- */
|
} /* --- if (!ft_servermode && !ft_nutmeg) --- */
|
||||||
|
|
||||||
if (!gotone && ft_batchmode && !ft_nutmeg)
|
if (!gotone && ft_batchmode && !ft_nutmeg)
|
||||||
inp_spsource(circuit_file, FALSE, NULL);
|
inp_spsource(circuit_file, FALSE, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
evl:
|
|
||||||
if (ft_batchmode) {
|
if (ft_batchmode) {
|
||||||
|
|
||||||
/* If we get back here in batch mode then something is wrong,
|
/* If we get back here in batch mode then something is wrong,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue