aboutsummaryrefslogtreecommitdiffstats
path: root/shell.c.bak
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2018-04-02 12:29:05 -0400
committerClyne Sullivan <clyne@bitgloo.com>2018-04-02 12:29:05 -0400
commit31458dd042da2a3ce732546cd94318457b4f5bcf (patch)
tree5e6cf8a524b84bd414f0d2760b9ee8bedc92cdec /shell.c.bak
parent8a25cb84e7c51749dd6d43d58e4952ef311eed45 (diff)
change load/run style, hunt for memory leaks
Diffstat (limited to 'shell.c.bak')
-rw-r--r--shell.c.bak22
1 files changed, 18 insertions, 4 deletions
diff --git a/shell.c.bak b/shell.c.bak
index a2a2100..8658197 100644
--- a/shell.c.bak
+++ b/shell.c.bak
@@ -19,6 +19,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "parser.h"
@@ -37,6 +38,18 @@ int print(instance *it)
return 0;
}
+int gets(instance *it)
+{
+ char *line = 0;
+ size_t size;
+ getline(&line, &size, stdin);
+ *strchr(line, '\n') = '\0';
+ variable *v = make_vars(0, line);
+ free(line);
+ ipush(it, (uint32_t)v);
+ return 0;
+}
+
int main(int argc, char **argv)
{
if (argc != 2) {
@@ -52,20 +65,21 @@ int main(int argc, char **argv)
instance *it = inewinstance();
inew_cfunc(it, "print", print);
+ inew_cfunc(it, "gets", gets);
char *line = 0;
size_t size;
int result;
while (getline(&line, &size, fp) != -1) {
*strchr(line, '\n') = '\0';
- result = idoline(it, line);
+ result = iaddline(it, line);
if (result != 0)
printf("Error: %d\n", result);
- //if (it->ret != 0)
- // printf("%s = %f\n", line, it->ret->value.f);
}
-
+ free(line);
fclose(fp);
+
+ irun(it);
idelinstance(it);
return 0;
}