From c9e85edbd1d93b2cf883289b8cc1694a4c818a6c Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Mon, 4 Oct 2021 19:34:54 +0200 Subject: [PATCH] Add type enum generation --- typegen/main.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/typegen/main.c b/typegen/main.c index 37b9fbd..6a1b904 100644 --- a/typegen/main.c +++ b/typegen/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -34,10 +35,10 @@ int main(__attribute((unused)) int argc, __attribute((unused)) char **argv) size_t msgs_len = split(&msgs, data, "\n"); char *msg = NULL; - for (size_t i = 0; i < msgs_len; i++) { + for (size_t i = 0; i < msgs_len; ++i) { if (msgs[i][0] != '\t') { if (msg != NULL) - fprintf(fp, "} %s;\n", msg); + fprintf(fp, "} %s;\n\n", msg); msg = msgs[i]; fprintf(fp, "typedef struct {\n"); @@ -97,12 +98,30 @@ int main(__attribute((unused)) int argc, __attribute((unused)) char **argv) // Blob strcpy(type, "DragonnetBlob "); - fprintf(fp, "\t%s%s;\n", type, &tokens[0][1]); + fprintf(fp, "\t%s%s;\n", type, tokens[1]); free(tokens); } } - fprintf(fp, "} %s;\n", msg); + fprintf(fp, "} %s;\n\ntypedef enum {\n", msg); + for (size_t i = 0; i < msgs_len; ++i) { + if (msgs[i][0] == '\t') + continue; + + char upper[1 + strlen(msgs[i])]; + char *ptr = upper; + strcpy(upper, msgs[i]); + + while ((*ptr = *ptr ? toupper(*ptr) : '\0')) + ++ptr; + + if (i == msgs_len-1) + fprintf(fp, "\tDRAGONNET_TYPE_%s\n", upper); + else + fprintf(fp, "\tDRAGONNET_TYPE_%s,\n", upper); + } + + fprintf(fp, "} DragonnetType;\n"); free(msgs); fclose(fp); -- 2.44.0