diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-05-19 13:49:07 +0200 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-05-19 13:49:07 +0200 |
commit | 2b1d1392b607905ceba6df972064ea1ea6777ba8 (patch) | |
tree | 674cb02015cefe598efc7769b017f01869cf2dd6 /generate_uudmap.c | |
parent | d85f917eae8ded4d020f0addd35e5aa488f2c0c0 (diff) | |
download | perl-2b1d1392b607905ceba6df972064ea1ea6777ba8.tar.gz |
Pass the output file name to generate_uudmap, and open it within the code,
instead of having the calling Makefile redirect stdout.
Diffstat (limited to 'generate_uudmap.c')
-rw-r--r-- | generate_uudmap.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/generate_uudmap.c b/generate_uudmap.c index 28cfd274ee..31aba75d86 100644 --- a/generate_uudmap.c +++ b/generate_uudmap.c @@ -1,5 +1,11 @@ #include <stdio.h> #include <stdlib.h> +/* If it turns out that we need to make this conditional on config.sh derived + values, it might be easier just to rip out the use of strerrer(). */ +#include <string.h> +/* If a platform doesn't support errno.h, it's probably so strange that + "hello world" won't port easily to it. */ +#include <errno.h> static const char PL_uuemap[] = "`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"; @@ -9,9 +15,21 @@ typedef unsigned char U8; /* This will ensure it is all zeros. */ static char PL_uudmap[256]; -int main() { +int main(int argc, char **argv) { size_t i; char *p; + FILE *uudmap_out; + + if (argc < 2 || argv[1][0] == '\0') { + fprintf(stderr, "Usage: %s uudemap.h\n", argv[0]); + return 1; + } + + if (!(uudmap_out = fopen(argv[1], "w"))) { + fprintf(stderr, "%s: Could not open '%s': %s\n", argv[0], argv[1], + strerror(errno)); + return 1; + } for (i = 0; i < sizeof(PL_uuemap) - 1; ++i) PL_uudmap[(U8)PL_uuemap[i]] = (char)i; @@ -24,18 +42,24 @@ int main() { i = sizeof(PL_uudmap); p = PL_uudmap; - fputs("{\n ", stdout); + fputs("{\n ", uudmap_out); while (i--) { - printf("%d", *p); + fprintf(uudmap_out, "%d", *p); p++; if (i) { - fputs(", ", stdout); + fputs(", ", uudmap_out); if (!(i & 15)) { - fputs("\n ", stdout); + fputs("\n ", uudmap_out); } } } - puts("\n}"); + fputs("\n}\n", uudmap_out); + + if (fclose(uudmap_out)) { + fprintf(stderr, "%s: Could not close '%s': %s\n", argv[0], argv[1], + strerror(errno)); + return 1; + } return 0; } |