yes: Simplify, only support one argument
The previous code was too difficult to decipher for such a simple tool. Since yes(1) is not specified in any standard and several well-known implementations only support a single argument, do the same here. Thanks to everyone who offered implementation suggestions in the hackers@suckless.org email thread.
This commit is contained in:
parent
39f92650d3
commit
4f1d0df755
6
yes.1
6
yes.1
@ -3,12 +3,12 @@
|
|||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm yes
|
.Nm yes
|
||||||
.Nd output strings repeatedly
|
.Nd output string repeatedly
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Ar string ...
|
.Op Ar string
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
will repeatedly write 'y' or a line with each
|
will repeatedly write 'y' or
|
||||||
.Ar string
|
.Ar string
|
||||||
to stdout.
|
to stdout.
|
||||||
|
13
yes.c
13
yes.c
@ -6,23 +6,20 @@
|
|||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [string ...]\n", argv0);
|
eprintf("usage: %s [string]\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char **p;
|
const char *s;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND
|
} ARGEND
|
||||||
|
|
||||||
for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
|
s = argc ? argv[0] : "y";
|
||||||
fputs(*p ? *p : "y", stdout);
|
for (;;)
|
||||||
putchar((!*p || !*(p + 1)) ? '\n' : ' ');
|
puts(s);
|
||||||
}
|
|
||||||
|
|
||||||
return 1; /* not reached */
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user