Remove remaining NETBSD uppercase references
This commit is contained in:
parent
5188a03964
commit
d8ef58adf3
|
|
@ -1,5 +1,3 @@
|
||||||
# $NetBSD: Makefile,v 1.18 2013/11/13 11:12:24 pettai Exp $
|
|
||||||
|
|
||||||
USE_FORT?= yes # data-driven bugs?
|
USE_FORT?= yes # data-driven bugs?
|
||||||
|
|
||||||
PROG= gzip
|
PROG= gzip
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/sh -
|
#!/bin/sh -
|
||||||
#
|
#
|
||||||
# $NetBSD: gzexe,v 1.3 2004/05/01 08:22:41 wiz Exp $
|
|
||||||
#
|
|
||||||
# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
|
# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
.\" $NetBSD: gzexe.1,v 1.3 2003/12/28 12:49:41 wiz Exp $
|
|
||||||
.\" $OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
|
.\" $OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
.\" $NetBSD: gzip.1,v 1.25 2015/04/06 21:41:17 wiz Exp $
|
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
|
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
|
|
|
||||||
3040
usr.bin/gzip/gzip.c
3040
usr.bin/gzip/gzip.c
File diff suppressed because it is too large
Load Diff
|
|
@ -1,10 +1,9 @@
|
||||||
/* $NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg Exp $ */
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
* Copyright (c) 2006 The Foundation, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
* This code is derived from software contributed to The Foundation
|
||||||
* by Simon Burge.
|
* by Simon Burge.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|
@ -16,7 +15,7 @@
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
|
@ -31,108 +30,107 @@
|
||||||
|
|
||||||
/* This file is #included by gzip.c */
|
/* This file is #included by gzip.c */
|
||||||
|
|
||||||
static off_t
|
static off_t unbzip2(int in, int out, char *pre, size_t prelen,
|
||||||
unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
off_t *bytes_in) {
|
||||||
{
|
int ret, end_of_file, cold = 0;
|
||||||
int ret, end_of_file, cold = 0;
|
off_t bytes_out = 0;
|
||||||
off_t bytes_out = 0;
|
bz_stream bzs;
|
||||||
bz_stream bzs;
|
static char *inbuf, *outbuf;
|
||||||
static char *inbuf, *outbuf;
|
|
||||||
|
|
||||||
if (inbuf == NULL)
|
if (inbuf == NULL)
|
||||||
inbuf = malloc(BUFLEN);
|
inbuf = malloc(BUFLEN);
|
||||||
if (outbuf == NULL)
|
if (outbuf == NULL)
|
||||||
outbuf = malloc(BUFLEN);
|
outbuf = malloc(BUFLEN);
|
||||||
if (inbuf == NULL || outbuf == NULL)
|
if (inbuf == NULL || outbuf == NULL)
|
||||||
maybe_err("malloc");
|
maybe_err("malloc");
|
||||||
|
|
||||||
bzs.bzalloc = NULL;
|
bzs.bzalloc = NULL;
|
||||||
bzs.bzfree = NULL;
|
bzs.bzfree = NULL;
|
||||||
bzs.opaque = NULL;
|
bzs.opaque = NULL;
|
||||||
|
|
||||||
end_of_file = 0;
|
end_of_file = 0;
|
||||||
ret = BZ2_bzDecompressInit(&bzs, 0, 0);
|
ret = BZ2_bzDecompressInit(&bzs, 0, 0);
|
||||||
if (ret != BZ_OK)
|
if (ret != BZ_OK)
|
||||||
maybe_errx("bzip2 init");
|
maybe_errx("bzip2 init");
|
||||||
|
|
||||||
/* Prepend. */
|
/* Prepend. */
|
||||||
bzs.avail_in = prelen;
|
bzs.avail_in = prelen;
|
||||||
bzs.next_in = pre;
|
bzs.next_in = pre;
|
||||||
|
|
||||||
if (bytes_in)
|
if (bytes_in)
|
||||||
*bytes_in = prelen;
|
*bytes_in = prelen;
|
||||||
|
|
||||||
while (ret == BZ_OK) {
|
while (ret == BZ_OK) {
|
||||||
if (bzs.avail_in == 0 && !end_of_file) {
|
if (bzs.avail_in == 0 && !end_of_file) {
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
n = read(in, inbuf, BUFLEN);
|
n = read(in, inbuf, BUFLEN);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
maybe_err("read");
|
maybe_err("read");
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
end_of_file = 1;
|
end_of_file = 1;
|
||||||
bzs.next_in = inbuf;
|
bzs.next_in = inbuf;
|
||||||
bzs.avail_in = n;
|
bzs.avail_in = n;
|
||||||
if (bytes_in)
|
if (bytes_in)
|
||||||
*bytes_in += n;
|
*bytes_in += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
bzs.next_out = outbuf;
|
bzs.next_out = outbuf;
|
||||||
bzs.avail_out = BUFLEN;
|
bzs.avail_out = BUFLEN;
|
||||||
ret = BZ2_bzDecompress(&bzs);
|
ret = BZ2_bzDecompress(&bzs);
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case BZ_STREAM_END:
|
case BZ_STREAM_END:
|
||||||
case BZ_OK:
|
case BZ_OK:
|
||||||
if (ret == BZ_OK && end_of_file) {
|
if (ret == BZ_OK && end_of_file) {
|
||||||
/*
|
/*
|
||||||
* If we hit this after a stream end, consider
|
* If we hit this after a stream end, consider
|
||||||
* it as the end of the whole file and don't
|
* it as the end of the whole file and don't
|
||||||
* bail out.
|
* bail out.
|
||||||
*/
|
*/
|
||||||
if (cold == 1)
|
if (cold == 1)
|
||||||
ret = BZ_STREAM_END;
|
ret = BZ_STREAM_END;
|
||||||
else
|
else
|
||||||
maybe_errx("truncated file");
|
maybe_errx("truncated file");
|
||||||
}
|
}
|
||||||
cold = 0;
|
cold = 0;
|
||||||
if (!tflag && bzs.avail_out != BUFLEN) {
|
if (!tflag && bzs.avail_out != BUFLEN) {
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
n = write(out, outbuf, BUFLEN - bzs.avail_out);
|
n = write(out, outbuf, BUFLEN - bzs.avail_out);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
maybe_err("write");
|
maybe_err("write");
|
||||||
bytes_out += n;
|
bytes_out += n;
|
||||||
}
|
}
|
||||||
if (ret == BZ_STREAM_END && !end_of_file) {
|
if (ret == BZ_STREAM_END && !end_of_file) {
|
||||||
if (BZ2_bzDecompressEnd(&bzs) != BZ_OK ||
|
if (BZ2_bzDecompressEnd(&bzs) != BZ_OK ||
|
||||||
BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK)
|
BZ2_bzDecompressInit(&bzs, 0, 0) != BZ_OK)
|
||||||
maybe_errx("bzip2 re-init");
|
maybe_errx("bzip2 re-init");
|
||||||
cold = 1;
|
cold = 1;
|
||||||
ret = BZ_OK;
|
ret = BZ_OK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BZ_DATA_ERROR:
|
case BZ_DATA_ERROR:
|
||||||
maybe_warnx("bzip2 data integrity error");
|
maybe_warnx("bzip2 data integrity error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BZ_DATA_ERROR_MAGIC:
|
case BZ_DATA_ERROR_MAGIC:
|
||||||
maybe_warnx("bzip2 magic number error");
|
maybe_warnx("bzip2 magic number error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BZ_MEM_ERROR:
|
case BZ_MEM_ERROR:
|
||||||
maybe_warnx("bzip2 out of memory");
|
maybe_warnx("bzip2 out of memory");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
maybe_warnx("unknown bzip2 error: %d", ret);
|
maybe_warnx("unknown bzip2 error: %d", ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != BZ_STREAM_END || BZ2_bzDecompressEnd(&bzs) != BZ_OK)
|
if (ret != BZ_STREAM_END || BZ2_bzDecompressEnd(&bzs) != BZ_OK)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
return (bytes_out);
|
return (bytes_out);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* $FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij $ */
|
/* $FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij
|
||||||
/* $NetBSD: unpack.c,v 1.2 2010/11/06 21:42:32 mrg Exp $ */
|
* $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2009 Xin LI <delphij@FreeBSD.org>
|
* Copyright (c) 2009 Xin LI <delphij@FreeBSD.org>
|
||||||
|
|
@ -56,8 +56,8 @@
|
||||||
* range [0..254], so all levels' symbol count would fit into 1 byte.
|
* range [0..254], so all levels' symbol count would fit into 1 byte.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PACK_HEADER_LENGTH 7
|
#define PACK_HEADER_LENGTH 7
|
||||||
#define HTREE_MAXLEVEL 24
|
#define HTREE_MAXLEVEL 24
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* unpack descriptor
|
* unpack descriptor
|
||||||
|
|
@ -69,22 +69,22 @@
|
||||||
* leaf nodes count.
|
* leaf nodes count.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int symbol_size; /* Size of the symbol table */
|
int symbol_size; /* Size of the symbol table */
|
||||||
int treelevels; /* Levels for the huffman tree */
|
int treelevels; /* Levels for the huffman tree */
|
||||||
|
|
||||||
int *symbolsin; /* Table of leaf symbols count in
|
int *symbolsin; /* Table of leaf symbols count in
|
||||||
each level */
|
each level */
|
||||||
int *inodesin; /* Table of internal nodes count in
|
int *inodesin; /* Table of internal nodes count in
|
||||||
each level */
|
each level */
|
||||||
|
|
||||||
char *symbol; /* The symbol table */
|
char *symbol; /* The symbol table */
|
||||||
char *symbol_eob; /* Pointer to the EOB symbol */
|
char *symbol_eob; /* Pointer to the EOB symbol */
|
||||||
char **tree; /* Decoding huffman tree (pointers to
|
char **tree; /* Decoding huffman tree (pointers to
|
||||||
first symbol of each tree level */
|
first symbol of each tree level */
|
||||||
|
|
||||||
off_t uncompressed_size; /* Uncompressed size */
|
off_t uncompressed_size; /* Uncompressed size */
|
||||||
FILE *fpIn; /* Input stream */
|
FILE *fpIn; /* Input stream */
|
||||||
FILE *fpOut; /* Output stream */
|
FILE *fpOut; /* Output stream */
|
||||||
} unpack_descriptor_t;
|
} unpack_descriptor_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -95,48 +95,43 @@ typedef struct {
|
||||||
* We don't zero out pointers here because nobody else would ever
|
* We don't zero out pointers here because nobody else would ever
|
||||||
* reference the memory block without scrubbing them.
|
* reference the memory block without scrubbing them.
|
||||||
*/
|
*/
|
||||||
static void
|
static void unpack_descriptor_fini(unpack_descriptor_t *unpackd) {
|
||||||
unpack_descriptor_fini(unpack_descriptor_t *unpackd)
|
|
||||||
{
|
|
||||||
|
|
||||||
free(unpackd->symbolsin);
|
free(unpackd->symbolsin);
|
||||||
free(unpackd->inodesin);
|
free(unpackd->inodesin);
|
||||||
free(unpackd->symbol);
|
free(unpackd->symbol);
|
||||||
free(unpackd->tree);
|
free(unpackd->tree);
|
||||||
|
|
||||||
fclose(unpackd->fpIn);
|
fclose(unpackd->fpIn);
|
||||||
fclose(unpackd->fpOut);
|
fclose(unpackd->fpOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recursively fill the internal node count table
|
* Recursively fill the internal node count table
|
||||||
*/
|
*/
|
||||||
static void
|
static void unpackd_fill_inodesin(const unpack_descriptor_t *unpackd,
|
||||||
unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level)
|
int level) {
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The internal nodes would be 1/2 of total internal nodes and
|
* The internal nodes would be 1/2 of total internal nodes and
|
||||||
* leaf nodes in the next level. For the last level there
|
* leaf nodes in the next level. For the last level there
|
||||||
* would be no internal node by definition.
|
* would be no internal node by definition.
|
||||||
*/
|
*/
|
||||||
if (level < unpackd->treelevels) {
|
if (level < unpackd->treelevels) {
|
||||||
unpackd_fill_inodesin(unpackd, level + 1);
|
unpackd_fill_inodesin(unpackd, level + 1);
|
||||||
unpackd->inodesin[level] = (unpackd->inodesin[level + 1] +
|
unpackd->inodesin[level] =
|
||||||
unpackd->symbolsin[level + 1]) / 2;
|
(unpackd->inodesin[level + 1] + unpackd->symbolsin[level + 1]) / 2;
|
||||||
} else
|
} else
|
||||||
unpackd->inodesin[level] = 0;
|
unpackd->inodesin[level] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update counter for accepted bytes
|
* Update counter for accepted bytes
|
||||||
*/
|
*/
|
||||||
static void
|
static void accepted_bytes(off_t *bytes_in, off_t newbytes) {
|
||||||
accepted_bytes(off_t *bytes_in, off_t newbytes)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (bytes_in != NULL)
|
if (bytes_in != NULL)
|
||||||
(*bytes_in) += newbytes;
|
(*bytes_in) += newbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -145,179 +140,170 @@ accepted_bytes(off_t *bytes_in, off_t newbytes)
|
||||||
*
|
*
|
||||||
* Return value is uncompressed size.
|
* Return value is uncompressed size.
|
||||||
*/
|
*/
|
||||||
static void
|
static void unpack_parse_header(int in, int out, char *pre, size_t prelen,
|
||||||
unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in,
|
off_t *bytes_in, unpack_descriptor_t *unpackd) {
|
||||||
unpack_descriptor_t *unpackd)
|
unsigned char hdr[PACK_HEADER_LENGTH]; /* buffer for header */
|
||||||
{
|
ssize_t bytesread; /* Bytes read from the file */
|
||||||
unsigned char hdr[PACK_HEADER_LENGTH]; /* buffer for header */
|
int i, j, thisbyte;
|
||||||
ssize_t bytesread; /* Bytes read from the file */
|
|
||||||
int i, j, thisbyte;
|
|
||||||
|
|
||||||
/* Prepend the header buffer if we already read some data */
|
/* Prepend the header buffer if we already read some data */
|
||||||
if (prelen != 0)
|
if (prelen != 0)
|
||||||
memcpy(hdr, pre, prelen);
|
memcpy(hdr, pre, prelen);
|
||||||
|
|
||||||
/* Read in and fill the rest bytes of header */
|
/* Read in and fill the rest bytes of header */
|
||||||
bytesread = read(in, hdr + prelen, PACK_HEADER_LENGTH - prelen);
|
bytesread = read(in, hdr + prelen, PACK_HEADER_LENGTH - prelen);
|
||||||
if (bytesread < 0)
|
if (bytesread < 0)
|
||||||
maybe_err("Error reading pack header");
|
maybe_err("Error reading pack header");
|
||||||
|
|
||||||
accepted_bytes(bytes_in, PACK_HEADER_LENGTH);
|
accepted_bytes(bytes_in, PACK_HEADER_LENGTH);
|
||||||
|
|
||||||
/* Obtain uncompressed length (bytes 2,3,4,5)*/
|
/* Obtain uncompressed length (bytes 2,3,4,5)*/
|
||||||
unpackd->uncompressed_size = 0;
|
unpackd->uncompressed_size = 0;
|
||||||
for (i = 2; i <= 5; i++) {
|
for (i = 2; i <= 5; i++) {
|
||||||
unpackd->uncompressed_size <<= 8;
|
unpackd->uncompressed_size <<= 8;
|
||||||
unpackd->uncompressed_size |= hdr[i];
|
unpackd->uncompressed_size |= hdr[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the levels of the tree */
|
/* Get the levels of the tree */
|
||||||
unpackd->treelevels = hdr[6];
|
unpackd->treelevels = hdr[6];
|
||||||
if (unpackd->treelevels > HTREE_MAXLEVEL || unpackd->treelevels < 1)
|
if (unpackd->treelevels > HTREE_MAXLEVEL || unpackd->treelevels < 1)
|
||||||
maybe_errx("Huffman tree has insane levels");
|
maybe_errx("Huffman tree has insane levels");
|
||||||
|
|
||||||
/* Let libc take care for buffering from now on */
|
/* Let libc take care for buffering from now on */
|
||||||
if ((unpackd->fpIn = fdopen(in, "r")) == NULL)
|
if ((unpackd->fpIn = fdopen(in, "r")) == NULL)
|
||||||
maybe_err("Can not fdopen() input stream");
|
maybe_err("Can not fdopen() input stream");
|
||||||
if ((unpackd->fpOut = fdopen(out, "w")) == NULL)
|
if ((unpackd->fpOut = fdopen(out, "w")) == NULL)
|
||||||
maybe_err("Can not fdopen() output stream");
|
maybe_err("Can not fdopen() output stream");
|
||||||
|
|
||||||
/* Allocate for the tables of bounds and the tree itself */
|
/* Allocate for the tables of bounds and the tree itself */
|
||||||
unpackd->inodesin =
|
unpackd->inodesin = calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin)));
|
||||||
calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin)));
|
unpackd->symbolsin =
|
||||||
unpackd->symbolsin =
|
calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin)));
|
||||||
calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin)));
|
unpackd->tree = calloc(unpackd->treelevels, (sizeof(*(unpackd->tree))));
|
||||||
unpackd->tree =
|
if (unpackd->inodesin == NULL || unpackd->symbolsin == NULL ||
|
||||||
calloc(unpackd->treelevels, (sizeof (*(unpackd->tree))));
|
unpackd->tree == NULL)
|
||||||
if (unpackd->inodesin == NULL || unpackd->symbolsin == NULL ||
|
maybe_err("calloc");
|
||||||
unpackd->tree == NULL)
|
|
||||||
maybe_err("calloc");
|
|
||||||
|
|
||||||
/* We count from 0 so adjust to match array upper bound */
|
/* We count from 0 so adjust to match array upper bound */
|
||||||
unpackd->treelevels--;
|
unpackd->treelevels--;
|
||||||
|
|
||||||
/* Read the levels symbol count table and calculate total */
|
/* Read the levels symbol count table and calculate total */
|
||||||
unpackd->symbol_size = 1; /* EOB */
|
unpackd->symbol_size = 1; /* EOB */
|
||||||
for (i = 0; i <= unpackd->treelevels; i++) {
|
for (i = 0; i <= unpackd->treelevels; i++) {
|
||||||
if ((thisbyte = fgetc(unpackd->fpIn)) == EOF)
|
if ((thisbyte = fgetc(unpackd->fpIn)) == EOF)
|
||||||
maybe_err("File appears to be truncated");
|
maybe_err("File appears to be truncated");
|
||||||
unpackd->symbolsin[i] = (unsigned char)thisbyte;
|
unpackd->symbolsin[i] = (unsigned char)thisbyte;
|
||||||
unpackd->symbol_size += unpackd->symbolsin[i];
|
unpackd->symbol_size += unpackd->symbolsin[i];
|
||||||
}
|
}
|
||||||
accepted_bytes(bytes_in, unpackd->treelevels);
|
accepted_bytes(bytes_in, unpackd->treelevels);
|
||||||
if (unpackd->symbol_size > 256)
|
if (unpackd->symbol_size > 256)
|
||||||
maybe_errx("Bad symbol table");
|
maybe_errx("Bad symbol table");
|
||||||
|
|
||||||
/* Allocate for the symbol table, point symbol_eob at the beginning */
|
/* Allocate for the symbol table, point symbol_eob at the beginning */
|
||||||
unpackd->symbol_eob = unpackd->symbol = calloc(1, unpackd->symbol_size);
|
unpackd->symbol_eob = unpackd->symbol = calloc(1, unpackd->symbol_size);
|
||||||
if (unpackd->symbol == NULL)
|
if (unpackd->symbol == NULL)
|
||||||
maybe_err("calloc");
|
maybe_err("calloc");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read in the symbol table, which contain [2, 256] symbols.
|
* Read in the symbol table, which contain [2, 256] symbols.
|
||||||
* In order to fit the count in one byte, pack(1) would offset
|
* In order to fit the count in one byte, pack(1) would offset
|
||||||
* it by reducing 2 from the actual number from the last level.
|
* it by reducing 2 from the actual number from the last level.
|
||||||
*
|
*
|
||||||
* We adjust the last level's symbol count by 1 here, because
|
* We adjust the last level's symbol count by 1 here, because
|
||||||
* the EOB symbol is not being transmitted explicitly. Another
|
* the EOB symbol is not being transmitted explicitly. Another
|
||||||
* adjustment would be done later afterward.
|
* adjustment would be done later afterward.
|
||||||
*/
|
*/
|
||||||
unpackd->symbolsin[unpackd->treelevels]++;
|
unpackd->symbolsin[unpackd->treelevels]++;
|
||||||
for (i = 0; i <= unpackd->treelevels; i++) {
|
for (i = 0; i <= unpackd->treelevels; i++) {
|
||||||
unpackd->tree[i] = unpackd->symbol_eob;
|
unpackd->tree[i] = unpackd->symbol_eob;
|
||||||
for (j = 0; j < unpackd->symbolsin[i]; j++) {
|
for (j = 0; j < unpackd->symbolsin[i]; j++) {
|
||||||
if ((thisbyte = fgetc(unpackd->fpIn)) == EOF)
|
if ((thisbyte = fgetc(unpackd->fpIn)) == EOF)
|
||||||
maybe_errx("Symbol table truncated");
|
maybe_errx("Symbol table truncated");
|
||||||
*unpackd->symbol_eob++ = (char)thisbyte;
|
*unpackd->symbol_eob++ = (char)thisbyte;
|
||||||
}
|
}
|
||||||
accepted_bytes(bytes_in, unpackd->symbolsin[i]);
|
accepted_bytes(bytes_in, unpackd->symbolsin[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now, take account for the EOB symbol as well */
|
/* Now, take account for the EOB symbol as well */
|
||||||
unpackd->symbolsin[unpackd->treelevels]++;
|
unpackd->symbolsin[unpackd->treelevels]++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The symbolsin table has been constructed now.
|
* The symbolsin table has been constructed now.
|
||||||
* Calculate the internal nodes count table based on it.
|
* Calculate the internal nodes count table based on it.
|
||||||
*/
|
*/
|
||||||
unpackd_fill_inodesin(unpackd, 0);
|
unpackd_fill_inodesin(unpackd, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decode huffman stream, based on the huffman tree.
|
* Decode huffman stream, based on the huffman tree.
|
||||||
*/
|
*/
|
||||||
static void
|
static void unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in) {
|
||||||
unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in)
|
int thislevel, thiscode, thisbyte, inlevelindex;
|
||||||
{
|
int i;
|
||||||
int thislevel, thiscode, thisbyte, inlevelindex;
|
off_t bytes_out = 0;
|
||||||
int i;
|
const char *thissymbol; /* The symbol pointer decoded from stream */
|
||||||
off_t bytes_out = 0;
|
|
||||||
const char *thissymbol; /* The symbol pointer decoded from stream */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decode huffman. Fetch every bytes from the file, get it
|
* Decode huffman. Fetch every bytes from the file, get it
|
||||||
* into 'thiscode' bit-by-bit, then output the symbol we got
|
* into 'thiscode' bit-by-bit, then output the symbol we got
|
||||||
* when one has been found.
|
* when one has been found.
|
||||||
*
|
*
|
||||||
* Assumption: sizeof(int) > ((max tree levels + 1) / 8).
|
* Assumption: sizeof(int) > ((max tree levels + 1) / 8).
|
||||||
* bad things could happen if not.
|
* bad things could happen if not.
|
||||||
*/
|
*/
|
||||||
thislevel = 0;
|
thislevel = 0;
|
||||||
thiscode = thisbyte = 0;
|
thiscode = thisbyte = 0;
|
||||||
|
|
||||||
while ((thisbyte = fgetc(unpackd->fpIn)) != EOF) {
|
while ((thisbyte = fgetc(unpackd->fpIn)) != EOF) {
|
||||||
accepted_bytes(bytes_in, 1);
|
accepted_bytes(bytes_in, 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Split one bit from thisbyte, from highest to lowest,
|
* Split one bit from thisbyte, from highest to lowest,
|
||||||
* feed the bit into thiscode, until we got a symbol from
|
* feed the bit into thiscode, until we got a symbol from
|
||||||
* the tree.
|
* the tree.
|
||||||
*/
|
*/
|
||||||
for (i = 7; i >= 0; i--) {
|
for (i = 7; i >= 0; i--) {
|
||||||
thiscode = (thiscode << 1) | ((thisbyte >> i) & 1);
|
thiscode = (thiscode << 1) | ((thisbyte >> i) & 1);
|
||||||
|
|
||||||
/* Did we got a symbol? (referencing leaf node) */
|
/* Did we got a symbol? (referencing leaf node) */
|
||||||
if (thiscode >= unpackd->inodesin[thislevel]) {
|
if (thiscode >= unpackd->inodesin[thislevel]) {
|
||||||
inlevelindex =
|
inlevelindex = thiscode - unpackd->inodesin[thislevel];
|
||||||
thiscode - unpackd->inodesin[thislevel];
|
if (inlevelindex > unpackd->symbolsin[thislevel])
|
||||||
if (inlevelindex > unpackd->symbolsin[thislevel])
|
maybe_errx("File corrupt");
|
||||||
maybe_errx("File corrupt");
|
|
||||||
|
|
||||||
thissymbol =
|
thissymbol = &(unpackd->tree[thislevel][inlevelindex]);
|
||||||
&(unpackd->tree[thislevel][inlevelindex]);
|
if ((thissymbol == unpackd->symbol_eob) &&
|
||||||
if ((thissymbol == unpackd->symbol_eob) &&
|
(bytes_out == unpackd->uncompressed_size))
|
||||||
(bytes_out == unpackd->uncompressed_size))
|
goto finished;
|
||||||
goto finished;
|
|
||||||
|
|
||||||
fputc((*thissymbol), unpackd->fpOut);
|
fputc((*thissymbol), unpackd->fpOut);
|
||||||
bytes_out++;
|
bytes_out++;
|
||||||
|
|
||||||
/* Prepare for next input */
|
/* Prepare for next input */
|
||||||
thislevel = 0; thiscode = 0;
|
thislevel = 0;
|
||||||
} else {
|
thiscode = 0;
|
||||||
thislevel++;
|
} else {
|
||||||
if (thislevel > unpackd->treelevels)
|
thislevel++;
|
||||||
maybe_errx("File corrupt");
|
if (thislevel > unpackd->treelevels)
|
||||||
}
|
maybe_errx("File corrupt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
finished:
|
finished:
|
||||||
if (bytes_out != unpackd->uncompressed_size)
|
if (bytes_out != unpackd->uncompressed_size)
|
||||||
maybe_errx("Premature EOF");
|
maybe_errx("Premature EOF");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handler for pack(1)'ed file */
|
/* Handler for pack(1)'ed file */
|
||||||
static off_t
|
static off_t unpack(int in, int out, char *pre, size_t prelen,
|
||||||
unpack(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
off_t *bytes_in) {
|
||||||
{
|
unpack_descriptor_t unpackd;
|
||||||
unpack_descriptor_t unpackd;
|
|
||||||
|
|
||||||
unpack_parse_header(dup(in), dup(out), pre, prelen, bytes_in, &unpackd);
|
unpack_parse_header(dup(in), dup(out), pre, prelen, bytes_in, &unpackd);
|
||||||
unpack_decode(&unpackd, bytes_in);
|
unpack_decode(&unpackd, bytes_in);
|
||||||
unpack_descriptor_fini(&unpackd);
|
unpack_descriptor_fini(&unpackd);
|
||||||
|
|
||||||
/* If we reached here, the unpack was successful */
|
/* If we reached here, the unpack was successful */
|
||||||
return (unpackd.uncompressed_size);
|
return (unpackd.uncompressed_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
/* $NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $ */
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
* Copyright (c) 2011 The Foundation, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
* This code is derived from software contributed to The Foundation
|
||||||
* by Christos Zoulas.
|
* by Christos Zoulas.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|
@ -17,13 +16,13 @@
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
* must display the following acknowledgement:
|
* must display the following acknowledgement:
|
||||||
* This product includes software developed by the NetBSD
|
* This product includes software developed by the
|
||||||
* Foundation, Inc. and its contributors.
|
* Foundation, Inc. and its contributors.
|
||||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
* 4. Neither the name of The Foundation nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived
|
* contributors may be used to endorse or promote products derived
|
||||||
* from this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
|
@ -36,125 +35,121 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $");
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <lzma.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <lzma.h>
|
|
||||||
|
|
||||||
static off_t
|
static off_t unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in) {
|
||||||
unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in)
|
lzma_stream strm = LZMA_STREAM_INIT;
|
||||||
{
|
static const int flags = LZMA_TELL_UNSUPPORTED_CHECK | LZMA_CONCATENATED;
|
||||||
lzma_stream strm = LZMA_STREAM_INIT;
|
lzma_ret ret;
|
||||||
static const int flags = LZMA_TELL_UNSUPPORTED_CHECK|LZMA_CONCATENATED;
|
lzma_action action = LZMA_RUN;
|
||||||
lzma_ret ret;
|
off_t bytes_out, bp;
|
||||||
lzma_action action = LZMA_RUN;
|
uint8_t ibuf[BUFSIZ];
|
||||||
off_t bytes_out, bp;
|
uint8_t obuf[BUFSIZ];
|
||||||
uint8_t ibuf[BUFSIZ];
|
|
||||||
uint8_t obuf[BUFSIZ];
|
|
||||||
|
|
||||||
if (bytes_in == NULL)
|
if (bytes_in == NULL)
|
||||||
bytes_in = &bp;
|
bytes_in = &bp;
|
||||||
|
|
||||||
strm.next_in = ibuf;
|
strm.next_in = ibuf;
|
||||||
memcpy(ibuf, pre, prelen);
|
memcpy(ibuf, pre, prelen);
|
||||||
strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
|
strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
|
||||||
if (strm.avail_in == (size_t)-1)
|
if (strm.avail_in == (size_t)-1)
|
||||||
maybe_err("read failed");
|
maybe_err("read failed");
|
||||||
strm.avail_in += prelen;
|
strm.avail_in += prelen;
|
||||||
*bytes_in = strm.avail_in;
|
*bytes_in = strm.avail_in;
|
||||||
|
|
||||||
if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, flags)) != LZMA_OK)
|
if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, flags)) != LZMA_OK)
|
||||||
maybe_errx("Can't initialize decoder (%d)", ret);
|
maybe_errx("Can't initialize decoder (%d)", ret);
|
||||||
|
|
||||||
strm.next_out = NULL;
|
strm.next_out = NULL;
|
||||||
strm.avail_out = 0;
|
strm.avail_out = 0;
|
||||||
if ((ret = lzma_code(&strm, LZMA_RUN)) != LZMA_OK)
|
if ((ret = lzma_code(&strm, LZMA_RUN)) != LZMA_OK)
|
||||||
maybe_errx("Can't read headers (%d)", ret);
|
maybe_errx("Can't read headers (%d)", ret);
|
||||||
|
|
||||||
bytes_out = 0;
|
bytes_out = 0;
|
||||||
strm.next_out = obuf;
|
strm.next_out = obuf;
|
||||||
strm.avail_out = sizeof(obuf);
|
strm.avail_out = sizeof(obuf);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (strm.avail_in == 0) {
|
if (strm.avail_in == 0) {
|
||||||
strm.next_in = ibuf;
|
strm.next_in = ibuf;
|
||||||
strm.avail_in = read(i, ibuf, sizeof(ibuf));
|
strm.avail_in = read(i, ibuf, sizeof(ibuf));
|
||||||
switch (strm.avail_in) {
|
switch (strm.avail_in) {
|
||||||
case (size_t)-1:
|
case (size_t)-1:
|
||||||
maybe_err("read failed");
|
maybe_err("read failed");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
case 0:
|
case 0:
|
||||||
action = LZMA_FINISH;
|
action = LZMA_FINISH;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*bytes_in += strm.avail_in;
|
*bytes_in += strm.avail_in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = lzma_code(&strm, action);
|
ret = lzma_code(&strm, action);
|
||||||
|
|
||||||
// Write and check write error before checking decoder error.
|
// Write and check write error before checking decoder error.
|
||||||
// This way as much data as possible gets written to output
|
// This way as much data as possible gets written to output
|
||||||
// even if decoder detected an error.
|
// even if decoder detected an error.
|
||||||
if (strm.avail_out == 0 || ret != LZMA_OK) {
|
if (strm.avail_out == 0 || ret != LZMA_OK) {
|
||||||
const size_t write_size = sizeof(obuf) - strm.avail_out;
|
const size_t write_size = sizeof(obuf) - strm.avail_out;
|
||||||
|
|
||||||
if (write(o, obuf, write_size) != (ssize_t)write_size)
|
if (write(o, obuf, write_size) != (ssize_t)write_size)
|
||||||
maybe_err("write failed");
|
maybe_err("write failed");
|
||||||
|
|
||||||
strm.next_out = obuf;
|
strm.next_out = obuf;
|
||||||
strm.avail_out = sizeof(obuf);
|
strm.avail_out = sizeof(obuf);
|
||||||
bytes_out += write_size;
|
bytes_out += write_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != LZMA_OK) {
|
if (ret != LZMA_OK) {
|
||||||
if (ret == LZMA_STREAM_END) {
|
if (ret == LZMA_STREAM_END) {
|
||||||
// Check that there's no trailing garbage.
|
// Check that there's no trailing garbage.
|
||||||
if (strm.avail_in != 0 || read(i, ibuf, 1))
|
if (strm.avail_in != 0 || read(i, ibuf, 1))
|
||||||
ret = LZMA_DATA_ERROR;
|
ret = LZMA_DATA_ERROR;
|
||||||
else {
|
else {
|
||||||
lzma_end(&strm);
|
lzma_end(&strm);
|
||||||
return bytes_out;
|
return bytes_out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *msg;
|
const char *msg;
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case LZMA_MEM_ERROR:
|
case LZMA_MEM_ERROR:
|
||||||
msg = strerror(ENOMEM);
|
msg = strerror(ENOMEM);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LZMA_FORMAT_ERROR:
|
case LZMA_FORMAT_ERROR:
|
||||||
msg = "File format not recognized";
|
msg = "File format not recognized";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LZMA_OPTIONS_ERROR:
|
case LZMA_OPTIONS_ERROR:
|
||||||
// FIXME: Better message?
|
// FIXME: Better message?
|
||||||
msg = "Unsupported compression options";
|
msg = "Unsupported compression options";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LZMA_DATA_ERROR:
|
case LZMA_DATA_ERROR:
|
||||||
msg = "File is corrupt";
|
msg = "File is corrupt";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LZMA_BUF_ERROR:
|
case LZMA_BUF_ERROR:
|
||||||
msg = "Unexpected end of input";
|
msg = "Unexpected end of input";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LZMA_MEMLIMIT_ERROR:
|
case LZMA_MEMLIMIT_ERROR:
|
||||||
msg = "Reached memory limit";
|
msg = "Reached memory limit";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
maybe_errx("Unknown error (%d)", ret);
|
maybe_errx("Unknown error (%d)", ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
maybe_errx("%s", msg);
|
maybe_errx("%s", msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
#!/bin/sh -
|
#!/bin/sh -
|
||||||
#
|
#
|
||||||
# $NetBSD: zdiff,v 1.5 2010/04/14 20:30:28 joerg Exp $
|
|
||||||
#
|
|
||||||
# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
|
# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
# Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
|
# Copyright (c) 2010 Joerg Sonnenberger <joerg@example.org>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
.\" $NetBSD: zdiff.1,v 1.5 2010/04/14 19:52:05 wiz Exp $
|
|
||||||
.\" $OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
|
.\" $OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
.\" Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
|
.\" Copyright (c) 2010 Joerg Sonnenberger <joerg@example.org>
|
||||||
.\"
|
.\"
|
||||||
.\" Permission to use, copy, modify, and distribute this software for any
|
.\" Permission to use, copy, modify, and distribute this software for any
|
||||||
.\" purpose with or without fee is hereby granted, provided that the above
|
.\" purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/sh -
|
#!/bin/sh -
|
||||||
#
|
#
|
||||||
# $NetBSD: zforce,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
|
||||||
#
|
|
||||||
# $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
# $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
.\" $NetBSD: zforce.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
|
||||||
.\" $OpenBSD: zforce.1,v 1.1 2003/07/29 11:50:09 otto Exp $
|
.\" $OpenBSD: zforce.1,v 1.1 2003/07/29 11:50:09 otto Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# $NetBSD: zgrep,v 1.9 2015/07/06 12:05:40 nakayama Exp $
|
|
||||||
#
|
|
||||||
# Copyright (c) 2003 Thomas Klausner.
|
# Copyright (c) 2003 Thomas Klausner.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
.\" $NetBSD: zgrep.1,v 1.3 2008/05/08 15:35:23 wiz Exp $
|
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Thomas Klausner.
|
.\" Copyright (c) 2003 Thomas Klausner.
|
||||||
.\"
|
.\"
|
||||||
|
|
@ -91,4 +90,4 @@ In case of missing arguments or missing pattern,
|
||||||
.Xr zcat 1
|
.Xr zcat 1
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.An Thomas Klausner
|
.An Thomas Klausner
|
||||||
.Aq wiz@NetBSD.org
|
.Aq wiz@example.org
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/sh -
|
#!/bin/sh -
|
||||||
#
|
#
|
||||||
# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $
|
|
||||||
#
|
|
||||||
# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
|
# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
.\" $NetBSD: zmore.1,v 1.4 2013/11/12 21:58:37 pettai Exp $
|
|
||||||
.\" $OpenBSD: zmore.1,v 1.10 2009/08/16 09:41:08 sobrado Exp $
|
.\" $OpenBSD: zmore.1,v 1.10 2009/08/16 09:41:08 sobrado Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#!/bin/ksh -
|
#!/bin/ksh -
|
||||||
#
|
#
|
||||||
# $NetBSD: znew,v 1.3 2008/04/27 09:07:13 nakayama Exp $
|
|
||||||
#
|
|
||||||
# $OpenBSD: znew,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
# $OpenBSD: znew,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
.\" $NetBSD: znew.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
|
||||||
.\" $OpenBSD: znew.1,v 1.1 2003/08/02 20:52:50 otto Exp $
|
.\" $OpenBSD: znew.1,v 1.1 2003/08/02 20:52:50 otto Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
/* $NetBSD: zuncompress.c,v 1.11 2011/08/16 13:55:02 joerg Exp $ */
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1985, 1986, 1992, 1993
|
* Copyright (c) 1985, 1986, 1992, 1993
|
||||||
|
|
@ -32,49 +31,47 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* from: NetBSD: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
|
* from: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This file is #included by gzip.c */
|
/* This file is #included by gzip.c */
|
||||||
|
|
||||||
static int zread(void *, char *, int);
|
static int zread(void *, char *, int);
|
||||||
|
|
||||||
#define tab_prefixof(i) (zs->zs_codetab[i])
|
#define tab_prefixof(i) (zs->zs_codetab[i])
|
||||||
#define tab_suffixof(i) ((char_type *)(zs->zs_htab))[i]
|
#define tab_suffixof(i) ((char_type *)(zs->zs_htab))[i]
|
||||||
#define de_stack ((char_type *)&tab_suffixof(1 << BITS))
|
#define de_stack ((char_type *)&tab_suffixof(1 << BITS))
|
||||||
|
|
||||||
#define BITS 16 /* Default bits. */
|
#define BITS 16 /* Default bits. */
|
||||||
#define HSIZE 69001 /* 95% occupancy */ /* XXX may not need HSIZE */
|
#define HSIZE 69001 /* 95% occupancy */ /* XXX may not need HSIZE */
|
||||||
#define BIT_MASK 0x1f /* Defines for third byte of header. */
|
#define BIT_MASK 0x1f /* Defines for third byte of header. */
|
||||||
#define BLOCK_MASK 0x80
|
#define BLOCK_MASK 0x80
|
||||||
#define CHECK_GAP 10000 /* Ratio check interval. */
|
#define CHECK_GAP 10000 /* Ratio check interval. */
|
||||||
#define BUFSIZE (64 * 1024)
|
#define BUFSIZE (64 * 1024)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
|
* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
|
||||||
* a fourth header byte (for expansion).
|
* a fourth header byte (for expansion).
|
||||||
*/
|
*/
|
||||||
#define INIT_BITS 9 /* Initial number of bits/code. */
|
#define INIT_BITS 9 /* Initial number of bits/code. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the next two codes should not be changed lightly, as they must not
|
* the next two codes should not be changed lightly, as they must not
|
||||||
* lie within the contiguous general code space.
|
* lie within the contiguous general code space.
|
||||||
*/
|
*/
|
||||||
#define FIRST 257 /* First free entry. */
|
#define FIRST 257 /* First free entry. */
|
||||||
#define CLEAR 256 /* Table clear output code. */
|
#define CLEAR 256 /* Table clear output code. */
|
||||||
|
|
||||||
|
#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
|
||||||
|
|
||||||
#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
|
typedef long code_int;
|
||||||
|
typedef long count_int;
|
||||||
|
typedef u_char char_type;
|
||||||
|
|
||||||
typedef long code_int;
|
static char_type magic_header[] = {'\037', '\235'}; /* 1F 9D */
|
||||||
typedef long count_int;
|
|
||||||
typedef u_char char_type;
|
|
||||||
|
|
||||||
static char_type magic_header[] =
|
static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f,
|
||||||
{'\037', '\235'}; /* 1F 9D */
|
0x1f, 0x3f, 0x7f, 0xff};
|
||||||
|
|
||||||
static char_type rmask[9] =
|
|
||||||
{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
|
|
||||||
|
|
||||||
/* XXX zuncompress global */
|
/* XXX zuncompress global */
|
||||||
off_t total_compressed_bytes;
|
off_t total_compressed_bytes;
|
||||||
|
|
@ -82,124 +79,116 @@ size_t compressed_prelen;
|
||||||
char *compressed_pre;
|
char *compressed_pre;
|
||||||
|
|
||||||
struct s_zstate {
|
struct s_zstate {
|
||||||
FILE *zs_fp; /* File stream for I/O */
|
FILE *zs_fp; /* File stream for I/O */
|
||||||
char zs_mode; /* r or w */
|
char zs_mode; /* r or w */
|
||||||
enum {
|
enum { S_START, S_MIDDLE, S_EOF } zs_state; /* State of computation */
|
||||||
S_START, S_MIDDLE, S_EOF
|
int zs_n_bits; /* Number of bits/code. */
|
||||||
} zs_state; /* State of computation */
|
int zs_maxbits; /* User settable max # bits/code. */
|
||||||
int zs_n_bits; /* Number of bits/code. */
|
code_int zs_maxcode; /* Maximum code, given n_bits. */
|
||||||
int zs_maxbits; /* User settable max # bits/code. */
|
code_int zs_maxmaxcode; /* Should NEVER generate this code. */
|
||||||
code_int zs_maxcode; /* Maximum code, given n_bits. */
|
count_int zs_htab[HSIZE];
|
||||||
code_int zs_maxmaxcode; /* Should NEVER generate this code. */
|
u_short zs_codetab[HSIZE];
|
||||||
count_int zs_htab [HSIZE];
|
code_int zs_hsize; /* For dynamic table sizing. */
|
||||||
u_short zs_codetab [HSIZE];
|
code_int zs_free_ent; /* First unused entry. */
|
||||||
code_int zs_hsize; /* For dynamic table sizing. */
|
/*
|
||||||
code_int zs_free_ent; /* First unused entry. */
|
* Block compression parameters -- after all codes are used up,
|
||||||
/*
|
* and compression rate changes, start over.
|
||||||
* Block compression parameters -- after all codes are used up,
|
*/
|
||||||
* and compression rate changes, start over.
|
int zs_block_compress;
|
||||||
*/
|
int zs_clear_flg;
|
||||||
int zs_block_compress;
|
long zs_ratio;
|
||||||
int zs_clear_flg;
|
count_int zs_checkpoint;
|
||||||
long zs_ratio;
|
int zs_offset;
|
||||||
count_int zs_checkpoint;
|
long zs_in_count; /* Length of input. */
|
||||||
int zs_offset;
|
long zs_bytes_out; /* Length of compressed output. */
|
||||||
long zs_in_count; /* Length of input. */
|
long zs_out_count; /* # of codes output (for debugging). */
|
||||||
long zs_bytes_out; /* Length of compressed output. */
|
char_type zs_buf[BITS];
|
||||||
long zs_out_count; /* # of codes output (for debugging). */
|
union {
|
||||||
char_type zs_buf[BITS];
|
struct {
|
||||||
union {
|
long zs_fcode;
|
||||||
struct {
|
code_int zs_ent;
|
||||||
long zs_fcode;
|
code_int zs_hsize_reg;
|
||||||
code_int zs_ent;
|
int zs_hshift;
|
||||||
code_int zs_hsize_reg;
|
} w; /* Write parameters */
|
||||||
int zs_hshift;
|
struct {
|
||||||
} w; /* Write parameters */
|
char_type *zs_stackp;
|
||||||
struct {
|
int zs_finchar;
|
||||||
char_type *zs_stackp;
|
code_int zs_code, zs_oldcode, zs_incode;
|
||||||
int zs_finchar;
|
int zs_roffset, zs_size;
|
||||||
code_int zs_code, zs_oldcode, zs_incode;
|
char_type zs_gbuf[BITS];
|
||||||
int zs_roffset, zs_size;
|
} r; /* Read parameters */
|
||||||
char_type zs_gbuf[BITS];
|
} u;
|
||||||
} r; /* Read parameters */
|
|
||||||
} u;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static code_int getcode(struct s_zstate *zs);
|
static code_int getcode(struct s_zstate *zs);
|
||||||
|
|
||||||
static off_t
|
static off_t zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
|
||||||
zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
|
off_t *compressed_bytes) {
|
||||||
off_t *compressed_bytes)
|
off_t bin, bout = 0;
|
||||||
{
|
char *buf;
|
||||||
off_t bin, bout = 0;
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
buf = malloc(BUFSIZE);
|
buf = malloc(BUFSIZE);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* XXX */
|
/* XXX */
|
||||||
compressed_prelen = prelen;
|
compressed_prelen = prelen;
|
||||||
if (prelen != 0)
|
if (prelen != 0)
|
||||||
compressed_pre = pre;
|
compressed_pre = pre;
|
||||||
else
|
else
|
||||||
compressed_pre = NULL;
|
compressed_pre = NULL;
|
||||||
|
|
||||||
while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
|
while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
|
||||||
if (tflag == 0 && (off_t)fwrite(buf, 1, bin, out) != bin) {
|
if (tflag == 0 && (off_t)fwrite(buf, 1, bin, out) != bin) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
bout += bin;
|
bout += bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressed_bytes)
|
if (compressed_bytes)
|
||||||
*compressed_bytes = total_compressed_bytes;
|
*compressed_bytes = total_compressed_bytes;
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return bout;
|
return bout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int zclose(void *zs) {
|
||||||
zclose(void *zs)
|
free(zs);
|
||||||
{
|
/* We leave the caller to close the fd passed to zdopen() */
|
||||||
free(zs);
|
return 0;
|
||||||
/* We leave the caller to close the fd passed to zdopen() */
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *
|
FILE *zdopen(int fd) {
|
||||||
zdopen(int fd)
|
struct s_zstate *zs;
|
||||||
{
|
|
||||||
struct s_zstate *zs;
|
|
||||||
|
|
||||||
if ((zs = calloc(1, sizeof(struct s_zstate))) == NULL)
|
if ((zs = calloc(1, sizeof(struct s_zstate))) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
zs->zs_state = S_START;
|
zs->zs_state = S_START;
|
||||||
|
|
||||||
/* XXX we can get rid of some of these */
|
/* XXX we can get rid of some of these */
|
||||||
zs->zs_hsize = HSIZE; /* For dynamic table sizing. */
|
zs->zs_hsize = HSIZE; /* For dynamic table sizing. */
|
||||||
zs->zs_free_ent = 0; /* First unused entry. */
|
zs->zs_free_ent = 0; /* First unused entry. */
|
||||||
zs->zs_block_compress = BLOCK_MASK;
|
zs->zs_block_compress = BLOCK_MASK;
|
||||||
zs->zs_clear_flg = 0; /* XXX we calloc()'d this structure why = 0? */
|
zs->zs_clear_flg = 0; /* XXX we calloc()'d this structure why = 0? */
|
||||||
zs->zs_ratio = 0;
|
zs->zs_ratio = 0;
|
||||||
zs->zs_checkpoint = CHECK_GAP;
|
zs->zs_checkpoint = CHECK_GAP;
|
||||||
zs->zs_in_count = 1; /* Length of input. */
|
zs->zs_in_count = 1; /* Length of input. */
|
||||||
zs->zs_out_count = 0; /* # of codes output (for debugging). */
|
zs->zs_out_count = 0; /* # of codes output (for debugging). */
|
||||||
zs->u.r.zs_roffset = 0;
|
zs->u.r.zs_roffset = 0;
|
||||||
zs->u.r.zs_size = 0;
|
zs->u.r.zs_size = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Layering compress on top of stdio in order to provide buffering,
|
* Layering compress on top of stdio in order to provide buffering,
|
||||||
* and ensure that reads and write work with the data specified.
|
* and ensure that reads and write work with the data specified.
|
||||||
*/
|
*/
|
||||||
if ((zs->zs_fp = fdopen(fd, "r")) == NULL) {
|
if ((zs->zs_fp = fdopen(fd, "r")) == NULL) {
|
||||||
free(zs);
|
free(zs);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return funopen(zs, zread, NULL, NULL, zclose);
|
return funopen(zs, zread, NULL, NULL, zclose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -208,117 +197,115 @@ zdopen(int fd)
|
||||||
* compressed file. The tables used herein are shared with those of the
|
* compressed file. The tables used herein are shared with those of the
|
||||||
* compress() routine. See the definitions above.
|
* compress() routine. See the definitions above.
|
||||||
*/
|
*/
|
||||||
static int
|
static int zread(void *cookie, char *rbp, int num) {
|
||||||
zread(void *cookie, char *rbp, int num)
|
u_int count, i;
|
||||||
{
|
struct s_zstate *zs;
|
||||||
u_int count, i;
|
u_char *bp, header[3];
|
||||||
struct s_zstate *zs;
|
|
||||||
u_char *bp, header[3];
|
|
||||||
|
|
||||||
if (num == 0)
|
if (num == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
zs = cookie;
|
zs = cookie;
|
||||||
count = num;
|
count = num;
|
||||||
bp = (u_char *)rbp;
|
bp = (u_char *)rbp;
|
||||||
switch (zs->zs_state) {
|
switch (zs->zs_state) {
|
||||||
case S_START:
|
case S_START:
|
||||||
zs->zs_state = S_MIDDLE;
|
zs->zs_state = S_MIDDLE;
|
||||||
break;
|
break;
|
||||||
case S_MIDDLE:
|
case S_MIDDLE:
|
||||||
goto middle;
|
goto middle;
|
||||||
case S_EOF:
|
case S_EOF:
|
||||||
goto eof;
|
goto eof;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the magic number */
|
/* Check the magic number */
|
||||||
for (i = 0; i < 3 && compressed_prelen; i++, compressed_prelen--)
|
for (i = 0; i < 3 && compressed_prelen; i++, compressed_prelen--)
|
||||||
header[i] = *compressed_pre++;
|
header[i] = *compressed_pre++;
|
||||||
|
|
||||||
if (fread(header + i, 1, sizeof(header) - i, zs->zs_fp) !=
|
if (fread(header + i, 1, sizeof(header) - i, zs->zs_fp) !=
|
||||||
sizeof(header) - i ||
|
sizeof(header) - i ||
|
||||||
memcmp(header, magic_header, sizeof(magic_header)) != 0) {
|
memcmp(header, magic_header, sizeof(magic_header)) != 0) {
|
||||||
errno = EFTYPE;
|
errno = EFTYPE;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
total_compressed_bytes = 0;
|
total_compressed_bytes = 0;
|
||||||
zs->zs_maxbits = header[2]; /* Set -b from file. */
|
zs->zs_maxbits = header[2]; /* Set -b from file. */
|
||||||
zs->zs_block_compress = zs->zs_maxbits & BLOCK_MASK;
|
zs->zs_block_compress = zs->zs_maxbits & BLOCK_MASK;
|
||||||
zs->zs_maxbits &= BIT_MASK;
|
zs->zs_maxbits &= BIT_MASK;
|
||||||
zs->zs_maxmaxcode = 1L << zs->zs_maxbits;
|
zs->zs_maxmaxcode = 1L << zs->zs_maxbits;
|
||||||
if (zs->zs_maxbits > BITS || zs->zs_maxbits < 12) {
|
if (zs->zs_maxbits > BITS || zs->zs_maxbits < 12) {
|
||||||
errno = EFTYPE;
|
errno = EFTYPE;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
/* As above, initialize the first 256 entries in the table. */
|
/* As above, initialize the first 256 entries in the table. */
|
||||||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
||||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--) {
|
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--) {
|
||||||
tab_prefixof(zs->u.r.zs_code) = 0;
|
tab_prefixof(zs->u.r.zs_code) = 0;
|
||||||
tab_suffixof(zs->u.r.zs_code) = (char_type) zs->u.r.zs_code;
|
tab_suffixof(zs->u.r.zs_code) = (char_type)zs->u.r.zs_code;
|
||||||
}
|
}
|
||||||
zs->zs_free_ent = zs->zs_block_compress ? FIRST : 256;
|
zs->zs_free_ent = zs->zs_block_compress ? FIRST : 256;
|
||||||
|
|
||||||
zs->u.r.zs_oldcode = -1;
|
zs->u.r.zs_oldcode = -1;
|
||||||
zs->u.r.zs_stackp = de_stack;
|
zs->u.r.zs_stackp = de_stack;
|
||||||
|
|
||||||
while ((zs->u.r.zs_code = getcode(zs)) > -1) {
|
while ((zs->u.r.zs_code = getcode(zs)) > -1) {
|
||||||
|
|
||||||
if ((zs->u.r.zs_code == CLEAR) && zs->zs_block_compress) {
|
if ((zs->u.r.zs_code == CLEAR) && zs->zs_block_compress) {
|
||||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0;
|
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--)
|
||||||
zs->u.r.zs_code--)
|
tab_prefixof(zs->u.r.zs_code) = 0;
|
||||||
tab_prefixof(zs->u.r.zs_code) = 0;
|
zs->zs_clear_flg = 1;
|
||||||
zs->zs_clear_flg = 1;
|
zs->zs_free_ent = FIRST;
|
||||||
zs->zs_free_ent = FIRST;
|
zs->u.r.zs_oldcode = -1;
|
||||||
zs->u.r.zs_oldcode = -1;
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
zs->u.r.zs_incode = zs->u.r.zs_code;
|
||||||
zs->u.r.zs_incode = zs->u.r.zs_code;
|
|
||||||
|
|
||||||
/* Special case for KwKwK string. */
|
/* Special case for KwKwK string. */
|
||||||
if (zs->u.r.zs_code >= zs->zs_free_ent) {
|
if (zs->u.r.zs_code >= zs->zs_free_ent) {
|
||||||
if (zs->u.r.zs_code > zs->zs_free_ent ||
|
if (zs->u.r.zs_code > zs->zs_free_ent || zs->u.r.zs_oldcode == -1) {
|
||||||
zs->u.r.zs_oldcode == -1) {
|
/* Bad stream. */
|
||||||
/* Bad stream. */
|
errno = EINVAL;
|
||||||
errno = EINVAL;
|
return (-1);
|
||||||
return (-1);
|
}
|
||||||
}
|
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar;
|
||||||
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar;
|
zs->u.r.zs_code = zs->u.r.zs_oldcode;
|
||||||
zs->u.r.zs_code = zs->u.r.zs_oldcode;
|
}
|
||||||
}
|
/*
|
||||||
/*
|
* The above condition ensures that code < free_ent.
|
||||||
* The above condition ensures that code < free_ent.
|
* The construction of tab_prefixof in turn guarantees that
|
||||||
* The construction of tab_prefixof in turn guarantees that
|
* each iteration decreases code and therefore stack usage is
|
||||||
* each iteration decreases code and therefore stack usage is
|
* bound by 1 << BITS - 256.
|
||||||
* bound by 1 << BITS - 256.
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/* Generate output characters in reverse order. */
|
/* Generate output characters in reverse order. */
|
||||||
while (zs->u.r.zs_code >= 256) {
|
while (zs->u.r.zs_code >= 256) {
|
||||||
*zs->u.r.zs_stackp++ = tab_suffixof(zs->u.r.zs_code);
|
*zs->u.r.zs_stackp++ = tab_suffixof(zs->u.r.zs_code);
|
||||||
zs->u.r.zs_code = tab_prefixof(zs->u.r.zs_code);
|
zs->u.r.zs_code = tab_prefixof(zs->u.r.zs_code);
|
||||||
}
|
}
|
||||||
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar = tab_suffixof(zs->u.r.zs_code);
|
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar = tab_suffixof(zs->u.r.zs_code);
|
||||||
|
|
||||||
/* And put them out in forward order. */
|
/* And put them out in forward order. */
|
||||||
middle: do {
|
middle:
|
||||||
if (count-- == 0)
|
do {
|
||||||
return (num);
|
if (count-- == 0)
|
||||||
*bp++ = *--zs->u.r.zs_stackp;
|
return (num);
|
||||||
} while (zs->u.r.zs_stackp > de_stack);
|
*bp++ = *--zs->u.r.zs_stackp;
|
||||||
|
} while (zs->u.r.zs_stackp > de_stack);
|
||||||
|
|
||||||
/* Generate the new entry. */
|
/* Generate the new entry. */
|
||||||
if ((zs->u.r.zs_code = zs->zs_free_ent) < zs->zs_maxmaxcode &&
|
if ((zs->u.r.zs_code = zs->zs_free_ent) < zs->zs_maxmaxcode &&
|
||||||
zs->u.r.zs_oldcode != -1) {
|
zs->u.r.zs_oldcode != -1) {
|
||||||
tab_prefixof(zs->u.r.zs_code) = (u_short) zs->u.r.zs_oldcode;
|
tab_prefixof(zs->u.r.zs_code) = (u_short)zs->u.r.zs_oldcode;
|
||||||
tab_suffixof(zs->u.r.zs_code) = zs->u.r.zs_finchar;
|
tab_suffixof(zs->u.r.zs_code) = zs->u.r.zs_finchar;
|
||||||
zs->zs_free_ent = zs->u.r.zs_code + 1;
|
zs->zs_free_ent = zs->u.r.zs_code + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remember previous code. */
|
/* Remember previous code. */
|
||||||
zs->u.r.zs_oldcode = zs->u.r.zs_incode;
|
zs->u.r.zs_oldcode = zs->u.r.zs_incode;
|
||||||
}
|
}
|
||||||
zs->zs_state = S_EOF;
|
zs->zs_state = S_EOF;
|
||||||
eof: return (num - count);
|
eof:
|
||||||
|
return (num - count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
|
|
@ -328,68 +315,68 @@ eof: return (num - count);
|
||||||
* Outputs:
|
* Outputs:
|
||||||
* code or -1 is returned.
|
* code or -1 is returned.
|
||||||
*/
|
*/
|
||||||
static code_int
|
static code_int getcode(struct s_zstate *zs) {
|
||||||
getcode(struct s_zstate *zs)
|
code_int gcode;
|
||||||
{
|
int r_off, bits, i;
|
||||||
code_int gcode;
|
char_type *bp;
|
||||||
int r_off, bits, i;
|
|
||||||
char_type *bp;
|
|
||||||
|
|
||||||
bp = zs->u.r.zs_gbuf;
|
bp = zs->u.r.zs_gbuf;
|
||||||
if (zs->zs_clear_flg > 0 || zs->u.r.zs_roffset >= zs->u.r.zs_size ||
|
if (zs->zs_clear_flg > 0 || zs->u.r.zs_roffset >= zs->u.r.zs_size ||
|
||||||
zs->zs_free_ent > zs->zs_maxcode) {
|
zs->zs_free_ent > zs->zs_maxcode) {
|
||||||
/*
|
/*
|
||||||
* If the next entry will be too big for the current gcode
|
* If the next entry will be too big for the current gcode
|
||||||
* size, then we must increase the size. This implies reading
|
* size, then we must increase the size. This implies reading
|
||||||
* a new buffer full, too.
|
* a new buffer full, too.
|
||||||
*/
|
*/
|
||||||
if (zs->zs_free_ent > zs->zs_maxcode) {
|
if (zs->zs_free_ent > zs->zs_maxcode) {
|
||||||
zs->zs_n_bits++;
|
zs->zs_n_bits++;
|
||||||
if (zs->zs_n_bits == zs->zs_maxbits) /* Won't get any bigger now. */
|
if (zs->zs_n_bits == zs->zs_maxbits) /* Won't get any bigger now. */
|
||||||
zs->zs_maxcode = zs->zs_maxmaxcode;
|
zs->zs_maxcode = zs->zs_maxmaxcode;
|
||||||
else
|
else
|
||||||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits);
|
zs->zs_maxcode = MAXCODE(zs->zs_n_bits);
|
||||||
}
|
}
|
||||||
if (zs->zs_clear_flg > 0) {
|
if (zs->zs_clear_flg > 0) {
|
||||||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
||||||
zs->zs_clear_flg = 0;
|
zs->zs_clear_flg = 0;
|
||||||
}
|
}
|
||||||
/* XXX */
|
/* XXX */
|
||||||
for (i = 0; i < zs->zs_n_bits && compressed_prelen; i++, compressed_prelen--)
|
for (i = 0; i < zs->zs_n_bits && compressed_prelen;
|
||||||
zs->u.r.zs_gbuf[i] = *compressed_pre++;
|
i++, compressed_prelen--)
|
||||||
zs->u.r.zs_size = fread(zs->u.r.zs_gbuf + i, 1, zs->zs_n_bits - i, zs->zs_fp);
|
zs->u.r.zs_gbuf[i] = *compressed_pre++;
|
||||||
zs->u.r.zs_size += i;
|
zs->u.r.zs_size =
|
||||||
if (zs->u.r.zs_size <= 0) /* End of file. */
|
fread(zs->u.r.zs_gbuf + i, 1, zs->zs_n_bits - i, zs->zs_fp);
|
||||||
return (-1);
|
zs->u.r.zs_size += i;
|
||||||
zs->u.r.zs_roffset = 0;
|
if (zs->u.r.zs_size <= 0) /* End of file. */
|
||||||
|
return (-1);
|
||||||
|
zs->u.r.zs_roffset = 0;
|
||||||
|
|
||||||
total_compressed_bytes += zs->u.r.zs_size;
|
total_compressed_bytes += zs->u.r.zs_size;
|
||||||
|
|
||||||
/* Round size down to integral number of codes. */
|
/* Round size down to integral number of codes. */
|
||||||
zs->u.r.zs_size = (zs->u.r.zs_size << 3) - (zs->zs_n_bits - 1);
|
zs->u.r.zs_size = (zs->u.r.zs_size << 3) - (zs->zs_n_bits - 1);
|
||||||
}
|
}
|
||||||
r_off = zs->u.r.zs_roffset;
|
r_off = zs->u.r.zs_roffset;
|
||||||
bits = zs->zs_n_bits;
|
bits = zs->zs_n_bits;
|
||||||
|
|
||||||
/* Get to the first byte. */
|
/* Get to the first byte. */
|
||||||
bp += (r_off >> 3);
|
bp += (r_off >> 3);
|
||||||
r_off &= 7;
|
r_off &= 7;
|
||||||
|
|
||||||
/* Get first part (low order bits). */
|
/* Get first part (low order bits). */
|
||||||
gcode = (*bp++ >> r_off);
|
gcode = (*bp++ >> r_off);
|
||||||
bits -= (8 - r_off);
|
bits -= (8 - r_off);
|
||||||
r_off = 8 - r_off; /* Now, roffset into gcode word. */
|
r_off = 8 - r_off; /* Now, roffset into gcode word. */
|
||||||
|
|
||||||
/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
|
/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
|
||||||
if (bits >= 8) {
|
if (bits >= 8) {
|
||||||
gcode |= *bp++ << r_off;
|
gcode |= *bp++ << r_off;
|
||||||
r_off += 8;
|
r_off += 8;
|
||||||
bits -= 8;
|
bits -= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* High order bits. */
|
/* High order bits. */
|
||||||
gcode |= (*bp & rmask[bits]) << r_off;
|
gcode |= (*bp & rmask[bits]) << r_off;
|
||||||
zs->u.r.zs_roffset += zs->zs_n_bits;
|
zs->u.r.zs_roffset += zs->zs_n_bits;
|
||||||
|
|
||||||
return (gcode);
|
return (gcode);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user