+struct mg_data_raw_t {
+ unsigned char type;
+ const char *value;
+ const char *comment;
+};
+
+static struct mg_data_raw_t mg_data_raw[] = {
+#ifdef WIN32
+# include "..\mg_raw.h"
+#else
+# include "mg_raw.h"
+#endif
+ {0, 0, 0}
+};
+
+struct mg_data_t {
+ const char *value;
+ const char *comment;
+};
+
+static struct mg_data_t mg_data[256];
+
+static void
+format_mg_data(FILE *out, const void *thing, size_t count) {
+ const struct mg_data_t *p = (const struct mg_data_t *)thing;
+
+ while (1) {
+ if (p->value) {
+ fprintf(out, " %s\n %s", p->comment, p->value);
+ } else {
+ fputs(" 0", out);
+ }
+ ++p;
+ if (!--count)
+ break;
+ fputs(",\n", out);
+ }
+ fputc('\n', out);
+}
+
+static void
+format_char_block(FILE *out, const void *thing, size_t count) {
+ const char *block = (const char *)thing;
+
+ fputs(" ", out);
+ while (count--) {
+ fprintf(out, "%d", *block);
+ block++;
+ if (count) {
+ fputs(", ", out);
+ if (!(count & 15)) {
+ fputs("\n ", out);
+ }
+ }
+ }
+ fputc('\n', out);
+}
+
+static void
+output_to_file(const char *progname, const char *filename,
+ void (format_function)(FILE *out, const void *thing, size_t count),
+ const void *thing, size_t count) {
+ FILE *const out = fopen(filename, "w");
+
+ if (!out) {
+ fprintf(stderr, "%s: Could not open '%s': %s\n", progname, filename,
+ strerror(errno));
+ exit(1);
+ }
+
+ fputs("{\n", out);
+ format_function(out, thing, count);
+ fputs("}\n", out);
+
+ if (fclose(out)) {
+ fprintf(stderr, "%s: Could not close '%s': %s\n", progname, filename,
+ strerror(errno));
+ exit(1);
+ }
+}
+
+