Page MenuHomeFreeBSD

Use a script wrapper for <compress>grep
ClosedPublic

Authored by bapt on Apr 25 2018, 10:34 AM.
Tags
None
Referenced Files
F105903593: D15193.diff
Sun, Dec 22, 9:03 AM
Unknown Object (File)
Wed, Dec 11, 10:26 PM
Unknown Object (File)
Tue, Dec 10, 7:59 PM
Unknown Object (File)
Tue, Dec 3, 10:31 AM
Unknown Object (File)
Mon, Nov 25, 6:10 AM
Unknown Object (File)
Sun, Nov 24, 9:02 PM
Unknown Object (File)
Sun, Nov 24, 12:56 AM
Unknown Object (File)
Fri, Nov 22, 11:22 PM
Subscribers

Details

Summary

Import the wrapper script from zstdgrep (written by wiz@netbsd.org)

Modify it to support more than just zstd (adding support for gzip,
lzma, xz and bzip2)

Write a simple manpage dedicated for it.

Only use that new wrapper both for gnu grep and bsd grep

Next step will be removing code related to compression format from bsdgrep

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Correct year for copyright

Fix a typo in the zstdcat arguments

Stop removing lz* and xz* versions of grep

I think other than the manpage thing, this should fix PR 227559 and we can probably MFC it before 11.2, yeah?

usr.bin/grep/Makefile
9 ↗(On Diff #41843)

I don't think we want this here, eh? zgrep is installed unconditionally, but the man page is only installed when bsdgrep is default here. =)

Add zgrep also when bsdgrep is installed

This revision is now accepted and ready to land.Apr 25 2018, 1:03 PM
This revision was automatically updated to reflect the committed changes.
jilles added inline comments.
head/usr.bin/grep/zgrep.sh
37

prg=${0##*/} would be slightly more efficient.

85–86

Real grep will accept and use more than one -e option. This could be implemented using explicit quoting and eval using -e options like necessary for grep_args anyway.

94

This needs quoting (such as surrounding with ' and ' and replacing ' with '\'' so it can pass through arguments containing spaces (using eval later). Pathnames to -f may contain spaces legitimately and any argument might contain IFS characters and metacharacters.

105–108

There should probably be a check for -R so it is performed using find or at least rejected cleanly rather than doing something nonsensical.

109–110

Some long options like --file can take an argument as a separate parameter.

138

${cattool}, ${catargs} and ${grep} should be quoted. ${grep_args} and ${pattern} need additional eval magic.

144–148

This looks slow if there are many small files, but it is the only way to get the labels right. Apparently, performance is not so important here.

On another note, a for file do loop may look slightly nicer.

bapt marked 2 inline comments as done.Apr 25 2018, 9:04 PM