[Toybox] [PATCH] Make it easier to switch regex implementations.

2020-10-28 Thread enh via Toybox
One reason to use toybox on the host is to get the same behavior across
Android/Linux/macOS. Unfortunately (as we've seen from a few bugs) one
area where that doesn't quite work is that toybox uses the libc regular
expression implementation. That's fine, and mostly what users want, but
those folks trying to get the exact same behavior everywhere might want
to switch in a known regex implementation (bionic's NetBSD regex
implementation, say) for increased consistency.

That actually works pretty well, but portability.h has an #ifndef test
for REG_STARTEND before including  that gets in the way. To
make up for that, this patch removes the unnecessary #include 
from grep.c itself.
---
 lib/portability.h | 1 +
 toys/posix/grep.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
From a9a1734cab78f5a44e8c098b1b4f21ffe5ec58dd Mon Sep 17 00:00:00 2001
From: Elliott Hughes 
Date: Wed, 28 Oct 2020 16:48:14 -0700
Subject: [PATCH] Make it easier to switch regex implementations.

One reason to use toybox on the host is to get the same behavior across
Android/Linux/macOS. Unfortunately (as we've seen from a few bugs) one
area where that doesn't quite work is that toybox uses the libc regular
expression implementation. That's fine, and mostly what users want, but
those folks trying to get the exact same behavior everywhere might want
to switch in a known regex implementation (bionic's NetBSD regex
implementation, say) for increased consistency.

That actually works pretty well, but portability.h has an #ifndef test
for REG_STARTEND before including  that gets in the way. To
make up for that, this patch removes the unnecessary #include 
from grep.c itself.
---
 lib/portability.h | 1 +
 toys/posix/grep.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/portability.h b/lib/portability.h
index acc32fd4..05a449ee 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -6,6 +6,7 @@
 
 // For musl
 #define _ALL_SOURCE
+#include 
 #ifndef REG_STARTEND
 #define REG_STARTEND 0
 #endif
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 1fa1a7c4..9f445fca 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -65,7 +65,6 @@ config FGREP
 
 #define FOR_grep
 #include "toys.h"
-#include 
 
 GLOBALS(
   long m, A, B, C;
-- 
2.29.1.341.ge80a0c044ae-goog

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] toys.h: remove unused declaration.

2020-10-28 Thread enh via Toybox
On Wed, Oct 28, 2020 at 2:26 PM Rob Landley  wrote:
>
> On 10/28/20 10:47 AM, enh wrote:
> > yeah, i don't have any particular use for it myself, but i accept the
> > "behave more like the thing you're replacing" argument and i don't see
> > any problem that patch would cause, so "lgtm".
>
> It's an optimization problem that I'm not the target audience for. Tricksy.

yeah, same here. i didn't even know (before the bug reports/feature
requests came in), for example, that not everyone knows what "-" and
"--" usually mean.

> > mostly off topic, but personally i'd like to surface the "generally
> > applicable but not widely known and kind of annoying if we repeat it
> > everywhere it's relevant" stuff from --help:
> > ```
> > The filename "-" means stdin/stdout, and "--" stops argument parsing.
> >
> > Numerical arguments accept a single letter suffix for
> > kilo, mega, giga, tera, peta, and exabytes, plus an additional
> > "d" to indicate decimal 1000's instead of 1024.
> >
> > Durations can be decimal fractions and accept minute ("m"), hour ("h"),
> > or day ("d") suffixes (so 0.1m = 6s).
> > ```
> > but that shouldn't get in the way of this patch.
>
> Yup. It's in the toybox --help because I wanted to document it somewhere, but 
> am
> not sure how to point people at it...

like i said, although i personally think this is a more interesting
problem, i don't think it should get in the way of submitting your
current patch which solves _a_ problem others are having :-)

> > the args parser knows whether there are numerical arguments so it
> > could automatically append the bit about suffixes everywhere it's
> > relevant, but the durations stuff isn't known, nor is whether any
> > argument is a filename. and, sadly, i've been surprised by the number
> > of people who don't know about `--` but would feel weird adding that
> > everywhere. i did wonder about having "Try `toybox --help` for general
> > information about arguments." automatically appended everywhere but i
> > don't actually know whether anyone who doesn't know the stuff above
> > would actually look, so i haven't suggested it. (until now.)
>
> Ok. Um. Hmmm. How about:
>
>   Toybox 0.8.4 multicall binary: https://landley.net/toybox (toybox --help)

i think part of the problem is that people don't know there's more
about argument parsing that they don't know, and much of `toybox
--help` is about installation and the like anyway. i also have strong
anecdata that people read man7.org more than they read any of toybox's
--help output anyway :-/

as i may have already said, i'm not sure _this_ problem even has a solution!

> And then I can change the top level toybox page from news.html to about.html
> except... looking at the about page again it's all FAQ entries, isn't it? I
> should just put an "about" section at the start of the FAQ, but although I can
> symlink index.html to any of the other pages I can't easily make it jump to an
> #anchor tag so it's not quite equivalent...
>
> While I'm at it I also need to collate the "general questions" to the end of 
> the
> FAQ. Things like "why time based releases" and "will you backport old 
> versions"
> are generic open source project questions, not really toybox specific. (In 
> fact
> the second one I originally wrote for busybox, but after I left they made it
> busybox-specific and thus a less useful general answer to the question. In
> https://busybox.net/FAQ.html#backporting everything from "if you don't want to
> take the risk" to right before "the volunteers are happy" was not part of 
> what I
> originally wrote. One of my motivations for doing a new FAQ...)
>
> Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] toys.h: remove unused declaration.

2020-10-28 Thread Rob Landley
On 10/28/20 10:47 AM, enh wrote:
> yeah, i don't have any particular use for it myself, but i accept the
> "behave more like the thing you're replacing" argument and i don't see
> any problem that patch would cause, so "lgtm".

It's an optimization problem that I'm not the target audience for. Tricksy.

> mostly off topic, but personally i'd like to surface the "generally
> applicable but not widely known and kind of annoying if we repeat it
> everywhere it's relevant" stuff from --help:
> ```
> The filename "-" means stdin/stdout, and "--" stops argument parsing.
> 
> Numerical arguments accept a single letter suffix for
> kilo, mega, giga, tera, peta, and exabytes, plus an additional
> "d" to indicate decimal 1000's instead of 1024.
> 
> Durations can be decimal fractions and accept minute ("m"), hour ("h"),
> or day ("d") suffixes (so 0.1m = 6s).
> ```
> but that shouldn't get in the way of this patch.

Yup. It's in the toybox --help because I wanted to document it somewhere, but am
not sure how to point people at it...

> the args parser knows whether there are numerical arguments so it
> could automatically append the bit about suffixes everywhere it's
> relevant, but the durations stuff isn't known, nor is whether any
> argument is a filename. and, sadly, i've been surprised by the number
> of people who don't know about `--` but would feel weird adding that
> everywhere. i did wonder about having "Try `toybox --help` for general
> information about arguments." automatically appended everywhere but i
> don't actually know whether anyone who doesn't know the stuff above
> would actually look, so i haven't suggested it. (until now.)

Ok. Um. Hmmm. How about:

  Toybox 0.8.4 multicall binary: https://landley.net/toybox (toybox --help)

And then I can change the top level toybox page from news.html to about.html
except... looking at the about page again it's all FAQ entries, isn't it? I
should just put an "about" section at the start of the FAQ, but although I can
symlink index.html to any of the other pages I can't easily make it jump to an
#anchor tag so it's not quite equivalent...

While I'm at it I also need to collate the "general questions" to the end of the
FAQ. Things like "why time based releases" and "will you backport old versions"
are generic open source project questions, not really toybox specific. (In fact
the second one I originally wrote for busybox, but after I left they made it
busybox-specific and thus a less useful general answer to the question. In
https://busybox.net/FAQ.html#backporting everything from "if you don't want to
take the risk" to right before "the volunteers are happy" was not part of what I
originally wrote. One of my motivations for doing a new FAQ...)

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] toys.h: remove unused declaration.

2020-10-28 Thread enh via Toybox
yeah, i don't have any particular use for it myself, but i accept the
"behave more like the thing you're replacing" argument and i don't see
any problem that patch would cause, so "lgtm".

-*-

mostly off topic, but personally i'd like to surface the "generally
applicable but not widely known and kind of annoying if we repeat it
everywhere it's relevant" stuff from --help:
```
The filename "-" means stdin/stdout, and "--" stops argument parsing.

Numerical arguments accept a single letter suffix for
kilo, mega, giga, tera, peta, and exabytes, plus an additional
"d" to indicate decimal 1000's instead of 1024.

Durations can be decimal fractions and accept minute ("m"), hour ("h"),
or day ("d") suffixes (so 0.1m = 6s).
```
but that shouldn't get in the way of this patch.

the args parser knows whether there are numerical arguments so it
could automatically append the bit about suffixes everywhere it's
relevant, but the durations stuff isn't known, nor is whether any
argument is a filename. and, sadly, i've been surprised by the number
of people who don't know about `--` but would feel weird adding that
everywhere. i did wonder about having "Try `toybox --help` for general
information about arguments." automatically appended everywhere but i
don't actually know whether anyone who doesn't know the stuff above
would actually look, so i haven't suggested it. (until now.)

On Wed, Oct 28, 2020 at 6:38 AM Rob Landley  wrote:
>
> On 10/27/20 6:09 PM, enh via Toybox wrote:
> > ---
> >  toys.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
>
> Sorry, a leak from an unfinished change in my tree, related to that "should
> toybox provide version info and a URL in the help" thing from endless arguing 
> in
> the bug reports, I think the attached is the rest of it. Wasn't sure about it,
> so I hadn't checked it in.
>
> Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] toys.h: remove unused declaration.

2020-10-28 Thread Rob Landley
On 10/27/20 6:09 PM, enh via Toybox wrote:
> ---
>  toys.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Sorry, a leak from an unfinished change in my tree, related to that "should
toybox provide version info and a URL in the help" thing from endless arguing in
the bug reports, I think the attached is the rest of it. Wasn't sure about it,
so I hadn't checked it in.

Rob
diff --git a/lib/help.c b/lib/help.c
index 86d6392b..814fed56 100644
--- a/lib/help.c
+++ b/lib/help.c
@@ -21,6 +21,10 @@ void show_help(FILE *out, int full)
   int i = toys.which-toy_list;
   char *s, *ss;
 
+  if (!(full&2))
+fprintf(out, "Toybox %s" USE_TOYBOX(" multicall binary")
+ ": https://landley.net/toybox/about.html\n\n;, toybox_version);
+
   if (CFG_TOYBOX_HELP) {
 for (;;) {
   s = help_data;
diff --git a/main.c b/main.c
index ced2a65b..7c60bdf4 100644
--- a/main.c
+++ b/main.c
@@ -21,7 +21,7 @@ struct toy_list toy_list[] = {
 
 struct toy_context toys;
 union global_union this;
-char toybuf[4096], libbuf[4096];
+char *toybox_version = TOYBOX_VERSION, toybuf[4096], libbuf[4096];
 
 struct toy_list *toy_find(char *name)
 {
@@ -84,7 +84,7 @@ void toy_singleinit(struct toy_list *which, char *argv[])
 }
 
 if (!strcmp(argv[1], "--version")) {
-  xputs("toybox "TOYBOX_VERSION);
+  xprintf("toybox %s\n", toybox_version);
   xexit();
 }
   }
diff --git a/toys/other/help.c b/toys/other/help.c
index 179dd4e7..9df703c2 100644
--- a/toys/other/help.c
+++ b/toys/other/help.c
@@ -30,12 +30,12 @@ static void do_help(struct toy_list *t)
 xprintf("%s\n", t->name, t->name);
 
   toys.which = t;
-  show_help(stdout, !FLAG(u));
+  show_help(stdout, FLAG(h)+!FLAG(u));
 
   if (FLAG(h)) xprintf("\n");
 }
 
-// The simple help is just toys.which = toy_find("name"); show_help(stdout);
+// The simple help is just toys.which = toy_find("name"); show_help(stdout, 1);
 // But iterating through html output and all commands is a big more 
 
 void help_main(void)
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net