dj(1), intcmp(1), mm(1), npc(1), scrut(1), str(1): make usage function consistent

This commit is contained in:
dtb 2024-07-27 18:32:04 -06:00
parent 429d064209
commit 5d48114083
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B
6 changed files with 34 additions and 22 deletions

View File

@ -146,11 +146,13 @@ parse(char *s) {
} }
static int static int
usage(char *s) { usage(char *argv0) {
fprintf( (void)fprintf(
stderr, "Usage: %s [-Hn] [-a byte] [-c count]\n" stderr,
"Usage: %s [-Hn] [-a byte] [-c count]\n"
"\t[-i file] [-b block_size] [-s offset]\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; return EX_USAGE;

View File

@ -32,8 +32,9 @@
char *program_name = "intcmp"; char *program_name = "intcmp";
int usage(char *s) { static int
fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s); usage(char *argv0) {
(void)fprintf(stderr, "Usage: %s [-egl] integer integer...\n", argv0);
return EX_USAGE; return EX_USAGE;
} }

View File

@ -107,11 +107,13 @@ oserr(char *s, char *r) {
} \ } \
return retval return retval
/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and static int
* returns an exit status appropriate for a usage error. */ usage(char *argv0) {
int usage(char *s) { (void)fprintf(
stderr,
fprintf(stderr, "Usage: %s [-aenu] [-i input]... [-o output]...\n", s); "Usage: %s [-aenu] [-i input]... [-o output]...\n",
argv0
);
return EX_USAGE; return EX_USAGE;
} }

View File

@ -25,8 +25,10 @@
char *program_name = "npc"; char *program_name = "npc";
int usage(char *s) { static int
fprintf(stderr, "Usage: %s [-et]\n", s); usage(char *argv0) {
fprintf(stderr, "Usage: %s [-et]\n", argv0);
return EX_USAGE; return EX_USAGE;
} }

View File

@ -27,15 +27,18 @@
* S_ISUID, S_ISVTX */ * S_ISUID, S_ISVTX */
char *program_name = "scrut"; 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; return EX_USAGE;
} }
int main(int argc, char *argv[]) { 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]); program_name = (argv[0] == NULL ? program_name : argv[0]);
if (argc < 2) { return usage(program_name); } if (argc < 2) { return usage(program_name); }
@ -44,9 +47,9 @@ int main(int argc, char *argv[]) {
char *p; char *p;
memset(sel, '\0', sizeof sel); memset(sel, '\0', sizeof sel);
for (int c; (c = getopt(argc, argv, args)) != -1;) { for (int c; (c = getopt(argc, argv, opts)) != -1;) {
if ((p = strchr(args, c)) == NULL) { return usage(program_name); } if ((p = strchr(opts, c)) == NULL) { return usage(program_name); }
else { sel[p - args] = c; } else { sel[p - opts] = c; }
} }
/* straighten out selections; permute out nulls */ /* straighten out selections; permute out nulls */

View File

@ -45,8 +45,10 @@ static struct {
{ NULL, NULL } /* marks end */ { NULL, NULL } /* marks end */
}; };
int usage(char *s){ static int
fprintf(stderr, "Usage: %s type string...\n", s); usage(char *argv0){
(void)fprintf(stderr, "Usage: %s type string...\n", argv0);
return EX_USAGE; return EX_USAGE;
} }