|
Packit |
df99a1 |
//C- -*- C++ -*-
|
|
Packit |
df99a1 |
//C- -------------------------------------------------------------------
|
|
Packit |
df99a1 |
//C- DjVuLibre-3.5
|
|
Packit |
df99a1 |
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
|
|
Packit |
df99a1 |
//C- Copyright (c) 2001 AT&T
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- This software is subject to, and may be distributed under, the
|
|
Packit |
df99a1 |
//C- GNU General Public License, either Version 2 of the license,
|
|
Packit |
df99a1 |
//C- or (at your option) any later version. The license should have
|
|
Packit |
df99a1 |
//C- accompanied the software or you may obtain a copy of the license
|
|
Packit |
df99a1 |
//C- from the Free Software Foundation at http://www.fsf.org .
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- This program is distributed in the hope that it will be useful,
|
|
Packit |
df99a1 |
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
df99a1 |
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
df99a1 |
//C- GNU General Public License for more details.
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
|
|
Packit |
df99a1 |
//C- Lizardtech Software. Lizardtech Software has authorized us to
|
|
Packit |
df99a1 |
//C- replace the original DjVu(r) Reference Library notice by the following
|
|
Packit |
df99a1 |
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- ------------------------------------------------------------------
|
|
Packit |
df99a1 |
//C- | DjVu (r) Reference Library (v. 3.5)
|
|
Packit |
df99a1 |
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
|
|
Packit |
df99a1 |
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
|
|
Packit |
df99a1 |
//C- | 6,058,214 and patents pending.
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | This software is subject to, and may be distributed under, the
|
|
Packit |
df99a1 |
//C- | GNU General Public License, either Version 2 of the license,
|
|
Packit |
df99a1 |
//C- | or (at your option) any later version. The license should have
|
|
Packit |
df99a1 |
//C- | accompanied the software or you may obtain a copy of the license
|
|
Packit |
df99a1 |
//C- | from the Free Software Foundation at http://www.fsf.org .
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | The computer code originally released by LizardTech under this
|
|
Packit |
df99a1 |
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
|
|
Packit |
df99a1 |
//C- | ORIGINAL CODE." Subject to any third party intellectual property
|
|
Packit |
df99a1 |
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
|
|
Packit |
df99a1 |
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
|
|
Packit |
df99a1 |
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
|
|
Packit |
df99a1 |
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
|
|
Packit |
df99a1 |
//C- | General Public License. This grant only confers the right to
|
|
Packit |
df99a1 |
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
|
|
Packit |
df99a1 |
//C- | the extent such infringement is reasonably necessary to enable
|
|
Packit |
df99a1 |
//C- | recipient to make, have made, practice, sell, or otherwise dispose
|
|
Packit |
df99a1 |
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
|
|
Packit |
df99a1 |
//C- | any greater extent that may be necessary to utilize further
|
|
Packit |
df99a1 |
//C- | modifications or combinations.
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
|
|
Packit |
df99a1 |
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
Packit |
df99a1 |
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
|
|
Packit |
df99a1 |
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
df99a1 |
//C- +------------------------------------------------------------------
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
df99a1 |
# include "config.h"
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#if NEED_GNUG_PRAGMAS
|
|
Packit |
df99a1 |
# pragma implementation
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// BZZ -- a frontend for BSByteStream
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** @name bzz
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
\begin{description}
|
|
Packit |
df99a1 |
\item[Compression:]
|
|
Packit |
df99a1 |
#bzz -e[<blocksize>] <infile> <outfile>#
|
|
Packit |
df99a1 |
\item[Decompression:]
|
|
Packit |
df99a1 |
#bzz -d <infile> <outfile>#
|
|
Packit |
df99a1 |
\end{description}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Program bzz is a simple front-end for the Burrows Wheeler encoder
|
|
Packit |
df99a1 |
implemented in \Ref{BSByteStream.h}. Although this compression model is
|
|
Packit |
df99a1 |
not currently used in DjVu files, it may be used in the future for
|
|
Packit |
df99a1 |
encoding textual data chunks. Argument #blocksize# is expressed in
|
|
Packit |
df99a1 |
kilobytes and must be in range 200 to 4096. The default value is 2048.
|
|
Packit |
df99a1 |
Arguments #infile# and #outfile# are the input and output filenames. A
|
|
Packit |
df99a1 |
single dash (#"-"#) can be used to represent the standard input or output.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
@memo
|
|
Packit |
df99a1 |
General purpose compression/decompression program
|
|
Packit |
df99a1 |
@author
|
|
Packit |
df99a1 |
L\'eon Bottou <leonb@research.att.com> -- initial implementation
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
//@{
|
|
Packit |
df99a1 |
//@}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include "GException.h"
|
|
Packit |
df99a1 |
#include "ByteStream.h"
|
|
Packit |
df99a1 |
#include "BSByteStream.h"
|
|
Packit |
df99a1 |
#include "GOS.h"
|
|
Packit |
df99a1 |
#include "GURL.h"
|
|
Packit |
df99a1 |
#include "DjVuMessage.h"
|
|
Packit |
df99a1 |
#include "common.h"
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static const char *program = "(unknown)";
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
void
|
|
Packit |
df99a1 |
usage(void)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
DjVuPrintErrorUTF8(
|
|
Packit |
df99a1 |
#ifdef DJVULIBRE_VERSION
|
|
Packit |
df99a1 |
"BZZ --- DjVuLibre-" DJVULIBRE_VERSION "\n"
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
"Compress/decompress <infile> using the Burrows Wheeler\n"
|
|
Packit |
df99a1 |
"transform and the ZP adaptive binary coder.\n\n"
|
|
Packit |
df99a1 |
"Usage [encoding]: %s -e[<blocksize>] <infile> <outfile>\n"
|
|
Packit |
df99a1 |
"Usage [decoding]: %s -d <infile> <outfile>\n"
|
|
Packit |
df99a1 |
" Argument <blocksize> must be in range [900..4096] (default 1100).\n"
|
|
Packit |
df99a1 |
" Arguments <infile> and <outfile> can be '-' for stdin/stdout.\n"
|
|
Packit |
df99a1 |
, program, program);
|
|
Packit |
df99a1 |
exit(1);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int
|
|
Packit |
df99a1 |
main(int argc, char **argv)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
DJVU_LOCALE;
|
|
Packit |
df99a1 |
GArray<GUTF8String> dargv(0,argc-1);
|
|
Packit |
df99a1 |
for(int i=0;i
|
|
Packit |
df99a1 |
dargv[i]=GNativeString(argv[i]);
|
|
Packit |
df99a1 |
G_TRY
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if(argc < 2)
|
|
Packit |
df99a1 |
usage();
|
|
Packit |
df99a1 |
// Get program name
|
|
Packit |
df99a1 |
program=dargv[0]=GOS::basename(dargv[0]);
|
|
Packit |
df99a1 |
// Obtain default mode from program name
|
|
Packit |
df99a1 |
int blocksize = -1;
|
|
Packit |
df99a1 |
if (dargv[0] == "bzz")
|
|
Packit |
df99a1 |
blocksize = 1100;
|
|
Packit |
df99a1 |
else if (dargv[0] == "unbzz")
|
|
Packit |
df99a1 |
blocksize = 0;
|
|
Packit |
df99a1 |
// Parse arguments
|
|
Packit |
df99a1 |
if (argc>=2 && dargv[1][0]=='-')
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (dargv[1][1]=='d' && dargv[1][2]==0)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
blocksize = 0;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
else if (dargv[1][1]=='e')
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
blocksize = 2048;
|
|
Packit |
df99a1 |
if (dargv[1][2])
|
|
Packit |
df99a1 |
blocksize = dargv[1].substr(2, dargv[1].length()).toInt(); //atoi(2+(const char *)dargv[1]);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
else
|
|
Packit |
df99a1 |
usage();
|
|
Packit |
df99a1 |
dargv.shift(-1);
|
|
Packit |
df99a1 |
argc--;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
if (blocksize < 0)
|
|
Packit |
df99a1 |
usage();
|
|
Packit |
df99a1 |
// Obtain filenames
|
|
Packit |
df99a1 |
const GURL::Filename::UTF8 inurl((argc>=2)?dargv[1]:GUTF8String("-"));
|
|
Packit |
df99a1 |
const GURL::Filename::UTF8 outurl((argc>=3)?dargv[2]:GUTF8String("-"));
|
|
Packit |
df99a1 |
if (argc >= 4)
|
|
Packit |
df99a1 |
usage();
|
|
Packit |
df99a1 |
// Action
|
|
Packit |
df99a1 |
GP<ByteStream> in=ByteStream::create(inurl,"rb");
|
|
Packit |
df99a1 |
GP<ByteStream> out=ByteStream::create(outurl,"wb");
|
|
Packit |
df99a1 |
if (blocksize)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
GP<ByteStream> gbsb=BSByteStream::create(out, blocksize);
|
|
Packit |
df99a1 |
gbsb->copy(*in);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
else
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
GP<ByteStream> gbsb=BSByteStream::create(in);
|
|
Packit |
df99a1 |
out->copy(*gbsb);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
G_CATCH(ex)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
ex.perror();
|
|
Packit |
df99a1 |
exit(1);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
G_ENDCATCH;
|
|
Packit |
df99a1 |
return 0;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|