From de05c7f7d895d9903e69db8a0a9f7731f256b6a1 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Tue, 15 Aug 2017 22:44:24 +0300 Subject: tmp --- src/bin/fspec/dump.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/bin') diff --git a/src/bin/fspec/dump.c b/src/bin/fspec/dump.c index 07a6757..8ca53b2 100644 --- a/src/bin/fspec/dump.c +++ b/src/bin/fspec/dump.c @@ -14,6 +14,7 @@ #include #include #include +#include "fspec/ragel/lexer-expr.h" #include "util/membuf.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -756,6 +757,29 @@ fopen_or_die(const char *path, const char *mode) #define container_of(ptr, type, member) ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member))) +struct expr { + struct fspec_expr expr; + struct membuf output; + FILE *file; +}; + +static size_t +fspec_expr_write(struct fspec_expr *expr, const void *output, const size_t size, const size_t nmemb) +{ + assert(expr && output); + // struct expr *l = container_of(expr, struct expr, expr); + (void)expr, (void)size, (void)nmemb; + return nmemb; +} + +static size_t +fspec_expr_read(struct fspec_expr *expr, void *input, const size_t size, const size_t nmemb) +{ + assert(expr && input); + struct expr *l = container_of(expr, struct expr, expr); + return fread(input, size, nmemb, l->file); +} + struct lexer { struct fspec_lexer lexer; struct membuf output; @@ -801,6 +825,25 @@ main(int argc, const char *argv[]) char output[4096]; + { + char input[4096]; + struct expr l = { + .expr = { + .ops.read = fspec_expr_read, + .ops.write = fspec_expr_write, + .mem.input = { .data = input, .len = sizeof(input) }, + }, + .file = fopen_or_die(argv[1], "rb"), + .output.mem = { .data = output, .len = sizeof(output) }, + }; + + if (!fspec_expr_parse(&l.expr, argv[1])) + exit(EXIT_FAILURE); + + fclose(l.file); + // bcode = l.expr.mem.output; + } + { char input[4096]; struct lexer l = { -- cgit v1.2.3