summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generate_uudmap.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/generate_uudmap.c b/generate_uudmap.c
index 2c3e24a267..6159259add 100644
--- a/generate_uudmap.c
+++ b/generate_uudmap.c
@@ -12,17 +12,11 @@
"hello world" won't port easily to it. */
#include <errno.h>
-void output_block_to_file(const char *progname, const char *filename,
- const char *block, size_t count) {
- FILE *const out = fopen(filename, "w");
+static void
+format_char_block(FILE *out, const void *thing, size_t count) {
+ const char *block = (const char *)thing;
- if (!out) {
- fprintf(stderr, "%s: Could not open '%s': %s\n", progname, filename,
- strerror(errno));
- exit(1);
- }
-
- fputs("{\n ", out);
+ fputs(" ", out);
while (count--) {
fprintf(out, "%d", *block);
block++;
@@ -33,7 +27,24 @@ void output_block_to_file(const char *progname, const char *filename,
}
}
}
- fputs("\n}\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,
@@ -69,7 +80,8 @@ int main(int argc, char **argv) {
*/
PL_uudmap[(U8)' '] = 0;
- output_block_to_file(argv[0], argv[1], PL_uudmap, sizeof(PL_uudmap));
+ output_to_file(argv[0], argv[1], &format_char_block,
+ (const void *)PL_uudmap, sizeof(PL_uudmap));
for (bits = 1; bits < 256; bits++) {
if (bits & 1) PL_bitcount[bits]++;
@@ -82,9 +94,8 @@ int main(int argc, char **argv) {
if (bits & 128) PL_bitcount[bits]++;
}
- output_block_to_file(argv[0], argv[2], PL_bitcount, sizeof(PL_bitcount));
+ output_to_file(argv[0], argv[2], &format_char_block,
+ (const void *)PL_bitcount, sizeof(PL_bitcount));
return 0;
}
-
-