From 16fd3794bbff69897b0123f3747156fdc8916e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 18 Mar 2004 09:05:37 +0000 Subject: [PATCH] Added the script zipgrep git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7023 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/unzip/Jamfile | 5 ++++ src/apps/bin/unzip/zipgrep | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/apps/bin/unzip/zipgrep diff --git a/src/apps/bin/unzip/Jamfile b/src/apps/bin/unzip/Jamfile index 7169856c37..6933193e76 100644 --- a/src/apps/bin/unzip/Jamfile +++ b/src/apps/bin/unzip/Jamfile @@ -58,3 +58,8 @@ BinCommand unzipsfx : ; LinkSharedOSLibs unzipsfx : be ; + +{ + MakeLocate zipgrep : $(OBOS_BIN_DIR) ; + Shell zipgrep : zipgrep ; +} diff --git a/src/apps/bin/unzip/zipgrep b/src/apps/bin/unzip/zipgrep new file mode 100644 index 0000000000..71c3a2e7d6 --- /dev/null +++ b/src/apps/bin/unzip/zipgrep @@ -0,0 +1,56 @@ +#! /bin/sh +# zipgrep: searches the given zip members for a string or pattern +# This shell script assumes that you have installed UnZip. + +pat="" +opt="" +while test $# -ne 0; do + case "$1" in + -e | -f) opt="$opt $1"; shift; pat="$1";; + -*) opt="$opt $1";; + *) if test -z "$pat"; then + pat="$1" + else + break; + fi;; + esac + shift +done + +if test $# = 0; then + echo "usage: `basename $0` [egrep_options] pattern zipfile [members...]" + echo searches the given zip members for a string or pattern + exit 1 +fi +zipfile="$1"; shift + +list=0 +silent=0 +opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'` +case "$opt" in + *l*) list=1; opt=`echo $opt | sed s/l//` +esac +case "$opt" in + *h*) silent=1 +esac +if test -n "$opt"; then + opt="-$opt" +fi + +res=0 +for i in `unzip -Z1 "$zipfile" ${1+"$@"}`; do + if test $list -eq 1; then + + unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" > /dev/null && echo $i + r=$? + elif test $silent -eq 1; then + + unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" + r=$? + else + unzip -p-L "$zipfile" "$i" | egrep $opt "$pat" | sed "s|^|${i}:|" + r=$? + fi + test "$r" -ne 0 && res="$r" +done +exit $res