1 /* Originally this program just generated uudmap.h
2 However, when we later wanted to generate bitcount.h, it was easier to
3 refactor it and keep the same name, than either alternative - rename it,
4 or duplicate all of the Makefile logic for a second program. */
8 /* If it turns out that we need to make this conditional on config.sh derived
9 values, it might be easier just to rip out the use of strerrer(). */
11 /* If a platform doesn't support errno.h, it's probably so strange that
12 "hello world" won't port easily to it. */
15 struct mg_data_raw_t {
21 static struct mg_data_raw_t mg_data_raw[] = {
23 # include "..\mg_raw.h"
35 static struct mg_data_t mg_data[256];
38 format_mg_data(FILE *out, const void *thing, size_t count) {
39 const struct mg_data_t *p = (const struct mg_data_t *)thing;
43 fprintf(out, " %s\n %s", p->comment, p->value);
56 format_char_block(FILE *out, const void *thing, size_t count) {
57 const char *block = (const char *)thing;
61 fprintf(out, "%d", *block);
74 output_to_file(const char *progname, const char *filename,
75 void (format_function)(FILE *out, const void *thing, size_t count),
76 const void *thing, size_t count) {
77 FILE *const out = fopen(filename, "w");
80 fprintf(stderr, "%s: Could not open '%s': %s\n", progname, filename,
86 format_function(out, thing, count);
90 fprintf(stderr, "%s: Could not close '%s': %s\n", progname, filename,
97 static const char PL_uuemap[]
98 = "`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
100 typedef unsigned char U8;
102 /* This will ensure it is initialized to all zeros. */
103 static char PL_uudmap[256];
104 static char PL_bitcount[256];
106 int main(int argc, char **argv) {
109 struct mg_data_raw_t *p = mg_data_raw;
111 if (argc < 4 || argv[1][0] == '\0' || argv[2][0] == '\0'
112 || argv[3][0] == '\0') {
113 fprintf(stderr, "Usage: %s uudemap.h bitcount.h mg_data.h\n", argv[0]);
117 for (i = 0; i < sizeof(PL_uuemap) - 1; ++i)
118 PL_uudmap[(U8)PL_uuemap[i]] = (char)i;
120 * Because ' ' and '`' map to the same value,
121 * we need to decode them both the same.
123 PL_uudmap[(U8)' '] = 0;
125 output_to_file(argv[0], argv[1], &format_char_block,
126 (const void *)PL_uudmap, sizeof(PL_uudmap));
128 for (bits = 1; bits < 256; bits++) {
129 if (bits & 1) PL_bitcount[bits]++;
130 if (bits & 2) PL_bitcount[bits]++;
131 if (bits & 4) PL_bitcount[bits]++;
132 if (bits & 8) PL_bitcount[bits]++;
133 if (bits & 16) PL_bitcount[bits]++;
134 if (bits & 32) PL_bitcount[bits]++;
135 if (bits & 64) PL_bitcount[bits]++;
136 if (bits & 128) PL_bitcount[bits]++;
139 output_to_file(argv[0], argv[2], &format_char_block,
140 (const void *)PL_bitcount, sizeof(PL_bitcount));
143 mg_data[p->type].value = p->value;
144 mg_data[p->type].comment = p->comment;
148 output_to_file(argv[0], argv[3], &format_mg_data,
149 (const void *)mg_data, sizeof(mg_data)/sizeof(mg_data[0]));