Browse Source

struct variable, #17/18, clean

pre-master-46
rlar 10 years ago
parent
commit
a6cd5eea45
  1. 11
      src/frontend/ftesopt.c
  2. 36
      src/frontend/options.c
  3. 16
      src/frontend/spiceif.c
  4. 12
      src/frontend/variable.c

11
src/frontend/ftesopt.c

@ -52,18 +52,13 @@ ft_getstat(struct circ *ci, char *name)
static struct variable * static struct variable *
getFTEstat(struct FTEparm *p, FTESTATistics *stat, struct variable *next) getFTEstat(struct FTEparm *p, FTESTATistics *stat, struct variable *next)
{ {
struct variable *v;
switch (p->id) { switch (p->id) {
case FTEOPT_NLDECK: case FTEOPT_NLDECK:
v = var_alloc_num(copy(p->description), stat->FTESTATdeckNumLines, next);
return v;
return var_alloc_num(copy(p->description), stat->FTESTATdeckNumLines, next);
case FTEOPT_NLT: case FTEOPT_NLT:
v = var_alloc_real(copy(p->description), stat->FTESTATnetLoadTime, next);
return v;
return var_alloc_real(copy(p->description), stat->FTESTATnetLoadTime, next);
case FTEOPT_NPT: case FTEOPT_NPT:
v = var_alloc_real(copy(p->description), stat->FTESTATnetParseTime, next);
return v;
return var_alloc_real(copy(p->description), stat->FTESTATnetParseTime, next);
default: default:
return NULL; return NULL;
} }

36
src/frontend/options.c

@ -48,11 +48,15 @@ cp_enqvar(char *word)
if (!d) if (!d)
return (NULL); return (NULL);
if (d->v_link2)
fprintf(cp_err,
"Warning: only one vector may be accessed with the $& notation.\n");
if (d->v_length == 1) { if (d->v_length == 1) {
double value = isreal(d) double value = isreal(d)
? d->v_realdata[0] ? d->v_realdata[0]
: realpart(d->v_compdata[0]); : realpart(d->v_compdata[0]);
vv = var_alloc_real(copy(word), value, NULL);
return var_alloc_real(copy(word), value, NULL);
} else { } else {
struct variable *list = NULL; struct variable *list = NULL;
int i; int i;
@ -62,38 +66,30 @@ cp_enqvar(char *word)
: realpart(d->v_compdata[i]); : realpart(d->v_compdata[i]);
list = var_alloc_real(NULL, value, list); list = var_alloc_real(NULL, value, list);
} }
vv = var_alloc_vlist(copy(word), list, NULL);
return var_alloc_vlist(copy(word), list, NULL);
} }
if (d->v_link2)
fprintf(cp_err,
"Warning: only one vector may be accessed with the $& notation.\n");
return (vv);
} }
if (plot_cur) { if (plot_cur) {
for (vv = plot_cur->pl_env; vv; vv = vv->va_next) for (vv = plot_cur->pl_env; vv; vv = vv->va_next)
if (eq(vv->va_name, word)) if (eq(vv->va_name, word))
return (vv); return (vv);
if (eq(word, "curplotname")) {
vv = var_alloc_string(copy(word), copy(plot_cur->pl_name), NULL);
} else if (eq(word, "curplottitle")) {
vv = var_alloc_string(copy(word), copy(plot_cur->pl_title), NULL);
} else if (eq(word, "curplotdate")) {
vv = var_alloc_string(copy(word), copy(plot_cur->pl_date), NULL);
} else if (eq(word, "curplot")) {
vv = var_alloc_string(copy(word), copy(plot_cur->pl_typename), NULL);
} else if (eq(word, "plots")) {
if (eq(word, "curplotname"))
return var_alloc_string(copy(word), copy(plot_cur->pl_name), NULL);
if (eq(word, "curplottitle"))
return var_alloc_string(copy(word), copy(plot_cur->pl_title), NULL);
if (eq(word, "curplotdate"))
return var_alloc_string(copy(word), copy(plot_cur->pl_date), NULL);
if (eq(word, "curplot"))
return var_alloc_string(copy(word), copy(plot_cur->pl_typename), NULL);
if (eq(word, "plots")) {
struct variable *list = NULL; struct variable *list = NULL;
struct plot *pl; struct plot *pl;
for (pl = plot_list; pl; pl = pl->pl_next) { for (pl = plot_list; pl; pl = pl->pl_next) {
list = var_alloc_string(NULL, copy(pl->pl_typename), list); list = var_alloc_string(NULL, copy(pl->pl_typename), list);
} }
vv = var_alloc_vlist(copy(word), list, NULL);
return var_alloc_vlist(copy(word), list, NULL);
} }
if (vv)
return (vv);
} }
if (ft_curckt) if (ft_curckt)

16
src/frontend/spiceif.c

@ -960,30 +960,24 @@ parmtovar(IFvalue *pv, IFparm *opt)
{ {
/* It is not clear whether we want to name the variable /* It is not clear whether we want to name the variable
* by `keyword' or by `description' */ * by `keyword' or by `description' */
struct variable *vv;
switch (opt->dataType & IF_VARTYPES) { switch (opt->dataType & IF_VARTYPES) {
case IF_INTEGER: case IF_INTEGER:
vv = var_alloc_num(copy(opt->description), pv->iValue, NULL);
return vv;
return var_alloc_num(copy(opt->description), pv->iValue, NULL);
case IF_REAL: case IF_REAL:
case IF_COMPLEX: case IF_COMPLEX:
vv = var_alloc_real(copy(opt->description), pv->rValue, NULL);
return vv;
return var_alloc_real(copy(opt->description), pv->rValue, NULL);
case IF_STRING: case IF_STRING:
vv = var_alloc_string(copy(opt->description), pv->sValue, NULL);
return vv;
return var_alloc_string(copy(opt->description), pv->sValue, NULL);
case IF_FLAG: case IF_FLAG:
vv = var_alloc_bool(copy(opt->description), pv->iValue ? TRUE : FALSE, NULL);
return vv;
return var_alloc_bool(copy(opt->description), pv->iValue ? TRUE : FALSE, NULL);
case IF_REALVEC: { case IF_REALVEC: {
struct variable *list = NULL; struct variable *list = NULL;
int i; int i;
for (i = pv->v.numValue; --i >= 0;) { for (i = pv->v.numValue; --i >= 0;) {
list = var_alloc_real(NULL, pv->v.vec.rVec[i], list); list = var_alloc_real(NULL, pv->v.vec.rVec[i], list);
} }
vv = var_alloc_vlist(copy(opt->description), list, NULL);
return vv;
return var_alloc_vlist(copy(opt->description), list, NULL);
/* It is a linked list where the first node is a variable /* It is a linked list where the first node is a variable
* pointing to the different values of the variables. * pointing to the different values of the variables.
* *

12
src/frontend/variable.c

@ -278,8 +278,7 @@ cp_setparse(wordlist *wl)
wl = wl->wl_next; wl = wl->wl_next;
if ((!wl || (*wl->wl_word != '=')) && !strchr(name, '=')) { if ((!wl || (*wl->wl_word != '=')) && !strchr(name, '=')) {
vv = var_alloc_bool(copy(name), TRUE, vars);
vars = vv;
vars = var_alloc_bool(copy(name), TRUE, vars);
tfree(name); /*DG: cp_unquote Memory leak*/ tfree(name); /*DG: cp_unquote Memory leak*/
continue; continue;
} }
@ -362,8 +361,7 @@ cp_setparse(wordlist *wl)
return (NULL); return (NULL);
} }
vv = var_alloc_vlist(copy(name), listv, vars);
vars = vv;
vars = var_alloc_vlist(copy(name), listv, vars);
wl = wl->wl_next; wl = wl->wl_next;
continue; continue;
@ -373,11 +371,9 @@ cp_setparse(wordlist *wl)
td = ft_numparse(&ss, FALSE); td = ft_numparse(&ss, FALSE);
if (td) { if (td) {
/*** We should try to get CP_NUM's... */ /*** We should try to get CP_NUM's... */
vv = var_alloc_real(copy(name), *td, vars);
vars = vv;
vars = var_alloc_real(copy(name), *td, vars);
} else { } else {
vv = var_alloc_string(copy(name), copy(val), vars);
vars = vv;
vars = var_alloc_string(copy(name), copy(val), vars);
} }
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 */

Loading…
Cancel
Save