diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2018-03-25 21:06:56 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2018-03-25 21:06:56 -0400 |
commit | ee4cfcdd2fb55d3e270c8ff4b7d7f89861254f81 (patch) | |
tree | 0adcc8f6a4d0c6b08f68f977ade8d64cf30a14f3 /shell.c.bak | |
parent | b2849b734f1feeb7ada96b7cdae11d6bf168ed08 (diff) |
Added shell and licensing
Diffstat (limited to 'shell.c.bak')
-rw-r--r-- | shell.c.bak | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/shell.c.bak b/shell.c.bak new file mode 100644 index 0000000..a2a2100 --- /dev/null +++ b/shell.c.bak @@ -0,0 +1,72 @@ +/** + * @file shell.c + * File loader to test scripts in host environment + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <string.h> + +#include "parser.h" + +int print(instance *it) +{ + variable *s = igetarg(it, 0); + if (s->type == NUMBER) { + if (s->value.f == (int)s->value.f) + printf("%d\n", (int)s->value.f); + else + printf("%.3f\n", s->value.f); + } else if (s->value.p != 0) { + printf("%s\n", (char *)s->value.p); + } + return 0; +} + +int main(int argc, char **argv) +{ + if (argc != 2) { + printf("Usage: %s file\n", argv[0]); + return -1; + } + + FILE *fp = fopen(argv[1], "r"); + if (fp == 0) { + printf("Could not open file: %s\n", argv[1]); + return -1; + } + + instance *it = inewinstance(); + inew_cfunc(it, "print", print); + + char *line = 0; + size_t size; + int result; + while (getline(&line, &size, fp) != -1) { + *strchr(line, '\n') = '\0'; + result = idoline(it, line); + if (result != 0) + printf("Error: %d\n", result); + //if (it->ret != 0) + // printf("%s = %f\n", line, it->ret->value.f); + } + + fclose(fp); + idelinstance(it); + return 0; +} + |