"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++;
}
}
}
- 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,
*/
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]++;
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;
}
-
-