On 4/23/19 8:06 PM, enh wrote:
> (sorry. busy.)
Sigh. I'll add a config symbol you can switch on, with help text complaining
about it.
Does the attached work/suffice? (I _think_ setlinebuf(stdout) followed by
setvbuf() something else is legal as long as we haven't output anything to the
stream yet? But the man page is unclear. Presumably the admonition is because
pending unflushed data in the buffer would get discarded, but they don't
_say_...)
Rob
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index c88d4c6..09f3405 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -50,6 +50,20 @@ config GREP
-H force filename -b byte offset of match
-h hide filename -n line number of match
+config GREP_PEDIANTIC
+ bool "pedantic posix compatibility for grep"
+ default n
+ depends on GREP
+ help
+ usage: grep --line-buffered
+
+ --line-buffered Disable pedantic posix compatibility
+
+ Without --line-buffered "(echo hello; yes) | grep hello | head -n 1" hangs
+ endlessly, there's no progressive disclosure in output piped to tee or
+ less (nothing, then a whole screen), and some shell pipelines are slower
+ on SMP systems.
+
config EGREP
bool
default y
@@ -450,6 +464,8 @@ void grep_main(void)
{
char **ss = toys.optargs;
+ if (CFG_GREP_PEDANTIC && ! FLAG(line_buffered)) setvbuf(stdout, 0, _IOFBF, 0);
+
if (FLAG(color) && (!TT.color || !strcmp(TT.color, "auto")) && !isatty(1))
toys.optflags &= ~FLAG_color;
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net