diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-14 07:51:19 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-14 07:51:19 +0000 |
commit | b6ccd32e3f061cc776c8cd5e526874e1bbb1a558 (patch) | |
tree | f23534c049567d2aa65926632445924bddd832e1 | |
parent | 6a9154b6f649341870bc06e896d2fe7235a4aef9 (diff) | |
download | busybox-w32-b6ccd32e3f061cc776c8cd5e526874e1bbb1a558.tar.gz busybox-w32-b6ccd32e3f061cc776c8cd5e526874e1bbb1a558.tar.bz2 busybox-w32-b6ccd32e3f061cc776c8cd5e526874e1bbb1a558.zip |
bzip2: implement -1..-9 command line flags
-rw-r--r-- | archival/bzip2.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/archival/bzip2.c b/archival/bzip2.c index bb1610eb4..e9a69c458 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c | |||
@@ -120,6 +120,7 @@ USE_DESKTOP(long long) int bz_write_tail(bz_stream *strm, void *wbuf) | |||
120 | return total; | 120 | return total; |
121 | } | 121 | } |
122 | 122 | ||
123 | static uint8_t level; | ||
123 | 124 | ||
124 | static | 125 | static |
125 | USE_DESKTOP(long long) int compressStream(void) | 126 | USE_DESKTOP(long long) int compressStream(void) |
@@ -134,7 +135,7 @@ USE_DESKTOP(long long) int compressStream(void) | |||
134 | 135 | ||
135 | iobuf = xmalloc(2 * IOBUF_SIZE); | 136 | iobuf = xmalloc(2 * IOBUF_SIZE); |
136 | 137 | ||
137 | BZ2_bzCompressInit(strm, 9 /*blockSize100k*/); | 138 | BZ2_bzCompressInit(strm, level); |
138 | 139 | ||
139 | while (1) { | 140 | while (1) { |
140 | count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE); | 141 | count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE); |
@@ -166,17 +167,39 @@ int bzip2_main(int argc, char **argv) | |||
166 | { | 167 | { |
167 | unsigned opt; | 168 | unsigned opt; |
168 | 169 | ||
170 | /* standard bzip2 flags | ||
171 | * -d --decompress force decompression | ||
172 | * -z --compress force compression | ||
173 | * -k --keep keep (don't delete) input files | ||
174 | * -f --force overwrite existing output files | ||
175 | * -t --test test compressed file integrity | ||
176 | * -c --stdout output to standard out | ||
177 | * -q --quiet suppress noncritical error messages | ||
178 | * -v --verbose be verbose (a 2nd -v gives more) | ||
179 | * -s --small use less memory (at most 2500k) | ||
180 | * -1 .. -9 set block size to 100k .. 900k | ||
181 | * --fast alias for -1 | ||
182 | * --best alias for -9 | ||
183 | */ | ||
184 | |||
169 | /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ | 185 | /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ |
170 | opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "q123456789" ); | 186 | opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" ); |
171 | #if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */ | 187 | #if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */ |
172 | if (opt & 0x8) // -d | 188 | if (opt & 0x8) // -d |
173 | return bunzip2_main(argc, argv); | 189 | return bunzip2_main(argc, argv); |
190 | opt >>= 4; | ||
191 | #else | ||
192 | opt >>= 3; | ||
174 | #endif | 193 | #endif |
175 | option_mask32 &= 0x7; /* ignore -q, -0..9 */ | 194 | opt = (uint8_t)opt; /* isolate bits for -1..-8 */ |
176 | //if (opt & 0x1) // -c | 195 | opt |= 0x100; /* if nothing else, assume -9 */ |
177 | //if (opt & 0x2) // -f | 196 | level = 1; |
178 | //if (opt & 0x4) // -v | 197 | while (!(opt & 1)) { |
179 | argv += optind; | 198 | level++; |
199 | opt >>= 1; | ||
200 | } | ||
180 | 201 | ||
202 | argv += optind; | ||
203 | option_mask32 &= 0x7; /* ignore all except -cfv */ | ||
181 | return bbunpack(argv, make_new_name_bzip2, compressStream); | 204 | return bbunpack(argv, make_new_name_bzip2, compressStream); |
182 | } | 205 | } |