aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorkatherine <shmibs@airen-no-jikken.icu>2019-05-08 23:33:41 -0700
committerkatherine <shmibs@airen-no-jikken.icu>2019-05-08 23:33:41 -0700
commit95a9726023abd85b49ed39837911e1b231f4389b (patch)
tree3535a3ca1feac910ecf736fdc07ddcb5559f4321 /src/main.c
parentca0d95e26663e05d702c6f3a5627812dbf0c9f90 (diff)
downloadconfconf-95a9726023abd85b49ed39837911e1b231f4389b.tar.gz
implement internal tokeniser
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index cd5eb3a..ed9c413 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,16 +1,48 @@
#include "opt.h"
+#include "err.h"
+#include "tok.h"
#include <stdio.h>
+#include <errno.h>
+
+
+
int main(int argc, char **argv)
{
+ FILE *fi = stdin;
+ struct tok_s t;
+
opt_parse(argc, argv);
- if (opt_infile_str())
- puts(opt_infile_str());
+ if (opt_infile_str() != NULL) {
+ fi = fopen(opt_infile_str(), "r");
+ TRY(fi != NULL, "could not read file `%s`", opt_infile_str());
+ }
+
+ 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);
+
+ 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);
+ }
+
+ fclose(fi);
- if (opt_outfile_str())
- puts(opt_outfile_str());
-
return 0;
}