commit f40608ef09cf5d76a6043472bd1683786d452c8e
parent 27b770c02c3e936d12d3e0606e6ebf6c68b145e6
Author: FRIGN <dev@frign.de>
Date: Sun, 1 Feb 2015 02:13:47 +0100
Finish up yes(1) by adding multiple string support
Diffstat:
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/README b/README
@@ -84,7 +84,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
= sha512sum non-posix none
wc yes none
= 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
provides all the non-portable tools. Together they are intended to
diff --git a/yes.1 b/yes.1
@@ -1,12 +1,14 @@
-.Dd January 30, 2015
+.Dd January 31, 2015
.Dt YES 1
.Os sbase
.Sh NAME
.Nm yes
-.Nd output a string repeatedly
+.Nd output strings repeatedly
.Sh SYNOPSIS
.Nm
.Op Ar string ...
.Sh DESCRIPTION
.Nm
-will repeatedly output 'y' or the strings specified.
+will repeatedly write 'y' or a line with each
+.Ar string
+to stdout.
diff --git a/yes.c b/yes.c
@@ -7,18 +7,22 @@
static void
usage(void)
{
- eprintf("usage: %s [string]\n", argv0);
+ eprintf("usage: %s [string ...]\n", argv0);
}
int
main(int argc, char *argv[])
{
+ size_t i;
+
ARGBEGIN {
default:
usage();
} ARGEND;
- for (;;)
- puts(argc >= 1 ? argv[0] : "y");
+ for (i = 0; ;i++, i %= argc) {
+ printf("%s", (argc > 0) ? argv[i] : "y");
+ putchar((i == argc - 1) ? '\n' : ' ');
+ }
return 1; /* should not reach */
}