sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit fcb8821246fa6367b279b493f52f264a27cea44b
parent f3188246d860c858df22d3d734e7871b8919ead0
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Tue, 15 May 2012 13:32:56 +0100

revert to per-cmd usage()
Diffstat:
Mbasename.c | 12+++++++++---
Mcksum.c | 11++++++++---
Mkill.c | 14++++++--------
Mtest.c | 14++++++--------
Mutil.h | 1-
Mutil/eprintf.c | 7-------
Myes.c | 12+++++++++---
7 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/basename.c b/basename.c @@ -5,7 +5,7 @@ #include <string.h> #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 @@ -5,9 +5,8 @@ #include <unistd.h> #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 @@ -8,8 +8,6 @@ #include <sys/wait.h> #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 @@ -7,11 +7,9 @@ #include <sys/stat.h> #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 @@ -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 @@ -30,13 +30,6 @@ enprintf(int status, const char *fmt, ...) } 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) { /*fprintf(stderr, "%s: ", argv0);*/ diff --git a/yes.c b/yes.c @@ -3,7 +3,7 @@ #include <stdlib.h> #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); +}