From 7799d0c878e8c42d25e4ded2dfd6c684ab70aca9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 24 Feb 2025 04:58:43 +0100 Subject: [PATCH] Merging upstream version 0.7. Signed-off-by: Daniel Baumann --- ChangeLog | 6 +++ Makefile.in | 23 +++++++--- NEWS | 7 +++- README | 6 +-- configure | 4 +- doc/zcat.1 | 7 +++- doc/zdiff.1 | 6 +-- doc/zgrep.1 | 4 +- doc/ztest.1 | 40 ++++++++++++++++++ doc/zutils.info | Bin 6062 -> 7251 bytes doc/zutils.texinfo | 64 ++++++++++++++++++++++++---- main.cc | 4 +- testsuite/check.sh | 22 ++++++---- zcat.in | 39 ++++++++++------- zdiff.in | 46 +++++++++----------- zgrep.in | 34 +++++++-------- ztest.in | 102 +++++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 318 insertions(+), 96 deletions(-) create mode 100644 doc/ztest.1 create mode 100644 ztest.in diff --git a/ChangeLog b/ChangeLog index 4a0b508..9b76424 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-10-21 Antonio Diaz Diaz + + * Version 0.7 released. + * Added new utility; ztest. + * zcat.in: Added new option "--recursive". + 2009-10-05 Antonio Diaz Diaz * Version 0.6 released. diff --git a/Makefile.in b/Makefile.in index a3c14ba..edaf42f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -8,7 +8,7 @@ INSTALL_DIR = $(INSTALL) -d -m 755 SHELL = /bin/sh objs = arg_parser.o main.o -scripts = zcat zcmp zdiff zegrep zfgrep zgrep +scripts = zcat zcmp zdiff zegrep zfgrep zgrep ztest .PHONY : all install install-info install-man install-strip \ @@ -47,6 +47,10 @@ zgrep : zgrep.in sed -e 's,VERSION,$(progversion),g' $(VPATH)/zgrep.in > zgrep chmod a+x zgrep +ztest : ztest.in + sed -e 's,VERSION,$(progversion),g' $(VPATH)/ztest.in > ztest + chmod a+x ztest + main.o : main.cc $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(progversion)\" -c -o $@ $< @@ -65,7 +69,8 @@ info : $(VPATH)/doc/$(progname).info $(VPATH)/doc/$(progname).info : $(VPATH)/doc/$(progname).texinfo cd $(VPATH)/doc && makeinfo $(progname).texinfo -man : $(VPATH)/doc/zcat.1 $(VPATH)/doc/zdiff.1 $(VPATH)/doc/zgrep.1 +man : $(VPATH)/doc/zcat.1 $(VPATH)/doc/zdiff.1 \ + $(VPATH)/doc/zgrep.1 $(VPATH)/doc/ztest.1 $(VPATH)/doc/zcat.1 : zcat help2man -n 'concatenate compressed files to stdout' \ @@ -79,6 +84,10 @@ $(VPATH)/doc/zgrep.1 : zgrep help2man -n 'search compressed files for a regular expression' \ -o $(VPATH)/doc/zgrep.1 --no-info ./zgrep +$(VPATH)/doc/ztest.1 : ztest + help2man -n 'verify integrity of compressed files' \ + -o $(VPATH)/doc/ztest.1 --no-info ./ztest + Makefile : $(VPATH)/configure $(VPATH)/Makefile.in ./config.status @@ -86,7 +95,7 @@ check : all $(VPATH)/testsuite/check.sh @$(VPATH)/testsuite/check.sh $(VPATH)/testsuite install : all install-info install-man - if test ! -d $(DESTDIR)$(bindir) ; then $(INSTALL_DIR) $(DESTDIR)$(bindir) ; fi + if [ ! -d $(DESTDIR)$(bindir) ] ; then $(INSTALL_DIR) $(DESTDIR)$(bindir) ; fi $(INSTALL_PROGRAM) ./$(progname) $(DESTDIR)$(bindir)/$(progname) $(INSTALL_SCRIPT) zcat $(DESTDIR)$(bindir)/zcat $(INSTALL_SCRIPT) zcmp $(DESTDIR)$(bindir)/zcmp @@ -94,14 +103,15 @@ install : all install-info install-man $(INSTALL_SCRIPT) zegrep $(DESTDIR)$(bindir)/zegrep $(INSTALL_SCRIPT) zfgrep $(DESTDIR)$(bindir)/zfgrep $(INSTALL_SCRIPT) zgrep $(DESTDIR)$(bindir)/zgrep + $(INSTALL_SCRIPT) ztest $(DESTDIR)$(bindir)/ztest install-info : - if test ! -d $(DESTDIR)$(infodir) ; then $(INSTALL_DIR) $(DESTDIR)$(infodir) ; fi + if [ ! -d $(DESTDIR)$(infodir) ] ; then $(INSTALL_DIR) $(DESTDIR)$(infodir) ; fi $(INSTALL_DATA) $(VPATH)/doc/$(progname).info $(DESTDIR)$(infodir)/$(progname).info -install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$(progname).info install-man : - if test ! -d $(DESTDIR)$(mandir)/man1 ; then $(INSTALL_DIR) $(DESTDIR)$(mandir)/man1 ; fi + if [ ! -d $(DESTDIR)$(mandir)/man1 ] ; then $(INSTALL_DIR) $(DESTDIR)$(mandir)/man1 ; fi $(INSTALL_DATA) $(VPATH)/doc/zcat.1 $(DESTDIR)$(mandir)/man1/zcat.1 -rm -f $(DESTDIR)$(mandir)/man1/zcmp.1 cd $(DESTDIR)$(mandir)/man1 && ln -s zdiff.1 zcmp.1 @@ -111,6 +121,7 @@ install-man : -rm -f $(DESTDIR)$(mandir)/man1/zfgrep.1 cd $(DESTDIR)$(mandir)/man1 && ln -s zgrep.1 zegrep.1 cd $(DESTDIR)$(mandir)/man1 && ln -s zgrep.1 zfgrep.1 + $(INSTALL_DATA) $(VPATH)/doc/ztest.1 $(DESTDIR)$(mandir)/man1/ztest.1 install-strip : all $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install @@ -123,6 +134,7 @@ uninstall : uninstall-info uninstall-man -rm -f $(DESTDIR)$(bindir)/zegrep -rm -f $(DESTDIR)$(bindir)/zfgrep -rm -f $(DESTDIR)$(bindir)/zgrep + -rm -f $(DESTDIR)$(bindir)/ztest uninstall-info : -install-info --info-dir=$(DESTDIR)$(infodir) --remove $(DESTDIR)$(infodir)/$(progname).info @@ -135,6 +147,7 @@ uninstall-man : -rm -f $(DESTDIR)$(mandir)/man1/zegrep.1 -rm -f $(DESTDIR)$(mandir)/man1/zfgrep.1 -rm -f $(DESTDIR)$(mandir)/man1/zgrep.1 + -rm -f $(DESTDIR)$(mandir)/man1/ztest.1 dist : ln -sf $(VPATH) $(DISTNAME) diff --git a/NEWS b/NEWS index 4cd06b6..f089972 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ -Changes in version 0.6: +Changes in version 0.7: -Format of data read from stdin is now automatically detected. +The new utility ztest, able to recursively test all the compressed files +in a directory tree, has been added. + +The option "--recursive" has been added to zcat. diff --git a/README b/README index c1454bc..2550b69 100644 --- a/README +++ b/README @@ -2,10 +2,10 @@ Description Zutils is a collection of utilities for dealing with any combination of compressed and non-compressed files transparently. The supported -compressors are gzip, bzip2, lzip and xz. +compressors are bzip2, gzip, lzip and xz. -The currently provided utilities are zcat, zcmp, zdiff, zegrep, zfgrep -and zgrep. +The currently provided utilities are zcat, zcmp, zdiff, zegrep, zfgrep, +zgrep and ztest. Copyright (C) 2009 Antonio Diaz Diaz. diff --git a/configure b/configure index 100a1e2..c8eda48 100755 --- a/configure +++ b/configure @@ -5,12 +5,12 @@ # This configure script is free software: you have unlimited permission # to copy, distribute and modify it. # -# Date of this version: 2009-10-05 +# Date of this version: 2009-10-21 args= no_create= progname=zutils -progversion=0.6 +progversion=0.7 srctrigger=zdiff.in # clear some things potentially inherited from environment. diff --git a/doc/zcat.1 b/doc/zcat.1 index 6789957..5187b27 100644 --- a/doc/zcat.1 +++ b/doc/zcat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZCAT "1" "October 2009" "Zcat 0.6" "User Commands" +.TH ZCAT "1" "October 2009" "Zcat 0.7" "User Commands" .SH NAME Zcat \- concatenate compressed files to stdout .SH SYNOPSIS @@ -16,7 +16,7 @@ corresponding to the supported compressors. If no files are specified, data is read from standard input, decompressed if needed, and sent to stdout. Data read from standard input must be of the same type; all uncompressed or all compressed with the same compressor. -The supported compressors are gzip, bzip2, lzip and xz. +The supported compressors are bzip2, gzip, lzip and xz. .PP CAT_OPTIONS are passed directly to cat. The exit status from cat is preserved. @@ -27,6 +27,9 @@ display this help and exit .TP \fB\-V\fR, \fB\-\-version\fR output version information and exit +.TP +\fB\-r\fR, \fB\-\-recursive\fR +operate recursively on directories .SH "REPORTING BUGS" Report bugs to zutils\-bug@nongnu.org Zutils home page: http://www.nongnu.org/zutils/zutils.html diff --git a/doc/zdiff.1 b/doc/zdiff.1 index cf19d27..896d735 100644 --- a/doc/zdiff.1 +++ b/doc/zdiff.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZDIFF "1" "October 2009" "Zdiff 0.6" "User Commands" +.TH ZDIFF "1" "October 2009" "Zdiff 0.7" "User Commands" .SH NAME Zdiff \- compare compressed files .SH SYNOPSIS @@ -11,7 +11,7 @@ Zdiff \- Diff/cmp wrapper for compressed files. Zdiff is a wrapper script around the diff and cmp commands that allows transparent comparison of any combination of compressed and non\-compressed files. If any given file is compressed, its uncompressed -content is used. The supported compressors are gzip, bzip2, lzip and xz. +content is used. The supported compressors are bzip2, gzip, lzip and xz. .PP Zcmp is a shortcut for "zdiff \fB\-\-cmp\fR" .PP @@ -19,7 +19,7 @@ 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). +FILE1.[bz2|gz|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 diff --git a/doc/zgrep.1 b/doc/zgrep.1 index fc22717..92c4010 100644 --- a/doc/zgrep.1 +++ b/doc/zgrep.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZGREP "1" "October 2009" "Zgrep 0.6" "User Commands" +.TH ZGREP "1" "October 2009" "Zgrep 0.7" "User Commands" .SH NAME Zgrep \- search compressed files for a regular expression .SH SYNOPSIS @@ -16,7 +16,7 @@ names corresponding to the supported compressors. If no files are specified, data is read from standard input, decompressed if needed, and fed to grep. Data read from standard input must be of the same type; all uncompressed or all compressed with the same compressor. -The supported compressors are gzip, bzip2, lzip and xz. +The supported compressors are bzip2, gzip, lzip and xz. .PP Zegrep is a shortcut for "zgrep \fB\-E\fR" Zfgrep is a shortcut for "zgrep \fB\-F\fR" diff --git a/doc/ztest.1 b/doc/ztest.1 new file mode 100644 index 0000000..f32c7d7 --- /dev/null +++ b/doc/ztest.1 @@ -0,0 +1,40 @@ +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. +.TH ZTEST "1" "October 2009" "Ztest 0.7" "User Commands" +.SH NAME +Ztest \- verify integrity of compressed files +.SH SYNOPSIS +.B ztest +[\fIOPTIONS\fR] [\fIFILES\fR] +.SH DESCRIPTION +Ztest \- Test integrity of compressed files. +.PP +Ztest verifies the integrity of the specified compressed files. +Non\-compressed files are ignored. If no files are specified, the +integrity of compressed data read from standard input is verified. Data +read from standard input must be all compressed with the same compressor. +The supported compressors are bzip2, gzip, lzip and xz. +.PP +The exit status is 1 if any compressed file is corrupt, 0 otherwise. +.SH OPTIONS +.TP +\fB\-h\fR, \fB\-\-help\fR +display this help and exit +.TP +\fB\-V\fR, \fB\-\-version\fR +output version information and exit +.TP +\fB\-q\fR, \fB\-\-quiet\fR +suppress all messages +.TP +\fB\-r\fR, \fB\-\-recursive\fR +operate recursively on directories +.TP +\fB\-v\fR, \fB\-\-verbose\fR +be verbose (a 2nd \fB\-v\fR gives more) +.SH "REPORTING BUGS" +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 +to copy, distribute and modify it. diff --git a/doc/zutils.info b/doc/zutils.info index 34f390b0572df0a8325e2e34fd552b942871e8ca..ba5ff0ac9ff10542c78246c4b68338aadf8827f3 100644 GIT binary patch delta 1025 zcmbVLO-~a+7*0!R$`FD=h+m+u#snm7p^KDSz4!qMQ7MFKLJ0}e-PvW5?anegEzp?k zZ_v4T^$!@6o;{d&)r)s8{sH0-FwV@n1U)*JnR#a3=Y8jSpLxIVt@dFqGY-#j(8WHQ zPlmjcDGjd_!K%ns=F3b=kVw?)BO^^U)4&572;y-nPJp?C$?VU}XuD5Cs|cQ&MCjw2js7386XOYt&bhBStsNqiqz7jzAj~h1*Lycz+AC-0pnTX$m#s_O-+N& z%XOZ~!2(M>eq|D9lvd)D;faEge3-vnfKE3O&?fS9d?thBX?`x&TB_@Hl!#`uh26$x zbG@;#y$8E%>(5rV_Yi8T_mE>MAQD(~Bb{Lps0-NllNTfjPoVL%2o+$ePJToqQZ~ei zI8iqY85fB-F7thMB!7**9a1&Ot-|eCb@H%FiO^j<{L{rP4FEH}q%0`Iwj$BWnamxv zz@C;*h5Ww_ba0Qvyv-tGq28b5FNuMm!yKYAAFw0SM$_bzR0)@HAlN=IGC;_gZTebH z1YPTLEd`W%vr4qU<^)G1Wl{OG>3z~8zA>X5nV7q%TXNoN)xo2Q&$+^UV*I*%H+5^+ zd;u9xU6uJui*aqqQvPvB9a=UPamA`Eo$Wi}Ld&798(Y@BT8e5n$4k{pH3c+Ze0Qai r-q_@J1G|jNts-0{y6z%(S$6BSSMYm?+4$dSep{ z6R1EyQGQZRYHo48iK&GpRLnU)FFCcKM8PvJCAFg7)X>nJOP in || framework_failure - $i in || framework_failure - echo -n . + $i in || compressor_needed done +echo -n "testing zutils..." cat "${testdir}"/../COPYING > in || framework_failure cat in > -in- || framework_failure cat in.lz > -in-.lz || framework_failure @@ -136,16 +137,21 @@ echo -n . "${ZFGREP}" License in 2>&1 > /dev/null || fail=1 echo -n . -if [ "gzip" != `"${ZUTILS}" -t in.gz` ]; then fail=1 ; fi +"${ZTEST}" in in.gz in.bz2 in.lz -- -in- || fail=1 echo -n . -if [ "bzip2" != `"${ZUTILS}" -t in.bz2` ]; then fail=1 ; fi +"${ZTEST}" -r . || fail=1 echo -n . -if [ "lzip" != `"${ZUTILS}" -t in.lz` ]; then fail=1 ; fi + +if [ "bzip2" != `"${ZUTILS}" -t in.bz2` ] ; then fail=1 ; fi +echo -n . +if [ "gzip" != `"${ZUTILS}" -t in.gz` ] ; then fail=1 ; fi +echo -n . +if [ "lzip" != `"${ZUTILS}" -t in.lz` ] ; then fail=1 ; fi echo -n . echo -if [ ${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 fb7ab73..010b7bb 100644 --- a/zcat.in +++ b/zcat.in @@ -8,6 +8,9 @@ LC_ALL=C export LC_ALL args= +gz_args= +xz_args= +recursive=0 two_hyphens=0 # Loop over args until a filename is found @@ -25,7 +28,7 @@ while [ x"$1" != x ] ; do echo "data is read from standard input, decompressed if needed, and sent to" echo "stdout. Data read from standard input must be of the same type; all" echo "uncompressed or all compressed with the same compressor." - echo "The supported compressors are gzip, bzip2, lzip and xz." + echo "The supported compressors are bzip2, gzip, lzip and xz." echo echo "Usage: $0 [OPTIONS] [CAT_OPTIONS] [FILES]" echo @@ -35,6 +38,7 @@ while [ x"$1" != x ] ; do echo "Options:" echo " -h, --help display this help and exit" echo " -V, --version output version information and exit" + echo " -r, --recursive operate recursively on directories" echo echo "Report bugs to zutils-bug@nongnu.org" echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html" @@ -45,8 +49,12 @@ while [ x"$1" != x ] ; do echo "This script is free software: you have unlimited permission" echo "to copy, distribute and modify it." exit 0 ;; - - | -f) + - | -c | --st* | -d | --de* | -f | --fo* | -q | --qu* | -L | --lic* ) ;; + -l | --lis*) + gz_args="${gz_args} $1"; xz_args="${xz_args} $1" ;; + -r | --re*) + recursive=1 ;; --) shift ; two_hyphens=1 ; break ;; -?*) @@ -57,14 +65,14 @@ while [ x"$1" != x ] ; do shift done -if [ $# = 0 ]; then +if [ $# = 0 ] ; then bindir=`echo "$0" | sed -e 's,[^/]*$,,'` prog_name=`"${bindir}"zutils -t` case "${prog_name}" in - gzip) prog="gzip -cdfq" ;; bzip2) prog="bzip2 -cdfq" ;; + gzip) prog="gzip -cdfq ${gz_args}" ;; lzip) prog="lzip -cdfq" ;; - xz) prog="xz -cdfq" ;; + xz) prog="xz -cdfq ${xz_args}" ;; *) prog=cat ;; esac { "${bindir}"zutils -m ${prog_name} ; cat ; } | ${prog} | cat ${args} @@ -75,29 +83,32 @@ retval=0 for i in "$@" ; do if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 else - if [ ! -f "$i" ]; then - if [ -f "$i.gz" ]; then i="$i.gz" - elif [ -f "$i.bz2" ]; then i="$i.bz2" - elif [ -f "$i.lz" ]; then i="$i.lz" - elif [ -f "$i.xz" ]; then i="$i.xz" + if [ ! -f "$i" ] ; then + if [ -f "$i.gz" ] ; then i="$i.gz" + elif [ -f "$i.bz2" ] ; then i="$i.bz2" + elif [ -f "$i.lz" ] ; then i="$i.lz" + elif [ -f "$i.xz" ] ; then i="$i.xz" + elif [ ${recursive} = 1 ] && [ -d "$i" ] ; then + find "$i" -type f -exec "$0" '{}' ';' + continue else echo "$0: File \"$i\" not found or not a regular file" 1>&2 - if [ ${retval} = 0 ]; then retval=1 ; fi + if [ ${retval} = 0 ] ; then retval=1 ; fi continue fi fi bindir=`echo "$0" | sed -e 's,[^/]*$,,'` prog_name=`"${bindir}"zutils -t -- "$i"` case "${prog_name}" in - gzip) prog="gzip -cdfq" ;; bzip2) prog="bzip2 -cdfq" ;; + gzip) prog="gzip -cdfq ${gz_args}" ;; lzip) prog="lzip -cdfq" ;; - xz) prog="xz -cdfq" ;; + xz) prog="xz -cdfq ${xz_args}" ;; *) prog=cat ;; esac ${prog} -- "$i" | cat ${args} r=$? - if [ $r != 0 ]; then retval=$r ; fi + if [ $r != 0 ] ; then retval=$r ; fi fi done diff --git a/zdiff.in b/zdiff.in index 9ac0a58..0ece51f 100644 --- a/zdiff.in +++ b/zdiff.in @@ -23,7 +23,7 @@ while [ x"$1" != x ] ; do echo "Zdiff is a wrapper script around the diff and cmp commands that allows" echo "transparent comparison of any combination of compressed and" echo "non-compressed files. If any given file is compressed, its uncompressed" - echo "content is used. The supported compressors are gzip, bzip2, lzip and xz." + echo "content is used. The supported compressors are bzip2, gzip, lzip and xz." echo echo "Zcmp is a shortcut for \"zdiff --cmp\"" echo @@ -33,7 +33,7 @@ while [ x"$1" != x ] ; do 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 "FILE1.[bz2|gz|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 @@ -73,10 +73,10 @@ done for i in "$@" ; do if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 else - if [ -f "$i" ]; then - if [ -z "${file1}" ]; then file1="$i" + if [ -f "$i" ] ; then + if [ -z "${file1}" ] ; then file1="$i" else - if [ -z "${file2}" ]; then file2="$i" + if [ -z "${file2}" ] ; then file2="$i" else echo "$0: Too many files; use --help for usage." 1>&2 fi @@ -88,27 +88,27 @@ for i in "$@" ; do fi done -if [ -z "${file1}" ]; then +if [ -z "${file1}" ] ; then echo "$0: No files given; use --help for usage." 1>&2 exit 1 fi -if [ -z "${file2}" ]; then +if [ -z "${file2}" ] ; then case "${file1}" in - *.gz) file2=`printf "%s" "${file1}" | sed -e 's,.gz$,,'` ;; - *.tgz) file2=`printf "%s" "${file1}" | sed -e 's,tgz$,tar,'` ;; *.bz2) file2=`printf "%s" "${file1}" | sed -e 's,.bz2$,,'` ;; *.tbz) file2=`printf "%s" "${file1}" | sed -e 's,tbz$,tar,'` ;; *.tbz2) file2=`printf "%s" "${file1}" | sed -e 's,tbz2$,tar,'` ;; + *.gz) file2=`printf "%s" "${file1}" | sed -e 's,.gz$,,'` ;; + *.tgz) file2=`printf "%s" "${file1}" | sed -e 's,tgz$,tar,'` ;; *.lz) file2=`printf "%s" "${file1}" | sed -e 's,.lz$,,'` ;; *.tlz) file2=`printf "%s" "${file1}" | sed -e 's,tlz$,tar,'` ;; *.xz) file2=`printf "%s" "${file1}" | sed -e 's,.xz$,,'` ;; *.txz) file2=`printf "%s" "${file1}" | sed -e 's,txz$,tar,'` ;; *) - 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" + if [ -f "${file1}.bz2" ] ; then file2="${file1}.bz2" + elif [ -f "${file1}.gz" ] ; then file2="${file1}.gz" + 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 @@ -119,28 +119,22 @@ fi prog1= prog2= bindir=`echo "$0" | sed -e 's,[^/]*$,,'` -if [ -f "${file1}" ]; then +if [ -f "${file1}" ] ; then prog_name=`"${bindir}"zutils -t -- "${file1}"` case "${prog_name}" in - gzip) prog1=gzip ;; - bzip2) prog1=bzip2 ;; - lzip) prog1=lzip ;; - xz) prog1=xz ;; + bzip2 | gzip | lzip | xz) prog1=${prog_name} ;; esac fi -if [ -f "${file2}" ]; then +if [ -f "${file2}" ] ; then prog_name=`"${bindir}"zutils -t -- "${file2}"` case "${prog_name}" in - gzip) prog2=gzip ;; - bzip2) prog2=bzip2 ;; - lzip) prog2=lzip ;; - xz) prog2=xz ;; + bzip2 | gzip | lzip | xz) prog2=${prog_name} ;; esac fi retval=0 -if [ -n "${prog1}" ]; then - if [ -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 @@ -154,7 +148,7 @@ if [ -n "${prog1}" ]; then retval=$? fi else - if [ -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 df400c3..3298646 100644 --- a/zgrep.in +++ b/zgrep.in @@ -28,7 +28,7 @@ while [ x"$1" != x ] ; do echo "specified, data is read from standard input, decompressed if needed, and" echo "fed to grep. Data read from standard input must be of the same type; all" echo "uncompressed or all compressed with the same compressor." - echo "The supported compressors are gzip, bzip2, lzip and xz." + echo "The supported compressors are bzip2, gzip, lzip and xz." echo echo "Zegrep is a shortcut for \"zgrep -E\"" echo "Zfgrep is a shortcut for \"zgrep -F\"" @@ -71,26 +71,23 @@ while [ x"$1" != x ] ; do -?*) args="${args} $1" ;; *) - if [ ${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 [ ${have_pat} = 0 ]; then +if [ ${have_pat} = 0 ] ; then echo "$0: Pattern not found; use --help for usage." 1>&2 exit 1 fi -if [ $# = 0 ]; then +if [ $# = 0 ] ; then bindir=`echo "$0" | sed -e 's,[^/]*$,,'` prog_name=`"${bindir}"zutils -t` case "${prog_name}" in - gzip) prog="gzip -cdfq" ;; - bzip2) prog="bzip2 -cdfq" ;; - lzip) prog="lzip -cdfq" ;; - xz) prog="xz -cdfq" ;; + bzip2 | gzip | lzip | xz) prog="${prog_name} -cdfq" ;; *) prog=cat ;; esac { "${bindir}"zutils -m ${prog_name} ; cat ; } | ${prog} | grep ${args} @@ -101,30 +98,27 @@ retval=0 for i in "$@" ; do if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 else - if [ ! -f "$i" ]; then - if [ -f "$i.gz" ]; then i="$i.gz" - elif [ -f "$i.bz2" ]; then i="$i.bz2" - elif [ -f "$i.lz" ]; then i="$i.lz" - elif [ -f "$i.xz" ]; then i="$i.xz" + if [ ! -f "$i" ] ; then + if [ -f "$i.gz" ] ; then i="$i.gz" + elif [ -f "$i.bz2" ] ; then i="$i.bz2" + elif [ -f "$i.lz" ] ; then i="$i.lz" + elif [ -f "$i.xz" ] ; then i="$i.xz" else echo "$0: File \"$i\" not found or not a regular file" 1>&2 - if [ ${retval} = 0 ]; then retval=1 ; fi + if [ ${retval} = 0 ] ; then retval=1 ; fi continue fi fi bindir=`echo "$0" | sed -e 's,[^/]*$,,'` prog_name=`"${bindir}"zutils -t -- "$i"` case "${prog_name}" in - gzip) prog="gzip -cdfq" ;; - bzip2) prog="bzip2 -cdfq" ;; - lzip) prog="lzip -cdfq" ;; - xz) prog="xz -cdfq" ;; + bzip2 | gzip | lzip | xz) prog="${prog_name} -cdfq" ;; *) prog=cat ;; esac - if [ ${list} = 1 ]; then + if [ ${list} = 1 ] ; then ${prog} -- "$i" | grep ${args} 2>&1 > /dev/null && echo "$i" r=$? - elif [ $# = 1 ] || [ ${no_name} = 1 ]; then + elif [ $# = 1 ] || [ ${no_name} = 1 ] ; then ${prog} -- "$i" | grep ${args} r=$? else diff --git a/ztest.in b/ztest.in new file mode 100644 index 0000000..f56c853 --- /dev/null +++ b/ztest.in @@ -0,0 +1,102 @@ +#! /bin/sh +# Ztest - Test integrity of compressed files. +# Copyright (C) 2009 Antonio Diaz Diaz. +# +# This script is free software: you have unlimited permission +# to copy, distribute and modify it. + +LC_ALL=C +export LC_ALL +args= +recursive=0 +two_hyphens=0 + +# Loop over args until a filename is found +while [ x"$1" != x ] ; do + + case "$1" in + --help | --he* | -h) + echo "Ztest - Test integrity of compressed files." + echo + echo "Ztest verifies the integrity of the specified compressed files." + echo "Non-compressed files are ignored. If no files are specified, the" + echo "integrity of compressed data read from standard input is verified. Data" + echo "read from standard input must be all compressed with the same compressor." + echo "The supported compressors are bzip2, gzip, lzip and xz." + echo + echo "Usage: $0 [OPTIONS] [FILES]" + echo + echo "The exit status is 1 if any compressed file is corrupt, 0 otherwise." + echo + echo "Options:" + echo " -h, --help display this help and exit" + echo " -V, --version output version information and exit" + echo " -q, --quiet suppress all messages" + echo " -r, --recursive operate recursively on directories" + echo " -v, --verbose be verbose (a 2nd -v gives more)" + echo + 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 "Ztest VERSION" + echo "Copyright (C) 2009 Antonio Diaz Diaz." + echo "This script is free software: you have unlimited permission" + echo "to copy, distribute and modify it." + exit 0 ;; + -r | --re*) + recursive=1 ;; + -v | -vv | -vvv | --ve* | -q | --qu*) + args="${args} $1" ;; + --) + shift ; two_hyphens=1 ; break ;; + - | -?*) + ;; + *) + break ;; + esac + shift +done + +if [ $# = 0 ] ; then + bindir=`echo "$0" | sed -e 's,[^/]*$,,'` + prog=`"${bindir}"zutils -t` + case "${prog}" in + bzip2 | gzip | lzip | xz) + ;; + *) echo "$0: Unknown data format read from stdin" 1>&2 + exit 1 ;; + esac + { "${bindir}"zutils -m ${prog} ; cat ; } | ${prog} -t ${args} + exit $? +fi + +retval=0 +for i in "$@" ; do + if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1 + else + if [ ! -f "$i" ] ; then + if [ ${recursive} = 1 ] && [ -d "$i" ] ; then + bad_files=`find "$i" -type f \( -exec "$0" ${args} '{}' ';' -o -print \)` + if [ ${retval} = 0 ] && [ -n "${bad_files}" ] ; then retval=1 ; fi + continue + else + echo "$0: File \"$i\" not found or not a regular file" 1>&2 + if [ ${retval} = 0 ] ; then retval=1 ; fi + continue + fi + fi + bindir=`echo "$0" | sed -e 's,[^/]*$,,'` + prog=`"${bindir}"zutils -t -- "$i"` + case "${prog}" in + bzip2 | gzip | lzip | xz) + ;; + *) continue ;; + esac + ${prog} -t ${args} -- "$i" + r=$? + if [ $r != 0 ] ; then retval=$r ; fi + fi +done + +exit ${retval}