From 6804fd50fa107605d652c063c2ae0844b812d4df Mon Sep 17 00:00:00 2001 From: katherine Date: Thu, 23 May 2019 12:42:51 -0700 Subject: add basetype funcs to gen --- src/gen-consts.h | 786 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gen.c | 47 ++-- src/main.c | 25 -- 3 files changed, 814 insertions(+), 44 deletions(-) create mode 100644 src/gen-consts.h diff --git a/src/gen-consts.h b/src/gen-consts.h new file mode 100644 index 0000000..035e3d2 --- /dev/null +++ b/src/gen-consts.h @@ -0,0 +1,786 @@ +static const char sheader[] = +"#ifndef CONFCONF_HEAD_H\n" +"#define CONFCONF_HEAD_H\n" +"\n" +"#include \n" +"#include \n" +"#include \n" +"\n" +"#ifndef CONFCONF_ALLOCWIDTH\n" +"#define CONFCONF_ALLOCWIDTH 32\n" +"#endif\n" +"\n" +"enum confconf_result_type {\n" +" CONFCONF_SUCCESS = 0,\n" +" CONFCONF_ERR_UNEXPECTED_EOF,\n" +" CONFCONF_ERR_UNEXPECTED_TOKEN,\n" +" CONFCONF_ERR_HASH_KEY_TOO_LONG,\n" +" CONFCONF_ERR_RANGE,\n" +" CONFCONF_ERR_MISSING_VARIABLE,\n" +" CONFCONF_ERR_MEMORY,\n" +" CONFCONF_ERR_BAD_ALLOC_WIDTH,\n" +"};\n" +"\n" +"struct confconf_priv_state {\n" +" void *fp;\n" +" int (*gcp)(void *);\n" +" int (*ugcp)(int, void *);\n" +" 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" +" };\n" +"};\n" +"\n" +"static int 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" +"{\n" +" return ungetc(c, (FILE *)fp);\n" +"}\n" +"\n" +"static void 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" +"\n" +" do {\n" +" c = (*(st->gcp))(st->fp);\n" +" st->col++;\n" +" st->byte++;\n" +" } while (c != '\\n' && c != EOF);\n" +"\n" +" if (c == '\\n') {\n" +" st->col = 1;\n" +" st->line++;\n" +" continue;\n" +" } else {\n" +" st->col--;\n" +" st->byte--;\n" +" return;\n" +" }\n" +" }\n" +"\n" +" /* space */\n" +" if (c == ' ' || c == '\\f' || c == '\\n'\n" +" || c == '\\r' || c == '\\t' || c == '\\v') {\n" +" while (c == ' ' || c == '\\f' || c == '\\n'\n" +" || c == '\\r' || c == '\\t' || c == '\\v') {\n" +" if (c == '\\n') {\n" +" st->col = 1;\n" +" st->line++;\n" +" } else {\n" +" st->col++;\n" +" }\n" +" st->byte++;\n" +"\n" +" c = (*(st->gcp))(st->fp);\n" +" }\n" +"\n" +" if (c == EOF) {\n" +" return;\n" +" } else {\n" +" (*(st->ugcp))(c, st->fp);\n" +" continue;\n" +" }\n" +" }\n" +"\n" +" (*(st->ugcp))(c, st->fp);\n" +" break;\n" +" }\n" +"}\n" +"\n" +"static enum confconf_result_type confconf_priv_get_tok(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" size_t len = 0, mlen = 0;\n" +" char *stmp;\n" +" int c;\n" +"\n" +" st->s = NULL;\n" +"\n" +" c = (*(st->gcp))(st->fp);\n" +"\n" +" if (c == EOF)\n" +" return CONFCONF_ERR_UNEXPECTED_EOF;\n" +"\n" +" while (c != ' ' && c != '\\f' && c != '\\n'\n" +" && c != '\\r' && c != '\\t' && c != '\\v'\n" +" && c != ']' && c != '}' && c != ','\n" +" && c != EOF) {\n" +" if (len == mlen) {\n" +" mlen += CONFCONF_ALLOCWIDTH;\n" +"\n" +" if (mlen < len) {\n" +" if (st->s != NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" }\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +"\n" +" stmp = realloc(st->s, mlen);\n" +" if (stmp == NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +" st->s = stmp;\n" +" }\n" +"\n" +" st->s[len] = c;\n" +" len++;\n" +" c = (*(st->gcp))(st->fp);\n" +" }\n" +"\n" +" if (len == mlen) {\n" +" mlen += CONFCONF_ALLOCWIDTH;\n" +"\n" +" if (mlen < len) {\n" +" if (st->s != NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" }\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +"\n" +" stmp = realloc(st->s, mlen);\n" +" if (stmp == NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +" st->s = stmp;\n" +" }\n" +"\n" +" (*(st->ugcp))(c, st->fp);\n" +"\n" +" st->s[len] = '\\0';\n" +"\n" +" st->col += len;\n" +" st->byte += len;\n" +"\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +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" +"{\n" +" enum confconf_result_type r;\n" +" char *off;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" off = st->s;\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" +" ) {\n" +" free(st->s);\n" +" st->b = true;\n" +" return CONFCONF_SUCCESS;\n" +" } else {\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" +" ) {\n" +" free(st->s);\n" +" st->b = true;\n" +" return CONFCONF_SUCCESS;\n" +" } else {\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" +" ) {\n" +" free(st->s);\n" +" st->b = false;\n" +" return CONFCONF_SUCCESS;\n" +" } else {\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" +" ) {\n" +" free(st->s);\n" +" st->b = false;\n" +" return CONFCONF_SUCCESS;\n" +" } else {\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" +" ) {\n" +" free(st->s);\n" +" st->b = true;\n" +" return CONFCONF_SUCCESS;\n" +" }\n" +"\n" +" if (\n" +" (*(++off) == 'f' || *off == 'F') &&\n" +" (*(++off) == 'f' || *off == 'F') &&\n" +" (*(++off) == '\\0')\n" +" ) {\n" +" free(st->s);\n" +" st->b = false;\n" +" return CONFCONF_SUCCESS;\n" +" } else {\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" +" }\n" +"\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +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" +"{\n" +" size_t len = 0, mlen = 0;\n" +" char *stmp;\n" +" int c, endc;\n" +" bool escape = false;\n" +"\n" +" st->s = NULL;\n" +"\n" +" c = (*(st->gcp))(st->fp);\n" +" if (c == EOF)\n" +" return CONFCONF_ERR_UNEXPECTED_EOF;\n" +"\n" +" if (c != '\\'' && c != '\\\"') {\n" +" (*(st->ugcp))(c, st->fp);\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" +"\n" +" endc = c;\n" +"\n" +" st->col++;\n" +" st->byte++;\n" +"\n" +" while (true) {\n" +" c = (*(st->gcp))(st->fp);\n" +" st->col++;\n" +" st->byte++;\n" +"\n" +" if (c == endc && !escape)\n" +" break;\n" +"\n" +" if (c == '\\\\' && !escape) {\n" +" escape = true;\n" +" continue;\n" +" }\n" +"\n" +" escape = false;\n" +"\n" +" if (c == '\\n') {\n" +" st->col = 1;\n" +" st->line++;\n" +" }\n" +"\n" +" if (c == EOF) {\n" +" if (st->s != NULL) {\n" +" free(st->s);\n" +" st->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->s != NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" }\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +"\n" +" stmp = realloc(st->s, mlen);\n" +" if (stmp == NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +" st->s = stmp;\n" +" }\n" +"\n" +" st->s[len] = c;\n" +" len++;\n" +" }\n" +"\n" +" if (len == mlen) {\n" +" mlen += CONFCONF_ALLOCWIDTH;\n" +"\n" +" if (mlen < len) {\n" +" if (st->s != NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" }\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +"\n" +" stmp = realloc(st->s, mlen);\n" +" if (stmp == NULL) {\n" +" free(st->s);\n" +" st->s = NULL;\n" +" return CONFCONF_ERR_MEMORY;\n" +" }\n" +" st->s = stmp;\n" +" }\n" +"\n" +" st->s[len] = '\\0';\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sid[] = +"#ifndef CONFCONF_ID_H\n" +"#define CONFCONF_ID_H\n" +"\n" +"static enum confconf_result_type confconf_priv_get_id(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" char *off;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" for (off = st->s; *off != '\\0'; off++) {\n" +" if (*off >= '0' && *off <= '9')\n" +" continue;\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" +" ) {\n" +" continue;\n" +" }\n" +" \n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +" }\n" +"\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sint[] = +"#ifndef CONFCONF_INT_H\n" +"#define CONFCONF_INT_H\n" +"\n" +"#include \n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_int(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" long int i;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" i = strtol(st->s, &check, 0);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" if (i > INT_MAX || i < INT_MIN)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" free(st->s);\n" +" st->i = (int)i;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sintl[] = +"#ifndef CONFCONF_INTL_H\n" +"#define CONFCONF_INTL_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_intl(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" long int il;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" il = strtol(st->s, &check, 0);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->il = il;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sintll[] = +"#ifndef CONFCONF_INTLL_H\n" +"#define CONFCONF_INTLL_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_intll(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" long long int ill;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" ill = strtoll(st->s, &check, 0);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->ill = ill;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char suint[] = +"#ifndef CONFCONF_UINT_H\n" +"#define CONFCONF_UINT_H\n" +"\n" +"#include \n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_uint(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" long unsigned u;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" u = strtoul(st->s, &check, 0);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" if (u > UINT_MAX)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" free(st->s);\n" +" st->u = (unsigned)u;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char suintl[] = +"#ifndef CONFCONF_UINTL_H\n" +"#define CONFCONF_UINTL_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_uintl(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" long unsigned ul;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" ul = strtoul(st->s, &check, 0);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->ul = ul;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char suintll[] = +"#ifndef CONFCONF_UINTLL_H\n" +"#define CONFCONF_UINTLL_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_uintll(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" long long unsigned ull;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" ull = strtoull(st->s, &check, 0);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->ull = ull;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sfloat[] = +"#ifndef CONFCONF_FLOAT_H\n" +"#define CONFCONF_FLOAT_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_float(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" double f;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" f = strtof(st->s, &check);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->f = f;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sdouble[] = +"#ifndef CONFCONF_DOUBLE_H\n" +"#define CONFCONF_DOUBLE_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_double(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" double d;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" d = strtod(st->s, &check);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->d = d;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; + +static const char sdoublel[] = +"#ifndef CONFCONF_DOUBLEL_H\n" +"#define CONFCONF_DOUBLEL_H\n" +"\n" +"#include \n" +"\n" +"static enum confconf_result_type confconf_priv_get_doublel(\n" +" struct confconf_priv_state *st)\n" +"{\n" +" enum confconf_result_type r;\n" +" double dl;\n" +" char *check;\n" +"\n" +" r = confconf_priv_get_tok(st);\n" +"\n" +" if (r != CONFCONF_SUCCESS)\n" +" return r;\n" +"\n" +" errno = EILSEQ;\n" +" dl = strtold(st->s, &check);\n" +"\n" +" if (errno == ERANGE)\n" +" return CONFCONF_ERR_RANGE;\n" +"\n" +" if (*check != '\\0')\n" +" return CONFCONF_ERR_UNEXPECTED_TOKEN;\n" +"\n" +" free(st->s);\n" +" st->dl = dl;\n" +" return CONFCONF_SUCCESS;\n" +"}\n" +"\n" +"#endif\n" +"\n" +; diff --git a/src/gen.c b/src/gen.c index 98e067b..fdad6e8 100644 --- a/src/gen.c +++ b/src/gen.c @@ -4,24 +4,7 @@ #include -static const char header[] = -"#ifndef CONFCONF_PRIV_H\n" -"#define CONFCONF_PRIV_H\n" -"\n" -"#include \n" -"#include \n" -"#include \n" -"\n" -"struct confconf_priv_fstate {\n" -" void *f;\n" -" int (*gcp)(void *);\n" -" size_t line;\n" -" size_t col;\n" -" size_t byte;\n" -"};\n" -"\n" -"#endif\n" -; +#include "gen-consts.h" void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) { @@ -34,5 +17,31 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) fprintf(f, "/* generated by %s on %04d-%02d-%02d */\n", VERSION, ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday); - fprintf(f, header); + fprintf(f, sheader); + + if (ar.uses_bool) + fprintf(f, sbool); + if (ar.uses_string) + fprintf(f, sstring); + if (ar.uses_id) + fprintf(f, sid); + if (ar.uses_int) + fprintf(f, sint); + if (ar.uses_intl) + fprintf(f, sintl); + if (ar.uses_intll) + fprintf(f, sintll); + if (ar.uses_uint) + fprintf(f, suint); + if (ar.uses_uintl) + fprintf(f, suintl); + if (ar.uses_uintll) + fprintf(f, suintll); + if (ar.uses_float) + fprintf(f, sfloat); + if (ar.uses_double) + fprintf(f, sdouble); + if (ar.uses_doublel) + fprintf(f, sdoublel); + } diff --git a/src/main.c b/src/main.c index 77f3c55..4ec0e75 100644 --- a/src/main.c +++ b/src/main.c @@ -59,31 +59,6 @@ int main(int argc, char **argv) print_tree(&ar.var_tree); puts(""); - if (ar.uses_bool) - puts("bool"); - if (ar.uses_string) - puts("string"); - if (ar.uses_id) - puts("id"); - if (ar.uses_int) - puts("int"); - if (ar.uses_intl) - puts("intl"); - if (ar.uses_intll) - puts("intll"); - if (ar.uses_uint) - puts("uint"); - if (ar.uses_uintl) - puts("uintl"); - if (ar.uses_uintll) - puts("uintll"); - if (ar.uses_float) - puts("float"); - if (ar.uses_double) - puts("double"); - if (ar.uses_doublel) - puts("doublel"); - gen(fo, pr, ar); if (fo != stdout) -- cgit v1.2.3