diff options
author | katherine <shmibs@airen-no-jikken.icu> | 2019-05-12 16:07:11 -0700 |
---|---|---|
committer | katherine <shmibs@airen-no-jikken.icu> | 2019-05-12 16:07:11 -0700 |
commit | 682972020b2828867b4cffc80eb2dbe0e06ce93b (patch) | |
tree | 973a6bde4467d63ab20dd3cd083f69ff13055097 /src/main.c | |
parent | 95a9726023abd85b49ed39837911e1b231f4389b (diff) | |
download | confconf-682972020b2828867b4cffc80eb2dbe0e06ce93b.tar.gz |
implement internal parser
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 43 |
1 files changed, 11 insertions, 32 deletions
@@ -1,48 +1,27 @@ -#include "opt.h" #include "err.h" -#include "tok.h" - -#include <stdio.h> -#include <errno.h> - - - +#include "opt.h" +#include "parse.h" int main(int argc, char **argv) { FILE *fi = stdin; - struct tok_s t; + const char *finame = "stdin"; + struct parse_result_s pr; opt_parse(argc, argv); if (opt_infile_str() != NULL) { - fi = fopen(opt_infile_str(), "r"); - TRY(fi != NULL, "could not read file `%s`", opt_infile_str()); + finame = opt_infile_str(); + fi = fopen(finame, "r"); + TRY(fi != NULL, "could not read file `%s`", finame); } - while (1) { - t = tok_get(fi); - - if (t.type == TOK_UNKNWN || t.type == TOK_END) - break; - - printf("%s:%zu:%zu: ", (fi == stdin ? "stdin" : opt_infile_str()), - t.line, t.col); + pr = parse(fi, finame); - if (t.type > TOK_QMARK) { - printf("%u, `%s`\n", t.type, t.val); - } else { - printf("%u\n", t.type); - } - }; - - if (t.type == TOK_UNKNWN) { - printf("%s:%zu:%zu: error: unrecognised token `%s`\n", - (fi == stdin ? "stdin" : opt_infile_str()), - t.line, t.col, t.val); - } + if (fi != stdin) + fclose(fi); - fclose(fi); + parse_result_wipe(&pr); return 0; } |