[Toybox] New toy: grep

Rob Landley rob at landley.net
Mon Feb 27 10:01:12 PST 2012


On 02/26/2012 10:01 PM, Andre Renaud wrote:
> Attached is a simplistic starter implementation of the grep command.
> There are currently a few issues with it:
> 1. It doesn't intelligently cope with lines that fall over a 'toybuf'
> read boundary. It should be stuffing the partial line back into toybuf &
> appending the next read to the end.

That's actually a concern for me: I'd like grep to be able to handle
unlimited-length input lines. Using toybuf for the regex might be
reasonable, but using it for the input data is much less so...

Oh, and it should probably be able to handle embedded NUL bytes.  People
use grep and sed on executables (because they're crazy, but they do it
anyway)...

> 2. It uses strcasestr for case-insensitive searches. This is a
> non-standard GNU extension, which I presume we shouldn't be using

Actually strcasecmp() is in posix-2008:

http://opengroup.org/onlinepubs/9699919799/functions/strcasecmp.html

So we're good there.

> 3. It doesn't handle the -E regular expression options. I see there is
> some xregcomp options in the toybox lib - is this something that we'd
> make conditional on a build option?

More like a compile-time probe to see if it's available in the library,
similar to the current unshare probe.

And actually grep is _always_ supposed to use regexes, the -E option
(and egrep alias) just feed the REGEX_EXTENDED flag to regcomp() so it
recognizes a more extensive syntax (which is slightly slower to use in
searches, I think).

It might be best if I take over this one since I'm doing sed anyway
(which is fiddly and evil, and requires me to do the xregcmp()
infrastructure in lib/ and the compile time test for it).

(I also note that I wrote my own regex/glob engine back in the 90's
under OS/2, so if bionic turns out not to have usable regexes and I have
to write my own, I'm prepared to do that...)

> Regards,
> Andre

Thanks,

Rob

 1330365672.0


More information about the Toybox mailing list