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

This commit is contained in:
rlar 2016-03-25 15:39:27 +01:00
parent 8691368a81
commit eb53b4d703
4 changed files with 24 additions and 72 deletions

View File

@ -56,21 +56,15 @@ getFTEstat(struct FTEparm *p, FTESTATistics *stat, struct variable *next)
switch (p->id) {
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);
return v;
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);
return v;
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);
return v;
default:

View File

@ -52,9 +52,7 @@ cp_enqvar(char *word)
double value = isreal(d)
? d->v_realdata[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);
} else {
struct variable *list = NULL;
@ -64,15 +62,11 @@ cp_enqvar(char *word)
? d->v_realdata[i]
: realpart(d->v_compdata[i]);
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);
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);
}
@ -88,39 +82,27 @@ cp_enqvar(char *word)
if (eq(vv->va_name, word))
return (vv);
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));
} 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));
} 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));
} 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));
} else if (eq(word, "plots")) {
struct variable *list = NULL;
struct plot *pl;
for (pl = plot_list; pl; pl = pl->pl_next) {
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));
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);
}
if (vv)

View File

@ -964,28 +964,20 @@ parmtovar(IFvalue *pv, IFparm *opt)
switch (opt->dataType & IF_VARTYPES) {
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);
return vv;
case IF_REAL:
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);
return vv;
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);
return vv;
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);
return vv;
case IF_REALVEC: {
@ -993,15 +985,11 @@ parmtovar(IFvalue *pv, IFparm *opt)
int i;
for (i = pv->v.numValue; --i >= 0;) {
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]);
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);
return vv;
/* It is a linked list where the first node is a variable

View File

@ -104,9 +104,7 @@ cp_vset(char *varname, enum cp_types type, void *value)
}
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;
}
@ -280,9 +278,7 @@ cp_setparse(wordlist *wl)
wl = wl->wl_next;
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);
vars = vv;
tfree(name); /*DG: cp_unquote Memory leak*/
@ -343,9 +339,7 @@ cp_setparse(wordlist *wl)
if (!--balance)
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);
td = ft_numparse(&ss, FALSE);
if (td) {
@ -370,9 +364,7 @@ cp_setparse(wordlist *wl)
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);
vars = vv;
@ -382,9 +374,7 @@ cp_setparse(wordlist *wl)
copyval = ss = cp_unquote(val);
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;
if (td) {
/*** We should try to get CP_NUM's... */
@ -454,9 +444,7 @@ cp_remvar(char *varname)
}
if (!v) {
/* 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);
found = FALSE;
}