[hackers] [sbase] Finish up yes(1) by adding multiple string support || FRIGN

From: <git_AT_suckless.org>
Date: Sun, 1 Feb 2015 02:30:46 +0100 (CET)

commit 2cf7e9387a7a082a301f7f70c75045cde6f114d0
Author: FRIGN <dev_AT_frign.de>
Date: Sun Feb 1 02:13:47 2015 +0100

    Finish up yes(1) by adding multiple string support

diff --git a/README b/README
index cbf4929..e752242 100644
--- a/README
+++ b/README
_AT_@ -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
index f47e888..73240e1 100644
--- a/yes.1
+++ b/yes.1
_AT_@ -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
index 3652536..fe9af7f 100644
--- a/yes.c
+++ b/yes.c
_AT_@ -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 */
 }
Received on Sun Feb 01 2015 - 02:30:46 CET

This archive was generated by hypermail 2.3.0 : Sun Feb 01 2015 - 02:36:09 CET