Browse Source

struct variable, #12/18, rewrite in terms of `var_alloc()' (do-2)

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

12
src/frontend/ftesopt.c

@ -56,21 +56,15 @@ getFTEstat(struct FTEparm *p, FTESTATistics *stat, struct variable *next)
switch (p->id) { switch (p->id) {
case FTEOPT_NLDECK: case FTEOPT_NLDECK:
v = TMALLOC(struct variable, 1);
v->va_name = copy(p->description);
v->va_next = next;
v = var_alloc(copy(p->description), next);
var_set_num(v, stat->FTESTATdeckNumLines); var_set_num(v, stat->FTESTATdeckNumLines);
return v; return v;
case FTEOPT_NLT: case FTEOPT_NLT:
v = TMALLOC(struct variable, 1);
v->va_name = copy(p->description);
v->va_next = next;
v = var_alloc(copy(p->description), next);
var_set_real(v, stat->FTESTATnetLoadTime); var_set_real(v, stat->FTESTATnetLoadTime);
return v; return v;
case FTEOPT_NPT: case FTEOPT_NPT:
v = TMALLOC(struct variable, 1);
v->va_name = copy(p->description);
v->va_next = next;
v = var_alloc(copy(p->description), next);
var_set_real(v, stat->FTESTATnetParseTime); var_set_real(v, stat->FTESTATnetParseTime);
return v; return v;
default: default:

36
src/frontend/options.c

@ -52,9 +52,7 @@ cp_enqvar(char *word)
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 = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_real(vv, value); var_set_real(vv, value);
} else { } else {
struct variable *list = NULL; struct variable *list = NULL;
@ -64,15 +62,11 @@ cp_enqvar(char *word)
? d->v_realdata[i] ? d->v_realdata[i]
: realpart(d->v_compdata[i]); : realpart(d->v_compdata[i]);
struct variable *tv; struct variable *tv;
tv = TMALLOC(struct variable, 1);
tv->va_name = NULL;
tv->va_next = list;
tv = var_alloc(NULL, list);
var_set_real(tv, value); var_set_real(tv, value);
list = tv; list = tv;
} }
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_vlist(vv, list); var_set_vlist(vv, list);
} }
@ -88,39 +82,27 @@ cp_enqvar(char *word)
if (eq(vv->va_name, word)) if (eq(vv->va_name, word))
return (vv); return (vv);
if (eq(word, "curplotname")) { if (eq(word, "curplotname")) {
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_string(vv, copy(plot_cur->pl_name)); var_set_string(vv, copy(plot_cur->pl_name));
} else if (eq(word, "curplottitle")) { } else if (eq(word, "curplottitle")) {
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_string(vv, copy(plot_cur->pl_title)); var_set_string(vv, copy(plot_cur->pl_title));
} else if (eq(word, "curplotdate")) { } else if (eq(word, "curplotdate")) {
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_string(vv, copy(plot_cur->pl_date)); var_set_string(vv, copy(plot_cur->pl_date));
} else if (eq(word, "curplot")) { } else if (eq(word, "curplot")) {
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_string(vv, copy(plot_cur->pl_typename)); var_set_string(vv, copy(plot_cur->pl_typename));
} else if (eq(word, "plots")) { } else 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) {
struct variable *tv; struct variable *tv;
tv = TMALLOC(struct variable, 1);
tv->va_name = NULL;
tv->va_next = list;
tv = var_alloc(NULL, list);
var_set_string(tv, copy(pl->pl_typename)); var_set_string(tv, copy(pl->pl_typename));
list = tv; list = tv;
} }
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word);
vv->va_next = NULL;
vv = var_alloc(copy(word), NULL);
var_set_vlist(vv, list); var_set_vlist(vv, list);
} }
if (vv) if (vv)

24
src/frontend/spiceif.c

@ -964,28 +964,20 @@ parmtovar(IFvalue *pv, IFparm *opt)
switch (opt->dataType & IF_VARTYPES) { switch (opt->dataType & IF_VARTYPES) {
case IF_INTEGER: case IF_INTEGER:
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description);
vv->va_next = NULL;
vv = var_alloc(copy(opt->description), NULL);
var_set_num(vv, pv->iValue); var_set_num(vv, pv->iValue);
return vv; return vv;
case IF_REAL: case IF_REAL:
case IF_COMPLEX: case IF_COMPLEX:
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description);
vv->va_next = NULL;
vv = var_alloc(copy(opt->description), NULL);
var_set_real(vv, pv->rValue); var_set_real(vv, pv->rValue);
return vv; return vv;
case IF_STRING: case IF_STRING:
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description);
vv->va_next = NULL;
vv = var_alloc(copy(opt->description), NULL);
var_set_string(vv, pv->sValue); var_set_string(vv, pv->sValue);
return vv; return vv;
case IF_FLAG: case IF_FLAG:
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description);
vv->va_next = NULL;
vv = var_alloc(copy(opt->description), NULL);
var_set_bool(vv, pv->iValue ? TRUE : FALSE); var_set_bool(vv, pv->iValue ? TRUE : FALSE);
return vv; return vv;
case IF_REALVEC: { case IF_REALVEC: {
@ -993,15 +985,11 @@ parmtovar(IFvalue *pv, IFparm *opt)
int i; int i;
for (i = pv->v.numValue; --i >= 0;) { for (i = pv->v.numValue; --i >= 0;) {
struct variable *nv; struct variable *nv;
nv = TMALLOC(struct variable, 1);
nv->va_name = NULL;
nv->va_next = list;
nv = var_alloc(NULL, list);
var_set_real(nv, pv->v.vec.rVec[i]); var_set_real(nv, pv->v.vec.rVec[i]);
list = nv; list = nv;
} }
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description);
vv->va_next = NULL;
vv = var_alloc(copy(opt->description), NULL);
var_set_vlist(vv, list); var_set_vlist(vv, list);
return vv; return vv;
/* It is a linked list where the first node is a variable /* It is a linked list where the first node is a variable

24
src/frontend/variable.c

@ -104,9 +104,7 @@ cp_vset(char *varname, enum cp_types type, void *value)
} }
if (!v) { if (!v) {
v = TMALLOC(struct variable, 1);
v->va_name = copy(copyvarname);
v->va_next = NULL;
v = var_alloc(copy(copyvarname), NULL);
v_free = TRUE; v_free = TRUE;
} }
@ -280,9 +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 = TMALLOC(struct variable, 1);
vv->va_name = copy(name);
vv->va_next = vars;
vv = var_alloc(copy(name), vars);
var_set_bool(vv, TRUE); var_set_bool(vv, TRUE);
vars = vv; vars = vv;
tfree(name); /*DG: cp_unquote Memory leak*/ tfree(name); /*DG: cp_unquote Memory leak*/
@ -343,9 +339,7 @@ cp_setparse(wordlist *wl)
if (!--balance) if (!--balance)
break; break;
} }
vv = TMALLOC(struct variable, 1);
vv->va_name = NULL;
vv->va_next = NULL;
vv = var_alloc(NULL, NULL);
copyval = ss = cp_unquote(wl->wl_word); copyval = ss = cp_unquote(wl->wl_word);
td = ft_numparse(&ss, FALSE); td = ft_numparse(&ss, FALSE);
if (td) { if (td) {
@ -370,9 +364,7 @@ cp_setparse(wordlist *wl)
return (NULL); return (NULL);
} }
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(name);
vv->va_next = vars;
vv = var_alloc(copy(name), vars);
var_set_vlist(vv, listv); var_set_vlist(vv, listv);
vars = vv; vars = vv;
@ -382,9 +374,7 @@ cp_setparse(wordlist *wl)
copyval = ss = cp_unquote(val); copyval = ss = cp_unquote(val);
td = ft_numparse(&ss, FALSE); td = ft_numparse(&ss, FALSE);
vv = TMALLOC(struct variable, 1);
vv->va_name = copy(name);
vv->va_next = vars;
vv = var_alloc(copy(name), vars);
vars = vv; vars = vv;
if (td) { if (td) {
/*** We should try to get CP_NUM's... */ /*** We should try to get CP_NUM's... */
@ -454,9 +444,7 @@ cp_remvar(char *varname)
} }
if (!v) { if (!v) {
/* Gotta make up a var struct for cp_usrset()... */ /* Gotta make up a var struct for cp_usrset()... */
v = TMALLOC(struct variable, 1);
v->va_name = copy(varname);
v->va_next = NULL;
v = var_alloc(copy(varname), NULL);
var_set_num(v, 0); var_set_num(v, 0);
found = FALSE; found = FALSE;
} }

Loading…
Cancel
Save