ngspice/src/frontend/cpitf.c

356 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
**********/
/*
* SJB 22 May 2001
* Corrected freeing of memory in ft_cpinit()
*/
2000-04-27 22:03:57 +02:00
#include "ngspice.h"
#include "cpdefs.h"
#include "ftedefs.h"
* src/Makefile.am src/main.c src/sconvert.c src/analysis/cktdisto.c src/analysis/cktnoise.c src/analysis/noisean.c: Updates for the new header files. * src/maths/cmaths/cmath1.c src/maths/cmaths/cmath2.c src/maths/cmaths/cmath3.c src/maths/cmaths/cmath4.c: Updates for the new header files. * src/frontend/.cvsignore src/frontend/Makefile.am: Updates for the new files. * src/frontend/agraf.c src/frontend/aspice.c src/frontend/breakp.c src/frontend/breakp2.c src/frontend/circuits.c src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/define.c src/frontend/diff.c src/frontend/dimens.c src/frontend/display.c src/frontend/doplot.c src/frontend/dotcards.c src/frontend/evaluate.c src/frontend/fourier.c src/frontend/graf.c src/frontend/grid.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/interp.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/misccoms.h src/frontend/miscvars.c src/frontend/mw_coms.c src/frontend/newcoms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/plotcurv.c src/frontend/points.c src/frontend/postcoms.c src/frontend/rawfile.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/typesdef.c src/frontend/vectors.c src/frontend/where.c src/frontend/postcoms.c: Updates for the new header files. Some commands have moved into the new files below. * src/frontend/README src/frontend/com_compose.c src/frontend/com_compose.h src/frontend/com_display.c src/frontend/com_display.h src/frontend/com_let.c src/frontend/com_let.h src/frontend/com_setscale.c src/frontend/com_setscale.h src/frontend/commands.c src/frontend/commands.h src/frontend/completion.h src/frontend/streams.h src/frontend/testcommands.c: Separation into different com_* commands. This is a start. The rest of the subdirectory needs doing. * src/include/complex.h src/include/cpdefs.h src/include/cpextern.h src/include/cpstd.h src/include/fteconst.h src/include/ftedata.h src/include/ftedev.h src/include/fteext.h src/include/ftegraph.h src/include/fteparse.h src/include/dvec.h src/include/grid.h src/include/plot.h src/include/pnode.h src/include/sim.h src/include/variable.h src/include/wordlist.h src/include/bool.h: Separation of header files into smaller pieces. This limits recompilation to only the affected source files. The original header files have a warning message embedded to flag obsoleted use. * src/frontend/compose.c src/frontend/compose.h src/frontend/nutctab.c src/frontend/nutctab.h src/frontend/plot5.c src/frontend/plot5.h src/frontend/spcmdtab.c src/frontend/x11.c src/frontend/x11.h src/frontend/xgraph.c src/frontend/xgraph.h: Moved these files into src/frontend/plotting subdirectory. * src/frontend/plotting/.cvsignore src/frontend/plotting/Makefile.am src/frontend/plotting/plot5.c src/frontend/plotting/plot5.h src/frontend/plotting/plotting.c src/frontend/plotting/plotting.h src/frontend/plotting/pvec.c src/frontend/plotting/pvec.h src/frontend/plotting/x11.c src/frontend/plotting/x11.h src/frontend/plotting/xgraph.c src/frontend/plotting/xgraph.h: The new libplotting library with automake and CVS infrastructure.
2000-05-06 16:12:51 +02:00
#include "dvec.h"
2000-04-27 22:03:57 +02:00
#include "fteparse.h"
#include "cpitf.h"
#include <terminal.h>
* src/Makefile.am src/main.c src/sconvert.c src/analysis/cktdisto.c src/analysis/cktnoise.c src/analysis/noisean.c: Updates for the new header files. * src/maths/cmaths/cmath1.c src/maths/cmaths/cmath2.c src/maths/cmaths/cmath3.c src/maths/cmaths/cmath4.c: Updates for the new header files. * src/frontend/.cvsignore src/frontend/Makefile.am: Updates for the new files. * src/frontend/agraf.c src/frontend/aspice.c src/frontend/breakp.c src/frontend/breakp2.c src/frontend/circuits.c src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/define.c src/frontend/diff.c src/frontend/dimens.c src/frontend/display.c src/frontend/doplot.c src/frontend/dotcards.c src/frontend/evaluate.c src/frontend/fourier.c src/frontend/graf.c src/frontend/grid.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/interp.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/misccoms.h src/frontend/miscvars.c src/frontend/mw_coms.c src/frontend/newcoms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/plotcurv.c src/frontend/points.c src/frontend/postcoms.c src/frontend/rawfile.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/typesdef.c src/frontend/vectors.c src/frontend/where.c src/frontend/postcoms.c: Updates for the new header files. Some commands have moved into the new files below. * src/frontend/README src/frontend/com_compose.c src/frontend/com_compose.h src/frontend/com_display.c src/frontend/com_display.h src/frontend/com_let.c src/frontend/com_let.h src/frontend/com_setscale.c src/frontend/com_setscale.h src/frontend/commands.c src/frontend/commands.h src/frontend/completion.h src/frontend/streams.h src/frontend/testcommands.c: Separation into different com_* commands. This is a start. The rest of the subdirectory needs doing. * src/include/complex.h src/include/cpdefs.h src/include/cpextern.h src/include/cpstd.h src/include/fteconst.h src/include/ftedata.h src/include/ftedev.h src/include/fteext.h src/include/ftegraph.h src/include/fteparse.h src/include/dvec.h src/include/grid.h src/include/plot.h src/include/pnode.h src/include/sim.h src/include/variable.h src/include/wordlist.h src/include/bool.h: Separation of header files into smaller pieces. This limits recompilation to only the affected source files. The original header files have a warning message embedded to flag obsoleted use. * src/frontend/compose.c src/frontend/compose.h src/frontend/nutctab.c src/frontend/nutctab.h src/frontend/plot5.c src/frontend/plot5.h src/frontend/spcmdtab.c src/frontend/x11.c src/frontend/x11.h src/frontend/xgraph.c src/frontend/xgraph.h: Moved these files into src/frontend/plotting subdirectory. * src/frontend/plotting/.cvsignore src/frontend/plotting/Makefile.am src/frontend/plotting/plot5.c src/frontend/plotting/plot5.h src/frontend/plotting/plotting.c src/frontend/plotting/plotting.h src/frontend/plotting/pvec.c src/frontend/plotting/pvec.h src/frontend/plotting/x11.c src/frontend/plotting/x11.h src/frontend/plotting/xgraph.c src/frontend/plotting/xgraph.h: The new libplotting library with automake and CVS infrastructure.
2000-05-06 16:12:51 +02:00
#include "completion.h"
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
#include "variable.h"
2000-04-27 22:03:57 +02:00
/* Set some standard variables and aliases, etc, and init the ccom stuff. */
void
ft_cpinit(void)
{
wordlist *wl;
wordlist wl1, wl2, wl3;
bool found = FALSE, t = TRUE;
char buf[BSIZE_SP], **x, *s, *r,*copys;
2000-04-27 22:03:57 +02:00
struct comm *c;
int i;
FILE *fp;
static char *predefs[] = {
"yes", "1",
"TRUE", "1",
"no", "0",
"FALSE", "0",
"pi", "3.14159265358979323846",
"e", "2.71828182844590452353",
"c", "2.997925e8",
"i", "0,1",
"kelvin", "-273.15",
"echarge", "1.60219e-19",
"boltz", "1.38062e-23",
"planck", "6.62620e-34"
} ;
static char *udfs[] = {
"max(x,y)", "(x gt y) * x + (x le y) * y",
"min(x,y)", "(x lt y) * x + (x ge y) * y",
"vdb(x)", "db(v(x))",
"vdb(x,y)", "db(v(x) - v(y))",
"vi(x)", "im(v(x))",
"vi(x,y)", "im(v(x) - v(y))",
"vm(x)", "mag(v(x))",
"vm(x,y)", "mag(v(x) - v(y))",
"vg(x)", "group_delay(v(x))", //A.Rroldan 10/06/05 group delay new function
"gd(x)", "group_delay(v(x))", //A.Rroldan 10/06/05 group delay new function
"vp(x)", "ph(v(x))",
2000-04-27 22:03:57 +02:00
"vp(x,y)", "ph(v(x) - v(y))",
"vr(x)", "re(v(x))",
"vr(x,y)", "re(v(x) - v(y))"
} ;
cp_ccon(TRUE); /* So the user can type ahead... */
cp_init();
if (!cp_nocc) {
/* Add commands... */
for (c = cp_coms; c->co_func; c++) {
if (c->co_spiceonly && ft_nutmeg)
continue;
cp_addcomm(c->co_comname, c->co_cctypes[0],
c->co_cctypes[1], c->co_cctypes[2],
c->co_cctypes[3]);
cp_addkword(CT_COMMANDS, c->co_comname);
}
/* And keywords... These are the ones that are constant... */
if (!ft_nutmeg) {
cp_addkword(CT_LISTINGARGS, "deck");
cp_addkword(CT_LISTINGARGS, "logical");
cp_addkword(CT_LISTINGARGS, "physical");
cp_addkword(CT_LISTINGARGS, "expand");
cp_addkword(CT_STOPARGS, "when");
cp_addkword(CT_STOPARGS, "after");
}
cp_addkword(CT_PLOT, "new");
cp_addkword(CT_PLOTKEYWORDS, "xlimit");
cp_addkword(CT_PLOTKEYWORDS, "ylimit");
cp_addkword(CT_PLOTKEYWORDS, "vs");
cp_addkword(CT_PLOTKEYWORDS, "xindices");
cp_addkword(CT_PLOTKEYWORDS, "xcompress");
cp_addkword(CT_PLOTKEYWORDS, "xdelta");
cp_addkword(CT_PLOTKEYWORDS, "ydelta");
cp_addkword(CT_PLOTKEYWORDS, "lingrid");
cp_addkword(CT_PLOTKEYWORDS, "loglog");
cp_addkword(CT_PLOTKEYWORDS, "linear");
cp_addkword(CT_PLOTKEYWORDS, "xlog");
cp_addkword(CT_PLOTKEYWORDS, "ylog");
cp_addkword(CT_PLOTKEYWORDS, "polar");
cp_addkword(CT_PLOTKEYWORDS, "smith");
cp_addkword(CT_PLOTKEYWORDS, "smithgrid");
cp_addkword(CT_PLOTKEYWORDS, "nointerp");
cp_addkword(CT_PLOTKEYWORDS, "title");
cp_addkword(CT_PLOTKEYWORDS, "xlabel");
cp_addkword(CT_PLOTKEYWORDS, "ylabel");
cp_addkword(CT_PLOTKEYWORDS, "linplot");
cp_addkword(CT_PLOTKEYWORDS, "combplot");
cp_addkword(CT_PLOTKEYWORDS, "pointplot");
cp_addkword(CT_RUSEARGS, "time");
cp_addkword(CT_RUSEARGS, "space");
cp_addkword(CT_RUSEARGS, "faults");
cp_addkword(CT_RUSEARGS, "elapsed");
cp_addkword(CT_RUSEARGS, "totiter");
cp_addkword(CT_RUSEARGS, "traniter");
cp_addkword(CT_RUSEARGS, "tranpoints");
cp_addkword(CT_RUSEARGS, "accept");
cp_addkword(CT_RUSEARGS, "rejected");
cp_addkword(CT_RUSEARGS, "time");
cp_addkword(CT_RUSEARGS, "trantime");
cp_addkword(CT_RUSEARGS, "lutime");
cp_addkword(CT_RUSEARGS, "solvetime");
cp_addkword(CT_RUSEARGS, "transolvetime");
cp_addkword(CT_RUSEARGS, "loadtime");
cp_addkword(CT_RUSEARGS, "all");
cp_addkword(CT_VECTOR, "all");
for (x = ft_setkwords; *x; x++)
cp_addkword(CT_VARIABLES, *x);
for (i = 0; ; i++) {
if (!(s = ft_typenames(i)))
break;
cp_addkword(CT_TYPENAMES, s);
}
}
cp_vset("program", VT_STRING, cp_program);
/* Make the prompt use only the last component of the path... */
if (DIR_TERM) {
for (s = cp_program; s && *s; s++)
;
s--;
while ((s > cp_program) && (*s != DIR_TERM))
s--;
if (*s == DIR_TERM)
s++;
(void) strcpy(buf, s);
for (s = buf; *s && (*s != '.'); s++)
;
*s = '\0';
(void) strcat(buf, " ! -> ");
} else
(void) sprintf(buf, "%s ! -> ", cp_program);
cp_vset("prompt", VT_STRING, buf);
cp_vset("noglob", VT_BOOL, (char *) &t);
2007-10-12 23:59:18 +02:00
cp_vset("brief", VT_BOOL, (char *) &t);
2000-04-27 22:03:57 +02:00
/* Now do a bunch of things that used to be in the spiceinit file
* but were too slow to read in...
*/
wl1.wl_next = &wl2;
wl1.wl_prev = NULL;
wl2.wl_next = NULL;
wl2.wl_prev = &wl1;
wl1.wl_word = "if";
wl2.wl_word = "1";
cp_setalias("begin", &wl1);
wl1.wl_next = NULL;
wl1.wl_word = "end";
cp_setalias("endif", &wl1);
cp_setalias("endwhile", &wl1);
cp_setalias("endforeach", &wl1);
cp_setalias("endrepeat", &wl1);
cp_setalias("enddowhile", &wl1);
wl1.wl_word = "help";
cp_setalias("?", &wl1);
wl1.wl_next = &wl2;
wl2.wl_next = &wl3;
wl2.wl_prev = &wl1;
wl3.wl_prev = &wl2;
wl3.wl_next = NULL;
wl2.wl_word = "=";
for (i = 0; i < sizeof (predefs) / sizeof (char *); i += 2) {
wl1.wl_word = predefs[i];
wl3.wl_word = predefs[i + 1];
com_let(&wl1);
}
wl2.wl_next = NULL;
for (i = 0; i < sizeof (udfs) / sizeof (char *); i += 2) {
wl1.wl_word = udfs[i];
wl2.wl_word = udfs[i + 1];
com_define(&wl1);
}
/* Reset this for the front end. */
cp_hash = '*';
if (Lib_Path && *Lib_Path) {
(void) sprintf(buf, "sourcepath = ( %s %s )", DIR_CWD, Lib_Path);
2009-03-28 21:06:38 +01:00
wl = cp_doglob(cp_lexer(buf));
2000-04-27 22:03:57 +02:00
cp_striplist(wl);
com_set(wl);
2009-03-28 21:06:38 +01:00
wl_free(wl);
2000-04-27 22:03:57 +02:00
/* Now source the standard startup file. */
/* XXX strange */
2008-12-23 19:04:51 +01:00
for (copys=s=cp_tildexpand(Lib_Path); copys && *copys; ) {/*DG*/
2000-04-27 22:03:57 +02:00
while (isspace(*s))
s++;
for (r = buf; *s && !isspace(*s); r++, s++)
*r = *s;
tfree(copys); /* sjb - it's safe to free this here */
2000-04-27 22:03:57 +02:00
(void) strcpy(r, DIR_PATHSEP);
2008-11-23 21:47:23 +01:00
#ifdef TCL_MODULE
(void) strcat(r, "tclspinit");
#else
2000-04-27 22:03:57 +02:00
(void) strcat(r, "spinit");
2008-11-23 21:47:23 +01:00
#endif
2000-04-27 22:03:57 +02:00
if ((fp = fopen(buf, "r"))) {
cp_interactive = FALSE;
inp_spsource(fp, TRUE, buf);
cp_interactive = TRUE;
/* the following caused me SIGSEGV's since inp_spsource
already closes fp - A. Veliath 12/7/97
MW. Its really needed - I changed inp_spsource to
close fp always. */
/* (void) fclose(fp); */
found = TRUE;
break;
} else if (ft_controldb)
fprintf(cp_err, "Note: can't open \"%s\".\n", buf);
}
if (!found)
fprintf(cp_err, "Note: can't find init file.\n");
}
tcap_init( );
/* tfree(copys);*/ /*DG Avoid memory leak*/
/* SJB - must not free here as cp_tildexpande() can return NULL */
2000-04-27 22:03:57 +02:00
return;
}
/* Decide whether a condition is TRUE or not. */
bool
2001-02-09 20:46:36 +01:00
cp_istrue(wordlist *wl)
2000-04-27 22:03:57 +02:00
{
int i;
struct dvec *v;
struct pnode *pn;
/* fprintf(stderr, "isTRUE: "); wl_print(wl, stderr); fprintf(stderr, "\n"); */
/* First do all the csh-type stuff here... */
wl = wl_copy(wl);
wl = cp_variablesubst(wl);
wl = cp_bquote(wl);
cp_striplist(wl);
pn = ft_getpnames(wl, TRUE);
v = ft_evaluate(pn);
/* It makes no sense to say while (all), but what the heck... */
while (v) {
if (isreal(v)) {
for (i = 0; i < v->v_length; i++)
if (v->v_realdata[i] != 0.0) {
free_pnode(pn);
return (TRUE);
}
2000-04-27 22:03:57 +02:00
} else {
for (i = 0; i < v->v_length; i++)
if ((realpart(&v->v_compdata[i]) != 0.0) ||
(imagpart(&v->v_compdata[i]) != 0.0)) {
free_pnode(pn);
2000-04-27 22:03:57 +02:00
return (TRUE);
}
2000-04-27 22:03:57 +02:00
}
v = v->v_link2;
}
free_pnode(pn);
return (FALSE);
2000-04-27 22:03:57 +02:00
}
/* This gets called before every command is executed... */
void
cp_periodic(void)
{
ft_setflag = FALSE;
ft_intrpt = FALSE;
2000-04-27 22:03:57 +02:00
ft_ckspace();
ft_checkkids();
vec_gc();
return;
}
void
cp_doquit(void)
{
com_quit((wordlist *) NULL);
return;
}
/* This is how we deal with emulation of commands by scripts... If the script
* is found, then set the variables argc and argv and call the script. Note
* that this also allows us to type a filename to load a spice deck...
*/
bool
cp_oddcomm(char *s, wordlist *wl)
{
FILE *fp;
char buf[BSIZE_SP];
wordlist ww;
if ((fp = inp_pathopen(s, "r"))) {
(void) fclose(fp);
(void) sprintf(buf, "argc = %d argv = ( ", wl_length(wl));
while (wl) {
(void) strcat(buf, wl->wl_word);
(void) strcat(buf, " ");
wl = wl->wl_next;
}
(void) strcat(buf, ")");
com_set(cp_lexer(buf));
inp_source(s);
cp_remvar("argc");
cp_remvar("argv");
return (TRUE);
} else if (wl && eq(wl->wl_word, "=")) {
ww.wl_next = wl;
wl->wl_prev = &ww;
ww.wl_prev = NULL;
ww.wl_word = s;
com_let(&ww);
return (TRUE);
} else
return (FALSE);
}