From 6b5838f72fe535afb542e888d7d2d2da3571bea2 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 24 Feb 2024 17:47:39 +0200 Subject: initial commit + Now to do the actual hard parts, heh --- src/main.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a0eeb42 --- /dev/null +++ b/src/main.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +#include +#include + +static char *read_file(const char *file, FILE *f) +{ + fseek(f, 0, SEEK_END); + /** @todo check how well standardized this actually is */ + long s = ftell(f); + if (s == LONG_MAX) { + error("%s might be a directory", file); + return NULL; + } + + fseek(f, 0, SEEK_SET); + + char *buf = malloc(s + 1); + if (!buf) + return NULL; + + fread(buf, s + 1, 1, f); + /* remember terminating null */ + buf[s] = 0; + return buf; +} + +static void usage(FILE *f) +{ + fprintf(f, "qbt .qbt\n"); +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + usage(stdout); + return -1; + } + + char *fname = argv[1]; + FILE *f = fopen(fname, "rb"); + if (!f) { + fprintf(stderr, "couldn't open %s\n", fname); + return -1; + } + + char *buf = read_file(fname, f); + fclose(f); + + struct parser *p = create_parser(); + parse(p, fname, buf); + + foreach_fn(i, p->fns) { + struct fn_map m = fn_at(p->fns, i); + dump_function(m.fn); + } + + destroy_parser(p); + free(buf); +} -- cgit v1.3