diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2017-03-30 17:31:44 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2017-04-13 14:49:46 +0300 |
commit | 76b8c9e03c97b16d9ff97f3b79c0ecbff0f5e7f2 (patch) | |
tree | 70f1d22a923d1c01b22b2fade3b6e96365990dda /src/ragel/fspec.h |
Initial commit
Diffstat (limited to 'src/ragel/fspec.h')
-rw-r--r-- | src/ragel/fspec.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/ragel/fspec.h b/src/ragel/fspec.h new file mode 100644 index 0000000..68998f4 --- /dev/null +++ b/src/ragel/fspec.h @@ -0,0 +1,77 @@ +#pragma once + +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +struct fspec_bytes { + const uint8_t *data; + size_t size; +}; + +enum fspec_kind_bits { + FSPEC_KIND_IGNORE = 1<<0, + FSPEC_KIND_HEXADECIMAL = 1<<1, + FSPEC_KIND_ENCODING = 1<<2, +}; + +struct fspec_kind { + const char *name; + uint32_t flags; +}; + +enum fspec_array_type { + FSPEC_ARRAY_FIXED, + FSPEC_ARRAY_MATCH, + FSPEC_ARRAY_VAR, +}; + +struct fspec_array { + enum fspec_array_type type; + + union { + struct fspec_bytes match; + const char *var; + size_t nmemb; + }; +}; + +enum fspec_type_bits { + FSPEC_TYPE_SIGNED = 1<<0, + FSPEC_TYPE_CONTAINER = 1<<1, +}; + +struct fspec_type { + const char *name; + size_t size; + uint32_t flags; +}; + +struct fspec_field { + struct fspec_type type; + struct fspec_array array; + struct fspec_kind kind; + const char *name; +}; + +struct fspec_container { + const char *name; +}; + +struct fspec; +struct fspec { + struct { + void (*field)(struct fspec *fspec, const struct fspec_container *container, const struct fspec_field *field); + size_t (*read)(struct fspec *fspec, char *buf, const size_t size, const size_t nmemb); + } ops; + + struct { + // XXX: replace with ops.alloc, ops.free + // on dump.c we can then just provide implementation that still uses reasonable amount of static memory + // but we don't limit the code from working with regular dynamic memory + uint8_t *data; + size_t size; + } mem; +}; + +void fspec_parse(struct fspec *fspec); |