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 void output_block_to_file(const char *progname, const char *filename,
16 const char *block, size_t count) {
17 FILE *const out = fopen(filename, "w");
20 fprintf(stderr, "%s: Could not open '%s': %s\n", progname, filename,
27 fprintf(out, "%d", *block);
39 fprintf(stderr, "%s: Could not close '%s': %s\n", progname, filename,
46 static const char PL_uuemap[]
47 = "`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
49 typedef unsigned char U8;
51 /* This will ensure it is all zeros. */
52 static char PL_uudmap[256];
53 static char PL_bitcount[256];
55 int main(int argc, char **argv) {
59 if (argc < 3 || argv[1][0] == '\0' || argv[2][0] == '\0') {
60 fprintf(stderr, "Usage: %s uudemap.h bitcount.h\n", argv[0]);
64 for (i = 0; i < sizeof(PL_uuemap) - 1; ++i)
65 PL_uudmap[(U8)PL_uuemap[i]] = (char)i;
67 * Because ' ' and '`' map to the same value,
68 * we need to decode them both the same.
70 PL_uudmap[(U8)' '] = 0;
72 output_block_to_file(argv[0], argv[1], PL_uudmap, sizeof(PL_uudmap));
74 for (bits = 1; bits < 256; bits++) {
75 if (bits & 1) PL_bitcount[bits]++;
76 if (bits & 2) PL_bitcount[bits]++;
77 if (bits & 4) PL_bitcount[bits]++;
78 if (bits & 8) PL_bitcount[bits]++;
79 if (bits & 16) PL_bitcount[bits]++;
80 if (bits & 32) PL_bitcount[bits]++;
81 if (bits & 64) PL_bitcount[bits]++;
82 if (bits & 128) PL_bitcount[bits]++;
85 output_block_to_file(argv[0], argv[2], PL_bitcount, sizeof(PL_bitcount));