/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1993-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* pack [-] [-f] file ...
*
* pack files using Huffman coding
*
* David Korn
* AT&T Research
*
*/
static const char usage[] =
"[-?\n@(#)$Id: pack (AT&T Research) 2003-04-28 $\n]"
"[+NAME?pack - pack files using Huffman coding]"
"[+DESCRIPTION?\bpack\b attempts to store the specified files in a compressed "
"form using static Huffman coding. Wherever possible each \afile\a "
"is replaced by a packed file named \afile\a\b.z\b with the same "
"access modes, access and modified dates, and owner as those of "
"\afile\a. The \b-f\b option forces packing of \afile\a even when "
"there is no space benefit for packing the file.]"
"[+?If \bpack\b is successful, \afile\a will be removed. Packed files "
"can be restored to their original form using \bunpack\b or \bpcat\b.]"
"[+?\bpack\b uses Huffman (minimum redundancy) codes on a byte-by-byte basis. "
"Ordinarily, for each file that is packed, a line is written to "
"standard output containing \afile\a\b.z\b and the percent "
"compression. If the \b-v\b options is specified, or if the \b-\b "
"argument is specified, an internal flag is set that causes the "
"number of times each byte is used, its relative frequency, and the "
"code for the byte to be written to the standard output. Additional "
"occurrences of \b-\b in place of name cause the internal flag to be "
"set and reset.]"
"[+?No packing occurs if:]{"
"[+-?\afile\a appears to be already packed.]"
"[+-?\afile\a has links.]"
"[+-?\afile\a is a directory.]"
"[+-?\afile\a cannot be opened.]"
"[+-?No disk storage blocks will be saved by packing unless \b-f\b "
"is specified.]"
"[+-?A file called \afile\a\b.z\b already exists.]"
"[+-?The \b.z\b file cannot be created.]"
"[+-?An I/O error occurred during processing.]"
"}"
"[f:force?Pack the file even if the packed size is larger than the original.]"
"[v:verbose?Causes additional information to be written to standard ouput.]"
"\n"
"\nfile ...\n"
"\n"
"[+EXIT STATUS]{"
"[+0?All files packed successfully.]"
"[+\an\a?\an\a files failed to pack, where \an\a is less than 125.]"
"[+125?125 or more files failed to pack.]"
"}"
"[+SEE ALSO?\bunpack\b(1), \bpcat\b(1), \bcompress\b(1), \bgzip\b(1)]"
;
#include "huffman.h"
#include <error.h>
#include <ls.h>
static char *outname(char*);
int
{
{
case 'f':
force++;
break;
case 'v':
break;
case ':':
break;
case '?':
break;
}
{
if(*infile == '-')
{
/* awful way to handle options, but preserves SVID */
switch(infile[1])
{
case 'f':
force++;
continue;
case 0:
continue;
}
}
nfile++;
deleted = 0;
continue;
else
{
else
{
double diff;
if(verbose)
npack++;
deleted = 0;
}
}
if(hp)
if(fpin)
if(fpout)
if(deleted)
if(outfile)
}
if(nfile > 125)
nfile = 125;
}
{
register char *cp;
{
return((char*)0);
}
{
}
return(cp);
}
{
}