Finish up yes(1) by adding multiple string support
This commit is contained in:
parent
27b770c02c
commit
f40608ef09
2
README
2
README
|
@ -84,7 +84,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
||||||
= sha512sum non-posix none
|
= sha512sum non-posix none
|
||||||
wc yes none
|
wc yes none
|
||||||
= xargs no -I, -L, -p, -s, -t, -x
|
= xargs no -I, -L, -p, -s, -t, -x
|
||||||
= yes yes none
|
=* yes yes none
|
||||||
|
|
||||||
The complement of sbase is ubase[1] which is Linux-specific and
|
The complement of sbase is ubase[1] which is Linux-specific and
|
||||||
provides all the non-portable tools. Together they are intended to
|
provides all the non-portable tools. Together they are intended to
|
||||||
|
|
8
yes.1
8
yes.1
|
@ -1,12 +1,14 @@
|
||||||
.Dd January 30, 2015
|
.Dd January 31, 2015
|
||||||
.Dt YES 1
|
.Dt YES 1
|
||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm yes
|
.Nm yes
|
||||||
.Nd output a string repeatedly
|
.Nd output strings repeatedly
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Ar string ...
|
.Op Ar string ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
will repeatedly output 'y' or the strings specified.
|
will repeatedly write 'y' or a line with each
|
||||||
|
.Ar string
|
||||||
|
to stdout.
|
||||||
|
|
10
yes.c
10
yes.c
|
@ -7,18 +7,22 @@
|
||||||
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[])
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
for (;;)
|
for (i = 0; ;i++, i %= argc) {
|
||||||
puts(argc >= 1 ? argv[0] : "y");
|
printf("%s", (argc > 0) ? argv[i] : "y");
|
||||||
|
putchar((i == argc - 1) ? '\n' : ' ');
|
||||||
|
}
|
||||||
return 1; /* should not reach */
|
return 1; /* should not reach */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user