From fcb8821246fa6367b279b493f52f264a27cea44b Mon Sep 17 00:00:00 2001 From: Connor Lane Smith Date: Tue, 15 May 2012 13:32:56 +0100 Subject: [PATCH] revert to per-cmd usage() --- basename.c | 12 +++++++++--- cksum.c | 11 ++++++++--- kill.c | 14 ++++++-------- test.c | 14 ++++++-------- util.h | 1 - util/eprintf.c | 7 ------- yes.c | 12 +++++++++--- 7 files changed, 38 insertions(+), 33 deletions(-) diff --git a/basename.c b/basename.c index 48c9289..db51ce1 100644 --- a/basename.c +++ b/basename.c @@ -5,7 +5,7 @@ #include #include "util.h" -#define USAGE() usage("name [suffix]") +static void usage(void); int main(int argc, char *argv[]) @@ -15,11 +15,11 @@ main(int argc, char *argv[]) ARGBEGIN { default: - USAGE(); + usage(); } ARGEND; if(argc < 1) - USAGE(); + usage(); s = basename(argv[0]); if(argc == 2 && argv[1]) { @@ -31,3 +31,9 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } + +void +usage(void) +{ + eprintf("usage: %s name [suffix]\n", argv0); +} diff --git a/cksum.c b/cksum.c index 548e913..efe241b 100644 --- a/cksum.c +++ b/cksum.c @@ -5,9 +5,8 @@ #include #include "util.h" -#define USAGE() usage("[files...]") - static void cksum(int, const char *); +static void usage(void); static const unsigned long crctab[] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, @@ -70,7 +69,7 @@ main(int argc, char *argv[]) ARGBEGIN { default: - USAGE(); + usage(); } ARGEND; if(argc == 0) @@ -106,3 +105,9 @@ cksum(int fd, const char *s) printf(" %s", s); putchar('\n'); } + +void +usage(void) +{ + eprintf("usage: %s [files...]\n", argv0); +} diff --git a/kill.c b/kill.c index 6994a29..00eda66 100644 --- a/kill.c +++ b/kill.c @@ -8,8 +8,6 @@ #include #include "util.h" -#define USAGE() killusage() - struct { const char *name; int sig; @@ -21,7 +19,7 @@ struct { #undef SIG }; -static void killusage(void); +static void usage(void); int main(int argc, char *argv[]) @@ -50,10 +48,10 @@ main(int argc, char *argv[]) eprintf("%s: unknown signal\n", optarg); break; default: - USAGE(); + usage(); } if(optind < argc-1) - USAGE(); + usage(); if(lflag) { sig = (optind == argc) ? 0 : estrtol(argv[optind], 0); @@ -73,8 +71,8 @@ main(int argc, char *argv[]) } void -killusage(void) +usage(void) { - fprintf(stderr, "usage: %s [-s signal] [pid...]\n" - " %s -l [signum]\n", argv0, argv0); + eprintf("usage: %s [-s signal] [pid...]\n" + " %s -l [signum]\n", argv0, argv0); } diff --git a/test.c b/test.c index bb78fd9..e54a0d3 100644 --- a/test.c +++ b/test.c @@ -7,11 +7,9 @@ #include #include "util.h" -#define USAGE() testusage() - static bool unary(const char *, const char *); static bool binary(const char *, const char *, const char *); -static void testusage(void); +static void usage(void); int main(int argc, char *argv[]) @@ -23,7 +21,7 @@ main(int argc, char *argv[]) /* [ ... ] alias */ if(!strcmp(argv[0], "[")) { if(strcmp(argv[argc-1], "]") != 0) - USAGE(); + usage(); argc--; } if(argc > 1 && !strcmp(argv[1], "!")) { @@ -42,7 +40,7 @@ main(int argc, char *argv[]) ret = binary(argv[1], argv[2], argv[3]); break; default: - USAGE(); + usage(); } if(not) ret = !ret; @@ -56,7 +54,7 @@ unary(const char *op, const char *arg) int r; if(op[0] != '-' || op[1] == '\0' || op[2] != '\0') - USAGE(); + usage(); switch(op[1]) { case 'b': case 'c': case 'd': case 'f': case 'g': case 'p': case 'S': case 's': case 'u': @@ -99,7 +97,7 @@ unary(const char *op, const char *arg) case 'z': return arg[0] == '\0'; default: - USAGE(); + usage(); } return false; /* should not reach */ } @@ -112,7 +110,7 @@ binary(const char *arg1, const char *op, const char *arg2) } void -testusage(void) +usage(void) { const char *ket = (*argv0 == '[') ? " ]" : ""; diff --git a/util.h b/util.h index 7589314..c7d3a28 100644 --- a/util.h +++ b/util.h @@ -40,4 +40,3 @@ long estrtol(const char *, int); void fnck(const char *, const char *, int (*)(const char *, const char *)); void putword(const char *); void recurse(const char *, void (*)(const char *)); -void usage(const char *); diff --git a/util/eprintf.c b/util/eprintf.c index 8617091..fc651d7 100644 --- a/util/eprintf.c +++ b/util/eprintf.c @@ -29,13 +29,6 @@ enprintf(int status, const char *fmt, ...) va_end(ap); } -void -usage(const char *s) -{ - fprintf(stderr, "usage: %s %s\n", argv0, s); - exit(EXIT_FAILURE); -} - void venprintf(int status, const char *fmt, va_list ap) { diff --git a/yes.c b/yes.c index 3719e41..a55a022 100644 --- a/yes.c +++ b/yes.c @@ -3,7 +3,7 @@ #include #include "util.h" -#define USAGE() usage("[string]") +static void usage(void); int main(int argc, char *argv[]) @@ -12,7 +12,7 @@ main(int argc, char *argv[]) ARGBEGIN { default: - USAGE(); + usage(); } ARGEND; switch(argc) { @@ -24,7 +24,13 @@ main(int argc, char *argv[]) puts(s); break; default: - USAGE(); + usage(); } return EXIT_FAILURE; /* should not reach */ } + +void +usage(void) +{ + eprintf("usage: %s [string]\n", argv0); +}