[Toybox] grep -vo

Rob Landley rob at landley.net
Wed Jul 20 12:51:29 PDT 2016



On 07/20/2016 10:31 AM, enh wrote:
> On Wed, Jul 20, 2016 at 12:10 AM, Rob Landley <rob at landley.net> wrote:
>> So grep --color requires surprisingly intrusive changes,
> 
> that's why i left it to you :-)

I'm most of the way through it.

I found more bugs! Subtle ones. "grep toybox nofile README" returns 0
because finding toybox in README resets the error value. The "file not
found" case should return 2 (even if later files exist and have
patches), and "grep toybox README empty" should return 0 as long as
empty exists, even if it had no matches, because we found a match in the
corpus we searched...

Adding tests for both cases. And checking the 0 vs 1 vs 2.

Seriously: dorodango. Much better name for the project.

Oh, and izabera complained on irc that the sequence of -f and -e is not
preserved (in grep or in sed) because the option parsing infrastructure
populates two separate lists. And I realized that I CAN make it work
with something like:

  char **blah;

  for (blah = toys.argv; *blah; blah++) {
    int off;

    if (**blah != '-') continue;
    off = strcspn(*blah, "fe");
    if (!(*blah)[off])) continue;
    if ((*blah)[off]=='f') pop_and_do_f();
    else pop_and_do_e();
  }

After all, I keep the unperturbed command line around in case I needed
it. This wouldn't handle the special & mode for "tar xvjf blah", and
could get confused by "grep -f -f", but I think it could be polished up
into a function that grep and sed could share. (What else has this sort
of thing?)

Polishing the ball of mud...

>> Dunno the right thing to do here, thought I'd ask on the list. Posix is,
>> as usual, no help whatsoever. Neither is LSB.
>>
>> Should I split the lines or not split the lines?
> 
> given that no one seems to have noticed that GNU grep outputs nothing,

Nobody seems to have noticed that in ubuntu "grep -F -e blah -e ''"
should match every line in a file (because the '' pattern matches every
line, it's right there in the desciption of -F) but instead matches nothing.

Not sure what's going on there actually, "grep -f e blah -e toybox
README" matches the lines that say toybox. But if the second -e is ''
it's ignored.

*shrug* Mine works. :)

By the way, back when I used to point people at test cases I assumed it
was easy for everybody else to do this sort of thing. Read the spec/man
page/help text, see what assertions it made, test multiple
implementations against each other (toybox aside: busybox and ubuntu
have existed for years), come up with Stupid Questions to ask when you
don't get why the output isn't what you expect. Alas, good tests seem to
be like good documentation: a thing that's easy to consume but
surprisingly hard to produce.

> how about just "[!ov]" until someone comes along with a convincing
> argument/use case?

I've already _got_ it doing the logical -o -v behavior (inverting -o so
showing the snippets that DIDN'T match, each on their own line), so my
default is to keep that for now. That's "right", just not necessarily
the most useful. (And adding ANOTHER flag to not output a newline in
that case... ew.)

There are other silly combinations such as -ox and -xw where the -x
trumps the other two flags, and it defaults to "silently ignored". Using
! would error out instead if you provided that combo, which is different
behavior. (It fails loudly and people are more likely to report it, but
could break scripts. Ok, stupid scripts, but there's a sed change for
perl's configuration stuff showing how widely stupid scripts can be
deployed...)

I'd be thrilled to appeal to a standards body that meant something, but
the Austin group has a bad case of Jorg Schilling, and after:

  http://landley.net/notes-2016.html#11-03-2016

I'm waiting for him to die of old age before going back there.

As for the Linux Foundation, ever since they took over LSB each
decision's been made by the highest bidder (Debian was annoyed when LSB
made RPM the official package format, then I think Cannonical threw
money at the problem and got it fixed?)

The fact that the CEO of the linux foundation blogged about how great it
is that Microsoft gave them money was bad enough:
https://web.archive.org/web/20160121174358/http://www.linuxfoundation.org/news-media/blogs/browse/2015/12/linux-foundation-and-microsoft-great-start-great-partnership

The fact it's no LONGER up at that URL and I had to fish it out of
archive.org is true of pretty much anything the linux foundation does a
year or two later.

So yeah, not them for standards either. It's a quandry. Maybe even a
conundrum. (I'd have to have it appraised.)

Rob


More information about the Toybox mailing list