Use an input file

This commit is contained in:
Dane Johnson 2021-12-21 09:58:33 -06:00
parent 9d4e426b4f
commit 28ac6d8331

View File

@ -5,6 +5,13 @@
#include <cstdlib>
#include <cassert>
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<Page*> 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;
}