diff --git a/src/frontend/ftesopt.c b/src/frontend/ftesopt.c index fee3db61a..19bbd82ea 100644 --- a/src/frontend/ftesopt.c +++ b/src/frontend/ftesopt.c @@ -59,22 +59,19 @@ getFTEstat(struct FTEparm *p, FTESTATistics *stat, struct variable *next) v = TMALLOC(struct variable, 1); v->va_name = copy(p->description); v->va_next = next; - v->va_type = CP_NUM; - v->va_num = stat->FTESTATdeckNumLines; + 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->va_type = CP_REAL; - v->va_real = stat->FTESTATnetLoadTime; + 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->va_type = CP_REAL; - v->va_real = stat->FTESTATnetParseTime; + var_set_real(v, stat->FTESTATnetParseTime); return v; default: return NULL; diff --git a/src/frontend/options.c b/src/frontend/options.c index 70d7d6994..b91930849 100644 --- a/src/frontend/options.c +++ b/src/frontend/options.c @@ -55,8 +55,7 @@ cp_enqvar(char *word) vv = TMALLOC(struct variable, 1); vv->va_name = copy(word); vv->va_next = NULL; - vv->va_type = CP_REAL; - vv->va_real = value; + var_set_real(vv, value); } else { struct variable *list = NULL; int i; @@ -68,15 +67,13 @@ cp_enqvar(char *word) tv = TMALLOC(struct variable, 1); tv->va_name = NULL; tv->va_next = list; - tv->va_type = CP_REAL; - tv->va_real = value; + var_set_real(tv, value); list = tv; } vv = TMALLOC(struct variable, 1); vv->va_name = copy(word); vv->va_next = NULL; - vv->va_type = CP_LIST; - vv->va_vlist = list; + var_set_vlist(vv, list); } if (d->v_link2) @@ -94,26 +91,22 @@ cp_enqvar(char *word) vv = TMALLOC(struct variable, 1); vv->va_name = copy(word); vv->va_next = NULL; - vv->va_type = CP_STRING; - vv->va_string = copy(plot_cur->pl_name); + 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->va_type = CP_STRING; - vv->va_string = copy(plot_cur->pl_title); + 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->va_type = CP_STRING; - vv->va_string = copy(plot_cur->pl_date); + 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->va_type = CP_STRING; - vv->va_string = copy(plot_cur->pl_typename); + var_set_string(vv, copy(plot_cur->pl_typename)); } else if (eq(word, "plots")) { struct variable *list = NULL; struct plot *pl; @@ -122,15 +115,13 @@ cp_enqvar(char *word) tv = TMALLOC(struct variable, 1); tv->va_name = NULL; tv->va_next = list; - tv->va_type = CP_STRING; - tv->va_string = copy(pl->pl_typename); + 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->va_type = CP_LIST; - vv->va_vlist = list; + var_set_vlist(vv, list); } if (vv) return (vv); diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index 2e7cf837a..c48ac6481 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -967,30 +967,26 @@ parmtovar(IFvalue *pv, IFparm *opt) vv = TMALLOC(struct variable, 1); vv->va_name = copy(opt->description); vv->va_next = NULL; - vv->va_type = CP_NUM; - vv->va_num = pv->iValue; + 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->va_type = CP_REAL; - vv->va_real = pv->rValue; + 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->va_type = CP_STRING; - vv->va_string = pv->sValue; + 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->va_type = CP_BOOL; - vv->va_bool = pv->iValue ? TRUE : FALSE; + var_set_bool(vv, pv->iValue ? TRUE : FALSE); return vv; case IF_REALVEC: { struct variable *list = NULL; @@ -1000,15 +996,13 @@ parmtovar(IFvalue *pv, IFparm *opt) nv = TMALLOC(struct variable, 1); nv->va_name = NULL; nv->va_next = list; - nv->va_type = CP_REAL; - nv->va_real = pv->v.vec.rVec[i]; + 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->va_type = CP_LIST; - vv->va_vlist = list; + var_set_vlist(vv, list); return vv; /* It is a linked list where the first node is a variable * pointing to the different values of the variables. diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 95af485ba..7735b5027 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -121,29 +121,24 @@ cp_vset(char *varname, enum cp_types type, void *value) tfree(copyvarname); return; } else { - v->va_type = CP_BOOL; - v->va_bool = TRUE; + var_set_bool(v, TRUE); } break; case CP_NUM: - v->va_type = CP_NUM; - v->va_num = * (int *) value; + var_set_num(v, * (int *) value); break; case CP_REAL: - v->va_type = CP_REAL; - v->va_real = * (double *) value; + var_set_real(v, * (double *) value); break; case CP_STRING: - v->va_type = CP_STRING; - v->va_string = copy((char*) value); + var_set_string(v, copy((char*) value)); break; case CP_LIST: - v->va_type = CP_LIST; - v->va_vlist = (struct variable *) value; + var_set_vlist(v, (struct variable *) value); break; default: @@ -288,8 +283,7 @@ cp_setparse(wordlist *wl) vv = TMALLOC(struct variable, 1); vv->va_name = copy(name); vv->va_next = vars; - vv->va_type = CP_BOOL; - vv->va_bool = TRUE; + var_set_bool(vv, TRUE); vars = vv; tfree(name); /*DG: cp_unquote Memory leak*/ continue; @@ -355,11 +349,9 @@ cp_setparse(wordlist *wl) copyval = ss = cp_unquote(wl->wl_word); td = ft_numparse(&ss, FALSE); if (td) { - vv->va_type = CP_REAL; - vv->va_real = *td; + var_set_real(vv, *td); } else { - vv->va_type = CP_STRING; - vv->va_string = copy(ss); + var_set_string(vv, copy(ss)); } tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak*/ if (listv) { @@ -381,8 +373,7 @@ cp_setparse(wordlist *wl) vv = TMALLOC(struct variable, 1); vv->va_name = copy(name); vv->va_next = vars; - vv->va_type = CP_LIST; - vv->va_vlist = listv; + var_set_vlist(vv, listv); vars = vv; wl = wl->wl_next; @@ -397,11 +388,9 @@ cp_setparse(wordlist *wl) vars = vv; if (td) { /*** We should try to get CP_NUM's... */ - vv->va_type = CP_REAL; - vv->va_real = *td; + var_set_real(vv, *td); } else { - vv->va_type = CP_STRING; - vv->va_string = copy(val); + var_set_string(vv, copy(val)); } 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 */ @@ -468,8 +457,7 @@ cp_remvar(char *varname) v = TMALLOC(struct variable, 1); v->va_name = copy(varname); v->va_next = NULL; - v->va_type = CP_NUM; - v->va_num = 0; + var_set_num(v, 0); found = FALSE; }