From 7777e97ea4c2d8b13b697dca9e4f3bbdd08e6eb5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 24 Feb 2025 04:51:19 +0100 Subject: [PATCH] Merging upstream version 0.3. Signed-off-by: Daniel Baumann --- ChangeLog | 7 +++ configure | 7 ++- doc/zcat.1 | 22 ++------- doc/zdiff.1 | 29 ++++-------- doc/zgrep.1 | 24 +++------- doc/zutils.info | Bin 6005 -> 5554 bytes doc/zutils.texinfo | 59 +++++------------------ testsuite/check.sh | 31 +++++++----- zcat.in | 85 +++++++++++++-------------------- zdiff.in | 71 +++++++++++++-------------- zgrep.in | 116 +++++++++++++++++++-------------------------- 11 files changed, 181 insertions(+), 270 deletions(-) diff --git a/ChangeLog b/ChangeLog index af22713..3c6c3b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-08-?? Antonio Diaz Diaz + + * Version 0.3 released. + * Removed default compressor. + * zcat.in: Do not read data from stdin. + * Updated home page and mailing list addresses. + 2009-08-13 Antonio Diaz Diaz * Version 0.2 released. diff --git a/configure b/configure index e5cf103..77df07b 100755 --- a/configure +++ b/configure @@ -7,11 +7,10 @@ # # Date of this version: 2009-08-13 -invocation_name=$0 args= no_create= pkgname=zutils -pkgversion=0.2 +pkgversion=0.3 srctrigger=zdiff.in # clear some things potentially inherited from environment. @@ -114,7 +113,7 @@ if [ x"${srcdir}" = x ] ; then if [ ! -r ${srcdir}/${srctrigger} ] ; then srcdir=.. ; fi if [ ! -r ${srcdir}/${srctrigger} ] ; then ## the sed command below emulates the dirname command - srcdir=`echo ${invocation_name} | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + srcdir=`echo $0 | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` fi fi @@ -163,7 +162,7 @@ if [ x${no_create} = x ] ; then # This script is free software: you have unlimited permission # to copy, distribute and modify it. -exec /bin/sh ${invocation_name} ${args} --no-create +exec /bin/sh $0 ${args} --no-create EOF chmod +x config.status fi diff --git a/doc/zcat.1 b/doc/zcat.1 index cd432f0..65bb3b3 100644 --- a/doc/zcat.1 +++ b/doc/zcat.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZCAT "1" "August 2009" "Zcat 0.2" "User Commands" +.TH ZCAT "1" "August 2009" "Zcat 0.3" "User Commands" .SH NAME -Zcat \- manual page for Zcat 0.2 +Zcat \- manual page for Zcat 0.3 .SH SYNOPSIS .B zcat [\fIOPTIONS\fR] [\fICAT_OPTIONS\fR] [\fIFILES\fR] @@ -12,7 +12,7 @@ Zcat is a wrapper script around the cat command that allows transparent concatenation of any combination of compressed and non\-compressed files. If any given file is compressed, its uncompressed content is used. If a given file does not exist, zcat tries the -compressed file name corresponding to the default compressor selected. +compressed file names corresponding to the supported compressors. The supported compressors are gzip, bzip2, lzip and xz. .PP CAT_OPTIONS are passed directly to cat. @@ -24,21 +24,9 @@ display this help and exit .TP \fB\-V\fR, \fB\-\-version\fR output version information and exit -.TP -\fB\-\-gzip\fR -use gzip as default decompressor -.TP -\fB\-\-bzip2\fR -use bzip2 as default decompressor -.TP -\fB\-\-lzip\fR -use lzip as default decompressor (default) -.TP -\fB\-\-xz\fR -use xz as default decompressor .SH "REPORTING BUGS" -Report bugs to lzip\-bug@nongnu.org -Lzip home page: http://www.nongnu.org/lzip/lzip.html +Report bugs to zutils\-bug@nongnu.org +Zutils home page: http://www.nongnu.org/zutils/zutils.html .SH COPYRIGHT Copyright \(co 2009 Antonio Diaz Diaz. This script is free software: you have unlimited permission diff --git a/doc/zdiff.1 b/doc/zdiff.1 index b28acfc..c7ecbfa 100644 --- a/doc/zdiff.1 +++ b/doc/zdiff.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZDIFF "1" "August 2009" "Zdiff 0.2" "User Commands" +.TH ZDIFF "1" "August 2009" "Zdiff 0.3" "User Commands" .SH NAME -Zdiff \- manual page for Zdiff 0.2 +Zdiff \- manual page for Zdiff 0.3 .SH SYNOPSIS .B zdiff [\fIOPTIONS\fR] [\fIDIFF_OPTIONS\fR] \fIFILE1 \fR[\fIFILE2\fR] @@ -15,9 +15,12 @@ content is used. The supported compressors are gzip, bzip2, lzip and xz. .PP Zcmp is a shortcut for "zdiff \fB\-\-cmp\fR" .PP -Compares FILE1 to FILE2. If FILE2 is omitted, compares FILE1 to the -uncompressed contents of FILE1.[gz|bz2|lz] (depending on the default -compressor selected). DIFF_OPTIONS are passed directly to diff or cmp. +Compares FILE1 to FILE2. If FILE2 is omitted and FILE1 is compressed, +compares FILE1 to the file with the corresponding decompressed file +name (removes the extension from FILE1). If FILE2 is omitted and FILE1 +is not compressed, compares FILE1 to the uncompressed contents of +FILE1.[gz|bz2|lz|xz] (the first one that is found). +DIFF_OPTIONS are passed directly to diff or cmp. The exit status from diff or cmp is preserved. .SH OPTIONS .TP @@ -27,26 +30,14 @@ display this help and exit \fB\-V\fR, \fB\-\-version\fR output version information and exit .TP -\fB\-\-gzip\fR -use gzip as default decompressor -.TP -\fB\-\-bzip2\fR -use bzip2 as default decompressor -.TP -\fB\-\-lzip\fR -use lzip as default decompressor (default) -.TP -\fB\-\-xz\fR -use xz as default decompressor -.TP \fB\-\-diff\fR use diff to compare files (default) .TP \fB\-\-cmp\fR use cmp to compare files .SH "REPORTING BUGS" -Report bugs to lzip\-bug@nongnu.org -Lzip home page: http://www.nongnu.org/lzip/lzip.html +Report bugs to zutils\-bug@nongnu.org +Zutils home page: http://www.nongnu.org/zutils/zutils.html .SH COPYRIGHT Copyright \(co 2009 Antonio Diaz Diaz. This script is free software: you have unlimited permission diff --git a/doc/zgrep.1 b/doc/zgrep.1 index 8913a96..f03b530 100644 --- a/doc/zgrep.1 +++ b/doc/zgrep.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZGREP "1" "August 2009" "Zgrep 0.2" "User Commands" +.TH ZGREP "1" "August 2009" "Zgrep 0.3" "User Commands" .SH NAME -Zgrep \- manual page for Zgrep 0.2 +Zgrep \- manual page for Zgrep 0.3 .SH SYNOPSIS .B zgrep [\fIOPTIONS\fR] [\fIGREP_OPTIONS\fR] \fIPATTERN \fR[\fIFILES\fR] @@ -12,8 +12,8 @@ Zgrep is a wrapper script around the grep command that allows transparent search on any combination of compressed and non\-compressed files. If any given file is compressed, its uncompressed content is used. If a given file does not exist, zgrep tries the compressed file -name corresponding to the default compressor selected. The supported -compressors are gzip, bzip2, lzip and xz. +names corresponding to the supported compressors. +The supported compressors are gzip, bzip2, lzip and xz. .PP GREP_OPTIONS are passed directly to grep. The exit status from grep is preserved. @@ -24,21 +24,9 @@ display this help and exit .TP \fB\-V\fR, \fB\-\-version\fR output version information and exit -.TP -\fB\-\-gzip\fR -use gzip as default decompressor -.TP -\fB\-\-bzip2\fR -use bzip2 as default decompressor -.TP -\fB\-\-lzip\fR -use lzip as default decompressor (default) -.TP -\fB\-\-xz\fR -use xz as default decompressor .SH "REPORTING BUGS" -Report bugs to lzip\-bug@nongnu.org -Lzip home page: http://www.nongnu.org/lzip/lzip.html +Report bugs to zutils\-bug@nongnu.org +Zutils home page: http://www.nongnu.org/zutils/zutils.html .SH COPYRIGHT Copyright \(co 2009 Antonio Diaz Diaz. This script is free software: you have unlimited permission diff --git a/doc/zutils.info b/doc/zutils.info index 1229e3bd8b4b2ba868146f238c4f1e26e16a0010..5ba19ac6de64c5e22797d1af813a5c5dcc9a6915 100644 GIT binary patch delta 544 zcmZvZ%}N6?5P)g5MI!!N@uJR26s6GG`iD2QvLIHmcu+*vCc7?lGfR?cSqgmv74jY; z?i=_7o;~S9=)sfOwThsJKr%D==F8+Q|FCfXl1WMZl9?#TW)PrIj6xm#Krks$$UM|8 z82pL^S_fSh{V1_?55AV>9EFWLXq(@$h_ha}Mai5s@h!(zJ;wp-yT%zfz#sQ@`MGPa7FIoRaX z2*8$Ashm~!YgTpd5Db~`^p0?8l>?iso5ICcdKI!jCC)ox&4;CX}jvQsJ+ gSGuuHwqcN-DwtJuWVwh9sa0BP1PQK7K7ZsCIz3U=3bS zHzHf2paHd76JlLO6_Q;QRk$pgTrZ%o`3^fb6O)d@WJWGgMy|<*d?Mb(3i)XYZk|4_ zhI-NIRW(UfMm0HAu^>ANQu9(W^U@Xa^At)lQepn(LiiRQT$*|cE}m{~lV`Fi@TO#@ zr6~Y|GC8+Ek883Cw=$!`1Jag9p+#oLrY^Wzx1IIs6aqb xeo{_qZgIVdnS}vV%sD?VIklif!80! copy || fail=1 +cmp in copy || fail=1 +echo -n . "${ZCAT}" in in.gz in.bz2 in.lz -- -in- > copy5 || fail=1 cmp in5 copy5 || fail=1 echo -n . +for i in ${extensions}; do + "${ZDIFF}" --cmp in.$i || fail=1 + echo -n . + "${ZDIFF}" --cmp in in.$i || fail=1 + echo -n . + "${ZDIFF}" --cmp in.$i in || fail=1 + echo -n . +done + + for i in ${extensions}; do "${ZDIFF}" in.$i || fail=1 echo -n . @@ -81,27 +94,23 @@ echo -n . echo -n . -for i in ${extensions}; do - "${ZDIFF}" --cmp in.$i || fail=1 - echo -n . - "${ZDIFF}" --cmp in in.$i || fail=1 - echo -n . - "${ZDIFF}" --cmp in.$i in || fail=1 - echo -n . -done - - for i in ${extensions}; do "${ZGREP}" License in.$i 2>&1 > /dev/null || fail=1 echo -n . done +"${ZGREP}" License in 2>&1 > /dev/null || fail=1 +echo -n . +"${ZGREP}" License -- -in- 2>&1 > /dev/null || fail=1 +echo -n . +"${ZGREP}" License -- -in-.lz 2>&1 > /dev/null || fail=1 +echo -n . "${ZGREP}" License in in.gz in.bz2 in.lz -- -in- 2>&1 > /dev/null || fail=1 echo -n . echo -if test ${fail} = 0; then +if [ ${fail} = 0 ]; then echo "tests completed successfully." cd "${objdir}" && rm -r tmp else diff --git a/zcat.in b/zcat.in index f5590ea..bf3f07a 100644 --- a/zcat.in +++ b/zcat.in @@ -7,11 +7,10 @@ LC_ALL=C export LC_ALL -invocation_name=$0 args= -default_prog=lzip +two_hyphens=0 -# Loop over args until pattern is found +# Loop over args until a filename is found while [ x"$1" != x ] ; do case "$1" in @@ -22,10 +21,10 @@ while [ x"$1" != x ] ; do echo "transparent concatenation of any combination of compressed and" echo "non-compressed files. If any given file is compressed, its uncompressed" echo "content is used. If a given file does not exist, zcat tries the" - echo "compressed file name corresponding to the default compressor selected." + echo "compressed file names corresponding to the supported compressors." echo "The supported compressors are gzip, bzip2, lzip and xz." echo - echo "Usage: ${invocation_name} [OPTIONS] [CAT_OPTIONS] [FILES]" + echo "Usage: $0 [OPTIONS] [CAT_OPTIONS] [FILES]" echo echo "CAT_OPTIONS are passed directly to cat." echo "The exit status from cat is preserved." @@ -33,13 +32,9 @@ while [ x"$1" != x ] ; do echo "Options:" echo " -h, --help display this help and exit" echo " -V, --version output version information and exit" - echo " --gzip use gzip as default decompressor" - echo " --bzip2 use bzip2 as default decompressor" - echo " --lzip use lzip as default decompressor (default)" - echo " --xz use xz as default decompressor" echo - echo "Report bugs to lzip-bug@nongnu.org" - echo "Lzip home page: http://www.nongnu.org/lzip/lzip.html" + echo "Report bugs to zutils-bug@nongnu.org" + echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html" exit 0 ;; --version | --ve* | -V) echo "Zcat VERSION" @@ -47,18 +42,10 @@ while [ x"$1" != x ] ; do echo "This script is free software: you have unlimited permission" echo "to copy, distribute and modify it." exit 0 ;; - --gz*) - default_prog=gzip ;; - --bz*) - default_prog=bzip2 ;; - --lz*) - default_prog=lzip ;; - --xz*) - default_prog=xz ;; -) ;; --) - shift; break ;; + shift ; two_hyphens=1 ; break ;; -?*) args="${args} $1" ;; *) @@ -67,41 +54,37 @@ while [ x"$1" != x ] ; do shift done -if test $# -eq 0; then - ${default_prog} -cd | cat ${args} - exit $? -fi retval=0 for i in "$@" ; do - prog="${default_prog} -cdfq" - case "$i" in - *.gz | *.tgz) - prog="gzip -cdfq" ;; - *.bz2 | *.tbz | *.tbz2) - prog="bzip2 -cdfq" ;; - *.lz | *.tlz) - prog="lzip -cdfq" ;; - *.xz | *.txz) - prog="xz -cdfq" ;; - *) - if test -f "$i"; then prog=cat - else - case ${default_prog} in - gzip) - if test -f "$i.gz"; then i="$i.gz"; fi ;; - bzip2) - if test -f "$i.bz2"; then i="$i.bz2"; fi ;; - lzip) - if test -f "$i.lz"; then i="$i.lz"; fi ;; - xz) - if test -f "$i.xz"; then i="$i.xz"; fi ;; + if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 + else + if [ -f "$i" ]; then + case "$i" in + *.gz | *.tgz) + prog="gzip -cdfq" ;; + *.bz2 | *.tbz | *.tbz2) + prog="bzip2 -cdfq" ;; + *.lz | *.tlz) + prog="lzip -cdfq" ;; + *.xz | *.txz) + prog="xz -cdfq" ;; + *) + prog=cat ;; esac - fi ;; - esac - ${prog} -- "$i" | cat ${args} - r=$? - test "$r" -ne 0 && retval="$r" + elif [ -f "$i.gz" ]; then i="$i.gz" ; prog="gzip -cdfq" + elif [ -f "$i.bz2" ]; then i="$i.bz2" ; prog="bzip2 -cdfq" + elif [ -f "$i.lz" ]; then i="$i.lz" ; prog="lzip -cdfq" + elif [ -f "$i.xz" ]; then i="$i.xz" ; prog="xz -cdfq" + else + echo "$0: File \"$i\" not found or not a regular file" 1>&2 + if [ ${retval} = 0 ]; then retval=1 ; fi + continue + fi + ${prog} -- "$i" | cat ${args} + r=$? + if [ $r != 0 ]; then retval=$r ; fi + fi done exit ${retval} diff --git a/zdiff.in b/zdiff.in index 4be41d8..21c3fbd 100644 --- a/zdiff.in +++ b/zdiff.in @@ -7,12 +7,11 @@ LC_ALL=C export LC_ALL -invocation_name=$0 args= -default_ext=.lz diff_prog=diff file1= file2= +two_hyphens=0 # Loop over args while [ x"$1" != x ] ; do @@ -28,25 +27,24 @@ while [ x"$1" != x ] ; do echo echo "Zcmp is a shortcut for \"zdiff --cmp\"" echo - echo "Usage: ${invocation_name} [OPTIONS] [DIFF_OPTIONS] FILE1 [FILE2]" + echo "Usage: $0 [OPTIONS] [DIFF_OPTIONS] FILE1 [FILE2]" echo - echo "Compares FILE1 to FILE2. If FILE2 is omitted, compares FILE1 to the" - echo "uncompressed contents of FILE1.[gz|bz2|lz] (depending on the default" - echo "compressor selected). DIFF_OPTIONS are passed directly to diff or cmp." + echo "Compares FILE1 to FILE2. If FILE2 is omitted and FILE1 is compressed," + echo "compares FILE1 to the file with the corresponding decompressed file" + echo "name (removes the extension from FILE1). If FILE2 is omitted and FILE1" + echo "is not compressed, compares FILE1 to the uncompressed contents of" + echo "FILE1.[gz|bz2|lz|xz] (the first one that is found)." + echo "DIFF_OPTIONS are passed directly to diff or cmp." echo "The exit status from diff or cmp is preserved." echo echo "Options:" echo " -h, --help display this help and exit" echo " -V, --version output version information and exit" - echo " --gzip use gzip as default decompressor" - echo " --bzip2 use bzip2 as default decompressor" - echo " --lzip use lzip as default decompressor (default)" - echo " --xz use xz as default decompressor" echo " --diff use diff to compare files (default)" echo " --cmp use cmp to compare files" echo - echo "Report bugs to lzip-bug@nongnu.org" - echo "Lzip home page: http://www.nongnu.org/lzip/lzip.html" + echo "Report bugs to zutils-bug@nongnu.org" + echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html" exit 0 ;; --version | --ve* | -V) echo "Zdiff VERSION" @@ -54,23 +52,15 @@ while [ x"$1" != x ] ; do echo "This script is free software: you have unlimited permission" echo "to copy, distribute and modify it." exit 0 ;; - --gz*) - default_ext=.gz ;; - --bz*) - default_ext=.bz2 ;; - --lz*) - default_ext=.lz ;; - --xz*) - default_prog=xz ;; --diff) diff_prog=diff ;; --cmp) diff_prog=cmp ;; -) - echo "${invocation_name}: reading from stdin not supported" + echo "$0: reading from stdin not supported" exit 1 ;; --) - shift; break ;; + shift; two_hyphens=1 ; break ;; -?*) args="${args} $1" ;; *) @@ -80,30 +70,30 @@ while [ x"$1" != x ] ; do done # Loop over files -while [ x"$1" != x ] ; do - if [ "$1" != "--" ] ; then - if test -f "$1"; then - if test -z "${file1}"; then file1="$1" +for i in "$@" ; do + if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 + else + if [ -f "$i" ]; then + if [ -z "${file1}" ]; then file1="$i" else - if test -z "${file2}"; then file2="$1" + if [ -z "${file2}" ]; then file2="$i" else - echo "${invocation_name}: Too many files; use --help for usage." 1>&2 + echo "$0: Too many files; use --help for usage." 1>&2 fi fi else - echo "${invocation_name}: File \"$1\" not found or not a regular file" 1>&2 + echo "$0: File \"$i\" not found or not a regular file" 1>&2 exit 1 fi fi - shift done -if test -z "${file1}"; then - echo "${invocation_name}: No files given; use --help for usage." 1>&2 +if [ -z "${file1}" ]; then + echo "$0: No files given; use --help for usage." 1>&2 exit 1 fi -if test -z "${file2}"; then +if [ -z "${file2}" ]; then case "${file1}" in *.gz) file2=`printf "%s" "${file1}" | sed 's/.gz$//'` ;; @@ -124,7 +114,14 @@ if test -z "${file2}"; then *.txz) file2=`printf "%s" "${file1}" | sed 's/txz$/tar/'` ;; *) - file2="${file1}${default_ext}" ;; + if [ -f "${file1}.gz" ]; then file2="${file1}.gz" + elif [ -f "${file1}.bz2" ]; then file2="${file1}.bz2" + elif [ -f "${file1}.lz" ]; then file2="${file1}.lz" + elif [ -f "${file1}.xz" ]; then file2="${file1}.xz" + else + echo "$0: Compressed version of ${file1} not found; use --help for usage." 1>&2 + exit 1 + fi ;; esac fi @@ -144,8 +141,8 @@ case "${file2}" in esac retval=0 -if test -n "${prog1}"; then - if test -n "${prog2}"; then +if [ -n "${prog1}" ]; then + if [ -n "${prog2}" ]; then tmp_file=`mktemp "${TMPDIR:-/tmp}"/zdiff.XXXXXXXXXX` || { echo 'cannot create a temporary file' 1>&2 exit 1 @@ -159,7 +156,7 @@ if test -n "${prog1}"; then retval=$? fi else - if test -n "${prog2}"; then + if [ -n "${prog2}" ]; then ${prog2} -cdfq -- "${file2}" | ${diff_prog} ${args} -- "${file1}" - retval=$? else diff --git a/zgrep.in b/zgrep.in index 3d9e8f3..7321bdb 100644 --- a/zgrep.in +++ b/zgrep.in @@ -7,12 +7,11 @@ LC_ALL=C export LC_ALL -invocation_name=$0 args= -default_prog=lzip have_pat=0 list=0 no_name=0 +two_hyphens=0 # Loop over args until pattern is found while [ x"$1" != x ] ; do @@ -25,10 +24,10 @@ while [ x"$1" != x ] ; do echo "transparent search on any combination of compressed and non-compressed" echo "files. If any given file is compressed, its uncompressed content is" echo "used. If a given file does not exist, zgrep tries the compressed file" - echo "name corresponding to the default compressor selected. The supported" - echo "compressors are gzip, bzip2, lzip and xz." + echo "names corresponding to the supported compressors." + echo "The supported compressors are gzip, bzip2, lzip and xz." echo - echo "Usage: ${invocation_name} [OPTIONS] [GREP_OPTIONS] PATTERN [FILES]" + echo "Usage: $0 [OPTIONS] [GREP_OPTIONS] PATTERN [FILES]" echo echo "GREP_OPTIONS are passed directly to grep." echo "The exit status from grep is preserved." @@ -36,13 +35,9 @@ while [ x"$1" != x ] ; do echo "Options:" echo " -h, --help display this help and exit" echo " -V, --version output version information and exit" - echo " --gzip use gzip as default decompressor" - echo " --bzip2 use bzip2 as default decompressor" - echo " --lzip use lzip as default decompressor (default)" - echo " --xz use xz as default decompressor" echo - echo "Report bugs to lzip-bug@nongnu.org" - echo "Lzip home page: http://www.nongnu.org/lzip/lzip.html" + echo "Report bugs to zutils-bug@nongnu.org" + echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html" exit 0 ;; --version | --ve* | -V) echo "Zgrep VERSION" @@ -50,16 +45,8 @@ while [ x"$1" != x ] ; do echo "This script is free software: you have unlimited permission" echo "to copy, distribute and modify it." exit 0 ;; - --gz*) - default_prog=gzip ;; - --bz*) - default_prog=bzip2 ;; - --lz*) - default_prog=lzip ;; - --xz*) - default_prog=xz ;; -[drRzZ] | --di* | --exc* | --inc* | --nu* | --rec*) - echo "${invocation_name}: option $1 not supported" + echo "$0: option $1 not supported" exit 1 ;; -e?* | -f?* | --file=* | --reg*=*) args="${args} $1"; have_pat=1 ;; @@ -74,69 +61,64 @@ while [ x"$1" != x ] ; do -h | --no-f*) args="${args} $1"; no_name=1 ;; --) - break ;; + shift ; two_hyphens=1 ; break ;; -?*) args="${args} $1" ;; *) - if test ${have_pat} = 0; then args="${args} $1"; have_pat=1 + if [ ${have_pat} = 0 ]; then args="${args} $1"; have_pat=1 else break fi ;; esac shift done -if test ${have_pat} = 0; then - echo "${invocation_name}: Pattern not found; use --help for usage." 1>&2 +if [ ${have_pat} = 0 ]; then + echo "$0: Pattern not found; use --help for usage." 1>&2 exit 1 fi -if test $# -eq 0; then - ${default_prog} -cdfq | grep ${args} - exit $? -fi - retval=0 for i in "$@" ; do - prog="${default_prog} -cdfq" - case "$i" in - *.gz | *.tgz) - prog="gzip -cdfq" ;; - *.bz2 | *.tbz | *.tbz2) - prog="bzip2 -cdfq" ;; - *.lz | *.tlz) - prog="lzip -cdfq" ;; - *.xz | *.txz) - prog="xz -cdfq" ;; - *) - if test -f "$i"; then prog=cat - else - case ${default_prog} in - gzip) - if test -f "$i.gz"; then i="$i.gz"; fi ;; - bzip2) - if test -f "$i.bz2"; then i="$i.bz2"; fi ;; - lzip) - if test -f "$i.lz"; then i="$i.lz"; fi ;; - xz) - if test -f "$i.xz"; then i="$i.xz"; fi ;; - esac - fi ;; - esac - if test ${list} -eq 1; then - ${prog} -- "$i" | grep ${args} 2>&1 > /dev/null && echo "$i" - r=$? - elif test $# -eq 1 -o ${no_name} -eq 1; then - ${prog} -- "$i" | grep ${args} - r=$? + if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 else - j=`printf "%s" "$i" | sed 's/\\\\/\\\\\\\\/g'` - j=`printf "%s" "$j" | sed 's/|/\\\\|/g'` - j=`printf "%s" "$j" | sed 's/&/\\\\&/g'` - j=`printf "%s" "$j" | tr '\n' ' '` - ${prog} -- "$i" | grep ${args} | sed "s|^|${j}:|" - r=$? + if [ -f "$i" ]; then + case "$i" in + *.gz | *.tgz) + prog="gzip -cdfq" ;; + *.bz2 | *.tbz | *.tbz2) + prog="bzip2 -cdfq" ;; + *.lz | *.tlz) + prog="lzip -cdfq" ;; + *.xz | *.txz) + prog="xz -cdfq" ;; + *) + prog=cat ;; + esac + elif [ -f "$i.gz" ]; then i="$i.gz" ; prog="gzip -cdfq" + elif [ -f "$i.bz2" ]; then i="$i.bz2" ; prog="bzip2 -cdfq" + elif [ -f "$i.lz" ]; then i="$i.lz" ; prog="lzip -cdfq" + elif [ -f "$i.xz" ]; then i="$i.xz" ; prog="xz -cdfq" + else + echo "$0: File \"$i\" not found or not a regular file" 1>&2 + if [ ${retval} = 0 ]; then retval=1 ; fi + continue + fi + if [ ${list} = 1 ]; then + ${prog} -- "$i" | grep ${args} 2>&1 > /dev/null && echo "$i" + r=$? + elif [ $# = 1 ] || [ ${no_name} = 1 ]; then + ${prog} -- "$i" | grep ${args} + r=$? + else + j=`printf "%s" "$i" | sed 's/\\\\/\\\\\\\\/g'` + j=`printf "%s" "$j" | sed 's/|/\\\\|/g'` + j=`printf "%s" "$j" | sed 's/&/\\\\&/g'` + j=`printf "%s" "$j" | tr '\n' ' '` + ${prog} -- "$i" | grep ${args} | sed "s|^|${j}:|" + r=$? + fi + [ $r != 0 ] && retval="$r" fi - test "$r" -ne 0 && retval="$r" done exit ${retval}