Re: [hackers] [sbase] yes: Simplify, only support one argument || Michael Forney

2019-11-01 Thread Laslo Hunhold
On Fri, 1 Nov 2019 02:24:45 +0100 (CET)
g...@suckless.org wrote:

Dear Michael,

> 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.

even though I wrote the previous code for yes(1), after more thought I
completely agree with this path! Thanks for taking your time to rewrite
it! :)

With best regards

Laslo


pgpRvhtJyjHgV.pgp
Description: OpenPGP digital signature


Re: [hackers] [sbase] yes: Simplify, only support one argument || Michael Forney

2019-11-01 Thread Quentin Rameau
> yes: Simplify, only support one argument
> 
> The previous code was too difficult to decipher for such a simple tool.

Agreed!



[hackers] [sbase] yes: Simplify, only support one argument || Michael Forney

2019-10-31 Thread git
commit 4f1d0df755e6eb85630380c3e77f0584eedf0627
Author: Michael Forney 
AuthorDate: Thu Oct 31 18:07:58 2019 -0700
Commit: Michael Forney 
CommitDate: Thu Oct 31 18:14:18 2019 -0700

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.

diff --git a/yes.1 b/yes.1
index 87e390a..f3803ad 100644
--- a/yes.1
+++ b/yes.1
@@ -3,12 +3,12 @@
 .Os sbase
 .Sh NAME
 .Nm yes
-.Nd output strings repeatedly
+.Nd output string repeatedly
 .Sh SYNOPSIS
 .Nm
-.Op Ar string ...
+.Op Ar string
 .Sh DESCRIPTION
 .Nm
-will repeatedly write 'y' or a line with each
+will repeatedly write 'y' or
 .Ar string
 to stdout.
diff --git a/yes.c b/yes.c
index ffc77f0..b5c3c10 100644
--- a/yes.c
+++ b/yes.c
@@ -6,23 +6,20 @@
 static void
 usage(void)
 {
-   eprintf("usage: %s [string ...]\n", argv0);
+   eprintf("usage: %s [string]\n", argv0);
 }
 
 int
 main(int argc, char *argv[])
 {
-   char **p;
+   const char *s;
 
ARGBEGIN {
default:
usage();
} ARGEND
 
-   for (p = argv; ; p = (*p && *(p + 1)) ? p + 1 : argv) {
-   fputs(*p ? *p : "y", stdout);
-   putchar((!*p || !*(p + 1)) ? '\n' : ' ');
-   }
-
-   return 1; /* not reached */
+   s = argc ? argv[0] : "y";
+   for (;;)
+   puts(s);
 }