Do not use arg.h for tools which take no flags

We've already seen the issue with echo(1): Before we changed it to
ignore "--", the command

$ echo --

did not work as expected. Given POSIX mandated this and makes most
sense, in the interest of consistency the other tools need to be
streamlined for that as well.
Looking at yes(1) for instance, there's no reason to skip "--" in
the argument list.
We do not have long options like GNU does and there's no reason to
tinker with that here.

The majority of tools changed are ones taking lists of arguments
or only a single one. There's no reason why dirname should "fail"
on "--". In the end, this is a valid name.

The practice of hand-holding the user was established with the GNU
coreutils. "--help" and "--version" long-options are a disgrace to
what could've been done properly with manpages.
This commit is contained in:
FRIGN 2015-04-24 23:54:17 +02:00 committed by sin
parent e73f58937d
commit 9016d288f1
16 changed files with 18 additions and 79 deletions

View File

@ -17,10 +17,7 @@ main(int argc, char *argv[])
ssize_t off; ssize_t off;
char *p; char *p;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc != 1 && argc != 2) if (argc != 1 && argc != 2)
usage(); usage();

View File

@ -17,10 +17,7 @@ main(int argc, char *argv[])
char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd; char *shell[] = { "/bin/sh", "-i", NULL }, *aux, *cmd;
int savederrno; int savederrno;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (!argc) if (!argc)
usage(); usage();

11
cksum.c
View File

@ -84,22 +84,13 @@ cksum(FILE *fp, const char *s)
putchar('\n'); putchar('\n');
} }
static void
usage(void)
{
eprintf("usage: %s [file ...]\n", argv0);
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
FILE *fp; FILE *fp;
int ret = 0; int ret = 0;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (!argc) { if (!argc) {
cksum(stdin, NULL); cksum(stdin, NULL);

View File

@ -13,10 +13,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc != 1) if (argc != 1)
usage(); usage();

4
echo.c
View File

@ -8,7 +8,9 @@ main(int argc, char *argv[])
{ {
int nflag = 0; int nflag = 0;
if (*++argv && !strcmp(*argv, "-n")) { argv0 = argv[0], argc--, argv++;
if (*argv && !strcmp(*argv, "-n")) {
nflag = 1; nflag = 1;
argc--, argv++; argc--, argv++;
} }

View File

@ -16,10 +16,7 @@ main(int argc, char *argv[])
{ {
char host[HOST_NAME_MAX + 1]; char host[HOST_NAME_MAX + 1];
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (!argc) { if (!argc) {
if (gethostname(host, sizeof(host)) < 0) if (gethostname(host, sizeof(host)) < 0)

5
link.c
View File

@ -12,10 +12,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc != 2) if (argc != 2)
usage(); usage();

View File

@ -19,10 +19,7 @@ main(int argc, char *argv[])
{ {
int fd, savederrno; int fd, savederrno;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (!argc) if (!argc)
usage(); usage();

View File

@ -6,22 +6,13 @@
extern char **environ; extern char **environ;
static void
usage(void)
{
eprintf("usage: %s [var ...]\n", argv0);
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *var; char *var;
int ret = 0; int ret = 0;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (!argc) { if (!argc) {
for (; *environ; environ++) for (; *environ; environ++)

View File

@ -15,10 +15,7 @@ main(int argc, char *argv[])
{ {
int savederrno; int savederrno;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (!argc) if (!argc)
usage(); usage();

View File

@ -14,10 +14,7 @@ main(int argc, char *argv[])
{ {
unsigned seconds; unsigned seconds;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc != 1) if (argc != 1)
usage(); usage();

View File

@ -15,10 +15,7 @@ main(int argc, char *argv[])
{ {
FILE *fp, *tmpfp; FILE *fp, *tmpfp;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc != 1) if (argc != 1)
usage(); usage();

5
sync.c
View File

@ -12,10 +12,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc) if (argc)
usage(); usage();

5
tty.c
View File

@ -15,10 +15,7 @@ main(int argc, char *argv[])
{ {
char *tty; char *tty;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc) if (argc)
usage(); usage();

View File

@ -12,10 +12,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
if (argc != 1) if (argc != 1)
usage(); usage();

11
yes.c
View File

@ -3,21 +3,12 @@
#include "util.h" #include "util.h"
static void
usage(void)
{
eprintf("usage: %s [string ...]\n", argv0);
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char **p; char **p;
ARGBEGIN { argv0 = argv[0], argc--, argv++;
default:
usage();
} ARGEND;
for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) { for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
fputs(*p ? *p : "y", stdout); fputs(*p ? *p : "y", stdout);