Skip to content

Commit

Permalink
file_cmds-212.1
Browse files Browse the repository at this point in the history
  • Loading branch information
saagarjha committed Nov 12, 2019
1 parent 76c7b99 commit 96758a7
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 67 deletions.
131 changes: 97 additions & 34 deletions compress/compress.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -45,65 +41,98 @@
.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
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
.Pq Sq Fl ,
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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 ,
Expand Down Expand Up @@ -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.
6 changes: 1 addition & 5 deletions compress/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -44,7 +40,7 @@ static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94";
#endif

#include <sys/cdefs.h>
__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 <sys/param.h>
#include <sys/stat.h>
Expand Down
4 changes: 2 additions & 2 deletions compress/doc/NOTES
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

Expand Down Expand Up @@ -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.

Expand Down
12 changes: 3 additions & 9 deletions compress/doc/revision.log
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 $";
6 changes: 1 addition & 5 deletions compress/zopen.3
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
31 changes: 19 additions & 12 deletions compress/zopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,7 +36,7 @@ static char sccsid[] = "@(#)zopen.c 8.1 (Berkeley) 6/27/93";
#endif /* LIBC_SCCS and not lint */

#include <sys/cdefs.h>
__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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 96758a7

Please sign in to comment.