//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;
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");
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);
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;
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;
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 {