From 5d85baa270b046eedf472d4cb851fe17fb608fc5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 12 Feb 2018 11:23:17 -0500 Subject: indent fixes, nested conditionals --- variable.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 727ca0c..620a4b6 100644 --- a/variable.c +++ b/variable.c @@ -5,6 +5,47 @@ #include extern char *str_undef; +extern char *str_func; + +variable *vmake(uint8_t fromc, uint8_t valtype, void *value) +{ + variable *v = (variable *)malloc(sizeof(variable)); + v->used = 0; + v->fromc = fromc; + v->valtype = valtype; + v->value = 0; + v->svalue = 0; + switch (valtype) { + case STRING: + v->value = 0; + v->svalue = value; + break; + case INTEGER: + INT(v) = (int32_t)value; + isetstr(v); + break; + case FUNC: + v->value = (uint32_t)value; + v->svalue = str_func; + break; + case EXPR: + v->value = 0; + v->svalue = value; + break; + } + return v; +} + +variable *vmakef(float value) +{ + variable *v = (variable *)malloc(sizeof(variable)); + v->used = 0; + v->fromc = 0; + v->valtype = FLOAT; + FLOAT(v) = value; + fsetstr(v); + return v; +} void fsetstr(variable *f) { @@ -17,7 +58,7 @@ void isetstr(variable *i) { if (i->svalue == 0 || i->svalue == str_undef) i->svalue = (char *)malloc(12); - snprintf(i->svalue, 12, "%d", INT(i)); + snprintf(i->svalue, 12, "%d", (int)INT(i)); } variable *itostring(variable *v) -- cgit v1.2.3