allow cp_getvar(,CP_BOOL,NULL) to avoid insane usage

This commit is contained in:
rlar 2010-07-20 18:41:25 +00:00
parent 9afba3083c
commit d44f818cad
12 changed files with 41 additions and 32 deletions

View File

@ -1,3 +1,25 @@
2010-07-20 Robert Larice
* src/frontend/com_display.c ,
* src/frontend/device.c ,
* src/frontend/inp.c ,
* src/frontend/inpcom.c ,
* src/frontend/measure.c ,
* src/frontend/nutinp.c ,
* src/frontend/outitf.c ,
* src/frontend/terminal.c ,
* src/frontend/variable.c ,
* src/frontend/plotting/graf.c ,
* src/frontend/plotting/x11.c :
allow cp_getvar(,CP_BOOL,NULL) to avoid insane usage
The third parameter is a pointer to the result value.
Frequently only the function return value is used,
(presence of nonpresence of the variable)
and the third parameter points to an unused variable.
Even worse, in several cases a dummy variable of incorrect type is used
for that purpose.
Thus,
allow the third parameter to be NULL, and kill those dummy variables.
2010-07-19 Holger Vogt
* b4ld.c: correct typo which led to non-convergence of ro_17.cir

View File

@ -32,7 +32,6 @@ com_display(wordlist *wl)
struct dvec *d;
struct dvec **dvs;
int len = 0, i = 0;
bool b;
char *s;
/* Maybe he wants to know about just a few vectors. */
@ -65,7 +64,7 @@ com_display(wordlist *wl)
dvs = (struct dvec **) tmalloc(len * (sizeof (struct dvec *)));
for (d = plot_cur->pl_dvecs, i = 0; d; d = d->v_next, i++)
dvs[i] = d;
if (!cp_getvar("nosort", CP_BOOL, (char *) &b))
if (!cp_getvar("nosort", CP_BOOL, NULL))
qsort((char *) dvs, len, sizeof (struct dvec *), dcomp);
out_printf("Title: %s\n", plot_cur->pl_title);

View File

@ -42,9 +42,7 @@ static int count;
void
com_showmod(wordlist *wl)
{
bool showmode;
if (cp_getvar("altshow", CP_BOOL, (char *) &showmode))
if (cp_getvar("altshow", CP_BOOL, NULL))
all_show(wl, 1);
else
all_show_old(wl, 1);
@ -53,9 +51,7 @@ com_showmod(wordlist *wl)
void
com_show(wordlist *wl)
{
bool showmode;
if (cp_getvar("altshow", CP_BOOL, (char *) &showmode))
if (cp_getvar("altshow", CP_BOOL, NULL))
all_show(wl, 0);
else
all_show_old(wl, 0);

View File

@ -322,12 +322,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
struct line *realdeck = NULL, *options = NULL, *curr_meas = NULL;
char *tt = NULL, name[BSIZE_SP], *s, *t, *temperature = NULL;
double testemp = 0.0;
bool nosubckts, commands = FALSE;
bool commands = FALSE;
wordlist *wl = NULL, *end = NULL, *wl_first = NULL;
wordlist *controls = NULL;
FILE *lastin, *lastout, *lasterr;
double temperature_value;
bool autostop;
/* read in the deck from a file */
char *filename_dup = ( filename == NULL ) ? strdup(".") : strdup(filename);
@ -526,7 +525,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
SetAnalyse( "Prepare Deck", 0);
#endif
/* Now expand subcircuit macros and substitute numparams.*/
if (!cp_getvar("nosubckt", CP_BOOL, (char *) &nosubckts))
if (!cp_getvar("nosubckt", CP_BOOL, NULL))
if( (deck->li_next = inp_subcktexpand(deck->li_next)) == NULL ){
line_free(realdeck,TRUE);
line_free(deck->li_actual, TRUE);
@ -598,7 +597,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
}
if ( ciprefix( ".meas", dd->li_line ) ) {
if ( cp_getvar( "autostop", CP_BOOL, (bool *) &autostop ) ) {
if ( cp_getvar( "autostop", CP_BOOL, NULL) ) {
if ( strstr( dd->li_line, " max " ) || strstr( dd->li_line, " min " ) || strstr( dd->li_line, " avg " ) ||
strstr( dd->li_line, " rms " ) || strstr( dd->li_line, " integ " ) ) {
printf( "Warning: .OPTION AUTOSTOP will not be effective because one of 'max|min|avg|rms|integ' is used in .meas\n" );

View File

@ -1077,7 +1077,6 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name, bool c
bool found_library, found_lib_name, found_end = FALSE, shell_eol_continuation = FALSE;
bool dir_name_flag = FALSE;
struct variable *v;
char *s_ptr, *s_lower;
/* Must set this to NULL or non-tilde includes segfault. -- Tim Molteno */
@ -1612,7 +1611,7 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name, bool c
inp_fix_gnd_name(working);
inp_chk_for_multi_in_vcvs(working, &line_number);
if (cp_getvar("addcontrol", CP_BOOL, (char *) &v))
if (cp_getvar("addcontrol", CP_BOOL, NULL))
inp_add_control_section(working, &line_number);
inp_compat_mode = ngspice_compat_mode() ;
if (inp_compat_mode == COMPATMODE_ALL) {

View File

@ -381,10 +381,9 @@ do_measure(
bool
check_autostop( char* what ) {
bool flag = FALSE;
bool autostop;
measures_passed = TRUE;
if ( cp_getvar( "autostop", CP_BOOL, (bool *) &autostop ) ) {
if ( cp_getvar( "autostop", CP_BOOL, NULL) ) {
do_measure( what, TRUE );
if ( measures_passed == TRUE ) flag = TRUE;

View File

@ -28,7 +28,7 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
struct line *deck, *dd, *ld;
struct line *realdeck, *options = NULL;
char *tt = NULL, name[BSIZE_SP], *s, *t;
bool nosubckts, commands = FALSE;
bool commands = FALSE;
wordlist *wl = NULL, *end = NULL;
wordlist *controls = NULL;
FILE *lastin, *lastout, *lasterr;
@ -168,8 +168,7 @@ inp_nutsource(FILE *fp, bool comfile, char *filename)
* fix the case before we do this but after we
* deal with the commands.
*/
if (!cp_getvar("nosubckt", CP_BOOL, (char *)
&nosubckts))
if (!cp_getvar("nosubckt", CP_BOOL, NULL))
deck->li_next = inp_subcktexpand(deck->
li_next);
deck->li_actual = realdeck;

View File

@ -82,7 +82,6 @@ static double *rowbuf;
static int column, rowbuflen;
static bool shouldstop = FALSE; /* Tell simulator to stop next time it asks. */
static bool printinfo = FALSE; /* Print informational "error messages". */
/* The two "begin plot" routines share all their internals... */
@ -146,7 +145,7 @@ beginPlot(void *analysisPtr, CKTcircuit *circuitPtr, char *cktName, char *analNa
/*end saj*/
/* Check to see if we want to print informational data. */
if (cp_getvar("printinfo", CP_BOOL, (char *) &printinfo))
if (cp_getvar("printinfo", CP_BOOL, NULL))
fprintf(cp_err, "(debug printing enabled)\n");
*runp = run = alloc(struct runDesc);
@ -1171,8 +1170,7 @@ OUTerror(int flags, char *format, IFuid *names)
char buf[BSIZE_SP], *s, *bptr;
int nindex = 0;
if ((flags == ERR_INFO) && cp_getvar("printinfo", CP_BOOL,
(char *) &printinfo))
if ((flags == ERR_INFO) && cp_getvar("printinfo", CP_BOOL, NULL))
return;
for (m = msgs; m->flag; m++)

View File

@ -81,7 +81,6 @@ gr_init(double *xlims, double *ylims, /* The size of the screen. */
{
GRAPH *graph;
int b;
wordlist *wl;
char *comb_title;
@ -109,7 +108,7 @@ gr_init(double *xlims, double *ylims, /* The size of the screen. */
(void) strcpy(pointchars, DEFPOINTCHARS);
if (!cp_getvar("ticmarks", CP_NUM, (char *) &graph->ticmarks)) {
if (cp_getvar("ticmarks", CP_BOOL, (char *) &b))
if (cp_getvar("ticmarks", CP_BOOL, NULL))
graph->ticmarks = 10;
else
graph->ticmarks = 0;

View File

@ -508,7 +508,7 @@ X11_Arc(int x0, int y0, int radius, double theta1, double theta2)
int t1, t2;
if (!cp_getvar("x11lineararcs", CP_BOOL, (char *) &t1)) {
if (!cp_getvar("x11lineararcs", CP_BOOL, NULL)) {
linear_arc(x0, y0, radius, theta1, theta2);
}
@ -812,11 +812,10 @@ zoomin(GRAPH *graph)
#if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE)
{
wordlist *wl;
int dummy;
/* hack for Gordon Jacobs */
/* add to history list if plothistory is set */
if (cp_getvar("plothistory", CP_BOOL, (char *) &dummy)) {
if (cp_getvar("plothistory", CP_BOOL, NULL)) {
wl = cp_parse(buf);
(void) cp_addhistent(cp_event++, wl);
}

View File

@ -80,11 +80,10 @@ out_init(void)
#ifdef TIOCGWINSZ
struct winsize ws;
#endif
bool moremode;
noprint = nopause = FALSE;
if (cp_getvar("nomoremode", CP_BOOL, (char *) &moremode))
if (cp_getvar("nomoremode", CP_BOOL, NULL))
out_moremode = FALSE;
else
out_moremode = TRUE;

View File

@ -557,7 +557,7 @@ cp_getvar(char *name, enum cp_types type, void *retval)
if (v == NULL) for (v = uv2; v && !eq(name, v->va_name); v = v->va_next);
if (v == NULL) {
if (type == CP_BOOL)
if (type == CP_BOOL && retval)
* (bool *) retval = FALSE;
free_struct_variable(uv1);
return (FALSE);
@ -565,7 +565,8 @@ cp_getvar(char *name, enum cp_types type, void *retval)
if (v->va_type == type) {
switch (type) {
case CP_BOOL:
* (bool *) retval = TRUE;
if(retval)
* (bool *) retval = TRUE;
break;
case CP_NUM: {
int *i;