Compare commits

..

No commits in common. "5d481140835ed94e263d3921c9418b4a43059d12" and "cba8394d95a76c75801681b929640788ee9f90b3" have entirely different histories.

6 changed files with 26 additions and 36 deletions

View File

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

View File

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

View File

@ -26,6 +26,8 @@
#include <unistd.h> /* getopt(3) */ #include <unistd.h> /* getopt(3) */
#include <sysexits.h> /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */ #include <sysexits.h> /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */
extern int errno;
/* This structure is how open files are tracked. */ /* This structure is how open files are tracked. */
struct Files{ struct Files{
size_t a; /* allocation */ size_t a; /* allocation */
@ -107,13 +109,11 @@ oserr(char *s, char *r) {
} \ } \
return retval return retval
static int /* Prints a usage text, in which s is the program being run (i.e. argv[0]), and
usage(char *argv0) { * returns an exit status appropriate for a usage error. */
(void)fprintf( int usage(char *s) {
stderr,
"Usage: %s [-aenu] [-i input]... [-o output]...\n", fprintf(stderr, "Usage: %s [-aenu] [-i input]... [-o output]...\n", s);
argv0
);
return EX_USAGE; return EX_USAGE;
} }
@ -149,9 +149,9 @@ int main(int argc, char *argv[]) {
k = 0; k = 0;
if (argc > 0) { if (argc > 0) { program_name = argv[0]; }
program_name = argv[0];
if (argc > 1) {
while ((c = getopt(argc, argv, "aehi:no:u")) != -1) { while ((c = getopt(argc, argv, "aehi:no:u")) != -1) {
switch (c){ switch (c){
case 'a': /* "rb+" -> "ab" */ case 'a': /* "rb+" -> "ab" */

View File

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

View File

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

View File

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