From 8ea51cc2f3391c015a33e20926e30e1ef3bfa005 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Tue, 28 Apr 2020 17:23:07 +0200 Subject: [PATCH] If command 'source' fails, don't move on with the script (and od nonsens simulations), but stop ngspice and await detaching (shared ngspice), or wait for user input. --- src/frontend/inp.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index bbb7cbac5..68a98ea76 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -1578,16 +1578,29 @@ com_source(wordlist *wl) tempfile = smktemp("sp"); if ((fp = inp_pathopen(tempfile, "w+")) == NULL) { perror(tempfile); + fprintf(cp_err, " Simulation interrupted due to error!\n\n"); cp_interactive = TRUE; - return; + /* If we cannot open the temporary file, stop all further command execution */ +#ifdef SHARED_MODULE + controlled_exit(1); +#else + cp_evloop(NULL); +#endif } while (wl) { if ((tp = inp_pathopen(wl->wl_word, "r")) == NULL) { + fprintf(cp_err, "Command 'source' failed:\n"); perror(wl->wl_word); + fprintf(cp_err, " Simulation interrupted due to error!\n\n"); fclose(fp); cp_interactive = TRUE; unlink(tempfile); - return; + /* If we cannot source the file, stop all further command execution */ +#ifdef SHARED_MODULE + controlled_exit(1); +#else + cp_evloop(NULL); +#endif } while ((n = fread(buf, 1, BSIZE_SP, tp)) > 0) fwrite(buf, 1, n, fp); @@ -1600,8 +1613,16 @@ com_source(wordlist *wl) } if (fp == NULL) { + fprintf(cp_err, "Command 'source' failed:\n"); perror(wl->wl_word); + fprintf(cp_err, " Simulation interrupted due to error!\n\n"); cp_interactive = TRUE; + /* If we cannot source the file, stop all further command execution */ +#ifdef SHARED_MODULE + controlled_exit(1); +#else + cp_evloop(NULL); +#endif return; }