[Toybox] [patch] add grep

Isaac idunham at lavabit.com
Fri Jul 19 21:50:18 PDT 2013


On Sat, Jul 13, 2013 at 12:06:54PM -0500, Strake wrote:
> On 09/07/2013, James McMechan <james_mcmechan at hotmail.com> wrote:
> >> Date: Mon, 8 Jul 2013 19:08:03 -0700
> >> From: idunham at lavabit.com
> >> To: strake888 at gmail.com
> >> CC: toybox at lists.landley.net
> >> Subject: Re: [Toybox] [patch] add grep
> >>
> >> ...
> >>
> >> This is not POSIX conformant yet, and would also break the kernel build.
> >>
> > I checked the kernel build (as of 3.8.13) by grepping for grep naturally...
> > It had grep fgrep egrep
> > and used flags  -d -E -v -q -m -- -w -i -e -o -h -abo
> > which was a shorter list than I was expecting.
> >
> >
> >> grep must support multiple regexes:
> >> "Multiple -e and -f options shall be accepted by the grep utility."
> >> grep -e signals that the next argument is a regex.
> >> grep -f <file> means each line in <file> is a regex.
> >>
> >> Also you didn't implement -F (exact match), which is specified by POSIX.
> >>
> >> Practically speaking, you also will need to support
> >> grep -h (which outputs only the matching line without the filename)
> >> This is required by the kernel build process.
> >> And as far as I can tell, you don't have a switch to suppress filename
> >> when only one file is specified.
> 
> I added some more flags: EFhinovclqe*f*m#
what the kernel needs:     EFabhiovwqd*e*m#
(just for reference)
-a is "treat anything as text"
-b is "print binary offset"
-d (read|skip|recurse) is a state switch that looks like insanity.
-w matches a whole word.

> Too, I moved it to pending, and disabled it by default.
> 
> I may hack it further later, but I already feel dirty for adding so
> many features.

Well, I compiled toybox with musl and gcc complains about using regoff_t 
as an int, so I took a look.
I didn't dare to poke at that, but noticed the exit (c).
This would break toysh and anything else that may xexec() grep, so I started
writing a patch to use xexit/error_exit/toys.exitval.
By now I've also added -Hs because they were trivial.
Mind if I submit it?

In my testing it seemed that -e and -f don't work; 
it looks like they're not hooked up?

I noticed one oddity in your style: is there any reason to use 
function (args); //normal is function(args) ?
The latter style makes a regex search for functions simpler.

Thanks,
Isaac Dunham


 1374295818.0


More information about the Toybox mailing list