commit 629bda065a04c74c07a451d05a20c04618d518aa parent 802b0f6c341c7a627a079b34a5c4c5785fa19c88 Author: William Casarin <jb55@jb55.com> Date: Fri, 22 Dec 2017 13:07:43 -0800 cli: accept extra arguments as tokens Closes #29 Diffstat:
M | main.c | | | 16 | ++++++++++++---- |
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/main.c b/main.c @@ -22,7 +22,7 @@ parse_error(char* err) { exit(1); } -int main() { +int main(int argc, const char *argv[]) { yyin = stdin; struct result result; @@ -36,9 +36,17 @@ int main() { stack_init(&tmp_stack); stack_init(&g_reader_stack); - do { - yyparse(); - } while(!feof(yyin)); + if (argc > 1) { + for (int i = 1; i < argc; ++i) { + yy_scan_string(argv[i]); + yyparse(); + } + } + else { + do { + yyparse(); + } while(!feof(yyin)); + } /* size = g_reader_buf_top - g_reader_buf; */ printf("script ");