dj(1), intcmp(1), mm(1), npc(1), scrut(1), str(1): make usage function consistent
This commit is contained in:
parent
429d064209
commit
5d48114083
10
src/dj.c
10
src/dj.c
@ -146,11 +146,13 @@ parse(char *s) {
|
||||
}
|
||||
|
||||
static int
|
||||
usage(char *s) {
|
||||
fprintf(
|
||||
stderr, "Usage: %s [-Hn] [-a byte] [-c count]\n"
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(
|
||||
stderr,
|
||||
"Usage: %s [-Hn] [-a byte] [-c count]\n"
|
||||
"\t[-i file] [-b block_size] [-s offset]\n"
|
||||
"\t[-o file] [-B block_size] [-S offset]\n", s
|
||||
"\t[-o file] [-B block_size] [-S offset]\n",
|
||||
argv0
|
||||
);
|
||||
|
||||
return EX_USAGE;
|
||||
|
@ -32,8 +32,9 @@
|
||||
|
||||
char *program_name = "intcmp";
|
||||
|
||||
int usage(char *s) {
|
||||
fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s);
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(stderr, "Usage: %s [-egl] integer integer...\n", argv0);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
12
src/mm.c
12
src/mm.c
@ -107,11 +107,13 @@ oserr(char *s, char *r) {
|
||||
} \
|
||||
return retval
|
||||
|
||||
/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and
|
||||
* returns an exit status appropriate for a usage error. */
|
||||
int usage(char *s) {
|
||||
|
||||
fprintf(stderr, "Usage: %s [-aenu] [-i input]... [-o output]...\n", s);
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(
|
||||
stderr,
|
||||
"Usage: %s [-aenu] [-i input]... [-o output]...\n",
|
||||
argv0
|
||||
);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
@ -25,8 +25,10 @@
|
||||
|
||||
char *program_name = "npc";
|
||||
|
||||
int usage(char *s) {
|
||||
fprintf(stderr, "Usage: %s [-et]\n", s);
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
fprintf(stderr, "Usage: %s [-et]\n", argv0);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
|
17
src/scrut.c
17
src/scrut.c
@ -27,15 +27,18 @@
|
||||
* S_ISUID, S_ISVTX */
|
||||
|
||||
char *program_name = "scrut";
|
||||
static char args[] = "bcdefgkprsuwxLS";
|
||||
#define OPTS "bcdefgkprsuwxLS"
|
||||
static char *opts = OPTS;
|
||||
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(stderr, "Usage: %s [-" OPTS "] file...\n", argv0);
|
||||
|
||||
int usage(char *s) {
|
||||
fprintf(stderr, "Usage: %s [-%s] file...\n", s, args);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char sel[(sizeof args) / (sizeof *args)];
|
||||
char sel[(sizeof opts) / (sizeof *opts)];
|
||||
program_name = (argv[0] == NULL ? program_name : argv[0]);
|
||||
|
||||
if (argc < 2) { return usage(program_name); }
|
||||
@ -44,9 +47,9 @@ int main(int argc, char *argv[]) {
|
||||
char *p;
|
||||
|
||||
memset(sel, '\0', sizeof sel);
|
||||
for (int c; (c = getopt(argc, argv, args)) != -1;) {
|
||||
if ((p = strchr(args, c)) == NULL) { return usage(program_name); }
|
||||
else { sel[p - args] = c; }
|
||||
for (int c; (c = getopt(argc, argv, opts)) != -1;) {
|
||||
if ((p = strchr(opts, c)) == NULL) { return usage(program_name); }
|
||||
else { sel[p - opts] = c; }
|
||||
}
|
||||
|
||||
/* straighten out selections; permute out nulls */
|
||||
|
Loading…
Reference in New Issue
Block a user