From 5fe2bcbeedea32b137a26d50a2fd91cee3fc03cb Mon Sep 17 00:00:00 2001 From: bentley Date: Tue, 12 Jan 2010 19:44:21 -0700 Subject: [PATCH] use errx(3) and warnx(3) instead of rolling our own error functions --- src/fix/main.c | 60 ++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 46 deletions(-) diff --git a/src/fix/main.c b/src/fix/main.c index ec8c4171..b170a2fe 100644 --- a/src/fix/main.c +++ b/src/fix/main.c @@ -3,10 +3,13 @@ * */ +#include +#include #include #include -#include #include +#include + #include "asmotor.h" /* @@ -58,41 +61,6 @@ PrintUsage(void) exit(1); } -void -vFatalError(char *s, va_list ap) -{ - fprintf(stderr, "*ERROR* : "); - vfprintf(stderr, s, ap); - fprintf(stderr, "\n"); -} - -void -FatalError(char *s,...) -{ - va_list ap; - va_start(ap, s); - vFatalError(s, ap); - va_end(ap); - exit(5); -} - -void -vWarning(char *s, va_list ap) -{ - fprintf(stderr, "*WARNING* : "); - vfprintf(stderr, s, ap); - fprintf(stderr, "\n"); -} - -void -Warning(char *s,...) -{ - va_list ap; - va_start(ap, s); - vWarning(s, ap); - va_end(ap); -} - long int FileSize(FILE * f) { @@ -230,9 +198,9 @@ main(int argc, char *argv[]) ulOptions |= OPTF_RAMSIZE; ram_size = strtoul(optarg, &ep, 0); if (optarg[0] == '\0' || *ep != '\0') - FatalError("Invalid argument for option 'm'"); + errx(EX_USAGE, "Invalid argument for option 'm'"); if (ram_size < 0 || ram_size > 0xFF) - FatalError("Argument for option 'm' must be between 0 and 0xFF"); + errx(EX_USAGE, "Argument for option 'm' must be between 0 and 0xFF"); break; case 'j': ulOptions |= OPTF_JAPAN; @@ -241,17 +209,17 @@ main(int argc, char *argv[]) ulOptions |= OPTF_MBCTYPE; mbc_type = strtoul(optarg, &ep, 0); if (optarg[0] == '\0' || *ep != '\0') - FatalError("Invalid argument for option 'b'"); + errx(EX_USAGE, "Invalid argument for option 'b'"); if (mbc_type < 0 || mbc_type > 0xFF) - FatalError("Argument for option 'b' must be between 0 and 0xFF"); + errx(EX_USAGE, "Argument for option 'b' must be between 0 and 0xFF"); break; case 'p': ulOptions |= OPTF_PAD; pad_value = strtoul(optarg, &ep, 0); if (optarg[0] == '\0' || *ep != '\0') - FatalError("Invalid argument for option 'p'"); + errx(EX_USAGE, "Invalid argument for option 'p'"); if (pad_value < 0 || pad_value > 0xFF) - FatalError("Argument for option 'p' must be between 0 and 0xFF"); + errx(EX_USAGE, "Argument for option 'p' must be between 0 and 0xFF"); break; case 'v': ulOptions |= OPTF_VALIDATE; @@ -269,14 +237,14 @@ main(int argc, char *argv[]) break; case 'o': if (ulOptions & OPTF_GBCMODE) { - FatalError("-c and -o can't be used together"); + errx(EX_USAGE, "-c and -o can't be used together"); } ulOptions |= OPTF_GBCMODE; gbc_mode = 0xC0; break; case 'c': if (ulOptions & OPTF_GBCMODE) { - FatalError("-c and -o can't be used together"); + errx(EX_USAGE, "-c and -o can't be used together"); } ulOptions |= OPTF_GBCMODE; gbc_mode = 0x80; @@ -468,7 +436,7 @@ main(int argc, char *argv[]) if (ulOptions & OPTF_TITLE) { if (cartname[0xF]) { - Warning("Last character of cartridge title was overwritten by '-%c' option", gbc_mode == 0x80 ? 'c' : 'o'); + warnx("Last character of cartridge title was overwritten by '-%c' option", gbc_mode == 0x80 ? 'c' : 'o'); } } } @@ -674,7 +642,7 @@ main(int argc, char *argv[]) } fclose(f); } else { - FatalError("File '%s' not found", filename); + errx(EX_NOINPUT, "File '%s' not found", filename); } return (0);