unwanted whitespace change, just a distracting mess
This commit is contained in:
parent
58333b320d
commit
8ca0b944df
|
|
@ -1,6 +1,6 @@
|
||||||
/**********
|
/**********
|
||||||
Copyright 1990 Regents of the University of California. All rights reserved.
|
Copyright 1990 Regents of the University of California. All rights reserved.
|
||||||
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
#include "ngspice/ngspice.h"
|
#include "ngspice/ngspice.h"
|
||||||
|
|
@ -12,14 +12,12 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||||
#include "ngspice/memory.h"
|
#include "ngspice/memory.h"
|
||||||
#include "ngspice/inpdefs.h"
|
#include "ngspice/inpdefs.h"
|
||||||
#include "ngspice/fteext.h"
|
#include "ngspice/fteext.h"
|
||||||
|
|
||||||
#include "circuits.h"
|
#include "circuits.h"
|
||||||
#include "com_history.h"
|
#include "com_history.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
#include "ngspice/cpextern.h"
|
#include "ngspice/cpextern.h"
|
||||||
#include "variable.h"
|
#include "variable.h"
|
||||||
|
|
||||||
|
|
||||||
bool cp_noglob = TRUE;
|
bool cp_noglob = TRUE;
|
||||||
bool cp_nonomatch = FALSE;
|
bool cp_nonomatch = FALSE;
|
||||||
bool cp_noclobber = FALSE;
|
bool cp_noclobber = FALSE;
|
||||||
|
|
@ -28,14 +26,12 @@ bool cp_echo = FALSE; /* CDHW */
|
||||||
|
|
||||||
struct variable *variables = NULL;
|
struct variable *variables = NULL;
|
||||||
|
|
||||||
|
|
||||||
wordlist *
|
wordlist *
|
||||||
cp_varwl(struct variable *var)
|
cp_varwl(struct variable *var)
|
||||||
{
|
{
|
||||||
wordlist *wl = NULL, *w, *wx = NULL;
|
wordlist *wl = NULL, *w, *wx = NULL;
|
||||||
char buf[BSIZE_SP], *copystring;
|
char buf[BSIZE_SP], *copystring;
|
||||||
struct variable *vt;
|
struct variable *vt;
|
||||||
|
|
||||||
switch (var->va_type) {
|
switch (var->va_type) {
|
||||||
case CP_BOOL:
|
case CP_BOOL:
|
||||||
/* Can't ever be FALSE. */
|
/* Can't ever be FALSE. */
|
||||||
|
|
@ -72,12 +68,10 @@ cp_varwl(struct variable *var)
|
||||||
var->va_type);
|
var->va_type);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl = wl_cons(copy(buf), NULL);
|
wl = wl_cons(copy(buf), NULL);
|
||||||
return wl;
|
return wl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set a variable. */
|
/* Set a variable. */
|
||||||
void
|
void
|
||||||
cp_vset(char *varname, enum cp_types type, void *value)
|
cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
|
|
@ -86,11 +80,8 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
int i;
|
int i;
|
||||||
bool alreadythere = FALSE, v_free = FALSE;
|
bool alreadythere = FALSE, v_free = FALSE;
|
||||||
char *copyvarname;
|
char *copyvarname;
|
||||||
|
|
||||||
/* varname = cp_unquote(varname); DG: Memory leak old varname is lost*/
|
/* varname = cp_unquote(varname); DG: Memory leak old varname is lost*/
|
||||||
|
|
||||||
copyvarname = cp_unquote(varname);
|
copyvarname = cp_unquote(varname);
|
||||||
|
|
||||||
w = NULL;
|
w = NULL;
|
||||||
for (v = variables; v; v = v->va_next) {
|
for (v = variables; v; v = v->va_next) {
|
||||||
if (eq(copyvarname, v->va_name)) {
|
if (eq(copyvarname, v->va_name)) {
|
||||||
|
|
@ -99,21 +90,18 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
}
|
}
|
||||||
w = v;
|
w = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alreadythere) {
|
if (alreadythere) {
|
||||||
if (v->va_type == CP_LIST)
|
if (v->va_type == CP_LIST)
|
||||||
free_struct_variable(v->va_vlist);
|
free_struct_variable(v->va_vlist);
|
||||||
if (v->va_type == CP_STRING)
|
if (v->va_type == CP_STRING)
|
||||||
tfree(v->va_string);
|
tfree(v->va_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!v) {
|
if (!v) {
|
||||||
v = alloc(struct variable);
|
v = alloc(struct variable);
|
||||||
v->va_name = copy(copyvarname);
|
v->va_name = copy(copyvarname);
|
||||||
v->va_next = NULL;
|
v->va_next = NULL;
|
||||||
v_free = TRUE;
|
v_free = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CP_BOOL:
|
case CP_BOOL:
|
||||||
if (* ((bool *) value) == FALSE) {
|
if (* ((bool *) value) == FALSE) {
|
||||||
|
|
@ -128,23 +116,18 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
v->va_bool = TRUE;
|
v->va_bool = TRUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CP_NUM:
|
case CP_NUM:
|
||||||
v->va_num = * (int *) value;
|
v->va_num = * (int *) value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CP_REAL:
|
case CP_REAL:
|
||||||
v->va_real = * (double *) value;
|
v->va_real = * (double *) value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CP_STRING:
|
case CP_STRING:
|
||||||
v->va_string = copy((char*) value);
|
v->va_string = copy((char*) value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CP_LIST:
|
case CP_LIST:
|
||||||
v->va_vlist = (struct variable *) value;
|
v->va_vlist = (struct variable *) value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(cp_err,
|
fprintf(cp_err,
|
||||||
"cp_vset: INTERNAL ERROR: bad variable type %d.\n",
|
"cp_vset: INTERNAL ERROR: bad variable type %d.\n",
|
||||||
|
|
@ -152,9 +135,7 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
tfree(copyvarname);
|
tfree(copyvarname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->va_type = type;
|
v->va_type = type;
|
||||||
|
|
||||||
/* Now, see if there is anything interesting going on. We
|
/* Now, see if there is anything interesting going on. We
|
||||||
* recognize these special variables: noglob, nonomatch, history,
|
* recognize these special variables: noglob, nonomatch, history,
|
||||||
* echo, noclobber, prompt, and verbose. cp_remvar looks for these
|
* echo, noclobber, prompt, and verbose. cp_remvar looks for these
|
||||||
|
|
@ -180,7 +161,6 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (i = cp_usrset(v, TRUE)) {
|
switch (i = cp_usrset(v, TRUE)) {
|
||||||
|
|
||||||
case US_OK:
|
case US_OK:
|
||||||
/* Normal case. */
|
/* Normal case. */
|
||||||
if (!alreadythere) {
|
if (!alreadythere) {
|
||||||
|
|
@ -188,7 +168,6 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
variables = v;
|
variables = v;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case US_DONTRECORD:
|
case US_DONTRECORD:
|
||||||
/* Do nothing... */
|
/* Do nothing... */
|
||||||
if (alreadythere) {
|
if (alreadythere) {
|
||||||
|
|
@ -196,19 +175,17 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
"%s already there, but `don't record'\n", v->va_name);
|
"%s already there, but `don't record'\n", v->va_name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case US_READONLY:
|
case US_READONLY:
|
||||||
fprintf(cp_err, "ERROR: %s is a read-only variable.\n", v->va_name);
|
fprintf(cp_err, "ERROR: %s is a read-only variable.\n", v->va_name);
|
||||||
if (alreadythere)
|
if (alreadythere)
|
||||||
fprintf(cp_err, "cp_vset: INTERNAL ERROR: "
|
fprintf(cp_err, "cp_vset: INTERNAL ERROR: "
|
||||||
"it was already there too!!\n");
|
"it was already there too!!\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case US_SIMVAR:
|
case US_SIMVAR:
|
||||||
if (alreadythere) {
|
if (alreadythere) {
|
||||||
/* somehow it got into the front-end list of variables */
|
/* somehow it got into the front-end list of variables */
|
||||||
if (w) {
|
if (w) {
|
||||||
w->va_next = v->va_next;
|
w->va_next = v->va_next;
|
||||||
} else {
|
} else {
|
||||||
variables = v->va_next;
|
variables = v->va_next;
|
||||||
}
|
}
|
||||||
|
|
@ -235,13 +212,11 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case US_NOSIMVAR:
|
case US_NOSIMVAR:
|
||||||
/* What do you do? */
|
/* What do you do? */
|
||||||
tfree(v->va_name);
|
tfree(v->va_name);
|
||||||
tfree(v);
|
tfree(v);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(cp_err, "cp_vset: INTERNAL ERROR: bad US val %d\n", i);
|
fprintf(cp_err, "cp_vset: INTERNAL ERROR: bad US val %d\n", i);
|
||||||
break;
|
break;
|
||||||
|
|
@ -249,12 +224,11 @@ cp_vset(char *varname, enum cp_types type, void *value)
|
||||||
tfree(copyvarname);
|
tfree(copyvarname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* CDHW This needs leak checking carefully CDHW */
|
/* CDHW This needs leak checking carefully CDHW */
|
||||||
/* mhx: Uses ft_numparse, which interprets SPICE numbers. Therefore it worked incorrectly
|
/* mhx: Uses ft_numparse, which interprets SPICE numbers. Therefore it worked incorrectly
|
||||||
for com_set: it prevented e.g. set ape="1MEG" (ape became CP_NUM 1e6 instead of CP_STRING '1meg').
|
for com_set: it prevented e.g. set ape="1MEG" (ape became CP_NUM 1e6 instead of CP_STRING '1meg').
|
||||||
Therefore I changed the function to FIRST check if the rhs is a string (look for quotes), and only
|
Therefore I changed the function to FIRST check if the rhs is a string (look for quotes), and only
|
||||||
if it is not, continue with ft_numparse.
|
if it is not, continue with ft_numparse.
|
||||||
Note: cp_setparse is used by com_set and com_option, where this new behavior should be ok.
|
Note: cp_setparse is used by com_set and com_option, where this new behavior should be ok.
|
||||||
cp_setparse is used in inp.c (4) for .option scale=xxx. Assumed new behavior will be ok.
|
cp_setparse is used in inp.c (4) for .option scale=xxx. Assumed new behavior will be ok.
|
||||||
cp_setparse is used in rawfile.c (2) to parse "option: xxx". Assumed new behavior will be ok.
|
cp_setparse is used in rawfile.c (2) to parse "option: xxx". Assumed new behavior will be ok.
|
||||||
|
|
@ -268,14 +242,10 @@ cp_setparse(wordlist *wl)
|
||||||
struct variable *listv = NULL, *vv, *lv = NULL;
|
struct variable *listv = NULL, *vv, *lv = NULL;
|
||||||
struct variable *vars = NULL;
|
struct variable *vars = NULL;
|
||||||
int balance;
|
int balance;
|
||||||
|
|
||||||
while (wl) {
|
while (wl) {
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
tfree(name);
|
tfree(name);
|
||||||
|
|
||||||
name = cp_unquote(wl->wl_word);
|
name = cp_unquote(wl->wl_word);
|
||||||
|
|
||||||
wl = wl->wl_next;
|
wl = wl->wl_next;
|
||||||
if ((!wl || (*wl->wl_word != '=')) && !strchr(name, '=')) { /* 'name ccccc' */
|
if ((!wl || (*wl->wl_word != '=')) && !strchr(name, '=')) { /* 'name ccccc' */
|
||||||
vv = alloc(struct variable);
|
vv = alloc(struct variable);
|
||||||
|
|
@ -287,8 +257,7 @@ cp_setparse(wordlist *wl)
|
||||||
tfree(name); /*DG: cp_unquote Memory leak*/
|
tfree(name); /*DG: cp_unquote Memory leak*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (wl && eq(wl->wl_word, "=")) { /* 'name =' */
|
||||||
if (wl && eq(wl->wl_word, "=")) { /* 'name =' */
|
|
||||||
wl = wl->wl_next;
|
wl = wl->wl_next;
|
||||||
if (wl == NULL) {
|
if (wl == NULL) {
|
||||||
fprintf(cp_err, "ERROR: bad set form.\n");
|
fprintf(cp_err, "ERROR: bad set form.\n");
|
||||||
|
|
@ -324,20 +293,18 @@ cp_setparse(wordlist *wl)
|
||||||
controlled_exit(EXIT_BAD);
|
controlled_exit(EXIT_BAD);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* val = cp_unquote(val); DG: bad old val is lost*/
|
/* val = cp_unquote(val); DG: bad old val is lost*/
|
||||||
isstring = (*val == '"'); /* mhx: is this sufficient? */
|
isstring = (*val == '"'); /* mhx: is this sufficient? */
|
||||||
copyval = cp_unquote(val); /*DG*/
|
copyval = cp_unquote(val); /*DG*/
|
||||||
strcpy(val, copyval);
|
strcpy(val, copyval);
|
||||||
tfree(copyval);
|
tfree(copyval);
|
||||||
|
|
||||||
if (eq(val, "(")) {
|
if (eq(val, "(")) {
|
||||||
/* The beginning of a list... We have to walk down the
|
/* The beginning of a list... We have to walk down the
|
||||||
* list until we find a close paren... If there are nested
|
* list until we find a close paren... If there are nested
|
||||||
* ()'s, treat them as tokens... */
|
* ()'s, treat them as tokens... */
|
||||||
balance = 1;
|
balance = 1;
|
||||||
while (wl && wl->wl_word) {
|
while (wl && wl->wl_word) {
|
||||||
bool isstringc;
|
bool isstringc;
|
||||||
if (eq(wl->wl_word, "(")) {
|
if (eq(wl->wl_word, "(")) {
|
||||||
balance++;
|
balance++;
|
||||||
} else if (eq(wl->wl_word, ")")) {
|
} else if (eq(wl->wl_word, ")")) {
|
||||||
|
|
@ -346,13 +313,13 @@ cp_setparse(wordlist *wl)
|
||||||
}
|
}
|
||||||
vv = alloc(struct variable);
|
vv = alloc(struct variable);
|
||||||
vv->va_next = NULL;
|
vv->va_next = NULL;
|
||||||
isstringc = (*wl->wl_word == '"'); /* mhx: is this sufficient? */
|
isstringc = (*wl->wl_word == '"'); /* mhx: is this sufficient? */
|
||||||
copyval = ss = cp_unquote(wl->wl_word);
|
copyval = ss = cp_unquote(wl->wl_word);
|
||||||
if (isstringc) {
|
if (isstringc) {
|
||||||
vv->va_type = CP_STRING;
|
vv->va_type = CP_STRING;
|
||||||
vv->va_string = copy(ss);
|
vv->va_string = copy(ss);
|
||||||
} else {
|
} else {
|
||||||
td = ft_numparse(&ss, FALSE);
|
td = ft_numparse(&ss, FALSE);
|
||||||
if (td) {
|
if (td) {
|
||||||
vv->va_type = CP_REAL;
|
vv->va_type = CP_REAL;
|
||||||
vv->va_real = *td;
|
vv->va_real = *td;
|
||||||
|
|
@ -361,7 +328,7 @@ cp_setparse(wordlist *wl)
|
||||||
vv->va_string = copy(ss);
|
vv->va_string = copy(ss);
|
||||||
fprintf(cp_err, "cp_setparse() :: ft_numparse() didn't recognize `%s' for assignment to `%s' as CP_REAL, using CP_STRING.\n", ss, name);
|
fprintf(cp_err, "cp_setparse() :: ft_numparse() didn't recognize `%s' for assignment to `%s' as CP_REAL, using CP_STRING.\n", ss, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak*/
|
tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak*/
|
||||||
if (listv) {
|
if (listv) {
|
||||||
lv->va_next = vv;
|
lv->va_next = vv;
|
||||||
|
|
@ -378,31 +345,28 @@ cp_setparse(wordlist *wl)
|
||||||
controlled_exit(EXIT_BAD);
|
controlled_exit(EXIT_BAD);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vv = alloc(struct variable);
|
vv = alloc(struct variable);
|
||||||
vv->va_name = copy(name);
|
vv->va_name = copy(name);
|
||||||
vv->va_type = CP_LIST;
|
vv->va_type = CP_LIST;
|
||||||
vv->va_vlist = listv;
|
vv->va_vlist = listv;
|
||||||
vv->va_next = vars;
|
vv->va_next = vars;
|
||||||
vars = vv;
|
vars = vv;
|
||||||
|
|
||||||
wl = wl->wl_next;
|
wl = wl->wl_next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/* there shouldn't be quotes around val at this point? */
|
||||||
/* there shouldn't be quotes around val at this point? */
|
|
||||||
if (*val == '"')
|
if (*val == '"')
|
||||||
isstring |= TRUE; /* mhx: is this sufficient? */
|
isstring |= TRUE; /* mhx: is this sufficient? */
|
||||||
copyval = ss = cp_unquote(val); /* 'name = ccccc' */
|
copyval = ss = cp_unquote(val); /* 'name = ccccc'*/
|
||||||
vv = alloc(struct variable);
|
vv = alloc(struct variable);
|
||||||
vv->va_name = copy(name);
|
vv->va_name = copy(name);
|
||||||
vv->va_next = vars;
|
vv->va_next = vars;
|
||||||
vars = vv;
|
vars = vv;
|
||||||
if (isstring) {
|
if (isstring) {
|
||||||
vv->va_type = CP_STRING;
|
vv->va_type = CP_STRING;
|
||||||
vv->va_string = copy(val);
|
vv->va_string = copy(val);
|
||||||
} else {
|
} else {
|
||||||
td = ft_numparse(&ss, FALSE); /* FALSE: because set x=1umeter should work and 'meter' ignored */
|
td = ft_numparse(&ss, FALSE); /* FALSE: because set x=1umeter should work and 'meter' ignored */
|
||||||
if (td) {
|
if (td) {
|
||||||
vv->va_type = CP_REAL;
|
vv->va_type = CP_REAL;
|
||||||
vv->va_real = *td;
|
vv->va_real = *td;
|
||||||
|
|
@ -410,17 +374,15 @@ cp_setparse(wordlist *wl)
|
||||||
vv->va_type = CP_STRING;
|
vv->va_type = CP_STRING;
|
||||||
vv->va_string = copy(val);
|
vv->va_string = copy(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak */
|
tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak */
|
||||||
tfree(name); /* va: cp_unquote memory leak: free name for every loop */
|
tfree(name); /* va: cp_unquote memory leak: free name for every loop */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
tfree(name);
|
tfree(name);
|
||||||
return vars;
|
return vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* free the struct variable. The type of the union is given by va_type */
|
/* free the struct variable. The type of the union is given by va_type */
|
||||||
void
|
void
|
||||||
free_struct_variable(struct variable *v)
|
free_struct_variable(struct variable *v)
|
||||||
|
|
@ -436,7 +398,6 @@ free_struct_variable(struct variable *v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
cp_remvar(char *varname)
|
cp_remvar(char *varname)
|
||||||
{
|
{
|
||||||
|
|
@ -444,9 +405,7 @@ cp_remvar(char *varname)
|
||||||
struct variable *uv1, *uv2;
|
struct variable *uv1, *uv2;
|
||||||
bool found = TRUE;
|
bool found = TRUE;
|
||||||
int i, var_index = 0;
|
int i, var_index = 0;
|
||||||
|
|
||||||
cp_usrvars(&uv1, &uv2);
|
cp_usrvars(&uv1, &uv2);
|
||||||
|
|
||||||
for (v = variables; v; v = v->va_next) {
|
for (v = variables; v; v = v->va_next) {
|
||||||
var_index = 0;
|
var_index = 0;
|
||||||
if (eq(v->va_name, varname))
|
if (eq(v->va_name, varname))
|
||||||
|
|
@ -480,7 +439,6 @@ cp_remvar(char *varname)
|
||||||
v->va_num = 0;
|
v->va_num = 0;
|
||||||
found = FALSE;
|
found = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note that 'unset history' doesn't do anything here... Causes
|
/* Note that 'unset history' doesn't do anything here... Causes
|
||||||
* trouble... */
|
* trouble... */
|
||||||
if (eq(varname, "noglob"))
|
if (eq(varname, "noglob"))
|
||||||
|
|
@ -501,7 +459,6 @@ cp_remvar(char *varname)
|
||||||
cp_program = "";
|
cp_program = "";
|
||||||
|
|
||||||
switch (i = cp_usrset(v, FALSE)) {
|
switch (i = cp_usrset(v, FALSE)) {
|
||||||
|
|
||||||
case US_OK:
|
case US_OK:
|
||||||
/* Normal case. */
|
/* Normal case. */
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
@ -515,10 +472,8 @@ cp_remvar(char *varname)
|
||||||
} else {
|
} else {
|
||||||
ft_curckt->ci_vars = v->va_next;
|
ft_curckt->ci_vars = v->va_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case US_DONTRECORD:
|
case US_DONTRECORD:
|
||||||
/* Do nothing... */
|
/* Do nothing... */
|
||||||
if (found)
|
if (found)
|
||||||
|
|
@ -543,7 +498,7 @@ cp_remvar(char *varname)
|
||||||
}
|
}
|
||||||
if (u) {
|
if (u) {
|
||||||
if (lv)
|
if (lv)
|
||||||
lv->va_next = u->va_next;
|
lv->va_next = u->va_next;
|
||||||
else
|
else
|
||||||
ft_curckt->ci_vars = u->va_next;
|
ft_curckt->ci_vars = u->va_next;
|
||||||
tfree(u);
|
tfree(u);
|
||||||
|
|
@ -555,14 +510,12 @@ cp_remvar(char *varname)
|
||||||
fprintf(cp_err, "cp_remvar: INTERNAL ERROR: US val %d\n", i);
|
fprintf(cp_err, "cp_remvar: INTERNAL ERROR: US val %d\n", i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->va_next = NULL;
|
v->va_next = NULL;
|
||||||
tfree(v->va_name);
|
tfree(v->va_name);
|
||||||
free_struct_variable(v);
|
free_struct_variable(v);
|
||||||
free_struct_variable(uv1);
|
free_struct_variable(uv1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine the value of a variable. Fail if the variable is unset,
|
* Determine the value of a variable. Fail if the variable is unset,
|
||||||
* and if the type doesn't match, try and make it work...
|
* and if the type doesn't match, try and make it work...
|
||||||
|
|
@ -572,9 +525,7 @@ cp_getvar(char *name, enum cp_types type, void *retval)
|
||||||
{
|
{
|
||||||
struct variable *v;
|
struct variable *v;
|
||||||
struct variable *uv1, *uv2;
|
struct variable *uv1, *uv2;
|
||||||
|
|
||||||
cp_usrvars(&uv1, &uv2);
|
cp_usrvars(&uv1, &uv2);
|
||||||
|
|
||||||
for (v = variables; v && !eq(name, v->va_name); v = v->va_next)
|
for (v = variables; v && !eq(name, v->va_name); v = v->va_next)
|
||||||
;
|
;
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
|
|
@ -583,14 +534,12 @@ cp_getvar(char *name, enum cp_types type, void *retval)
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
for (v = uv2; v && !eq(name, v->va_name); v = v->va_next)
|
for (v = uv2; v && !eq(name, v->va_name); v = v->va_next)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
if (type == CP_BOOL && retval)
|
if (type == CP_BOOL && retval)
|
||||||
* (bool *) retval = FALSE;
|
* (bool *) retval = FALSE;
|
||||||
free_struct_variable(uv1);
|
free_struct_variable(uv1);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->va_type == type) {
|
if (v->va_type == type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CP_BOOL:
|
case CP_BOOL:
|
||||||
|
|
@ -630,9 +579,7 @@ cp_getvar(char *name, enum cp_types type, void *retval)
|
||||||
}
|
}
|
||||||
free_struct_variable(uv1);
|
free_struct_variable(uv1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Try to coerce it.. */
|
/* Try to coerce it.. */
|
||||||
if ((type == CP_NUM) && (v->va_type == CP_REAL)) {
|
if ((type == CP_NUM) && (v->va_type == CP_REAL)) {
|
||||||
int *i;
|
int *i;
|
||||||
|
|
@ -660,7 +607,6 @@ cp_getvar(char *name, enum cp_types type, void *retval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* A variable substitution is indicated by a $, and the variable name
|
/* A variable substitution is indicated by a $, and the variable name
|
||||||
* is the following string of non-special characters. All variable
|
* is the following string of non-special characters. All variable
|
||||||
* values are inserted as a single word, except for lists, which are a
|
* values are inserted as a single word, except for lists, which are a
|
||||||
|
|
@ -685,7 +631,6 @@ span_var_expr(char *t)
|
||||||
{
|
{
|
||||||
int parenthesis = 0;
|
int parenthesis = 0;
|
||||||
int brackets = 0;
|
int brackets = 0;
|
||||||
|
|
||||||
while (*t && (isalphanum((int)*t) || strchr(VALIDCHARS, *t)))
|
while (*t && (isalphanum((int)*t) || strchr(VALIDCHARS, *t)))
|
||||||
switch (*t++)
|
switch (*t++)
|
||||||
{
|
{
|
||||||
|
|
@ -710,11 +655,9 @@ span_var_expr(char *t)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wordlist *
|
wordlist *
|
||||||
cp_variablesubst(wordlist *wlist)
|
cp_variablesubst(wordlist *wlist)
|
||||||
{
|
{
|
||||||
|
|
@ -724,7 +667,6 @@ cp_variablesubst(wordlist *wlist)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (wl = wlist; wl; wl = wl->wl_next) {
|
for (wl = wlist; wl; wl = wl->wl_next) {
|
||||||
|
|
||||||
t = wl->wl_word;
|
t = wl->wl_word;
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((s = strchr(t, cp_dol)) != NULL) {
|
while ((s = strchr(t, cp_dol)) != NULL) {
|
||||||
|
|
@ -744,9 +686,9 @@ cp_variablesubst(wordlist *wlist)
|
||||||
if (i) {
|
if (i) {
|
||||||
(void) strcpy(buf, wbuf);
|
(void) strcpy(buf, wbuf);
|
||||||
if (nwl) {
|
if (nwl) {
|
||||||
(void) strcat(buf, nwl->wl_word);
|
(void) strcat(buf, nwl->wl_word);
|
||||||
tfree(nwl->wl_word);
|
tfree(nwl->wl_word);
|
||||||
nwl->wl_word = copy(buf);
|
nwl->wl_word = copy(buf);
|
||||||
} else {
|
} else {
|
||||||
nwl = wl_cons(copy(buf), NULL);
|
nwl = wl_cons(copy(buf), NULL);
|
||||||
}
|
}
|
||||||
|
|
@ -770,11 +712,9 @@ cp_variablesubst(wordlist *wlist)
|
||||||
wbuf[i++] = *s;
|
wbuf[i++] = *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wlist;
|
return wlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Evaluate a variable. */
|
/* Evaluate a variable. */
|
||||||
wordlist *
|
wordlist *
|
||||||
vareval(char *string)
|
vareval(char *string)
|
||||||
|
|
@ -785,21 +725,17 @@ vareval(char *string)
|
||||||
char *oldstring = copy(string);
|
char *oldstring = copy(string);
|
||||||
char *range = NULL;
|
char *range = NULL;
|
||||||
int i, up, low;
|
int i, up, low;
|
||||||
|
|
||||||
cp_wstrip(string);
|
cp_wstrip(string);
|
||||||
if ((s = strchr(string, '[')) != NULL) {
|
if ((s = strchr(string, '[')) != NULL) {
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
range = s + 1;
|
range = s + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (*string) {
|
switch (*string) {
|
||||||
|
|
||||||
case '$':
|
case '$':
|
||||||
(void) sprintf(buf, "%d", getpid());
|
(void) sprintf(buf, "%d", getpid());
|
||||||
wl = wl_cons(copy(buf), NULL);
|
wl = wl_cons(copy(buf), NULL);
|
||||||
tfree(oldstring);
|
tfree(oldstring);
|
||||||
return (wl);
|
return (wl);
|
||||||
|
|
||||||
case '<':
|
case '<':
|
||||||
(void) fflush(cp_out);
|
(void) fflush(cp_out);
|
||||||
if (!fgets(buf, BSIZE_SP, cp_in)) {
|
if (!fgets(buf, BSIZE_SP, cp_in)) {
|
||||||
|
|
@ -815,7 +751,6 @@ vareval(char *string)
|
||||||
wl->wl_word = copy("");
|
wl->wl_word = copy("");
|
||||||
tfree(oldstring);
|
tfree(oldstring);
|
||||||
return (wl);
|
return (wl);
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
string++;
|
string++;
|
||||||
for (v = variables; v; v = v->va_next)
|
for (v = variables; v; v = v->va_next)
|
||||||
|
|
@ -826,7 +761,6 @@ vareval(char *string)
|
||||||
wl = wl_cons(copy(v ? "1" : "0"), NULL);
|
wl = wl_cons(copy(v ? "1" : "0"), NULL);
|
||||||
tfree(oldstring);
|
tfree(oldstring);
|
||||||
return (wl);
|
return (wl);
|
||||||
|
|
||||||
case '#':
|
case '#':
|
||||||
string++;
|
string++;
|
||||||
for (v = variables; v; v = v->va_next)
|
for (v = variables; v; v = v->va_next)
|
||||||
|
|
@ -848,13 +782,11 @@ vareval(char *string)
|
||||||
wl = wl_cons(copy(buf), NULL);
|
wl = wl_cons(copy(buf), NULL);
|
||||||
tfree(oldstring);
|
tfree(oldstring);
|
||||||
return (wl);
|
return (wl);
|
||||||
|
|
||||||
case '\0':
|
case '\0':
|
||||||
wl = wl_cons(copy("$"), NULL);
|
wl = wl_cons(copy("$"), NULL);
|
||||||
tfree(oldstring);
|
tfree(oldstring);
|
||||||
return (wl);
|
return (wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The notation var[stuff] has two meanings... If this is a real
|
/* The notation var[stuff] has two meanings... If this is a real
|
||||||
* variable, then the [] denotes range, but if this is a strange
|
* variable, then the [] denotes range, but if this is a strange
|
||||||
* (e.g, device parameter) variable, it could be anything...
|
* (e.g, device parameter) variable, it could be anything...
|
||||||
|
|
@ -884,7 +816,6 @@ vareval(char *string)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wl = cp_varwl(v);
|
wl = cp_varwl(v);
|
||||||
|
|
||||||
/* Now parse and deal with 'range' ... */
|
/* Now parse and deal with 'range' ... */
|
||||||
if (range) {
|
if (range) {
|
||||||
/* rather crude fix when range itself is a $expression */
|
/* rather crude fix when range itself is a $expression */
|
||||||
|
|
@ -922,21 +853,18 @@ vareval(char *string)
|
||||||
return wl;
|
return wl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vcmp(const void *a, const void *b)
|
vcmp(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct xxx *v1 = (struct xxx *) a;
|
struct xxx *v1 = (struct xxx *) a;
|
||||||
struct xxx *v2 = (struct xxx *) b;
|
struct xxx *v2 = (struct xxx *) b;
|
||||||
|
|
||||||
if ((i = strcmp(v1->x_v->va_name, v2->x_v->va_name)) != 0)
|
if ((i = strcmp(v1->x_v->va_name, v2->x_v->va_name)) != 0)
|
||||||
return (i);
|
return (i);
|
||||||
else
|
else
|
||||||
return (v1->x_char - v2->x_char);
|
return (v1->x_char - v2->x_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print the values of currently defined variables. */
|
/* Print the values of currently defined variables. */
|
||||||
void
|
void
|
||||||
cp_vprint(void)
|
cp_vprint(void)
|
||||||
|
|
@ -947,18 +875,14 @@ cp_vprint(void)
|
||||||
int i, j;
|
int i, j;
|
||||||
char *s;
|
char *s;
|
||||||
struct xxx *vars;
|
struct xxx *vars;
|
||||||
|
|
||||||
cp_usrvars(&uv1, &uv2);
|
cp_usrvars(&uv1, &uv2);
|
||||||
|
|
||||||
for (v = uv1, i = 0; v; v = v->va_next)
|
for (v = uv1, i = 0; v; v = v->va_next)
|
||||||
i++;
|
i++;
|
||||||
for (v = uv2; v; v = v->va_next)
|
for (v = uv2; v; v = v->va_next)
|
||||||
i++;
|
i++;
|
||||||
for (v = variables; v; v = v->va_next)
|
for (v = variables; v; v = v->va_next)
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
vars = TMALLOC(struct xxx, i);
|
vars = TMALLOC(struct xxx, i);
|
||||||
|
|
||||||
out_init();
|
out_init();
|
||||||
for (v = variables, i = 0; v; v = v->va_next, i++) {
|
for (v = variables, i = 0; v; v = v->va_next, i++) {
|
||||||
vars[i].x_v = v;
|
vars[i].x_v = v;
|
||||||
|
|
@ -972,9 +896,7 @@ cp_vprint(void)
|
||||||
vars[i].x_v = v;
|
vars[i].x_v = v;
|
||||||
vars[i].x_char = '+';
|
vars[i].x_char = '+';
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(vars, (size_t) i, sizeof(*vars), vcmp);
|
qsort(vars, (size_t) i, sizeof(*vars), vcmp);
|
||||||
|
|
||||||
for (j = 0; j < i; j++) {
|
for (j = 0; j < i; j++) {
|
||||||
if (j && eq(vars[j].x_v->va_name, vars[j-1].x_v->va_name))
|
if (j && eq(vars[j].x_v->va_name, vars[j-1].x_v->va_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -991,6 +913,5 @@ cp_vprint(void)
|
||||||
out_printf("%s\n", s);
|
out_printf("%s\n", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(vars);
|
tfree(vars);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/**********
|
/**********
|
||||||
Copyright 1990 Regents of the University of California. All rights reserved.
|
Copyright 1990 Regents of the University of California. All rights reserved.
|
||||||
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -24,7 +24,6 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||||
|
|
||||||
struct dvec *EVTfindvec(char *node);
|
struct dvec *EVTfindvec(char *node);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vec_rebuild_lookup_table(struct plot *pl)
|
vec_rebuild_lookup_table(struct plot *pl)
|
||||||
{
|
{
|
||||||
|
|
@ -55,7 +54,6 @@ vec_rebuild_lookup_table(struct plot *pl)
|
||||||
pl->pl_lookup_valid = TRUE;
|
pl->pl_lookup_valid = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Find a named vector in a plot. We are careful to copy the vector if
|
/* Find a named vector in a plot. We are careful to copy the vector if
|
||||||
* v_link2 is set, because otherwise we will get screwed up. */
|
* v_link2 is set, because otherwise we will get screwed up. */
|
||||||
static struct dvec *
|
static struct dvec *
|
||||||
|
|
@ -111,8 +109,8 @@ findvec(char *word, struct plot *pl)
|
||||||
for (d = pl->pl_dvecs; d; d = d->v_next) {
|
for (d = pl->pl_dvecs; d; d = d->v_next) {
|
||||||
if ((d->v_flags & VF_PERMANENT) && (d->v_type == SV_CURRENT)) {
|
if ((d->v_flags & VF_PERMANENT) && (d->v_type == SV_CURRENT)) {
|
||||||
if (d->v_link2) {
|
if (d->v_link2) {
|
||||||
v = vec_copy(d);
|
v = vec_copy(d);
|
||||||
vec_new(v);
|
vec_new(v);
|
||||||
} else {
|
} else {
|
||||||
v = d;
|
v = d;
|
||||||
}
|
}
|
||||||
|
|
@ -130,8 +128,8 @@ findvec(char *word, struct plot *pl)
|
||||||
for (d = pl->pl_dvecs; d; d = d->v_next) {
|
for (d = pl->pl_dvecs; d; d = d->v_next) {
|
||||||
if ((d->v_flags & VF_PERMANENT) && (!cieq(d->v_name, pl->pl_scale->v_name))) {
|
if ((d->v_flags & VF_PERMANENT) && (!cieq(d->v_name, pl->pl_scale->v_name))) {
|
||||||
if (d->v_link2) {
|
if (d->v_link2) {
|
||||||
v = vec_copy(d);
|
v = vec_copy(d);
|
||||||
vec_new(v);
|
vec_new(v);
|
||||||
} else {
|
} else {
|
||||||
v = d;
|
v = d;
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +185,6 @@ findvec(char *word, struct plot *pl)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* If there are imbedded numeric strings, compare them numerically, not
|
/* If there are imbedded numeric strings, compare them numerically, not
|
||||||
* alphabetically.
|
* alphabetically.
|
||||||
*/
|
*/
|
||||||
|
|
@ -219,7 +216,6 @@ namecmp(const void *a, const void *b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
veccmp(const void *a, const void *b)
|
veccmp(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
|
|
@ -233,7 +229,6 @@ veccmp(const void *a, const void *b)
|
||||||
return namecmp((*d1)->v_name, (*d2)->v_name);
|
return namecmp((*d1)->v_name, (*d2)->v_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Sort all the vectors in d, first by plot name and then by vector
|
/* Sort all the vectors in d, first by plot name and then by vector
|
||||||
* name. Do the right thing with numbers. */
|
* name. Do the right thing with numbers. */
|
||||||
static struct dvec *
|
static struct dvec *
|
||||||
|
|
@ -261,7 +256,6 @@ sortvecs(struct dvec *d)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Load in a rawfile. */
|
/* Load in a rawfile. */
|
||||||
void
|
void
|
||||||
ft_loadfile(char *file)
|
ft_loadfile(char *file)
|
||||||
|
|
@ -293,7 +287,6 @@ ft_loadfile(char *file)
|
||||||
plotl_changed = TRUE;
|
plotl_changed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
plot_add(struct plot *pl)
|
plot_add(struct plot *pl)
|
||||||
{
|
{
|
||||||
|
|
@ -303,7 +296,6 @@ plot_add(struct plot *pl)
|
||||||
|
|
||||||
fprintf(cp_out, "Title: %s\nName: %s\nDate: %s\n\n", pl->pl_title,
|
fprintf(cp_out, "Title: %s\nName: %s\nDate: %s\n\n", pl->pl_title,
|
||||||
pl->pl_name, pl->pl_date);
|
pl->pl_name, pl->pl_date);
|
||||||
|
|
||||||
if (plot_cur)
|
if (plot_cur)
|
||||||
plot_cur->pl_ccom = cp_kwswitch(CT_VECTOR, pl->pl_ccom);
|
plot_cur->pl_ccom = cp_kwswitch(CT_VECTOR, pl->pl_ccom);
|
||||||
|
|
||||||
|
|
@ -329,32 +321,24 @@ plot_add(struct plot *pl)
|
||||||
plot_setcur(pl->pl_typename);
|
plot_setcur(pl->pl_typename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Remove a vector from the database, if it is there. */
|
/* Remove a vector from the database, if it is there. */
|
||||||
|
|
||||||
void
|
void
|
||||||
vec_remove(char *name)
|
vec_remove(char *name)
|
||||||
{
|
{
|
||||||
struct dvec *ov;
|
struct dvec *ov;
|
||||||
|
|
||||||
for (ov = plot_cur->pl_dvecs; ov; ov = ov->v_next)
|
for (ov = plot_cur->pl_dvecs; ov; ov = ov->v_next)
|
||||||
if (cieq(name, ov->v_name) && (ov->v_flags & VF_PERMANENT))
|
if (cieq(name, ov->v_name) && (ov->v_flags & VF_PERMANENT))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!ov)
|
if (!ov)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ov->v_flags &= ~VF_PERMANENT;
|
ov->v_flags &= ~VF_PERMANENT;
|
||||||
|
|
||||||
/* Remove from the keyword list. */
|
/* Remove from the keyword list. */
|
||||||
cp_remkword(CT_VECTOR, name);
|
cp_remkword(CT_VECTOR, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get a vector by name. This deals with v(1), etc. almost properly. Also,
|
/* Get a vector by name. This deals with v(1), etc. almost properly. Also,
|
||||||
* it checks for pre-defined vectors.
|
* it checks for pre-defined vectors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct dvec *
|
struct dvec *
|
||||||
vec_fromplot(char *word, struct plot *plot)
|
vec_fromplot(char *word, struct plot *plot)
|
||||||
{
|
{
|
||||||
|
|
@ -374,7 +358,7 @@ vec_fromplot(char *word, struct plot *plot)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scanf("%c(%s)" doesn't do what it should do. ) */
|
/* scanf("%c(%s)" doesn't do what it should do. ) */
|
||||||
if (!d && (sscanf(word, "%c(%s", /* ) */ &cc, buf) == 2) &&
|
if (!d && (sscanf(word, "%c(%s", /* ) */ &cc, buf) == 2) &&
|
||||||
/* ( */ ((s = strrchr(buf, ')')) != NULL) &&
|
/* ( */ ((s = strrchr(buf, ')')) != NULL) &&
|
||||||
(s[1] == '\0')) {
|
(s[1] == '\0')) {
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
|
|
@ -385,17 +369,15 @@ vec_fromplot(char *word, struct plot *plot)
|
||||||
}
|
}
|
||||||
d = findvec(buf, plot);
|
d = findvec(buf, plot);
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is the main lookup routine for names. The possible types of names are:
|
/* This is the main lookup routine for names. The possible types of names are:
|
||||||
* name An ordinary vector.
|
* name An ordinary vector.
|
||||||
* plot.name A vector from a particular plot.
|
* plot.name A vector from a particular plot.
|
||||||
* @device[parm] A device parameter.
|
* @device[parm] A device parameter.
|
||||||
* @model[parm] A model parameter.
|
* @model[parm] A model parameter.
|
||||||
* @param A circuit parameter.
|
* @param A circuit parameter.
|
||||||
* For the @ cases, we construct a dvec with length 1 to hold the value.
|
* For the @ cases, we construct a dvec with length 1 to hold the value.
|
||||||
* In the other two cases, either the plot or the name can be "all", a
|
* In the other two cases, either the plot or the name can be "all", a
|
||||||
* wildcard.
|
* wildcard.
|
||||||
|
|
@ -413,12 +395,12 @@ vec_get(const char *vec_name)
|
||||||
char buf[BSIZE_SP], *s, *wd, *word, *whole, *name = NULL, *param;
|
char buf[BSIZE_SP], *s, *wd, *word, *whole, *name = NULL, *param;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
struct variable *vv;
|
struct variable *vv;
|
||||||
int indexvar; /* mhx */
|
int indexvar; /* mhx */
|
||||||
|
|
||||||
wd = word = copy(vec_name); /* Gets mangled below... */
|
wd = word = copy(vec_name); /* Gets mangled below... */
|
||||||
|
|
||||||
if (*word != SPECCHAR) { /* mhx: eventually replace atoi() by full evaluate */
|
if (*word != SPECCHAR) { /* mhx: eventually replace atoi() by full evaluate */
|
||||||
char *ps = strchr(wd, '['), *pe = strchr(wd, ']');
|
char *ps = strchr(wd, '['), *pe = strchr(wd, ']');
|
||||||
if (ps && pe && pe > ps) {
|
if (ps && pe && pe > ps) {
|
||||||
whole = copy(word);
|
whole = copy(word);
|
||||||
*ps = '\0';
|
*ps = '\0';
|
||||||
|
|
@ -448,7 +430,7 @@ vec_get(const char *vec_name)
|
||||||
} else {
|
} else {
|
||||||
/* This used to be an error... */
|
/* This used to be an error... */
|
||||||
pl = plot_cur;
|
pl = plot_cur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pl = plot_cur;
|
pl = plot_cur;
|
||||||
|
|
@ -486,16 +468,16 @@ vec_get(const char *vec_name)
|
||||||
(vector of length 1) instead of the vector.
|
(vector of length 1) instead of the vector.
|
||||||
Duplicates a lot of code that still follows :-( */
|
Duplicates a lot of code that still follows :-( */
|
||||||
if (d && indexvar != -1) {
|
if (d && indexvar != -1) {
|
||||||
struct dvec *ad;
|
struct dvec *ad;
|
||||||
ad = alloc(struct dvec);
|
ad = alloc(struct dvec);
|
||||||
ZERO(ad, struct dvec);
|
ZERO(ad, struct dvec);
|
||||||
ad->v_name = copy(whole); /* so the name could be data[2] or data[expression] :-) */
|
ad->v_name = copy(whole); /* so the name could be data[2] or data[expression] :-) */
|
||||||
ad->v_type = d->v_type;
|
ad->v_type = d->v_type;
|
||||||
ad->v_flags = d->v_flags; /* VF_REAL; or complex? */
|
ad->v_flags = d->v_flags; /* VF_REAL; or complex? */
|
||||||
ad->v_length = 1;
|
ad->v_length = 1;
|
||||||
ad->v_realdata = TMALLOC(double, 1);
|
ad->v_realdata = TMALLOC(double, 1);
|
||||||
*ad->v_realdata = *d->v_realdata;
|
*ad->v_realdata = *d->v_realdata;
|
||||||
tfree(whole);
|
tfree(whole);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d && (*word == SPECCHAR)) {
|
if (!d && (*word == SPECCHAR)) {
|
||||||
|
|
@ -521,14 +503,12 @@ vec_get(const char *vec_name)
|
||||||
param = NULL;
|
param = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ft_curckt) {
|
if (ft_curckt) {
|
||||||
/*
|
/*
|
||||||
* This is what is done in case of "alter r1 resistance = 1234"
|
* This is what is done in case of "alter r1 resistance = 1234"
|
||||||
* r1 resistance, 0
|
* r1 resistance, 0
|
||||||
* if_setparam(ft_curckt->ci_ckt, &dev, param, dv, do_model);
|
* if_setparam(ft_curckt->ci_ckt, &dev, param, dv, do_model);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* vv = if_getparam (ft_curckt->ci_ckt, &name, param, 0, 0); */
|
/* vv = if_getparam (ft_curckt->ci_ckt, &name, param, 0, 0); */
|
||||||
vv = if_getparam(ft_curckt->ci_ckt, &name, param, 0, 0);
|
vv = if_getparam(ft_curckt->ci_ckt, &name, param, 0, 0);
|
||||||
if (!vv) {
|
if (!vv) {
|
||||||
|
|
@ -595,7 +575,6 @@ vec_get(const char *vec_name)
|
||||||
* used with the parameters of isrc and vsrc
|
* used with the parameters of isrc and vsrc
|
||||||
*/
|
*/
|
||||||
struct variable *nv;
|
struct variable *nv;
|
||||||
|
|
||||||
double *list;
|
double *list;
|
||||||
list = TMALLOC(double, 1);
|
list = TMALLOC(double, 1);
|
||||||
nv = alloc(struct variable);
|
nv = alloc(struct variable);
|
||||||
|
|
@ -646,17 +625,15 @@ vec_get(const char *vec_name)
|
||||||
case CP_NUM:
|
case CP_NUM:
|
||||||
fprintf(stdout, "%s=%d\n", nv->va_name, nv->va_num);
|
fprintf(stdout, "%s=%d\n", nv->va_name, nv->va_num);
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
fprintf(stderr, "ERROR: enumeration value `CP_BOOL' or `CP_LIST' not handled in vec_get\nAborting...\n");
|
fprintf(stderr, "ERROR: enumeration value `CP_BOOL' or `CP_LIST' not handled in vec_get\nAborting...\n");
|
||||||
controlled_exit(EXIT_FAILURE);
|
controlled_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nv = nv->va_next;
|
nv = nv->va_next;
|
||||||
|
|
||||||
if (!nv)
|
if (!nv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To distinguish those does not take anything for print screen to
|
/* To distinguish those does not take anything for print screen to
|
||||||
* make a print or M1 @ @ M1 [all] leaving only the correct data
|
* make a print or M1 @ @ M1 [all] leaving only the correct data
|
||||||
* and not the last
|
* and not the last
|
||||||
|
|
@ -664,7 +641,6 @@ vec_get(const char *vec_name)
|
||||||
d->v_rlength = 1;
|
d->v_rlength = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(vv->va_name);
|
tfree(vv->va_name);
|
||||||
tfree(vv); /* va: tfree vv->va_name and vv (avoid memory leakages) */
|
tfree(vv); /* va: tfree vv->va_name and vv (avoid memory leakages) */
|
||||||
tfree(wd);
|
tfree(wd);
|
||||||
|
|
@ -672,16 +648,13 @@ vec_get(const char *vec_name)
|
||||||
tfree(whole);
|
tfree(whole);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(wd);
|
tfree(wd);
|
||||||
return sortvecs(d);
|
return sortvecs(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Execute the commands for a plot. This is done whenever a plot becomes
|
/* Execute the commands for a plot. This is done whenever a plot becomes
|
||||||
* the current plot.
|
* the current plot.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
plot_docoms(wordlist *wl)
|
plot_docoms(wordlist *wl)
|
||||||
{
|
{
|
||||||
|
|
@ -697,9 +670,7 @@ plot_docoms(wordlist *wl)
|
||||||
cp_interactive = inter;
|
cp_interactive = inter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Create a copy of a vector. */
|
/* Create a copy of a vector. */
|
||||||
|
|
||||||
struct dvec *
|
struct dvec *
|
||||||
vec_copy(struct dvec *v)
|
vec_copy(struct dvec *v)
|
||||||
{
|
{
|
||||||
|
|
@ -743,9 +714,9 @@ vec_copy(struct dvec *v)
|
||||||
*/
|
*/
|
||||||
nv->v_rlength = v->v_rlength;
|
nv->v_rlength = v->v_rlength;
|
||||||
|
|
||||||
nv->v_outindex = 0; /*XXX???*/
|
nv->v_outindex = 0; /*XXX???*/
|
||||||
nv->v_linestyle = 0; /*XXX???*/
|
nv->v_linestyle = 0; /*XXX???*/
|
||||||
nv->v_color = 0; /*XXX???*/
|
nv->v_color = 0; /*XXX???*/
|
||||||
nv->v_defcolor = v->v_defcolor;
|
nv->v_defcolor = v->v_defcolor;
|
||||||
nv->v_numdims = v->v_numdims;
|
nv->v_numdims = v->v_numdims;
|
||||||
for (i = 0; i < v->v_numdims; i++)
|
for (i = 0; i < v->v_numdims; i++)
|
||||||
|
|
@ -758,11 +729,9 @@ vec_copy(struct dvec *v)
|
||||||
return nv;
|
return nv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Create a new plot structure. This just fills in the typename and sets up
|
/* Create a new plot structure. This just fills in the typename and sets up
|
||||||
* the ccom struct.
|
* the ccom struct.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct plot *
|
struct plot *
|
||||||
plot_alloc(char *name)
|
plot_alloc(char *name)
|
||||||
{
|
{
|
||||||
|
|
@ -792,16 +761,14 @@ plot_alloc(char *name)
|
||||||
return pl;
|
return pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Stick a new vector in the proper place in the plot list. */
|
/* Stick a new vector in the proper place in the plot list. */
|
||||||
|
|
||||||
void
|
void
|
||||||
vec_new(struct dvec *d)
|
vec_new(struct dvec *d)
|
||||||
{
|
{
|
||||||
/* Note that this can't happen. */
|
/* Note that this can't happen. */
|
||||||
if (plot_cur == NULL) {
|
if (plot_cur == NULL) {
|
||||||
fprintf(cp_err, "vec_new: INTERNAL ERROR: no cur plot\n");
|
fprintf(cp_err, "vec_new: INTERNAL ERROR: no cur plot\n");
|
||||||
controlled_exit(1);
|
controlled_exit(1);
|
||||||
}
|
}
|
||||||
plot_cur->pl_lookup_valid = FALSE;
|
plot_cur->pl_lookup_valid = FALSE;
|
||||||
if ((d->v_flags & VF_PERMANENT) && (plot_cur->pl_scale == NULL))
|
if ((d->v_flags & VF_PERMANENT) && (plot_cur->pl_scale == NULL))
|
||||||
|
|
@ -816,7 +783,6 @@ vec_new(struct dvec *d)
|
||||||
d->v_plot->pl_dvecs = d;
|
d->v_plot->pl_dvecs = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Because of the way that all vectors, including temporary vectors,
|
/* Because of the way that all vectors, including temporary vectors,
|
||||||
* are linked together under the current plot, they can often be
|
* are linked together under the current plot, they can often be
|
||||||
* left lying around. This gets rid of all vectors that don't have
|
* left lying around. This gets rid of all vectors that don't have
|
||||||
|
|
@ -841,13 +807,11 @@ vec_gc(void)
|
||||||
vec_free(d);
|
vec_free(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (pl = plot_list; pl; pl = pl->pl_next)
|
for (pl = plot_list; pl; pl = pl->pl_next)
|
||||||
for (d = pl->pl_dvecs; d; d = d->v_next)
|
for (d = pl->pl_dvecs; d; d = d->v_next)
|
||||||
d->v_link2 = NULL;
|
d->v_link2 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Free a dvector. This is sort of a pain because we also have to make sure
|
/* Free a dvector. This is sort of a pain because we also have to make sure
|
||||||
* that it has been unlinked from its plot structure. If the name of the
|
* that it has been unlinked from its plot structure. If the name of the
|
||||||
* vector is NULL, then we have already freed it so don't try again. (This
|
* vector is NULL, then we have already freed it so don't try again. (This
|
||||||
|
|
@ -885,14 +849,14 @@ vec_free_x(struct dvec *v)
|
||||||
}
|
}
|
||||||
if (pl->pl_scale == v) {
|
if (pl->pl_scale == v) {
|
||||||
if (pl->pl_dvecs)
|
if (pl->pl_dvecs)
|
||||||
pl->pl_scale = pl->pl_dvecs; /* Random one... */
|
pl->pl_scale = pl->pl_dvecs; /* Random one... */
|
||||||
else
|
else
|
||||||
pl->pl_scale = NULL;
|
pl->pl_scale = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->v_name)
|
if (v->v_name)
|
||||||
tfree(v->v_name);
|
tfree(v->v_name);
|
||||||
if (v->v_realdata)
|
if (v->v_realdata)
|
||||||
tfree(v->v_realdata);
|
tfree(v->v_realdata);
|
||||||
if (v->v_compdata)
|
if (v->v_compdata)
|
||||||
|
|
@ -900,34 +864,29 @@ vec_free_x(struct dvec *v)
|
||||||
tfree(v);
|
tfree(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return TRUE if every vector element is zero
|
* return TRUE if every vector element is zero
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
vec_iszero(struct dvec *v)
|
vec_iszero(struct dvec *v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
for (; v; v = v->v_link2)
|
||||||
for (; v; v = v->v_link2)
|
if (isreal(v))
|
||||||
if (isreal(v))
|
for (i = 0; i < v->v_length; i++) {
|
||||||
for (i = 0; i < v->v_length; i++) {
|
|
||||||
if (v->v_realdata[i] != 0.0)
|
if (v->v_realdata[i] != 0.0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (i = 0; i < v->v_length; i++) {
|
for (i = 0; i < v->v_length; i++) {
|
||||||
if (realpart(v->v_compdata[i]) != 0.0)
|
if (realpart(v->v_compdata[i]) != 0.0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (imagpart(v->v_compdata[i]) != 0.0)
|
if (imagpart(v->v_compdata[i]) != 0.0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is something we do in a few places... Since vectors get copied a lot,
|
/* This is something we do in a few places... Since vectors get copied a lot,
|
||||||
* we can't just compare pointers to tell if two vectors are 'really' the same.
|
* we can't just compare pointers to tell if two vectors are 'really' the same.
|
||||||
*/
|
*/
|
||||||
|
|
@ -945,7 +904,7 @@ vec_eq(struct dvec *v1, struct dvec *v2)
|
||||||
s2 = vec_basename(v2);
|
s2 = vec_basename(v2);
|
||||||
|
|
||||||
if (cieq(s1, s2))
|
if (cieq(s1, s2))
|
||||||
rtn = TRUE;
|
rtn = TRUE;
|
||||||
else
|
else
|
||||||
rtn = FALSE;
|
rtn = FALSE;
|
||||||
|
|
||||||
|
|
@ -966,7 +925,7 @@ vec_basename(struct dvec *v)
|
||||||
|
|
||||||
if (strchr(v->v_name, '.')) {
|
if (strchr(v->v_name, '.')) {
|
||||||
if (cieq(v->v_plot->pl_typename, v->v_name))
|
if (cieq(v->v_plot->pl_typename, v->v_name))
|
||||||
(void) strcpy(buf, v->v_name + strlen(v->v_name) + 1);
|
(void) strcpy(buf, v->v_name + strlen(v->v_name) + 1);
|
||||||
else
|
else
|
||||||
(void) strcpy(buf, v->v_name);
|
(void) strcpy(buf, v->v_name);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -984,7 +943,6 @@ vec_basename(struct dvec *v)
|
||||||
return copy(s);
|
return copy(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Make a plot the current one. This gets called by cp_usrset() when one
|
/* Make a plot the current one. This gets called by cp_usrset() when one
|
||||||
* does a 'set curplot = name'.
|
* does a 'set curplot = name'.
|
||||||
* va: ATTENTION: has unlinked old keyword-class-tree from keywords[CT_VECTOR]
|
* va: ATTENTION: has unlinked old keyword-class-tree from keywords[CT_VECTOR]
|
||||||
|
|
@ -1042,7 +1000,6 @@ plot_new(struct plot *pl)
|
||||||
* The data array is replaced with a new one that has the elements
|
* The data array is replaced with a new one that has the elements
|
||||||
* in the proper order. Otherwise the transposition is done in place.
|
* in the proper order. Otherwise the transposition is done in place.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
vec_transpose(struct dvec *v)
|
vec_transpose(struct dvec *v)
|
||||||
{
|
{
|
||||||
|
|
@ -1064,7 +1021,6 @@ vec_transpose(struct dvec *v)
|
||||||
*/
|
*/
|
||||||
blocksize = dim0*dim1;
|
blocksize = dim0*dim1;
|
||||||
nummatrices = v->v_length / blocksize;
|
nummatrices = v->v_length / blocksize;
|
||||||
|
|
||||||
/* Note:
|
/* Note:
|
||||||
* olda[i,j] is at data[i*dim0+j]
|
* olda[i,j] is at data[i*dim0+j]
|
||||||
* newa[j,i] is at data[j*dim1+i]
|
* newa[j,i] is at data[j*dim1+i]
|
||||||
|
|
@ -1074,7 +1030,6 @@ vec_transpose(struct dvec *v)
|
||||||
* though. The formulation below gathers scattered old data into
|
* though. The formulation below gathers scattered old data into
|
||||||
* consecutive new data.
|
* consecutive new data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (isreal(v)) {
|
if (isreal(v)) {
|
||||||
newreal = TMALLOC(double, v->v_length);
|
newreal = TMALLOC(double, v->v_length);
|
||||||
oldreal = v->v_realdata;
|
oldreal = v->v_realdata;
|
||||||
|
|
@ -1119,7 +1074,6 @@ vec_transpose(struct dvec *v)
|
||||||
* of 1-d vectors, linked together with v_link2. It is here so that plot
|
* of 1-d vectors, linked together with v_link2. It is here so that plot
|
||||||
* can do intelligent things.
|
* can do intelligent things.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct dvec *
|
struct dvec *
|
||||||
vec_mkfamily(struct dvec *v)
|
vec_mkfamily(struct dvec *v)
|
||||||
{
|
{
|
||||||
|
|
@ -1145,14 +1099,11 @@ vec_mkfamily(struct dvec *v)
|
||||||
for (i = 0; i < MAXDIMS; i++)
|
for (i = 0; i < MAXDIMS; i++)
|
||||||
count[i] = 0;
|
count[i] = 0;
|
||||||
for (d = vecs, j = 0; d; j++, d = d->v_link2) {
|
for (d = vecs, j = 0; d; j++, d = d->v_link2) {
|
||||||
|
|
||||||
indexstring(count, v->v_numdims - 1, buf2);
|
indexstring(count, v->v_numdims - 1, buf2);
|
||||||
|
|
||||||
(void) sprintf(buf, "%s%s", v->v_name, buf2);
|
(void) sprintf(buf, "%s%s", v->v_name, buf2);
|
||||||
d->v_name = copy(buf);
|
d->v_name = copy(buf);
|
||||||
d->v_type = v->v_type;
|
d->v_type = v->v_type;
|
||||||
d->v_flags = v->v_flags;
|
d->v_flags = v->v_flags;
|
||||||
|
|
||||||
d->v_minsignal = v->v_minsignal;
|
d->v_minsignal = v->v_minsignal;
|
||||||
d->v_maxsignal = v->v_maxsignal;
|
d->v_maxsignal = v->v_maxsignal;
|
||||||
d->v_gridtype = v->v_gridtype;
|
d->v_gridtype = v->v_gridtype;
|
||||||
|
|
@ -1177,13 +1128,10 @@ vec_mkfamily(struct dvec *v)
|
||||||
|
|
||||||
for (d = vecs; d; d = d->v_link2)
|
for (d = vecs; d; d = d->v_link2)
|
||||||
vec_new(d);
|
vec_new(d);
|
||||||
|
|
||||||
return vecs;
|
return vecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This function will match "op" with "op1", but not "op1" with "op12". */
|
/* This function will match "op" with "op1", but not "op1" with "op12". */
|
||||||
|
|
||||||
bool
|
bool
|
||||||
plot_prefix(char *pre, char *str)
|
plot_prefix(char *pre, char *str)
|
||||||
{
|
{
|
||||||
|
|
@ -1198,7 +1146,7 @@ plot_prefix(char *pre, char *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pre || (*str && isdigit((int)pre[-1])))
|
if (*pre || (*str && isdigit((int)pre[-1])))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
else
|
else
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue