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