Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153056458
D25613.id74590.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D25613.id74590.diff
View Options
Index: contrib/netbsd-tests/usr.bin/grep/t_grep.sh
===================================================================
--- contrib/netbsd-tests/usr.bin/grep/t_grep.sh
+++ contrib/netbsd-tests/usr.bin/grep/t_grep.sh
@@ -214,6 +214,89 @@
atf_check -o file:"$(atf_get_srcdir)/d_zgrep.out" zgrep -h line d_input.gz
}
+atf_test_case zgrep_combined_flags
+zgrep_combined_flags_head()
+{
+ atf_set "descr" "Checks for zgrep wrapper problems with combined flags (PR 247126)"
+}
+zgrep_combined_flags_body()
+{
+ atf_expect_fail "known but unsolved zgrep wrapper script regression"
+
+ echo 'foo bar' > test
+
+ atf_check -o inline:"foo bar\n" zgrep -we foo test
+ # Avoid hang on reading from stdin in the failure case
+ atf_check -o inline:"foo bar\n" zgrep -wefoo test < /dev/null
+}
+
+atf_test_case zgrep_eflag
+zgrep_eflag_head()
+{
+ atf_set "descr" "Checks for zgrep wrapper problems with -e PATTERN (PR 247126)"
+}
+zgrep_eflag_body()
+{
+ echo 'foo bar' > test
+
+ # Avoid hang on reading from stdin in the failure case
+ atf_check -o inline:"foo bar\n" zgrep -e 'foo bar' test < /dev/null
+ atf_check -o inline:"foo bar\n" zgrep --regexp='foo bar' test < /dev/null
+}
+
+atf_test_case zgrep_fflag
+zgrep_fflag_head()
+{
+ atf_set "descr" "Checks for zgrep wrapper problems with -f FILE (PR 247126)"
+}
+zgrep_fflag_body()
+{
+ echo foo > pattern
+ echo foobar > test
+
+ # Avoid hang on reading from stdin in the failure case
+ atf_check -o inline:"foobar\n" zgrep -f pattern test </dev/null
+ atf_check -o inline:"foobar\n" zgrep --file=pattern test </dev/null
+}
+
+atf_test_case zgrep_long_eflag
+zgrep_long_eflag_head()
+{
+ atf_set "descr" "Checks for zgrep wrapper problems with --ignore-case reading from stdin (PR 247126)"
+}
+zgrep_long_eflag_body()
+{
+ echo foobar > test
+
+ atf_check -o inline:"foobar\n" zgrep -e foo --ignore-case < test
+}
+
+atf_test_case zgrep_multiple_eflags
+zgrep_multiple_eflags_head()
+{
+ atf_set "descr" "Checks for zgrep wrapper problems with multiple -e flags (PR 247126)"
+}
+zgrep_multiple_eflags_body()
+{
+ atf_expect_fail "known but unsolved zgrep wrapper script regression"
+
+ echo foobar > test
+
+ atf_check -o inline:"foobar\n" zgrep -e foo -e xxx test
+}
+
+atf_test_case zgrep_empty_eflag
+zgrep_empty_eflag_head()
+{
+ atf_set "descr" "Checks for zgrep wrapper problems with empty -e flags pattern (PR 247126)"
+}
+zgrep_empty_eflag_body()
+{
+ echo foobar > test
+
+ atf_check -o inline:"foobar\n" zgrep -e '' test
+}
+
atf_test_case nonexistent
nonexistent_head()
{
@@ -826,6 +909,12 @@
atf_add_test_case file_exp
atf_add_test_case egrep
atf_add_test_case zgrep
+ atf_add_test_case zgrep_combined_flags
+ atf_add_test_case zgrep_eflag
+ atf_add_test_case zgrep_empty_eflag
+ atf_add_test_case zgrep_fflag
+ atf_add_test_case zgrep_long_eflag
+ atf_add_test_case zgrep_multiple_eflags
atf_add_test_case nonexistent
atf_add_test_case context2
# Begin FreeBSD
Index: usr.bin/grep/zgrep.1
===================================================================
--- usr.bin/grep/zgrep.1
+++ usr.bin/grep/zgrep.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 21, 2018
+.Dd July 17, 2020
.Dt ZGREP 1
.Os
.Sh NAME
@@ -86,9 +86,32 @@
.Sh SEE ALSO
.Xr bzip2 1 ,
.Xr grep 1 ,
-.Xr xz 1
+.Xr gzip 1 ,
+.Xr xz 1 ,
+.Xr zstd 1
.Sh AUTHORS
This version of the
.Nm
utility was written by
.An Thomas Klausner Aq Mt wiz@NetBSD.org .
+.Sh BUGS
+Here are known problems with
+.Xr zgrep 1 .
+.Pp
+.Xr zgrep 1
+does not handle flags that take arguments if there is no whitespace
+between the flag and the argument, for example:
+.Pp
+.Dl "zgrep -enfs /etc/rpc"
+.Pp
+When more than one
+.Fl e
+flag is used matching
+should occur for any of the patterns (similar to multiple patterns
+supplied in a file with the
+.Fl f
+flag).
+.Xr zgrep 1
+only matches the last
+.Fl e
+pattern.
Index: usr.bin/grep/zgrep.sh
===================================================================
--- usr.bin/grep/zgrep.sh
+++ usr.bin/grep/zgrep.sh
@@ -29,6 +29,7 @@
zcat=zstdcat
endofopts=0
+pattern_file=0
pattern_found=0
grep_args=""
hyphen=0
@@ -75,29 +76,46 @@
do
case $1 in
# from GNU grep-2.5.1 -- keep in sync!
- -[ABCDXdefm])
+ --)
+ shift
+ endofopts=1
+ ;;
+ --file=*)
+ pattern_file=1
+ grep_args="${grep_args} ${1}"
+ shift
+ ;;
+ --regexp=*)
+ pattern="${1#--regexp=}"
+ pattern_found=1
+ shift
+ ;;
+ --*)
+ grep_args="${grep_args} $1"
+ shift
+ ;;
+ -*[ABCDXdefm])
if [ $# -lt 2 ]
then
echo "${prg}: missing argument for $1 flag" >&2
exit 1
fi
case $1 in
- -e)
+ -*e)
pattern="$2"
pattern_found=1
shift 2
- break
+ continue
;;
+ -*f)
+ pattern_file=1
+ ;;
*)
;;
esac
grep_args="${grep_args} $1 $2"
shift 2
;;
- --)
- shift
- endofopts=1
- ;;
-)
hyphen=1
shift
@@ -125,7 +143,7 @@
done
# if no -e option was found, take next argument as grep-pattern
-if [ ${pattern_found} -lt 1 ]
+if [ ${pattern_file} -eq 0 -a ${pattern_found} -eq 0 ]
then
if [ $# -ge 1 ]; then
pattern="$1"
@@ -136,6 +154,7 @@
echo "${prg}: missing pattern" >&2
exit 1
fi
+ pattern_found=1
fi
ret=0
@@ -143,15 +162,24 @@
if [ $# -lt 1 ]
then
# ... on stdin
- ${cattool} ${catargs} - | ${grep} ${grep_args} -- "${pattern}" - || ret=$?
+ if [ ${pattern_file} -eq 0 ]; then
+ ${cattool} ${catargs} - | ${grep} ${grep_args} -- "${pattern}" - || ret=$?
+ else
+ ${cattool} ${catargs} - | ${grep} ${grep_args} -- - || ret=$?
+ fi
else
# ... on all files given on the command line
if [ ${silent} -lt 1 -a $# -gt 1 ]; then
grep_args="-H ${grep_args}"
fi
for file; do
- ${cattool} ${catargs} -- "${file}" |
- ${grep} --label="${file}" ${grep_args} -- "${pattern}" - || ret=$?
+ if [ ${pattern_file} -eq 0 ]; then
+ ${cattool} ${catargs} -- "${file}" |
+ ${grep} --label="${file}" ${grep_args} -- "${pattern}" - || ret=$?
+ else
+ ${cattool} ${catargs} -- "${file}" |
+ ${grep} --label="${file}" ${grep_args} -- - || ret=$?
+ fi
done
fi
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 19, 9:27 PM (15 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31799765
Default Alt Text
D25613.id74590.diff (6 KB)
Attached To
Mode
D25613: Update zgrep(1) to correctly handle -f FILE and combined flags
Attached
Detach File
Event Timeline
Log In to Comment