From: Not Zed Date: Thu, 11 Jan 2024 05:37:48 +0000 (+1030) Subject: Create allocating *_decode() functions. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=25404d28256badc86c32ac4dd32ba1c0cd7ab049;p=libeze Create allocating *_decode() functions. Make header export a separate mode. --- diff --git a/ez-blob-compiler.c b/ez-blob-compiler.c index bf9b1f9..56f023c 100644 --- a/ez-blob-compiler.c +++ b/ez-blob-compiler.c @@ -49,7 +49,7 @@ static int doinline = 0; //static int doobstack = 1; static ez_elf *elf; -void export_size(const ez_blob_desc *desc, const char *name) { +static void export_size(const ez_blob_desc *desc, const char *name) { size_t size = 0; int strings = 0; @@ -118,7 +118,7 @@ void export_size(const ez_blob_desc *desc, const char *name) { printf("}\n"); } -void export_encode(const ez_blob_desc *desc, const char *name) { +static void export_encode(const ez_blob_desc *desc, const char *name) { printf("void %s_encode_raw(const void * __restrict p, ez_blob *blob) {\n", name); printf("\tchar * __restrict b = blob->eb_data;\n"); printf("\tconst char *s;\n"); @@ -170,7 +170,8 @@ void export_encode(const ez_blob_desc *desc, const char *name) { printf("}\n"); } -void export_decode(const ez_blob_desc *desc, const char *name, int doos) { +static void export_decode(const ez_blob_desc *desc, const char *name, int doos) { + fputs("\n", stdout); if (doos) { printf("void *%s_decode_os(const ez_blob * __restrict blob, struct obstack * __restrict os) {\n", name); printf("\tvoid *p = obstack_alloc(os, %u);\n", desc->bd_offset); @@ -235,10 +236,20 @@ void export_decode(const ez_blob_desc *desc, const char *name, int doos) { if (doos) printf("\treturn p;\n"); printf("}\n"); + + if (!doos) { + fputs("\n", stdout); + printf("void *%1$s_decode(const ez_blob *blob) {\n" + "\tvoid *p = calloc(1, %2$u);\n" + "\t%1$s_decode_raw(blob, p);\n" + "\treturn p;\n" + "}\n", + name, desc->bd_offset); + } } int main(int argc, char **argv) { - int gen = ~0; + int gen = 0; int header = 0; char *file = NULL; int tables = argc; @@ -270,12 +281,12 @@ int main(int argc, char **argv) { dogen |= 4; else if (strcmp(s, "decode_obstack") == 0) dogen |= 8; - else if (strcmp(s, "header") == 0) - header = 1; } if (dogen) gen = dogen; i += 1; + } else if (strcmp(cmd, "--header") == 0 || strcmp(cmd, "-h") == 0) { + header = 1; } else { file = cmd; tables = i + 1; @@ -361,8 +372,11 @@ int main(int argc, char **argv) { printf("size_t %s_size(const void *p);\n", xname); if (gen & 2) printf("void %s_encode_raw(const void *p, ez_blob *blob);\n", xname); - if (gen & 4) + if (gen & 4) { printf("void %s_decode_raw(const ez_blob *blob, void *p);\n", xname); + if ((gen & 8) == 0) + printf("void *%s_decode(const ez_blob *blob);\n", xname); + } if (gen & 8) printf("void *%s_decode_os(const ez_blob *blob, struct obstack *os);\n", xname); } else {