diff --git a/cyoa.leg b/cyoa.leg index 2d94070..8dafaec 100644 --- a/cyoa.leg +++ b/cyoa.leg @@ -5,6 +5,13 @@ #include #include +FILE* yyin = stdin; + +#define YY_INPUT(buf, result, max_size) { \ + int yyc = getc(yyin); \ + result = (EOF == yyc) ? 0 : (*(buf) = yyc, 1); \ + } + #define STATCHECK_GT 1 #define STATCHECK_LT 2 @@ -217,14 +224,21 @@ void print_page(Page *page) { } } -int main() { - if (!yyparse()) { - printf("Parsing Error!\n"); +std::vector CyoaParse(FILE *file) { + yyin = file; + yyparse(); + yyin = stdin; + return pages; +} + +int main(int argc, char **argv) { + if (argc < 2) { return 1; - } else { - for (Page* page : pages) { - print_page(page); - } + } + FILE* fin = fopen(argv[1], "r"); + auto mypages = CyoaParse(fin); + for (Page* page : pages) { + print_page(page); } return 0; }