vczip.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
0N/A/*********************************************************************** 0N/A* This software is part of the ast package * 0N/A* Copyright (c) 2003-2011 AT&T Intellectual Property * 0N/A* and is licensed under the * 0N/A* Eclipse Public License, Version 1.0 * 2362N/A* by AT&T Intellectual Property * 2362N/A* A copy of the License is available at * 0N/A* (with md5 checksum b35adb5213ca9657e911e9befb180842) * 0N/A* Information and Software Systems Research * 0N/A* Phong Vo <kpv@research.att.com> * 0N/A* Glenn Fowler <gsf@research.att.com> * 0N/A***********************************************************************/ 2362N/A/* Command to encode and decode with Vcodex methods. 2362N/A** Written by Kiem-Phong Vo (09/06/2003 - ILNGUYEN) 0N/A"[-?\n@(#)$Id: vczip (AT&T Research) 2009-10-01 $\n]" 0N/A"[+DESCRIPTION?\bvczip\b is a filter that decodes the standard input " 0N/A "and/or encodes the standard output. The \b--method\b option specifies " 0N/A "the encoding. The default encoding is \b--method=" DFLTZIP "\b. The " 0N/A "method is automatically determined when decoding.]" 0N/A"[+?For delta methods the \asource\a operand optionally specifies the " 0N/A "file to delta against. If \asource\a is omitted then the input file is " 0N/A "simply compressed. Delta-encoded data must be decoded with the same " 0N/A"[+?Method aliases may be defined in \b../" ALIASES "\b in one of the " 0N/A "directories on \b$PATH\b, or in \b$HOME/" VCZIPRC "\b, searched in " 0N/A "order. Each alias is a \aname=value\a pair where \avalue\a is a " 0N/A "\b--method\b option value, described below. Method names are searched " 0N/A "before alias names.]" 0N/A"[i:input?Input data is read from \afile\a instead of the standard " 0N/A"[m:method|encode?Set the transformation method from the \b,\b (or \b^\b) " 0N/A "separated list of \amethod\a[.\aarg\a]] elements, where \amethod\a is " 0N/A "a method alias or primitive method, \aarg\a is an optional method " 0N/A "specific argument, and \b-\b denotes the default argument. Parenthesized " 0N/A "values are implementation details. The \alibvcodex\a (\b-catalog\b) " 0N/A "denotes a method supplied by the default library. Otherwise the method " 0N/A "is a separate plugin; that plugin will be required to decode any " 0N/A "encoded data. The primitive methods and method aliases " 0N/A "are:]:[method[.arg]][,method[.arg]]...]]:=" DFLTZIP "]" 0N/A "{\fvcodex\f[vcdiff|ietf?Encode as defined in IETF RFC3284.]}" 0N/A"[o:output?Output data is written to \afile\a instead of the standard " 0N/A"[p:plain?Do not encode transformation information in the data. This means " 0N/A "the transform must be explicitly supplied to decode.]" 0N/A"[q:identify?Identify the standard input encoding and write the " 0N/A "\b--method\b transformation string on the standard output. " 0N/A "If the standard input is not vczip encoded then nothing is " 0N/A"[t:transform?Apply the \bcodex\b(3) data transform around the " 0N/A "\bvcodex\b(3) transform. A codex transform is a catenation of the " 0N/A "following methods, each method prefixed by \b<\b to decode the input or " 0N/A "\b>\b to encode the output. Method arguments, if any, must be prefixed " 0N/A "by \b-\b. The method are:]:[[<>]]method[-arg...]]...]" 0N/A"[u:undo|decode?Decode data.]" 0N/A"[v:verbose?List the compresses size on the standard error.]" 0N/A"[w:window?Set the data partition window size to \awindow\a. " 0N/A "\amethod\a specifies an optional window matching " 0N/A "method. The window methods are:]:[window[,method]]]" 0N/A"[d:vcdiff|ietf?Encode as defined in IETF RFC3284. Obsolete -- use " 0N/A"[D:debug?Set the debug trace level to \alevel\a. Higher levels produce " 0N/A "more output.]:[level]" 0N/A"[M:move?Use sfmove() for io.]" 0N/A"[P:pause?Debug: print the pid and sleep(10); then continue processing.]" 0N/A"\n[ source ] < input > output\n" 0N/A "[+../" ALIASES "?\b--method\b \aname=value\a alias file, found " 0N/A"[+SEE ALSO?\bcodex\b(1), \bcodex\b(3), \bvcodex\b(3)]" 0N/A * optget() info discipline function 0N/A register const char* p;
0N/A /* vcodex methods */ 0N/A /* vcodex window methods */ 0N/Aapply(
int action,
const char*
vt,
Vcsfdata_t*
vcodexdisc,
const char*
ct,
Codexdisc_t*
codexdisc,
const char*
input,
const char*
source,
const char*
output,
void*
buf,
size_t bufsize,
Sfoff_t donez,
Sfoff_t lastz)
0N/A * set up the sfio input stream 0N/A * set up the sfio output stream 0N/A * check codex sfio discipline 0N/A * check vcodex sfio discipline 0N/A * copy from ip to op 0N/A char*
vt;
/* vcodex transform */ 0N/A char*
ct;
/* codex transform */ 0N/A char name[
256];
/* method name buffer */ 0N/A /* NOTE: disciplines may be accessed after main() returns */ 0N/A apply(
action,
vt, &
vcodexdisc,
ct, &
codexdisc,
NiL, *
argv,
NiL,
buf,
bufsize,
donez,
lastz);
0N/A#
define DFLTZIP "sieve.delta,bwt,mtf,rle.0,huffgroup" 0N/A "vczip [-Arguments] [SourceFile] < Input > Output\n",
0N/A "\nBelow are the standard 'Arguments':\n",
0N/A "-?: This prints this message.\n",
0N/A "-i[InputFile]: This redefines the standard 'Input' to be 'InputFile'.\n",
0N/A "-o[OutputFile]: This redefines the standard 'Output' to be 'OutputFile'.\n",
0N/A "-w[size[.alg]]: This argument is ignored during decoding (i.e., -u).\n",
0N/A " On encoding, it defines the window processing for a large input file.\n",
0N/A " 'size' is the window size, i.e., the size to break the input file into\n",
0N/A " chunks for processing. Units 'k' and 'm' mean kilo and megabytes.\n",
0N/A " 'alg' selects a windowing matching algorithm for delta compression:\n",
0N/A " p: matching windows by a prefix matching method (default) or\n",
0N/A " m: matching windows by simply mirroring file positions.\n",
0N/A "-E[type]: This translates between EBCDIC and ASCII during encoding or\n",
0N/A " decoding via the given 'type'. See also the 'map' transform below.\n",
0N/A "-vcdiff: This encodes data as defined in IETF RFC3284.\n",
0N/A "-plain: This means that the transformed data will not have information\n",
0N/A " about the transformation used for encoding. So, that information\n",
0N/A " will have to be supplied explicitly on decoding.\n",
0N/A "-u[transformation]: This decodes some previously encoded data.\n",
0N/A " If 'transformation' is not empty, it is the transformation used\n",
0N/A " to encode data. The data to be decoded will be treated as if it\n",
0N/A " was encoded with '-plain'. That is, '-utransformation' is the same\n",
0N/A " as '-u -plain -mtransformation'.\n",
0N/A "-m[transformation]: A 'transformation' is defined as a comma-separated list:\n",
0N/A " transform1[.arg11.arg12...],transform2[.arg21.arg22],...'\n",
0N/A " For example, '-mbwt,mtf,rle.0,huffgroup' defines a transformation that\n" 0N/A " compresses data based on the Burrows-Wheeler transform. When the first\n",
0N/A " transform in a transformation is a delta compressor such as 'delta' or\n",
0N/A " 'sieve', a 'SourceFile' can help enhancing compression. In that case,\n" 0N/A " the same source file must be given on both encoding and decoding.\n",
0N/A /* print the set of primitive methods */ 0N/A int type = 0;
/* type of processing */ 0N/A /* get program name */ 0N/A /* make list of default aliases */ 0N/A ;
/* state file has been made obsolete */ 0N/A case 'E':
/* ebcdic <-> ascii translation */ 0N/A error(
"Program name should be vczip or vcunzip");
0N/A /* see if this is just a pipe showing up initially empty */ 0N/A return 0;
/* empty data transforms to empty output */ 0N/A /* turn off share mode to avoid peeking on unseekable devices */ 0N/A#
if _WIN32 /* on Windows systems, use binary mode for file I/O */ 0N/A /* open stream for data processing */ 0N/A error(
"Can't set up stream to encode or decode data.");
0N/A /* get buffer for IO */ 0N/A if(!
eavc)
/* do any ascii <-> ebcdic mapping required */