variables, variables, cp_getvar, rewrite
This commit is contained in:
parent
26acc887e8
commit
18423ba8de
|
|
@ -516,89 +516,76 @@ cp_getvar(char *name, enum cp_types type, void *retval)
|
||||||
fprintf(stderr, "in cp_getvar, trying to get value of variable %s.\n", name);
|
fprintf(stderr, "in cp_getvar, trying to get value of variable %s.\n", name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (v = variables; v && !eq(name, v->va_name); v = v->va_next)
|
for (v = variables; v; v = v->va_next)
|
||||||
;
|
if (eq(name, v->va_name))
|
||||||
if (v == NULL)
|
break;
|
||||||
for (v = uv1; v && !eq(name, v->va_name); v = v->va_next)
|
|
||||||
;
|
|
||||||
if (v == NULL && ft_curckt)
|
|
||||||
for (v = ft_curckt->ci_vars; v && !eq(name, v->va_name); v = v->va_next)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (v == NULL) {
|
if (!v)
|
||||||
|
for (v = uv1; v; v = v->va_next)
|
||||||
|
if (eq(name, v->va_name))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!v && ft_curckt)
|
||||||
|
for (v = ft_curckt->ci_vars; v; v = v->va_next)
|
||||||
|
if (eq(name, v->va_name))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!v) {
|
||||||
if (type == CP_BOOL && retval)
|
if (type == CP_BOOL && retval)
|
||||||
* (bool *) retval = FALSE;
|
*(bool *) retval = FALSE;
|
||||||
free_struct_variable(uv1);
|
free_struct_variable(uv1);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->va_type == type) {
|
if (v->va_type == type) {
|
||||||
if (retval)
|
|
||||||
switch (type) {
|
if (retval)
|
||||||
case CP_BOOL:
|
switch (type) {
|
||||||
* (bool *) retval = TRUE;
|
case CP_BOOL:
|
||||||
break;
|
*(bool *) retval = TRUE;
|
||||||
case CP_NUM: {
|
break;
|
||||||
int *i;
|
case CP_NUM:
|
||||||
i = (int *) retval;
|
*(int *) retval = v->va_num;
|
||||||
*i = v->va_num;
|
break;
|
||||||
break;
|
case CP_REAL:
|
||||||
}
|
*(double *) retval = v->va_real;
|
||||||
case CP_REAL: {
|
break;
|
||||||
double *d;
|
case CP_STRING: { /* Gotta be careful to have room. */
|
||||||
d = (double *) retval;
|
char *s = cp_unquote(v->va_string);
|
||||||
*d = v->va_real;
|
cp_wstrip(s);
|
||||||
break;
|
strcpy((char*) retval, s);
|
||||||
}
|
tfree(s);
|
||||||
case CP_STRING: { /* Gotta be careful to have room. */
|
break;
|
||||||
char *s;
|
}
|
||||||
s = cp_unquote(v->va_string);
|
case CP_LIST: /* Funny case... */
|
||||||
cp_wstrip(s);
|
*(struct variable **) retval = v->va_vlist;
|
||||||
(void) strcpy((char*) retval, s);
|
break;
|
||||||
tfree(s);/*DG*/
|
default:
|
||||||
break;
|
fprintf(cp_err,
|
||||||
}
|
"cp_getvar: Internal Error: bad var type %d.\n", type);
|
||||||
case CP_LIST: { /* Funny case... */
|
break;
|
||||||
struct variable **tv;
|
}
|
||||||
tv = (struct variable **) retval;
|
|
||||||
*tv = v->va_vlist;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fprintf(cp_err,
|
|
||||||
"cp_getvar: Internal Error: bad var type %d.\n", type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free_struct_variable(uv1);
|
free_struct_variable(uv1);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try to coerce it.. */
|
||||||
|
if ((type == CP_NUM) && (v->va_type == CP_REAL)) {
|
||||||
|
*(int *) retval = (int) v->va_real;
|
||||||
|
} else if ((type == CP_REAL) && (v->va_type == CP_NUM)) {
|
||||||
|
*(double *) retval = (double) v->va_num;
|
||||||
|
} else if ((type == CP_STRING) && (v->va_type == CP_NUM)) {
|
||||||
|
sprintf((char*) retval, "%d", v->va_num);
|
||||||
|
} else if ((type == CP_STRING) && (v->va_type == CP_REAL)) {
|
||||||
|
sprintf((char*) retval, "%f", v->va_real);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Try to coerce it.. */
|
|
||||||
if ((type == CP_NUM) && (v->va_type == CP_REAL)) {
|
|
||||||
int *i;
|
|
||||||
i = (int *) retval;
|
|
||||||
*i = (int) v->va_real;
|
|
||||||
free_struct_variable(uv1);
|
|
||||||
return (TRUE);
|
|
||||||
} else if ((type == CP_REAL) && (v->va_type == CP_NUM)) {
|
|
||||||
double *d;
|
|
||||||
d = (double *) retval;
|
|
||||||
*d = (double) v->va_num;
|
|
||||||
free_struct_variable(uv1);
|
|
||||||
return (TRUE);
|
|
||||||
} else if ((type == CP_STRING) && (v->va_type == CP_NUM)) {
|
|
||||||
(void) sprintf((char*) retval, "%d", v->va_num);
|
|
||||||
free_struct_variable(uv1);
|
|
||||||
return (TRUE);
|
|
||||||
} else if ((type == CP_STRING) && (v->va_type == CP_REAL)) {
|
|
||||||
(void) sprintf((char*) retval, "%f", v->va_real);
|
|
||||||
free_struct_variable(uv1);
|
|
||||||
return (TRUE);
|
|
||||||
}
|
|
||||||
free_struct_variable(uv1);
|
free_struct_variable(uv1);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free_struct_variable(uv1);
|
||||||
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue