-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbzz.cpp
More file actions
161 lines (149 loc) · 4.51 KB
/
bzz.cpp
File metadata and controls
161 lines (149 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//C- Copyright © 1999-2001 LizardTech, Inc. All Rights Reserved.
//C-
//C- This software (the "Original Code") is subject to, and may be
//C- distributed under, the GNU General Public License, Version 2.
//C- You may obtain a copy of the license from the Free Software
//C- Foundation at http://www.fsf.org .
//C-
//C- With respect to the Original Code, and subject to any third party
//C- intellectual property claims, LizardTech grants recipient a worldwide,
//C- royalty-free, non-exclusive license under patent claims infringed by
//C- making, using, or selling Original Code which are now or hereafter
//C- owned or controlled by LizardTech, but solely to the extent that any
//C- such patent is reasonably necessary to enable you to make, have made,
//C- practice, sell, or otherwise dispose of Original Code (or portions
//C- thereof) and not to any greater extent that may be necessary to utilize
//C- further modifications or combinations.
//C-
//C- The Original Code is provided "AS IS" WITHOUT WARRANTY OF ANY KIND,
//C- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY
//C- OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF MERCHANTIBILITY OF
//C- FITNESS FOR A PARTICULAR PURPOSE.
//C-
// BZZ -- a frontend for BSByteStream
/** @name bzz
\begin{description}
\item[Compression:]
#bzz -e[<blocksize>] <infile> <outfile>#
\item[Decompression:]
#bzz -d <infile> <outfile>#
\end{description}
Program bzz is a simple front-end for the Burrows Wheeler encoder
implemented in \Ref{BSByteStream.h}. Although this compression model is
not currently used in DjVu files, it may be used in the future for
encoding textual data chunks. Argument #blocksize# is expressed in
kilobytes and must be in range 200 to 4096. The default value is 2048.
Arguments #infile# and #outfile# are the input and output filenames. A
single dash (#"-"#) can be used to represent the standard input or output.
@memo
General purpose compression/decompression program
@author
L\'eon Bottou <leonb@research.att.com> -- initial implementation
@version
#$Id: bzz.cpp,v 1.3 2001-01-04 22:04:53 bcr Exp $# */
//@{
//@}
#include "GException.h"
#include "ByteStream.h"
#include "BSByteStream.h"
const char *program = "(unknown)";
void
usage(void)
{
fprintf(stderr,
"BZZ -- ZPCoded Burrows Wheeler compression\n"
"%s\n"
"Usage [encoding]: %s -e[<blocksize>(K|M|G)] <infile> <outfile>\n"
"Usage [decoding]: %s -d <infile> <outfile>\n"
" Argument <blocksize> must be in range [900K..1G] (default 2M).\n"
" Arguments <infile> and <outfile> can be '-' for stdin/stdout.\n",
"Copyright (c) 1999-2000 LizardTech, Inc. All Rights Reserved.", program, program);
exit(1);
}
int
main(int argc, char **argv)
{
TRY
{
// Get program name
program = strrchr(argv[0],'/');
if (program)
program += 1;
else
program = argv[0];
// Obtain default mode from program name
int blocksize = -1;
#if 0
if (!strcmp(program,"bzz"))
blocksize = 1100;
else if (!strcmp(program,"unbzz"))
blocksize = 0;
#endif
// Parse arguments
if (argc>=2 && argv[1][0]=='-')
{
if (argv[1][1]=='d' && argv[1][2]==0)
{
blocksize = 0;
}
else if (argv[1][1]=='e')
{
blocksize = 2048;
if (argv[1][2]) {
char *eptr;
long bs = strtol(argv[1]+2, &eptr, 10);
if (eptr[0]!=0 && eptr[1]!=0)
usage();
switch(eptr[0]) {
case 'k': case 'K': case 0:
break;
case 'm': case 'M':
bs *= 1024; break;
case 'g': case 'G':
bs *= 1024*1024; break;
default:
usage();
}
blocksize = bs;
if (blocksize != bs)
usage();
}
}
else
usage();
argv++;
argc--;
}
if (blocksize < 0)
usage();
// Obtain filenames
const char *infile = "-";
const char *outfile = "-";
if (argc >= 2)
infile = argv[1];
if (argc >= 3)
outfile = argv[2];
if (argc >= 4)
usage();
// Action
StdioByteStream in(infile,"rb");
StdioByteStream out(outfile,"wb");
if (blocksize)
{
BSByteStream bsb(out, blocksize);
bsb.copy(in);
}
else
{
BSByteStream bsb(in);
out.copy(bsb);
}
}
CATCH(ex)
{
ex.perror();
exit(1);
}
ENDCATCH;
return 0;
}