revert to per-cmd usage()

This commit is contained in:
Connor Lane Smith 2012-05-15 13:32:56 +01:00
parent f3188246d8
commit fcb8821246
7 changed files with 38 additions and 33 deletions

View File

@ -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);
}

11
cksum.c
View File

@ -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);
}

12
kill.c
View File

@ -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"
eprintf("usage: %s [-s signal] [pid...]\n"
" %s -l [signum]\n", argv0, argv0);
}

14
test.c
View File

@ -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 == '[') ? " ]" : "";

1
util.h
View File

@ -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 *);

View File

@ -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)
{

12
yes.c
View File

@ -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);
}