Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/archival/gzip.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/archival/gzip.c
r1765 r2725 14 14 * command line handling. 15 15 * 16 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.16 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 17 17 */ 18 18 … … 41 41 42 42 #include "libbb.h" 43 #include "archive.h" 43 44 44 45 … … 68 69 #define SMALL_MEM 69 70 70 #ifndef 71 #ifndef INBUFSIZ 71 72 # ifdef SMALL_MEM 72 73 # define INBUFSIZ 0x2000 /* input buffer size */ … … 76 77 #endif 77 78 78 #ifndef 79 #ifndef OUTBUFSIZ 79 80 # ifdef SMALL_MEM 80 81 # define OUTBUFSIZ 8192 /* output buffer size */ … … 267 268 type * array 268 269 #define ALLOC(type, array, size) \ 269 array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)) ;270 array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)) 270 271 #define FREE(array) \ 271 272 do { free(array); array = NULL; } while (0) … … 340 341 #endif 341 342 342 uint32_t *crc_32_tab;343 /*uint32_t *crc_32_tab;*/ 343 344 uint32_t crc; /* shift register contents */ 344 345 }; … … 389 390 390 391 /* =========================================================================== 391 * Clear input and output buffers392 */393 static void clear_bufs(void)394 {395 G1.outcnt = 0;396 #ifdef DEBUG397 G1.insize = 0;398 #endif399 G1.isize = 0;400 }401 402 403 /* ===========================================================================404 392 * Run a set of bytes through the crc shift register. If s is a NULL 405 393 * pointer, then initialize the crc shift register contents instead. 406 394 * Return the current crc in either case. 407 395 */ 408 static uint32_t updcrc(uch * s, unsigned n) 409 { 410 uint32_t c = G1.crc; 411 while (n) { 412 c = G1.crc_32_tab[(uch)(c ^ *s++)] ^ (c >> 8); 413 n--; 414 } 415 G1.crc = c; 416 return c; 396 static void updcrc(uch * s, unsigned n) 397 { 398 G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/); 417 399 } 418 400 … … 633 615 * or if the match length is less than 2: 634 616 */ 635 if (match[best_len] != scan_end || 636 match[best_len - 1] != scan_end1 || 637 *match != *scan || *++match != scan[1]) 617 if (match[best_len] != scan_end 618 || match[best_len - 1] != scan_end1 619 || *match != *scan || *++match != scan[1] 620 ) { 638 621 continue; 622 } 639 623 640 624 /* The check at best_len-1 can be removed because it will be made … … 687 671 bb_error_msg("\\[%d,%d]", start - match, length); 688 672 do { 689 putc(G1.window[start++], stderr);673 bb_putchar_stderr(G1.window[start++]); 690 674 } while (--length != 0); 691 675 } … … 975 959 # define SEND_CODE(c, tree) \ 976 960 { \ 977 if (verbose > 1) bb_error_msg("\ncd %3d ", (c)); \961 if (verbose > 1) bb_error_msg("\ncd %3d ", (c)); \ 978 962 send_bits(tree[c].Code, tree[c].Len); \ 979 963 } … … 1186 1170 Tracec(tree != G2.static_ltree, 1187 1171 (stderr, "\nn %3d %c l %2d c %4x (%x) ", n, 1188 ( isgraph(n)? n : ' '), len, tree[n].Code,1172 (n > ' ' ? n : ' '), len, tree[n].Code, 1189 1173 next_code[len] - 1)); 1190 1174 } … … 1554 1538 if ((flag & 1) == 0) { 1555 1539 SEND_CODE(lc, ltree); /* send a literal byte */ 1556 Tracecv( isgraph(lc), (stderr, " '%c' ", lc));1540 Tracecv(lc > ' ', (stderr, " '%c' ", lc)); 1557 1541 } else { 1558 1542 /* Here, lc is the match length - MIN_MATCH */ … … 2009 1993 /* ======================================================================== */ 2010 1994 static 2011 char* make_new_name_gzip(char *filename) 2012 { 2013 return xasprintf("%s.gz", filename); 2014 } 2015 2016 static 2017 USE_DESKTOP(long long) int pack_gzip(void) 1995 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(unpack_info_t *info UNUSED_PARAM) 2018 1996 { 2019 1997 struct stat s; 2020 1998 2021 clear_bufs(); 2022 s.st_ctime = 0; 2023 fstat(STDIN_FILENO, &s); 2024 zip(s.st_ctime); 2025 return 0; 2026 } 2027 2028 int gzip_main(int argc, char **argv); 2029 int gzip_main(int argc, char **argv) 2030 { 2031 unsigned opt; 2032 2033 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2034 opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789" ); 2035 option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */ 2036 //if (opt & 0x1) // -c 2037 //if (opt & 0x2) // -f 2038 //if (opt & 0x4) // -v 2039 #if ENABLE_GUNZIP /* gunzip_main may not be visible... */ 2040 if (opt & 0x8) { // -d 2041 return gunzip_main(argc, argv); 2042 } 2043 #endif 2044 argv += optind; 2045 2046 PTR_TO_GLOBALS = xzalloc(sizeof(struct globals) + sizeof(struct globals2)) 2047 + sizeof(struct globals); 2048 G2.l_desc.dyn_tree = G2.dyn_ltree; 2049 G2.l_desc.static_tree = G2.static_ltree; 2050 G2.l_desc.extra_bits = extra_lbits; 2051 G2.l_desc.extra_base = LITERALS + 1; 2052 G2.l_desc.elems = L_CODES; 2053 G2.l_desc.max_length = MAX_BITS; 2054 //G2.l_desc.max_code = 0; 2055 2056 G2.d_desc.dyn_tree = G2.dyn_dtree; 2057 G2.d_desc.static_tree = G2.static_dtree; 2058 G2.d_desc.extra_bits = extra_dbits; 2059 //G2.d_desc.extra_base = 0; 2060 G2.d_desc.elems = D_CODES; 2061 G2.d_desc.max_length = MAX_BITS; 2062 //G2.d_desc.max_code = 0; 2063 1999 /* Clear input and output buffers */ 2000 G1.outcnt = 0; 2001 #ifdef DEBUG 2002 G1.insize = 0; 2003 #endif 2004 G1.isize = 0; 2005 2006 /* Reinit G2.xxx */ 2007 memset(&G2, 0, sizeof(G2)); 2008 G2.l_desc.dyn_tree = G2.dyn_ltree; 2009 G2.l_desc.static_tree = G2.static_ltree; 2010 G2.l_desc.extra_bits = extra_lbits; 2011 G2.l_desc.extra_base = LITERALS + 1; 2012 G2.l_desc.elems = L_CODES; 2013 G2.l_desc.max_length = MAX_BITS; 2014 //G2.l_desc.max_code = 0; 2015 G2.d_desc.dyn_tree = G2.dyn_dtree; 2016 G2.d_desc.static_tree = G2.static_dtree; 2017 G2.d_desc.extra_bits = extra_dbits; 2018 //G2.d_desc.extra_base = 0; 2019 G2.d_desc.elems = D_CODES; 2020 G2.d_desc.max_length = MAX_BITS; 2021 //G2.d_desc.max_code = 0; 2064 2022 G2.bl_desc.dyn_tree = G2.bl_tree; 2065 2023 //G2.bl_desc.static_tree = NULL; … … 2070 2028 //G2.bl_desc.max_code = 0; 2071 2029 2030 s.st_ctime = 0; 2031 fstat(STDIN_FILENO, &s); 2032 zip(s.st_ctime); 2033 return 0; 2034 } 2035 2036 #if ENABLE_FEATURE_GZIP_LONG_OPTIONS 2037 static const char gzip_longopts[] ALIGN1 = 2038 "stdout\0" No_argument "c" 2039 "to-stdout\0" No_argument "c" 2040 "force\0" No_argument "f" 2041 "verbose\0" No_argument "v" 2042 #if ENABLE_GUNZIP 2043 "decompress\0" No_argument "d" 2044 "uncompress\0" No_argument "d" 2045 "test\0" No_argument "t" 2046 #endif 2047 "quiet\0" No_argument "q" 2048 "fast\0" No_argument "1" 2049 "best\0" No_argument "9" 2050 ; 2051 #endif 2052 2053 /* 2054 * Linux kernel build uses gzip -d -n. We accept and ignore -n. 2055 * Man page says: 2056 * -n --no-name 2057 * gzip: do not save the original file name and time stamp. 2058 * (The original name is always saved if the name had to be truncated.) 2059 * gunzip: do not restore the original file name/time even if present 2060 * (remove only the gzip suffix from the compressed file name). 2061 * This option is the default when decompressing. 2062 * -N --name 2063 * gzip: always save the original file name and time stamp (this is the default) 2064 * gunzip: restore the original file name and time stamp if present. 2065 */ 2066 2067 int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 2068 #if ENABLE_GUNZIP 2069 int gzip_main(int argc, char **argv) 2070 #else 2071 int gzip_main(int argc UNUSED_PARAM, char **argv) 2072 #endif 2073 { 2074 unsigned opt; 2075 2076 #if ENABLE_FEATURE_GZIP_LONG_OPTIONS 2077 applet_long_options = gzip_longopts; 2078 #endif 2079 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2080 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n"); 2081 #if ENABLE_GUNZIP /* gunzip_main may not be visible... */ 2082 if (opt & 0x18) // -d and/or -t 2083 return gunzip_main(argc, argv); 2084 #endif 2085 option_mask32 &= 0x7; /* ignore -q, -0..9 */ 2086 //if (opt & 0x1) // -c 2087 //if (opt & 0x2) // -f 2088 //if (opt & 0x4) // -v 2089 argv += optind; 2090 2091 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2092 + sizeof(struct globals)); 2093 2072 2094 /* Allocate all global buffers (for DYN_ALLOC option) */ 2073 2095 ALLOC(uch, G1.l_buf, INBUFSIZ); … … 2077 2099 ALLOC(ush, G1.prev, 1L << BITS); 2078 2100 2079 /* Initiali se the CRC32 table */2080 G1.crc_32_tab= crc32_filltable(NULL, 0);2081 2082 return bbunpack(argv, make_new_name_gzip, pack_gzip);2083 } 2101 /* Initialize the CRC32 table */ 2102 global_crc32_table = crc32_filltable(NULL, 0); 2103 2104 return bbunpack(argv, pack_gzip, append_ext, "gz"); 2105 }
Note:
See TracChangeset
for help on using the changeset viewer.