diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-14 19:22:48 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-14 19:22:48 +0100 |
commit | 13802c4d560e8e6de4a06fb8f7e707e41436dffe (patch) | |
tree | dd6af82efeece61b01725609c742788be5052611 | |
parent | eaca074e5fee695fcf08a9b21687e3f01df107ae (diff) | |
download | sloth-13802c4d560e8e6de4a06fb8f7e707e41436dffe.tar.gz |
sloth_exec_line
-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); |