variables, use a pointer to the anchor of the variable instead of 'lv'
This commit is contained in:
parent
b13125ac84
commit
d14ee053d7
|
|
@ -403,35 +403,33 @@ free_struct_variable(struct variable *v)
|
||||||
void
|
void
|
||||||
cp_remvar(char *varname)
|
cp_remvar(char *varname)
|
||||||
{
|
{
|
||||||
struct variable *v, *u, *lv = NULL;
|
struct variable *v, *u, **p;
|
||||||
struct variable *uv1;
|
struct variable *uv1;
|
||||||
bool found = TRUE;
|
bool found = TRUE;
|
||||||
int i, var_index;
|
int i;
|
||||||
|
|
||||||
uv1 = cp_usrvars();
|
uv1 = cp_usrvars();
|
||||||
|
|
||||||
var_index = 0;
|
p = &variables;
|
||||||
for (v = variables; v; v = v->va_next) {
|
for (v = variables; v; v = v->va_next) {
|
||||||
if (eq(v->va_name, varname))
|
if (eq(v->va_name, varname))
|
||||||
break;
|
break;
|
||||||
lv = v;
|
p = &v->va_next;
|
||||||
}
|
}
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
var_index = 1;
|
p = &uv1;
|
||||||
lv = NULL;
|
|
||||||
for (v = uv1; v; v = v->va_next) {
|
for (v = uv1; v; v = v->va_next) {
|
||||||
if (eq(v->va_name, varname))
|
if (eq(v->va_name, varname))
|
||||||
break;
|
break;
|
||||||
lv = v;
|
p = &v->va_next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (v == NULL && ft_curckt) {
|
if (v == NULL && ft_curckt) {
|
||||||
var_index = 2;
|
p = &ft_curckt->ci_vars;
|
||||||
lv = NULL;
|
|
||||||
for (v = ft_curckt->ci_vars; v; v = v->va_next) {
|
for (v = ft_curckt->ci_vars; v; v = v->va_next) {
|
||||||
if (eq(v->va_name, varname))
|
if (eq(v->va_name, varname))
|
||||||
break;
|
break;
|
||||||
lv = v;
|
p = &v->va_next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!v) {
|
if (!v) {
|
||||||
|
|
@ -464,17 +462,7 @@ cp_remvar(char *varname)
|
||||||
case US_OK:
|
case US_OK:
|
||||||
/* Normal case. */
|
/* Normal case. */
|
||||||
if (found) {
|
if (found) {
|
||||||
if (lv)
|
*p = v->va_next;
|
||||||
lv->va_next = v->va_next;
|
|
||||||
else
|
|
||||||
if (var_index == 0) {
|
|
||||||
variables = v->va_next;
|
|
||||||
} else if (var_index == 1) {
|
|
||||||
uv1 = v->va_next;
|
|
||||||
} else {
|
|
||||||
ft_curckt->ci_vars = v->va_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -496,18 +484,15 @@ cp_remvar(char *varname)
|
||||||
case US_SIMVAR:
|
case US_SIMVAR:
|
||||||
/* variables processed by if_option(ft_curckt->ci_ckt, ...) */
|
/* variables processed by if_option(ft_curckt->ci_ckt, ...) */
|
||||||
fprintf(stderr, "it's a US_SIMVAR!\n");
|
fprintf(stderr, "it's a US_SIMVAR!\n");
|
||||||
lv = NULL;
|
|
||||||
if (ft_curckt) {
|
if (ft_curckt) {
|
||||||
|
p = &ft_curckt->ci_vars;
|
||||||
for (u = ft_curckt->ci_vars; u; u = u->va_next) {
|
for (u = ft_curckt->ci_vars; u; u = u->va_next) {
|
||||||
if (eq(varname, u->va_name))
|
if (eq(varname, u->va_name))
|
||||||
break;
|
break;
|
||||||
lv = u;
|
p = &u->va_next;
|
||||||
}
|
}
|
||||||
if (u) {
|
if (u) {
|
||||||
if (lv)
|
*p = u->va_next;
|
||||||
lv->va_next = u->va_next;
|
|
||||||
else
|
|
||||||
ft_curckt->ci_vars = u->va_next;
|
|
||||||
tfree(u);
|
tfree(u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue