Browse Source

cpif.c, whitespace, indentation, cleanups

rlar 14 years ago
parent
commit
8d0306c27a
  1. 171
      src/frontend/cpitf.c

171
src/frontend/cpitf.c

@ -1,9 +1,7 @@
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
***********
*/
***********/
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
@ -21,17 +19,18 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
#include "completion.h"
#include "variable.h"
/* Set some standard variables and aliases, etc, and init the ccom stuff.
/* Set some standard variables and aliases, etc, and init the ccom stuff.
Called by fcn main() */
void
ft_cpinit(void)
{
bool found = FALSE, t = TRUE;
char buf[BSIZE_SP], **x, *s, *r,*copys;
char buf[BSIZE_SP], **x, *s, *r, *copys;
struct comm *c;
int i;
FILE *fp;
static char *predefs[] = {
"yes", "1",
"TRUE", "1",
@ -45,7 +44,8 @@ ft_cpinit(void)
"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",
@ -56,33 +56,36 @@ ft_cpinit(void)
"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
"gd(x)", "group_delay(v(x))", //A.Rroldan 10/06/05 group delay new function
"vp(x)", "ph(v(x))",
"vp(x,y)", "ph(v(x) - v(y))",
"vr(x)", "re(v(x))",
"vr(x,y)", "re(v(x) - v(y))"
} ;
};
/* if TIOCSTI is defined (not available in MS Windows:
Make escape the break character.
So the user can type ahead...
fcn defined in complete.c. */
cp_ccon(TRUE);
/* Initialize io, cp_chars[], variable "history" in init.c. */
cp_init();
/* If command completion is available (global variable cp_nocc
set in main.c by command line option -q) */
set in main.c by command line option -q) */
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_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");
@ -164,89 +167,91 @@ ft_cpinit(void)
;
*s = '\0';
(void) strcat(buf, " ! -> ");
} else
} else {
(void) sprintf(buf, "%s ! -> ", cp_program);
}
cp_vset("prompt", CP_STRING, buf);
cp_vset("noglob", CP_BOOL, &t);
cp_vset("brief", CP_BOOL, &t);
/* Make vectors from values in predefs[] for the current plot.
Define functions from entries in udfs[] (like user defined functions).
*/
/* Make vectors from values in predefs[] for the current plot.
Define functions from entries in udfs[] (like user defined functions).
*/
{
wordlist wl1, wl2, wl3;
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; (size_t) i < NUMELEMS(predefs); i += 2) {
wl1.wl_word = predefs[i];
wl3.wl_word = predefs[i + 1];
com_let(&wl1);
}
wordlist wl1, wl2, wl3;
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; (size_t) i < NUMELEMS(predefs); i += 2) {
wl1.wl_word = predefs[i];
wl3.wl_word = predefs[i + 1];
com_let(&wl1);
}
wl2.wl_next = NULL;
for (i = 0; (size_t) i < NUMELEMS(udfs); i += 2) {
wl1.wl_word = udfs[i];
wl2.wl_word = udfs[i + 1];
com_define(&wl1);
}
wl2.wl_next = NULL;
for (i = 0; (size_t) i < NUMELEMS(udfs); i += 2) {
wl1.wl_word = udfs[i];
wl2.wl_word = udfs[i + 1];
com_define(&wl1);
}
}
/* Reset this for the front end. */
cp_hash = '*';
/* NGSPICEDATADIR has been set to path "$dprefix/share/ngspice" in configure.ac,
Spice_Lib_Dir has been set to NGSPICEDATADIR in conf.c,
/* NGSPICEDATADIR has been set to path "$dprefix/share/ngspice" in configure.ac,
Spice_Lib_Dir has been set to NGSPICEDATADIR in conf.c,
may be overridden by environmental variable SPICE_LIB_DIR in ivars().
Lib_Path has been set to Spice_Lib_Dir adding /scripts in ivars() */
if (Lib_Path && *Lib_Path) {
/* set variable 'sourcepath' */
if (Inp_Path && *Inp_Path)
/* set variable 'sourcepath' */
if (Inp_Path && *Inp_Path)
(void) sprintf(buf, "sourcepath = ( %s %s %s )", DIR_CWD, Lib_Path, Inp_Path);
else
(void) sprintf(buf, "sourcepath = ( %s %s )", DIR_CWD, Lib_Path);
{
wordlist *wl;
wl = cp_doglob(cp_lexer(buf));
cp_striplist(wl);
com_set(wl);
wl_free(wl);
wordlist *wl;
wl = cp_doglob(cp_lexer(buf));
cp_striplist(wl);
com_set(wl);
wl_free(wl);
}
/* Now source the standard startup file spinit or tclspinit. */
/* jump over leading spaces */
for (copys=s=cp_tildexpand(Lib_Path); copys && *copys; ) {
for (copys = s = cp_tildexpand(Lib_Path); copys && *copys; ) {
while (isspace(*s))
s++;
/* copy s into buf until space is seen, r is the actual position */
for (r = buf; *s && !isspace(*s); r++, s++)
*r = *s;
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);
#ifdef TCL_MODULE
/* add "tclspinit" to buf after actual position */
@ -256,13 +261,15 @@ ft_cpinit(void)
(void) strcat(r, "spinit");
#endif
if ((fp = fopen(buf, "r")) != NULL) {
cp_interactive = FALSE;
inp_spsource(fp, TRUE, buf);
cp_interactive = TRUE;
found = TRUE;
break;
#if defined (HAS_WINDOWS) || 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
} else if ((fp = fopen("./tclspinit", "r")) != NULL) {
#else
@ -273,16 +280,16 @@ ft_cpinit(void)
cp_interactive = TRUE;
found = TRUE;
break;
#endif
#endif
} 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( );
return;
tcap_init();
}
/* Decide whether a condition is TRUE or not. */
@ -294,7 +301,6 @@ cp_istrue(wordlist *wl)
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);
@ -303,15 +309,15 @@ cp_istrue(wordlist *wl)
pn = ft_getpnames(wl, TRUE);
wl_free(wl);
v = ft_evaluate(pn);
/* It makes no sense to say while (all), but what the heck... */
while (v) {
for (; v; v = v->v_link2)
if (isreal(v)) {
for (i = 0; i < v->v_length; i++)
if (v->v_realdata[i] != 0.0) {
free_pnode(pn);
return (TRUE);
free_pnode(pn);
return (TRUE);
}
} else {
for (i = 0; i < v->v_length; i++)
@ -321,13 +327,12 @@ cp_istrue(wordlist *wl)
return (TRUE);
}
}
v = v->v_link2;
}
free_pnode(pn);
return (FALSE);
free_pnode(pn);
return (FALSE);
}
/* This gets called before every command is executed...
/* This gets called before every command is executed...
from fcns do_command() or do_block() in control.c */
void
@ -338,14 +343,12 @@ cp_periodic(void)
ft_ckspace(); /* check for max. data size (resource.c) */
ft_checkkids(); /* check for jobs (only if OK_ASPICE is defined, apsice.c) */
vec_gc(); /* remove vectors which do not have permanent flag set (vectors.c) */
return;
}
void
cp_doquit(void)
{
com_quit(NULL);
return;
}
/* This is how we deal with emulation of commands by scripts... If the script
@ -373,13 +376,15 @@ cp_oddcomm(char *s, wordlist *wl)
cp_remvar("argc");
cp_remvar("argv");
return (TRUE);
} else if (wl && eq(wl->wl_word, "=")) {
}
if (wl && eq(wl->wl_word, "=")) {
wordlist *ww = wl_cons(copy(s), wl);
com_let(ww);
wl_chop_rest(ww);
wl_free(ww);
return (TRUE);
} else
return (FALSE);
}
}
return (FALSE);
}
Loading…
Cancel
Save