From 06cb82a8ccc3587dff728321dff5416b18090483 Mon Sep 17 00:00:00 2001 From: katherine Date: Wed, 10 Jul 2019 20:24:08 -0700 Subject: implement deftype get --- src/gen-consts.h | 691 +++++++++++++++++++++++++------------------------------ 1 file changed, 315 insertions(+), 376 deletions(-) (limited to 'src/gen-consts.h') diff --git a/src/gen-consts.h b/src/gen-consts.h index 72c1a46..90c2d9c 100644 --- a/src/gen-consts.h +++ b/src/gen-consts.h @@ -28,39 +28,32 @@ static const char sheadp1[] = " size_t line;\n" " size_t col;\n" " size_t byte;\n" -" union {\n" -" bool b;\n" -" char *s;\n" -" int i;\n" -" long int il;\n" -" long long int ill;\n" -" unsigned u;\n" -" long unsigned ul;\n" -" long long unsigned ull;\n" -" float f;\n" -" double d;\n" -" long double dl;\n" -" } val;\n" +" size_t sbuf_len;\n" +" size_t sbuf_mlen;\n" +" char *sbuf;\n" +" void *vp;\n" "};\n" "\n" -"static int confconf_priv_gcp_file(void *fp)\n" +"static int\n" +"confconf_priv_gcp_file(void *fp)\n" "{\n" " return getc((FILE *)fp);\n" "}\n" "\n" -"static int confconf_priv_ugcp_file(int c, void *fp)\n" +"static int\n" +"confconf_priv_ugcp_file(int c, void *fp)\n" "{\n" " return ungetc(c, (FILE *)fp);\n" "}\n" "\n" -"static void confconf_priv_eat_space(struct confconf_priv_state *st)\n" +"static void\n" +"confconf_priv_eat_space(struct confconf_priv_state *st)\n" "{\n" " int c;\n" "\n" " while (true) {\n" " c = (*(st->gcp))(st->fp);\n" "\n" -" /* comment */\n" " if (c == '#') {\n" " st->col++;\n" " st->byte++;\n" @@ -82,11 +75,12 @@ static const char sheadp1[] = " }\n" " }\n" "\n" -" /* space */\n" " if (c == ' ' || c == '\\f' || c == '\\n'\n" -" || c == '\\r' || c == '\\t' || c == '\\v') {\n" +" || c == '\\r' || c == '\\t' || c == '\\v'\n" +" ) {\n" " while (c == ' ' || c == '\\f' || c == '\\n'\n" -" || c == '\\r' || c == '\\t' || c == '\\v') {\n" +" || c == '\\r' || c == '\\t' || c == '\\v'\n" +" ) {\n" " if (c == '\\n') {\n" " st->col = 1;\n" " st->line++;\n" @@ -111,153 +105,153 @@ static const char sheadp1[] = " }\n" "}\n" "\n" +"static bool\n" +"confconf_priv_push_char(struct confconf_priv_state *st, char c)\n" +"{\n" +" char *stmp;\n" +"\n" +" if (st->sbuf_len == st->sbuf_mlen\n" +" || st->sbuf_len + 1 == st->sbuf_mlen\n" +" ) {\n" +" st->sbuf_mlen += CONFCONF_ALLOCWIDTH;\n" +" stmp = realloc(st->sbuf, st->sbuf_mlen * sizeof(char));\n" +" \n" +" if (stmp == NULL) {\n" +" if (st->sbuf != NULL)\n" +" free(st->sbuf);\n" +" st->sbuf = NULL;\n" +" return false;\n" +" }\n" +"\n" +" st->sbuf = stmp;\n" +" }\n" +"\n" +" st->sbuf[st->sbuf_len] = c;\n" +" st->sbuf_len++;\n" +" st->sbuf[st->sbuf_len] = '\\0';\n" +"\n" +" return true;\n" +"}\n" +"\n" ; static const char sheadp2[] = -"static enum confconf_result_type confconf_priv_get_tok(\n" -" struct confconf_priv_state *st)\n" +"struct confconf_priv_pos {\n" +" size_t line;\n" +" size_t col;\n" +" size_t byte;\n" +"};\n" +"\n" +"static struct confconf_priv_pos\n" +"confconf_priv_pos_get(struct confconf_priv_state *st)\n" +"{\n" +" struct confconf_priv_pos pos = {\n" +" .line = st->line,\n" +" .col = st->col,\n" +" .byte = st->byte,\n" +" };\n" +"\n" +" return pos;\n" +"}\n" +"static void\n" +"confconf_priv_pos_set(struct confconf_priv_state *st,\n" +" struct confconf_priv_pos pos)\n" +"{\n" +" st->line = pos.line;\n" +" st->col = pos.col;\n" +" st->byte = pos.byte;\n" +"}\n" +"\n" +"static enum confconf_result_type\n" +"confconf_priv_get_tok(struct confconf_priv_state *st)\n" "{\n" -" size_t len = 0, mlen = CONFCONF_ALLOCWIDTH;\n" -" char *stmp;\n" " int c;\n" "\n" -" st->val.s = NULL;\n" +" st->sbuf_len = 0;\n" "\n" " c = (*(st->gcp))(st->fp);\n" "\n" " if (c == EOF)\n" " return CONFCONF_ERR_UNEXPECTED_EOF;\n" "\n" -" st->val.s = realloc(st->val.s, mlen);\n" -" if (st->val.s == NULL)\n" -" return CONFCONF_ERR_MEMORY;\n" -" st->val.s[0] = '\\0';\n" -"\n" " while (c != ' ' && c != '\\f' && c != '\\n'\n" -" && c != '\\r' && c != '\\t' && c != '\\v'\n" -" && c != ']' && c != '}'\n" -" && c != '[' && c != '{'\n" -" && c != ',' && c != ':'\n" -" && c != EOF) {\n" -" if (len == mlen) {\n" -" mlen += CONFCONF_ALLOCWIDTH;\n" -"\n" -" if (mlen < len) {\n" -" if (st->val.s != NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" }\n" -" return CONFCONF_ERR_MEMORY;\n" -" }\n" -"\n" -" stmp = realloc(st->val.s, mlen);\n" -" if (stmp == NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" return CONFCONF_ERR_MEMORY;\n" -" }\n" -" st->val.s = stmp;\n" -" }\n" +" && c != '\\r' && c != '\\t' && c != '\\v'\n" +" && c != ']' && c != '}'\n" +" && c != '[' && c != '{'\n" +" && c != ',' && c != ':'\n" +" && c != '\\'' && c != '\"'\n" +" && c != '=' && c != EOF\n" +" ) {\n" +" if ( !confconf_priv_push_char(st, (char)c) )\n" +" return CONFCONF_ERR_MEMORY;\n" "\n" -" st->val.s[len] = c;\n" -" len++;\n" " c = (*(st->gcp))(st->fp);\n" " }\n" "\n" -" if (st->val.s[0] == '\\0') {\n" -" st->val.s[0] = c;\n" -" len++;\n" -" if (len == mlen) {\n" -" mlen += CONFCONF_ALLOCWIDTH;\n" -"\n" -" if (mlen < len) {\n" -" if (st->val.s != NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" }\n" +" if (st->sbuf_len == 0) {\n" +" if (c == ' ' || c == '\\f' || c == '\\n'\n" +" || c == '\\r' || c == '\\t' || c == '\\v'\n" +" ) {\n" +" (*(st->ugcp))(c, st->fp);\n" +" if ( !confconf_priv_push_char(st, '\\0') )\n" " return CONFCONF_ERR_MEMORY;\n" -" }\n" -"\n" -" stmp = realloc(st->val.s, mlen);\n" -" if (stmp == NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" +" } else {\n" +" if ( !confconf_priv_push_char(st, (char)c) )\n" " return CONFCONF_ERR_MEMORY;\n" -" }\n" -" st->val.s = stmp;\n" -" }\n" -" st->val.s[1] = '\\0';\n" -" return CONFCONF_SUCCESS;\n" -" }\n" -"\n" -" if (len == mlen) {\n" -" mlen += CONFCONF_ALLOCWIDTH;\n" -"\n" -" if (mlen < len) {\n" -" if (st->val.s != NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" }\n" -" return CONFCONF_ERR_MEMORY;\n" +" st->sbuf_len = 1;\n" " }\n" -"\n" -" stmp = realloc(st->val.s, mlen);\n" -" if (stmp == NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" return CONFCONF_ERR_MEMORY;\n" -" }\n" -" st->val.s = stmp;\n" +" } else {\n" +" (*(st->ugcp))(c, st->fp);\n" " }\n" "\n" -" (*(st->ugcp))(c, st->fp);\n" -"\n" -" st->val.s[len] = '\\0';\n" -"\n" -" st->col += len;\n" -" st->byte += len;\n" +" st->col += st->sbuf_len;\n" +" st->byte += st->sbuf_len;\n" "\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" -"static enum confconf_result_type confconf_priv_get_id(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_id(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" " char *off;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" -" for (off = st->val.s; *off != '\\0'; off++) {\n" +" for (off = st->sbuf; *off != '\\0'; off++) {\n" " if (*off >= '0' && *off <= '9')\n" " continue;\n" +"\n" " if (\n" -" *off == 'a' || *off == 'b' || *off == 'c' ||\n" -" *off == 'd' || *off == 'e' || *off == 'f' ||\n" -" *off == 'g' || *off == 'h' || *off == 'i' ||\n" -" *off == 'j' || *off == 'k' || *off == 'l' ||\n" -" *off == 'm' || *off == 'n' || *off == 'o' ||\n" -" *off == 'p' || *off == 'q' || *off == 'r' ||\n" -" *off == 's' || *off == 't' || *off == 'u' ||\n" -" *off == 'v' || *off == 'w' || *off == 'x' ||\n" -" *off == 'y' || *off == 'z' ||\n" -" *off == 'A' || *off == 'B' || *off == 'C' ||\n" -" *off == 'D' || *off == 'E' || *off == 'F' ||\n" -" *off == 'G' || *off == 'H' || *off == 'I' ||\n" -" *off == 'J' || *off == 'K' || *off == 'L' ||\n" -" *off == 'M' || *off == 'N' || *off == 'O' ||\n" -" *off == 'P' || *off == 'Q' || *off == 'R' ||\n" -" *off == 'S' || *off == 'T' || *off == 'U' ||\n" -" *off == 'V' || *off == 'W' || *off == 'X' ||\n" -" *off == 'Y' || *off == 'Z' ||\n" -" *off == '-' || *off == '_'\n" +" *off == 'a' || *off == 'b' || *off == 'c' ||\n" +" *off == 'd' || *off == 'e' || *off == 'f' ||\n" +" *off == 'g' || *off == 'h' || *off == 'i' ||\n" +" *off == 'j' || *off == 'k' || *off == 'l' ||\n" +" *off == 'm' || *off == 'n' || *off == 'o' ||\n" +" *off == 'p' || *off == 'q' || *off == 'r' ||\n" +" *off == 's' || *off == 't' || *off == 'u' ||\n" +" *off == 'v' || *off == 'w' || *off == 'x' ||\n" +" *off == 'y' || *off == 'z' ||\n" +" *off == 'A' || *off == 'B' || *off == 'C' ||\n" +" *off == 'D' || *off == 'E' || *off == 'F' ||\n" +" *off == 'G' || *off == 'H' || *off == 'I' ||\n" +" *off == 'J' || *off == 'K' || *off == 'L' ||\n" +" *off == 'M' || *off == 'N' || *off == 'O' ||\n" +" *off == 'P' || *off == 'Q' || *off == 'R' ||\n" +" *off == 'S' || *off == 'T' || *off == 'U' ||\n" +" *off == 'V' || *off == 'W' || *off == 'X' ||\n" +" *off == 'Y' || *off == 'Z' ||\n" +" *off == '-' || *off == '_'\n" " ) {\n" -" continue;\n" +" continue;\n" " }\n" -" \n" +"\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" "\n" @@ -272,100 +266,103 @@ static const char sbool[] = "#ifndef CONFCONF_BOOL_H\n" "#define CONFCONF_BOOL_H\n" "\n" -"static enum confconf_result_type confconf_priv_get_bool(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_bool(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" +" bool *b = st->vp;\n" " char *off;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" -" off = st->val.s;\n" +" off = st->sbuf;\n" "\n" " if (*off == 't' || *off == 'T') {\n" " if (\n" -" (*(++off) == 'r' || *off == 'R') &&\n" -" (*(++off) == 'u' || *off == 'U') &&\n" -" (*(++off) == 'e' || *off == 'E') &&\n" -" (*(++off) == '\\0')\n" +" (*(++off) == 'r' || *off == 'R') &&\n" +" (*(++off) == 'u' || *off == 'U') &&\n" +" (*(++off) == 'e' || *off == 'E') &&\n" +" (*(++off) == '\\0')\n" " ) {\n" -" free(st->val.s);\n" -" st->val.b = true;\n" +" *b = true;\n" " return CONFCONF_SUCCESS;\n" " } else {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" " }\n" "\n" " if (*off == 'y' || *off == 'Y') {\n" " if (\n" -" (*(++off) == 'e' || *off == 'E') &&\n" -" (*(++off) == 's' || *off == 'S') &&\n" -" (*(++off) == '\\0')\n" +" (*(++off) == 'e' || *off == 'E') &&\n" +" (*(++off) == 's' || *off == 'S') &&\n" +" (*(++off) == '\\0')\n" " ) {\n" -" free(st->val.s);\n" -" st->val.b = true;\n" +" *b = true;\n" " return CONFCONF_SUCCESS;\n" " } else {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" " }\n" "\n" " if (*off == 'n' || *off == 'N') {\n" " if (\n" -" (*(++off) == 'o' || *off == 'O') &&\n" -" (*(++off) == '\\0')\n" +" (*(++off) == 'o' || *off == 'O') &&\n" +" (*(++off) == '\\0')\n" " ) {\n" -" free(st->val.s);\n" -" st->val.b = false;\n" +" *b = false;\n" " return CONFCONF_SUCCESS;\n" " } else {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" " }\n" "\n" " if (*off == 'f' || *off == 'F') {\n" " if (\n" -" (*(++off) == 'a' || *off == 'A') &&\n" -" (*(++off) == 'l' || *off == 'L') &&\n" -" (*(++off) == 's' || *off == 'S') &&\n" -" (*(++off) == 'e' || *off == 'E') &&\n" -" (*(++off) == '\\0')\n" +" (*(++off) == 'a' || *off == 'A') &&\n" +" (*(++off) == 'l' || *off == 'L') &&\n" +" (*(++off) == 's' || *off == 'S') &&\n" +" (*(++off) == 'e' || *off == 'E') &&\n" +" (*(++off) == '\\0')\n" " ) {\n" -" free(st->val.s);\n" -" st->val.b = false;\n" +" *b = false;\n" " return CONFCONF_SUCCESS;\n" " } else {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" " }\n" "\n" " if (*off == 'o' || *off == 'O') {\n" " if (\n" -" (*(off+1) == 'n' || *(off+1) == 'N') &&\n" -" (*(off+2) == '\\0')\n" +" (*(off+1) == 'n' || *(off+1) == 'N') &&\n" +" (*(off+2) == '\\0')\n" " ) {\n" -" free(st->val.s);\n" -" st->val.b = true;\n" +" *b = true;\n" " return CONFCONF_SUCCESS;\n" " }\n" "\n" " if (\n" -" (*(++off) == 'f' || *off == 'F') &&\n" -" (*(++off) == 'f' || *off == 'F') &&\n" -" (*(++off) == '\\0')\n" +" (*(++off) == 'f' || *off == 'F') &&\n" +" (*(++off) == 'f' || *off == 'F') &&\n" +" (*(++off) == '\\0')\n" " ) {\n" -" free(st->val.s);\n" -" st->val.b = false;\n" +" *b = false;\n" " return CONFCONF_SUCCESS;\n" " } else {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" " }\n" "\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" "}\n" "\n" @@ -377,32 +374,63 @@ static const char sstring[] = "#ifndef CONFCONF_STRING_H\n" "#define CONFCONF_STRING_H\n" "\n" -"static enum confconf_result_type confconf_priv_get_str(\n" -" struct confconf_priv_state *st)\n" +"#include \n" +"\n" +"static char*\n" +"confconf_priv_dup_sbuf(struct confconf_priv_state *st)\n" +"{\n" +" char *s;\n" +"\n" +" s = malloc((st->sbuf_len + 1) * sizeof(char));\n" +"\n" +" if (s == NULL)\n" +" return NULL;\n" +"\n" +" if (st->sbuf_len == 0)\n" +" s[0] = '\\0';\n" +" else\n" +" strcpy(s, st->sbuf);\n" +"\n" +" return s;\n" +"}\n" +"\n" +"static enum confconf_result_type\n" +"confconf_priv_get_str(struct confconf_priv_state *st)\n" "{\n" -" size_t len = 0, mlen = 0;\n" -" char *stmp;\n" " int c, endc;\n" " bool escape = false;\n" -"\n" -" st->val.s = NULL;\n" +" enum confconf_result_type r;\n" +" struct confconf_priv_pos pos;\n" "\n" " c = (*(st->gcp))(st->fp);\n" +"\n" " if (c == EOF)\n" " return CONFCONF_ERR_UNEXPECTED_EOF;\n" "\n" " if (c != '\\'' && c != '\\\"') {\n" " (*(st->ugcp))(c, st->fp);\n" +" pos = confconf_priv_pos_get(st);\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" " }\n" "\n" " endc = c;\n" -"\n" " st->col++;\n" " st->byte++;\n" "\n" +" st->sbuf_len = 0;\n" +"\n" " while (true) {\n" " c = (*(st->gcp))(st->fp);\n" +"\n" +" if (c == EOF)\n" +" return CONFCONF_ERR_UNEXPECTED_EOF;\n" +"\n" " st->col++;\n" " st->byte++;\n" "\n" @@ -421,59 +449,10 @@ static const char sstring[] = " st->line++;\n" " }\n" "\n" -" if (c == EOF) {\n" -" if (st->val.s != NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" }\n" -" return CONFCONF_ERR_UNEXPECTED_EOF;\n" -" }\n" -"\n" -" if (len == mlen) {\n" -" mlen += CONFCONF_ALLOCWIDTH;\n" -"\n" -" if (mlen < len) {\n" -" if (st->val.s != NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" }\n" -" return CONFCONF_ERR_MEMORY;\n" -" }\n" -"\n" -" stmp = realloc(st->val.s, mlen);\n" -" if (stmp == NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" return CONFCONF_ERR_MEMORY;\n" -" }\n" -" st->val.s = stmp;\n" -" }\n" -"\n" -" st->val.s[len] = c;\n" -" len++;\n" -" }\n" -"\n" -" if (len == mlen) {\n" -" mlen += CONFCONF_ALLOCWIDTH;\n" -"\n" -" if (mlen < len) {\n" -" if (st->val.s != NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" }\n" +" if ( !confconf_priv_push_char(st, (char)c) )\n" " return CONFCONF_ERR_MEMORY;\n" -" }\n" -"\n" -" stmp = realloc(st->val.s, mlen);\n" -" if (stmp == NULL) {\n" -" free(st->val.s);\n" -" st->val.s = NULL;\n" -" return CONFCONF_ERR_MEMORY;\n" -" }\n" -" st->val.s = stmp;\n" " }\n" "\n" -" st->val.s[len] = '\\0';\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -488,32 +467,40 @@ static const char sint[] = "#include \n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_int(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_int(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" long int i;\n" +" int *i = st->vp;\n" +" long int local_i;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" i = strtol(st->val.s, &check, 0);\n" +" local_i = strtol(st->sbuf, &check, 0);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" if (i > INT_MAX || i < INT_MIN)\n" +" if (local_i > INT_MAX || local_i < INT_MIN) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.i = (int)i;\n" +" *i = (int)local_i;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -527,29 +514,33 @@ static const char sintl[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_intl(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_intl(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" long int il;\n" +" long int *il = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" il = strtol(st->val.s, &check, 0);\n" +" *il = strtol(st->sbuf, &check, 0);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.il = il;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -563,29 +554,33 @@ static const char sintll[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_intll(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_intll(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" long long int ill;\n" +" long long int *ill = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" ill = strtoll(st->val.s, &check, 0);\n" +" *ill = strtoll(st->sbuf, &check, 0);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.ill = ill;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -600,32 +595,40 @@ static const char suint[] = "#include \n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_uint(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_uint(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" long unsigned u;\n" +" unsigned *u = st->vp;\n" +" long unsigned u_local;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" u = strtoul(st->val.s, &check, 0);\n" +" u_local = strtoul(st->sbuf, &check, 0);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" if (u > UINT_MAX)\n" +" if (u_local > UINT_MAX) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.u = (unsigned)u;\n" +" *u = (unsigned)u_local;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -639,29 +642,33 @@ static const char suintl[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_uintl(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_uintl(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" long unsigned ul;\n" +" long unsigned *ul = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" ul = strtoul(st->val.s, &check, 0);\n" +" *ul = strtoul(st->sbuf, &check, 0);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.ul = ul;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -675,29 +682,33 @@ static const char suintll[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_uintll(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_uintll(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" long long unsigned ull;\n" +" long long unsigned *ull = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" ull = strtoull(st->val.s, &check, 0);\n" +" *ull = strtoull(st->sbuf, &check, 0);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.ull = ull;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -711,29 +722,33 @@ static const char sfloat[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_float(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_float(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" double f;\n" +" float *f = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" f = strtof(st->val.s, &check);\n" +" *f = strtof(st->sbuf, &check);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.f = f;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -747,29 +762,33 @@ static const char sdouble[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_double(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_double(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" double d;\n" +" double *d = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" d = strtod(st->val.s, &check);\n" +" *d = strtod(st->sbuf, &check);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.d = d;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" @@ -783,116 +802,36 @@ static const char sdoublel[] = "\n" "#include \n" "\n" -"static enum confconf_result_type confconf_priv_get_doublel(\n" -" struct confconf_priv_state *st)\n" +"static enum confconf_result_type\n" +"confconf_priv_get_doublel(struct confconf_priv_state *st)\n" "{\n" " enum confconf_result_type r;\n" -" double dl;\n" +" long double *dl = st->vp;\n" " char *check;\n" +" struct confconf_priv_pos pos;\n" "\n" +" pos = confconf_priv_pos_get(st);\n" " r = confconf_priv_get_tok(st);\n" "\n" " if (r != CONFCONF_SUCCESS)\n" " return r;\n" "\n" " errno = EILSEQ;\n" -" dl = strtold(st->val.s, &check);\n" +" *dl = strtold(st->sbuf, &check);\n" "\n" -" if (errno == ERANGE)\n" +" if (errno == ERANGE) {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_RANGE;\n" +" }\n" "\n" -" if (*check != '\\0')\n" +" if (*check != '\\0') {\n" +" confconf_priv_pos_set(st, pos);\n" " return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" "\n" -" free(st->val.s);\n" -" st->val.dl = dl;\n" " return CONFCONF_SUCCESS;\n" "}\n" "\n" "#endif\n" "\n" ; - -static const char shash[] = -"#ifndef CONFCONF_HASH_H\n" -"#define CONFCONF_HASH_H\n" -"\n" -"#include %s\n" -"\n" -"#define CONFCONF_PRIV_GET_HASH_main(h, htmp, fun, mem) \\\n" -" do { \\\n" -" int c; \\\n" -" char *hash_swp; \\\n" -" (h) = NULL; \\\n" -" c = (*(st.gcp))(st.fp); \\\n" -" if (c != '[') { \\\n" -" if (c == EOF) { \\\n" -" r = CONFCONF_ERR_UNEXPECTED_EOF; \\\n" -" st.val.s = NULL; \\\n" -" break; \\\n" -" } \\\n" -" (*(st.ugcp))(c, st.fp); \\\n" -" confconf_priv_get_tok(&st); \\\n" -" r = CONFCONF_ERR_UNEXPECTED_TOKEN; \\\n" -" } \\\n" -" st.col++; \\\n" -" st.byte++; \\\n" -" while (1) { \\\n" -" confconf_priv_eat_space(&st); \\\n" -" r = confconf_priv_get_id(&st); \\\n" -" if (r != CONFCONF_SUCCESS) \\\n" -" break; \\\n" -" HASH_FIND_STR((h), st.val.s, (htmp)); \\\n" -" if ((htmp) != NULL) { \\\n" -" r = CONFCONF_ERR_HASH_DUPLICATE_KEY; \\\n" -" break; \\\n" -" } \\\n" -" hash_swp = st.val.s; \\\n" -" confconf_priv_eat_space(&st); \\\n" -" c = (*(st.gcp))(st.fp); \\\n" -" if (c == ':') { \\\n" -" st.col++; \\\n" -" st.byte++; \\\n" -" confconf_priv_eat_space(&st); \\\n" -" } else { \\\n" -" (*(st.ugcp))(c, st.fp); \\\n" -" free(hash_swp); \\\n" -" r = confconf_priv_get_tok(&st); \\\n" -" if (r == CONFCONF_SUCCESS) \\\n" -" r = CONFCONF_ERR_UNEXPECTED_TOKEN; \\\n" -" break; \\\n" -" } \\\n" -" r = confconf_priv_get_ ## fun (&st); \\\n" -" if (r != CONFCONF_SUCCESS) { \\\n" -" free(hash_swp); \\\n" -" break; \\\n" -" } \\\n" -" (htmp) = malloc(sizeof(*(htmp))); \\\n" -" if ((htmp) == NULL) { \\\n" -" free(hash_swp); \\\n" -" r = CONFCONF_ERR_MEMORY; \\\n" -" break; \\\n" -" } \\\n" -" (htmp)->key = hash_swp; \\\n" -" (htmp)->val.mem = st.val.mem; \\\n" -" HASH_ADD_STR((h), key, (htmp)); \\\n" -" confconf_priv_eat_space(&st); \\\n" -" c = (*(st.gcp))(st.fp); \\\n" -" if (c == ',') { \\\n" -" st.col++; \\\n" -" st.byte++; \\\n" -" confconf_priv_eat_space(&st); \\\n" -" } else if (c == ']') { \\\n" -" st.col++; \\\n" -" st.byte++; \\\n" -" r = CONFCONF_SUCCESS; \\\n" -" break; \\\n" -" } else { \\\n" -" (*(st.ugcp))(c, st.fp); \\\n" -" } \\\n" -" } \\\n" -" } while (0)\n" -"\n" -"#endif\n" -"\n" -; -- cgit v1.2.3