vfs: check userland buffers before reading them.
[haiku.git] / src / bin / unzip / zipgrep
blob71c3a2e7d61fe18124935e3a23688d9864cfc1b6
1 #! /bin/sh
2 # zipgrep: searches the given zip members for a string or pattern
3 # This shell script assumes that you have installed UnZip.
5 pat=""
6 opt=""
7 while test $# -ne 0; do
8 case "$1" in
9 -e | -f) opt="$opt $1"; shift; pat="$1";;
10 -*) opt="$opt $1";;
11 *) if test -z "$pat"; then
12 pat="$1"
13 else
14 break;
15 fi;;
16 esac
17 shift
18 done
20 if test $# = 0; then
21 echo "usage: `basename $0` [egrep_options] pattern zipfile [members...]"
22 echo searches the given zip members for a string or pattern
23 exit 1
25 zipfile="$1"; shift
27 list=0
28 silent=0
29 opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
30 case "$opt" in
31 *l*) list=1; opt=`echo $opt | sed s/l//`
32 esac
33 case "$opt" in
34 *h*) silent=1
35 esac
36 if test -n "$opt"; then
37 opt="-$opt"
40 res=0
41 for i in `unzip -Z1 "$zipfile" ${1+"$@"}`; do
42 if test $list -eq 1; then
44 unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" > /dev/null && echo $i
45 r=$?
46 elif test $silent -eq 1; then
48 unzip -p-L "$zipfile" "$i" | egrep $opt "$pat"
49 r=$?
50 else
51 unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" | sed "s|^|${i}:|"
52 r=$?
54 test "$r" -ne 0 && res="$r"
55 done
56 exit $res