Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival/gzip.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/archival/gzip.c
r3232 r3621 16 16 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 17 17 */ 18 19 18 /* big objects in bss: 20 19 * 00000020 b bl_count … … 32 31 * 000008f4 b dyn_ltree 33 32 */ 34 35 33 /* TODO: full support for -v for DESKTOP 36 34 * "/usr/bin/gzip -v a bogus aa" should say: … … 40 38 */ 41 39 40 //config:config GZIP 41 //config: bool "gzip" 42 //config: default y 43 //config: help 44 //config: gzip is used to compress files. 45 //config: It's probably the most widely used UNIX compression program. 46 //config: 47 //config:config FEATURE_GZIP_LONG_OPTIONS 48 //config: bool "Enable long options" 49 //config: default y 50 //config: depends on GZIP && LONG_OPTS 51 //config: help 52 //config: Enable use of long options, increases size by about 106 Bytes 53 //config: 54 //config:config GZIP_FAST 55 //config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)" 56 //config: default 0 57 //config: range 0 2 58 //config: depends on GZIP 59 //config: help 60 //config: Enable big memory options for gzip. 61 //config: 0: small buffers, small hash-tables 62 //config: 1: larger buffers, larger hash-tables 63 //config: 2: larger buffers, largest hash-tables 64 //config: Larger models may give slightly better compression 65 //config: 66 //config:config FEATURE_GZIP_LEVELS 67 //config: bool "Enable compression levels" 68 //config: default n 69 //config: depends on GZIP 70 //config: help 71 //config: Enable support for compression levels 4-9. The default level 72 //config: is 6. If levels 1-3 are specified, 4 is used. 73 //config: If this option is not selected, -N options are ignored and -9 74 //config: is used. 75 76 //applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) 77 //kbuild:lib-$(CONFIG_GZIP) += gzip.o 78 42 79 //usage:#define gzip_trivial_usage 43 //usage: "[-cf d] [FILE]..."80 //usage: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." 44 81 //usage:#define gzip_full_usage "\n\n" 45 82 //usage: "Compress FILEs (or stdin)\n" 83 //usage: IF_FEATURE_GZIP_LEVELS( 84 //usage: "\n -1..9 Compression level" 85 //usage: ) 86 //usage: IF_GUNZIP( 46 87 //usage: "\n -d Decompress" 88 //usage: ) 47 89 //usage: "\n -c Write to stdout" 48 90 //usage: "\n -f Force" … … 226 268 */ 227 269 270 #ifndef ENABLE_FEATURE_GZIP_LEVELS 271 228 272 max_chain_length = 4096, 229 273 /* To speed up deflation, hash chains are never searched beyond this length. … … 257 301 * meaning. 258 302 */ 303 #endif /* ENABLE_FEATURE_GZIP_LEVELS */ 259 304 }; 260 305 261 306 262 307 struct globals { 308 309 #ifdef ENABLE_FEATURE_GZIP_LEVELS 310 unsigned max_chain_length; 311 unsigned max_lazy_match; 312 unsigned good_match; 313 unsigned nice_match; 314 #define max_chain_length (G1.max_chain_length) 315 #define max_lazy_match (G1.max_lazy_match) 316 #define good_match (G1.good_match) 317 #define nice_match (G1.nice_match) 318 #endif 263 319 264 320 lng block_start; … … 391 447 do { \ 392 448 G1.outbuf[G1.outcnt++] = (c); \ 393 if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \ 449 if (G1.outcnt == OUTBUFSIZ) \ 450 flush_outbuf(); \ 394 451 } while (0) 395 452 … … 397 454 static void put_16bit(ush w) 398 455 { 399 if (G1.outcnt < OUTBUFSIZ - 2) { 400 G1.outbuf[G1.outcnt++] = w; 401 G1.outbuf[G1.outcnt++] = w >> 8; 402 } else { 403 put_8bit(w); 404 put_8bit(w >> 8); 405 } 456 /* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt 457 * (probably because of fear of aliasing with G1.outbuf[] 458 * stores), do it explicitly: 459 */ 460 unsigned outcnt = G1.outcnt; 461 uch *dst = &G1.outbuf[outcnt]; 462 463 #if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN 464 if (outcnt < OUTBUFSIZ-2) { 465 /* Common case */ 466 ush *dst16 = (void*) dst; 467 *dst16 = w; /* unalinged LSB 16-bit store */ 468 G1.outcnt = outcnt + 2; 469 return; 470 } 471 *dst = (uch)w; 472 w >>= 8; 473 #else 474 *dst = (uch)w; 475 w >>= 8; 476 if (outcnt < OUTBUFSIZ-2) { 477 /* Common case */ 478 dst[1] = w; 479 G1.outcnt = outcnt + 2; 480 return; 481 } 482 #endif 483 484 /* Slowpath: we will need to do flush_outbuf() */ 485 G1.outcnt = ++outcnt; 486 if (outcnt == OUTBUFSIZ) 487 flush_outbuf(); 488 put_8bit(w); 406 489 } 407 490 … … 1292 1375 G2.heap[SMALLEST] = node++; 1293 1376 pqdownheap(tree, SMALLEST); 1294 1295 1377 } while (G2.heap_len >= 2); 1296 1378 … … 1640 1722 copy_block(buf, (unsigned) stored_len, 0); /* without header */ 1641 1723 G2.compressed_len = stored_len << 3; 1642 1643 1724 } else if (stored_len + 4 <= opt_lenb && buf != NULL) { 1644 1725 /* 4: two words for the lengths */ … … 1654 1735 1655 1736 copy_block(buf, (unsigned) stored_len, 1); /* with header */ 1656 1657 1737 } else if (static_lenb == opt_lenb) { 1658 1738 send_bits((STATIC_TREES << 1) + eof, 3); … … 1981 2061 */ 1982 2062 1983 static void zip( ulg time_stamp)2063 static void zip(void) 1984 2064 { 1985 2065 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ … … 1992 2072 /* general flags: 0 */ 1993 2073 put_32bit(0x00088b1f); 1994 put_32bit( time_stamp);2074 put_32bit(0); /* Unix timestamp */ 1995 2075 1996 2076 /* Write deflated file to zip file */ … … 2016 2096 /* ======================================================================== */ 2017 2097 static 2018 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM) 2019 { 2020 struct stat s; 2021 2098 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM) 2099 { 2022 2100 /* Clear input and output buffers */ 2023 2101 G1.outcnt = 0; … … 2051 2129 //G2.bl_desc.max_code = 0; 2052 2130 2131 #if 0 2132 /* Saving of timestamp is disabled. Why? 2133 * - it is not Y2038-safe. 2134 * - some people want deterministic results 2135 * (normally they'd use -n, but our -n is a nop). 2136 * - it's bloat. 2137 * Per RFC 1952, gzfile.time=0 is "no timestamp". 2138 * If users will demand this to be reinstated, 2139 * implement -n "don't save timestamp". 2140 */ 2141 struct stat s; 2053 2142 s.st_ctime = 0; 2054 2143 fstat(STDIN_FILENO, &s); 2055 2144 zip(s.st_ctime); 2145 #else 2146 zip(); 2147 #endif 2056 2148 return 0; 2057 2149 } … … 2071 2163 "fast\0" No_argument "1" 2072 2164 "best\0" No_argument "9" 2165 "no-name\0" No_argument "n" 2073 2166 ; 2074 2167 #endif … … 2096 2189 { 2097 2190 unsigned opt; 2191 #ifdef ENABLE_FEATURE_GZIP_LEVELS 2192 static const struct { 2193 uint8_t good; 2194 uint8_t chain_shift; 2195 uint8_t lazy2; 2196 uint8_t nice2; 2197 } gzip_level_config[6] = { 2198 {4, 4, 4/2, 16/2}, /* Level 4 */ 2199 {8, 5, 16/2, 32/2}, /* Level 5 */ 2200 {8, 7, 16/2, 128/2}, /* Level 6 */ 2201 {8, 8, 32/2, 128/2}, /* Level 7 */ 2202 {32, 10, 128/2, 258/2}, /* Level 8 */ 2203 {32, 12, 258/2, 258/2}, /* Level 9 */ 2204 }; 2205 #endif 2206 2207 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2208 + sizeof(struct globals)); 2098 2209 2099 2210 #if ENABLE_FEATURE_GZIP_LONG_OPTIONS … … 2101 2212 #endif 2102 2213 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2103 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q 123456789n");2214 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789"); 2104 2215 #if ENABLE_GUNZIP /* gunzip_main may not be visible... */ 2105 2216 if (opt & 0x18) // -d and/or -t 2106 2217 return gunzip_main(argc, argv); 2107 2218 #endif 2108 option_mask32 &= 0x7; /* ignore -q, -0..9 */ 2109 //if (opt & 0x1) // -c 2110 //if (opt & 0x2) // -f 2111 //if (opt & 0x4) // -v 2112 argv += optind; 2113 2114 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2115 + sizeof(struct globals)); 2219 #ifdef ENABLE_FEATURE_GZIP_LEVELS 2220 opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */ 2221 if (opt == 0) 2222 opt = 1 << 6; /* default: 6 */ 2223 opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ 2224 max_chain_length = 1 << gzip_level_config[opt].chain_shift; 2225 good_match = gzip_level_config[opt].good; 2226 max_lazy_match = gzip_level_config[opt].lazy2 * 2; 2227 nice_match = gzip_level_config[opt].nice2 * 2; 2228 #endif 2229 option_mask32 &= 0x7; /* retain only -cfv */ 2116 2230 2117 2231 /* Allocate all global buffers (for DYN_ALLOC option) */ … … 2125 2239 global_crc32_table = crc32_filltable(NULL, 0); 2126 2240 2241 argv += optind; 2127 2242 return bbunpack(argv, pack_gzip, append_ext, "gz"); 2128 2243 }
Note:
See TracChangeset
for help on using the changeset viewer.