diff options
-rw-r--r-- | main.c | 5 | ||||
-rw-r--r-- | sloth.c | 18 | ||||
-rw-r--r-- | sloth.h | 2 |
3 files changed, 22 insertions, 3 deletions
@@ -14,13 +14,12 @@ int main(int argc, char **argv) /* Read stdin line by line until exhaustion. */ char *line = NULL; while ((line = getln(stdin)) != NULL) { - err = sloth_push(sloth, line[0]); + err = sloth_exec_line(sloth, line); + free(line); if (err != NULL) { fprintf(stderr, "%s\n", err); break; } - sloth_inspect_stack(sloth); - free(line); } /* Free everything. */ getln_cleanup(); @@ -1,6 +1,7 @@ #include "sloth.h" #include <stdio.h> #include <stdlib.h> +#include <string.h> void sloth_deinit(Sloth *ctx) { @@ -10,6 +11,23 @@ void sloth_deinit(Sloth *ctx) } } +SlothError sloth_exec(Sloth *ctx, const char *s) +{ + printf("exec %s\n", s); + return NULL; +} + +SlothError sloth_exec_line(Sloth *ctx, char *s) +{ + static const char *sep = "\t\n\v\f\r "; + for (char *tok = strtok(s, sep); tok != NULL; tok = strtok(NULL, sep)) { + const SlothError err = sloth_exec(ctx, tok); + if (err != NULL) + return err; + } + return NULL; +} + SlothError sloth_pop(Sloth *ctx, SlothByte *v) { if (ctx->stack_size == 0) @@ -15,6 +15,8 @@ typedef struct Sloth { } Sloth; void sloth_deinit(Sloth *ctx); +SlothError sloth_exec(Sloth *ctx, const char *s); +SlothError sloth_exec_line(Sloth *ctx, char *s); SlothError sloth_pop(Sloth *ctx, SlothByte *v); SlothError sloth_push(Sloth *ctx, SlothByte v); void sloth_inspect_stack(const Sloth *ctx); |