ngspice/src/frontend/misccoms.c

379 lines
9.9 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
2000-04-27 22:03:57 +02:00
**********/
2020-04-25 19:25:15 +02:00
#include "../misc/ivars.h"
#include "circuits.h"
#include "com_alias.h"
#include "define.h"
#include "display.h"
#include "ftehelp.h"
#include "misccoms.h"
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
#include "ngspice/ftedefs.h"
#include "ngspice/dvec.h"
2018-08-31 17:08:04 +02:00
#include "ngspice/iferrmsg.h"
#include "ngspice/hlpdefs.h"
#include "plotting/graf.h"
2020-04-25 19:25:15 +02:00
#include "plotting/plotit.h"
#include "postcoms.h"
#include "runcoms2.h"
2020-04-25 19:25:15 +02:00
#include "variable.h"
2020-05-21 20:00:51 +02:00
#include "com_unset.h"
2000-04-27 22:03:57 +02:00
#ifndef SHARED_MODULE
#ifdef HAVE_GNUREADLINE
#include <readline/readline.h>
#include <readline/history.h>
extern char history_file[];
#endif
#ifdef HAVE_BSDEDITLINE
#include <editline/readline.h>
extern char history_file[];
#endif
#endif
#ifdef SHARED_MODULE
extern void rem_controls(void);
extern void destroy_wallace(void);
2020-05-21 20:00:51 +02:00
extern void sh_delete_myvec(void);
#endif
2007-05-01 05:40:17 +02:00
extern IFsimulator SIMinfo;
extern void spice_destroy_devices(void); /* FIXME need a better place */
src/Makefile.am src/help.c src/main.c src/circuit/Makefile.am src/circuit/ifnewuid.c src/frontend/Makefile.am src/frontend/aspice.c src/frontend/circuits.h src/frontend/com_display.c src/frontend/com_hardcopy.c src/frontend/commands.c src/frontend/commands.h src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/device.c src/frontend/diff.c src/frontend/display.c src/frontend/dotcards.c src/frontend/fourier.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/mw_coms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/postcoms.c src/frontend/postsc.c src/frontend/rawfile.c src/frontend/resource.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/subckt.c src/frontend/vectors.c src/frontend/where.c src/frontend/plotting/Makefile.am src/frontend/plotting/agraf.c src/frontend/plotting/graf.c src/frontend/plotting/plotcurv.c src/frontend/plotting/plotit.c src/frontend/plotting/x11.c src/frontend/plotting/xgraph.c src/include/Makefile.am src/maths/cmaths/cmath4.c src/misc/terminal.c src/misc/terminal.h src/parser/cshpar.c src/parser/front.c src/parser/front.h src/parser/history.c src/parser/history.h src/parser/modify.c src/parser/var2.c src/parser/var2.h src/parser/variable.c: Refactoring of frontend code. * src/include/ftehelp.h src/include/variable.h: Moved into frontend directory. * src/include/cpdefs.h src/include/cpextern.h src/include/ftedefs.h src/include/plot.h: Updates.
2000-06-27 18:09:02 +02:00
static void byemesg(void);
static int confirm_quit(void);
2000-04-27 22:03:57 +02:00
2000-04-27 22:03:57 +02:00
void
com_quit(wordlist *wl)
{
int exitcode = EXIT_NORMAL;
2000-04-27 22:03:57 +02:00
2012-05-17 19:06:08 +02:00
bool noask =
(wl && wl->wl_word && 1 == sscanf(wl->wl_word, "%d", &exitcode)) ||
2012-05-17 19:06:08 +02:00
(wl && wl->wl_word && cieq(wl->wl_word, "noask")) ||
!cp_getvar("askquit", CP_BOOL, NULL, 0);
/* Update screen. */
2000-04-27 22:03:57 +02:00
gr_clean();
2000-04-27 22:03:57 +02:00
/* Make sure the guy really wants to quit. */
if (!ft_nutmeg)
if (!noask && !confirm_quit())
return;
/* start to clean up the mess */
2012-05-17 19:20:51 +02:00
#ifdef SHARED_MODULE
{
wordlist all = { "all", NULL, NULL };
wordlist star = { "*", NULL, NULL };
com_destroy(&all);
com_unalias(&star);
com_undefine(&star);
cp_remvar("history");
cp_remvar("noglob");
cp_remvar("brief");
cp_remvar("sourcepath");
cp_remvar("program");
cp_remvar("prompt");
destroy_wallace();
}
rem_controls();
/* Destroy CKT when quit. */
if (!ft_nutmeg) {
while (ft_curckt) {
wl_delete(ft_curckt->ci_sourceinfo);
com_remcirc(NULL);
}
}
cp_destroy_keywords();
destroy_ivars();
2018-08-28 16:24:43 +02:00
#else
/* remove plotting parameters */
pl_rempar();
while (ft_curckt) {
// wl_delete(ft_curckt->ci_sourceinfo);
2018-08-28 16:24:43 +02:00
com_remcirc(NULL);
}
#endif
2018-08-31 17:08:04 +02:00
tfree(errMsg);
2012-05-17 19:07:15 +02:00
byemesg();
2018-08-28 16:24:43 +02:00
#ifdef SHARED_MODULE
2012-09-21 21:15:41 +02:00
destroy_const_plot();
spice_destroy_devices();
2020-05-21 19:49:58 +02:00
unset_all();
cp_resetcontrol(FALSE);
2020-05-21 20:00:51 +02:00
sh_delete_myvec();
/* add 1000 to notify that we exit from 'quit' */
controlled_exit(1000 + exitcode);
#else
exit(exitcode);
#endif
2000-04-27 22:03:57 +02:00
}
#ifdef SYSTEM_MAIL
void
com_bug(wordlist *wl)
{
char buf[BSIZE_SP];
2010-11-16 21:38:24 +01:00
NG_IGNORE(wl);
2010-11-16 20:11:32 +01:00
2000-04-27 22:03:57 +02:00
if (!Bug_Addr || !*Bug_Addr) {
fprintf(cp_err, "Error: No address to send bug reports to.\n");
return;
2000-04-27 22:03:57 +02:00
}
2000-04-27 22:03:57 +02:00
fprintf(cp_out,
2012-05-17 19:18:33 +02:00
"Calling the mail program . . .(sending to %s)\n\n"
"Please include the OS version number and machine architecture.\n"
"If the problem is with a specific circuit, please include the\n"
"input file.\n",
Bug_Addr);
2000-04-27 22:03:57 +02:00
2012-05-17 19:18:33 +02:00
(void) sprintf(buf, SYSTEM_MAIL, ft_sim->simulator, ft_sim->version, Bug_Addr);
2020-04-25 19:25:15 +02:00
if (system(buf) == -1) {
fprintf(cp_err, "Bug report could not be sent: \"%s\" failed.\n",
buf);
}
2000-04-27 22:03:57 +02:00
fprintf(cp_out, "Bug report sent. Thank you.\n");
}
#else
2000-04-27 22:03:57 +02:00
void
com_bug(wordlist *wl)
{
2011-06-11 19:07:38 +02:00
NG_IGNORE(wl);
2012-05-17 19:18:33 +02:00
fprintf(cp_out,
"Please use the ngspice bug tracker at:\n"
2023-03-07 23:18:25 +01:00
"https://sourceforge.net/p/ngspice/bugs/\n");
2000-04-27 22:03:57 +02:00
}
#endif
2000-04-27 22:03:57 +02:00
/* printout upon startup or 'version' command. options to version are -s (short),
-f (full), -v (just version), -d (just compile date).
'version' with options may also be used in ngspice pipe mode. */
2000-04-27 22:03:57 +02:00
void
com_version(wordlist *wl)
{
if (!wl) {
/* no printout in pipe mode (-p) */
if (ft_pipemode)
return;
fprintf(cp_out,
2012-05-17 19:18:33 +02:00
"******\n"
"** %s-%s : %s\n"
#ifdef KLU
"** Compiled with KLU Direct Linear Solver\n"
#else
"** Compiled with Sparse Direct Linear Solver\n"
#endif
2012-05-17 19:18:33 +02:00
"** The U. C. Berkeley CAD Group\n"
"** Copyright 1985-1994, Regents of the University of California.\n"
2025-08-03 14:20:41 +02:00
"** Copyright 2001-2025, The ngspice team.\n"
2012-05-17 19:18:33 +02:00
"** %s\n",
ft_sim->simulator, ft_sim->version, ft_sim->description, Spice_Manual);
2020-04-23 15:19:04 +02:00
if (*Spice_Notice != '\0')
fprintf(cp_out, "** %s\n", Spice_Notice);
2020-04-23 13:30:55 +02:00
if (*Spice_Build_Date != '\0')
fprintf(cp_out, "** Creation Date: %s\n", Spice_Build_Date);
fprintf(cp_out, "******\n");
2000-04-27 22:03:57 +02:00
} else {
2012-05-17 19:19:37 +02:00
char *s = wl_flatten(wl);
2012-05-17 19:16:30 +02:00
if (!strncasecmp(s, "-s", 2)) {
2012-05-17 19:18:33 +02:00
fprintf(cp_out,
"******\n"
"** %s-%s\n"
"** %s\n",
ft_sim->simulator, ft_sim->version, Spice_Manual);
2020-04-23 15:19:04 +02:00
if (*Spice_Notice != '\0')
fprintf(cp_out, "** %s\n", Spice_Notice);
2020-04-23 13:30:55 +02:00
if (*Spice_Build_Date != '\0')
fprintf(cp_out, "** Creation Date: %s\n", Spice_Build_Date);
fprintf(cp_out, "******\n");
} else if (!strncasecmp(s, "-v", 2)) {
fprintf(cp_out, "%s-%s\n",ft_sim->simulator, ft_sim->version);
2020-04-23 13:30:55 +02:00
} else if (!strncasecmp(s, "-d", 2) && *Spice_Build_Date != '\0'){
fprintf(cp_out, "%s\n", Spice_Build_Date);
} else if (!strncasecmp(s, "-f", 2)) {
fprintf(cp_out,
2012-05-17 19:18:33 +02:00
"******\n"
"** %s-%s : %s\n"
#ifdef KLU
"** Compiled with KLU Direct Linear Solver\n"
#else
"** Compiled with Sparse Direct Linear Solver\n"
#endif
2012-05-17 19:18:33 +02:00
"** The U. C. Berkeley CAD Group\n"
"** Copyright 1985-1994, Regents of the University of California.\n"
2025-08-03 14:26:31 +02:00
"** Copyright 2001-2025, The ngspice team.\n"
2012-05-17 19:18:33 +02:00
"** %s\n",
ft_sim->simulator, ft_sim->version, ft_sim->description, Spice_Manual);
2020-04-23 15:19:04 +02:00
if (*Spice_Notice != '\0')
fprintf(cp_out, "** %s\n", Spice_Notice);
2020-04-23 13:30:55 +02:00
if (*Spice_Build_Date != '\0')
fprintf(cp_out, "** Creation Date: %s\n", Spice_Build_Date);
fprintf(cp_out, "**\n");
#ifdef CIDER
fprintf(cp_out, "** CIDER 1.b1 (CODECS simulator) included\n");
#endif
#ifdef XSPICE
fprintf(cp_out, "** XSPICE extensions included\n");
#endif
fprintf(cp_out, "** Relevant compilation options (refer to user's manual):\n");
2011-08-10 18:39:46 +02:00
#ifdef NGDEBUG
fprintf(cp_out, "** Debugging option (-g) enabled\n");
2011-08-10 18:39:46 +02:00
#endif
#ifdef USE_OMP
fprintf(cp_out, "** OpenMP multithreading for BSIM3, BSIM4 enabled\n");
2011-08-10 18:39:46 +02:00
#endif
#if defined(X_DISPLAY_MISSING) && !defined(HAS_WINGUI)
fprintf(cp_out, "** X11 interface not compiled into ngspice\n");
#endif
#ifdef NOBYPASS
fprintf(cp_out, "** --enable-nobypass\n");
#endif
#ifdef CAPBYPASS
fprintf(cp_out, "** --enable-capbypass\n");
#endif
#ifdef NODELIMITING
fprintf(cp_out, "** --enable-nodelimiting\n");
#endif
#ifdef PREDICTOR
fprintf(cp_out, "** --enable-predictor\n");
#endif
#ifdef NEWTRUNC
fprintf(cp_out, "** --enable-newtrunc\n");
#endif
#ifdef WANT_SENSE2
fprintf(cp_out, "** --enable-sense2\n");
#endif
fprintf(cp_out, "**\n");
#ifdef EXPERIMENTAL_CODE
fprintf(cp_out, "** Experimental code enabled.\n");
#endif
#ifdef EXP_DEV
fprintf(cp_out, "** Experimental devices enabled.\n");
2022-10-24 17:04:45 +02:00
#endif
#ifdef SHARED_MODULE
fprintf(cp_out, "** ngspice shared library.\n");
#endif
fprintf(cp_out, "******\n");
} else if (!eq(ft_sim->version, s)) {
2000-04-27 22:03:57 +02:00
fprintf(stderr,
"Note: rawfile is version %s (current version is %s)\n",
2000-04-27 22:03:57 +02:00
wl->wl_word, ft_sim->version);
2000-04-27 22:03:57 +02:00
}
2000-04-27 22:03:57 +02:00
tfree(s);
}
}
2000-04-27 22:03:57 +02:00
static void
byemesg(void)
{
#ifndef SHARED_MODULE
#if defined(HAVE_GNUREADLINE) || defined(HAVE_BSDEDITLINE)
/* write out command history only when saying goodbye. */
if (cp_interactive && (cp_maxhistlength > 0)) {
stifle_history(cp_maxhistlength);
write_history(history_file);
}
#endif
#endif
2000-04-27 22:03:57 +02:00
printf("%s-%s done\n", ft_sim->simulator, ft_sim->version);
}
static int
confirm_quit(void)
{
struct circ *cc;
struct plot *pl;
int ncc = 0, npl = 0;
char buf[64];
for (cc = ft_circuits; cc; cc = cc->ci_next)
if (cc->ci_inprogress)
ncc++;
for (pl = plot_list; pl; pl = pl->pl_next)
if (!pl->pl_written && pl->pl_dvecs)
npl++;
if (!ncc && !npl)
return 1;
fprintf(cp_out, "Warning: ");
if (ncc) {
fprintf(cp_out,
"the following simulation%s still in progress:\n",
(ncc > 1) ? "s are" : " is");
for (cc = ft_circuits; cc; cc = cc->ci_next)
if (cc->ci_inprogress)
fprintf(cp_out, "\t%s\n", cc->ci_name);
}
if (ncc && npl)
fprintf(cp_out, "and ");
if (npl) {
fprintf(cp_out,
"the following plot%s been saved:\n",
(npl > 1) ? "s haven't" : " hasn't");
for (pl = plot_list; pl; pl = pl->pl_next)
if (!pl->pl_written && pl->pl_dvecs)
fprintf(cp_out, "%s\t%s, %s\n",
pl->pl_typename, pl->pl_title, pl->pl_name);
}
fprintf(cp_out, "\nAre you sure you want to quit (yes)? ");
(void) fflush(cp_out);
if (!fgets(buf, sizeof(buf), stdin)) {
clearerr(stdin);
*buf = 'y';
}
return ((*buf == 'y') || (*buf == 'Y') || (*buf == '\n'));
}