From e19e38b253de139e081f5d462bc053e7b809ea38 Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 2 Nov 2011 00:05:17 +0000 Subject: [PATCH] file_cmds-212.1.tar.gz --- compress/compress.1 | 131 ++++++++++++++++++++++++++++---------- compress/compress.c | 6 +- compress/doc/NOTES | 4 +- compress/doc/revision.log | 12 +--- compress/zopen.3 | 6 +- compress/zopen.c | 31 +++++---- 6 files changed, 123 insertions(+), 67 deletions(-) diff --git a/compress/compress.1 b/compress/compress.1 index b616c13..a353c19 100644 --- a/compress/compress.1 +++ b/compress/compress.1 @@ -13,10 +13,6 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. @@ -34,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)compress.1 8.2 (Berkeley) 4/18/94 -.\" $FreeBSD: src/usr.bin/compress/compress.1,v 1.19 2004/07/05 17:12:53 ru Exp $ +.\" $FreeBSD: src/usr.bin/compress/compress.1,v 1.23 2010/12/11 08:32:16 joel Exp $ .\" .Dd May 17, 2002 .Dt COMPRESS 1 @@ -45,33 +41,50 @@ .Nd compress and expand data .Sh SYNOPSIS .Nm -.Op Fl cfv +.Op Fl fv .Op Fl b Ar bits .Op Ar +.Nm +.Fl c +.Op Fl b Ar bits +.Op Ar file .Nm uncompress -.Op Fl cfv +.Op Fl fv .Op Ar +.Nm uncompress +.Fl c +.Op Ar file .Sh DESCRIPTION The .Nm -utility reduces the size of the named files using adaptive Lempel-Ziv coding. +utility reduces the size of files using adaptive Lempel-Ziv coding. Each .Ar file is renamed to the same name plus the extension -.Dq .Z . -As many of the modification time, access time, file flags, file mode, -user ID, and group ID as allowed by permissions are retained in the -new file. +.Pa .Z . +A +.Ar file +argument with a +.Pa .Z +extension will be ignored except it will cause an +error exit after other arguments are processed. If compression would not reduce the size of a .Ar file , the file is ignored. .Pp The .Nm uncompress -utility restores the compressed files to their original form, renaming the +utility restores compressed files to their original form, renaming the files by deleting the -.Dq .Z +.Pa .Z +extensions. +A file specification need not include the file's +.Pa .Z extension. +If a file's name in its file system does not have a +.Pa .Z +extension, it will not be uncompressed and it will cause +an error exit after other arguments are processed. .Pp If renaming the files would cause files to be overwritten and the standard input device is a terminal, the user is prompted (on the standard error @@ -79,6 +92,10 @@ output) for confirmation. If prompting is not possible or confirmation is not received, the files are not overwritten. .Pp +As many of the modification time, access time, file flags, file mode, +user ID, and group ID as allowed by permissions are retained in the +new file. +.Pp If no files are specified or a .Ar file argument is a single dash @@ -86,24 +103,36 @@ argument is a single dash the standard input is compressed or uncompressed to the standard output. If either the input and output files are not regular files, the checks for reduction in size and file overwriting are not performed, the input file is -not removed, and the attributes of the input file are not retained. +not removed, and the attributes of the input file are not retained +in the output file. .Pp The options are as follows: -.Bl -tag -width indent -.It Fl b -Specify the -.Ar bits -code limit (see below). +.Bl -tag -width ".Fl b Ar bits" +.It Fl b Ar bits +The code size (see below) is limited to +.Ar bits , +which must be in the range 9..16. +The default is 16. .It Fl c Compressed or uncompressed output is written to the standard output. No files are modified. +The +.Fl v +option is ignored. +Compression is attempted even if the results will be larger than the +original. .It Fl f -Force compression of -.Ar file , -even if it is not actually reduced in size. -Additionally, files are overwritten without prompting for confirmation. +Files are overwritten without prompting for confirmation. +Also, for +.Nm compress , +files are compressed even if they are not actually reduced in size. .It Fl v Print the percentage reduction of each file. +Ignored by +.Nm uncompress +or if the +.Fl c +option is also used. .El .Pp The @@ -114,13 +143,9 @@ When code 512 is reached, the algorithm switches to 10-bit codes and continues to use more bits until the limit specified by the .Fl b -flag is reached (the default is 16). -.Ar Bits -must be between 9 and 16. +option or its default is reached. .Pp -After the -.Ar bits -limit is reached, +After the limit is reached, .Nm periodically checks the compression ratio. If it is increasing, @@ -134,7 +159,7 @@ the algorithm to adapt to the next "block" of the file. .Pp The .Fl b -flag is omitted for +option is unavailable for .Nm uncompress since the .Ar bits @@ -152,15 +177,15 @@ Compression is generally much better than that achieved by Huffman coding (as used in the historical command pack), or adaptive Huffman coding (as used in the historical command compact), and takes less time to compute. -.Sh DIAGNOSTICS +.Sh EXIT STATUS .Ex -std compress uncompress .Pp The .Nm compress -utility exits 2 if attempting to compress the file would not reduce its size +utility exits 2 if attempting to compress a file would not reduce its size and the .Fl f -option was not specified. +option was not specified and if no other error occurs. .Sh SEE ALSO .Xr gunzip 1 , .Xr gzexe 1 , @@ -188,3 +213,41 @@ The .Nm command appeared in .Bx 4.3 . +.Sh BUGS +Some of these might be considered otherwise-undocumented features. +.Pp +.Nm compress : +If the utility does not compress a file because doing so would not +reduce its size, and a file of the same name except with an +.Pa .Z +extension exists, the named file is not really ignored as stated above; +it causes a prompt to confirm the overwriting of the file with the extension. +If the operation is confirmed, that file is deleted. +.Pp +.Nm uncompress : +If an empty file is compressed (using +.Fl f ) , +the resulting +.Pa .Z +file is also empty. +That seems right, but if +.Nm uncompress +is then used on that file, an error will occur. +.Pp +Both utilities: If a +.Sq Fl +argument is used and the utility prompts the user, the standard input +is taken as the user's reply to the prompt. +.Pp +Both utilities: +If the specified file does not exist, but a similarly-named one with (for +.Nm compress ) +or without (for +.Nm uncompress ) +a +.Pa .Z +extension does exist, the utility will waste the user's time by not +immediately emitting an error message about the missing file and +continuing. +Instead, it first asks for confirmation to overwrite +the existing file and then does not overwrite it. diff --git a/compress/compress.c b/compress/compress.c index 03311f9..ffbc7e4 100644 --- a/compress/compress.c +++ b/compress/compress.c @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -44,7 +40,7 @@ static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94"; #endif #include -__FBSDID("$FreeBSD: src/usr.bin/compress/compress.c,v 1.21 2003/06/14 13:41:31 trhodes Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/compress/compress.c,v 1.23 2010/12/11 08:32:16 joel Exp $"); #include #include diff --git a/compress/doc/NOTES b/compress/doc/NOTES index aec6b75..4ced689 100644 --- a/compress/doc/NOTES +++ b/compress/doc/NOTES @@ -1,5 +1,5 @@ - $FreeBSD: src/usr.bin/compress/doc/NOTES,v 1.2 2002/10/16 12:42:15 charnier Exp $ + $FreeBSD: src/usr.bin/compress/doc/NOTES,v 1.3 2011/10/16 14:30:28 eadler Exp $ From: James A. Woods @@ -51,7 +51,7 @@ comprehensive survey of an area which will remain murky for some time. Until the dust clears, how you approach ideas which are patented depends on how paranoid you are of a legal onslaught. Arbitrary? Yes. But -the patent bar the the CCPA (Court of Customs and Patent Appeals) +the patent bar the CCPA (Court of Customs and Patent Appeals) thanks you for any uncertainty as they, at least, stand to gain from any trouble. diff --git a/compress/doc/revision.log b/compress/doc/revision.log index fb23b08..04c96e6 100644 --- a/compress/doc/revision.log +++ b/compress/doc/revision.log @@ -1,13 +1,7 @@ -/* $FreeBSD: src/usr.bin/compress/doc/revision.log,v 1.4 2001/08/13 14:06:30 ru Exp $ */ +/* $FreeBSD: src/usr.bin/compress/doc/revision.log,v 1.5 2011/03/31 14:35:33 emaste Exp $ */ /* - * $Header: /Users/Shared/file_cmds/file_cmds/compress/doc/revision.log,v 1.3 2005/04/12 23:51:24 nicolai Exp $ - * $Log: revision.log,v $ - * Revision 1.3 2005/04/12 23:51:24 nicolai - * merging Tiger back to head - * - * Revision 1.1.1.2 2004/07/21 04:59:15 llattanz - * Freshen source for standards conformance + * $Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $ * * Revision 4.0 85/07/30 12:50:00 joe * Removed ferror() calls in output routine on every output except first. @@ -121,4 +115,4 @@ */ static char rcs_ident[] = - "$Header: /Users/Shared/file_cmds/file_cmds/compress/doc/revision.log,v 1.3 2005/04/12 23:51:24 nicolai Exp $"; + "$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $"; diff --git a/compress/zopen.3 b/compress/zopen.3 index 730a120..f6c7f34 100644 --- a/compress/zopen.3 +++ b/compress/zopen.3 @@ -9,10 +9,6 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. @@ -30,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)zopen.3 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD: src/usr.bin/compress/zopen.3,v 1.8 2001/10/01 15:01:57 ru Exp $ +.\" $FreeBSD: src/usr.bin/compress/zopen.3,v 1.9 2010/12/11 08:32:16 joel Exp $ .\" .Dd June 9, 1993 .Dt ZOPEN 3 diff --git a/compress/zopen.c b/compress/zopen.c index 030755f..0191f77 100644 --- a/compress/zopen.c +++ b/compress/zopen.c @@ -14,10 +14,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -40,7 +36,7 @@ static char sccsid[] = "@(#)zopen.c 8.1 (Berkeley) 6/27/93"; #endif /* LIBC_SCCS and not lint */ #include -__FBSDID("$FreeBSD: src/usr.bin/compress/zopen.c,v 1.10 2002/07/28 15:32:17 dwmalone Exp $"); +__FBSDID("$FreeBSD: src/usr.bin/compress/zopen.c,v 1.17 2011/09/28 08:47:17 bz Exp $"); /*- * fcompress.c - File compression ala IEEE Computer, June 1984. @@ -131,7 +127,7 @@ struct s_zstate { code_int zs_ent; code_int zs_hsize_reg; int zs_hshift; - } w; /* Write paramenters */ + } w; /* Write parameters */ struct { char_type *zs_stackp; int zs_finchar; @@ -490,7 +486,7 @@ zread(void *cookie, char *rbp, int num) block_compress = maxbits & BLOCK_MASK; maxbits &= BIT_MASK; maxmaxcode = 1L << maxbits; - if (maxbits > BITS) { + if (maxbits > BITS || maxbits < 12) { errno = EFTYPE; return (-1); } @@ -517,17 +513,28 @@ zread(void *cookie, char *rbp, int num) for (code = 255; code >= 0; code--) tab_prefixof(code) = 0; clear_flg = 1; - free_ent = FIRST - 1; - if ((code = getcode(zs)) == -1) /* O, untimely death! */ - break; + free_ent = FIRST; + oldcode = -1; + continue; } incode = code; - /* Special case for KwKwK string. */ + /* Special case for kWkWk string. */ if (code >= free_ent) { + if (code > free_ent || oldcode == -1) { + /* Bad stream. */ + errno = EINVAL; + return (-1); + } *stackp++ = finchar; code = oldcode; } + /* + * The above condition ensures that code < free_ent. + * The construction of tab_prefixof in turn guarantees that + * each iteration decreases code and therefore stack usage is + * bound by 1 << BITS - 256. + */ /* Generate output characters in reverse order. */ while (code >= 256) { @@ -544,7 +551,7 @@ middle: do { } while (stackp > de_stack); /* Generate the new entry. */ - if ((code = free_ent) < maxmaxcode) { + if ((code = free_ent) < maxmaxcode && oldcode != -1) { tab_prefixof(code) = (u_short) oldcode; tab_suffixof(code) = finchar; free_ent = code + 1; -- 2.45.2