1 #include <ccan/cdump/cdump.h>
2 #include <ccan/tal/grab_file/grab_file.h>
3 #include <ccan/err/err.h>
5 static bool dump_map(const char *name, struct cdump_type *t, void *unused)
11 " const char *name;\n"
12 "} enum_%s_names[] = {\n", name, name);
14 for (i = 0; i < tal_count(t->u.enum_vals); i++)
15 printf(" { %s, \"%s\" },\n",
16 t->u.enum_vals[i].name,
17 t->u.enum_vals[i].name);
18 printf(" { 0, NULL } };\n");
22 int main(int argc, char *argv[])
24 char *code, *problems;
25 struct cdump_definitions *defs;
28 errx(1, "Usage: cdump-enumstr <filename> [<enums>...]");
30 code = grab_file(NULL, streq(argv[1], "-") ? NULL : argv[1]);
32 err(1, "Reading %s", argv[1]);
34 defs = cdump_extract(code, code, &problems);
36 errx(1, "Parsing %s:\n%s", argv[1], problems);
39 strmap_iterate(&defs->enums, dump_map, NULL);
44 for (i = 2; i < argc; i++) {
45 t = strmap_get(&defs->enums, argv[i]);
47 errx(1, "Enum %s not found", argv[i]);
48 dump_map(argv[i], t, NULL);