Browse Source

struct variable, #10/18, rewrite in terms of `var_set_xxx()' (do-1)

pre-master-46
rlar 10 years ago
parent
commit
68042b3d1b
  1. 9
      src/frontend/ftesopt.c
  2. 27
      src/frontend/options.c
  3. 18
      src/frontend/spiceif.c
  4. 36
      src/frontend/variable.c

9
src/frontend/ftesopt.c

@ -59,22 +59,19 @@ getFTEstat(struct FTEparm *p, FTESTATistics *stat, struct variable *next)
v = TMALLOC(struct variable, 1); v = TMALLOC(struct variable, 1);
v->va_name = copy(p->description); v->va_name = copy(p->description);
v->va_next = next; v->va_next = next;
v->va_type = CP_NUM;
v->va_num = stat->FTESTATdeckNumLines;
var_set_num(v, stat->FTESTATdeckNumLines);
return v; return v;
case FTEOPT_NLT: case FTEOPT_NLT:
v = TMALLOC(struct variable, 1); v = TMALLOC(struct variable, 1);
v->va_name = copy(p->description); v->va_name = copy(p->description);
v->va_next = next; v->va_next = next;
v->va_type = CP_REAL;
v->va_real = stat->FTESTATnetLoadTime;
var_set_real(v, stat->FTESTATnetLoadTime);
return v; return v;
case FTEOPT_NPT: case FTEOPT_NPT:
v = TMALLOC(struct variable, 1); v = TMALLOC(struct variable, 1);
v->va_name = copy(p->description); v->va_name = copy(p->description);
v->va_next = next; v->va_next = next;
v->va_type = CP_REAL;
v->va_real = stat->FTESTATnetParseTime;
var_set_real(v, stat->FTESTATnetParseTime);
return v; return v;
default: default:
return NULL; return NULL;

27
src/frontend/options.c

@ -55,8 +55,7 @@ cp_enqvar(char *word)
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_REAL;
vv->va_real = value;
var_set_real(vv, value);
} else { } else {
struct variable *list = NULL; struct variable *list = NULL;
int i; int i;
@ -68,15 +67,13 @@ cp_enqvar(char *word)
tv = TMALLOC(struct variable, 1); tv = TMALLOC(struct variable, 1);
tv->va_name = NULL; tv->va_name = NULL;
tv->va_next = list; tv->va_next = list;
tv->va_type = CP_REAL;
tv->va_real = value;
var_set_real(tv, value);
list = tv; list = tv;
} }
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_LIST;
vv->va_vlist = list;
var_set_vlist(vv, list);
} }
if (d->v_link2) if (d->v_link2)
@ -94,26 +91,22 @@ cp_enqvar(char *word)
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; 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")) { } else if (eq(word, "curplottitle")) {
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; 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")) { } else if (eq(word, "curplotdate")) {
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; 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")) { } else if (eq(word, "curplot")) {
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; 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")) { } else if (eq(word, "plots")) {
struct variable *list = NULL; struct variable *list = NULL;
struct plot *pl; struct plot *pl;
@ -122,15 +115,13 @@ cp_enqvar(char *word)
tv = TMALLOC(struct variable, 1); tv = TMALLOC(struct variable, 1);
tv->va_name = NULL; tv->va_name = NULL;
tv->va_next = list; 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; list = tv;
} }
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(word); vv->va_name = copy(word);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_LIST;
vv->va_vlist = list;
var_set_vlist(vv, list);
} }
if (vv) if (vv)
return (vv); return (vv);

18
src/frontend/spiceif.c

@ -967,30 +967,26 @@ parmtovar(IFvalue *pv, IFparm *opt)
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description); vv->va_name = copy(opt->description);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_NUM;
vv->va_num = 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 = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description); vv->va_name = copy(opt->description);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_REAL;
vv->va_real = pv->rValue;
var_set_real(vv, pv->rValue);
return vv; return vv;
case IF_STRING: case IF_STRING:
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description); vv->va_name = copy(opt->description);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_STRING;
vv->va_string = pv->sValue;
var_set_string(vv, pv->sValue);
return vv; return vv;
case IF_FLAG: case IF_FLAG:
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description); vv->va_name = copy(opt->description);
vv->va_next = NULL; 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; return vv;
case IF_REALVEC: { case IF_REALVEC: {
struct variable *list = NULL; struct variable *list = NULL;
@ -1000,15 +996,13 @@ parmtovar(IFvalue *pv, IFparm *opt)
nv = TMALLOC(struct variable, 1); nv = TMALLOC(struct variable, 1);
nv->va_name = NULL; nv->va_name = NULL;
nv->va_next = list; 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; list = nv;
} }
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(opt->description); vv->va_name = copy(opt->description);
vv->va_next = NULL; vv->va_next = NULL;
vv->va_type = CP_LIST;
vv->va_vlist = 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
* pointing to the different values of the variables. * pointing to the different values of the variables.

36
src/frontend/variable.c

@ -121,29 +121,24 @@ cp_vset(char *varname, enum cp_types type, void *value)
tfree(copyvarname); tfree(copyvarname);
return; return;
} else { } else {
v->va_type = CP_BOOL;
v->va_bool = TRUE;
var_set_bool(v, TRUE);
} }
break; break;
case CP_NUM: case CP_NUM:
v->va_type = CP_NUM;
v->va_num = * (int *) value;
var_set_num(v, * (int *) value);
break; break;
case CP_REAL: case CP_REAL:
v->va_type = CP_REAL;
v->va_real = * (double *) value;
var_set_real(v, * (double *) value);
break; break;
case CP_STRING: case CP_STRING:
v->va_type = CP_STRING;
v->va_string = copy((char*) value);
var_set_string(v, copy((char*) value));
break; break;
case CP_LIST: case CP_LIST:
v->va_type = CP_LIST;
v->va_vlist = (struct variable *) value;
var_set_vlist(v, (struct variable *) value);
break; break;
default: default:
@ -288,8 +283,7 @@ cp_setparse(wordlist *wl)
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(name); vv->va_name = copy(name);
vv->va_next = vars; vv->va_next = vars;
vv->va_type = CP_BOOL;
vv->va_bool = TRUE;
var_set_bool(vv, TRUE);
vars = vv; vars = vv;
tfree(name); /*DG: cp_unquote Memory leak*/ tfree(name); /*DG: cp_unquote Memory leak*/
continue; continue;
@ -355,11 +349,9 @@ cp_setparse(wordlist *wl)
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) {
vv->va_type = CP_REAL;
vv->va_real = *td;
var_set_real(vv, *td);
} else { } 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*/ tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak*/
if (listv) { if (listv) {
@ -381,8 +373,7 @@ cp_setparse(wordlist *wl)
vv = TMALLOC(struct variable, 1); vv = TMALLOC(struct variable, 1);
vv->va_name = copy(name); vv->va_name = copy(name);
vv->va_next = vars; vv->va_next = vars;
vv->va_type = CP_LIST;
vv->va_vlist = listv;
var_set_vlist(vv, listv);
vars = vv; vars = vv;
wl = wl->wl_next; wl = wl->wl_next;
@ -397,11 +388,9 @@ cp_setparse(wordlist *wl)
vars = vv; vars = vv;
if (td) { if (td) {
/*** We should try to get CP_NUM's... */ /*** We should try to get CP_NUM's... */
vv->va_type = CP_REAL;
vv->va_real = *td;
var_set_real(vv, *td);
} else { } 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(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 */
@ -468,8 +457,7 @@ cp_remvar(char *varname)
v = TMALLOC(struct variable, 1); v = TMALLOC(struct variable, 1);
v->va_name = copy(varname); v->va_name = copy(varname);
v->va_next = NULL; v->va_next = NULL;
v->va_type = CP_NUM;
v->va_num = 0;
var_set_num(v, 0);
found = FALSE; found = FALSE;
} }

Loading…
Cancel
Save