ACCC1380 commited on
Commit
f4a68ef
1 Parent(s): 2b20c4b

Upload etc/alternatives/lzegrep with huggingface_hub

Browse files
Files changed (1) hide show
  1. etc/alternatives/lzegrep +219 -0
etc/alternatives/lzegrep ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
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>
5
+
6
+ # Copyright (C) 1998, 2001, 2002, 2006, 2007 Free Software Foundation
7
+ # Copyright (C) 1993 Jean-loup Gailly
8
+
9
+ # Modified for XZ Utils by Andrew Dudman and Lasse Collin.
10
+
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
13
+ # the Free Software Foundation; either version 2 of the License, or
14
+ # (at your option) any later version.
15
+
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+
21
+ #SET_PATH - This line is a placeholder to ease patching this script.
22
+
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
25
+ # specified via XZ_OPT. With gzip, bzip2, and lzop it's OK to just unset the
26
+ # environment variables.
27
+ xz='xz --format=auto'
28
+ unset GZIP BZIP BZIP2 LZOP
29
+
30
+ case ${0##*/} in
31
+ *egrep*) prog=xzegrep; grep=${GREP:-egrep};;
32
+ *fgrep*) prog=xzfgrep; grep=${GREP:-fgrep};;
33
+ *) prog=xzgrep; grep=${GREP:-grep};;
34
+ esac
35
+
36
+ version="$prog (XZ Utils) 5.2.4"
37
+
38
+ usage="Usage: ${0##*/} [OPTION]... [-e] PATTERN [FILE]...
39
+ Look for instances of PATTERN in the input FILEs, using their
40
+ uncompressed contents if they are compressed.
41
+
42
+ OPTIONs are the same as for '$grep'.
43
+
44
+ Report bugs to <lasse.collin@tukaani.org>."
45
+
46
+ # sed script to escape all ' for the shell, and then (to handle trailing
47
+ # newlines correctly) turn trailing X on last line into '.
48
+ escape='
49
+ s/'\''/'\''\\'\'''\''/g
50
+ $s/X$/'\''/
51
+ '
52
+ operands=
53
+ have_pat=0
54
+ files_with_matches=0
55
+ files_without_matches=0
56
+ no_filename=0
57
+ with_filename=0
58
+
59
+ while test $# -ne 0; do
60
+ option=$1
61
+ shift
62
+ optarg=
63
+
64
+ case $option in
65
+ (-[0123456789abcdhHiIKLlnoqrRsTuUvVwxyzZ]?*)
66
+ arg2=-\'$(expr "X${option}X" : 'X-.[0-9]*\(.*\)' | sed "$escape")
67
+ eval "set -- $arg2 "'${1+"$@"}'
68
+ option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
69
+ (--binary-*=* | --[lm]a*=* | --reg*=*)
70
+ ;;
71
+ (-[ABCDefm] | --binary-* | --file | --[lm]a* | --reg*)
72
+ case ${1?"$option option requires an argument"} in
73
+ (*\'*)
74
+ optarg=" '"$(printf '%sX\n' "$1" | sed "$escape");;
75
+ (*)
76
+ optarg=" '$1'";;
77
+ esac
78
+ shift;;
79
+ (--)
80
+ break;;
81
+ (-?*)
82
+ ;;
83
+ (*)
84
+ case $option in
85
+ (*\'*)
86
+ operands="$operands '"$(printf '%sX\n' "$option" | sed "$escape");;
87
+ (*)
88
+ operands="$operands '$option'";;
89
+ esac
90
+ ${POSIXLY_CORRECT+break}
91
+ continue;;
92
+ esac
93
+
94
+ case $option in
95
+ (-[drRzZ] | --di* | --exc* | --inc* | --rec* | --nu*)
96
+ printf >&2 '%s: %s: Option not supported\n' "$0" "$option"
97
+ exit 2;;
98
+ (-[ef]* | --file | --file=* | --reg*)
99
+ have_pat=1;;
100
+ (--h | --he | --hel | --help)
101
+ echo "$usage" || exit 2
102
+ exit;;
103
+ (-H | --wi | --wit | --with | --with- | --with-f | --with-fi \
104
+ | --with-fil | --with-file | --with-filen | --with-filena | --with-filenam \
105
+ | --with-filename)
106
+ with_filename=1
107
+ continue;;
108
+ (-l | --files-with-*)
109
+ files_with_matches=1
110
+ continue;;
111
+ (-L | --files-witho*)
112
+ files_without_matches=1
113
+ continue;;
114
+ (-h | --no-f*)
115
+ no_filename=1;;
116
+ (-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
117
+ echo "$version" || exit 2
118
+ exit;;
119
+ esac
120
+
121
+ case $option in
122
+ (*\'?*)
123
+ option=\'$(expr "X${option}X" : 'X\(.*\)' | sed "$escape");;
124
+ (*)
125
+ option="'$option'";;
126
+ esac
127
+
128
+ grep="$grep $option$optarg"
129
+ done
130
+
131
+ if test $files_with_matches -eq 1 || test $files_without_matches -eq 1; then
132
+ grep="$grep -q"
133
+ fi
134
+
135
+ eval "set -- $operands "'${1+"$@"}'
136
+
137
+ if test $have_pat -eq 0; then
138
+ case ${1?"Missing pattern; try \`${0##*/} --help' for help"} in
139
+ (*\'*)
140
+ grep="$grep -- '"$(printf '%sX\n' "$1" | sed "$escape");;
141
+ (*)
142
+ grep="$grep -- '$1'";;
143
+ esac
144
+ shift
145
+ fi
146
+
147
+ if test $# -eq 0; then
148
+ set -- -
149
+ fi
150
+
151
+ exec 3>&1
152
+
153
+ # res=1 means that no file matched yet
154
+ res=1
155
+
156
+ for i; do
157
+ case $i in
158
+ *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) uncompress="gzip -cdfq";;
159
+ *[-.]bz2 | *[-.]tbz | *.tbz2) uncompress="bzip2 -cdfq";;
160
+ *[-.]lzo | *[-.]tzo) uncompress="lzop -cdfq";;
161
+ *) uncompress="$xz -cdfq";;
162
+ esac
163
+ # Fail if xz or grep (or sed) fails.
164
+ xz_status=$(
165
+ exec 5>&1
166
+ ($uncompress -- "$i" 5>&-; echo $? >&5) 3>&- |
167
+ if test $files_with_matches -eq 1; then
168
+ eval "$grep" && { printf '%s\n' "$i" || exit 2; }
169
+ elif test $files_without_matches -eq 1; then
170
+ eval "$grep" || {
171
+ r=$?
172
+ if test $r -eq 1; then
173
+ printf '%s\n' "$i" || r=2
174
+ fi
175
+ exit $r
176
+ }
177
+ elif test $with_filename -eq 0 &&
178
+ { test $# -eq 1 || test $no_filename -eq 1; }; then
179
+ eval "$grep"
180
+ else
181
+ # Append a colon so that the last character will never be a newline
182
+ # which would otherwise get lost in shell command substitution.
183
+ i="$i:"
184
+
185
+ # Escape & \ | and newlines only if such characters are present
186
+ # (speed optimization).
187
+ case $i in
188
+ (*'
189
+ '* | *'&'* | *'\'* | *'|'*)
190
+ i=$(printf '%s\n' "$i" | LC_ALL=C sed 's/[&\|]/\\&/g; $!s/$/\\/');;
191
+ esac
192
+
193
+ # $i already ends with a colon so don't add it here.
194
+ sed_script="s|^|$i|"
195
+
196
+ # Fail if grep or sed fails.
197
+ r=$(
198
+ exec 4>&1
199
+ (eval "$grep" 4>&-; echo $? >&4) 3>&- |
200
+ LC_ALL=C sed "$sed_script" >&3 4>&-
201
+ ) || r=2
202
+ exit $r
203
+ fi >&3 5>&-
204
+ )
205
+ r=$?
206
+
207
+ # fail occured previously, nothing worse can happen
208
+ test $res -gt 1 && continue
209
+
210
+ test "$xz_status" -eq 0 || test "$xz_status" -eq 2 \
211
+ || test "$(kill -l "$xz_status" 2> /dev/null)" = "PIPE" || r=2
212
+
213
+ # still no match
214
+ test $r -eq 1 && continue
215
+
216
+ # 0 == match, >=2 == fail
217
+ res=$r
218
+ done
219
+ exit $res