diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 16:12:41 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 16:12:41 +0000 |
commit | b1a0f85fe3a832e8b91ef367399cd76632d633f4 (patch) | |
tree | 3fcdbbc4f8b21f1a1f518321828bf456ca6e8601 | |
parent | Adding upstream version 0.6. (diff) | |
download | zutils-b1a0f85fe3a832e8b91ef367399cd76632d633f4.tar.xz zutils-b1a0f85fe3a832e8b91ef367399cd76632d633f4.zip |
Adding upstream version 0.7.upstream/0.7
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Makefile.in | 23 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | README | 6 | ||||
-rwxr-xr-x | configure | 4 | ||||
-rw-r--r-- | doc/zcat.1 | 7 | ||||
-rw-r--r-- | doc/zdiff.1 | 6 | ||||
-rw-r--r-- | doc/zgrep.1 | 4 | ||||
-rw-r--r-- | doc/ztest.1 | 40 | ||||
-rw-r--r-- | doc/zutils.info | bin | 6062 -> 7251 bytes | |||
-rw-r--r-- | doc/zutils.texinfo | 64 | ||||
-rw-r--r-- | main.cc | 4 | ||||
-rwxr-xr-x | testsuite/check.sh | 22 | ||||
-rw-r--r-- | zcat.in | 39 | ||||
-rw-r--r-- | zdiff.in | 46 | ||||
-rw-r--r-- | zgrep.in | 34 | ||||
-rw-r--r-- | ztest.in | 102 |
17 files changed, 318 insertions, 96 deletions
@@ -1,3 +1,9 @@ +2009-10-21 Antonio Diaz Diaz <ant_diaz@teleline.es> + + * Version 0.7 released. + * Added new utility; ztest. + * zcat.in: Added new option "--recursive". + 2009-10-05 Antonio Diaz Diaz <ant_diaz@teleline.es> * 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) @@ -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. @@ -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. @@ -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. @@ -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 Binary files differindex 34f390b..ba5ff0a 100644 --- a/doc/zutils.info +++ b/doc/zutils.info diff --git a/doc/zutils.texinfo b/doc/zutils.texinfo index 3902270..d6f724d 100644 --- a/doc/zutils.texinfo +++ b/doc/zutils.texinfo @@ -1,12 +1,12 @@ \input texinfo @c -*-texinfo-*- @c %**start of header @setfilename zutils.info -@settitle Zutils +@settitle Zutils Manual @finalout @c %**end of header -@set UPDATED 5 October 2009 -@set VERSION 0.6 +@set UPDATED 21 October 2009 +@set VERSION 0.7 @dircategory Data Compression @direntry @@ -36,6 +36,7 @@ This manual is for Zutils (version @value{VERSION}, @value{UPDATED}). * Zcat:: Concatenating compressed files * Zcmp/Zdiff:: Comparing compressed files * Zgrep:: Searching inside compressed files +* Ztest:: Testing integrity of compressed files * Problems:: Reporting bugs * Concept Index:: Index of concepts @end menu @@ -53,10 +54,10 @@ to copy, distribute and modify it. 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. @node Zcat @@ -93,6 +94,10 @@ Print an informative help message describing the options and exit. @itemx -V Print the version number of zcat on the standard output and exit. +@item --recursive +@itemx -r +Operate recursively on directories. + @end table @@ -121,7 +126,7 @@ Compares @var{file1} to @var{file2}. If @var{file2} is omitted and corresponding decompressed file name (removes the extension from @var{file1}). If @var{file2} is omitted and @var{file1} is not compressed, compares @var{file1} to the uncompressed contents of -@var{file1}.[gz|bz2|lz|xz] (the first one that is found). +@var{file1}.[bz2|gz|lz|xz] (the first one that is found). @var{diff_options} are passed directly to diff or cmp. The exit status from diff or cmp is preserved. @@ -192,6 +197,51 @@ Print the version number of zgrep on the standard output and exit. @end table +@node Ztest +@chapter Ztest +@cindex ztest + +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 format for running ztest is: + +@example +ztest [@var{options}] [@var{files}] +@end example + +@noindent +The exit status is 0 if all files verify OK, 1 otherwise. + +Ztest supports the following options: + +@table @samp +@item --help +@itemx -h +Print an informative help message describing the options and exit. + +@item --version +@itemx -V +Print the version number of ztest on the standard output and exit. + +@item --quiet +@itemx -q +Quiet operation. Suppress all messages. + +@item --recursive +@itemx -r +Operate recursively on directories. + +@item --verbose +@itemx -v +Verbose mode. Show the verify status for each file processed. +Further -v's increase the verbosity level. + +@end table + + @node Problems @chapter Reporting Bugs @cindex bugs @@ -551,8 +551,8 @@ int print_magic_type( const std::string & magic_type ) { std::string data; - if( magic_type == "gzip" ) std::printf( "\x1F\x8B" ); - else if( magic_type == "bzip2" ) std::printf( "BZh" ); + if( magic_type == "bzip2" ) std::printf( "BZh" ); + else if( magic_type == "gzip" ) std::printf( "\x1F\x8B" ); else if( magic_type == "lzip" ) std::printf( "LZIP" ); else if( magic_type == "xz" ) std::printf( "%c7zXZ", '\xFD' ); else if( hex_to_data( magic_type, data ) ) std::printf( data.c_str() ); diff --git a/testsuite/check.sh b/testsuite/check.sh index 41e44b7..1c8b249 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -15,10 +15,12 @@ ZDIFF="${objdir}"/zdiff ZGREP="${objdir}"/zgrep ZEGREP="${objdir}"/zegrep ZFGREP="${objdir}"/zfgrep +ZTEST="${objdir}"/ztest ZUTILS="${objdir}"/zutils -compressors="gzip bzip2 lzip" +compressors="bzip2 gzip lzip" extensions="gz bz2 lz" framework_failure() { echo 'failure in testing framework'; exit 1; } +compressor_needed() { echo "${compressors} are needed to run tests"; exit 1; } if [ ! -x "${ZCAT}" ] ; then echo "${ZCAT}: cannot execute" @@ -27,15 +29,14 @@ fi if [ -d tmp ] ; then rm -rf tmp ; fi mkdir tmp -echo -n "testing zutils..." cd "${objdir}"/tmp for i in ${compressors}; do cat "${testdir}"/../COPYING > 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 . +"${ZTEST}" -r . || fail=1 +echo -n . + +if [ "bzip2" != `"${ZUTILS}" -t in.bz2` ] ; then fail=1 ; fi echo -n . -if [ "bzip2" != `"${ZUTILS}" -t in.bz2` ]; then fail=1 ; fi +if [ "gzip" != `"${ZUTILS}" -t in.gz` ] ; then fail=1 ; fi echo -n . -if [ "lzip" != `"${ZUTILS}" -t in.lz` ]; then fail=1 ; fi +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 @@ -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 @@ -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 @@ -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} |