On Fri, 28 Jun 2019 01:06:56 -0700
Michael Forney <[email protected]> wrote:

Dear Michael,

thanks for your quick feedback!

> I think we are all on the same page here about simplifying yes(1)
> rather than optimizing it. See aidanwillie0317's most recent patch.

> (I think you mean "space separated" here)

Yes, my bad. Sorry.

> How did you determine this consensus? All the BSD implementations I
> looked at (OpenBSD, FreeBSD, NetBSD) only support a single argument.
> 
> Do you have any examples of scripts relying on this behavior of
> yes(1)?

No, I do not. However, the "sad" truth is that the GNU coreutils are
used the most and they allow an arbitrary number of arguments. To be
honest, allowing more than one argument is not a limitation, so we
should just keep the behaviour.

> This will end up printing an extra space before the newline.

Oh yes, I missed that! Find a fixed patch attached.

> This looks pretty good to me. If we decide to support any number of
> operands, this seems like the way to do it.

Thanks! Yeah, let's see how the others see it. I would vote for the
arbitrary amount of operands. There's no need to limit a tool
artificially. This maxime was also decicive for many other tools in
sbase (see the -d flag for cut(1) for instance).

With best regards

Laslo

-- 
Laslo Hunhold <[email protected]>
>From 1804251e3c4a1ca9bd343e73465a1acfa58b71e4 Mon Sep 17 00:00:00 2001
From: Laslo Hunhold <[email protected]>
Date: Fri, 28 Jun 2019 08:56:10 +0200
Subject: [PATCH] Improve yes(1) readability

The code was terse, but at the cost of readability. Relax the loop
a bit, separate the main check instead of doing it with ternary
operators within the loop.

Signed-off-by: Laslo Hunhold <[email protected]>
---
 yes.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/yes.c b/yes.c
index dd97ea6..ce0fd64 100644
--- a/yes.c
+++ b/yes.c
@@ -6,13 +6,24 @@
 int
 main(int argc, char *argv[])
 {
-	char **p;
+	int i;
 
 	argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;
 
-	for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
-		fputs(*p ? *p : "y", stdout);
-		putchar((!*p || !*(p + 1)) ? '\n' : ' ');
+	if (argc == 0) {
+		for (;;) {
+			fputs("y\n", stdout);
+		}
+	} else {
+		for (;;) {
+			for (i = 0; i < argc; i++) {
+				fputs(argv[i], stdout);
+				if (i + 1 < argc) {
+					fputc(' ', stdout);
+				}
+			}
+			fputc('\n', stdout);
+		}
 	}
 
 	return 1; /* not reached */
-- 
2.22.0

Attachment: pgpI34CWShBUI.pgp
Description: PGP signature

Reply via email to