From 01209d714d3720cd4aa18edac10a549177c81b1e Mon Sep 17 00:00:00 2001 From: katherine Date: Tue, 4 Jun 2019 17:52:21 -0700 Subject: add name-suffix and uthash-header options --- src/gen.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/gen.c') diff --git a/src/gen.c b/src/gen.c index 1283119..846f122 100644 --- a/src/gen.c +++ b/src/gen.c @@ -2,6 +2,7 @@ #include "version.h" #include "parse.h" +#include "opt.h" #include #include @@ -28,8 +29,8 @@ 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, sheaderp1); - fprintf(f, sheaderp2); + fprintf(f, sheadp1); + fprintf(f, sheadp2); if (ar.uses_type[PARSE_TYPE_BOOL]) fprintf(f, sbool); @@ -54,8 +55,10 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) if (ar.uses_type[PARSE_TYPE_DOUBLEL]) fprintf(f, sdoublel); + /* if (ar.uses_array) */ + /* fprintf(f, sarray); */ if (ar.uses_hash) - fprintf(f, shash, pr.location); + fprintf(f, shash, (opt_header_str() ? opt_header_str() : pr.header)); /******** * BODY * @@ -64,10 +67,11 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) fprintf(f, "#ifndef CONFCONF_BODY_%s_H\n" "#define CONFCONF_BODY_%s_H\n\n", - pr.suffix, pr.suffix - ); + (opt_suffix_str() ? opt_suffix_str() : pr.suffix), + (opt_suffix_str() ? opt_suffix_str() : pr.suffix) + ); - /* types */ + /* deftypes */ HASH_ITER(hh, pr.deftypes, dcur, dtmp) { if (!dcur->is_used) continue; @@ -77,14 +81,17 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) (dcur->type == PARSE_DEFTYPE_UNION ? "union" : "struct") ), - dcur->name, pr.suffix); + dcur->name, + (opt_suffix_str() ? opt_suffix_str() : pr.suffix) + ); for (i = 0; i < dcur->member_list_len; i++) { if (dcur->type == PARSE_DEFTYPE_ENUM) { fprintf(f, " CONFCONF_TYPE_%s_%s_%s,\n", dcur->name, dcur->member_name_list[i], - pr.suffix); + (opt_suffix_str() ? opt_suffix_str() : pr.suffix) + ); continue; } @@ -135,9 +142,7 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) fprintf(f, "};\n\n"); } - /* array */ - - /* hash */ + /* hash type */ if (ar.uses_hash) { fprintf(f, "#include %s\n\n" @@ -145,8 +150,8 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) " char *key;\n" " union {\n" "%s%s%s%s%s%s%s%s%s%s%s", - pr.location, - pr.suffix, + (opt_header_str() ? opt_header_str() : pr.header), + (opt_suffix_str() ? opt_suffix_str() : pr.suffix), (ar.uses_type[PARSE_TYPE_HASH_BOOL] ? " bool b;\n" : ""), (ar.uses_type[PARSE_TYPE_HASH_STRING] @@ -177,7 +182,10 @@ void gen(FILE *f, struct parse_result_s pr, struct analyse_result_s ar) (dcur->type == PARSE_DEFTYPE_UNION ? "union" : "struct") ), - dcur->name, pr.suffix, dcur->name); + dcur->name, + (opt_suffix_str() ? opt_suffix_str() : pr.suffix), + dcur->name + ); } } fprintf(f, -- cgit v1.2.3