OLD | NEW |
1 #!@POSIX_SHELL@ | 1 #!@POSIX_SHELL@ |
2 | 2 |
3 # xzgrep -- a wrapper around a grep program that decompresses files as needed | 3 # xzgrep -- a wrapper around a grep program that decompresses files as needed |
4 # Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca> | 4 # Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca> |
5 | 5 |
6 # Copyright (C) 1998, 2001, 2002, 2006, 2007 Free Software Foundation | 6 # Copyright (C) 1998, 2001, 2002, 2006, 2007 Free Software Foundation |
7 # Copyright (C) 1993 Jean-loup Gailly | 7 # Copyright (C) 1993 Jean-loup Gailly |
8 | 8 |
9 # Modified for XZ Utils by Andrew Dudman and Lasse Collin. | 9 # Modified for XZ Utils by Andrew Dudman and Lasse Collin. |
10 | 10 |
11 # This program is free software; you can redistribute it and/or modify | 11 # This program is free software; you can redistribute it and/or modify |
12 # it under the terms of the GNU General Public License as published by | 12 # it under the terms of the GNU General Public License as published by |
13 # the Free Software Foundation; either version 2 of the License, or | 13 # the Free Software Foundation; either version 2 of the License, or |
14 # (at your option) any later version. | 14 # (at your option) any later version. |
15 | 15 |
16 # This program is distributed in the hope that it will be useful, | 16 # This program is distributed in the hope that it will be useful, |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 # GNU General Public License for more details. | 19 # GNU General Public License for more details. |
20 | 20 |
21 #SET_PATH - This line is a placeholder to ease patching this script. | 21 #SET_PATH - This line is a placeholder to ease patching this script. |
22 | 22 |
23 # Instead of unsetting XZ_OPT, just make sure that xz will use file format | 23 # Instead of unsetting XZ_OPT, just make sure that xz will use file format |
24 # autodetection. This way memory usage limit and thread limit can be | 24 # autodetection. This way memory usage limit and thread limit can be |
25 # specified via XZ_OPT. With gzip and bzip2 it's OK to just unset the | 25 # specified via XZ_OPT. With gzip and bzip2 it's OK to just unset the |
26 # environment variables. | 26 # environment variables. |
27 xz='@xz@ --format=auto' | 27 xz='@xz@ --format=auto' |
28 unset GZIP BZIP BZIP2 | 28 unset GZIP BZIP BZIP2 |
29 | 29 |
30 case ${0##/*} in | 30 case ${0##*/} in |
31 *egrep*) prog=xzegrep; grep=${GREP:-egrep};; | 31 *egrep*) prog=xzegrep; grep=${GREP:-egrep};; |
32 *fgrep*) prog=xzfgrep; grep=${GREP:-fgrep};; | 32 *fgrep*) prog=xzfgrep; grep=${GREP:-fgrep};; |
33 *) prog=xzgrep; grep=${GREP:-grep};; | 33 *) prog=xzgrep; grep=${GREP:-grep};; |
34 esac | 34 esac |
35 | 35 |
36 version="$prog (@PACKAGE_NAME@) @VERSION@" | 36 version="$prog (@PACKAGE_NAME@) @VERSION@" |
37 | 37 |
38 usage="Usage: ${0##/*} [OPTION]... [-e] PATTERN [FILE]... | 38 usage="Usage: ${0##*/} [OPTION]... [-e] PATTERN [FILE]... |
39 Look for instances of PATTERN in the input FILEs, using their | 39 Look for instances of PATTERN in the input FILEs, using their |
40 uncompressed contents if they are compressed. | 40 uncompressed contents if they are compressed. |
41 | 41 |
42 OPTIONs are the same as for '$grep'. | 42 OPTIONs are the same as for '$grep'. |
43 | 43 |
44 Report bugs to <@PACKAGE_BUGREPORT@>." | 44 Report bugs to <@PACKAGE_BUGREPORT@>." |
45 | 45 |
46 # sed script to escape all ' for the shell, and then (to handle trailing | 46 # sed script to escape all ' for the shell, and then (to handle trailing |
47 # newlines correctly) turn trailing X on last line into '. | 47 # newlines correctly) turn trailing X on last line into '. |
48 escape=' | 48 escape=' |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 case $option in | 119 case $option in |
120 (*\'?*) | 120 (*\'?*) |
121 option=\'$(expr "X${option}X" : 'X\(.*\)' | sed "$escape");; | 121 option=\'$(expr "X${option}X" : 'X\(.*\)' | sed "$escape");; |
122 (*) | 122 (*) |
123 option="'$option'";; | 123 option="'$option'";; |
124 esac | 124 esac |
125 | 125 |
126 grep="$grep $option$optarg" | 126 grep="$grep $option$optarg" |
127 done | 127 done |
128 | 128 |
| 129 if test $files_with_matches -eq 1 || test $files_without_matches -eq 1; then |
| 130 grep="$grep -q" |
| 131 fi |
| 132 |
129 eval "set -- $operands "'${1+"$@"}' | 133 eval "set -- $operands "'${1+"$@"}' |
130 | 134 |
131 if test $have_pat -eq 0; then | 135 if test $have_pat -eq 0; then |
132 case ${1?"Missing pattern; try \`${0##*/} --help' for help"} in | 136 case ${1?"Missing pattern; try \`${0##*/} --help' for help"} in |
133 (*\'*) | 137 (*\'*) |
134 grep="$grep -- '"$(printf '%sX\n' "$1" | sed "$escape");; | 138 grep="$grep -- '"$(printf '%sX\n' "$1" | sed "$escape");; |
135 (*) | 139 (*) |
136 grep="$grep -- '$1'";; | 140 grep="$grep -- '$1'";; |
137 esac | 141 esac |
138 shift | 142 shift |
(...skipping 10 matching lines...) Expand all Loading... |
149 case $i in | 153 case $i in |
150 *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) uncompress="gzip -cdfq";; | 154 *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) uncompress="gzip -cdfq";; |
151 *[-.]bz2 | *[-.]tbz | *.tbz2) uncompress="bzip2 -cdfq";; | 155 *[-.]bz2 | *[-.]tbz | *.tbz2) uncompress="bzip2 -cdfq";; |
152 *) uncompress="$xz -cdfq";; | 156 *) uncompress="$xz -cdfq";; |
153 esac | 157 esac |
154 # Fail if xz or grep (or sed) fails. | 158 # Fail if xz or grep (or sed) fails. |
155 xz_status=$( | 159 xz_status=$( |
156 exec 5>&1 | 160 exec 5>&1 |
157 ($uncompress -- "$i" 5>&-; echo $? >&5) 3>&- | | 161 ($uncompress -- "$i" 5>&-; echo $? >&5) 3>&- | |
158 if test $files_with_matches -eq 1; then | 162 if test $files_with_matches -eq 1; then |
159 eval "$grep" -q && { printf '%s\n' "$i" || exit 2; } | 163 eval "$grep" && { printf '%s\n' "$i" || exit 2; } |
160 elif test $files_without_matches -eq 1; then | 164 elif test $files_without_matches -eq 1; then |
161 eval "$grep" -q || { | 165 eval "$grep" || { |
162 r=$? | 166 r=$? |
163 if test $r -eq 1; then | 167 if test $r -eq 1; then |
164 printf '%s\n' "$i" || r=2 | 168 printf '%s\n' "$i" || r=2 |
165 fi | 169 fi |
166 exit $r | 170 exit $r |
167 } | 171 } |
168 elif test $with_filename -eq 0 && | 172 elif test $with_filename -eq 0 && |
169 { test $# -eq 1 || test $no_filename -eq 1; }; then | 173 { test $# -eq 1 || test $no_filename -eq 1; }; then |
170 eval "$grep" | 174 eval "$grep" |
171 else | 175 else |
(...skipping 15 matching lines...) Expand all Loading... |
187 (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&- | 191 (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&- |
188 ) || r=2 | 192 ) || r=2 |
189 exit $r | 193 exit $r |
190 fi >&3 5>&- | 194 fi >&3 5>&- |
191 ) | 195 ) |
192 r=$? | 196 r=$? |
193 test "$xz_status" -eq 0 || test "$xz_status" -eq 2 || r=2 | 197 test "$xz_status" -eq 0 || test "$xz_status" -eq 2 || r=2 |
194 test $res -lt $r && res=$r | 198 test $res -lt $r && res=$r |
195 done | 199 done |
196 exit $res | 200 exit $res |
OLD | NEW |