aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2018-02-20 22:21:46 -0500
committerClyne Sullivan <tullivan99@gmail.com>2018-02-20 22:21:46 -0500
commitf414175e0cf08e02d65ca09028641ac2adbd0f8e (patch)
tree76637b32274f64975b4d225aea6573681b5dc9fe /variable.c
parent5d85baa270b046eedf472d4cb851fe17fb608fc5 (diff)
stdlib independence, fixes for calculator
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/variable.c b/variable.c
index 620a4b6..38b771b 100644
--- a/variable.c
+++ b/variable.c
@@ -1,12 +1,33 @@
#include "variable.h"
#include "parser.h"
-#include <stdio.h>
#include <stdlib.h>
+#include <memory.h>
+#include <string.h>
+
+extern int atoi(const char *);
extern char *str_undef;
extern char *str_func;
+char *fixstring(char *s)
+{
+ int len = strlen(s);
+ char *n = malloc(len + 1);
+ int i, j;
+ for (i = 0, j = 0; s[i] != '\0'; i++, j++) {
+ if (s[i] == '\\') {
+ if (s[i + 1] == 'n')
+ n[j] = '\n';
+ i++;
+ } else {
+ n[j] = s[i];
+ }
+ }
+ n[j] = '\0';
+ return n;
+}
+
variable *vmake(uint8_t fromc, uint8_t valtype, void *value)
{
variable *v = (variable *)malloc(sizeof(variable));
@@ -18,7 +39,8 @@ variable *vmake(uint8_t fromc, uint8_t valtype, void *value)
switch (valtype) {
case STRING:
v->value = 0;
- v->svalue = value;
+ v->svalue = fixstring(value);
+ free(value);
break;
case INTEGER:
INT(v) = (int32_t)value;