Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/gnu/usr.bin/gzip Handle decompressing bzip2 files.



details:   https://anonhg.NetBSD.org/src/rev/a969aee4eafc
branches:  trunk
changeset: 474892:a969aee4eafc
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sun Jul 25 07:06:05 1999 +0000

description:
Handle decompressing bzip2 files.

diffstat:

 gnu/usr.bin/gzip/Makefile  |   8 ++--
 gnu/usr.bin/gzip/gzip.1    |  10 ++--
 gnu/usr.bin/gzip/gzip.c    |  13 ++++++-
 gnu/usr.bin/gzip/gzip.h    |   7 +++-
 gnu/usr.bin/gzip/unbzip2.c |  78 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 104 insertions(+), 12 deletions(-)

diffs (211 lines):

diff -r 82330b0a8d39 -r a969aee4eafc gnu/usr.bin/gzip/Makefile
--- a/gnu/usr.bin/gzip/Makefile Sun Jul 25 06:39:53 1999 +0000
+++ b/gnu/usr.bin/gzip/Makefile Sun Jul 25 07:06:05 1999 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.26 1999/02/02 02:04:40 thorpej Exp $
+#      $NetBSD: Makefile,v 1.27 1999/07/25 07:06:05 simonb Exp $
 
 .include <bsd.own.mk>
 
 PROG=  gzip
 SRCS=  gzip.c zip.c deflate.c trees.c bits.c unzip.c inflate.c util.c \
-       crypt.c lzw.c unlzw.c unlzh.c unpack.c getopt.c
+       crypt.c lzw.c unbzip2.c unlzw.c unlzh.c unpack.c getopt.c
 MAN=   gzexe.1 gzip.1 zdiff.1 zforce.1 zgrep.1 zmore.1 znew.1
 CPPFLAGS+=-DSTDC_HEADERS=1 -DHAVE_UNISTD_H=1 -DDIRENT=1 -Dunix
 
@@ -20,8 +20,8 @@
 .endif # m68k || i386
 
 LDSTATIC?= -static
-LDADD+=        -lgnumalloc
-DPADD+=        ${LIBGNUMALLOC}
+LDADD+=        -lgnumalloc -lbz2
+DPADD+=        ${LIBGNUMALLOC} ${LIBBZ2}
 
 MLINKS+= gzip.1 gunzip.1 gzip.1 gzcat.1 gzip.1 zcat.1
 MLINKS+= zdiff.1 zcmp.1
diff -r 82330b0a8d39 -r a969aee4eafc gnu/usr.bin/gzip/gzip.1
--- a/gnu/usr.bin/gzip/gzip.1   Sun Jul 25 06:39:53 1999 +0000
+++ b/gnu/usr.bin/gzip/gzip.1   Sun Jul 25 07:06:05 1999 +0000
@@ -1,4 +1,4 @@
-.\" $Id: gzip.1,v 1.4 1997/11/12 00:49:15 mrg Exp $
+.\" $Id: gzip.1,v 1.5 1999/07/25 07:06:06 simonb Exp $
 .PU
 .TH GZIP 1
 .SH NAME
@@ -97,11 +97,11 @@
 .PP
 .I gunzip
 can currently decompress files created by
-.I gzip, zip, compress, compress -H
+.I gzip, zip, bzip2, compress, compress -H
 or
 .I pack.
 The detection of the input format is automatic.  When using
-the first two formats,
+the first three formats,
 .I gunzip
 checks a 32 bit CRC. For
 .I pack, gunzip
@@ -368,8 +368,8 @@
 On Vax/VMS, the name of the environment variable is GZIP_OPT, to
 avoid a conflict with the symbol set for invocation of the program.
 .SH "SEE ALSO"
-znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), zip(1), unzip(1), compress(1),
-pack(1), compact(1)
+znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), zip(1), unzip(1), bzip2(1),
+compress(1), pack(1), compact(1)
 .SH "DIAGNOSTICS"
 Exit status is normally 0;
 if an error occurs, exit status is 1. If a warning occurs, exit status is 2.
diff -r 82330b0a8d39 -r a969aee4eafc gnu/usr.bin/gzip/gzip.c
--- a/gnu/usr.bin/gzip/gzip.c   Sun Jul 25 06:39:53 1999 +0000
+++ b/gnu/usr.bin/gzip/gzip.c   Sun Jul 25 07:06:05 1999 +0000
@@ -45,7 +45,7 @@
  */
 
 #ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.3 1998/03/06 18:17:13 tv Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.4 1999/07/25 07:06:06 simonb Exp $";
 #endif
 
 #include <ctype.h>
@@ -1278,6 +1278,14 @@
        /* check_zipfile may get ofname from the local header */
        last_member = 1;
 
+    } else if (memcmp(magic, BZIP2_MAGIC, 2) == 0 && inptr == 2
+           && memcmp((char*)inbuf, BZIP2_MAGIC, 3) == 0
+           && (inbuf[3] >= '0' && inbuf[3] <= '9')) {
+        inptr = 0;
+       work = unbzip2;
+       method = BZIP2ED;
+       last_member = 1;
+
     } else if (memcmp(magic, PACK_MAGIC, 2) == 0) {
        work = unpack;
        method = PACKED;
@@ -1327,7 +1335,8 @@
         "compr",  /* 1 */
         "pack ",  /* 2 */
         "lzh  ",  /* 3 */
-        "", "", "", "", /* 4 to 7 reserved */
+        "", "", "", /* 4 to 6 reserved */
+       "bzip2",
         "defla"}; /* 8 */
     char *date;
 
diff -r 82330b0a8d39 -r a969aee4eafc gnu/usr.bin/gzip/gzip.h
--- a/gnu/usr.bin/gzip/gzip.h   Sun Jul 25 06:39:53 1999 +0000
+++ b/gnu/usr.bin/gzip/gzip.h   Sun Jul 25 07:06:05 1999 +0000
@@ -55,7 +55,8 @@
 #define COMPRESSED  1
 #define PACKED      2
 #define LZHED       3
-/* methods 4 to 7 reserved */
+/* methods 4 to 6 reserved */
+#define BZIP2ED     7
 #define DEFLATED    8
 #define MAX_METHODS 9
 extern int method;         /* compression method */
@@ -157,6 +158,7 @@
 #define        OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
 #define        LZH_MAGIC      "\037\240" /* Magic header for SCO LZH Compress files*/
 #define PKZIP_MAGIC    "\120\113\003\004" /* Magic header for pkzip files */
+#define BZIP2_MAGIC    "\102\132\150" /* Magic header for bzip2 files */
 
 /* gzip flag byte */
 #define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
@@ -272,6 +274,9 @@
        /* in unlzh.c */
 extern int unlzh      OF((int in, int out));
 
+       /* in unbzip2.c */
+extern int unbzip2    OF((int in, int out));
+
        /* in gzip.c */
 RETSIGTYPE abort_gzip OF((void));
 
diff -r 82330b0a8d39 -r a969aee4eafc gnu/usr.bin/gzip/unbzip2.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/gnu/usr.bin/gzip/unbzip2.c        Sun Jul 25 07:06:05 1999 +0000
@@ -0,0 +1,78 @@
+/* unbzip2.c -- decompress files in bzip2 format.
+ */
+
+#ifdef RCSID
+static char rcsid[] = "$Id: unbzip2.c,v 1.1 1999/07/25 07:06:06 simonb Exp $";
+#endif
+
+#define BZ_NO_STDIO
+#include <bzlib.h>
+#include <stddef.h>
+
+#include "gzip.h"
+
+
+/* ============================================================================
+ * Bunzip2 in to out.
+ */
+int unbzip2(in, out) 
+    int in, out;    /* input and output file descriptors */
+{
+       int             n, ret, end_of_file;
+       bz_stream       bzs;
+
+       bzs.bzalloc = NULL;
+       bzs.bzfree = NULL;
+       bzs.opaque = NULL;
+
+       end_of_file = 0;
+       if (bzDecompressInit(&bzs, 0, 0) != BZ_OK)
+               return(ERROR);
+
+       /* Use up the remainder of "inbuf" that's been read in already */
+       bzs.next_in = inbuf;
+       bzs.avail_in = insize;
+
+       while (1) {
+               if (bzs.avail_in == 0 && !end_of_file) {
+                       n = read(in, inbuf, INBUFSIZ);
+                       if (n < 0)
+                               read_error();
+                       if (n == 0)
+                               end_of_file = 1;
+                       bzs.next_in = inbuf;
+                       bzs.avail_in = n;
+               }
+
+               bzs.next_out = outbuf;
+               bzs.avail_out = OUTBUFSIZ;
+               ret = bzDecompress(&bzs);
+
+               if (ret == BZ_STREAM_END) {
+                       n = write(out, outbuf, OUTBUFSIZ - bzs.avail_out);
+                       if (n < 0)
+                               write_error();
+                       break;
+               }
+               else if (ret == BZ_OK) {
+                       if (end_of_file)
+                               read_error();
+                       n = write(out, outbuf, OUTBUFSIZ - bzs.avail_out);
+               }
+               else {
+                       switch (ret) {
+                         case BZ_DATA_ERROR:
+                               error("bzip2 data integrity error");
+                         case BZ_DATA_ERROR_MAGIC:
+                               error("bzip2 magic number error");
+                         case BZ_MEM_ERROR:
+                               error("bzip2 out of memory");
+                       }
+               }
+       }
+
+       if (bzDecompressEnd(&bzs) != BZ_OK)
+               return(ERROR);
+
+       return(OK);
+}



Home | Main Index | Thread Index | Old Index