diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 16:12:15 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2015-11-07 16:12:15 +0000 |
commit | 904eea648db33416c7222842a0607f9b7d013656 (patch) | |
tree | 01fb0b1be8eff6e37d50938f8200eac45c97f14a | |
parent | Adding debian version 0.5-1. (diff) | |
download | zutils-904eea648db33416c7222842a0607f9b7d013656.tar.xz zutils-904eea648db33416c7222842a0607f9b7d013656.zip |
Merging upstream version 0.6.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to '')
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Makefile.in | 17 | ||||
-rw-r--r-- | NEWS | 4 | ||||
-rwxr-xr-x | configure | 4 | ||||
-rw-r--r-- | doc/zcat.1 | 21 | ||||
-rw-r--r-- | doc/zdiff.1 | 4 | ||||
-rw-r--r-- | doc/zgrep.1 | 21 | ||||
-rw-r--r-- | doc/zutils.1 | 46 | ||||
-rw-r--r-- | doc/zutils.info | bin | 6266 -> 6062 bytes | |||
-rw-r--r-- | doc/zutils.texinfo | 38 | ||||
-rw-r--r-- | main.cc | 146 | ||||
-rwxr-xr-x | testsuite/check.sh | 13 | ||||
-rw-r--r-- | zcat.in | 29 | ||||
-rw-r--r-- | zgrep.in | 29 |
14 files changed, 207 insertions, 172 deletions
@@ -1,3 +1,10 @@ +2009-10-05 Antonio Diaz Diaz <ant_diaz@teleline.es> + + * Version 0.6 released. + * zcat.in, zgrep.in: Removed again default compressor. Format of + data read from stdin is now automatically detected. + * Makefile.in: Added "--name" option to help2man invocation. + 2009-10-01 Antonio Diaz Diaz <ant_diaz@teleline.es> * Version 0.5 released. diff --git a/Makefile.in b/Makefile.in index 23330c1..a3c14ba 100644 --- a/Makefile.in +++ b/Makefile.in @@ -65,20 +65,19 @@ info : $(VPATH)/doc/$(progname).info $(VPATH)/doc/$(progname).info : $(VPATH)/doc/$(progname).texinfo cd $(VPATH)/doc && makeinfo $(progname).texinfo -man : $(VPATH)/doc/$(progname).1 $(VPATH)/doc/zcat.1 $(VPATH)/doc/zdiff.1 \ - $(VPATH)/doc/zgrep.1 - -$(VPATH)/doc/$(progname).1 : $(progname) - help2man -o $(VPATH)/doc/$(progname).1 ./$(progname) +man : $(VPATH)/doc/zcat.1 $(VPATH)/doc/zdiff.1 $(VPATH)/doc/zgrep.1 $(VPATH)/doc/zcat.1 : zcat - help2man -o $(VPATH)/doc/zcat.1 --no-info ./zcat + help2man -n 'concatenate compressed files to stdout' \ + -o $(VPATH)/doc/zcat.1 --no-info ./zcat $(VPATH)/doc/zdiff.1 : zdiff - help2man -o $(VPATH)/doc/zdiff.1 --no-info ./zdiff + help2man -n 'compare compressed files' \ + -o $(VPATH)/doc/zdiff.1 --no-info ./zdiff $(VPATH)/doc/zgrep.1 : zgrep - help2man -o $(VPATH)/doc/zgrep.1 --no-info ./zgrep + help2man -n 'search compressed files for a regular expression' \ + -o $(VPATH)/doc/zgrep.1 --no-info ./zgrep Makefile : $(VPATH)/configure $(VPATH)/Makefile.in ./config.status @@ -103,7 +102,6 @@ install-info : install-man : if test ! -d $(DESTDIR)$(mandir)/man1 ; then $(INSTALL_DIR) $(DESTDIR)$(mandir)/man1 ; fi - $(INSTALL_DATA) $(VPATH)/doc/$(progname).1 $(DESTDIR)$(mandir)/man1/$(progname).1 $(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 @@ -131,7 +129,6 @@ uninstall-info : -rm -f $(DESTDIR)$(infodir)/$(progname).info uninstall-man : - -rm -f $(DESTDIR)$(mandir)/man1/$(progname).1 -rm -f $(DESTDIR)$(mandir)/man1/zcat.1 -rm -f $(DESTDIR)$(mandir)/man1/zcmp.1 -rm -f $(DESTDIR)$(mandir)/man1/zdiff.1 @@ -1,3 +1,3 @@ -Changes in version 0.5: +Changes in version 0.6: -Zcat, zegrep, zfgrep and zgrep can read again compressed data from stdin. +Format of data read from stdin is now automatically detected. @@ -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-01 +# Date of this version: 2009-10-05 args= no_create= progname=zutils -progversion=0.5 +progversion=0.6 srctrigger=zdiff.in # clear some things potentially inherited from environment. @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZCAT "1" "October 2009" "Zcat 0.5" "User Commands" +.TH ZCAT "1" "October 2009" "Zcat 0.6" "User Commands" .SH NAME -Zcat \- manual page for Zcat 0.5 +Zcat \- concatenate compressed files to stdout .SH SYNOPSIS .B zcat [\fIOPTIONS\fR] [\fICAT_OPTIONS\fR] [\fIFILES\fR] @@ -13,8 +13,9 @@ 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 names corresponding to the supported compressors. If no files are specified, -the standard input is decompressed using the selected compressor and -sent to stdout. +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. .PP CAT_OPTIONS are passed directly to cat. @@ -26,18 +27,6 @@ display this help and exit .TP \fB\-V\fR, \fB\-\-version\fR output version information and exit -.TP -\fB\-\-gzip\fR -use gzip as decompressor for stdin (default) -.TP -\fB\-\-bzip2\fR -use bzip2 as decompressor for stdin -.TP -\fB\-\-lzip\fR -use lzip as decompressor for stdin -.TP -\fB\-\-xz\fR -use xz as decompressor for stdin .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 3509c21..cf19d27 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" "October 2009" "Zdiff 0.5" "User Commands" +.TH ZDIFF "1" "October 2009" "Zdiff 0.6" "User Commands" .SH NAME -Zdiff \- manual page for Zdiff 0.5 +Zdiff \- compare compressed files .SH SYNOPSIS .B zdiff [\fIOPTIONS\fR] [\fIDIFF_OPTIONS\fR] \fIFILE1 \fR[\fIFILE2\fR] diff --git a/doc/zgrep.1 b/doc/zgrep.1 index 3db747b..fc22717 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" "October 2009" "Zgrep 0.5" "User Commands" +.TH ZGREP "1" "October 2009" "Zgrep 0.6" "User Commands" .SH NAME -Zgrep \- manual page for Zgrep 0.5 +Zgrep \- search compressed files for a regular expression .SH SYNOPSIS .B zgrep [\fIOPTIONS\fR] [\fIGREP_OPTIONS\fR] \fIPATTERN \fR[\fIFILES\fR] @@ -13,8 +13,9 @@ 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 names corresponding to the supported compressors. If no files are -specified, the standard input is decompressed using the selected -compressor and fed to grep. +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. .PP Zegrep is a shortcut for "zgrep \fB\-E\fR" @@ -29,18 +30,6 @@ display this help and exit .TP \fB\-V\fR, \fB\-\-version\fR output version information and exit -.TP -\fB\-\-gzip\fR -use gzip as decompressor for stdin (default) -.TP -\fB\-\-bzip2\fR -use bzip2 as decompressor for stdin -.TP -\fB\-\-lzip\fR -use lzip as decompressor for stdin -.TP -\fB\-\-xz\fR -use xz as decompressor for stdin .SH "REPORTING BUGS" Report bugs to zutils\-bug@nongnu.org Zutils home page: http://www.nongnu.org/zutils/zutils.html diff --git a/doc/zutils.1 b/doc/zutils.1 deleted file mode 100644 index 4836ace..0000000 --- a/doc/zutils.1 +++ /dev/null @@ -1,46 +0,0 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36. -.TH ZUTILS "1" "October 2009" "Zutils 0.5" "User Commands" -.SH NAME -Zutils \- manual page for Zutils 0.5 -.SH SYNOPSIS -.B zutils -[\fIoptions\fR] [\fIfiles\fR] -.SH DESCRIPTION -Zutils \- A file format detector for compressed files. -.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\-t\fR, \fB\-\-test\fR -test compressed file type -.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. -License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> -.br -This is free software: you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law. -.SH "SEE ALSO" -The full documentation for -.B Zutils -is maintained as a Texinfo manual. If the -.B info -and -.B Zutils -programs are properly installed at your site, the command -.IP -.B info Zutils -.PP -should give you access to the complete manual. diff --git a/doc/zutils.info b/doc/zutils.info Binary files differindex e2d3258..34f390b 100644 --- a/doc/zutils.info +++ b/doc/zutils.info diff --git a/doc/zutils.texinfo b/doc/zutils.texinfo index 76f771b..3902270 100644 --- a/doc/zutils.texinfo +++ b/doc/zutils.texinfo @@ -5,8 +5,8 @@ @finalout @c %**end of header -@set UPDATED 1 October 2009 -@set VERSION 0.5 +@set UPDATED 5 October 2009 +@set VERSION 0.6 @dircategory Data Compression @direntry @@ -68,8 +68,9 @@ 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 names corresponding to the supported compressors. If no files are specified, -the standard input is decompressed using the selected compressor and -sent to stdout. +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 format for running zcat is: @@ -92,18 +93,6 @@ 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 --gzip -Use gzip as decompressor for stdin (default). - -@item --bzip2 -Use bzip2 as decompressor for stdin. - -@item --lzip -Use lzip as decompressor for stdin. - -@item --xz -Use xz as decompressor for stdin. - @end table @@ -170,8 +159,9 @@ 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 names corresponding to the supported compressors. If no files are -specified, the standard input is decompressed using the selected -compressor and fed to grep. +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. @noindent Zegrep is a shortcut for @samp{zgrep -E}@* @@ -199,18 +189,6 @@ Print an informative help message describing the options and exit. @itemx -V Print the version number of zgrep on the standard output and exit. -@item --gzip -Use gzip as decompressor for stdin (default). - -@item --bzip2 -Use bzip2 as decompressor for stdin. - -@item --lzip -Use lzip as decompressor for stdin. - -@item --xz -Use xz as decompressor for stdin. - @end table @@ -134,6 +134,7 @@ void show_help() throw() // std::printf( " -d, --decompress decompress\n" ); // std::printf( " -f, --force overwrite existing output files\n" ); // std::printf( " -k, --keep keep (don't delete) input files\n" ); + std::printf( " -m, --magic=<type> output magic bytes for given file type\n" ); // std::printf( " -o, --output=<file> if reading stdin, place the output into <file>\n" ); std::printf( " -q, --quiet suppress all messages\n" ); std::printf( " -t, --test test compressed file type\n" ); @@ -492,6 +493,129 @@ int decompress( const int inhandle, const Pretty_print & pp ) } */ +unsigned char xdigit( const int value ) throw() + { + if( value >= 0 && value <= 9 ) return '0' + value; + if( value >= 10 && value <= 15 ) return 'A' + value - 10; + return 0; + } + + +int xtoi( const unsigned char ch ) throw() + { + switch( ch ) + { + case '0': return 0; + case '1': return 1; + case '2': return 2; + case '3': return 3; + case '4': return 4; + case '5': return 5; + case '6': return 6; + case '7': return 7; + case '8': return 8; + case '9': return 9; + case 'a': + case 'A': return 0x0A; + case 'b': + case 'B': return 0x0B; + case 'c': + case 'C': return 0x0C; + case 'd': + case 'D': return 0x0D; + case 'e': + case 'E': return 0x0E; + case 'f': + case 'F': return 0x0F; + default: return -1; + } + } + + +bool hex_to_data( const std::string & hex, std::string & data ) + { + data.clear(); + if( hex.size() == 0 || hex.size() % 2 != 0 ) return false; + for( unsigned int i = 0; 2 * i + 1 < hex.size(); ++i ) + { + int uch = xtoi( hex[2*i] ); + int lch = xtoi( hex[2*i+1] ); + if( uch < 0 || lch < 0 ) return false; + data.push_back( ( uch << 4 ) | lch ); + } + return true; + } + + +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" ); + 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() ); + else return 1; + return 0; + } + + +int test_stdin_type( const int inhandle, const Pretty_print & pp ) + { + unsigned char buf[5]; + const char * msg = 0; + int i = 0; + if( readblock( inhandle, (char *)buf, 1 ) == 1 ) + { + if( buf[0] == 0x1F ) + { + if( readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 0x8B ) + msg = "gzip"; + } + else if( buf[0] == 'B' ) + { + if( readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'Z' && + readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'h' ) + msg = "bzip2"; + } + else if( buf[0] == 'L' ) + { + if( readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'Z' && + readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'I' && + readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'P' ) + msg = "lzip"; + } + else if( buf[0] == 0xFD ) + { + if( readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == '7' && + readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'z' && + readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'X' && + readblock( inhandle, (char *)&buf[++i], 1 ) == 1 && buf[i] == 'Z' ) + msg = "xz"; + } + } + const int retval = ( msg ? 0 : 1 ); + if( verbosity >= 0 ) + { + if( verbosity >= 1 ) pp(); + if( !msg ) + { + char hexmsg[(2*sizeof buf)+1]; + for( int j = 0; j <= i; ++j ) + { + hexmsg[2*j] = xdigit( buf[j] >> 4 ); + hexmsg[2*j+1] = xdigit( buf[j] & 0x0F ); + } + hexmsg[2*i+2] = 0; + msg = hexmsg; + } + std::printf( "%s\n", msg ); + } + return retval; + } + + int test_type( const int inhandle, const Pretty_print & pp ) { unsigned char buf[5]; @@ -505,7 +629,7 @@ int test_type( const int inhandle, const Pretty_print & pp ) msg = "bzip2"; else if( buf[0] == 'L' && buf[1] == 'Z' && buf[2] == 'I' && buf[3] == 'P' ) msg = "lzip"; - else if( buf[1] == '7' && buf[2] == 'z' && buf[3] == 'X' && buf[4] == 'Z' ) + else if( buf[0] == 0xFD && buf[1] == '7' && buf[2] == 'z' && buf[3] == 'X' && buf[4] == 'Z' ) msg = "xz"; } const int retval = ( msg ? 0 : 1 ); @@ -546,6 +670,7 @@ int main( const int argc, const char * argv[] ) std::string input_filename; std::string default_output_filename; std::vector< std::string > filenames; + std::string magic_type; invocation_name = argv[0]; const Arg_parser::Option options[] = @@ -555,6 +680,7 @@ int main( const int argc, const char * argv[] ) { 'f', "force", Arg_parser::no }, { 'h', "help", Arg_parser::no }, { 'k', "keep", Arg_parser::no }, + { 'm', "magic", Arg_parser::yes }, { 'o', "output", Arg_parser::yes }, { 'q', "quiet", Arg_parser::no }, { 't', "test", Arg_parser::no }, @@ -571,7 +697,7 @@ int main( const int argc, const char * argv[] ) { const int code = parser.code( argind ); if( !code ) break; // no more options - const char * arg = parser.argument( argind ).c_str(); + const std::string & arg = parser.argument( argind ); switch( code ) { case 'c': to_stdout = true; break; @@ -579,6 +705,7 @@ int main( const int argc, const char * argv[] ) case 'f': force = true; break; case 'h': show_help(); return 0; case 'k': keep_input_files = true; break; + case 'm': magic_type = arg; break; case 'o': default_output_filename = arg; break; case 'q': verbosity = -1; break; case 't': program_mode = m_test; break; @@ -588,6 +715,8 @@ int main( const int argc, const char * argv[] ) } } + if( magic_type.size() ) return print_magic_type( magic_type ); + bool filenames_given = false; for( ; argind < parser.arguments(); ++argind ) { @@ -669,19 +798,22 @@ int main( const int argc, const char * argv[] ) case m_decompress: /*tmp = decompress( inhandle, pp );*/ break; case m_test: - tmp = test_type( inhandle, pp ); break; + if( inhandle == STDIN_FILENO ) + tmp = test_stdin_type( inhandle, pp ); + else tmp = test_type( inhandle, pp ); + break; } if( tmp > retval ) retval = tmp; if( tmp && program_mode != m_test ) cleanup_and_fail( retval ); -/* - if( delete_output_on_interrupt ) - close_and_set_permissions( in_statsp, &retval ); + +// if( delete_output_on_interrupt ) +// close_and_set_permissions( in_statsp, &retval ); if( input_filename.size() ) { close( inhandle ); inhandle = -1; if( !keep_input_files && !to_stdout && program_mode != m_test ) std::remove( input_filename.c_str() ); - }*/ + } } if( outhandle >= 0 ) close( outhandle ); return retval; diff --git a/testsuite/check.sh b/testsuite/check.sh index a8843f3..41e44b7 100755 --- a/testsuite/check.sh +++ b/testsuite/check.sh @@ -55,13 +55,10 @@ echo -n . "${ZCAT}" < in.gz > copy || fail=1 cmp in copy || fail=1 echo -n . -"${ZCAT}" --gzip < in.gz > copy || fail=1 +"${ZCAT}" < in.bz2 > copy || fail=1 cmp in copy || fail=1 echo -n . -"${ZCAT}" --bzip2 < in.bz2 > copy || fail=1 -cmp in copy || fail=1 -echo -n . -"${ZCAT}" --lzip < in.lz > copy || fail=1 +"${ZCAT}" < in.lz > copy || fail=1 cmp in copy || fail=1 echo -n . "${ZCAT}" in > copy || fail=1 @@ -122,11 +119,9 @@ done echo -n . "${ZGREP}" License < in.gz 2>&1 > /dev/null || fail=1 echo -n . -"${ZGREP}" --gzip License < in.gz 2>&1 > /dev/null || fail=1 -echo -n . -"${ZGREP}" --bzip2 License < in.bz2 2>&1 > /dev/null || fail=1 +"${ZGREP}" License < in.bz2 2>&1 > /dev/null || fail=1 echo -n . -"${ZGREP}" --lzip License < in.lz 2>&1 > /dev/null || fail=1 +"${ZGREP}" License < in.lz 2>&1 > /dev/null || fail=1 echo -n . "${ZGREP}" License in 2>&1 > /dev/null || fail=1 echo -n . @@ -8,7 +8,6 @@ LC_ALL=C export LC_ALL args= -default_prog=gzip two_hyphens=0 # Loop over args until a filename is found @@ -23,8 +22,9 @@ while [ x"$1" != x ] ; do echo "If any given file is compressed, its uncompressed content is used. If a" echo "given file does not exist, zcat tries the compressed file names" echo "corresponding to the supported compressors. If no files are specified," - echo "the standard input is decompressed using the selected compressor and" - echo "sent to stdout." + 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 echo "Usage: $0 [OPTIONS] [CAT_OPTIONS] [FILES]" @@ -35,10 +35,6 @@ 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 decompressor for stdin (default)" - echo " --bzip2 use bzip2 as decompressor for stdin" - echo " --lzip use lzip as decompressor for stdin" - echo " --xz use xz as decompressor for stdin" echo echo "Report bugs to zutils-bug@nongnu.org" echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html" @@ -49,14 +45,6 @@ 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 ;; - | -f) ;; --) @@ -70,7 +58,16 @@ while [ x"$1" != x ] ; do done if [ $# = 0 ]; then - ${default_prog} -cdfq | cat ${args} + 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" ;; + *) prog=cat ;; + esac + { "${bindir}"zutils -m ${prog_name} ; cat ; } | ${prog} | cat ${args} exit $? fi @@ -8,7 +8,6 @@ LC_ALL=C export LC_ALL args= -default_prog=gzip have_pat=0 list=0 no_name=0 @@ -26,8 +25,9 @@ while [ x"$1" != x ] ; do 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 "names corresponding to the supported compressors. If no files are" - echo "specified, the standard input is decompressed using the selected" - echo "compressor and fed to grep." + 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 echo "Zegrep is a shortcut for \"zgrep -E\"" @@ -41,10 +41,6 @@ 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 decompressor for stdin (default)" - echo " --bzip2 use bzip2 as decompressor for stdin" - echo " --lzip use lzip as decompressor for stdin" - echo " --xz use xz as decompressor for stdin" echo echo "Report bugs to zutils-bug@nongnu.org" echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html" @@ -55,14 +51,6 @@ 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 "$0: option $1 not supported" exit 1 ;; @@ -96,7 +84,16 @@ if [ ${have_pat} = 0 ]; then fi if [ $# = 0 ]; then - ${default_prog} -cdfq | grep ${args} + 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" ;; + *) prog=cat ;; + esac + { "${bindir}"zutils -m ${prog_name} ; cat ; } | ${prog} | grep ${args} exit $? fi |