annotate src/bzip2-1.0.6/bzgrep @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents e13257ea84a4
children
rev   line source
Chris@4 1 #!/bin/sh
Chris@4 2
Chris@4 3 # Bzgrep wrapped for bzip2,
Chris@4 4 # adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
Chris@4 5 ## zgrep notice:
Chris@4 6 ## zgrep -- a wrapper around a grep program that decompresses files as needed
Chris@4 7 ## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
Chris@4 8
Chris@4 9 PATH="/usr/bin:$PATH"; export PATH
Chris@4 10
Chris@4 11 prog=`echo $0 | sed 's|.*/||'`
Chris@4 12 case "$prog" in
Chris@4 13 *egrep) grep=${EGREP-egrep} ;;
Chris@4 14 *fgrep) grep=${FGREP-fgrep} ;;
Chris@4 15 *) grep=${GREP-grep} ;;
Chris@4 16 esac
Chris@4 17 pat=""
Chris@4 18 while test $# -ne 0; do
Chris@4 19 case "$1" in
Chris@4 20 -e | -f) opt="$opt $1"; shift; pat="$1"
Chris@4 21 if test "$grep" = grep; then # grep is buggy with -e on SVR4
Chris@4 22 grep=egrep
Chris@4 23 fi;;
Chris@4 24 -A | -B) opt="$opt $1 $2"; shift;;
Chris@4 25 -*) opt="$opt $1";;
Chris@4 26 *) if test -z "$pat"; then
Chris@4 27 pat="$1"
Chris@4 28 else
Chris@4 29 break;
Chris@4 30 fi;;
Chris@4 31 esac
Chris@4 32 shift
Chris@4 33 done
Chris@4 34
Chris@4 35 if test -z "$pat"; then
Chris@4 36 echo "grep through bzip2 files"
Chris@4 37 echo "usage: $prog [grep_options] pattern [files]"
Chris@4 38 exit 1
Chris@4 39 fi
Chris@4 40
Chris@4 41 list=0
Chris@4 42 silent=0
Chris@4 43 op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
Chris@4 44 case "$op" in
Chris@4 45 *l*) list=1
Chris@4 46 esac
Chris@4 47 case "$op" in
Chris@4 48 *h*) silent=1
Chris@4 49 esac
Chris@4 50
Chris@4 51 if test $# -eq 0; then
Chris@4 52 bzip2 -cdfq | $grep $opt "$pat"
Chris@4 53 exit $?
Chris@4 54 fi
Chris@4 55
Chris@4 56 res=0
Chris@4 57 for i do
Chris@4 58 if test -f "$i"; then :; else if test -f "$i.bz2"; then i="$i.bz2"; fi; fi
Chris@4 59 if test $list -eq 1; then
Chris@4 60 bzip2 -cdfq "$i" | $grep $opt "$pat" 2>&1 > /dev/null && echo $i
Chris@4 61 r=$?
Chris@4 62 elif test $# -eq 1 -o $silent -eq 1; then
Chris@4 63 bzip2 -cdfq "$i" | $grep $opt "$pat"
Chris@4 64 r=$?
Chris@4 65 else
Chris@4 66 j=${i//\\/\\\\}
Chris@4 67 j=${j//|/\\|}
Chris@4 68 j=${j//&/\\&}
Chris@4 69 j=`printf "%s" "$j" | tr '\n' ' '`
Chris@4 70 bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
Chris@4 71 r=$?
Chris@4 72 fi
Chris@4 73 test "$r" -ne 0 && res="$r"
Chris@4 74 done
Chris@4 75 exit $res