From 85456307365f470378df2f5e7fc3a355bc3d4ace Mon Sep 17 00:00:00 2001 From: katherine Date: Thu, 30 May 2019 07:34:25 -0700 Subject: add configurable uthash header location --- src/tok.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 5 deletions(-) (limited to 'src/tok.c') diff --git a/src/tok.c b/src/tok.c index c80d397..bae9285 100644 --- a/src/tok.c +++ b/src/tok.c @@ -1,5 +1,6 @@ #include "tok.h" +#include #include #include @@ -68,12 +69,13 @@ static void sub_match_op(void) struct { bool possible; enum tok_type_e type; - char name[(32 < TOK_MAX_LEN ? 32 : TOK_MAX_LEN)]; + char name[32]; } ops[] = { - { true, TOK_OP_SUFFIX, ".suffix" }, { true, TOK_OP_STRUCT, ".struct" }, { true, TOK_OP_UNION, ".union" }, { true, TOK_OP_ENUM, ".enum" }, + { true, TOK_OP_NAMING_SUFFIX, ".naming-suffix" }, + { true, TOK_OP_UTHASH_LOCATION, ".uthash-location" }, }; unsigned i, j; bool again; @@ -96,7 +98,7 @@ static void sub_match_op(void) val[vlen] = c; vlen++; - for (j = 0; j < 4; j++) { + for (j = 0; j < 5; j++) { if (!ops[j].possible) continue; @@ -121,6 +123,14 @@ static void sub_match_op(void) vlen++; c = getc(curf); } while (c != EOF && !isspace(c) && vlen < TOK_MAX_LEN - 1); + + if (vlen + 2 == TOK_MAX_LEN) { + vlen = 0; + val[0] = '\0'; + curtok.type = TOK_LONG; + return; + } + ungetc(c, curf); val[vlen] = '\0'; curtok.type = TOK_UNKNWN; @@ -136,6 +146,7 @@ static void sub_match_uint(void) curtok.type = TOK_UINT; while (true) { + c = getc(curf); if (!isdigit(c)) { @@ -144,6 +155,13 @@ static void sub_match_uint(void) return; } + if (vlen + 2 == TOK_MAX_LEN) { + vlen = 0; + val[0] = '\0'; + curtok.type = TOK_LONG; + return; + } + val[vlen] = c; vlen++; } @@ -164,11 +182,58 @@ static void sub_match_id(void) return; } + if (vlen + 2 == TOK_MAX_LEN) { + vlen = 0; + val[0] = '\0'; + curtok.type = TOK_LONG; + return; + } + val[vlen] = c; vlen++; } } +static void sub_match_header(void) +{ + int c, cend; + + curtok.type = TOK_END; + + cend = (val[0] == '"' ? '"' : '>'); + + while (true) { + c = getc(curf); + + if (c == EOF) + return; + + if (c == '\n') { + val[vlen] = '\0'; + curtok.type = TOK_UNKNWN; + return; + } + + if (vlen + 2 == TOK_MAX_LEN) { + vlen = 0; + val[0] = '\0'; + curtok.type = TOK_LONG; + return; + } + + val[vlen] = c; + vlen++; + + if (c == cend) + break; + } + + curtok.type = TOK_HEADER; + + val[vlen] = '\0'; + vlen++; +} + void tok_reset(FILE *f) { curf = f; @@ -182,11 +247,12 @@ struct tok_s tok_get(void) { int c; + assert(TOK_MAX_LEN >= 32); + if (unget) { unget = false; return curtok; - } - + } curtok.col += vlen; vlen = 0; @@ -256,6 +322,13 @@ struct tok_s tok_get(void) return curtok; default: + if (c == '"' || c == '<') { + val[0] = c; + vlen = 1; + sub_match_header(); + return curtok; + } + if (isdigit(c)) { val[0] = c; vlen = 1; -- cgit v1.2.3