New upstream version 3.3.83
Dr. Tobias Quathamer
6 years ago
1599 | 1599 | 3.3.82 02jul17 Get sys_fst working with VCS VPI. |
1600 | 1600 | Added string concatenations for vectors. |
1601 | 1601 | Added asserts to ghwlib.c to make scan-view clean. |
1602 | 3.3.83 04aug17 Preserve search type for regex search across reloads or | |
1603 | close/reopens of regex search widget. | |
1604 | Update local libz to current version. |
0 | 0 | ########################################################################## |
1 | 1 | |
2 | GTKWave 3.3.81 Wave Viewer is Copyright (C) 1999-2017 Tony Bybell. | |
2 | GTKWave 3.3.83 Wave Viewer is Copyright (C) 1999-2017 Tony Bybell. | |
3 | 3 | Portions of GTKWave are Copyright (C) 1999-2017 Udi Finkelstein. |
4 | 4 | Context support is Copyright (C) 2007-2017 Kermin Elliott Fleming. |
5 | 5 | Trace group support is Copyright (C) 2009-2017 Donald Baltus. |
0 | 0 | #! /bin/sh |
1 | 1 | # Guess values for system-dependent variables and create Makefiles. |
2 | # Generated by GNU Autoconf 2.69 for gtkwave 3.3.82. | |
2 | # Generated by GNU Autoconf 2.69 for gtkwave 3.3.83. | |
3 | 3 | # |
4 | 4 | # Report bugs to <bybell@rocketmail.com>. |
5 | 5 | # |
579 | 579 | # Identity of this package. |
580 | 580 | PACKAGE_NAME='gtkwave' |
581 | 581 | PACKAGE_TARNAME='gtkwave' |
582 | PACKAGE_VERSION='3.3.82' | |
583 | PACKAGE_STRING='gtkwave 3.3.82' | |
582 | PACKAGE_VERSION='3.3.83' | |
583 | PACKAGE_STRING='gtkwave 3.3.83' | |
584 | 584 | PACKAGE_BUGREPORT='bybell@rocketmail.com' |
585 | 585 | PACKAGE_URL='' |
586 | 586 | |
1382 | 1382 | # Omit some internal or obsolete options to make the list less imposing. |
1383 | 1383 | # This message is too long to be a string in the A/UX 3.1 sh. |
1384 | 1384 | cat <<_ACEOF |
1385 | \`configure' configures gtkwave 3.3.82 to adapt to many kinds of systems. | |
1385 | \`configure' configures gtkwave 3.3.83 to adapt to many kinds of systems. | |
1386 | 1386 | |
1387 | 1387 | Usage: $0 [OPTION]... [VAR=VALUE]... |
1388 | 1388 | |
1448 | 1448 | |
1449 | 1449 | if test -n "$ac_init_help"; then |
1450 | 1450 | case $ac_init_help in |
1451 | short | recursive ) echo "Configuration of gtkwave 3.3.82:";; | |
1451 | short | recursive ) echo "Configuration of gtkwave 3.3.83:";; | |
1452 | 1452 | esac |
1453 | 1453 | cat <<\_ACEOF |
1454 | 1454 | |
1594 | 1594 | test -n "$ac_init_help" && exit $ac_status |
1595 | 1595 | if $ac_init_version; then |
1596 | 1596 | cat <<\_ACEOF |
1597 | gtkwave configure 3.3.82 | |
1597 | gtkwave configure 3.3.83 | |
1598 | 1598 | generated by GNU Autoconf 2.69 |
1599 | 1599 | |
1600 | 1600 | Copyright (C) 2012 Free Software Foundation, Inc. |
2238 | 2238 | This file contains any messages produced by compilers while |
2239 | 2239 | running configure, to aid debugging if configure makes a mistake. |
2240 | 2240 | |
2241 | It was created by gtkwave $as_me 3.3.82, which was | |
2241 | It was created by gtkwave $as_me 3.3.83, which was | |
2242 | 2242 | generated by GNU Autoconf 2.69. Invocation command line was |
2243 | 2243 | |
2244 | 2244 | $ $0 $@ |
3105 | 3105 | |
3106 | 3106 | # Define the identity of the package. |
3107 | 3107 | PACKAGE='gtkwave' |
3108 | VERSION='3.3.82' | |
3108 | VERSION='3.3.83' | |
3109 | 3109 | |
3110 | 3110 | |
3111 | 3111 | cat >>confdefs.h <<_ACEOF |
10996 | 10996 | # report actual input values of CONFIG_FILES etc. instead of their |
10997 | 10997 | # values after options handling. |
10998 | 10998 | ac_log=" |
10999 | This file was extended by gtkwave $as_me 3.3.82, which was | |
10999 | This file was extended by gtkwave $as_me 3.3.83, which was | |
11000 | 11000 | generated by GNU Autoconf 2.69. Invocation command line was |
11001 | 11001 | |
11002 | 11002 | CONFIG_FILES = $CONFIG_FILES |
11062 | 11062 | cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 |
11063 | 11063 | ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" |
11064 | 11064 | ac_cs_version="\\ |
11065 | gtkwave config.status 3.3.82 | |
11065 | gtkwave config.status 3.3.83 | |
11066 | 11066 | configured by $0, generated by GNU Autoconf 2.69, |
11067 | 11067 | with options \\"\$ac_cs_config\\" |
11068 | 11068 |
1 | 1 | # Process this file with autoconf to produce a configure script. |
2 | 2 | |
3 | 3 | AC_PREREQ(2.59) |
4 | AC_INIT(gtkwave, 3.3.82, bybell@rocketmail.com) | |
4 | AC_INIT(gtkwave, 3.3.83, bybell@rocketmail.com) | |
5 | 5 | AC_CONFIG_SRCDIR([src/vcd.c]) |
6 | 6 | AM_INIT_AUTOMAKE |
7 | 7 | AC_CONFIG_HEADER([config.h]) |
7 | 7 | <key>CFBundleExecutable</key> |
8 | 8 | <string>gtkwave</string> |
9 | 9 | <key>CFBundleGetInfoString</key> |
10 | <string>3.3.82, (C) 1999-2017 Tony Bybell http://gtkwave.sourceforge.net</string> | |
10 | <string>3.3.83, (C) 1999-2017 Tony Bybell http://gtkwave.sourceforge.net</string> | |
11 | 11 | <key>CFBundleIconFile</key> |
12 | 12 | <string>gtkwave.icns</string> |
13 | 13 | <key>CFBundleIdentifier</key> |
17 | 17 | <key>CFBundlePackageType</key> |
18 | 18 | <string>APPL</string> |
19 | 19 | <key>CFBundleShortVersionString</key> |
20 | <string>3.3.82</string> | |
20 | <string>3.3.83</string> | |
21 | 21 | <key>CFBundleSignature</key> |
22 | 22 | <string>????</string> |
23 | 23 | <key>CFBundleVersion</key> |
24 | <string>3.3.82</string> | |
24 | <string>3.3.83</string> | |
25 | 25 | <key>NSHumanReadableCopyright</key> |
26 | 26 | <string>Copyright 1999 - 2017 Tony Bybell, GNU General Public License.</string> |
27 | 27 | <key>LSMinimumSystemVersion</key> |
1849 | 1849 | eptr rc=NULL; |
1850 | 1850 | exptr exp1; |
1851 | 1851 | |
1852 | int row_hi = 0, row_lo = 0, new_msi = 0, new_lsi = 0; | |
1853 | int row_delta = 0, bit_delta = 0; | |
1854 | int curr_row = 0, curr_bit = 0; | |
1855 | int is_2d = 0; | |
1856 | ||
1852 | 1857 | if(n->mv.mvlfac) import_trace(n); |
1853 | 1858 | |
1854 | 1859 | if(!n->extvals) |
1896 | 1901 | if(namex[i]=='[') break; |
1897 | 1902 | } |
1898 | 1903 | if(i>-1) offset=i; |
1904 | ||
1905 | if(i>3) | |
1906 | { | |
1907 | if(namex[i-1]==']') | |
1908 | { | |
1909 | int j = i-2; | |
1910 | int colon_seen = 0; | |
1911 | for(;j>=0;j--) | |
1912 | { | |
1913 | if(namex[j]=='[') break; | |
1914 | if(namex[j]==':') colon_seen = 1; | |
1915 | } | |
1916 | ||
1917 | if((j>-1)&&(colon_seen)) | |
1918 | { | |
1919 | int items = sscanf(namex+j, "[%d:%d][%d:%d]", &row_hi, &row_lo, &new_msi, &new_lsi); | |
1920 | if(items == 4) | |
1921 | { | |
1922 | /* printf(">> %d %d %d %d (items = %d)\n", row_hi, row_lo, new_msi, new_lsi, items); */ | |
1923 | ||
1924 | row_delta = (row_hi > row_lo) ? -1 : 1; | |
1925 | bit_delta = (new_msi > new_lsi) ? -1 : 1; | |
1926 | ||
1927 | curr_row = row_hi; | |
1928 | curr_bit = new_msi; | |
1929 | ||
1930 | is_2d = (((row_lo - row_hi) * row_delta) + 1) * (((new_lsi - new_msi) * bit_delta) + 1) == width; | |
1931 | if(is_2d) offset = j; | |
1932 | } | |
1933 | } | |
1934 | } | |
1935 | } | |
1899 | 1936 | |
1900 | 1937 | nam=(char *)wave_alloca(offset+20+30); |
1901 | 1938 | memcpy(nam, namex, offset); |
1949 | 1986 | for(i=0;i<width;i++) |
1950 | 1987 | { |
1951 | 1988 | narray[i] = (nptr)calloc_2(1, sizeof(struct Node)); |
1952 | sprintf(nam+offset, "[%d]", actual); | |
1989 | if(!is_2d) | |
1990 | { | |
1991 | sprintf(nam+offset, "[%d]", actual); | |
1992 | } | |
1993 | else | |
1994 | { | |
1995 | sprintf(nam+offset, "[%d][%d]", curr_row, curr_bit); | |
1996 | if(curr_bit == new_lsi) | |
1997 | { | |
1998 | curr_bit = new_msi; | |
1999 | curr_row += row_delta; | |
2000 | } | |
2001 | else | |
2002 | { | |
2003 | curr_bit += bit_delta; | |
2004 | } | |
2005 | } | |
1953 | 2006 | #ifdef WAVE_ARRAY_SUPPORT |
1954 | 2007 | if(n->array_height) |
1955 | 2008 | { |
2052 | 2105 | int actual; |
2053 | 2106 | nptr np; |
2054 | 2107 | char *nam; |
2055 | int offset, len; | |
2108 | int offset, len, width; | |
2056 | 2109 | exptr exp1; |
2110 | ||
2111 | int row_hi = 0, row_lo = 0, new_msi = 0, new_lsi = 0; | |
2112 | int row_delta = 0, bit_delta = 0; | |
2113 | int curr_row = 0, curr_bit = 0; | |
2114 | int is_2d = 0; | |
2057 | 2115 | |
2058 | 2116 | if(n->mv.mvlfac) import_trace(n); |
2059 | 2117 | |
2069 | 2127 | |
2070 | 2128 | if(n->lsi > n->msi) |
2071 | 2129 | { |
2130 | width = n->lsi - n->msi + 1; | |
2072 | 2131 | rgh = n->lsi; lft = n->msi; |
2073 | 2132 | actual = n->msi + bit; |
2074 | 2133 | } |
2075 | 2134 | else |
2076 | 2135 | { |
2136 | width = n->msi - n->lsi + 1; | |
2077 | 2137 | rgh = n->msi; lft = n->lsi; |
2078 | 2138 | actual = n->msi - bit; |
2079 | 2139 | } |
2092 | 2152 | { |
2093 | 2153 | namex = n->nname; |
2094 | 2154 | } |
2155 | ||
2095 | 2156 | offset = strlen(namex); |
2096 | 2157 | for(i=offset-1;i>=0;i--) |
2097 | 2158 | { |
2098 | 2159 | if(namex[i]=='[') break; |
2099 | 2160 | } |
2100 | 2161 | if(i>-1) offset=i; |
2162 | ||
2163 | if(i>3) | |
2164 | { | |
2165 | if(namex[i-1]==']') | |
2166 | { | |
2167 | int j = i-2; | |
2168 | int colon_seen = 0; | |
2169 | for(;j>=0;j--) | |
2170 | { | |
2171 | if(namex[j]=='[') break; | |
2172 | if(namex[j]==':') colon_seen = 1; | |
2173 | } | |
2174 | ||
2175 | if((j>-1)&&(colon_seen)) | |
2176 | { | |
2177 | int items = sscanf(namex+j, "[%d:%d][%d:%d]", &row_hi, &row_lo, &new_msi, &new_lsi); | |
2178 | if(items == 4) | |
2179 | { | |
2180 | /* printf("bit >> %d %d %d %d (items = %d)\n", row_hi, row_lo, new_msi, new_lsi, items); */ | |
2181 | ||
2182 | row_delta = (row_hi > row_lo) ? -1 : 1; | |
2183 | bit_delta = (new_msi > new_lsi) ? -1 : 1; | |
2184 | ||
2185 | curr_row = row_hi; | |
2186 | curr_bit = new_msi; | |
2187 | ||
2188 | is_2d = (((row_lo - row_hi) * row_delta) + 1) * (((new_lsi - new_msi) * bit_delta) + 1) == width; | |
2189 | if(is_2d) offset = j; | |
2190 | } | |
2191 | } | |
2192 | } | |
2193 | } | |
2101 | 2194 | |
2102 | 2195 | nam=(char *)wave_alloca(offset+20); |
2103 | 2196 | memcpy(nam, namex, offset); |
2149 | 2242 | DEBUG(fprintf(stderr, "Extracting: (%d to %d) for offset #%d over %d entries.\n", n->msi, n->lsi, bit, n->numhist)); |
2150 | 2243 | |
2151 | 2244 | np = (nptr)calloc_2(1, sizeof(struct Node)); |
2152 | sprintf(nam+offset, "[%d]", actual); | |
2245 | ||
2246 | ||
2247 | if(!is_2d) | |
2248 | { | |
2249 | sprintf(nam+offset, "[%d]", actual); | |
2250 | } | |
2251 | else | |
2252 | { | |
2253 | for(i=0;i<bit;i++) | |
2254 | { | |
2255 | if(curr_bit == new_lsi) | |
2256 | { | |
2257 | curr_bit = new_msi; | |
2258 | curr_row += row_delta; | |
2259 | } | |
2260 | else | |
2261 | { | |
2262 | curr_bit += bit_delta; | |
2263 | } | |
2264 | } | |
2265 | sprintf(nam+offset, "[%d][%d]", curr_row, curr_bit); | |
2266 | } | |
2267 | ||
2153 | 2268 | #ifdef WAVE_ARRAY_SUPPORT |
2154 | 2269 | if(n->array_height) |
2155 | 2270 | { |
205 | 205 | #endif |
206 | 206 | |
207 | 207 | #ifdef WAVE_FSDB_READER_IS_PRESENT |
208 | static char *get_varname(char *sbuff, unsigned char *vtp, unsigned char *vdp, int i) | |
208 | static char *get_varname(char *sbuff, unsigned char *vtp, unsigned char *vdp, int i, int *patched_len) | |
209 | 209 | { |
210 | 210 | #else |
211 | static char *get_varname(unsigned char *vtp, unsigned char *vdp, int i) | |
211 | static char *get_varname(unsigned char *vtp, unsigned char *vdp, int i, int *patched_len) | |
212 | 212 | { |
213 | 213 | static char sbuff[65537]; |
214 | 214 | #endif |
215 | 215 | char * rc; |
216 | 216 | int vt, vt_len; |
217 | ||
218 | *patched_len = 0; /* zero says is ok, otherwise size overrides msi/lsi */ | |
217 | 219 | |
218 | 220 | #ifndef WAVE_FSDB_READER_IS_PRESENT |
219 | 221 | for(;;) |
307 | 309 | { |
308 | 310 | lb = colon = rb = NULL; |
309 | 311 | } |
312 | if(pnt[1] == '[') esc = pnt; /* pretend we're escaped to handle 2d */ | |
310 | 313 | } |
311 | 314 | else if(pnt[0] == ':') |
312 | 315 | { |
386 | 389 | ? (GLOBALS->extload_node_block[i].msi - GLOBALS->extload_node_block[i].lsi + 1) |
387 | 390 | : (GLOBALS->extload_node_block[i].lsi - GLOBALS->extload_node_block[i].msi + 1); |
388 | 391 | |
389 | if(len_parse != GLOBALS->mvlfacs_vzt_c_3[i].len) | |
392 | if((GLOBALS->mvlfacs_vzt_c_3[i].len > len_parse) && !(GLOBALS->mvlfacs_vzt_c_3[i].len % len_parse)) /* check if 2d array */ | |
390 | 393 | { |
391 | GLOBALS->extload_node_block[i].msi=l; | |
392 | GLOBALS->extload_node_block[i].lsi=r; | |
394 | /* printf("len_parse: %d vs len: %d\n", len_parse, GLOBALS->mvlfacs_vzt_c_3[i].len); */ | |
395 | *patched_len = GLOBALS->mvlfacs_vzt_c_3[i].len; | |
396 | } | |
397 | else /* original, non-2d behavior */ | |
398 | { | |
399 | if(len_parse != GLOBALS->mvlfacs_vzt_c_3[i].len) | |
400 | { | |
401 | GLOBALS->extload_node_block[i].msi=l; | |
402 | GLOBALS->extload_node_block[i].lsi=r; | |
403 | } | |
393 | 404 | } |
394 | 405 | } |
395 | 406 | else |
634 | 645 | char *fnam; |
635 | 646 | int flen; |
636 | 647 | int longest_nam_candidate = 0; |
648 | int patched_len = 0; | |
637 | 649 | |
638 | 650 | i = GLOBALS->extload_i; |
639 | 651 | |
640 | 652 | if(i<0) |
641 | 653 | { |
642 | 654 | #ifdef WAVE_FSDB_READER_IS_PRESENT |
643 | fnam = get_varname(s_gv, &GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, 0); | |
655 | fnam = get_varname(s_gv, &GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, 0, &patched_len); | |
644 | 656 | flen = strlen(fnam); |
645 | 657 | |
646 | 658 | if(GLOBALS->extload_hlen) |
650 | 662 | *(GLOBALS->extload_namecache[0 & F_NAME_MODULUS]+GLOBALS->extload_hlen) = '.'; |
651 | 663 | strcpy(GLOBALS->extload_namecache[0 & F_NAME_MODULUS]+GLOBALS->extload_hlen+1, fnam); |
652 | 664 | GLOBALS->extload_namecache_lens[0 & F_NAME_MODULUS]=GLOBALS->extload_hlen + 1 + flen; |
665 | GLOBALS->extload_namecache_patched[0 & F_NAME_MODULUS]=patched_len; | |
653 | 666 | } |
654 | 667 | else |
655 | 668 | { |
656 | 669 | GLOBALS->extload_namecache[0 & F_NAME_MODULUS]=malloc_2(GLOBALS->extload_namecache_max[0 & F_NAME_MODULUS]=flen+1); |
657 | 670 | strcpy(GLOBALS->extload_namecache[0 & F_NAME_MODULUS], fnam); |
658 | 671 | GLOBALS->extload_namecache_lens[0 & F_NAME_MODULUS] = flen; |
672 | GLOBALS->extload_namecache_patched[0 & F_NAME_MODULUS]=patched_len; | |
659 | 673 | } |
660 | 674 | #else |
661 | fnam = get_varname(&GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, 0); | |
675 | fnam = get_varname(&GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, 0, &patched_len); | |
662 | 676 | flen = strlen(fnam); |
663 | 677 | |
664 | 678 | GLOBALS->extload_namecache[0 & F_NAME_MODULUS]=malloc_2(GLOBALS->extload_namecache_max[0 & F_NAME_MODULUS]=flen+1); |
665 | 679 | strcpy(GLOBALS->extload_namecache[0 & F_NAME_MODULUS], fnam); |
666 | 680 | GLOBALS->extload_namecache_lens[0 & F_NAME_MODULUS] = flen; |
681 | GLOBALS->extload_namecache_patched[0 & F_NAME_MODULUS]=patched_len; | |
667 | 682 | #endif |
668 | 683 | } |
669 | 684 | else |
673 | 688 | if(i!=(GLOBALS->numfacs-1)) |
674 | 689 | { |
675 | 690 | #ifdef WAVE_FSDB_READER_IS_PRESENT |
676 | fnam = get_varname(s_gv, &GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, i+1); | |
691 | fnam = get_varname(s_gv, &GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, i+1, &patched_len); | |
677 | 692 | flen = strlen(fnam); |
678 | 693 | |
679 | 694 | if(GLOBALS->extload_hlen) |
688 | 703 | *(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS]+GLOBALS->extload_hlen) = '.'; |
689 | 704 | strcpy(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS]+GLOBALS->extload_hlen+1, fnam); |
690 | 705 | GLOBALS->extload_namecache_lens[(i+1)&F_NAME_MODULUS] = GLOBALS->extload_hlen + 1 + flen; |
706 | GLOBALS->extload_namecache_patched[(i+1)&F_NAME_MODULUS] = patched_len; | |
691 | 707 | } |
692 | 708 | else |
693 | 709 | { |
698 | 714 | } |
699 | 715 | strcpy(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS], fnam); |
700 | 716 | GLOBALS->extload_namecache_lens[(i+1)&F_NAME_MODULUS] = flen; |
717 | GLOBALS->extload_namecache_patched[(i+1)&F_NAME_MODULUS] = patched_len; | |
701 | 718 | } |
702 | 719 | #else |
703 | fnam = get_varname(&GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, i+1); | |
720 | fnam = get_varname(&GLOBALS->extload_vt_prev, &GLOBALS->extload_vd_prev, i+1, &patched_len); | |
704 | 721 | flen = strlen(fnam); |
705 | 722 | |
706 | 723 | if(GLOBALS->extload_namecache_max[(i+1)&F_NAME_MODULUS] < (flen+1)) |
709 | 726 | } |
710 | 727 | strcpy(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS], fnam); |
711 | 728 | GLOBALS->extload_namecache_lens[(i+1)&F_NAME_MODULUS] = flen; |
729 | GLOBALS->extload_namecache_patched[(i+1)&F_NAME_MODULUS] = patched_len; | |
712 | 730 | #endif |
713 | 731 | } |
714 | 732 | |
717 | 735 | if((f->len>1)&& (!(f->flags&(VZT_RD_SYM_F_INTEGER|VZT_RD_SYM_F_DOUBLE|VZT_RD_SYM_F_STRING))) ) |
718 | 736 | { |
719 | 737 | int len=sprintf_2_sdd(buf, GLOBALS->extload_namecache[i&F_NAME_MODULUS],GLOBALS->extload_node_block[i].msi, GLOBALS->extload_node_block[i].lsi); |
738 | if(GLOBALS->extload_namecache_patched[i&F_NAME_MODULUS]) /* 2d */ | |
739 | { | |
740 | GLOBALS->extload_node_block[i].msi=GLOBALS->extload_namecache_patched[i&F_NAME_MODULUS] - 1; | |
741 | GLOBALS->extload_node_block[i].lsi=0; | |
742 | } | |
720 | 743 | longest_nam_candidate = len; |
721 | 744 | |
722 | 745 | if(!GLOBALS->do_hier_compress) |
891 | 914 | static void extload_hiertree_callback(void *pnt) |
892 | 915 | { |
893 | 916 | static int tree_end = 0; |
917 | int patched_len = 0; | |
894 | 918 | |
895 | 919 | char *s = (char *)pnt; |
896 | 920 | |
899 | 923 | switch(s[0]) |
900 | 924 | { |
901 | 925 | case 'S': |
902 | case 'U': get_varname(s, NULL, NULL, -1); | |
926 | case 'U': get_varname(s, NULL, NULL, -1, &patched_len); | |
903 | 927 | GLOBALS->extload_hlen = GLOBALS->fst_scope_name ? strlen(GLOBALS->fst_scope_name) : 0; |
904 | 928 | break; |
905 | 929 | |
1036 | 1060 | } |
1037 | 1061 | |
1038 | 1062 | #else |
1063 | int patched_len = 0; | |
1039 | 1064 | |
1040 | 1065 | last_modification_check(); |
1041 | 1066 | sprintf(sbuff, "%s -info %s 2>&1", EXTLOAD_PATH, fname); |
1175 | 1200 | GLOBALS->extload_namecache=(char **)calloc_2(F_NAME_MODULUS+1, sizeof(char *)); |
1176 | 1201 | GLOBALS->extload_namecache_max=(int *)calloc_2(F_NAME_MODULUS+1, sizeof(int)); |
1177 | 1202 | GLOBALS->extload_namecache_lens=(int *)calloc_2(F_NAME_MODULUS+1, sizeof(int)); |
1203 | GLOBALS->extload_namecache_patched=(int *)calloc_2(F_NAME_MODULUS+1, sizeof(int)); | |
1178 | 1204 | GLOBALS->extload_sym_block = (struct symbol *)calloc_2(GLOBALS->numfacs, sizeof(struct symbol)); |
1179 | 1205 | GLOBALS->extload_node_block=(struct Node *)calloc_2(GLOBALS->numfacs,sizeof(struct Node)); |
1180 | 1206 | GLOBALS->extload_idcodes=(unsigned int *)calloc_2(GLOBALS->numfacs, sizeof(unsigned int)); |
1220 | 1246 | free_2(GLOBALS->extload_namecache); GLOBALS->extload_namecache = NULL; |
1221 | 1247 | free_2(GLOBALS->extload_namecache_max); GLOBALS->extload_namecache_max = NULL; |
1222 | 1248 | free_2(GLOBALS->extload_namecache_lens); GLOBALS->extload_namecache_lens = NULL; |
1249 | free_2(GLOBALS->extload_namecache_patched); GLOBALS->extload_namecache_patched = NULL; | |
1223 | 1250 | |
1224 | 1251 | fstReaderClose(GLOBALS->extload_xc); /* corresponds to fstReaderOpenForUtilitiesOnly() */ |
1225 | 1252 | |
1242 | 1269 | { |
1243 | 1270 | process_extload_variable(); |
1244 | 1271 | } |
1245 | while(get_varname(&GLOBALS->extload_vt_prev, NULL, -1)); /* read through end to process all upscopes */ | |
1272 | while(get_varname(&GLOBALS->extload_vt_prev, NULL, -1, &patched_len)); /* read through end to process all upscopes */ | |
1246 | 1273 | |
1247 | 1274 | decorated_module_cleanup(); /* ...also now in gtk2_treesearch.c */ |
1248 | 1275 | iter_through_comp_name_table(); |
0 | 0 | /* |
1 | * Copyright (c) Tony Bybell 2009-2016. | |
1 | * Copyright (c) Tony Bybell 2009-2017. | |
2 | 2 | * |
3 | 3 | * This program is free software; you can redistribute it and/or |
4 | 4 | * modify it under the terms of the GNU General Public License |
629 | 629 | unsigned char nvt, nvd, ndt; |
630 | 630 | int longest_nam_candidate = 0; |
631 | 631 | char *fnam; |
632 | int len_subst = 0; | |
632 | 633 | |
633 | 634 | h = extractNextVar(GLOBALS->fst_fst_c_1, &msb, &lsb, &nnam, &name_len, &nnam_max); |
634 | 635 | if(!h) |
685 | 686 | } |
686 | 687 | else |
687 | 688 | { |
689 | int abslen = (msb >= lsb) ? (msb - lsb + 1) : (lsb - msb + 1); | |
690 | ||
691 | if((h->u.var.length > abslen) && !(h->u.var.length % abslen)) /* check if 2d array */ | |
692 | { | |
693 | /* printf("h->u.var.length: %d, abslen: %d '%s'\n", h->u.var.length, abslen, fnam); */ | |
694 | len_subst = 1; | |
695 | } | |
696 | ||
688 | 697 | node_block[i].msi = msb; |
689 | 698 | node_block[i].lsi = lsb; |
690 | 699 | } |
812 | 821 | if((f->len>1)&& (!(f->flags&(VZT_RD_SYM_F_INTEGER|VZT_RD_SYM_F_DOUBLE|VZT_RD_SYM_F_STRING))) ) |
813 | 822 | { |
814 | 823 | int len=sprintf_2_sdd(buf, f_name[(i)&F_NAME_MODULUS],node_block[i].msi, node_block[i].lsi); |
824 | ||
825 | if(len_subst) /* preserve 2d in name, but make 1d internally */ | |
826 | { | |
827 | node_block[i].msi = h->u.var.length-1; | |
828 | node_block[i].lsi = 0; | |
829 | } | |
830 | ||
815 | 831 | longest_nam_candidate = len; |
816 | 832 | |
817 | 833 | if(!GLOBALS->do_hier_compress) |
0 | 0 | /* |
1 | * Copyright (c) Kermin Elliott Fleming 2007-2016. | |
1 | * Copyright (c) Kermin Elliott Fleming 2007-2017. | |
2 | 2 | * |
3 | 3 | * This program is free software; you can redistribute it and/or |
4 | 4 | * modify it under the terms of the GNU General Public License |
247 | 247 | NULL, /* extload_namecache */ |
248 | 248 | NULL, /* extload_namecache_max */ |
249 | 249 | NULL, /* extload_namecache_lens */ |
250 | NULL, /* extload_namecache_patched */ | |
250 | 251 | NULL, /* extload_sym_block */ |
251 | 252 | NULL, /* extload_node_block */ |
252 | 253 | NULL, /* extload_xc */ |
1930 | 1931 | strcpy2_into_new_context(new_globals, &new_globals->pFileChooseFilterName, &GLOBALS->pFileChooseFilterName); |
1931 | 1932 | #endif |
1932 | 1933 | |
1934 | /* search.c */ | |
1935 | new_globals->regex_which_search_c_1 = GLOBALS->regex_which_search_c_1; /* preserve search type */ | |
1936 | ||
1933 | 1937 | /* ttranslate.c */ |
1934 | 1938 | strcpy2_into_new_context(new_globals, &new_globals->ttranslate_args, &GLOBALS->ttranslate_args); |
1935 | 1939 |
248 | 248 | char **extload_namecache; |
249 | 249 | int *extload_namecache_max; |
250 | 250 | int *extload_namecache_lens; |
251 | int *extload_namecache_patched; | |
251 | 252 | struct symbol *extload_sym_block; |
252 | 253 | struct Node *extload_node_block; |
253 | 254 | void *extload_xc; |
0 | 0 | ZLIB DATA COMPRESSION LIBRARY |
1 | 1 | |
2 | zlib 1.2.8 is a general purpose data compression library. All the code is | |
2 | zlib 1.2.11 is a general purpose data compression library. All the code is | |
3 | 3 | thread safe. The data format used by the zlib library is described by RFCs |
4 | 4 | (Request for Comments) 1950 to 1952 in the files |
5 | 5 | http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and |
30 | 30 | issue of Dr. Dobb's Journal; a copy of the article is available at |
31 | 31 | http://marknelson.us/1997/01/01/zlib-engine/ . |
32 | 32 | |
33 | The changes made in version 1.2.8 are documented in the file ChangeLog. | |
33 | The changes made in version 1.2.11 are documented in the file ChangeLog. | |
34 | 34 | |
35 | 35 | Unsupported third party contributions are provided in directory contrib/ . |
36 | 36 | |
83 | 83 | |
84 | 84 | Copyright notice: |
85 | 85 | |
86 | (C) 1995-2013 Jean-loup Gailly and Mark Adler | |
86 | (C) 1995-2017 Jean-loup Gailly and Mark Adler | |
87 | 87 | |
88 | 88 | This software is provided 'as-is', without any express or implied |
89 | 89 | warranty. In no event will the authors be held liable for any damages |
0 | 0 | /* adler32.c -- compute the Adler-32 checksum of a data stream |
1 | * Copyright (C) 1995-2011 Mark Adler | |
1 | * Copyright (C) 1995-2011, 2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
6 | 6 | |
7 | 7 | #include "zutil.h" |
8 | 8 | |
9 | #define local static | |
10 | ||
11 | 9 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); |
12 | 10 | |
13 | #define BASE 65521 /* largest prime smaller than 65536 */ | |
11 | #define BASE 65521U /* largest prime smaller than 65536 */ | |
14 | 12 | #define NMAX 5552 |
15 | 13 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ |
16 | 14 | |
61 | 59 | #endif |
62 | 60 | |
63 | 61 | /* ========================================================================= */ |
64 | uLong ZEXPORT adler32(adler, buf, len) | |
62 | uLong ZEXPORT adler32_z(adler, buf, len) | |
65 | 63 | uLong adler; |
66 | 64 | const Bytef *buf; |
67 | uInt len; | |
65 | z_size_t len; | |
68 | 66 | { |
69 | 67 | unsigned long sum2; |
70 | 68 | unsigned n; |
132 | 130 | } |
133 | 131 | |
134 | 132 | /* ========================================================================= */ |
133 | uLong ZEXPORT adler32(adler, buf, len) | |
134 | uLong adler; | |
135 | const Bytef *buf; | |
136 | uInt len; | |
137 | { | |
138 | return adler32_z(adler, buf, len); | |
139 | } | |
140 | ||
141 | /* ========================================================================= */ | |
135 | 142 | local uLong adler32_combine_(adler1, adler2, len2) |
136 | 143 | uLong adler1; |
137 | 144 | uLong adler2; |
155 | 162 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; |
156 | 163 | if (sum1 >= BASE) sum1 -= BASE; |
157 | 164 | if (sum1 >= BASE) sum1 -= BASE; |
158 | if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); | |
165 | if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1); | |
159 | 166 | if (sum2 >= BASE) sum2 -= BASE; |
160 | 167 | return sum1 | (sum2 << 16); |
161 | 168 | } |
0 | 0 | /* compress.c -- compress a memory buffer |
1 | * Copyright (C) 1995-2005 Jean-loup Gailly. | |
1 | * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
27 | 27 | { |
28 | 28 | z_stream stream; |
29 | 29 | int err; |
30 | const uInt max = (uInt)-1; | |
31 | uLong left; | |
30 | 32 | |
31 | stream.next_in = (z_const Bytef *)source; | |
32 | stream.avail_in = (uInt)sourceLen; | |
33 | #ifdef MAXSEG_64K | |
34 | /* Check for source > 64K on 16-bit machine: */ | |
35 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | |
36 | #endif | |
37 | stream.next_out = dest; | |
38 | stream.avail_out = (uInt)*destLen; | |
39 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; | |
33 | left = *destLen; | |
34 | *destLen = 0; | |
40 | 35 | |
41 | 36 | stream.zalloc = (alloc_func)0; |
42 | 37 | stream.zfree = (free_func)0; |
45 | 40 | err = deflateInit(&stream, level); |
46 | 41 | if (err != Z_OK) return err; |
47 | 42 | |
48 | err = deflate(&stream, Z_FINISH); | |
49 | if (err != Z_STREAM_END) { | |
50 | deflateEnd(&stream); | |
51 | return err == Z_OK ? Z_BUF_ERROR : err; | |
52 | } | |
43 | stream.next_out = dest; | |
44 | stream.avail_out = 0; | |
45 | stream.next_in = (z_const Bytef *)source; | |
46 | stream.avail_in = 0; | |
47 | ||
48 | do { | |
49 | if (stream.avail_out == 0) { | |
50 | stream.avail_out = left > (uLong)max ? max : (uInt)left; | |
51 | left -= stream.avail_out; | |
52 | } | |
53 | if (stream.avail_in == 0) { | |
54 | stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen; | |
55 | sourceLen -= stream.avail_in; | |
56 | } | |
57 | err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH); | |
58 | } while (err == Z_OK); | |
59 | ||
53 | 60 | *destLen = stream.total_out; |
54 | ||
55 | err = deflateEnd(&stream); | |
56 | return err; | |
61 | deflateEnd(&stream); | |
62 | return err == Z_STREAM_END ? Z_OK : err; | |
57 | 63 | } |
58 | 64 | |
59 | 65 | /* =========================================================================== |
0 | 0 | /* crc32.c -- compute the CRC-32 of a data stream |
1 | * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler | |
1 | * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | * |
4 | 4 | * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster |
29 | 29 | |
30 | 30 | #include "zutil.h" /* for STDC and FAR definitions */ |
31 | 31 | |
32 | #define local static | |
33 | ||
34 | 32 | /* Definitions for doing the crc four data bytes at a time. */ |
35 | 33 | #if !defined(NOBYFOUR) && defined(Z_U4) |
36 | 34 | # define BYFOUR |
37 | 35 | #endif |
38 | 36 | #ifdef BYFOUR |
39 | 37 | local unsigned long crc32_little OF((unsigned long, |
40 | const unsigned char FAR *, unsigned)); | |
38 | const unsigned char FAR *, z_size_t)); | |
41 | 39 | local unsigned long crc32_big OF((unsigned long, |
42 | const unsigned char FAR *, unsigned)); | |
40 | const unsigned char FAR *, z_size_t)); | |
43 | 41 | # define TBLS 8 |
44 | 42 | #else |
45 | 43 | # define TBLS 1 |
200 | 198 | #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 |
201 | 199 | |
202 | 200 | /* ========================================================================= */ |
203 | unsigned long ZEXPORT crc32(crc, buf, len) | |
201 | unsigned long ZEXPORT crc32_z(crc, buf, len) | |
204 | 202 | unsigned long crc; |
205 | 203 | const unsigned char FAR *buf; |
206 | uInt len; | |
204 | z_size_t len; | |
207 | 205 | { |
208 | 206 | if (buf == Z_NULL) return 0UL; |
209 | 207 | |
234 | 232 | return crc ^ 0xffffffffUL; |
235 | 233 | } |
236 | 234 | |
235 | /* ========================================================================= */ | |
236 | unsigned long ZEXPORT crc32(crc, buf, len) | |
237 | unsigned long crc; | |
238 | const unsigned char FAR *buf; | |
239 | uInt len; | |
240 | { | |
241 | return crc32_z(crc, buf, len); | |
242 | } | |
243 | ||
237 | 244 | #ifdef BYFOUR |
245 | ||
246 | /* | |
247 | This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit | |
248 | integer pointer type. This violates the strict aliasing rule, where a | |
249 | compiler can assume, for optimization purposes, that two pointers to | |
250 | fundamentally different types won't ever point to the same memory. This can | |
251 | manifest as a problem only if one of the pointers is written to. This code | |
252 | only reads from those pointers. So long as this code remains isolated in | |
253 | this compilation unit, there won't be a problem. For this reason, this code | |
254 | should not be copied and pasted into a compilation unit in which other code | |
255 | writes to the buffer that is passed to these routines. | |
256 | */ | |
238 | 257 | |
239 | 258 | /* ========================================================================= */ |
240 | 259 | #define DOLIT4 c ^= *buf4++; \ |
246 | 265 | local unsigned long crc32_little(crc, buf, len) |
247 | 266 | unsigned long crc; |
248 | 267 | const unsigned char FAR *buf; |
249 | unsigned len; | |
268 | z_size_t len; | |
250 | 269 | { |
251 | 270 | register z_crc_t c; |
252 | 271 | register const z_crc_t FAR *buf4; |
277 | 296 | } |
278 | 297 | |
279 | 298 | /* ========================================================================= */ |
280 | #define DOBIG4 c ^= *++buf4; \ | |
299 | #define DOBIG4 c ^= *buf4++; \ | |
281 | 300 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ |
282 | 301 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] |
283 | 302 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 |
286 | 305 | local unsigned long crc32_big(crc, buf, len) |
287 | 306 | unsigned long crc; |
288 | 307 | const unsigned char FAR *buf; |
289 | unsigned len; | |
308 | z_size_t len; | |
290 | 309 | { |
291 | 310 | register z_crc_t c; |
292 | 311 | register const z_crc_t FAR *buf4; |
299 | 318 | } |
300 | 319 | |
301 | 320 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf; |
302 | buf4--; | |
303 | 321 | while (len >= 32) { |
304 | 322 | DOBIG32; |
305 | 323 | len -= 32; |
308 | 326 | DOBIG4; |
309 | 327 | len -= 4; |
310 | 328 | } |
311 | buf4++; | |
312 | 329 | buf = (const unsigned char FAR *)buf4; |
313 | 330 | |
314 | 331 | if (len) do { |
0 | 0 | /* deflate.c -- compress data using the deflation algorithm |
1 | * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler | |
1 | * Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
51 | 51 | #include "deflate.h" |
52 | 52 | |
53 | 53 | const char deflate_copyright[] = |
54 | " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; | |
54 | " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; | |
55 | 55 | /* |
56 | 56 | If you use the zlib library in a product, an acknowledgment is welcome |
57 | 57 | in the documentation of your product. If for some reason you cannot |
72 | 72 | typedef block_state (*compress_func) OF((deflate_state *s, int flush)); |
73 | 73 | /* Compression function. Returns the block state after the call. */ |
74 | 74 | |
75 | local int deflateStateCheck OF((z_streamp strm)); | |
76 | local void slide_hash OF((deflate_state *s)); | |
75 | 77 | local void fill_window OF((deflate_state *s)); |
76 | 78 | local block_state deflate_stored OF((deflate_state *s, int flush)); |
77 | 79 | local block_state deflate_fast OF((deflate_state *s, int flush)); |
83 | 85 | local void lm_init OF((deflate_state *s)); |
84 | 86 | local void putShortMSB OF((deflate_state *s, uInt b)); |
85 | 87 | local void flush_pending OF((z_streamp strm)); |
86 | local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); | |
88 | local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); | |
87 | 89 | #ifdef ASMV |
90 | # pragma message("Assembler code may have bugs -- use at your own risk") | |
88 | 91 | void match_init OF((void)); /* asm code initialization */ |
89 | 92 | uInt longest_match OF((deflate_state *s, IPos cur_match)); |
90 | 93 | #else |
91 | 94 | local uInt longest_match OF((deflate_state *s, IPos cur_match)); |
92 | 95 | #endif |
93 | 96 | |
94 | #ifdef DEBUG | |
97 | #ifdef ZLIB_DEBUG | |
95 | 98 | local void check_match OF((deflate_state *s, IPos start, IPos match, |
96 | 99 | int length)); |
97 | 100 | #endif |
147 | 150 | * meaning. |
148 | 151 | */ |
149 | 152 | |
150 | #define EQUAL 0 | |
151 | /* result of memcmp for equal strings */ | |
152 | ||
153 | #ifndef NO_DUMMY_DECL | |
154 | struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ | |
155 | #endif | |
156 | ||
157 | 153 | /* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ |
158 | #define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) | |
154 | #define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0)) | |
159 | 155 | |
160 | 156 | /* =========================================================================== |
161 | 157 | * Update a hash value with the given input byte |
162 | * IN assertion: all calls to to UPDATE_HASH are made with consecutive | |
163 | * input characters, so that a running hash key can be computed from the | |
164 | * previous key instead of complete recalculation each time. | |
158 | * IN assertion: all calls to UPDATE_HASH are made with consecutive input | |
159 | * characters, so that a running hash key can be computed from the previous | |
160 | * key instead of complete recalculation each time. | |
165 | 161 | */ |
166 | 162 | #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) |
167 | 163 | |
172 | 168 | * the previous length of the hash chain. |
173 | 169 | * If this file is compiled with -DFASTEST, the compression level is forced |
174 | 170 | * to 1, and no hash chains are maintained. |
175 | * IN assertion: all calls to to INSERT_STRING are made with consecutive | |
176 | * input characters and the first MIN_MATCH bytes of str are valid | |
177 | * (except for the last MIN_MATCH-1 bytes of the input file). | |
171 | * IN assertion: all calls to INSERT_STRING are made with consecutive input | |
172 | * characters and the first MIN_MATCH bytes of str are valid (except for | |
173 | * the last MIN_MATCH-1 bytes of the input file). | |
178 | 174 | */ |
179 | 175 | #ifdef FASTEST |
180 | 176 | #define INSERT_STRING(s, str, match_head) \ |
195 | 191 | #define CLEAR_HASH(s) \ |
196 | 192 | s->head[s->hash_size-1] = NIL; \ |
197 | 193 | zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); |
194 | ||
195 | /* =========================================================================== | |
196 | * Slide the hash table when sliding the window down (could be avoided with 32 | |
197 | * bit values at the expense of memory usage). We slide even when level == 0 to | |
198 | * keep the hash table consistent if we switch back to level > 0 later. | |
199 | */ | |
200 | local void slide_hash(s) | |
201 | deflate_state *s; | |
202 | { | |
203 | unsigned n, m; | |
204 | Posf *p; | |
205 | uInt wsize = s->w_size; | |
206 | ||
207 | n = s->hash_size; | |
208 | p = &s->head[n]; | |
209 | do { | |
210 | m = *--p; | |
211 | *p = (Pos)(m >= wsize ? m - wsize : NIL); | |
212 | } while (--n); | |
213 | n = wsize; | |
214 | #ifndef FASTEST | |
215 | p = &s->prev[n]; | |
216 | do { | |
217 | m = *--p; | |
218 | *p = (Pos)(m >= wsize ? m - wsize : NIL); | |
219 | /* If n is not on any hash chain, prev[n] is garbage but | |
220 | * its value will never be used. | |
221 | */ | |
222 | } while (--n); | |
223 | #endif | |
224 | } | |
198 | 225 | |
199 | 226 | /* ========================================================================= */ |
200 | 227 | int ZEXPORT deflateInit_(strm, level, version, stream_size) |
269 | 296 | #endif |
270 | 297 | if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || |
271 | 298 | windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || |
272 | strategy < 0 || strategy > Z_FIXED) { | |
299 | strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) { | |
273 | 300 | return Z_STREAM_ERROR; |
274 | 301 | } |
275 | 302 | if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ |
277 | 304 | if (s == Z_NULL) return Z_MEM_ERROR; |
278 | 305 | strm->state = (struct internal_state FAR *)s; |
279 | 306 | s->strm = strm; |
307 | s->status = INIT_STATE; /* to pass state test in deflateReset() */ | |
280 | 308 | |
281 | 309 | s->wrap = wrap; |
282 | 310 | s->gzhead = Z_NULL; |
283 | s->w_bits = windowBits; | |
311 | s->w_bits = (uInt)windowBits; | |
284 | 312 | s->w_size = 1 << s->w_bits; |
285 | 313 | s->w_mask = s->w_size - 1; |
286 | 314 | |
287 | s->hash_bits = memLevel + 7; | |
315 | s->hash_bits = (uInt)memLevel + 7; | |
288 | 316 | s->hash_size = 1 << s->hash_bits; |
289 | 317 | s->hash_mask = s->hash_size - 1; |
290 | 318 | s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); |
318 | 346 | return deflateReset(strm); |
319 | 347 | } |
320 | 348 | |
349 | /* ========================================================================= | |
350 | * Check for a valid deflate stream state. Return 0 if ok, 1 if not. | |
351 | */ | |
352 | local int deflateStateCheck (strm) | |
353 | z_streamp strm; | |
354 | { | |
355 | deflate_state *s; | |
356 | if (strm == Z_NULL || | |
357 | strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) | |
358 | return 1; | |
359 | s = strm->state; | |
360 | if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE && | |
361 | #ifdef GZIP | |
362 | s->status != GZIP_STATE && | |
363 | #endif | |
364 | s->status != EXTRA_STATE && | |
365 | s->status != NAME_STATE && | |
366 | s->status != COMMENT_STATE && | |
367 | s->status != HCRC_STATE && | |
368 | s->status != BUSY_STATE && | |
369 | s->status != FINISH_STATE)) | |
370 | return 1; | |
371 | return 0; | |
372 | } | |
373 | ||
321 | 374 | /* ========================================================================= */ |
322 | 375 | int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) |
323 | 376 | z_streamp strm; |
330 | 383 | unsigned avail; |
331 | 384 | z_const unsigned char *next; |
332 | 385 | |
333 | if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) | |
386 | if (deflateStateCheck(strm) || dictionary == Z_NULL) | |
334 | 387 | return Z_STREAM_ERROR; |
335 | 388 | s = strm->state; |
336 | 389 | wrap = s->wrap; |
388 | 441 | } |
389 | 442 | |
390 | 443 | /* ========================================================================= */ |
444 | int ZEXPORT deflateGetDictionary (strm, dictionary, dictLength) | |
445 | z_streamp strm; | |
446 | Bytef *dictionary; | |
447 | uInt *dictLength; | |
448 | { | |
449 | deflate_state *s; | |
450 | uInt len; | |
451 | ||
452 | if (deflateStateCheck(strm)) | |
453 | return Z_STREAM_ERROR; | |
454 | s = strm->state; | |
455 | len = s->strstart + s->lookahead; | |
456 | if (len > s->w_size) | |
457 | len = s->w_size; | |
458 | if (dictionary != Z_NULL && len) | |
459 | zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len); | |
460 | if (dictLength != Z_NULL) | |
461 | *dictLength = len; | |
462 | return Z_OK; | |
463 | } | |
464 | ||
465 | /* ========================================================================= */ | |
391 | 466 | int ZEXPORT deflateResetKeep (strm) |
392 | 467 | z_streamp strm; |
393 | 468 | { |
394 | 469 | deflate_state *s; |
395 | 470 | |
396 | if (strm == Z_NULL || strm->state == Z_NULL || | |
397 | strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { | |
471 | if (deflateStateCheck(strm)) { | |
398 | 472 | return Z_STREAM_ERROR; |
399 | 473 | } |
400 | 474 | |
409 | 483 | if (s->wrap < 0) { |
410 | 484 | s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ |
411 | 485 | } |
412 | s->status = s->wrap ? INIT_STATE : BUSY_STATE; | |
486 | s->status = | |
487 | #ifdef GZIP | |
488 | s->wrap == 2 ? GZIP_STATE : | |
489 | #endif | |
490 | s->wrap ? INIT_STATE : BUSY_STATE; | |
413 | 491 | strm->adler = |
414 | 492 | #ifdef GZIP |
415 | 493 | s->wrap == 2 ? crc32(0L, Z_NULL, 0) : |
439 | 517 | z_streamp strm; |
440 | 518 | gz_headerp head; |
441 | 519 | { |
442 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
443 | if (strm->state->wrap != 2) return Z_STREAM_ERROR; | |
520 | if (deflateStateCheck(strm) || strm->state->wrap != 2) | |
521 | return Z_STREAM_ERROR; | |
444 | 522 | strm->state->gzhead = head; |
445 | 523 | return Z_OK; |
446 | 524 | } |
451 | 529 | int *bits; |
452 | 530 | z_streamp strm; |
453 | 531 | { |
454 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
532 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | |
455 | 533 | if (pending != Z_NULL) |
456 | 534 | *pending = strm->state->pending; |
457 | 535 | if (bits != Z_NULL) |
468 | 546 | deflate_state *s; |
469 | 547 | int put; |
470 | 548 | |
471 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
549 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | |
472 | 550 | s = strm->state; |
473 | 551 | if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) |
474 | 552 | return Z_BUF_ERROR; |
493 | 571 | { |
494 | 572 | deflate_state *s; |
495 | 573 | compress_func func; |
496 | int err = Z_OK; | |
497 | ||
498 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
574 | ||
575 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | |
499 | 576 | s = strm->state; |
500 | 577 | |
501 | 578 | #ifdef FASTEST |
509 | 586 | func = configuration_table[s->level].func; |
510 | 587 | |
511 | 588 | if ((strategy != s->strategy || func != configuration_table[level].func) && |
512 | strm->total_in != 0) { | |
589 | s->high_water) { | |
513 | 590 | /* Flush the last buffer: */ |
514 | err = deflate(strm, Z_BLOCK); | |
515 | if (err == Z_BUF_ERROR && s->pending == 0) | |
516 | err = Z_OK; | |
591 | int err = deflate(strm, Z_BLOCK); | |
592 | if (err == Z_STREAM_ERROR) | |
593 | return err; | |
594 | if (strm->avail_out == 0) | |
595 | return Z_BUF_ERROR; | |
517 | 596 | } |
518 | 597 | if (s->level != level) { |
598 | if (s->level == 0 && s->matches != 0) { | |
599 | if (s->matches == 1) | |
600 | slide_hash(s); | |
601 | else | |
602 | CLEAR_HASH(s); | |
603 | s->matches = 0; | |
604 | } | |
519 | 605 | s->level = level; |
520 | 606 | s->max_lazy_match = configuration_table[level].max_lazy; |
521 | 607 | s->good_match = configuration_table[level].good_length; |
523 | 609 | s->max_chain_length = configuration_table[level].max_chain; |
524 | 610 | } |
525 | 611 | s->strategy = strategy; |
526 | return err; | |
612 | return Z_OK; | |
527 | 613 | } |
528 | 614 | |
529 | 615 | /* ========================================================================= */ |
536 | 622 | { |
537 | 623 | deflate_state *s; |
538 | 624 | |
539 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
625 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | |
540 | 626 | s = strm->state; |
541 | s->good_match = good_length; | |
542 | s->max_lazy_match = max_lazy; | |
627 | s->good_match = (uInt)good_length; | |
628 | s->max_lazy_match = (uInt)max_lazy; | |
543 | 629 | s->nice_match = nice_length; |
544 | s->max_chain_length = max_chain; | |
630 | s->max_chain_length = (uInt)max_chain; | |
545 | 631 | return Z_OK; |
546 | 632 | } |
547 | 633 | |
568 | 654 | { |
569 | 655 | deflate_state *s; |
570 | 656 | uLong complen, wraplen; |
571 | Bytef *str; | |
572 | 657 | |
573 | 658 | /* conservative upper bound for compressed data */ |
574 | 659 | complen = sourceLen + |
575 | 660 | ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; |
576 | 661 | |
577 | 662 | /* if can't get parameters, return conservative bound plus zlib wrapper */ |
578 | if (strm == Z_NULL || strm->state == Z_NULL) | |
663 | if (deflateStateCheck(strm)) | |
579 | 664 | return complen + 6; |
580 | 665 | |
581 | 666 | /* compute wrapper length */ |
587 | 672 | case 1: /* zlib wrapper */ |
588 | 673 | wraplen = 6 + (s->strstart ? 4 : 0); |
589 | 674 | break; |
675 | #ifdef GZIP | |
590 | 676 | case 2: /* gzip wrapper */ |
591 | 677 | wraplen = 18; |
592 | 678 | if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ |
679 | Bytef *str; | |
593 | 680 | if (s->gzhead->extra != Z_NULL) |
594 | 681 | wraplen += 2 + s->gzhead->extra_len; |
595 | 682 | str = s->gzhead->name; |
606 | 693 | wraplen += 2; |
607 | 694 | } |
608 | 695 | break; |
696 | #endif | |
609 | 697 | default: /* for compiler happiness */ |
610 | 698 | wraplen = 6; |
611 | 699 | } |
633 | 721 | } |
634 | 722 | |
635 | 723 | /* ========================================================================= |
636 | * Flush as much pending output as possible. All deflate() output goes | |
637 | * through this function so some applications may wish to modify it | |
638 | * to avoid allocating a large strm->next_out buffer and copying into it. | |
639 | * (See also read_buf()). | |
724 | * Flush as much pending output as possible. All deflate() output, except for | |
725 | * some deflate_stored() output, goes through this function so some | |
726 | * applications may wish to modify it to avoid allocating a large | |
727 | * strm->next_out buffer and copying into it. (See also read_buf()). | |
640 | 728 | */ |
641 | 729 | local void flush_pending(strm) |
642 | 730 | z_streamp strm; |
653 | 741 | strm->next_out += len; |
654 | 742 | s->pending_out += len; |
655 | 743 | strm->total_out += len; |
656 | strm->avail_out -= len; | |
657 | s->pending -= len; | |
744 | strm->avail_out -= len; | |
745 | s->pending -= len; | |
658 | 746 | if (s->pending == 0) { |
659 | 747 | s->pending_out = s->pending_buf; |
660 | 748 | } |
661 | 749 | } |
750 | ||
751 | /* =========================================================================== | |
752 | * Update the header CRC with the bytes s->pending_buf[beg..s->pending - 1]. | |
753 | */ | |
754 | #define HCRC_UPDATE(beg) \ | |
755 | do { \ | |
756 | if (s->gzhead->hcrc && s->pending > (beg)) \ | |
757 | strm->adler = crc32(strm->adler, s->pending_buf + (beg), \ | |
758 | s->pending - (beg)); \ | |
759 | } while (0) | |
662 | 760 | |
663 | 761 | /* ========================================================================= */ |
664 | 762 | int ZEXPORT deflate (strm, flush) |
668 | 766 | int old_flush; /* value of flush param for previous deflate call */ |
669 | 767 | deflate_state *s; |
670 | 768 | |
671 | if (strm == Z_NULL || strm->state == Z_NULL || | |
672 | flush > Z_BLOCK || flush < 0) { | |
769 | if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) { | |
673 | 770 | return Z_STREAM_ERROR; |
674 | 771 | } |
675 | 772 | s = strm->state; |
676 | 773 | |
677 | 774 | if (strm->next_out == Z_NULL || |
678 | (strm->next_in == Z_NULL && strm->avail_in != 0) || | |
775 | (strm->avail_in != 0 && strm->next_in == Z_NULL) || | |
679 | 776 | (s->status == FINISH_STATE && flush != Z_FINISH)) { |
680 | 777 | ERR_RETURN(strm, Z_STREAM_ERROR); |
681 | 778 | } |
682 | 779 | if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); |
683 | 780 | |
684 | s->strm = strm; /* just in case */ | |
685 | 781 | old_flush = s->last_flush; |
686 | 782 | s->last_flush = flush; |
687 | ||
688 | /* Write the header */ | |
689 | if (s->status == INIT_STATE) { | |
690 | #ifdef GZIP | |
691 | if (s->wrap == 2) { | |
692 | strm->adler = crc32(0L, Z_NULL, 0); | |
693 | put_byte(s, 31); | |
694 | put_byte(s, 139); | |
695 | put_byte(s, 8); | |
696 | if (s->gzhead == Z_NULL) { | |
697 | put_byte(s, 0); | |
698 | put_byte(s, 0); | |
699 | put_byte(s, 0); | |
700 | put_byte(s, 0); | |
701 | put_byte(s, 0); | |
702 | put_byte(s, s->level == 9 ? 2 : | |
703 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | |
704 | 4 : 0)); | |
705 | put_byte(s, OS_CODE); | |
706 | s->status = BUSY_STATE; | |
707 | } | |
708 | else { | |
709 | put_byte(s, (s->gzhead->text ? 1 : 0) + | |
710 | (s->gzhead->hcrc ? 2 : 0) + | |
711 | (s->gzhead->extra == Z_NULL ? 0 : 4) + | |
712 | (s->gzhead->name == Z_NULL ? 0 : 8) + | |
713 | (s->gzhead->comment == Z_NULL ? 0 : 16) | |
714 | ); | |
715 | put_byte(s, (Byte)(s->gzhead->time & 0xff)); | |
716 | put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); | |
717 | put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); | |
718 | put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); | |
719 | put_byte(s, s->level == 9 ? 2 : | |
720 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | |
721 | 4 : 0)); | |
722 | put_byte(s, s->gzhead->os & 0xff); | |
723 | if (s->gzhead->extra != Z_NULL) { | |
724 | put_byte(s, s->gzhead->extra_len & 0xff); | |
725 | put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); | |
726 | } | |
727 | if (s->gzhead->hcrc) | |
728 | strm->adler = crc32(strm->adler, s->pending_buf, | |
729 | s->pending); | |
730 | s->gzindex = 0; | |
731 | s->status = EXTRA_STATE; | |
732 | } | |
733 | } | |
734 | else | |
735 | #endif | |
736 | { | |
737 | uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; | |
738 | uInt level_flags; | |
739 | ||
740 | if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) | |
741 | level_flags = 0; | |
742 | else if (s->level < 6) | |
743 | level_flags = 1; | |
744 | else if (s->level == 6) | |
745 | level_flags = 2; | |
746 | else | |
747 | level_flags = 3; | |
748 | header |= (level_flags << 6); | |
749 | if (s->strstart != 0) header |= PRESET_DICT; | |
750 | header += 31 - (header % 31); | |
751 | ||
752 | s->status = BUSY_STATE; | |
753 | putShortMSB(s, header); | |
754 | ||
755 | /* Save the adler32 of the preset dictionary: */ | |
756 | if (s->strstart != 0) { | |
757 | putShortMSB(s, (uInt)(strm->adler >> 16)); | |
758 | putShortMSB(s, (uInt)(strm->adler & 0xffff)); | |
759 | } | |
760 | strm->adler = adler32(0L, Z_NULL, 0); | |
761 | } | |
762 | } | |
763 | #ifdef GZIP | |
764 | if (s->status == EXTRA_STATE) { | |
765 | if (s->gzhead->extra != Z_NULL) { | |
766 | uInt beg = s->pending; /* start of bytes to update crc */ | |
767 | ||
768 | while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { | |
769 | if (s->pending == s->pending_buf_size) { | |
770 | if (s->gzhead->hcrc && s->pending > beg) | |
771 | strm->adler = crc32(strm->adler, s->pending_buf + beg, | |
772 | s->pending - beg); | |
773 | flush_pending(strm); | |
774 | beg = s->pending; | |
775 | if (s->pending == s->pending_buf_size) | |
776 | break; | |
777 | } | |
778 | put_byte(s, s->gzhead->extra[s->gzindex]); | |
779 | s->gzindex++; | |
780 | } | |
781 | if (s->gzhead->hcrc && s->pending > beg) | |
782 | strm->adler = crc32(strm->adler, s->pending_buf + beg, | |
783 | s->pending - beg); | |
784 | if (s->gzindex == s->gzhead->extra_len) { | |
785 | s->gzindex = 0; | |
786 | s->status = NAME_STATE; | |
787 | } | |
788 | } | |
789 | else | |
790 | s->status = NAME_STATE; | |
791 | } | |
792 | if (s->status == NAME_STATE) { | |
793 | if (s->gzhead->name != Z_NULL) { | |
794 | uInt beg = s->pending; /* start of bytes to update crc */ | |
795 | int val; | |
796 | ||
797 | do { | |
798 | if (s->pending == s->pending_buf_size) { | |
799 | if (s->gzhead->hcrc && s->pending > beg) | |
800 | strm->adler = crc32(strm->adler, s->pending_buf + beg, | |
801 | s->pending - beg); | |
802 | flush_pending(strm); | |
803 | beg = s->pending; | |
804 | if (s->pending == s->pending_buf_size) { | |
805 | val = 1; | |
806 | break; | |
807 | } | |
808 | } | |
809 | val = s->gzhead->name[s->gzindex++]; | |
810 | put_byte(s, val); | |
811 | } while (val != 0); | |
812 | if (s->gzhead->hcrc && s->pending > beg) | |
813 | strm->adler = crc32(strm->adler, s->pending_buf + beg, | |
814 | s->pending - beg); | |
815 | if (val == 0) { | |
816 | s->gzindex = 0; | |
817 | s->status = COMMENT_STATE; | |
818 | } | |
819 | } | |
820 | else | |
821 | s->status = COMMENT_STATE; | |
822 | } | |
823 | if (s->status == COMMENT_STATE) { | |
824 | if (s->gzhead->comment != Z_NULL) { | |
825 | uInt beg = s->pending; /* start of bytes to update crc */ | |
826 | int val; | |
827 | ||
828 | do { | |
829 | if (s->pending == s->pending_buf_size) { | |
830 | if (s->gzhead->hcrc && s->pending > beg) | |
831 | strm->adler = crc32(strm->adler, s->pending_buf + beg, | |
832 | s->pending - beg); | |
833 | flush_pending(strm); | |
834 | beg = s->pending; | |
835 | if (s->pending == s->pending_buf_size) { | |
836 | val = 1; | |
837 | break; | |
838 | } | |
839 | } | |
840 | val = s->gzhead->comment[s->gzindex++]; | |
841 | put_byte(s, val); | |
842 | } while (val != 0); | |
843 | if (s->gzhead->hcrc && s->pending > beg) | |
844 | strm->adler = crc32(strm->adler, s->pending_buf + beg, | |
845 | s->pending - beg); | |
846 | if (val == 0) | |
847 | s->status = HCRC_STATE; | |
848 | } | |
849 | else | |
850 | s->status = HCRC_STATE; | |
851 | } | |
852 | if (s->status == HCRC_STATE) { | |
853 | if (s->gzhead->hcrc) { | |
854 | if (s->pending + 2 > s->pending_buf_size) | |
855 | flush_pending(strm); | |
856 | if (s->pending + 2 <= s->pending_buf_size) { | |
857 | put_byte(s, (Byte)(strm->adler & 0xff)); | |
858 | put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); | |
859 | strm->adler = crc32(0L, Z_NULL, 0); | |
860 | s->status = BUSY_STATE; | |
861 | } | |
862 | } | |
863 | else | |
864 | s->status = BUSY_STATE; | |
865 | } | |
866 | #endif | |
867 | 783 | |
868 | 784 | /* Flush as much pending output as possible */ |
869 | 785 | if (s->pending != 0) { |
893 | 809 | ERR_RETURN(strm, Z_BUF_ERROR); |
894 | 810 | } |
895 | 811 | |
812 | /* Write the header */ | |
813 | if (s->status == INIT_STATE) { | |
814 | /* zlib header */ | |
815 | uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; | |
816 | uInt level_flags; | |
817 | ||
818 | if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) | |
819 | level_flags = 0; | |
820 | else if (s->level < 6) | |
821 | level_flags = 1; | |
822 | else if (s->level == 6) | |
823 | level_flags = 2; | |
824 | else | |
825 | level_flags = 3; | |
826 | header |= (level_flags << 6); | |
827 | if (s->strstart != 0) header |= PRESET_DICT; | |
828 | header += 31 - (header % 31); | |
829 | ||
830 | putShortMSB(s, header); | |
831 | ||
832 | /* Save the adler32 of the preset dictionary: */ | |
833 | if (s->strstart != 0) { | |
834 | putShortMSB(s, (uInt)(strm->adler >> 16)); | |
835 | putShortMSB(s, (uInt)(strm->adler & 0xffff)); | |
836 | } | |
837 | strm->adler = adler32(0L, Z_NULL, 0); | |
838 | s->status = BUSY_STATE; | |
839 | ||
840 | /* Compression must start with an empty pending buffer */ | |
841 | flush_pending(strm); | |
842 | if (s->pending != 0) { | |
843 | s->last_flush = -1; | |
844 | return Z_OK; | |
845 | } | |
846 | } | |
847 | #ifdef GZIP | |
848 | if (s->status == GZIP_STATE) { | |
849 | /* gzip header */ | |
850 | strm->adler = crc32(0L, Z_NULL, 0); | |
851 | put_byte(s, 31); | |
852 | put_byte(s, 139); | |
853 | put_byte(s, 8); | |
854 | if (s->gzhead == Z_NULL) { | |
855 | put_byte(s, 0); | |
856 | put_byte(s, 0); | |
857 | put_byte(s, 0); | |
858 | put_byte(s, 0); | |
859 | put_byte(s, 0); | |
860 | put_byte(s, s->level == 9 ? 2 : | |
861 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | |
862 | 4 : 0)); | |
863 | put_byte(s, OS_CODE); | |
864 | s->status = BUSY_STATE; | |
865 | ||
866 | /* Compression must start with an empty pending buffer */ | |
867 | flush_pending(strm); | |
868 | if (s->pending != 0) { | |
869 | s->last_flush = -1; | |
870 | return Z_OK; | |
871 | } | |
872 | } | |
873 | else { | |
874 | put_byte(s, (s->gzhead->text ? 1 : 0) + | |
875 | (s->gzhead->hcrc ? 2 : 0) + | |
876 | (s->gzhead->extra == Z_NULL ? 0 : 4) + | |
877 | (s->gzhead->name == Z_NULL ? 0 : 8) + | |
878 | (s->gzhead->comment == Z_NULL ? 0 : 16) | |
879 | ); | |
880 | put_byte(s, (Byte)(s->gzhead->time & 0xff)); | |
881 | put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); | |
882 | put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); | |
883 | put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); | |
884 | put_byte(s, s->level == 9 ? 2 : | |
885 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | |
886 | 4 : 0)); | |
887 | put_byte(s, s->gzhead->os & 0xff); | |
888 | if (s->gzhead->extra != Z_NULL) { | |
889 | put_byte(s, s->gzhead->extra_len & 0xff); | |
890 | put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); | |
891 | } | |
892 | if (s->gzhead->hcrc) | |
893 | strm->adler = crc32(strm->adler, s->pending_buf, | |
894 | s->pending); | |
895 | s->gzindex = 0; | |
896 | s->status = EXTRA_STATE; | |
897 | } | |
898 | } | |
899 | if (s->status == EXTRA_STATE) { | |
900 | if (s->gzhead->extra != Z_NULL) { | |
901 | ulg beg = s->pending; /* start of bytes to update crc */ | |
902 | uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex; | |
903 | while (s->pending + left > s->pending_buf_size) { | |
904 | uInt copy = s->pending_buf_size - s->pending; | |
905 | zmemcpy(s->pending_buf + s->pending, | |
906 | s->gzhead->extra + s->gzindex, copy); | |
907 | s->pending = s->pending_buf_size; | |
908 | HCRC_UPDATE(beg); | |
909 | s->gzindex += copy; | |
910 | flush_pending(strm); | |
911 | if (s->pending != 0) { | |
912 | s->last_flush = -1; | |
913 | return Z_OK; | |
914 | } | |
915 | beg = 0; | |
916 | left -= copy; | |
917 | } | |
918 | zmemcpy(s->pending_buf + s->pending, | |
919 | s->gzhead->extra + s->gzindex, left); | |
920 | s->pending += left; | |
921 | HCRC_UPDATE(beg); | |
922 | s->gzindex = 0; | |
923 | } | |
924 | s->status = NAME_STATE; | |
925 | } | |
926 | if (s->status == NAME_STATE) { | |
927 | if (s->gzhead->name != Z_NULL) { | |
928 | ulg beg = s->pending; /* start of bytes to update crc */ | |
929 | int val; | |
930 | do { | |
931 | if (s->pending == s->pending_buf_size) { | |
932 | HCRC_UPDATE(beg); | |
933 | flush_pending(strm); | |
934 | if (s->pending != 0) { | |
935 | s->last_flush = -1; | |
936 | return Z_OK; | |
937 | } | |
938 | beg = 0; | |
939 | } | |
940 | val = s->gzhead->name[s->gzindex++]; | |
941 | put_byte(s, val); | |
942 | } while (val != 0); | |
943 | HCRC_UPDATE(beg); | |
944 | s->gzindex = 0; | |
945 | } | |
946 | s->status = COMMENT_STATE; | |
947 | } | |
948 | if (s->status == COMMENT_STATE) { | |
949 | if (s->gzhead->comment != Z_NULL) { | |
950 | ulg beg = s->pending; /* start of bytes to update crc */ | |
951 | int val; | |
952 | do { | |
953 | if (s->pending == s->pending_buf_size) { | |
954 | HCRC_UPDATE(beg); | |
955 | flush_pending(strm); | |
956 | if (s->pending != 0) { | |
957 | s->last_flush = -1; | |
958 | return Z_OK; | |
959 | } | |
960 | beg = 0; | |
961 | } | |
962 | val = s->gzhead->comment[s->gzindex++]; | |
963 | put_byte(s, val); | |
964 | } while (val != 0); | |
965 | HCRC_UPDATE(beg); | |
966 | } | |
967 | s->status = HCRC_STATE; | |
968 | } | |
969 | if (s->status == HCRC_STATE) { | |
970 | if (s->gzhead->hcrc) { | |
971 | if (s->pending + 2 > s->pending_buf_size) { | |
972 | flush_pending(strm); | |
973 | if (s->pending != 0) { | |
974 | s->last_flush = -1; | |
975 | return Z_OK; | |
976 | } | |
977 | } | |
978 | put_byte(s, (Byte)(strm->adler & 0xff)); | |
979 | put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); | |
980 | strm->adler = crc32(0L, Z_NULL, 0); | |
981 | } | |
982 | s->status = BUSY_STATE; | |
983 | ||
984 | /* Compression must start with an empty pending buffer */ | |
985 | flush_pending(strm); | |
986 | if (s->pending != 0) { | |
987 | s->last_flush = -1; | |
988 | return Z_OK; | |
989 | } | |
990 | } | |
991 | #endif | |
992 | ||
896 | 993 | /* Start a new block or continue the current one. |
897 | 994 | */ |
898 | 995 | if (strm->avail_in != 0 || s->lookahead != 0 || |
899 | 996 | (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { |
900 | 997 | block_state bstate; |
901 | 998 | |
902 | bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : | |
903 | (s->strategy == Z_RLE ? deflate_rle(s, flush) : | |
904 | (*(configuration_table[s->level].func))(s, flush)); | |
999 | bstate = s->level == 0 ? deflate_stored(s, flush) : | |
1000 | s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : | |
1001 | s->strategy == Z_RLE ? deflate_rle(s, flush) : | |
1002 | (*(configuration_table[s->level].func))(s, flush); | |
905 | 1003 | |
906 | 1004 | if (bstate == finish_started || bstate == finish_done) { |
907 | 1005 | s->status = FINISH_STATE; |
943 | 1041 | } |
944 | 1042 | } |
945 | 1043 | } |
946 | Assert(strm->avail_out > 0, "bug2"); | |
947 | 1044 | |
948 | 1045 | if (flush != Z_FINISH) return Z_OK; |
949 | 1046 | if (s->wrap <= 0) return Z_STREAM_END; |
980 | 1077 | { |
981 | 1078 | int status; |
982 | 1079 | |
983 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1080 | if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | |
984 | 1081 | |
985 | 1082 | status = strm->state->status; |
986 | if (status != INIT_STATE && | |
987 | status != EXTRA_STATE && | |
988 | status != NAME_STATE && | |
989 | status != COMMENT_STATE && | |
990 | status != HCRC_STATE && | |
991 | status != BUSY_STATE && | |
992 | status != FINISH_STATE) { | |
993 | return Z_STREAM_ERROR; | |
994 | } | |
995 | 1083 | |
996 | 1084 | /* Deallocate in reverse order of allocations: */ |
997 | 1085 | TRY_FREE(strm, strm->state->pending_buf); |
1022 | 1110 | ushf *overlay; |
1023 | 1111 | |
1024 | 1112 | |
1025 | if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { | |
1113 | if (deflateStateCheck(source) || dest == Z_NULL) { | |
1026 | 1114 | return Z_STREAM_ERROR; |
1027 | 1115 | } |
1028 | 1116 | |
1072 | 1160 | * allocating a large strm->next_in buffer and copying from it. |
1073 | 1161 | * (See also flush_pending()). |
1074 | 1162 | */ |
1075 | local int read_buf(strm, buf, size) | |
1163 | local unsigned read_buf(strm, buf, size) | |
1076 | 1164 | z_streamp strm; |
1077 | 1165 | Bytef *buf; |
1078 | 1166 | unsigned size; |
1096 | 1184 | strm->next_in += len; |
1097 | 1185 | strm->total_in += len; |
1098 | 1186 | |
1099 | return (int)len; | |
1187 | return len; | |
1100 | 1188 | } |
1101 | 1189 | |
1102 | 1190 | /* =========================================================================== |
1150 | 1238 | { |
1151 | 1239 | unsigned chain_length = s->max_chain_length;/* max hash chain length */ |
1152 | 1240 | register Bytef *scan = s->window + s->strstart; /* current string */ |
1153 | register Bytef *match; /* matched string */ | |
1241 | register Bytef *match; /* matched string */ | |
1154 | 1242 | register int len; /* length of current match */ |
1155 | int best_len = s->prev_length; /* best match length so far */ | |
1243 | int best_len = (int)s->prev_length; /* best match length so far */ | |
1156 | 1244 | int nice_match = s->nice_match; /* stop if match long enough */ |
1157 | 1245 | IPos limit = s->strstart > (IPos)MAX_DIST(s) ? |
1158 | 1246 | s->strstart - (IPos)MAX_DIST(s) : NIL; |
1187 | 1275 | /* Do not look for matches beyond the end of the input. This is necessary |
1188 | 1276 | * to make deflate deterministic. |
1189 | 1277 | */ |
1190 | if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; | |
1278 | if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead; | |
1191 | 1279 | |
1192 | 1280 | Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); |
1193 | 1281 | |
1348 | 1436 | |
1349 | 1437 | #endif /* FASTEST */ |
1350 | 1438 | |
1351 | #ifdef DEBUG | |
1439 | #ifdef ZLIB_DEBUG | |
1440 | ||
1441 | #define EQUAL 0 | |
1442 | /* result of memcmp for equal strings */ | |
1443 | ||
1352 | 1444 | /* =========================================================================== |
1353 | 1445 | * Check that the match at match_start is indeed a match. |
1354 | 1446 | */ |
1374 | 1466 | } |
1375 | 1467 | #else |
1376 | 1468 | # define check_match(s, start, match, length) |
1377 | #endif /* DEBUG */ | |
1469 | #endif /* ZLIB_DEBUG */ | |
1378 | 1470 | |
1379 | 1471 | /* =========================================================================== |
1380 | 1472 | * Fill the window when the lookahead becomes insufficient. |
1389 | 1481 | local void fill_window(s) |
1390 | 1482 | deflate_state *s; |
1391 | 1483 | { |
1392 | register unsigned n, m; | |
1393 | register Posf *p; | |
1484 | unsigned n; | |
1394 | 1485 | unsigned more; /* Amount of free space at the end of the window. */ |
1395 | 1486 | uInt wsize = s->w_size; |
1396 | 1487 | |
1417 | 1508 | */ |
1418 | 1509 | if (s->strstart >= wsize+MAX_DIST(s)) { |
1419 | 1510 | |
1420 | zmemcpy(s->window, s->window+wsize, (unsigned)wsize); | |
1511 | zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more); | |
1421 | 1512 | s->match_start -= wsize; |
1422 | 1513 | s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
1423 | 1514 | s->block_start -= (long) wsize; |
1424 | ||
1425 | /* Slide the hash table (could be avoided with 32 bit values | |
1426 | at the expense of memory usage). We slide even when level == 0 | |
1427 | to keep the hash table consistent if we switch back to level > 0 | |
1428 | later. (Using level 0 permanently is not an optimal usage of | |
1429 | zlib, so we don't care about this pathological case.) | |
1430 | */ | |
1431 | n = s->hash_size; | |
1432 | p = &s->head[n]; | |
1433 | do { | |
1434 | m = *--p; | |
1435 | *p = (Pos)(m >= wsize ? m-wsize : NIL); | |
1436 | } while (--n); | |
1437 | ||
1438 | n = wsize; | |
1439 | #ifndef FASTEST | |
1440 | p = &s->prev[n]; | |
1441 | do { | |
1442 | m = *--p; | |
1443 | *p = (Pos)(m >= wsize ? m-wsize : NIL); | |
1444 | /* If n is not on any hash chain, prev[n] is garbage but | |
1445 | * its value will never be used. | |
1446 | */ | |
1447 | } while (--n); | |
1448 | #endif | |
1515 | slide_hash(s); | |
1449 | 1516 | more += wsize; |
1450 | 1517 | } |
1451 | 1518 | if (s->strm->avail_in == 0) break; |
1551 | 1618 | if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ |
1552 | 1619 | } |
1553 | 1620 | |
1621 | /* Maximum stored block length in deflate format (not including header). */ | |
1622 | #define MAX_STORED 65535 | |
1623 | ||
1624 | /* Minimum of a and b. */ | |
1625 | #define MIN(a, b) ((a) > (b) ? (b) : (a)) | |
1626 | ||
1554 | 1627 | /* =========================================================================== |
1555 | 1628 | * Copy without compression as much as possible from the input stream, return |
1556 | 1629 | * the current block state. |
1557 | * This function does not insert new strings in the dictionary since | |
1558 | * uncompressible data is probably not useful. This function is used | |
1559 | * only for the level=0 compression option. | |
1560 | * NOTE: this function should be optimized to avoid extra copying from | |
1561 | * window to pending_buf. | |
1630 | * | |
1631 | * In case deflateParams() is used to later switch to a non-zero compression | |
1632 | * level, s->matches (otherwise unused when storing) keeps track of the number | |
1633 | * of hash table slides to perform. If s->matches is 1, then one hash table | |
1634 | * slide will be done when switching. If s->matches is 2, the maximum value | |
1635 | * allowed here, then the hash table will be cleared, since two or more slides | |
1636 | * is the same as a clear. | |
1637 | * | |
1638 | * deflate_stored() is written to minimize the number of times an input byte is | |
1639 | * copied. It is most efficient with large input and output buffers, which | |
1640 | * maximizes the opportunites to have a single copy from next_in to next_out. | |
1562 | 1641 | */ |
1563 | 1642 | local block_state deflate_stored(s, flush) |
1564 | 1643 | deflate_state *s; |
1565 | 1644 | int flush; |
1566 | 1645 | { |
1567 | /* Stored blocks are limited to 0xffff bytes, pending_buf is limited | |
1568 | * to pending_buf_size, and each stored block has a 5 byte header: | |
1646 | /* Smallest worthy block size when not flushing or finishing. By default | |
1647 | * this is 32K. This can be as small as 507 bytes for memLevel == 1. For | |
1648 | * large input and output buffers, the stored block size will be larger. | |
1569 | 1649 | */ |
1570 | ulg max_block_size = 0xffff; | |
1571 | ulg max_start; | |
1572 | ||
1573 | if (max_block_size > s->pending_buf_size - 5) { | |
1574 | max_block_size = s->pending_buf_size - 5; | |
1575 | } | |
1576 | ||
1577 | /* Copy as much as possible from input to output: */ | |
1578 | for (;;) { | |
1579 | /* Fill the window as much as possible: */ | |
1580 | if (s->lookahead <= 1) { | |
1581 | ||
1582 | Assert(s->strstart < s->w_size+MAX_DIST(s) || | |
1583 | s->block_start >= (long)s->w_size, "slide too late"); | |
1584 | ||
1585 | fill_window(s); | |
1586 | if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; | |
1587 | ||
1588 | if (s->lookahead == 0) break; /* flush the current block */ | |
1589 | } | |
1590 | Assert(s->block_start >= 0L, "block gone"); | |
1591 | ||
1592 | s->strstart += s->lookahead; | |
1593 | s->lookahead = 0; | |
1594 | ||
1595 | /* Emit a stored block if pending_buf will be full: */ | |
1596 | max_start = s->block_start + max_block_size; | |
1597 | if (s->strstart == 0 || (ulg)s->strstart >= max_start) { | |
1598 | /* strstart == 0 is possible when wraparound on 16-bit machine */ | |
1599 | s->lookahead = (uInt)(s->strstart - max_start); | |
1600 | s->strstart = (uInt)max_start; | |
1601 | FLUSH_BLOCK(s, 0); | |
1602 | } | |
1603 | /* Flush if we may have to slide, otherwise block_start may become | |
1604 | * negative and the data will be gone: | |
1650 | unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size); | |
1651 | ||
1652 | /* Copy as many min_block or larger stored blocks directly to next_out as | |
1653 | * possible. If flushing, copy the remaining available input to next_out as | |
1654 | * stored blocks, if there is enough space. | |
1655 | */ | |
1656 | unsigned len, left, have, last = 0; | |
1657 | unsigned used = s->strm->avail_in; | |
1658 | do { | |
1659 | /* Set len to the maximum size block that we can copy directly with the | |
1660 | * available input data and output space. Set left to how much of that | |
1661 | * would be copied from what's left in the window. | |
1605 | 1662 | */ |
1606 | if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { | |
1607 | FLUSH_BLOCK(s, 0); | |
1608 | } | |
1609 | } | |
1610 | s->insert = 0; | |
1611 | if (flush == Z_FINISH) { | |
1612 | FLUSH_BLOCK(s, 1); | |
1663 | len = MAX_STORED; /* maximum deflate stored block length */ | |
1664 | have = (s->bi_valid + 42) >> 3; /* number of header bytes */ | |
1665 | if (s->strm->avail_out < have) /* need room for header */ | |
1666 | break; | |
1667 | /* maximum stored block length that will fit in avail_out: */ | |
1668 | have = s->strm->avail_out - have; | |
1669 | left = s->strstart - s->block_start; /* bytes left in window */ | |
1670 | if (len > (ulg)left + s->strm->avail_in) | |
1671 | len = left + s->strm->avail_in; /* limit len to the input */ | |
1672 | if (len > have) | |
1673 | len = have; /* limit len to the output */ | |
1674 | ||
1675 | /* If the stored block would be less than min_block in length, or if | |
1676 | * unable to copy all of the available input when flushing, then try | |
1677 | * copying to the window and the pending buffer instead. Also don't | |
1678 | * write an empty block when flushing -- deflate() does that. | |
1679 | */ | |
1680 | if (len < min_block && ((len == 0 && flush != Z_FINISH) || | |
1681 | flush == Z_NO_FLUSH || | |
1682 | len != left + s->strm->avail_in)) | |
1683 | break; | |
1684 | ||
1685 | /* Make a dummy stored block in pending to get the header bytes, | |
1686 | * including any pending bits. This also updates the debugging counts. | |
1687 | */ | |
1688 | last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0; | |
1689 | _tr_stored_block(s, (char *)0, 0L, last); | |
1690 | ||
1691 | /* Replace the lengths in the dummy stored block with len. */ | |
1692 | s->pending_buf[s->pending - 4] = len; | |
1693 | s->pending_buf[s->pending - 3] = len >> 8; | |
1694 | s->pending_buf[s->pending - 2] = ~len; | |
1695 | s->pending_buf[s->pending - 1] = ~len >> 8; | |
1696 | ||
1697 | /* Write the stored block header bytes. */ | |
1698 | flush_pending(s->strm); | |
1699 | ||
1700 | #ifdef ZLIB_DEBUG | |
1701 | /* Update debugging counts for the data about to be copied. */ | |
1702 | s->compressed_len += len << 3; | |
1703 | s->bits_sent += len << 3; | |
1704 | #endif | |
1705 | ||
1706 | /* Copy uncompressed bytes from the window to next_out. */ | |
1707 | if (left) { | |
1708 | if (left > len) | |
1709 | left = len; | |
1710 | zmemcpy(s->strm->next_out, s->window + s->block_start, left); | |
1711 | s->strm->next_out += left; | |
1712 | s->strm->avail_out -= left; | |
1713 | s->strm->total_out += left; | |
1714 | s->block_start += left; | |
1715 | len -= left; | |
1716 | } | |
1717 | ||
1718 | /* Copy uncompressed bytes directly from next_in to next_out, updating | |
1719 | * the check value. | |
1720 | */ | |
1721 | if (len) { | |
1722 | read_buf(s->strm, s->strm->next_out, len); | |
1723 | s->strm->next_out += len; | |
1724 | s->strm->avail_out -= len; | |
1725 | s->strm->total_out += len; | |
1726 | } | |
1727 | } while (last == 0); | |
1728 | ||
1729 | /* Update the sliding window with the last s->w_size bytes of the copied | |
1730 | * data, or append all of the copied data to the existing window if less | |
1731 | * than s->w_size bytes were copied. Also update the number of bytes to | |
1732 | * insert in the hash tables, in the event that deflateParams() switches to | |
1733 | * a non-zero compression level. | |
1734 | */ | |
1735 | used -= s->strm->avail_in; /* number of input bytes directly copied */ | |
1736 | if (used) { | |
1737 | /* If any input was used, then no unused input remains in the window, | |
1738 | * therefore s->block_start == s->strstart. | |
1739 | */ | |
1740 | if (used >= s->w_size) { /* supplant the previous history */ | |
1741 | s->matches = 2; /* clear hash */ | |
1742 | zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size); | |
1743 | s->strstart = s->w_size; | |
1744 | } | |
1745 | else { | |
1746 | if (s->window_size - s->strstart <= used) { | |
1747 | /* Slide the window down. */ | |
1748 | s->strstart -= s->w_size; | |
1749 | zmemcpy(s->window, s->window + s->w_size, s->strstart); | |
1750 | if (s->matches < 2) | |
1751 | s->matches++; /* add a pending slide_hash() */ | |
1752 | } | |
1753 | zmemcpy(s->window + s->strstart, s->strm->next_in - used, used); | |
1754 | s->strstart += used; | |
1755 | } | |
1756 | s->block_start = s->strstart; | |
1757 | s->insert += MIN(used, s->w_size - s->insert); | |
1758 | } | |
1759 | if (s->high_water < s->strstart) | |
1760 | s->high_water = s->strstart; | |
1761 | ||
1762 | /* If the last block was written to next_out, then done. */ | |
1763 | if (last) | |
1613 | 1764 | return finish_done; |
1614 | } | |
1615 | if ((long)s->strstart > s->block_start) | |
1616 | FLUSH_BLOCK(s, 0); | |
1617 | return block_done; | |
1765 | ||
1766 | /* If flushing and all input has been consumed, then done. */ | |
1767 | if (flush != Z_NO_FLUSH && flush != Z_FINISH && | |
1768 | s->strm->avail_in == 0 && (long)s->strstart == s->block_start) | |
1769 | return block_done; | |
1770 | ||
1771 | /* Fill the window with any remaining input. */ | |
1772 | have = s->window_size - s->strstart - 1; | |
1773 | if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) { | |
1774 | /* Slide the window down. */ | |
1775 | s->block_start -= s->w_size; | |
1776 | s->strstart -= s->w_size; | |
1777 | zmemcpy(s->window, s->window + s->w_size, s->strstart); | |
1778 | if (s->matches < 2) | |
1779 | s->matches++; /* add a pending slide_hash() */ | |
1780 | have += s->w_size; /* more space now */ | |
1781 | } | |
1782 | if (have > s->strm->avail_in) | |
1783 | have = s->strm->avail_in; | |
1784 | if (have) { | |
1785 | read_buf(s->strm, s->window + s->strstart, have); | |
1786 | s->strstart += have; | |
1787 | } | |
1788 | if (s->high_water < s->strstart) | |
1789 | s->high_water = s->strstart; | |
1790 | ||
1791 | /* There was not enough avail_out to write a complete worthy or flushed | |
1792 | * stored block to next_out. Write a stored block to pending instead, if we | |
1793 | * have enough input for a worthy block, or if flushing and there is enough | |
1794 | * room for the remaining input as a stored block in the pending buffer. | |
1795 | */ | |
1796 | have = (s->bi_valid + 42) >> 3; /* number of header bytes */ | |
1797 | /* maximum stored block length that will fit in pending: */ | |
1798 | have = MIN(s->pending_buf_size - have, MAX_STORED); | |
1799 | min_block = MIN(have, s->w_size); | |
1800 | left = s->strstart - s->block_start; | |
1801 | if (left >= min_block || | |
1802 | ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && | |
1803 | s->strm->avail_in == 0 && left <= have)) { | |
1804 | len = MIN(left, have); | |
1805 | last = flush == Z_FINISH && s->strm->avail_in == 0 && | |
1806 | len == left ? 1 : 0; | |
1807 | _tr_stored_block(s, (charf *)s->window + s->block_start, len, last); | |
1808 | s->block_start += len; | |
1809 | flush_pending(s->strm); | |
1810 | } | |
1811 | ||
1812 | /* We've done all we can with the available input and output. */ | |
1813 | return last ? finish_started : need_more; | |
1618 | 1814 | } |
1619 | 1815 | |
1620 | 1816 | /* =========================================================================== |
1891 | 2087 | prev == *++scan && prev == *++scan && |
1892 | 2088 | prev == *++scan && prev == *++scan && |
1893 | 2089 | scan < strend); |
1894 | s->match_length = MAX_MATCH - (int)(strend - scan); | |
2090 | s->match_length = MAX_MATCH - (uInt)(strend - scan); | |
1895 | 2091 | if (s->match_length > s->lookahead) |
1896 | 2092 | s->match_length = s->lookahead; |
1897 | 2093 | } |
0 | 0 | /* deflate.h -- internal compression state |
1 | * Copyright (C) 1995-2012 Jean-loup Gailly | |
1 | * Copyright (C) 1995-2016 Jean-loup Gailly | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
50 | 50 | #define Buf_size 16 |
51 | 51 | /* size of bit buffer in bi_buf */ |
52 | 52 | |
53 | #define INIT_STATE 42 | |
54 | #define EXTRA_STATE 69 | |
55 | #define NAME_STATE 73 | |
56 | #define COMMENT_STATE 91 | |
57 | #define HCRC_STATE 103 | |
58 | #define BUSY_STATE 113 | |
59 | #define FINISH_STATE 666 | |
53 | #define INIT_STATE 42 /* zlib header -> BUSY_STATE */ | |
54 | #ifdef GZIP | |
55 | # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */ | |
56 | #endif | |
57 | #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */ | |
58 | #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */ | |
59 | #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */ | |
60 | #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */ | |
61 | #define BUSY_STATE 113 /* deflate -> FINISH_STATE */ | |
62 | #define FINISH_STATE 666 /* stream complete */ | |
60 | 63 | /* Stream status */ |
61 | 64 | |
62 | 65 | |
82 | 85 | typedef struct tree_desc_s { |
83 | 86 | ct_data *dyn_tree; /* the dynamic tree */ |
84 | 87 | int max_code; /* largest code with non zero frequency */ |
85 | static_tree_desc *stat_desc; /* the corresponding static tree */ | |
88 | const static_tree_desc *stat_desc; /* the corresponding static tree */ | |
86 | 89 | } FAR tree_desc; |
87 | 90 | |
88 | 91 | typedef ush Pos; |
99 | 102 | Bytef *pending_buf; /* output still pending */ |
100 | 103 | ulg pending_buf_size; /* size of pending_buf */ |
101 | 104 | Bytef *pending_out; /* next pending byte to output to the stream */ |
102 | uInt pending; /* nb of bytes in the pending buffer */ | |
105 | ulg pending; /* nb of bytes in the pending buffer */ | |
103 | 106 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ |
104 | 107 | gz_headerp gzhead; /* gzip header information to write */ |
105 | uInt gzindex; /* where in extra, name, or comment */ | |
108 | ulg gzindex; /* where in extra, name, or comment */ | |
106 | 109 | Byte method; /* can only be DEFLATED */ |
107 | 110 | int last_flush; /* value of flush param for previous deflate call */ |
108 | 111 | |
248 | 251 | uInt matches; /* number of string matches in current block */ |
249 | 252 | uInt insert; /* bytes at end of window left to insert */ |
250 | 253 | |
251 | #ifdef DEBUG | |
254 | #ifdef ZLIB_DEBUG | |
252 | 255 | ulg compressed_len; /* total bit length of compressed file mod 2^32 */ |
253 | 256 | ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ |
254 | 257 | #endif |
274 | 277 | /* Output a byte on the stream. |
275 | 278 | * IN assertion: there is enough room in pending_buf. |
276 | 279 | */ |
277 | #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} | |
280 | #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);} | |
278 | 281 | |
279 | 282 | |
280 | 283 | #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) |
308 | 311 | * used. |
309 | 312 | */ |
310 | 313 | |
311 | #ifndef DEBUG | |
314 | #ifndef ZLIB_DEBUG | |
312 | 315 | /* Inline versions of _tr_tally for speed: */ |
313 | 316 | |
314 | 317 | #if defined(GEN_TREES_H) || !defined(STDC) |
327 | 330 | flush = (s->last_lit == s->lit_bufsize-1); \ |
328 | 331 | } |
329 | 332 | # define _tr_tally_dist(s, distance, length, flush) \ |
330 | { uch len = (length); \ | |
331 | ush dist = (distance); \ | |
333 | { uch len = (uch)(length); \ | |
334 | ush dist = (ush)(distance); \ | |
332 | 335 | s->d_buf[s->last_lit] = dist; \ |
333 | 336 | s->l_buf[s->last_lit++] = len; \ |
334 | 337 | dist--; \ |
0 | 0 | /* gzguts.h -- zlib internal header definitions for gz* operations |
1 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler | |
1 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
24 | 24 | # include <stdlib.h> |
25 | 25 | # include <limits.h> |
26 | 26 | #endif |
27 | ||
28 | #ifndef _POSIX_SOURCE | |
29 | # define _POSIX_SOURCE | |
30 | #endif | |
27 | 31 | #include <fcntl.h> |
28 | 32 | |
29 | 33 | #ifdef _WIN32 |
32 | 36 | |
33 | 37 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) |
34 | 38 | # include <io.h> |
39 | #endif | |
40 | ||
41 | #if defined(_WIN32) || defined(__CYGWIN__) | |
42 | # define WIDECHAR | |
35 | 43 | #endif |
36 | 44 | |
37 | 45 | #ifdef WINAPI_FAMILY |
94 | 102 | # endif |
95 | 103 | #endif |
96 | 104 | |
97 | /* unlike snprintf (which is required in C99, yet still not supported by | |
98 | Microsoft more than a decade later!), _snprintf does not guarantee null | |
99 | termination of the result -- however this is only used in gzlib.c where | |
105 | /* unlike snprintf (which is required in C99), _snprintf does not guarantee | |
106 | null termination of the result -- however this is only used in gzlib.c where | |
100 | 107 | the result is assured to fit in the space provided */ |
101 | #ifdef _MSC_VER | |
108 | #if defined(_MSC_VER) && _MSC_VER < 1900 | |
102 | 109 | # define snprintf _snprintf |
103 | 110 | #endif |
104 | 111 | |
105 | 112 | #ifndef local |
106 | 113 | # define local static |
107 | 114 | #endif |
108 | /* compile with -Dlocal if your debugger can't find static symbols */ | |
115 | /* since "static" is used to mean two completely different things in C, we | |
116 | define "local" for the non-static meaning of "static", for readability | |
117 | (compile with -Dlocal if your debugger can't find static symbols) */ | |
109 | 118 | |
110 | 119 | /* gz* functions always use library allocation functions */ |
111 | 120 | #ifndef STDC |
169 | 178 | char *path; /* path or fd for error messages */ |
170 | 179 | unsigned size; /* buffer size, zero if not allocated yet */ |
171 | 180 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ |
172 | unsigned char *in; /* input buffer */ | |
181 | unsigned char *in; /* input buffer (double-sized when writing) */ | |
173 | 182 | unsigned char *out; /* output buffer (double-sized when reading) */ |
174 | 183 | int direct; /* 0 if processing gzip, 1 if transparent */ |
175 | 184 | /* just for reading */ |
0 | 0 | /* gzlib.c -- zlib functions common to reading and writing gzip files |
1 | * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler | |
1 | * Copyright (C) 2004-2017 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
5 | 5 | #include "gzguts.h" |
6 | 6 | |
7 | #if defined(_WIN32) && !defined(__BORLANDC__) | |
7 | #if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__) | |
8 | 8 | # define LSEEK _lseeki64 |
9 | 9 | #else |
10 | 10 | #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 |
93 | 93 | const char *mode; |
94 | 94 | { |
95 | 95 | gz_statep state; |
96 | size_t len; | |
96 | z_size_t len; | |
97 | 97 | int oflag; |
98 | 98 | #ifdef O_CLOEXEC |
99 | 99 | int cloexec = 0; |
187 | 187 | } |
188 | 188 | |
189 | 189 | /* save the path name for error messages */ |
190 | #ifdef _WIN32 | |
190 | #ifdef WIDECHAR | |
191 | 191 | if (fd == -2) { |
192 | 192 | len = wcstombs(NULL, path, 0); |
193 | if (len == (size_t)-1) | |
193 | if (len == (z_size_t)-1) | |
194 | 194 | len = 0; |
195 | 195 | } |
196 | 196 | else |
201 | 201 | free(state); |
202 | 202 | return NULL; |
203 | 203 | } |
204 | #ifdef _WIN32 | |
204 | #ifdef WIDECHAR | |
205 | 205 | if (fd == -2) |
206 | 206 | if (len) |
207 | 207 | wcstombs(state->path, path, len + 1); |
210 | 210 | else |
211 | 211 | #endif |
212 | 212 | #if !defined(NO_snprintf) && !defined(NO_vsnprintf) |
213 | snprintf(state->path, len + 1, "%s", (const char *)path); | |
213 | (void)snprintf(state->path, len + 1, "%s", (const char *)path); | |
214 | 214 | #else |
215 | 215 | strcpy(state->path, path); |
216 | 216 | #endif |
238 | 238 | |
239 | 239 | /* open the file with the appropriate flags (or just use fd) */ |
240 | 240 | state->fd = fd > -1 ? fd : ( |
241 | #ifdef _WIN32 | |
241 | #ifdef WIDECHAR | |
242 | 242 | fd == -2 ? _wopen(path, oflag, 0666) : |
243 | 243 | #endif |
244 | 244 | open((const char *)path, oflag, 0666)); |
247 | 247 | free(state); |
248 | 248 | return NULL; |
249 | 249 | } |
250 | if (state->mode == GZ_APPEND) | |
250 | if (state->mode == GZ_APPEND) { | |
251 | LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */ | |
251 | 252 | state->mode = GZ_WRITE; /* simplify later checks */ |
253 | } | |
252 | 254 | |
253 | 255 | /* save the current position for rewinding (only if reading) */ |
254 | 256 | if (state->mode == GZ_READ) { |
290 | 292 | if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) |
291 | 293 | return NULL; |
292 | 294 | #if !defined(NO_snprintf) && !defined(NO_vsnprintf) |
293 | snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */ | |
295 | (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); | |
294 | 296 | #else |
295 | 297 | sprintf(path, "<fd:%d>", fd); /* for debugging */ |
296 | 298 | #endif |
300 | 302 | } |
301 | 303 | |
302 | 304 | /* -- see zlib.h -- */ |
303 | #ifdef _WIN32 | |
305 | #ifdef WIDECHAR | |
304 | 306 | gzFile ZEXPORT gzopen_w(path, mode) |
305 | 307 | const wchar_t *path; |
306 | 308 | const char *mode; |
328 | 330 | return -1; |
329 | 331 | |
330 | 332 | /* check and set requested size */ |
333 | if ((size << 1) < size) | |
334 | return -1; /* need to be able to double it */ | |
331 | 335 | if (size < 2) |
332 | 336 | size = 2; /* need two bytes to check magic header */ |
333 | 337 | state->want = size; |
603 | 607 | return; |
604 | 608 | } |
605 | 609 | #if !defined(NO_snprintf) && !defined(NO_vsnprintf) |
606 | snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, | |
607 | "%s%s%s", state->path, ": ", msg); | |
610 | (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, | |
611 | "%s%s%s", state->path, ": ", msg); | |
608 | 612 | #else |
609 | 613 | strcpy(state->msg, state->path); |
610 | 614 | strcat(state->msg, ": "); |
611 | 615 | strcat(state->msg, msg); |
612 | 616 | #endif |
613 | return; | |
614 | 617 | } |
615 | 618 | |
616 | 619 | #ifndef INT_MAX |
0 | 0 | /* gzread.c -- zlib functions for reading gzip files |
1 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler | |
1 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
11 | 11 | local int gz_decomp OF((gz_statep)); |
12 | 12 | local int gz_fetch OF((gz_statep)); |
13 | 13 | local int gz_skip OF((gz_statep, z_off64_t)); |
14 | local z_size_t gz_read OF((gz_statep, voidp, z_size_t)); | |
14 | 15 | |
15 | 16 | /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from |
16 | 17 | state->fd, and update state->eof, state->err, and state->msg as appropriate. |
23 | 24 | unsigned *have; |
24 | 25 | { |
25 | 26 | int ret; |
27 | unsigned get, max = ((unsigned)-1 >> 2) + 1; | |
26 | 28 | |
27 | 29 | *have = 0; |
28 | 30 | do { |
29 | ret = read(state->fd, buf + *have, len - *have); | |
31 | get = len - *have; | |
32 | if (get > max) | |
33 | get = max; | |
34 | ret = read(state->fd, buf + *have, get); | |
30 | 35 | if (ret <= 0) |
31 | 36 | break; |
32 | *have += ret; | |
37 | *have += (unsigned)ret; | |
33 | 38 | } while (*have < len); |
34 | 39 | if (ret < 0) { |
35 | 40 | gz_error(state, Z_ERRNO, zstrerror()); |
93 | 98 | state->in = (unsigned char *)malloc(state->want); |
94 | 99 | state->out = (unsigned char *)malloc(state->want << 1); |
95 | 100 | if (state->in == NULL || state->out == NULL) { |
96 | if (state->out != NULL) | |
97 | free(state->out); | |
98 | if (state->in != NULL) | |
99 | free(state->in); | |
101 | free(state->out); | |
102 | free(state->in); | |
100 | 103 | gz_error(state, Z_MEM_ERROR, "out of memory"); |
101 | 104 | return -1; |
102 | 105 | } |
283 | 286 | return 0; |
284 | 287 | } |
285 | 288 | |
286 | /* -- see zlib.h -- */ | |
287 | int ZEXPORT gzread(file, buf, len) | |
288 | gzFile file; | |
289 | /* Read len bytes into buf from file, or less than len up to the end of the | |
290 | input. Return the number of bytes read. If zero is returned, either the | |
291 | end of file was reached, or there was an error. state->err must be | |
292 | consulted in that case to determine which. */ | |
293 | local z_size_t gz_read(state, buf, len) | |
294 | gz_statep state; | |
289 | 295 | voidp buf; |
290 | unsigned len; | |
291 | { | |
292 | unsigned got, n; | |
293 | gz_statep state; | |
294 | z_streamp strm; | |
295 | ||
296 | /* get internal structure */ | |
297 | if (file == NULL) | |
298 | return -1; | |
299 | state = (gz_statep)file; | |
300 | strm = &(state->strm); | |
301 | ||
302 | /* check that we're reading and that there's no (serious) error */ | |
303 | if (state->mode != GZ_READ || | |
304 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) | |
305 | return -1; | |
306 | ||
307 | /* since an int is returned, make sure len fits in one, otherwise return | |
308 | with an error (this avoids the flaw in the interface) */ | |
309 | if ((int)len < 0) { | |
310 | gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); | |
311 | return -1; | |
312 | } | |
296 | z_size_t len; | |
297 | { | |
298 | z_size_t got; | |
299 | unsigned n; | |
313 | 300 | |
314 | 301 | /* if len is zero, avoid unnecessary operations */ |
315 | 302 | if (len == 0) |
319 | 306 | if (state->seek) { |
320 | 307 | state->seek = 0; |
321 | 308 | if (gz_skip(state, state->skip) == -1) |
322 | return -1; | |
309 | return 0; | |
323 | 310 | } |
324 | 311 | |
325 | 312 | /* get len bytes to buf, or less than len if at the end */ |
326 | 313 | got = 0; |
327 | 314 | do { |
315 | /* set n to the maximum amount of len that fits in an unsigned int */ | |
316 | n = -1; | |
317 | if (n > len) | |
318 | n = len; | |
319 | ||
328 | 320 | /* first just try copying data from the output buffer */ |
329 | 321 | if (state->x.have) { |
330 | n = state->x.have > len ? len : state->x.have; | |
322 | if (state->x.have < n) | |
323 | n = state->x.have; | |
331 | 324 | memcpy(buf, state->x.next, n); |
332 | 325 | state->x.next += n; |
333 | 326 | state->x.have -= n; |
334 | 327 | } |
335 | 328 | |
336 | 329 | /* output buffer empty -- return if we're at the end of the input */ |
337 | else if (state->eof && strm->avail_in == 0) { | |
330 | else if (state->eof && state->strm.avail_in == 0) { | |
338 | 331 | state->past = 1; /* tried to read past end */ |
339 | 332 | break; |
340 | 333 | } |
341 | 334 | |
342 | 335 | /* need output data -- for small len or new stream load up our output |
343 | 336 | buffer */ |
344 | else if (state->how == LOOK || len < (state->size << 1)) { | |
337 | else if (state->how == LOOK || n < (state->size << 1)) { | |
345 | 338 | /* get more output, looking for header if required */ |
346 | 339 | if (gz_fetch(state) == -1) |
347 | return -1; | |
340 | return 0; | |
348 | 341 | continue; /* no progress yet -- go back to copy above */ |
349 | 342 | /* the copy above assures that we will leave with space in the |
350 | 343 | output buffer, allowing at least one gzungetc() to succeed */ |
352 | 345 | |
353 | 346 | /* large len -- read directly into user buffer */ |
354 | 347 | else if (state->how == COPY) { /* read directly */ |
355 | if (gz_load(state, (unsigned char *)buf, len, &n) == -1) | |
356 | return -1; | |
348 | if (gz_load(state, (unsigned char *)buf, n, &n) == -1) | |
349 | return 0; | |
357 | 350 | } |
358 | 351 | |
359 | 352 | /* large len -- decompress directly into user buffer */ |
360 | 353 | else { /* state->how == GZIP */ |
361 | strm->avail_out = len; | |
362 | strm->next_out = (unsigned char *)buf; | |
354 | state->strm.avail_out = n; | |
355 | state->strm.next_out = (unsigned char *)buf; | |
363 | 356 | if (gz_decomp(state) == -1) |
364 | return -1; | |
357 | return 0; | |
365 | 358 | n = state->x.have; |
366 | 359 | state->x.have = 0; |
367 | 360 | } |
373 | 366 | state->x.pos += n; |
374 | 367 | } while (len); |
375 | 368 | |
376 | /* return number of bytes read into user buffer (will fit in int) */ | |
377 | return (int)got; | |
369 | /* return number of bytes read into user buffer */ | |
370 | return got; | |
371 | } | |
372 | ||
373 | /* -- see zlib.h -- */ | |
374 | int ZEXPORT gzread(file, buf, len) | |
375 | gzFile file; | |
376 | voidp buf; | |
377 | unsigned len; | |
378 | { | |
379 | gz_statep state; | |
380 | ||
381 | /* get internal structure */ | |
382 | if (file == NULL) | |
383 | return -1; | |
384 | state = (gz_statep)file; | |
385 | ||
386 | /* check that we're reading and that there's no (serious) error */ | |
387 | if (state->mode != GZ_READ || | |
388 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) | |
389 | return -1; | |
390 | ||
391 | /* since an int is returned, make sure len fits in one, otherwise return | |
392 | with an error (this avoids a flaw in the interface) */ | |
393 | if ((int)len < 0) { | |
394 | gz_error(state, Z_STREAM_ERROR, "request does not fit in an int"); | |
395 | return -1; | |
396 | } | |
397 | ||
398 | /* read len or fewer bytes to buf */ | |
399 | len = gz_read(state, buf, len); | |
400 | ||
401 | /* check for an error */ | |
402 | if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR) | |
403 | return -1; | |
404 | ||
405 | /* return the number of bytes read (this is assured to fit in an int) */ | |
406 | return (int)len; | |
407 | } | |
408 | ||
409 | /* -- see zlib.h -- */ | |
410 | z_size_t ZEXPORT gzfread(buf, size, nitems, file) | |
411 | voidp buf; | |
412 | z_size_t size; | |
413 | z_size_t nitems; | |
414 | gzFile file; | |
415 | { | |
416 | z_size_t len; | |
417 | gz_statep state; | |
418 | ||
419 | /* get internal structure */ | |
420 | if (file == NULL) | |
421 | return 0; | |
422 | state = (gz_statep)file; | |
423 | ||
424 | /* check that we're reading and that there's no (serious) error */ | |
425 | if (state->mode != GZ_READ || | |
426 | (state->err != Z_OK && state->err != Z_BUF_ERROR)) | |
427 | return 0; | |
428 | ||
429 | /* compute bytes to read -- error on overflow */ | |
430 | len = nitems * size; | |
431 | if (size && len / size != nitems) { | |
432 | gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t"); | |
433 | return 0; | |
434 | } | |
435 | ||
436 | /* read len or fewer bytes to buf, return the number of full items read */ | |
437 | return len ? gz_read(state, buf, len) / size : 0; | |
378 | 438 | } |
379 | 439 | |
380 | 440 | /* -- see zlib.h -- */ |
407 | 467 | return *(state->x.next)++; |
408 | 468 | } |
409 | 469 | |
410 | /* nothing there -- try gzread() */ | |
411 | ret = gzread(file, buf, 1); | |
470 | /* nothing there -- try gz_read() */ | |
471 | ret = gz_read(state, buf, 1); | |
412 | 472 | return ret < 1 ? -1 : buf[0]; |
413 | 473 | } |
414 | 474 | |
450 | 510 | if (state->x.have == 0) { |
451 | 511 | state->x.have = 1; |
452 | 512 | state->x.next = state->out + (state->size << 1) - 1; |
453 | state->x.next[0] = c; | |
513 | state->x.next[0] = (unsigned char)c; | |
454 | 514 | state->x.pos--; |
455 | 515 | state->past = 0; |
456 | 516 | return c; |
472 | 532 | } |
473 | 533 | state->x.have++; |
474 | 534 | state->x.next--; |
475 | state->x.next[0] = c; | |
535 | state->x.next[0] = (unsigned char)c; | |
476 | 536 | state->x.pos--; |
477 | 537 | state->past = 0; |
478 | 538 | return c; |
0 | 0 | /* gzwrite.c -- zlib functions for writing gzip files |
1 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler | |
1 | * Copyright (C) 2004-2017 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
8 | 8 | local int gz_init OF((gz_statep)); |
9 | 9 | local int gz_comp OF((gz_statep, int)); |
10 | 10 | local int gz_zero OF((gz_statep, z_off64_t)); |
11 | local z_size_t gz_write OF((gz_statep, voidpc, z_size_t)); | |
11 | 12 | |
12 | 13 | /* Initialize state for writing a gzip file. Mark initialization by setting |
13 | state->size to non-zero. Return -1 on failure or 0 on success. */ | |
14 | state->size to non-zero. Return -1 on a memory allocation failure, or 0 on | |
15 | success. */ | |
14 | 16 | local int gz_init(state) |
15 | 17 | gz_statep state; |
16 | 18 | { |
17 | 19 | int ret; |
18 | 20 | z_streamp strm = &(state->strm); |
19 | 21 | |
20 | /* allocate input buffer */ | |
21 | state->in = (unsigned char *)malloc(state->want); | |
22 | /* allocate input buffer (double size for gzprintf) */ | |
23 | state->in = (unsigned char *)malloc(state->want << 1); | |
22 | 24 | if (state->in == NULL) { |
23 | 25 | gz_error(state, Z_MEM_ERROR, "out of memory"); |
24 | 26 | return -1; |
46 | 48 | gz_error(state, Z_MEM_ERROR, "out of memory"); |
47 | 49 | return -1; |
48 | 50 | } |
51 | strm->next_in = NULL; | |
49 | 52 | } |
50 | 53 | |
51 | 54 | /* mark state as initialized */ |
61 | 64 | } |
62 | 65 | |
63 | 66 | /* Compress whatever is at avail_in and next_in and write to the output file. |
64 | Return -1 if there is an error writing to the output file, otherwise 0. | |
65 | flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, | |
66 | then the deflate() state is reset to start a new gzip stream. If gz->direct | |
67 | is true, then simply write to the output file without compressing, and | |
68 | ignore flush. */ | |
67 | Return -1 if there is an error writing to the output file or if gz_init() | |
68 | fails to allocate memory, otherwise 0. flush is assumed to be a valid | |
69 | deflate() flush value. If flush is Z_FINISH, then the deflate() state is | |
70 | reset to start a new gzip stream. If gz->direct is true, then simply write | |
71 | to the output file without compressing, and ignore flush. */ | |
69 | 72 | local int gz_comp(state, flush) |
70 | 73 | gz_statep state; |
71 | 74 | int flush; |
72 | 75 | { |
73 | int ret, got; | |
74 | unsigned have; | |
76 | int ret, writ; | |
77 | unsigned have, put, max = ((unsigned)-1 >> 2) + 1; | |
75 | 78 | z_streamp strm = &(state->strm); |
76 | 79 | |
77 | 80 | /* allocate memory if this is the first time through */ |
80 | 83 | |
81 | 84 | /* write directly if requested */ |
82 | 85 | if (state->direct) { |
83 | got = write(state->fd, strm->next_in, strm->avail_in); | |
84 | if (got < 0 || (unsigned)got != strm->avail_in) { | |
85 | gz_error(state, Z_ERRNO, zstrerror()); | |
86 | return -1; | |
87 | } | |
88 | strm->avail_in = 0; | |
86 | while (strm->avail_in) { | |
87 | put = strm->avail_in > max ? max : strm->avail_in; | |
88 | writ = write(state->fd, strm->next_in, put); | |
89 | if (writ < 0) { | |
90 | gz_error(state, Z_ERRNO, zstrerror()); | |
91 | return -1; | |
92 | } | |
93 | strm->avail_in -= (unsigned)writ; | |
94 | strm->next_in += writ; | |
95 | } | |
89 | 96 | return 0; |
90 | 97 | } |
91 | 98 | |
96 | 103 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ |
97 | 104 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && |
98 | 105 | (flush != Z_FINISH || ret == Z_STREAM_END))) { |
99 | have = (unsigned)(strm->next_out - state->x.next); | |
100 | if (have && ((got = write(state->fd, state->x.next, have)) < 0 || | |
101 | (unsigned)got != have)) { | |
102 | gz_error(state, Z_ERRNO, zstrerror()); | |
103 | return -1; | |
106 | while (strm->next_out > state->x.next) { | |
107 | put = strm->next_out - state->x.next > (int)max ? max : | |
108 | (unsigned)(strm->next_out - state->x.next); | |
109 | writ = write(state->fd, state->x.next, put); | |
110 | if (writ < 0) { | |
111 | gz_error(state, Z_ERRNO, zstrerror()); | |
112 | return -1; | |
113 | } | |
114 | state->x.next += writ; | |
104 | 115 | } |
105 | 116 | if (strm->avail_out == 0) { |
106 | 117 | strm->avail_out = state->size; |
107 | 118 | strm->next_out = state->out; |
119 | state->x.next = state->out; | |
108 | 120 | } |
109 | state->x.next = strm->next_out; | |
110 | 121 | } |
111 | 122 | |
112 | 123 | /* compress */ |
128 | 139 | return 0; |
129 | 140 | } |
130 | 141 | |
131 | /* Compress len zeros to output. Return -1 on error, 0 on success. */ | |
142 | /* Compress len zeros to output. Return -1 on a write error or memory | |
143 | allocation failure by gz_comp(), or 0 on success. */ | |
132 | 144 | local int gz_zero(state, len) |
133 | 145 | gz_statep state; |
134 | 146 | z_off64_t len; |
160 | 172 | return 0; |
161 | 173 | } |
162 | 174 | |
163 | /* -- see zlib.h -- */ | |
164 | int ZEXPORT gzwrite(file, buf, len) | |
165 | gzFile file; | |
175 | /* Write len bytes from buf to file. Return the number of bytes written. If | |
176 | the returned value is less than len, then there was an error. */ | |
177 | local z_size_t gz_write(state, buf, len) | |
178 | gz_statep state; | |
166 | 179 | voidpc buf; |
167 | unsigned len; | |
168 | { | |
169 | unsigned put = len; | |
170 | gz_statep state; | |
171 | z_streamp strm; | |
172 | ||
173 | /* get internal structure */ | |
174 | if (file == NULL) | |
175 | return 0; | |
176 | state = (gz_statep)file; | |
177 | strm = &(state->strm); | |
178 | ||
179 | /* check that we're writing and that there's no error */ | |
180 | if (state->mode != GZ_WRITE || state->err != Z_OK) | |
181 | return 0; | |
182 | ||
183 | /* since an int is returned, make sure len fits in one, otherwise return | |
184 | with an error (this avoids the flaw in the interface) */ | |
185 | if ((int)len < 0) { | |
186 | gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); | |
187 | return 0; | |
188 | } | |
180 | z_size_t len; | |
181 | { | |
182 | z_size_t put = len; | |
189 | 183 | |
190 | 184 | /* if len is zero, avoid unnecessary operations */ |
191 | 185 | if (len == 0) |
208 | 202 | do { |
209 | 203 | unsigned have, copy; |
210 | 204 | |
211 | if (strm->avail_in == 0) | |
212 | strm->next_in = state->in; | |
213 | have = (unsigned)((strm->next_in + strm->avail_in) - state->in); | |
205 | if (state->strm.avail_in == 0) | |
206 | state->strm.next_in = state->in; | |
207 | have = (unsigned)((state->strm.next_in + state->strm.avail_in) - | |
208 | state->in); | |
214 | 209 | copy = state->size - have; |
215 | 210 | if (copy > len) |
216 | 211 | copy = len; |
217 | 212 | memcpy(state->in + have, buf, copy); |
218 | strm->avail_in += copy; | |
213 | state->strm.avail_in += copy; | |
219 | 214 | state->x.pos += copy; |
220 | 215 | buf = (const char *)buf + copy; |
221 | 216 | len -= copy; |
225 | 220 | } |
226 | 221 | else { |
227 | 222 | /* consume whatever's left in the input buffer */ |
228 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | |
223 | if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | |
229 | 224 | return 0; |
230 | 225 | |
231 | 226 | /* directly compress user buffer to file */ |
232 | strm->avail_in = len; | |
233 | strm->next_in = (z_const Bytef *)buf; | |
234 | state->x.pos += len; | |
235 | if (gz_comp(state, Z_NO_FLUSH) == -1) | |
236 | return 0; | |
237 | } | |
238 | ||
239 | /* input was all buffered or compressed (put will fit in int) */ | |
240 | return (int)put; | |
227 | state->strm.next_in = (z_const Bytef *)buf; | |
228 | do { | |
229 | unsigned n = (unsigned)-1; | |
230 | if (n > len) | |
231 | n = len; | |
232 | state->strm.avail_in = n; | |
233 | state->x.pos += n; | |
234 | if (gz_comp(state, Z_NO_FLUSH) == -1) | |
235 | return 0; | |
236 | len -= n; | |
237 | } while (len); | |
238 | } | |
239 | ||
240 | /* input was all buffered or compressed */ | |
241 | return put; | |
242 | } | |
243 | ||
244 | /* -- see zlib.h -- */ | |
245 | int ZEXPORT gzwrite(file, buf, len) | |
246 | gzFile file; | |
247 | voidpc buf; | |
248 | unsigned len; | |
249 | { | |
250 | gz_statep state; | |
251 | ||
252 | /* get internal structure */ | |
253 | if (file == NULL) | |
254 | return 0; | |
255 | state = (gz_statep)file; | |
256 | ||
257 | /* check that we're writing and that there's no error */ | |
258 | if (state->mode != GZ_WRITE || state->err != Z_OK) | |
259 | return 0; | |
260 | ||
261 | /* since an int is returned, make sure len fits in one, otherwise return | |
262 | with an error (this avoids a flaw in the interface) */ | |
263 | if ((int)len < 0) { | |
264 | gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); | |
265 | return 0; | |
266 | } | |
267 | ||
268 | /* write len bytes from buf (the return value will fit in an int) */ | |
269 | return (int)gz_write(state, buf, len); | |
270 | } | |
271 | ||
272 | /* -- see zlib.h -- */ | |
273 | z_size_t ZEXPORT gzfwrite(buf, size, nitems, file) | |
274 | voidpc buf; | |
275 | z_size_t size; | |
276 | z_size_t nitems; | |
277 | gzFile file; | |
278 | { | |
279 | z_size_t len; | |
280 | gz_statep state; | |
281 | ||
282 | /* get internal structure */ | |
283 | if (file == NULL) | |
284 | return 0; | |
285 | state = (gz_statep)file; | |
286 | ||
287 | /* check that we're writing and that there's no error */ | |
288 | if (state->mode != GZ_WRITE || state->err != Z_OK) | |
289 | return 0; | |
290 | ||
291 | /* compute bytes to read -- error on overflow */ | |
292 | len = nitems * size; | |
293 | if (size && len / size != nitems) { | |
294 | gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t"); | |
295 | return 0; | |
296 | } | |
297 | ||
298 | /* write len bytes to buf, return the number of full items written */ | |
299 | return len ? gz_write(state, buf, len) / size : 0; | |
241 | 300 | } |
242 | 301 | |
243 | 302 | /* -- see zlib.h -- */ |
274 | 333 | strm->next_in = state->in; |
275 | 334 | have = (unsigned)((strm->next_in + strm->avail_in) - state->in); |
276 | 335 | if (have < state->size) { |
277 | state->in[have] = c; | |
336 | state->in[have] = (unsigned char)c; | |
278 | 337 | strm->avail_in++; |
279 | 338 | state->x.pos++; |
280 | 339 | return c & 0xff; |
282 | 341 | } |
283 | 342 | |
284 | 343 | /* no room in buffer or not initialized, use gz_write() */ |
285 | buf[0] = c; | |
286 | if (gzwrite(file, buf, 1) != 1) | |
344 | buf[0] = (unsigned char)c; | |
345 | if (gz_write(state, buf, 1) != 1) | |
287 | 346 | return -1; |
288 | 347 | return c & 0xff; |
289 | 348 | } |
294 | 353 | const char *str; |
295 | 354 | { |
296 | 355 | int ret; |
297 | unsigned len; | |
356 | z_size_t len; | |
357 | gz_statep state; | |
358 | ||
359 | /* get internal structure */ | |
360 | if (file == NULL) | |
361 | return -1; | |
362 | state = (gz_statep)file; | |
363 | ||
364 | /* check that we're writing and that there's no error */ | |
365 | if (state->mode != GZ_WRITE || state->err != Z_OK) | |
366 | return -1; | |
298 | 367 | |
299 | 368 | /* write string */ |
300 | len = (unsigned)strlen(str); | |
301 | ret = gzwrite(file, str, len); | |
369 | len = strlen(str); | |
370 | ret = gz_write(state, str, len); | |
302 | 371 | return ret == 0 && len != 0 ? -1 : ret; |
303 | 372 | } |
304 | 373 | |
308 | 377 | /* -- see zlib.h -- */ |
309 | 378 | int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) |
310 | 379 | { |
311 | int size, len; | |
380 | int len; | |
381 | unsigned left; | |
382 | char *next; | |
312 | 383 | gz_statep state; |
313 | 384 | z_streamp strm; |
314 | 385 | |
315 | 386 | /* get internal structure */ |
316 | 387 | if (file == NULL) |
317 | return -1; | |
388 | return Z_STREAM_ERROR; | |
318 | 389 | state = (gz_statep)file; |
319 | 390 | strm = &(state->strm); |
320 | 391 | |
321 | 392 | /* check that we're writing and that there's no error */ |
322 | 393 | if (state->mode != GZ_WRITE || state->err != Z_OK) |
323 | return 0; | |
394 | return Z_STREAM_ERROR; | |
324 | 395 | |
325 | 396 | /* make sure we have some buffer space */ |
326 | 397 | if (state->size == 0 && gz_init(state) == -1) |
327 | return 0; | |
398 | return state->err; | |
328 | 399 | |
329 | 400 | /* check for seek request */ |
330 | 401 | if (state->seek) { |
331 | 402 | state->seek = 0; |
332 | 403 | if (gz_zero(state, state->skip) == -1) |
333 | return 0; | |
334 | } | |
335 | ||
336 | /* consume whatever's left in the input buffer */ | |
337 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | |
338 | return 0; | |
339 | ||
340 | /* do the printf() into the input buffer, put length in len */ | |
341 | size = (int)(state->size); | |
342 | state->in[size - 1] = 0; | |
404 | return state->err; | |
405 | } | |
406 | ||
407 | /* do the printf() into the input buffer, put length in len -- the input | |
408 | buffer is double-sized just for this function, so there is guaranteed to | |
409 | be state->size bytes available after the current contents */ | |
410 | if (strm->avail_in == 0) | |
411 | strm->next_in = state->in; | |
412 | next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in); | |
413 | next[state->size - 1] = 0; | |
343 | 414 | #ifdef NO_vsnprintf |
344 | 415 | # ifdef HAS_vsprintf_void |
345 | (void)vsprintf((char *)(state->in), format, va); | |
346 | for (len = 0; len < size; len++) | |
347 | if (state->in[len] == 0) break; | |
416 | (void)vsprintf(next, format, va); | |
417 | for (len = 0; len < state->size; len++) | |
418 | if (next[len] == 0) break; | |
348 | 419 | # else |
349 | len = vsprintf((char *)(state->in), format, va); | |
420 | len = vsprintf(next, format, va); | |
350 | 421 | # endif |
351 | 422 | #else |
352 | 423 | # ifdef HAS_vsnprintf_void |
353 | (void)vsnprintf((char *)(state->in), size, format, va); | |
354 | len = strlen((char *)(state->in)); | |
424 | (void)vsnprintf(next, state->size, format, va); | |
425 | len = strlen(next); | |
355 | 426 | # else |
356 | len = vsnprintf((char *)(state->in), size, format, va); | |
427 | len = vsnprintf(next, state->size, format, va); | |
357 | 428 | # endif |
358 | 429 | #endif |
359 | 430 | |
360 | 431 | /* check that printf() results fit in buffer */ |
361 | if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) | |
362 | return 0; | |
363 | ||
364 | /* update buffer and position, defer compression until needed */ | |
365 | strm->avail_in = (unsigned)len; | |
366 | strm->next_in = state->in; | |
432 | if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0) | |
433 | return 0; | |
434 | ||
435 | /* update buffer and position, compress first half if past that */ | |
436 | strm->avail_in += (unsigned)len; | |
367 | 437 | state->x.pos += len; |
438 | if (strm->avail_in >= state->size) { | |
439 | left = strm->avail_in - state->size; | |
440 | strm->avail_in = state->size; | |
441 | if (gz_comp(state, Z_NO_FLUSH) == -1) | |
442 | return state->err; | |
443 | memcpy(state->in, state->in + state->size, left); | |
444 | strm->next_in = state->in; | |
445 | strm->avail_in = left; | |
446 | } | |
368 | 447 | return len; |
369 | 448 | } |
370 | 449 | |
389 | 468 | int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, |
390 | 469 | a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; |
391 | 470 | { |
392 | int size, len; | |
471 | unsigned len, left; | |
472 | char *next; | |
393 | 473 | gz_statep state; |
394 | 474 | z_streamp strm; |
395 | 475 | |
396 | 476 | /* get internal structure */ |
397 | 477 | if (file == NULL) |
398 | return -1; | |
478 | return Z_STREAM_ERROR; | |
399 | 479 | state = (gz_statep)file; |
400 | 480 | strm = &(state->strm); |
401 | 481 | |
402 | 482 | /* check that can really pass pointer in ints */ |
403 | 483 | if (sizeof(int) != sizeof(void *)) |
404 | return 0; | |
405 | ||
406 | /* check that we're writing and that there's no error */ | |
407 | if (state->mode != GZ_WRITE || state->err != Z_OK) | |
408 | return 0; | |
484 | return Z_STREAM_ERROR; | |
485 | ||
486 | /* check that we're writing and that there's no error */ | |
487 | if (state->mode != GZ_WRITE || state->err != Z_OK) | |
488 | return Z_STREAM_ERROR; | |
409 | 489 | |
410 | 490 | /* make sure we have some buffer space */ |
411 | 491 | if (state->size == 0 && gz_init(state) == -1) |
412 | return 0; | |
492 | return state->error; | |
413 | 493 | |
414 | 494 | /* check for seek request */ |
415 | 495 | if (state->seek) { |
416 | 496 | state->seek = 0; |
417 | 497 | if (gz_zero(state, state->skip) == -1) |
418 | return 0; | |
419 | } | |
420 | ||
421 | /* consume whatever's left in the input buffer */ | |
422 | if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) | |
423 | return 0; | |
424 | ||
425 | /* do the printf() into the input buffer, put length in len */ | |
426 | size = (int)(state->size); | |
427 | state->in[size - 1] = 0; | |
498 | return state->error; | |
499 | } | |
500 | ||
501 | /* do the printf() into the input buffer, put length in len -- the input | |
502 | buffer is double-sized just for this function, so there is guaranteed to | |
503 | be state->size bytes available after the current contents */ | |
504 | if (strm->avail_in == 0) | |
505 | strm->next_in = state->in; | |
506 | next = (char *)(strm->next_in + strm->avail_in); | |
507 | next[state->size - 1] = 0; | |
428 | 508 | #ifdef NO_snprintf |
429 | 509 | # ifdef HAS_sprintf_void |
430 | sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, | |
431 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | |
510 | sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, | |
511 | a13, a14, a15, a16, a17, a18, a19, a20); | |
432 | 512 | for (len = 0; len < size; len++) |
433 | if (state->in[len] == 0) break; | |
513 | if (next[len] == 0) | |
514 | break; | |
434 | 515 | # else |
435 | len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, | |
436 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | |
516 | len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, | |
517 | a12, a13, a14, a15, a16, a17, a18, a19, a20); | |
437 | 518 | # endif |
438 | 519 | #else |
439 | 520 | # ifdef HAS_snprintf_void |
440 | snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8, | |
441 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | |
442 | len = strlen((char *)(state->in)); | |
521 | snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, | |
522 | a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | |
523 | len = strlen(next); | |
443 | 524 | # else |
444 | len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, | |
445 | a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, | |
446 | a19, a20); | |
525 | len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, | |
526 | a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); | |
447 | 527 | # endif |
448 | 528 | #endif |
449 | 529 | |
450 | 530 | /* check that printf() results fit in buffer */ |
451 | if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) | |
452 | return 0; | |
453 | ||
454 | /* update buffer and position, defer compression until needed */ | |
455 | strm->avail_in = (unsigned)len; | |
456 | strm->next_in = state->in; | |
531 | if (len == 0 || len >= state->size || next[state->size - 1] != 0) | |
532 | return 0; | |
533 | ||
534 | /* update buffer and position, compress first half if past that */ | |
535 | strm->avail_in += len; | |
457 | 536 | state->x.pos += len; |
458 | return len; | |
537 | if (strm->avail_in >= state->size) { | |
538 | left = strm->avail_in - state->size; | |
539 | strm->avail_in = state->size; | |
540 | if (gz_comp(state, Z_NO_FLUSH) == -1) | |
541 | return state->err; | |
542 | memcpy(state->in, state->in + state->size, left); | |
543 | strm->next_in = state->in; | |
544 | strm->avail_in = left; | |
545 | } | |
546 | return (int)len; | |
459 | 547 | } |
460 | 548 | |
461 | 549 | #endif |
469 | 557 | |
470 | 558 | /* get internal structure */ |
471 | 559 | if (file == NULL) |
472 | return -1; | |
560 | return Z_STREAM_ERROR; | |
473 | 561 | state = (gz_statep)file; |
474 | 562 | |
475 | 563 | /* check that we're writing and that there's no error */ |
484 | 572 | if (state->seek) { |
485 | 573 | state->seek = 0; |
486 | 574 | if (gz_zero(state, state->skip) == -1) |
487 | return -1; | |
575 | return state->err; | |
488 | 576 | } |
489 | 577 | |
490 | 578 | /* compress remaining data with requested flush */ |
491 | gz_comp(state, flush); | |
579 | (void)gz_comp(state, flush); | |
492 | 580 | return state->err; |
493 | 581 | } |
494 | 582 | |
519 | 607 | if (state->seek) { |
520 | 608 | state->seek = 0; |
521 | 609 | if (gz_zero(state, state->skip) == -1) |
522 | return -1; | |
610 | return state->err; | |
523 | 611 | } |
524 | 612 | |
525 | 613 | /* change compression parameters for subsequent input */ |
526 | 614 | if (state->size) { |
527 | 615 | /* flush previous input with previous parameters before changing */ |
528 | if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) | |
616 | if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1) | |
529 | 617 | return state->err; |
530 | 618 | deflateParams(strm, level, strategy); |
531 | 619 | } |
0 | 0 | /* infback.c -- inflate using a call-back interface |
1 | * Copyright (C) 1995-2011 Mark Adler | |
1 | * Copyright (C) 1995-2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
60 | 60 | Tracev((stderr, "inflate: allocated\n")); |
61 | 61 | strm->state = (struct internal_state FAR *)state; |
62 | 62 | state->dmax = 32768U; |
63 | state->wbits = windowBits; | |
63 | state->wbits = (uInt)windowBits; | |
64 | 64 | state->wsize = 1U << windowBits; |
65 | 65 | state->window = window; |
66 | 66 | state->wnext = 0; |
0 | 0 | /* inffast.c -- fast decoding |
1 | * Copyright (C) 1995-2008, 2010, 2013 Mark Adler | |
1 | * Copyright (C) 1995-2017 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
7 | 7 | #include "inflate.h" |
8 | 8 | #include "inffast.h" |
9 | 9 | |
10 | #ifndef ASMINF | |
11 | ||
12 | /* Allow machine dependent optimization for post-increment or pre-increment. | |
13 | Based on testing to date, | |
14 | Pre-increment preferred for: | |
15 | - PowerPC G3 (Adler) | |
16 | - MIPS R5000 (Randers-Pehrson) | |
17 | Post-increment preferred for: | |
18 | - none | |
19 | No measurable difference: | |
20 | - Pentium III (Anderson) | |
21 | - M68060 (Nikl) | |
22 | */ | |
23 | #ifdef POSTINC | |
24 | # define OFF 0 | |
25 | # define PUP(a) *(a)++ | |
10 | #ifdef ASMINF | |
11 | # pragma message("Assembler code may have bugs -- use at your own risk") | |
26 | 12 | #else |
27 | # define OFF 1 | |
28 | # define PUP(a) *++(a) | |
29 | #endif | |
30 | 13 | |
31 | 14 | /* |
32 | 15 | Decode literal, length, and distance codes and write out the resulting |
95 | 78 | |
96 | 79 | /* copy state to local variables */ |
97 | 80 | state = (struct inflate_state FAR *)strm->state; |
98 | in = strm->next_in - OFF; | |
81 | in = strm->next_in; | |
99 | 82 | last = in + (strm->avail_in - 5); |
100 | out = strm->next_out - OFF; | |
83 | out = strm->next_out; | |
101 | 84 | beg = out - (start - strm->avail_out); |
102 | 85 | end = out + (strm->avail_out - 257); |
103 | 86 | #ifdef INFLATE_STRICT |
118 | 101 | input data or output space */ |
119 | 102 | do { |
120 | 103 | if (bits < 15) { |
121 | hold += (unsigned long)(PUP(in)) << bits; | |
104 | hold += (unsigned long)(*in++) << bits; | |
122 | 105 | bits += 8; |
123 | hold += (unsigned long)(PUP(in)) << bits; | |
106 | hold += (unsigned long)(*in++) << bits; | |
124 | 107 | bits += 8; |
125 | 108 | } |
126 | 109 | here = lcode[hold & lmask]; |
133 | 116 | Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? |
134 | 117 | "inflate: literal '%c'\n" : |
135 | 118 | "inflate: literal 0x%02x\n", here.val)); |
136 | PUP(out) = (unsigned char)(here.val); | |
119 | *out++ = (unsigned char)(here.val); | |
137 | 120 | } |
138 | 121 | else if (op & 16) { /* length base */ |
139 | 122 | len = (unsigned)(here.val); |
140 | 123 | op &= 15; /* number of extra bits */ |
141 | 124 | if (op) { |
142 | 125 | if (bits < op) { |
143 | hold += (unsigned long)(PUP(in)) << bits; | |
126 | hold += (unsigned long)(*in++) << bits; | |
144 | 127 | bits += 8; |
145 | 128 | } |
146 | 129 | len += (unsigned)hold & ((1U << op) - 1); |
149 | 132 | } |
150 | 133 | Tracevv((stderr, "inflate: length %u\n", len)); |
151 | 134 | if (bits < 15) { |
152 | hold += (unsigned long)(PUP(in)) << bits; | |
135 | hold += (unsigned long)(*in++) << bits; | |
153 | 136 | bits += 8; |
154 | hold += (unsigned long)(PUP(in)) << bits; | |
137 | hold += (unsigned long)(*in++) << bits; | |
155 | 138 | bits += 8; |
156 | 139 | } |
157 | 140 | here = dcode[hold & dmask]; |
164 | 147 | dist = (unsigned)(here.val); |
165 | 148 | op &= 15; /* number of extra bits */ |
166 | 149 | if (bits < op) { |
167 | hold += (unsigned long)(PUP(in)) << bits; | |
150 | hold += (unsigned long)(*in++) << bits; | |
168 | 151 | bits += 8; |
169 | 152 | if (bits < op) { |
170 | hold += (unsigned long)(PUP(in)) << bits; | |
153 | hold += (unsigned long)(*in++) << bits; | |
171 | 154 | bits += 8; |
172 | 155 | } |
173 | 156 | } |
195 | 178 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR |
196 | 179 | if (len <= op - whave) { |
197 | 180 | do { |
198 | PUP(out) = 0; | |
181 | *out++ = 0; | |
199 | 182 | } while (--len); |
200 | 183 | continue; |
201 | 184 | } |
202 | 185 | len -= op - whave; |
203 | 186 | do { |
204 | PUP(out) = 0; | |
187 | *out++ = 0; | |
205 | 188 | } while (--op > whave); |
206 | 189 | if (op == 0) { |
207 | 190 | from = out - dist; |
208 | 191 | do { |
209 | PUP(out) = PUP(from); | |
192 | *out++ = *from++; | |
210 | 193 | } while (--len); |
211 | 194 | continue; |
212 | 195 | } |
213 | 196 | #endif |
214 | 197 | } |
215 | from = window - OFF; | |
198 | from = window; | |
216 | 199 | if (wnext == 0) { /* very common case */ |
217 | 200 | from += wsize - op; |
218 | 201 | if (op < len) { /* some from window */ |
219 | 202 | len -= op; |
220 | 203 | do { |
221 | PUP(out) = PUP(from); | |
204 | *out++ = *from++; | |
222 | 205 | } while (--op); |
223 | 206 | from = out - dist; /* rest from output */ |
224 | 207 | } |
229 | 212 | if (op < len) { /* some from end of window */ |
230 | 213 | len -= op; |
231 | 214 | do { |
232 | PUP(out) = PUP(from); | |
215 | *out++ = *from++; | |
233 | 216 | } while (--op); |
234 | from = window - OFF; | |
217 | from = window; | |
235 | 218 | if (wnext < len) { /* some from start of window */ |
236 | 219 | op = wnext; |
237 | 220 | len -= op; |
238 | 221 | do { |
239 | PUP(out) = PUP(from); | |
222 | *out++ = *from++; | |
240 | 223 | } while (--op); |
241 | 224 | from = out - dist; /* rest from output */ |
242 | 225 | } |
247 | 230 | if (op < len) { /* some from window */ |
248 | 231 | len -= op; |
249 | 232 | do { |
250 | PUP(out) = PUP(from); | |
233 | *out++ = *from++; | |
251 | 234 | } while (--op); |
252 | 235 | from = out - dist; /* rest from output */ |
253 | 236 | } |
254 | 237 | } |
255 | 238 | while (len > 2) { |
256 | PUP(out) = PUP(from); | |
257 | PUP(out) = PUP(from); | |
258 | PUP(out) = PUP(from); | |
239 | *out++ = *from++; | |
240 | *out++ = *from++; | |
241 | *out++ = *from++; | |
259 | 242 | len -= 3; |
260 | 243 | } |
261 | 244 | if (len) { |
262 | PUP(out) = PUP(from); | |
245 | *out++ = *from++; | |
263 | 246 | if (len > 1) |
264 | PUP(out) = PUP(from); | |
247 | *out++ = *from++; | |
265 | 248 | } |
266 | 249 | } |
267 | 250 | else { |
268 | 251 | from = out - dist; /* copy direct from output */ |
269 | 252 | do { /* minimum length is three */ |
270 | PUP(out) = PUP(from); | |
271 | PUP(out) = PUP(from); | |
272 | PUP(out) = PUP(from); | |
253 | *out++ = *from++; | |
254 | *out++ = *from++; | |
255 | *out++ = *from++; | |
273 | 256 | len -= 3; |
274 | 257 | } while (len > 2); |
275 | 258 | if (len) { |
276 | PUP(out) = PUP(from); | |
259 | *out++ = *from++; | |
277 | 260 | if (len > 1) |
278 | PUP(out) = PUP(from); | |
261 | *out++ = *from++; | |
279 | 262 | } |
280 | 263 | } |
281 | 264 | } |
312 | 295 | hold &= (1U << bits) - 1; |
313 | 296 | |
314 | 297 | /* update state and return */ |
315 | strm->next_in = in + OFF; | |
316 | strm->next_out = out + OFF; | |
298 | strm->next_in = in; | |
299 | strm->next_out = out; | |
317 | 300 | strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); |
318 | 301 | strm->avail_out = (unsigned)(out < end ? |
319 | 302 | 257 + (end - out) : 257 - (out - end)); |
0 | 0 | /* inflate.c -- zlib decompression |
1 | * Copyright (C) 1995-2012 Mark Adler | |
1 | * Copyright (C) 1995-2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
91 | 91 | #endif |
92 | 92 | |
93 | 93 | /* function prototypes */ |
94 | local int inflateStateCheck OF((z_streamp strm)); | |
94 | 95 | local void fixedtables OF((struct inflate_state FAR *state)); |
95 | 96 | local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, |
96 | 97 | unsigned copy)); |
100 | 101 | local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, |
101 | 102 | unsigned len)); |
102 | 103 | |
104 | local int inflateStateCheck(strm) | |
105 | z_streamp strm; | |
106 | { | |
107 | struct inflate_state FAR *state; | |
108 | if (strm == Z_NULL || | |
109 | strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) | |
110 | return 1; | |
111 | state = (struct inflate_state FAR *)strm->state; | |
112 | if (state == Z_NULL || state->strm != strm || | |
113 | state->mode < HEAD || state->mode > SYNC) | |
114 | return 1; | |
115 | return 0; | |
116 | } | |
117 | ||
103 | 118 | int ZEXPORT inflateResetKeep(strm) |
104 | 119 | z_streamp strm; |
105 | 120 | { |
106 | 121 | struct inflate_state FAR *state; |
107 | 122 | |
108 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
123 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
109 | 124 | state = (struct inflate_state FAR *)strm->state; |
110 | 125 | strm->total_in = strm->total_out = state->total = 0; |
111 | 126 | strm->msg = Z_NULL; |
130 | 145 | { |
131 | 146 | struct inflate_state FAR *state; |
132 | 147 | |
133 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
148 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
134 | 149 | state = (struct inflate_state FAR *)strm->state; |
135 | 150 | state->wsize = 0; |
136 | 151 | state->whave = 0; |
146 | 161 | struct inflate_state FAR *state; |
147 | 162 | |
148 | 163 | /* get the state */ |
149 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
164 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
150 | 165 | state = (struct inflate_state FAR *)strm->state; |
151 | 166 | |
152 | 167 | /* extract wrap request from windowBits parameter */ |
155 | 170 | windowBits = -windowBits; |
156 | 171 | } |
157 | 172 | else { |
158 | wrap = (windowBits >> 4) + 1; | |
173 | wrap = (windowBits >> 4) + 5; | |
159 | 174 | #ifdef GUNZIP |
160 | 175 | if (windowBits < 48) |
161 | 176 | windowBits &= 15; |
209 | 224 | if (state == Z_NULL) return Z_MEM_ERROR; |
210 | 225 | Tracev((stderr, "inflate: allocated\n")); |
211 | 226 | strm->state = (struct internal_state FAR *)state; |
227 | state->strm = strm; | |
212 | 228 | state->window = Z_NULL; |
229 | state->mode = HEAD; /* to pass state test in inflateReset2() */ | |
213 | 230 | ret = inflateReset2(strm, windowBits); |
214 | 231 | if (ret != Z_OK) { |
215 | 232 | ZFREE(strm, state); |
233 | 250 | { |
234 | 251 | struct inflate_state FAR *state; |
235 | 252 | |
236 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
253 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
237 | 254 | state = (struct inflate_state FAR *)strm->state; |
238 | 255 | if (bits < 0) { |
239 | 256 | state->hold = 0; |
240 | 257 | state->bits = 0; |
241 | 258 | return Z_OK; |
242 | 259 | } |
243 | if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; | |
260 | if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR; | |
244 | 261 | value &= (1L << bits) - 1; |
245 | state->hold += value << state->bits; | |
246 | state->bits += bits; | |
262 | state->hold += (unsigned)value << state->bits; | |
263 | state->bits += (uInt)bits; | |
247 | 264 | return Z_OK; |
248 | 265 | } |
249 | 266 | |
624 | 641 | static const unsigned short order[19] = /* permutation of code lengths */ |
625 | 642 | {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; |
626 | 643 | |
627 | if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || | |
644 | if (inflateStateCheck(strm) || strm->next_out == Z_NULL || | |
628 | 645 | (strm->next_in == Z_NULL && strm->avail_in != 0)) |
629 | 646 | return Z_STREAM_ERROR; |
630 | 647 | |
644 | 661 | NEEDBITS(16); |
645 | 662 | #ifdef GUNZIP |
646 | 663 | if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ |
664 | if (state->wbits == 0) | |
665 | state->wbits = 15; | |
647 | 666 | state->check = crc32(0L, Z_NULL, 0); |
648 | 667 | CRC2(state->check, hold); |
649 | 668 | INITBITS(); |
671 | 690 | len = BITS(4) + 8; |
672 | 691 | if (state->wbits == 0) |
673 | 692 | state->wbits = len; |
674 | else if (len > state->wbits) { | |
693 | if (len > 15 || len > state->wbits) { | |
675 | 694 | strm->msg = (char *)"invalid window size"; |
676 | 695 | state->mode = BAD; |
677 | 696 | break; |
698 | 717 | } |
699 | 718 | if (state->head != Z_NULL) |
700 | 719 | state->head->text = (int)((hold >> 8) & 1); |
701 | if (state->flags & 0x0200) CRC2(state->check, hold); | |
720 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
721 | CRC2(state->check, hold); | |
702 | 722 | INITBITS(); |
703 | 723 | state->mode = TIME; |
704 | 724 | case TIME: |
705 | 725 | NEEDBITS(32); |
706 | 726 | if (state->head != Z_NULL) |
707 | 727 | state->head->time = hold; |
708 | if (state->flags & 0x0200) CRC4(state->check, hold); | |
728 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
729 | CRC4(state->check, hold); | |
709 | 730 | INITBITS(); |
710 | 731 | state->mode = OS; |
711 | 732 | case OS: |
714 | 735 | state->head->xflags = (int)(hold & 0xff); |
715 | 736 | state->head->os = (int)(hold >> 8); |
716 | 737 | } |
717 | if (state->flags & 0x0200) CRC2(state->check, hold); | |
738 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
739 | CRC2(state->check, hold); | |
718 | 740 | INITBITS(); |
719 | 741 | state->mode = EXLEN; |
720 | 742 | case EXLEN: |
723 | 745 | state->length = (unsigned)(hold); |
724 | 746 | if (state->head != Z_NULL) |
725 | 747 | state->head->extra_len = (unsigned)hold; |
726 | if (state->flags & 0x0200) CRC2(state->check, hold); | |
748 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
749 | CRC2(state->check, hold); | |
727 | 750 | INITBITS(); |
728 | 751 | } |
729 | 752 | else if (state->head != Z_NULL) |
741 | 764 | len + copy > state->head->extra_max ? |
742 | 765 | state->head->extra_max - len : copy); |
743 | 766 | } |
744 | if (state->flags & 0x0200) | |
767 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
745 | 768 | state->check = crc32(state->check, next, copy); |
746 | 769 | have -= copy; |
747 | 770 | next += copy; |
760 | 783 | if (state->head != Z_NULL && |
761 | 784 | state->head->name != Z_NULL && |
762 | 785 | state->length < state->head->name_max) |
763 | state->head->name[state->length++] = len; | |
786 | state->head->name[state->length++] = (Bytef)len; | |
764 | 787 | } while (len && copy < have); |
765 | if (state->flags & 0x0200) | |
788 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
766 | 789 | state->check = crc32(state->check, next, copy); |
767 | 790 | have -= copy; |
768 | 791 | next += copy; |
781 | 804 | if (state->head != Z_NULL && |
782 | 805 | state->head->comment != Z_NULL && |
783 | 806 | state->length < state->head->comm_max) |
784 | state->head->comment[state->length++] = len; | |
807 | state->head->comment[state->length++] = (Bytef)len; | |
785 | 808 | } while (len && copy < have); |
786 | if (state->flags & 0x0200) | |
809 | if ((state->flags & 0x0200) && (state->wrap & 4)) | |
787 | 810 | state->check = crc32(state->check, next, copy); |
788 | 811 | have -= copy; |
789 | 812 | next += copy; |
795 | 818 | case HCRC: |
796 | 819 | if (state->flags & 0x0200) { |
797 | 820 | NEEDBITS(16); |
798 | if (hold != (state->check & 0xffff)) { | |
821 | if ((state->wrap & 4) && hold != (state->check & 0xffff)) { | |
799 | 822 | strm->msg = (char *)"header crc mismatch"; |
800 | 823 | state->mode = BAD; |
801 | 824 | break; |
1176 | 1199 | out -= left; |
1177 | 1200 | strm->total_out += out; |
1178 | 1201 | state->total += out; |
1179 | if (out) | |
1202 | if ((state->wrap & 4) && out) | |
1180 | 1203 | strm->adler = state->check = |
1181 | 1204 | UPDATE(state->check, put - out, out); |
1182 | 1205 | out = left; |
1183 | if (( | |
1206 | if ((state->wrap & 4) && ( | |
1184 | 1207 | #ifdef GUNZIP |
1185 | 1208 | state->flags ? hold : |
1186 | 1209 | #endif |
1239 | 1262 | strm->total_in += in; |
1240 | 1263 | strm->total_out += out; |
1241 | 1264 | state->total += out; |
1242 | if (state->wrap && out) | |
1265 | if ((state->wrap & 4) && out) | |
1243 | 1266 | strm->adler = state->check = |
1244 | 1267 | UPDATE(state->check, strm->next_out - out, out); |
1245 | strm->data_type = state->bits + (state->last ? 64 : 0) + | |
1268 | strm->data_type = (int)state->bits + (state->last ? 64 : 0) + | |
1246 | 1269 | (state->mode == TYPE ? 128 : 0) + |
1247 | 1270 | (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); |
1248 | 1271 | if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) |
1254 | 1277 | z_streamp strm; |
1255 | 1278 | { |
1256 | 1279 | struct inflate_state FAR *state; |
1257 | if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) | |
1280 | if (inflateStateCheck(strm)) | |
1258 | 1281 | return Z_STREAM_ERROR; |
1259 | 1282 | state = (struct inflate_state FAR *)strm->state; |
1260 | 1283 | if (state->window != Z_NULL) ZFREE(strm, state->window); |
1272 | 1295 | struct inflate_state FAR *state; |
1273 | 1296 | |
1274 | 1297 | /* check state */ |
1275 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1298 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1276 | 1299 | state = (struct inflate_state FAR *)strm->state; |
1277 | 1300 | |
1278 | 1301 | /* copy dictionary */ |
1297 | 1320 | int ret; |
1298 | 1321 | |
1299 | 1322 | /* check state */ |
1300 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1323 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1301 | 1324 | state = (struct inflate_state FAR *)strm->state; |
1302 | 1325 | if (state->wrap != 0 && state->mode != DICT) |
1303 | 1326 | return Z_STREAM_ERROR; |
1329 | 1352 | struct inflate_state FAR *state; |
1330 | 1353 | |
1331 | 1354 | /* check state */ |
1332 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1355 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1333 | 1356 | state = (struct inflate_state FAR *)strm->state; |
1334 | 1357 | if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; |
1335 | 1358 | |
1382 | 1405 | struct inflate_state FAR *state; |
1383 | 1406 | |
1384 | 1407 | /* check parameters */ |
1385 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1408 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1386 | 1409 | state = (struct inflate_state FAR *)strm->state; |
1387 | 1410 | if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; |
1388 | 1411 | |
1429 | 1452 | { |
1430 | 1453 | struct inflate_state FAR *state; |
1431 | 1454 | |
1432 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1455 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1433 | 1456 | state = (struct inflate_state FAR *)strm->state; |
1434 | 1457 | return state->mode == STORED && state->bits == 0; |
1435 | 1458 | } |
1444 | 1467 | unsigned wsize; |
1445 | 1468 | |
1446 | 1469 | /* check input */ |
1447 | if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || | |
1448 | source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) | |
1470 | if (inflateStateCheck(source) || dest == Z_NULL) | |
1449 | 1471 | return Z_STREAM_ERROR; |
1450 | 1472 | state = (struct inflate_state FAR *)source->state; |
1451 | 1473 | |
1466 | 1488 | /* copy state */ |
1467 | 1489 | zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); |
1468 | 1490 | zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); |
1491 | copy->strm = dest; | |
1469 | 1492 | if (state->lencode >= state->codes && |
1470 | 1493 | state->lencode <= state->codes + ENOUGH - 1) { |
1471 | 1494 | copy->lencode = copy->codes + (state->lencode - state->codes); |
1487 | 1510 | { |
1488 | 1511 | struct inflate_state FAR *state; |
1489 | 1512 | |
1490 | if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; | |
1491 | state = (struct inflate_state FAR *)strm->state; | |
1513 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1514 | state = (struct inflate_state FAR *)strm->state; | |
1515 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | |
1492 | 1516 | state->sane = !subvert; |
1493 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR | |
1494 | 1517 | return Z_OK; |
1495 | 1518 | #else |
1519 | (void)subvert; | |
1496 | 1520 | state->sane = 1; |
1497 | 1521 | return Z_DATA_ERROR; |
1498 | 1522 | #endif |
1499 | 1523 | } |
1500 | 1524 | |
1525 | int ZEXPORT inflateValidate(strm, check) | |
1526 | z_streamp strm; | |
1527 | int check; | |
1528 | { | |
1529 | struct inflate_state FAR *state; | |
1530 | ||
1531 | if (inflateStateCheck(strm)) return Z_STREAM_ERROR; | |
1532 | state = (struct inflate_state FAR *)strm->state; | |
1533 | if (check) | |
1534 | state->wrap |= 4; | |
1535 | else | |
1536 | state->wrap &= ~4; | |
1537 | return Z_OK; | |
1538 | } | |
1539 | ||
1501 | 1540 | long ZEXPORT inflateMark(strm) |
1502 | 1541 | z_streamp strm; |
1503 | 1542 | { |
1504 | 1543 | struct inflate_state FAR *state; |
1505 | 1544 | |
1506 | if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; | |
1507 | state = (struct inflate_state FAR *)strm->state; | |
1508 | return ((long)(state->back) << 16) + | |
1545 | if (inflateStateCheck(strm)) | |
1546 | return -(1L << 16); | |
1547 | state = (struct inflate_state FAR *)strm->state; | |
1548 | return (long)(((unsigned long)((long)state->back)) << 16) + | |
1509 | 1549 | (state->mode == COPY ? state->length : |
1510 | 1550 | (state->mode == MATCH ? state->was - state->length : 0)); |
1511 | 1551 | } |
1552 | ||
1553 | unsigned long ZEXPORT inflateCodesUsed(strm) | |
1554 | z_streamp strm; | |
1555 | { | |
1556 | struct inflate_state FAR *state; | |
1557 | if (inflateStateCheck(strm)) return (unsigned long)-1; | |
1558 | state = (struct inflate_state FAR *)strm->state; | |
1559 | return (unsigned long)(state->next - state->codes); | |
1560 | } |
0 | 0 | /* inflate.h -- internal inflate state definition |
1 | * Copyright (C) 1995-2009 Mark Adler | |
1 | * Copyright (C) 1995-2016 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
17 | 17 | |
18 | 18 | /* Possible inflate modes between inflate() calls */ |
19 | 19 | typedef enum { |
20 | HEAD, /* i: waiting for magic header */ | |
20 | HEAD = 16180, /* i: waiting for magic header */ | |
21 | 21 | FLAGS, /* i: waiting for method and flags (gzip) */ |
22 | 22 | TIME, /* i: waiting for modification time (gzip) */ |
23 | 23 | OS, /* i: waiting for extra flags and operating system (gzip) */ |
76 | 76 | CHECK -> LENGTH -> DONE |
77 | 77 | */ |
78 | 78 | |
79 | /* state maintained between inflate() calls. Approximately 10K bytes. */ | |
79 | /* State maintained between inflate() calls -- approximately 7K bytes, not | |
80 | including the allocated sliding window, which is up to 32K bytes. */ | |
80 | 81 | struct inflate_state { |
82 | z_streamp strm; /* pointer back to this zlib stream */ | |
81 | 83 | inflate_mode mode; /* current inflate mode */ |
82 | 84 | int last; /* true if processing last block */ |
83 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ | |
85 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip, | |
86 | bit 2 true to validate check value */ | |
84 | 87 | int havedict; /* true if dictionary provided */ |
85 | 88 | int flags; /* gzip header method and flags (0 if zlib) */ |
86 | 89 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ |
0 | 0 | /* inftrees.c -- generate Huffman trees for efficient decoding |
1 | * Copyright (C) 1995-2013 Mark Adler | |
1 | * Copyright (C) 1995-2017 Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
8 | 8 | #define MAXBITS 15 |
9 | 9 | |
10 | 10 | const char inflate_copyright[] = |
11 | " inflate 1.2.8 Copyright 1995-2013 Mark Adler "; | |
11 | " inflate 1.2.11 Copyright 1995-2017 Mark Adler "; | |
12 | 12 | /* |
13 | 13 | If you use the zlib library in a product, an acknowledgment is welcome |
14 | 14 | in the documentation of your product. If for some reason you cannot |
53 | 53 | code FAR *next; /* next available space in table */ |
54 | 54 | const unsigned short FAR *base; /* base value table to use */ |
55 | 55 | const unsigned short FAR *extra; /* extra bits table to use */ |
56 | int end; /* use base and extra for symbol > end */ | |
56 | unsigned match; /* use base and extra for symbol >= match */ | |
57 | 57 | unsigned short count[MAXBITS+1]; /* number of codes of each length */ |
58 | 58 | unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ |
59 | 59 | static const unsigned short lbase[31] = { /* Length codes 257..285 base */ |
61 | 61 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; |
62 | 62 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
63 | 63 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, |
64 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; | |
64 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202}; | |
65 | 65 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ |
66 | 66 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, |
67 | 67 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, |
180 | 180 | switch (type) { |
181 | 181 | case CODES: |
182 | 182 | base = extra = work; /* dummy value--not used */ |
183 | end = 19; | |
183 | match = 20; | |
184 | 184 | break; |
185 | 185 | case LENS: |
186 | 186 | base = lbase; |
187 | base -= 257; | |
188 | 187 | extra = lext; |
189 | extra -= 257; | |
190 | end = 256; | |
188 | match = 257; | |
191 | 189 | break; |
192 | default: /* DISTS */ | |
190 | default: /* DISTS */ | |
193 | 191 | base = dbase; |
194 | 192 | extra = dext; |
195 | end = -1; | |
193 | match = 0; | |
196 | 194 | } |
197 | 195 | |
198 | 196 | /* initialize state for loop */ |
215 | 213 | for (;;) { |
216 | 214 | /* create table entry */ |
217 | 215 | here.bits = (unsigned char)(len - drop); |
218 | if ((int)(work[sym]) < end) { | |
216 | if (work[sym] + 1U < match) { | |
219 | 217 | here.op = (unsigned char)0; |
220 | 218 | here.val = work[sym]; |
221 | 219 | } |
222 | else if ((int)(work[sym]) > end) { | |
223 | here.op = (unsigned char)(extra[work[sym]]); | |
224 | here.val = base[work[sym]]; | |
220 | else if (work[sym] >= match) { | |
221 | here.op = (unsigned char)(extra[work[sym] - match]); | |
222 | here.val = base[work[sym] - match]; | |
225 | 223 | } |
226 | 224 | else { |
227 | 225 | here.op = (unsigned char)(32 + 64); /* end of block */ |
0 | 0 | /* trees.c -- output deflated data using Huffman coding |
1 | * Copyright (C) 1995-2012 Jean-loup Gailly | |
1 | * Copyright (C) 1995-2017 Jean-loup Gailly | |
2 | 2 | * detect_data_type() function provided freely by Cosmin Truta, 2006 |
3 | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | 4 | */ |
35 | 35 | |
36 | 36 | #include "deflate.h" |
37 | 37 | |
38 | #ifdef DEBUG | |
38 | #ifdef ZLIB_DEBUG | |
39 | 39 | # include <ctype.h> |
40 | 40 | #endif |
41 | 41 | |
121 | 121 | int max_length; /* max bit length for the codes */ |
122 | 122 | }; |
123 | 123 | |
124 | local static_tree_desc static_l_desc = | |
124 | local const static_tree_desc static_l_desc = | |
125 | 125 | {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; |
126 | 126 | |
127 | local static_tree_desc static_d_desc = | |
127 | local const static_tree_desc static_d_desc = | |
128 | 128 | {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; |
129 | 129 | |
130 | local static_tree_desc static_bl_desc = | |
130 | local const static_tree_desc static_bl_desc = | |
131 | 131 | {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; |
132 | 132 | |
133 | 133 | /* =========================================================================== |
151 | 151 | local unsigned bi_reverse OF((unsigned value, int length)); |
152 | 152 | local void bi_windup OF((deflate_state *s)); |
153 | 153 | local void bi_flush OF((deflate_state *s)); |
154 | local void copy_block OF((deflate_state *s, charf *buf, unsigned len, | |
155 | int header)); | |
156 | 154 | |
157 | 155 | #ifdef GEN_TREES_H |
158 | 156 | local void gen_trees_header OF((void)); |
159 | 157 | #endif |
160 | 158 | |
161 | #ifndef DEBUG | |
159 | #ifndef ZLIB_DEBUG | |
162 | 160 | # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) |
163 | 161 | /* Send a code of the given tree. c and tree must not have side effects */ |
164 | 162 | |
165 | #else /* DEBUG */ | |
163 | #else /* !ZLIB_DEBUG */ | |
166 | 164 | # define send_code(s, c, tree) \ |
167 | 165 | { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ |
168 | 166 | send_bits(s, tree[c].Code, tree[c].Len); } |
181 | 179 | * Send a value on a given number of bits. |
182 | 180 | * IN assertion: length <= 16 and value fits in length bits. |
183 | 181 | */ |
184 | #ifdef DEBUG | |
182 | #ifdef ZLIB_DEBUG | |
185 | 183 | local void send_bits OF((deflate_state *s, int value, int length)); |
186 | 184 | |
187 | 185 | local void send_bits(s, value, length) |
207 | 205 | s->bi_valid += length; |
208 | 206 | } |
209 | 207 | } |
210 | #else /* !DEBUG */ | |
208 | #else /* !ZLIB_DEBUG */ | |
211 | 209 | |
212 | 210 | #define send_bits(s, value, length) \ |
213 | 211 | { int len = length;\ |
214 | 212 | if (s->bi_valid > (int)Buf_size - len) {\ |
215 | int val = value;\ | |
213 | int val = (int)value;\ | |
216 | 214 | s->bi_buf |= (ush)val << s->bi_valid;\ |
217 | 215 | put_short(s, s->bi_buf);\ |
218 | 216 | s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ |
222 | 220 | s->bi_valid += len;\ |
223 | 221 | }\ |
224 | 222 | } |
225 | #endif /* DEBUG */ | |
223 | #endif /* ZLIB_DEBUG */ | |
226 | 224 | |
227 | 225 | |
228 | 226 | /* the arguments must not have side effects */ |
316 | 314 | * Genererate the file trees.h describing the static trees. |
317 | 315 | */ |
318 | 316 | #ifdef GEN_TREES_H |
319 | # ifndef DEBUG | |
317 | # ifndef ZLIB_DEBUG | |
320 | 318 | # include <stdio.h> |
321 | 319 | # endif |
322 | 320 | |
393 | 391 | |
394 | 392 | s->bi_buf = 0; |
395 | 393 | s->bi_valid = 0; |
396 | #ifdef DEBUG | |
394 | #ifdef ZLIB_DEBUG | |
397 | 395 | s->compressed_len = 0L; |
398 | 396 | s->bits_sent = 0L; |
399 | 397 | #endif |
521 | 519 | xbits = 0; |
522 | 520 | if (n >= base) xbits = extra[n-base]; |
523 | 521 | f = tree[n].Freq; |
524 | s->opt_len += (ulg)f * (bits + xbits); | |
525 | if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); | |
522 | s->opt_len += (ulg)f * (unsigned)(bits + xbits); | |
523 | if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits); | |
526 | 524 | } |
527 | 525 | if (overflow == 0) return; |
528 | 526 | |
529 | Trace((stderr,"\nbit length overflow\n")); | |
527 | Tracev((stderr,"\nbit length overflow\n")); | |
530 | 528 | /* This happens for example on obj2 and pic of the Calgary corpus */ |
531 | 529 | |
532 | 530 | /* Find the first bit length which could increase: */ |
553 | 551 | m = s->heap[--h]; |
554 | 552 | if (m > max_code) continue; |
555 | 553 | if ((unsigned) tree[m].Len != (unsigned) bits) { |
556 | Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); | |
557 | s->opt_len += ((long)bits - (long)tree[m].Len) | |
558 | *(long)tree[m].Freq; | |
554 | Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); | |
555 | s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq; | |
559 | 556 | tree[m].Len = (ush)bits; |
560 | 557 | } |
561 | 558 | n--; |
577 | 574 | ushf *bl_count; /* number of codes at each bit length */ |
578 | 575 | { |
579 | 576 | ush next_code[MAX_BITS+1]; /* next code value for each bit length */ |
580 | ush code = 0; /* running code value */ | |
577 | unsigned code = 0; /* running code value */ | |
581 | 578 | int bits; /* bit index */ |
582 | 579 | int n; /* code index */ |
583 | 580 | |
585 | 582 | * without bit reversal. |
586 | 583 | */ |
587 | 584 | for (bits = 1; bits <= MAX_BITS; bits++) { |
588 | next_code[bits] = code = (code + bl_count[bits-1]) << 1; | |
585 | code = (code + bl_count[bits-1]) << 1; | |
586 | next_code[bits] = (ush)code; | |
589 | 587 | } |
590 | 588 | /* Check that the bit counts in bl_count are consistent. The last code |
591 | 589 | * must be all ones. |
598 | 596 | int len = tree[n].Len; |
599 | 597 | if (len == 0) continue; |
600 | 598 | /* Now reverse the bits */ |
601 | tree[n].Code = bi_reverse(next_code[len]++, len); | |
599 | tree[n].Code = (ush)bi_reverse(next_code[len]++, len); | |
602 | 600 | |
603 | 601 | Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", |
604 | 602 | n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); |
820 | 818 | if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; |
821 | 819 | } |
822 | 820 | /* Update opt_len to include the bit length tree and counts */ |
823 | s->opt_len += 3*(max_blindex+1) + 5+5+4; | |
821 | s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4; | |
824 | 822 | Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", |
825 | 823 | s->opt_len, s->static_len)); |
826 | 824 | |
868 | 866 | int last; /* one if this is the last block for a file */ |
869 | 867 | { |
870 | 868 | send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ |
871 | #ifdef DEBUG | |
869 | bi_windup(s); /* align on byte boundary */ | |
870 | put_short(s, (ush)stored_len); | |
871 | put_short(s, (ush)~stored_len); | |
872 | zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len); | |
873 | s->pending += stored_len; | |
874 | #ifdef ZLIB_DEBUG | |
872 | 875 | s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; |
873 | 876 | s->compressed_len += (stored_len + 4) << 3; |
874 | #endif | |
875 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ | |
877 | s->bits_sent += 2*16; | |
878 | s->bits_sent += stored_len<<3; | |
879 | #endif | |
876 | 880 | } |
877 | 881 | |
878 | 882 | /* =========================================================================== |
893 | 897 | { |
894 | 898 | send_bits(s, STATIC_TREES<<1, 3); |
895 | 899 | send_code(s, END_BLOCK, static_ltree); |
896 | #ifdef DEBUG | |
900 | #ifdef ZLIB_DEBUG | |
897 | 901 | s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ |
898 | 902 | #endif |
899 | 903 | bi_flush(s); |
901 | 905 | |
902 | 906 | /* =========================================================================== |
903 | 907 | * Determine the best encoding for the current block: dynamic trees, static |
904 | * trees or store, and output the encoded block to the zip file. | |
908 | * trees or store, and write out the encoded block. | |
905 | 909 | */ |
906 | 910 | void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) |
907 | 911 | deflate_state *s; |
973 | 977 | send_bits(s, (STATIC_TREES<<1)+last, 3); |
974 | 978 | compress_block(s, (const ct_data *)static_ltree, |
975 | 979 | (const ct_data *)static_dtree); |
976 | #ifdef DEBUG | |
980 | #ifdef ZLIB_DEBUG | |
977 | 981 | s->compressed_len += 3 + s->static_len; |
978 | 982 | #endif |
979 | 983 | } else { |
982 | 986 | max_blindex+1); |
983 | 987 | compress_block(s, (const ct_data *)s->dyn_ltree, |
984 | 988 | (const ct_data *)s->dyn_dtree); |
985 | #ifdef DEBUG | |
989 | #ifdef ZLIB_DEBUG | |
986 | 990 | s->compressed_len += 3 + s->opt_len; |
987 | 991 | #endif |
988 | 992 | } |
994 | 998 | |
995 | 999 | if (last) { |
996 | 1000 | bi_windup(s); |
997 | #ifdef DEBUG | |
1001 | #ifdef ZLIB_DEBUG | |
998 | 1002 | s->compressed_len += 7; /* align on byte boundary */ |
999 | 1003 | #endif |
1000 | 1004 | } |
1089 | 1093 | send_code(s, code, dtree); /* send the distance code */ |
1090 | 1094 | extra = extra_dbits[code]; |
1091 | 1095 | if (extra != 0) { |
1092 | dist -= base_dist[code]; | |
1096 | dist -= (unsigned)base_dist[code]; | |
1093 | 1097 | send_bits(s, dist, extra); /* send the extra distance bits */ |
1094 | 1098 | } |
1095 | 1099 | } /* literal or match pair ? */ |
1192 | 1196 | } |
1193 | 1197 | s->bi_buf = 0; |
1194 | 1198 | s->bi_valid = 0; |
1195 | #ifdef DEBUG | |
1199 | #ifdef ZLIB_DEBUG | |
1196 | 1200 | s->bits_sent = (s->bits_sent+7) & ~7; |
1197 | 1201 | #endif |
1198 | 1202 | } |
1199 | ||
1200 | /* =========================================================================== | |
1201 | * Copy a stored block, storing first the length and its | |
1202 | * one's complement if requested. | |
1203 | */ | |
1204 | local void copy_block(s, buf, len, header) | |
1205 | deflate_state *s; | |
1206 | charf *buf; /* the input data */ | |
1207 | unsigned len; /* its length */ | |
1208 | int header; /* true if block header must be written */ | |
1209 | { | |
1210 | bi_windup(s); /* align on byte boundary */ | |
1211 | ||
1212 | if (header) { | |
1213 | put_short(s, (ush)len); | |
1214 | put_short(s, (ush)~len); | |
1215 | #ifdef DEBUG | |
1216 | s->bits_sent += 2*16; | |
1217 | #endif | |
1218 | } | |
1219 | #ifdef DEBUG | |
1220 | s->bits_sent += (ulg)len<<3; | |
1221 | #endif | |
1222 | while (len--) { | |
1223 | put_byte(s, *buf++); | |
1224 | } | |
1225 | } |
0 | 0 | /* uncompr.c -- decompress a memory buffer |
1 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. | |
1 | * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
8 | 8 | #include "zlib.h" |
9 | 9 | |
10 | 10 | /* =========================================================================== |
11 | Decompresses the source buffer into the destination buffer. sourceLen is | |
12 | the byte length of the source buffer. Upon entry, destLen is the total | |
13 | size of the destination buffer, which must be large enough to hold the | |
14 | entire uncompressed data. (The size of the uncompressed data must have | |
15 | been saved previously by the compressor and transmitted to the decompressor | |
16 | by some mechanism outside the scope of this compression library.) | |
17 | Upon exit, destLen is the actual size of the compressed buffer. | |
11 | Decompresses the source buffer into the destination buffer. *sourceLen is | |
12 | the byte length of the source buffer. Upon entry, *destLen is the total size | |
13 | of the destination buffer, which must be large enough to hold the entire | |
14 | uncompressed data. (The size of the uncompressed data must have been saved | |
15 | previously by the compressor and transmitted to the decompressor by some | |
16 | mechanism outside the scope of this compression library.) Upon exit, | |
17 | *destLen is the size of the decompressed data and *sourceLen is the number | |
18 | of source bytes consumed. Upon return, source + *sourceLen points to the | |
19 | first unused input byte. | |
18 | 20 | |
19 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not | |
20 | enough memory, Z_BUF_ERROR if there was not enough room in the output | |
21 | buffer, or Z_DATA_ERROR if the input data was corrupted. | |
21 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough | |
22 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, or | |
23 | Z_DATA_ERROR if the input data was corrupted, including if the input data is | |
24 | an incomplete zlib stream. | |
22 | 25 | */ |
26 | int ZEXPORT uncompress2 (dest, destLen, source, sourceLen) | |
27 | Bytef *dest; | |
28 | uLongf *destLen; | |
29 | const Bytef *source; | |
30 | uLong *sourceLen; | |
31 | { | |
32 | z_stream stream; | |
33 | int err; | |
34 | const uInt max = (uInt)-1; | |
35 | uLong len, left; | |
36 | Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ | |
37 | ||
38 | len = *sourceLen; | |
39 | if (*destLen) { | |
40 | left = *destLen; | |
41 | *destLen = 0; | |
42 | } | |
43 | else { | |
44 | left = 1; | |
45 | dest = buf; | |
46 | } | |
47 | ||
48 | stream.next_in = (z_const Bytef *)source; | |
49 | stream.avail_in = 0; | |
50 | stream.zalloc = (alloc_func)0; | |
51 | stream.zfree = (free_func)0; | |
52 | stream.opaque = (voidpf)0; | |
53 | ||
54 | err = inflateInit(&stream); | |
55 | if (err != Z_OK) return err; | |
56 | ||
57 | stream.next_out = dest; | |
58 | stream.avail_out = 0; | |
59 | ||
60 | do { | |
61 | if (stream.avail_out == 0) { | |
62 | stream.avail_out = left > (uLong)max ? max : (uInt)left; | |
63 | left -= stream.avail_out; | |
64 | } | |
65 | if (stream.avail_in == 0) { | |
66 | stream.avail_in = len > (uLong)max ? max : (uInt)len; | |
67 | len -= stream.avail_in; | |
68 | } | |
69 | err = inflate(&stream, Z_NO_FLUSH); | |
70 | } while (err == Z_OK); | |
71 | ||
72 | *sourceLen -= len + stream.avail_in; | |
73 | if (dest != buf) | |
74 | *destLen = stream.total_out; | |
75 | else if (stream.total_out && err == Z_BUF_ERROR) | |
76 | left = 1; | |
77 | ||
78 | inflateEnd(&stream); | |
79 | return err == Z_STREAM_END ? Z_OK : | |
80 | err == Z_NEED_DICT ? Z_DATA_ERROR : | |
81 | err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : | |
82 | err; | |
83 | } | |
84 | ||
23 | 85 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) |
24 | 86 | Bytef *dest; |
25 | 87 | uLongf *destLen; |
26 | 88 | const Bytef *source; |
27 | 89 | uLong sourceLen; |
28 | 90 | { |
29 | z_stream stream; | |
30 | int err; | |
31 | ||
32 | stream.next_in = (z_const Bytef *)source; | |
33 | stream.avail_in = (uInt)sourceLen; | |
34 | /* Check for source > 64K on 16-bit machine: */ | |
35 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | |
36 | ||
37 | stream.next_out = dest; | |
38 | stream.avail_out = (uInt)*destLen; | |
39 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; | |
40 | ||
41 | stream.zalloc = (alloc_func)0; | |
42 | stream.zfree = (free_func)0; | |
43 | ||
44 | err = inflateInit(&stream); | |
45 | if (err != Z_OK) return err; | |
46 | ||
47 | err = inflate(&stream, Z_FINISH); | |
48 | if (err != Z_STREAM_END) { | |
49 | inflateEnd(&stream); | |
50 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) | |
51 | return Z_DATA_ERROR; | |
52 | return err; | |
53 | } | |
54 | *destLen = stream.total_out; | |
55 | ||
56 | err = inflateEnd(&stream); | |
57 | return err; | |
91 | return uncompress2(dest, destLen, source, &sourceLen); | |
58 | 92 | } |
0 | 0 | /* zconf.h -- configuration of the zlib compression library |
1 | * Copyright (C) 1995-2013 Jean-loup Gailly. | |
1 | * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
16 | 16 | #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ |
17 | 17 | # define Z_PREFIX_SET |
18 | 18 | |
19 | /* all linked symbols */ | |
19 | /* all linked symbols and init macros */ | |
20 | 20 | # define _dist_code z__dist_code |
21 | 21 | # define _length_code z__length_code |
22 | 22 | # define _tr_align z__tr_align |
28 | 28 | # define adler32 z_adler32 |
29 | 29 | # define adler32_combine z_adler32_combine |
30 | 30 | # define adler32_combine64 z_adler32_combine64 |
31 | # define adler32_z z_adler32_z | |
31 | 32 | # ifndef Z_SOLO |
32 | 33 | # define compress z_compress |
33 | 34 | # define compress2 z_compress2 |
36 | 37 | # define crc32 z_crc32 |
37 | 38 | # define crc32_combine z_crc32_combine |
38 | 39 | # define crc32_combine64 z_crc32_combine64 |
40 | # define crc32_z z_crc32_z | |
39 | 41 | # define deflate z_deflate |
40 | 42 | # define deflateBound z_deflateBound |
41 | 43 | # define deflateCopy z_deflateCopy |
42 | 44 | # define deflateEnd z_deflateEnd |
45 | # define deflateGetDictionary z_deflateGetDictionary | |
46 | # define deflateInit z_deflateInit | |
47 | # define deflateInit2 z_deflateInit2 | |
43 | 48 | # define deflateInit2_ z_deflateInit2_ |
44 | 49 | # define deflateInit_ z_deflateInit_ |
45 | 50 | # define deflateParams z_deflateParams |
66 | 71 | # define gzeof z_gzeof |
67 | 72 | # define gzerror z_gzerror |
68 | 73 | # define gzflush z_gzflush |
74 | # define gzfread z_gzfread | |
75 | # define gzfwrite z_gzfwrite | |
69 | 76 | # define gzgetc z_gzgetc |
70 | 77 | # define gzgetc_ z_gzgetc_ |
71 | 78 | # define gzgets z_gzgets |
77 | 84 | # define gzopen_w z_gzopen_w |
78 | 85 | # endif |
79 | 86 | # define gzprintf z_gzprintf |
80 | # define gzvprintf z_gzvprintf | |
81 | 87 | # define gzputc z_gzputc |
82 | 88 | # define gzputs z_gzputs |
83 | 89 | # define gzread z_gzread |
88 | 94 | # define gztell z_gztell |
89 | 95 | # define gztell64 z_gztell64 |
90 | 96 | # define gzungetc z_gzungetc |
97 | # define gzvprintf z_gzvprintf | |
91 | 98 | # define gzwrite z_gzwrite |
92 | 99 | # endif |
93 | 100 | # define inflate z_inflate |
94 | 101 | # define inflateBack z_inflateBack |
95 | 102 | # define inflateBackEnd z_inflateBackEnd |
103 | # define inflateBackInit z_inflateBackInit | |
96 | 104 | # define inflateBackInit_ z_inflateBackInit_ |
105 | # define inflateCodesUsed z_inflateCodesUsed | |
97 | 106 | # define inflateCopy z_inflateCopy |
98 | 107 | # define inflateEnd z_inflateEnd |
108 | # define inflateGetDictionary z_inflateGetDictionary | |
99 | 109 | # define inflateGetHeader z_inflateGetHeader |
110 | # define inflateInit z_inflateInit | |
111 | # define inflateInit2 z_inflateInit2 | |
100 | 112 | # define inflateInit2_ z_inflateInit2_ |
101 | 113 | # define inflateInit_ z_inflateInit_ |
102 | 114 | # define inflateMark z_inflateMark |
103 | 115 | # define inflatePrime z_inflatePrime |
104 | 116 | # define inflateReset z_inflateReset |
105 | 117 | # define inflateReset2 z_inflateReset2 |
118 | # define inflateResetKeep z_inflateResetKeep | |
106 | 119 | # define inflateSetDictionary z_inflateSetDictionary |
107 | # define inflateGetDictionary z_inflateGetDictionary | |
108 | 120 | # define inflateSync z_inflateSync |
109 | 121 | # define inflateSyncPoint z_inflateSyncPoint |
110 | 122 | # define inflateUndermine z_inflateUndermine |
111 | # define inflateResetKeep z_inflateResetKeep | |
123 | # define inflateValidate z_inflateValidate | |
112 | 124 | # define inflate_copyright z_inflate_copyright |
113 | 125 | # define inflate_fast z_inflate_fast |
114 | 126 | # define inflate_table z_inflate_table |
115 | 127 | # ifndef Z_SOLO |
116 | 128 | # define uncompress z_uncompress |
129 | # define uncompress2 z_uncompress2 | |
117 | 130 | # endif |
118 | 131 | # define zError z_zError |
119 | 132 | # ifndef Z_SOLO |
223 | 236 | # define z_const |
224 | 237 | #endif |
225 | 238 | |
226 | /* Some Mac compilers merge all .h files incorrectly: */ | |
227 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) | |
228 | # define NO_DUMMY_DECL | |
239 | #ifdef Z_SOLO | |
240 | typedef unsigned long z_size_t; | |
241 | #else | |
242 | # define z_longlong long long | |
243 | # if defined(NO_SIZE_T) | |
244 | typedef unsigned NO_SIZE_T z_size_t; | |
245 | # elif defined(STDC) | |
246 | # include <stddef.h> | |
247 | typedef size_t z_size_t; | |
248 | # else | |
249 | typedef unsigned long z_size_t; | |
250 | # endif | |
251 | # undef z_longlong | |
229 | 252 | #endif |
230 | 253 | |
231 | 254 | /* Maximum value for memLevel in deflateInit2 */ |
255 | 278 | Of course this will generally degrade compression (there's no free lunch). |
256 | 279 | |
257 | 280 | The memory requirements for inflate are (in bytes) 1 << windowBits |
258 | that is, 32K for windowBits=15 (default value) plus a few kilobytes | |
281 | that is, 32K for windowBits=15 (default value) plus about 7 kilobytes | |
259 | 282 | for small objects. |
260 | 283 | */ |
261 | 284 |
0 | 0 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
1 | version 1.2.8, April 28th, 2013 | |
2 | ||
3 | Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler | |
1 | version 1.2.11, January 15th, 2017 | |
2 | ||
3 | Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler | |
4 | 4 | |
5 | 5 | This software is provided 'as-is', without any express or implied |
6 | 6 | warranty. In no event will the authors be held liable for any damages |
36 | 36 | extern "C" { |
37 | 37 | #endif |
38 | 38 | |
39 | #define ZLIB_VERSION "1.2.8" | |
40 | #define ZLIB_VERNUM 0x1280 | |
39 | #define ZLIB_VERSION "1.2.11" | |
40 | #define ZLIB_VERNUM 0x12b0 | |
41 | 41 | #define ZLIB_VER_MAJOR 1 |
42 | 42 | #define ZLIB_VER_MINOR 2 |
43 | #define ZLIB_VER_REVISION 8 | |
43 | #define ZLIB_VER_REVISION 11 | |
44 | 44 | #define ZLIB_VER_SUBREVISION 0 |
45 | 45 | |
46 | 46 | /* |
64 | 64 | with "gz". The gzip format is different from the zlib format. gzip is a |
65 | 65 | gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. |
66 | 66 | |
67 | This library can optionally read and write gzip streams in memory as well. | |
67 | This library can optionally read and write gzip and raw deflate streams in | |
68 | memory as well. | |
68 | 69 | |
69 | 70 | The zlib format was designed to be compact and fast for use in memory |
70 | 71 | and on communications channels. The gzip format was designed for single- |
73 | 74 | |
74 | 75 | The library does not install any signal handler. The decoder checks |
75 | 76 | the consistency of the compressed data, so the library should never crash |
76 | even in case of corrupted input. | |
77 | even in the case of corrupted input. | |
77 | 78 | */ |
78 | 79 | |
79 | 80 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
86 | 87 | uInt avail_in; /* number of bytes available at next_in */ |
87 | 88 | uLong total_in; /* total number of input bytes read so far */ |
88 | 89 | |
89 | Bytef *next_out; /* next output byte should be put there */ | |
90 | Bytef *next_out; /* next output byte will go here */ | |
90 | 91 | uInt avail_out; /* remaining free space at next_out */ |
91 | 92 | uLong total_out; /* total number of bytes output so far */ |
92 | 93 | |
97 | 98 | free_func zfree; /* used to free the internal state */ |
98 | 99 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
99 | 100 | |
100 | int data_type; /* best guess about the data type: binary or text */ | |
101 | uLong adler; /* adler32 value of the uncompressed data */ | |
101 | int data_type; /* best guess about the data type: binary or text | |
102 | for deflate, or the decoding state for inflate */ | |
103 | uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ | |
102 | 104 | uLong reserved; /* reserved for future use */ |
103 | 105 | } z_stream; |
104 | 106 | |
141 | 143 | |
142 | 144 | zalloc must return Z_NULL if there is not enough memory for the object. |
143 | 145 | If zlib is used in a multi-threaded application, zalloc and zfree must be |
144 | thread safe. | |
146 | thread safe. In that case, zlib is thread-safe. When zalloc and zfree are | |
147 | Z_NULL on entry to the initialization function, they are set to internal | |
148 | routines that use the standard library functions malloc() and free(). | |
145 | 149 | |
146 | 150 | On 16-bit systems, the functions zalloc and zfree must be able to allocate |
147 | 151 | exactly 65536 bytes, but will not be required to allocate more than this if |
154 | 158 | |
155 | 159 | The fields total_in and total_out can be used for statistics or progress |
156 | 160 | reports. After compression, total_in holds the total size of the |
157 | uncompressed data and may be saved for use in the decompressor (particularly | |
161 | uncompressed data and may be saved for use by the decompressor (particularly | |
158 | 162 | if the decompressor wants to decompress everything in a single step). |
159 | 163 | */ |
160 | 164 | |
199 | 203 | #define Z_TEXT 1 |
200 | 204 | #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ |
201 | 205 | #define Z_UNKNOWN 2 |
202 | /* Possible values of the data_type field (though see inflate()) */ | |
206 | /* Possible values of the data_type field for deflate() */ | |
203 | 207 | |
204 | 208 | #define Z_DEFLATED 8 |
205 | 209 | /* The deflate compression method (the only one supported in this version) */ |
257 | 261 | enough room in the output buffer), next_in and avail_in are updated and |
258 | 262 | processing will resume at this point for the next call of deflate(). |
259 | 263 | |
260 | - Provide more output starting at next_out and update next_out and avail_out | |
264 | - Generate more output starting at next_out and update next_out and avail_out | |
261 | 265 | accordingly. This action is forced if the parameter flush is non zero. |
262 | 266 | Forcing flush frequently degrades the compression ratio, so this parameter |
263 | should be set only when necessary (in interactive applications). Some | |
264 | output may be provided even if flush is not set. | |
267 | should be set only when necessary. Some output may be provided even if | |
268 | flush is zero. | |
265 | 269 | |
266 | 270 | Before the call of deflate(), the application should ensure that at least |
267 | 271 | one of the actions is possible, by providing more input and/or consuming more |
270 | 274 | output when it wants, for example when the output buffer is full (avail_out |
271 | 275 | == 0), or after each call of deflate(). If deflate returns Z_OK and with |
272 | 276 | zero avail_out, it must be called again after making room in the output |
273 | buffer because there might be more output pending. | |
277 | buffer because there might be more output pending. See deflatePending(), | |
278 | which can be used if desired to determine whether or not there is more ouput | |
279 | in that case. | |
274 | 280 | |
275 | 281 | Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to |
276 | 282 | decide how much data to accumulate before producing output, in order to |
291 | 297 | input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. |
292 | 298 | This completes the current deflate block and follows it with an empty fixed |
293 | 299 | codes block that is 10 bits long. This assures that enough bytes are output |
294 | in order for the decompressor to finish the block before the empty fixed code | |
295 | block. | |
300 | in order for the decompressor to finish the block before the empty fixed | |
301 | codes block. | |
296 | 302 | |
297 | 303 | If flush is set to Z_BLOCK, a deflate block is completed and emitted, as |
298 | 304 | for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to |
318 | 324 | |
319 | 325 | If the parameter flush is set to Z_FINISH, pending input is processed, |
320 | 326 | pending output is flushed and deflate returns with Z_STREAM_END if there was |
321 | enough output space; if deflate returns with Z_OK, this function must be | |
322 | called again with Z_FINISH and more output space (updated avail_out) but no | |
323 | more input data, until it returns with Z_STREAM_END or an error. After | |
324 | deflate has returned Z_STREAM_END, the only possible operations on the stream | |
325 | are deflateReset or deflateEnd. | |
326 | ||
327 | Z_FINISH can be used immediately after deflateInit if all the compression | |
328 | is to be done in a single step. In this case, avail_out must be at least the | |
329 | value returned by deflateBound (see below). Then deflate is guaranteed to | |
330 | return Z_STREAM_END. If not enough output space is provided, deflate will | |
331 | not return Z_STREAM_END, and it must be called again as described above. | |
332 | ||
333 | deflate() sets strm->adler to the adler32 checksum of all input read | |
334 | so far (that is, total_in bytes). | |
327 | enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this | |
328 | function must be called again with Z_FINISH and more output space (updated | |
329 | avail_out) but no more input data, until it returns with Z_STREAM_END or an | |
330 | error. After deflate has returned Z_STREAM_END, the only possible operations | |
331 | on the stream are deflateReset or deflateEnd. | |
332 | ||
333 | Z_FINISH can be used in the first deflate call after deflateInit if all the | |
334 | compression is to be done in a single step. In order to complete in one | |
335 | call, avail_out must be at least the value returned by deflateBound (see | |
336 | below). Then deflate is guaranteed to return Z_STREAM_END. If not enough | |
337 | output space is provided, deflate will not return Z_STREAM_END, and it must | |
338 | be called again as described above. | |
339 | ||
340 | deflate() sets strm->adler to the Adler-32 checksum of all input read | |
341 | so far (that is, total_in bytes). If a gzip stream is being generated, then | |
342 | strm->adler will be the CRC-32 checksum of the input read so far. (See | |
343 | deflateInit2 below.) | |
335 | 344 | |
336 | 345 | deflate() may update strm->data_type if it can make a good guess about |
337 | the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered | |
338 | binary. This field is only for information purposes and does not affect the | |
339 | compression algorithm in any manner. | |
346 | the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is | |
347 | considered binary. This field is only for information purposes and does not | |
348 | affect the compression algorithm in any manner. | |
340 | 349 | |
341 | 350 | deflate() returns Z_OK if some progress has been made (more input |
342 | 351 | processed or more output produced), Z_STREAM_END if all input has been |
343 | 352 | consumed and all output has been produced (only when flush is set to |
344 | 353 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example |
345 | if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible | |
346 | (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not | |
347 | fatal, and deflate() can be called again with more input and more output | |
348 | space to continue compressing. | |
354 | if next_in or next_out was Z_NULL or the state was inadvertently written over | |
355 | by the application), or Z_BUF_ERROR if no progress is possible (for example | |
356 | avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and | |
357 | deflate() can be called again with more input and more output space to | |
358 | continue compressing. | |
349 | 359 | */ |
350 | 360 | |
351 | 361 | |
368 | 378 | |
369 | 379 | Initializes the internal stream state for decompression. The fields |
370 | 380 | next_in, avail_in, zalloc, zfree and opaque must be initialized before by |
371 | the caller. If next_in is not Z_NULL and avail_in is large enough (the | |
372 | exact value depends on the compression method), inflateInit determines the | |
373 | compression method from the zlib header and allocates all data structures | |
374 | accordingly; otherwise the allocation will be deferred to the first call of | |
375 | inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to | |
376 | use default allocation functions. | |
381 | the caller. In the current version of inflate, the provided input is not | |
382 | read or consumed. The allocation of a sliding window will be deferred to | |
383 | the first call of inflate (if the decompression does not complete on the | |
384 | first call). If zalloc and zfree are set to Z_NULL, inflateInit updates | |
385 | them to use default allocation functions. | |
377 | 386 | |
378 | 387 | inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough |
379 | 388 | memory, Z_VERSION_ERROR if the zlib library version is incompatible with the |
380 | 389 | version assumed by the caller, or Z_STREAM_ERROR if the parameters are |
381 | 390 | invalid, such as a null pointer to the structure. msg is set to null if |
382 | there is no error message. inflateInit does not perform any decompression | |
383 | apart from possibly reading the zlib header if present: actual decompression | |
384 | will be done by inflate(). (So next_in and avail_in may be modified, but | |
385 | next_out and avail_out are unused and unchanged.) The current implementation | |
386 | of inflateInit() does not process any header information -- that is deferred | |
387 | until inflate() is called. | |
391 | there is no error message. inflateInit does not perform any decompression. | |
392 | Actual decompression will be done by inflate(). So next_in, and avail_in, | |
393 | next_out, and avail_out are unused and unchanged. The current | |
394 | implementation of inflateInit() does not process any header information -- | |
395 | that is deferred until inflate() is called. | |
388 | 396 | */ |
389 | 397 | |
390 | 398 | |
400 | 408 | |
401 | 409 | - Decompress more input starting at next_in and update next_in and avail_in |
402 | 410 | accordingly. If not all input can be processed (because there is not |
403 | enough room in the output buffer), next_in is updated and processing will | |
404 | resume at this point for the next call of inflate(). | |
405 | ||
406 | - Provide more output starting at next_out and update next_out and avail_out | |
411 | enough room in the output buffer), then next_in and avail_in are updated | |
412 | accordingly, and processing will resume at this point for the next call of | |
413 | inflate(). | |
414 | ||
415 | - Generate more output starting at next_out and update next_out and avail_out | |
407 | 416 | accordingly. inflate() provides as much output as possible, until there is |
408 | 417 | no more input data or no more space in the output buffer (see below about |
409 | 418 | the flush parameter). |
410 | 419 | |
411 | 420 | Before the call of inflate(), the application should ensure that at least |
412 | 421 | one of the actions is possible, by providing more input and/or consuming more |
413 | output, and updating the next_* and avail_* values accordingly. The | |
422 | output, and updating the next_* and avail_* values accordingly. If the | |
423 | caller of inflate() does not provide both available input and available | |
424 | output space, it is possible that there will be no progress made. The | |
414 | 425 | application can consume the uncompressed output when it wants, for example |
415 | 426 | when the output buffer is full (avail_out == 0), or after each call of |
416 | 427 | inflate(). If inflate returns Z_OK and with zero avail_out, it must be |
427 | 438 | gets to the end of that block, or when it runs out of data. |
428 | 439 | |
429 | 440 | The Z_BLOCK option assists in appending to or combining deflate streams. |
430 | Also to assist in this, on return inflate() will set strm->data_type to the | |
441 | To assist in this, on return inflate() always sets strm->data_type to the | |
431 | 442 | number of unused bits in the last byte taken from strm->next_in, plus 64 if |
432 | 443 | inflate() is currently decoding the last block in the deflate stream, plus |
433 | 444 | 128 if inflate() returned immediately after decoding an end-of-block code or |
453 | 464 | this case all pending input is processed and all pending output is flushed; |
454 | 465 | avail_out must be large enough to hold all of the uncompressed data for the |
455 | 466 | operation to complete. (The size of the uncompressed data may have been |
456 | saved by the compressor for this purpose.) The use of Z_FINISH is not | |
467 | saved by the compressor for this purpose.) The use of Z_FINISH is not | |
457 | 468 | required to perform an inflation in one step. However it may be used to |
458 | 469 | inform inflate that a faster approach can be used for the single inflate() |
459 | 470 | call. Z_FINISH also informs inflate to not maintain a sliding window if the |
475 | 486 | chosen by the compressor and returns Z_NEED_DICT; otherwise it sets |
476 | 487 | strm->adler to the Adler-32 checksum of all output produced so far (that is, |
477 | 488 | total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described |
478 | below. At the end of the stream, inflate() checks that its computed adler32 | |
489 | below. At the end of the stream, inflate() checks that its computed Adler-32 | |
479 | 490 | checksum is equal to that saved by the compressor and returns Z_STREAM_END |
480 | 491 | only if the checksum is correct. |
481 | 492 | |
482 | 493 | inflate() can decompress and check either zlib-wrapped or gzip-wrapped |
483 | 494 | deflate data. The header type is detected automatically, if requested when |
484 | 495 | initializing with inflateInit2(). Any information contained in the gzip |
485 | header is not retained, so applications that need that information should | |
486 | instead use raw inflate, see inflateInit2() below, or inflateBack() and | |
487 | perform their own processing of the gzip header and trailer. When processing | |
496 | header is not retained unless inflateGetHeader() is used. When processing | |
488 | 497 | gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output |
489 | producted so far. The CRC-32 is checked against the gzip trailer. | |
498 | produced so far. The CRC-32 is checked against the gzip trailer, as is the | |
499 | uncompressed length, modulo 2^32. | |
490 | 500 | |
491 | 501 | inflate() returns Z_OK if some progress has been made (more input processed |
492 | 502 | or more output produced), Z_STREAM_END if the end of the compressed data has |
493 | 503 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a |
494 | 504 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was |
495 | 505 | corrupted (input stream not conforming to the zlib format or incorrect check |
496 | value), Z_STREAM_ERROR if the stream structure was inconsistent (for example | |
497 | next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, | |
498 | Z_BUF_ERROR if no progress is possible or if there was not enough room in the | |
499 | output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and | |
506 | value, in which case strm->msg points to a string with a more specific | |
507 | error), Z_STREAM_ERROR if the stream structure was inconsistent (for example | |
508 | next_in or next_out was Z_NULL, or the state was inadvertently written over | |
509 | by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR | |
510 | if no progress was possible or if there was not enough room in the output | |
511 | buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and | |
500 | 512 | inflate() can be called again with more input and more output space to |
501 | 513 | continue decompressing. If Z_DATA_ERROR is returned, the application may |
502 | 514 | then call inflateSync() to look for a good compression block if a partial |
503 | recovery of the data is desired. | |
515 | recovery of the data is to be attempted. | |
504 | 516 | */ |
505 | 517 | |
506 | 518 | |
510 | 522 | This function discards any unprocessed input and does not flush any pending |
511 | 523 | output. |
512 | 524 | |
513 | inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state | |
514 | was inconsistent. In the error case, msg may be set but then points to a | |
515 | static string (which must not be deallocated). | |
525 | inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state | |
526 | was inconsistent. | |
516 | 527 | */ |
517 | 528 | |
518 | 529 | |
543 | 554 | compression at the expense of memory usage. The default value is 15 if |
544 | 555 | deflateInit is used instead. |
545 | 556 | |
557 | For the current implementation of deflate(), a windowBits value of 8 (a | |
558 | window size of 256 bytes) is not supported. As a result, a request for 8 | |
559 | will result in 9 (a 512-byte window). In that case, providing 8 to | |
560 | inflateInit2() will result in an error when the zlib header with 9 is | |
561 | checked against the initialization of inflate(). The remedy is to not use 8 | |
562 | with deflateInit2() with this initialization, or at least in that case use 9 | |
563 | with inflateInit2(). | |
564 | ||
546 | 565 | windowBits can also be -8..-15 for raw deflate. In this case, -windowBits |
547 | 566 | determines the window size. deflate() will then generate raw deflate data |
548 | with no zlib header or trailer, and will not compute an adler32 check value. | |
567 | with no zlib header or trailer, and will not compute a check value. | |
549 | 568 | |
550 | 569 | windowBits can also be greater than 15 for optional gzip encoding. Add |
551 | 570 | 16 to windowBits to write a simple gzip header and trailer around the |
552 | 571 | compressed data instead of a zlib wrapper. The gzip header will have no |
553 | 572 | file name, no extra data, no comment, no modification time (set to zero), no |
554 | header crc, and the operating system will be set to 255 (unknown). If a | |
555 | gzip stream is being written, strm->adler is a crc32 instead of an adler32. | |
573 | header crc, and the operating system will be set to the appropriate value, | |
574 | if the operating system was determined at compile time. If a gzip stream is | |
575 | being written, strm->adler is a CRC-32 instead of an Adler-32. | |
576 | ||
577 | For raw deflate or gzip encoding, a request for a 256-byte window is | |
578 | rejected as invalid, since only the zlib header provides a means of | |
579 | transmitting the window size to the decompressor. | |
556 | 580 | |
557 | 581 | The memLevel parameter specifies how much memory should be allocated |
558 | 582 | for the internal compression state. memLevel=1 uses minimum memory but is |
613 | 637 | addition, the current implementation of deflate will use at most the window |
614 | 638 | size minus 262 bytes of the provided dictionary. |
615 | 639 | |
616 | Upon return of this function, strm->adler is set to the adler32 value | |
640 | Upon return of this function, strm->adler is set to the Adler-32 value | |
617 | 641 | of the dictionary; the decompressor may later use this value to determine |
618 | which dictionary has been used by the compressor. (The adler32 value | |
642 | which dictionary has been used by the compressor. (The Adler-32 value | |
619 | 643 | applies to the whole dictionary even if only a subset of the dictionary is |
620 | 644 | actually used by the compressor.) If a raw deflate was requested, then the |
621 | adler32 value is not computed and strm->adler is not set. | |
645 | Adler-32 value is not computed and strm->adler is not set. | |
622 | 646 | |
623 | 647 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a |
624 | 648 | parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is |
625 | 649 | inconsistent (for example if deflate has already been called for this stream |
626 | 650 | or if not at a block boundary for raw deflate). deflateSetDictionary does |
627 | 651 | not perform any compression: this will be done by deflate(). |
652 | */ | |
653 | ||
654 | ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, | |
655 | Bytef *dictionary, | |
656 | uInt *dictLength)); | |
657 | /* | |
658 | Returns the sliding dictionary being maintained by deflate. dictLength is | |
659 | set to the number of bytes in the dictionary, and that many bytes are copied | |
660 | to dictionary. dictionary must have enough space, where 32768 bytes is | |
661 | always enough. If deflateGetDictionary() is called with dictionary equal to | |
662 | Z_NULL, then only the dictionary length is returned, and nothing is copied. | |
663 | Similary, if dictLength is Z_NULL, then it is not set. | |
664 | ||
665 | deflateGetDictionary() may return a length less than the window size, even | |
666 | when more than the window size in input has been provided. It may return up | |
667 | to 258 bytes less in that case, due to how zlib's implementation of deflate | |
668 | manages the sliding window and lookahead for matches, where matches can be | |
669 | up to 258 bytes long. If the application needs the last window-size bytes of | |
670 | input, then that would need to be saved by the application outside of zlib. | |
671 | ||
672 | deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the | |
673 | stream state is inconsistent. | |
628 | 674 | */ |
629 | 675 | |
630 | 676 | ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, |
647 | 693 | |
648 | 694 | ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); |
649 | 695 | /* |
650 | This function is equivalent to deflateEnd followed by deflateInit, | |
651 | but does not free and reallocate all the internal compression state. The | |
652 | stream will keep the same compression level and any other attributes that | |
653 | may have been set by deflateInit2. | |
696 | This function is equivalent to deflateEnd followed by deflateInit, but | |
697 | does not free and reallocate the internal compression state. The stream | |
698 | will leave the compression level and any other attributes that may have been | |
699 | set unchanged. | |
654 | 700 | |
655 | 701 | deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
656 | 702 | stream state was inconsistent (such as zalloc or state being Z_NULL). |
661 | 707 | int strategy)); |
662 | 708 | /* |
663 | 709 | Dynamically update the compression level and compression strategy. The |
664 | interpretation of level and strategy is as in deflateInit2. This can be | |
710 | interpretation of level and strategy is as in deflateInit2(). This can be | |
665 | 711 | used to switch between compression and straight copy of the input data, or |
666 | 712 | to switch to a different kind of input data requiring a different strategy. |
667 | If the compression level is changed, the input available so far is | |
668 | compressed with the old level (and may be flushed); the new level will take | |
669 | effect only at the next call of deflate(). | |
670 | ||
671 | Before the call of deflateParams, the stream state must be set as for | |
672 | a call of deflate(), since the currently available input may have to be | |
673 | compressed and flushed. In particular, strm->avail_out must be non-zero. | |
674 | ||
675 | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source | |
676 | stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if | |
677 | strm->avail_out was zero. | |
713 | If the compression approach (which is a function of the level) or the | |
714 | strategy is changed, and if any input has been consumed in a previous | |
715 | deflate() call, then the input available so far is compressed with the old | |
716 | level and strategy using deflate(strm, Z_BLOCK). There are three approaches | |
717 | for the compression levels 0, 1..3, and 4..9 respectively. The new level | |
718 | and strategy will take effect at the next call of deflate(). | |
719 | ||
720 | If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does | |
721 | not have enough output space to complete, then the parameter change will not | |
722 | take effect. In this case, deflateParams() can be called again with the | |
723 | same parameters and more output space to try again. | |
724 | ||
725 | In order to assure a change in the parameters on the first try, the | |
726 | deflate stream should be flushed using deflate() with Z_BLOCK or other flush | |
727 | request until strm.avail_out is not zero, before calling deflateParams(). | |
728 | Then no more input data should be provided before the deflateParams() call. | |
729 | If this is done, the old level and strategy will be applied to the data | |
730 | compressed before deflateParams(), and the new level and strategy will be | |
731 | applied to the the data compressed after deflateParams(). | |
732 | ||
733 | deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream | |
734 | state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if | |
735 | there was not enough output space to complete the compression of the | |
736 | available input data before a change in the strategy or approach. Note that | |
737 | in the case of a Z_BUF_ERROR, the parameters are not changed. A return | |
738 | value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be | |
739 | retried with more output space. | |
678 | 740 | */ |
679 | 741 | |
680 | 742 | ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, |
792 | 854 | is for use with other formats that use the deflate compressed data format |
793 | 855 | such as zip. Those formats provide their own check values. If a custom |
794 | 856 | format is developed using the raw deflate format for compressed data, it is |
795 | recommended that a check value such as an adler32 or a crc32 be applied to | |
857 | recommended that a check value such as an Adler-32 or a CRC-32 be applied to | |
796 | 858 | the uncompressed data as is done in the zlib, gzip, and zip formats. For |
797 | 859 | most applications, the zlib format should be used as is. Note that comments |
798 | 860 | above on the use in deflateInit2() applies to the magnitude of windowBits. |
801 | 863 | 32 to windowBits to enable zlib and gzip decoding with automatic header |
802 | 864 | detection, or add 16 to decode only the gzip format (the zlib format will |
803 | 865 | return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a |
804 | crc32 instead of an adler32. | |
866 | CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see | |
867 | below), inflate() will not automatically decode concatenated gzip streams. | |
868 | inflate() will return Z_STREAM_END at the end of the gzip stream. The state | |
869 | would need to be reset to continue decoding a subsequent gzip stream. | |
805 | 870 | |
806 | 871 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
807 | 872 | memory, Z_VERSION_ERROR if the zlib library version is incompatible with the |
822 | 887 | Initializes the decompression dictionary from the given uncompressed byte |
823 | 888 | sequence. This function must be called immediately after a call of inflate, |
824 | 889 | if that call returned Z_NEED_DICT. The dictionary chosen by the compressor |
825 | can be determined from the adler32 value returned by that call of inflate. | |
890 | can be determined from the Adler-32 value returned by that call of inflate. | |
826 | 891 | The compressor and decompressor must use exactly the same dictionary (see |
827 | 892 | deflateSetDictionary). For raw inflate, this function can be called at any |
828 | 893 | time to set the dictionary. If the provided dictionary is smaller than the |
833 | 898 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
834 | 899 | parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is |
835 | 900 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the |
836 | expected one (incorrect adler32 value). inflateSetDictionary does not | |
901 | expected one (incorrect Adler-32 value). inflateSetDictionary does not | |
837 | 902 | perform any decompression: this will be done by subsequent calls of |
838 | 903 | inflate(). |
839 | 904 | */ |
891 | 956 | ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); |
892 | 957 | /* |
893 | 958 | This function is equivalent to inflateEnd followed by inflateInit, |
894 | but does not free and reallocate all the internal decompression state. The | |
959 | but does not free and reallocate the internal decompression state. The | |
895 | 960 | stream will keep attributes that may have been set by inflateInit2. |
896 | 961 | |
897 | 962 | inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
903 | 968 | /* |
904 | 969 | This function is the same as inflateReset, but it also permits changing |
905 | 970 | the wrap and window size requests. The windowBits parameter is interpreted |
906 | the same as it is for inflateInit2. | |
971 | the same as it is for inflateInit2. If the window size is changed, then the | |
972 | memory allocated for the window is freed, and the window will be reallocated | |
973 | by inflate() if needed. | |
907 | 974 | |
908 | 975 | inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source |
909 | 976 | stream state was inconsistent (such as zalloc or state being Z_NULL), or if |
955 | 1022 | location in the input stream can be determined from avail_in and data_type |
956 | 1023 | as noted in the description for the Z_BLOCK flush parameter for inflate. |
957 | 1024 | |
958 | inflateMark returns the value noted above or -1 << 16 if the provided | |
1025 | inflateMark returns the value noted above, or -65536 if the provided | |
959 | 1026 | source stream state was inconsistent. |
960 | 1027 | */ |
961 | 1028 | |
1047 | 1114 | This routine would normally be used in a utility that reads zip or gzip |
1048 | 1115 | files and writes out uncompressed files. The utility would decode the |
1049 | 1116 | header and process the trailer on its own, hence this routine expects only |
1050 | the raw deflate stream to decompress. This is different from the normal | |
1051 | behavior of inflate(), which expects either a zlib or gzip header and | |
1052 | trailer around the deflate stream. | |
1117 | the raw deflate stream to decompress. This is different from the default | |
1118 | behavior of inflate(), which expects a zlib header and trailer around the | |
1119 | deflate stream. | |
1053 | 1120 | |
1054 | 1121 | inflateBack() uses two subroutines supplied by the caller that are then |
1055 | 1122 | called by inflateBack() for input and output. inflateBack() calls those |
1058 | 1125 | parameters and return types are defined above in the in_func and out_func |
1059 | 1126 | typedefs. inflateBack() will call in(in_desc, &buf) which should return the |
1060 | 1127 | number of bytes of provided input, and a pointer to that input in buf. If |
1061 | there is no input available, in() must return zero--buf is ignored in that | |
1062 | case--and inflateBack() will return a buffer error. inflateBack() will call | |
1063 | out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() | |
1064 | should return zero on success, or non-zero on failure. If out() returns | |
1065 | non-zero, inflateBack() will return with an error. Neither in() nor out() | |
1066 | are permitted to change the contents of the window provided to | |
1128 | there is no input available, in() must return zero -- buf is ignored in that | |
1129 | case -- and inflateBack() will return a buffer error. inflateBack() will | |
1130 | call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. | |
1131 | out() should return zero on success, or non-zero on failure. If out() | |
1132 | returns non-zero, inflateBack() will return with an error. Neither in() nor | |
1133 | out() are permitted to change the contents of the window provided to | |
1067 | 1134 | inflateBackInit(), which is also the buffer that out() uses to write from. |
1068 | 1135 | The length written by out() will be at most the window size. Any non-zero |
1069 | 1136 | amount of input may be provided by in(). |
1091 | 1158 | using strm->next_in which will be Z_NULL only if in() returned an error. If |
1092 | 1159 | strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning |
1093 | 1160 | non-zero. (in() will always be called before out(), so strm->next_in is |
1094 | assured to be defined if out() returns non-zero.) Note that inflateBack() | |
1161 | assured to be defined if out() returns non-zero.) Note that inflateBack() | |
1095 | 1162 | cannot return Z_OK. |
1096 | 1163 | */ |
1097 | 1164 | |
1113 | 1180 | 7.6: size of z_off_t |
1114 | 1181 | |
1115 | 1182 | Compiler, assembler, and debug options: |
1116 | 8: DEBUG | |
1183 | 8: ZLIB_DEBUG | |
1117 | 1184 | 9: ASMV or ASMINF -- use ASM code |
1118 | 1185 | 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention |
1119 | 1186 | 11: 0 (reserved) |
1163 | 1230 | the byte length of the source buffer. Upon entry, destLen is the total size |
1164 | 1231 | of the destination buffer, which must be at least the value returned by |
1165 | 1232 | compressBound(sourceLen). Upon exit, destLen is the actual size of the |
1166 | compressed buffer. | |
1233 | compressed data. compress() is equivalent to compress2() with a level | |
1234 | parameter of Z_DEFAULT_COMPRESSION. | |
1167 | 1235 | |
1168 | 1236 | compress returns Z_OK if success, Z_MEM_ERROR if there was not |
1169 | 1237 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
1179 | 1247 | length of the source buffer. Upon entry, destLen is the total size of the |
1180 | 1248 | destination buffer, which must be at least the value returned by |
1181 | 1249 | compressBound(sourceLen). Upon exit, destLen is the actual size of the |
1182 | compressed buffer. | |
1250 | compressed data. | |
1183 | 1251 | |
1184 | 1252 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
1185 | 1253 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, |
1202 | 1270 | uncompressed data. (The size of the uncompressed data must have been saved |
1203 | 1271 | previously by the compressor and transmitted to the decompressor by some |
1204 | 1272 | mechanism outside the scope of this compression library.) Upon exit, destLen |
1205 | is the actual size of the uncompressed buffer. | |
1273 | is the actual size of the uncompressed data. | |
1206 | 1274 | |
1207 | 1275 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
1208 | 1276 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
1209 | 1277 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In |
1210 | 1278 | the case where there is not enough room, uncompress() will fill the output |
1211 | 1279 | buffer with the uncompressed data up to that point. |
1280 | */ | |
1281 | ||
1282 | ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, | |
1283 | const Bytef *source, uLong *sourceLen)); | |
1284 | /* | |
1285 | Same as uncompress, except that sourceLen is a pointer, where the | |
1286 | length of the source is *sourceLen. On return, *sourceLen is the number of | |
1287 | source bytes consumed. | |
1212 | 1288 | */ |
1213 | 1289 | |
1214 | 1290 | /* gzip file access functions */ |
1289 | 1365 | default buffer size is 8192 bytes. This function must be called after |
1290 | 1366 | gzopen() or gzdopen(), and before any other calls that read or write the |
1291 | 1367 | file. The buffer memory allocation is always deferred to the first read or |
1292 | write. Two buffers are allocated, either both of the specified size when | |
1293 | writing, or one of the specified size and the other twice that size when | |
1294 | reading. A larger buffer size of, for example, 64K or 128K bytes will | |
1295 | noticeably increase the speed of decompression (reading). | |
1368 | write. Three times that size in buffer space is allocated. A larger buffer | |
1369 | size of, for example, 64K or 128K bytes will noticeably increase the speed | |
1370 | of decompression (reading). | |
1296 | 1371 | |
1297 | 1372 | The new buffer size also affects the maximum length for gzprintf(). |
1298 | 1373 | |
1303 | 1378 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); |
1304 | 1379 | /* |
1305 | 1380 | Dynamically update the compression level or strategy. See the description |
1306 | of deflateInit2 for the meaning of these parameters. | |
1307 | ||
1308 | gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not | |
1309 | opened for writing. | |
1381 | of deflateInit2 for the meaning of these parameters. Previously provided | |
1382 | data is flushed before the parameter change. | |
1383 | ||
1384 | gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not | |
1385 | opened for writing, Z_ERRNO if there is an error writing the flushed data, | |
1386 | or Z_MEM_ERROR if there is a memory allocation error. | |
1310 | 1387 | */ |
1311 | 1388 | |
1312 | 1389 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); |
1334 | 1411 | case. |
1335 | 1412 | |
1336 | 1413 | gzread returns the number of uncompressed bytes actually read, less than |
1337 | len for end of file, or -1 for error. | |
1414 | len for end of file, or -1 for error. If len is too large to fit in an int, | |
1415 | then nothing is read, -1 is returned, and the error state is set to | |
1416 | Z_STREAM_ERROR. | |
1417 | */ | |
1418 | ||
1419 | ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, | |
1420 | gzFile file)); | |
1421 | /* | |
1422 | Read up to nitems items of size size from file to buf, otherwise operating | |
1423 | as gzread() does. This duplicates the interface of stdio's fread(), with | |
1424 | size_t request and return types. If the library defines size_t, then | |
1425 | z_size_t is identical to size_t. If not, then z_size_t is an unsigned | |
1426 | integer type that can contain a pointer. | |
1427 | ||
1428 | gzfread() returns the number of full items read of size size, or zero if | |
1429 | the end of the file was reached and a full item could not be read, or if | |
1430 | there was an error. gzerror() must be consulted if zero is returned in | |
1431 | order to determine if there was an error. If the multiplication of size and | |
1432 | nitems overflows, i.e. the product does not fit in a z_size_t, then nothing | |
1433 | is read, zero is returned, and the error state is set to Z_STREAM_ERROR. | |
1434 | ||
1435 | In the event that the end of file is reached and only a partial item is | |
1436 | available at the end, i.e. the remaining uncompressed data length is not a | |
1437 | multiple of size, then the final partial item is nevetheless read into buf | |
1438 | and the end-of-file flag is set. The length of the partial item read is not | |
1439 | provided, but could be inferred from the result of gztell(). This behavior | |
1440 | is the same as the behavior of fread() implementations in common libraries, | |
1441 | but it prevents the direct use of gzfread() to read a concurrently written | |
1442 | file, reseting and retrying on end-of-file, when size is not 1. | |
1338 | 1443 | */ |
1339 | 1444 | |
1340 | 1445 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, |
1345 | 1450 | error. |
1346 | 1451 | */ |
1347 | 1452 | |
1453 | ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, | |
1454 | z_size_t nitems, gzFile file)); | |
1455 | /* | |
1456 | gzfwrite() writes nitems items of size size from buf to file, duplicating | |
1457 | the interface of stdio's fwrite(), with size_t request and return types. If | |
1458 | the library defines size_t, then z_size_t is identical to size_t. If not, | |
1459 | then z_size_t is an unsigned integer type that can contain a pointer. | |
1460 | ||
1461 | gzfwrite() returns the number of full items written of size size, or zero | |
1462 | if there was an error. If the multiplication of size and nitems overflows, | |
1463 | i.e. the product does not fit in a z_size_t, then nothing is written, zero | |
1464 | is returned, and the error state is set to Z_STREAM_ERROR. | |
1465 | */ | |
1466 | ||
1348 | 1467 | ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); |
1349 | 1468 | /* |
1350 | 1469 | Converts, formats, and writes the arguments to the compressed file under |
1351 | 1470 | control of the format string, as in fprintf. gzprintf returns the number of |
1352 | uncompressed bytes actually written, or 0 in case of error. The number of | |
1353 | uncompressed bytes written is limited to 8191, or one less than the buffer | |
1354 | size given to gzbuffer(). The caller should assure that this limit is not | |
1355 | exceeded. If it is exceeded, then gzprintf() will return an error (0) with | |
1356 | nothing written. In this case, there may also be a buffer overflow with | |
1357 | unpredictable consequences, which is possible only if zlib was compiled with | |
1358 | the insecure functions sprintf() or vsprintf() because the secure snprintf() | |
1359 | or vsnprintf() functions were not available. This can be determined using | |
1360 | zlibCompileFlags(). | |
1471 | uncompressed bytes actually written, or a negative zlib error code in case | |
1472 | of error. The number of uncompressed bytes written is limited to 8191, or | |
1473 | one less than the buffer size given to gzbuffer(). The caller should assure | |
1474 | that this limit is not exceeded. If it is exceeded, then gzprintf() will | |
1475 | return an error (0) with nothing written. In this case, there may also be a | |
1476 | buffer overflow with unpredictable consequences, which is possible only if | |
1477 | zlib was compiled with the insecure functions sprintf() or vsprintf() | |
1478 | because the secure snprintf() or vsnprintf() functions were not available. | |
1479 | This can be determined using zlibCompileFlags(). | |
1361 | 1480 | */ |
1362 | 1481 | |
1363 | 1482 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); |
1417 | 1536 | If the flush parameter is Z_FINISH, the remaining data is written and the |
1418 | 1537 | gzip stream is completed in the output. If gzwrite() is called again, a new |
1419 | 1538 | gzip stream will be started in the output. gzread() is able to read such |
1420 | concatented gzip streams. | |
1539 | concatenated gzip streams. | |
1421 | 1540 | |
1422 | 1541 | gzflush should be called only when strictly necessary because it will |
1423 | 1542 | degrade compression if called too often. |
1571 | 1690 | return the updated checksum. If buf is Z_NULL, this function returns the |
1572 | 1691 | required initial value for the checksum. |
1573 | 1692 | |
1574 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed | |
1693 | An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed | |
1575 | 1694 | much faster. |
1576 | 1695 | |
1577 | 1696 | Usage example: |
1582 | 1701 | adler = adler32(adler, buffer, length); |
1583 | 1702 | } |
1584 | 1703 | if (adler != original_adler) error(); |
1704 | */ | |
1705 | ||
1706 | ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, | |
1707 | z_size_t len)); | |
1708 | /* | |
1709 | Same as adler32(), but with a size_t length. | |
1585 | 1710 | */ |
1586 | 1711 | |
1587 | 1712 | /* |
1611 | 1736 | crc = crc32(crc, buffer, length); |
1612 | 1737 | } |
1613 | 1738 | if (crc != original_crc) error(); |
1739 | */ | |
1740 | ||
1741 | ZEXTERN uLong ZEXPORT crc32_z OF((uLong adler, const Bytef *buf, | |
1742 | z_size_t len)); | |
1743 | /* | |
1744 | Same as crc32(), but with a size_t length. | |
1614 | 1745 | */ |
1615 | 1746 | |
1616 | 1747 | /* |
1643 | 1774 | unsigned char FAR *window, |
1644 | 1775 | const char *version, |
1645 | 1776 | int stream_size)); |
1646 | #define deflateInit(strm, level) \ | |
1647 | deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1648 | #define inflateInit(strm) \ | |
1649 | inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1650 | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | |
1651 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | |
1652 | (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1653 | #define inflateInit2(strm, windowBits) \ | |
1654 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ | |
1655 | (int)sizeof(z_stream)) | |
1656 | #define inflateBackInit(strm, windowBits, window) \ | |
1657 | inflateBackInit_((strm), (windowBits), (window), \ | |
1658 | ZLIB_VERSION, (int)sizeof(z_stream)) | |
1777 | #ifdef Z_PREFIX_SET | |
1778 | # define z_deflateInit(strm, level) \ | |
1779 | deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1780 | # define z_inflateInit(strm) \ | |
1781 | inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1782 | # define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | |
1783 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | |
1784 | (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1785 | # define z_inflateInit2(strm, windowBits) \ | |
1786 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ | |
1787 | (int)sizeof(z_stream)) | |
1788 | # define z_inflateBackInit(strm, windowBits, window) \ | |
1789 | inflateBackInit_((strm), (windowBits), (window), \ | |
1790 | ZLIB_VERSION, (int)sizeof(z_stream)) | |
1791 | #else | |
1792 | # define deflateInit(strm, level) \ | |
1793 | deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1794 | # define inflateInit(strm) \ | |
1795 | inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1796 | # define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ | |
1797 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ | |
1798 | (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) | |
1799 | # define inflateInit2(strm, windowBits) \ | |
1800 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ | |
1801 | (int)sizeof(z_stream)) | |
1802 | # define inflateBackInit(strm, windowBits, window) \ | |
1803 | inflateBackInit_((strm), (windowBits), (window), \ | |
1804 | ZLIB_VERSION, (int)sizeof(z_stream)) | |
1805 | #endif | |
1659 | 1806 | |
1660 | 1807 | #ifndef Z_SOLO |
1661 | 1808 | |
1675 | 1822 | #ifdef Z_PREFIX_SET |
1676 | 1823 | # undef z_gzgetc |
1677 | 1824 | # define z_gzgetc(g) \ |
1678 | ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) | |
1825 | ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) | |
1679 | 1826 | #else |
1680 | 1827 | # define gzgetc(g) \ |
1681 | ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) | |
1828 | ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) | |
1682 | 1829 | #endif |
1683 | 1830 | |
1684 | 1831 | /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or |
1736 | 1883 | |
1737 | 1884 | #endif /* !Z_SOLO */ |
1738 | 1885 | |
1739 | /* hack for buggy compilers */ | |
1740 | #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) | |
1741 | struct internal_state {int dummy;}; | |
1742 | #endif | |
1743 | ||
1744 | 1886 | /* undocumented functions */ |
1745 | 1887 | ZEXTERN const char * ZEXPORT zError OF((int)); |
1746 | 1888 | ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); |
1747 | 1889 | ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); |
1748 | 1890 | ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); |
1891 | ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); | |
1892 | ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); | |
1749 | 1893 | ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); |
1750 | 1894 | ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); |
1751 | #if defined(_WIN32) && !defined(Z_SOLO) | |
1895 | #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO) | |
1752 | 1896 | ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, |
1753 | 1897 | const char *mode)); |
1754 | 1898 | #endif |
0 | 0 | /* zutil.c -- target dependent utility functions for the compression library |
1 | * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. | |
1 | * Copyright (C) 1995-2017 Jean-loup Gailly | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
9 | 9 | # include "gzguts.h" |
10 | 10 | #endif |
11 | 11 | |
12 | #ifndef NO_DUMMY_DECL | |
13 | struct internal_state {int dummy;}; /* for buggy compilers */ | |
14 | #endif | |
15 | ||
16 | 12 | z_const char * const z_errmsg[10] = { |
17 | "need dictionary", /* Z_NEED_DICT 2 */ | |
18 | "stream end", /* Z_STREAM_END 1 */ | |
19 | "", /* Z_OK 0 */ | |
20 | "file error", /* Z_ERRNO (-1) */ | |
21 | "stream error", /* Z_STREAM_ERROR (-2) */ | |
22 | "data error", /* Z_DATA_ERROR (-3) */ | |
23 | "insufficient memory", /* Z_MEM_ERROR (-4) */ | |
24 | "buffer error", /* Z_BUF_ERROR (-5) */ | |
25 | "incompatible version",/* Z_VERSION_ERROR (-6) */ | |
26 | ""}; | |
13 | (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ | |
14 | (z_const char *)"stream end", /* Z_STREAM_END 1 */ | |
15 | (z_const char *)"", /* Z_OK 0 */ | |
16 | (z_const char *)"file error", /* Z_ERRNO (-1) */ | |
17 | (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */ | |
18 | (z_const char *)"data error", /* Z_DATA_ERROR (-3) */ | |
19 | (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */ | |
20 | (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */ | |
21 | (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ | |
22 | (z_const char *)"" | |
23 | }; | |
27 | 24 | |
28 | 25 | |
29 | 26 | const char * ZEXPORT zlibVersion() |
60 | 57 | case 8: flags += 2 << 6; break; |
61 | 58 | default: flags += 3 << 6; |
62 | 59 | } |
63 | #ifdef DEBUG | |
60 | #ifdef ZLIB_DEBUG | |
64 | 61 | flags += 1 << 8; |
65 | 62 | #endif |
66 | 63 | #if defined(ASMV) || defined(ASMINF) |
114 | 111 | return flags; |
115 | 112 | } |
116 | 113 | |
117 | #ifdef DEBUG | |
118 | ||
114 | #ifdef ZLIB_DEBUG | |
115 | #include <stdlib.h> | |
119 | 116 | # ifndef verbose |
120 | 117 | # define verbose 0 |
121 | 118 | # endif |
218 | 215 | |
219 | 216 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) |
220 | 217 | { |
221 | voidpf buf = opaque; /* just to make some compilers happy */ | |
218 | voidpf buf; | |
222 | 219 | ulg bsize = (ulg)items*size; |
220 | ||
221 | (void)opaque; | |
223 | 222 | |
224 | 223 | /* If we allocate less than 65520 bytes, we assume that farmalloc |
225 | 224 | * will return a usable pointer which doesn't have to be normalized. |
243 | 242 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) |
244 | 243 | { |
245 | 244 | int n; |
245 | ||
246 | (void)opaque; | |
247 | ||
246 | 248 | if (*(ush*)&ptr != 0) { /* object < 64K */ |
247 | 249 | farfree(ptr); |
248 | 250 | return; |
258 | 260 | next_ptr--; |
259 | 261 | return; |
260 | 262 | } |
261 | ptr = opaque; /* just to make some compilers happy */ | |
262 | 263 | Assert(0, "zcfree: ptr not found"); |
263 | 264 | } |
264 | 265 | |
277 | 278 | |
278 | 279 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) |
279 | 280 | { |
280 | if (opaque) opaque = 0; /* to make compiler happy */ | |
281 | (void)opaque; | |
281 | 282 | return _halloc((long)items, size); |
282 | 283 | } |
283 | 284 | |
284 | 285 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) |
285 | 286 | { |
286 | if (opaque) opaque = 0; /* to make compiler happy */ | |
287 | (void)opaque; | |
287 | 288 | _hfree(ptr); |
288 | 289 | } |
289 | 290 | |
305 | 306 | unsigned items; |
306 | 307 | unsigned size; |
307 | 308 | { |
308 | if (opaque) items += size - size; /* make compiler happy */ | |
309 | (void)opaque; | |
309 | 310 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : |
310 | 311 | (voidpf)calloc(items, size); |
311 | 312 | } |
314 | 315 | voidpf opaque; |
315 | 316 | voidpf ptr; |
316 | 317 | { |
318 | (void)opaque; | |
317 | 319 | free(ptr); |
318 | if (opaque) return; /* make compiler happy */ | |
319 | 320 | } |
320 | 321 | |
321 | 322 | #endif /* MY_ZCALLOC */ |
0 | 0 | /* zutil.h -- internal interface and configuration of the compression library |
1 | * Copyright (C) 1995-2013 Jean-loup Gailly. | |
1 | * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler | |
2 | 2 | * For conditions of distribution and use, see copyright notice in zlib.h |
3 | 3 | */ |
4 | 4 | |
35 | 35 | #ifndef local |
36 | 36 | # define local static |
37 | 37 | #endif |
38 | /* compile with -Dlocal if your debugger can't find static symbols */ | |
38 | /* since "static" is used to mean two completely different things in C, we | |
39 | define "local" for the non-static meaning of "static", for readability | |
40 | (compile with -Dlocal if your debugger can't find static symbols) */ | |
39 | 41 | |
40 | 42 | typedef unsigned char uch; |
41 | 43 | typedef uch FAR uchf; |
97 | 99 | #endif |
98 | 100 | |
99 | 101 | #ifdef AMIGA |
100 | # define OS_CODE 0x01 | |
102 | # define OS_CODE 1 | |
101 | 103 | #endif |
102 | 104 | |
103 | 105 | #if defined(VAXC) || defined(VMS) |
104 | # define OS_CODE 0x02 | |
106 | # define OS_CODE 2 | |
105 | 107 | # define F_OPEN(name, mode) \ |
106 | 108 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") |
107 | 109 | #endif |
108 | 110 | |
111 | #ifdef __370__ | |
112 | # if __TARGET_LIB__ < 0x20000000 | |
113 | # define OS_CODE 4 | |
114 | # elif __TARGET_LIB__ < 0x40000000 | |
115 | # define OS_CODE 11 | |
116 | # else | |
117 | # define OS_CODE 8 | |
118 | # endif | |
119 | #endif | |
120 | ||
109 | 121 | #if defined(ATARI) || defined(atarist) |
110 | # define OS_CODE 0x05 | |
122 | # define OS_CODE 5 | |
111 | 123 | #endif |
112 | 124 | |
113 | 125 | #ifdef OS2 |
114 | # define OS_CODE 0x06 | |
126 | # define OS_CODE 6 | |
115 | 127 | # if defined(M_I86) && !defined(Z_SOLO) |
116 | 128 | # include <malloc.h> |
117 | 129 | # endif |
118 | 130 | #endif |
119 | 131 | |
120 | 132 | #if defined(MACOS) || defined(TARGET_OS_MAC) |
121 | # define OS_CODE 0x07 | |
133 | # define OS_CODE 7 | |
122 | 134 | # ifndef Z_SOLO |
123 | 135 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os |
124 | 136 | # include <unix.h> /* for fdopen */ |
130 | 142 | # endif |
131 | 143 | #endif |
132 | 144 | |
133 | #ifdef TOPS20 | |
134 | # define OS_CODE 0x0a | |
135 | #endif | |
136 | ||
137 | #ifdef WIN32 | |
138 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ | |
139 | # define OS_CODE 0x0b | |
140 | # endif | |
141 | #endif | |
142 | ||
143 | #ifdef __50SERIES /* Prime/PRIMOS */ | |
144 | # define OS_CODE 0x0f | |
145 | #ifdef __acorn | |
146 | # define OS_CODE 13 | |
147 | #endif | |
148 | ||
149 | #if defined(WIN32) && !defined(__CYGWIN__) | |
150 | # define OS_CODE 10 | |
151 | #endif | |
152 | ||
153 | #ifdef _BEOS_ | |
154 | # define OS_CODE 16 | |
155 | #endif | |
156 | ||
157 | #ifdef __TOS_OS400__ | |
158 | # define OS_CODE 18 | |
159 | #endif | |
160 | ||
161 | #ifdef __APPLE__ | |
162 | # define OS_CODE 19 | |
145 | 163 | #endif |
146 | 164 | |
147 | 165 | #if defined(_BEOS_) || defined(RISCOS) |
176 | 194 | /* common defaults */ |
177 | 195 | |
178 | 196 | #ifndef OS_CODE |
179 | # define OS_CODE 0x03 /* assume Unix */ | |
197 | # define OS_CODE 3 /* assume Unix */ | |
180 | 198 | #endif |
181 | 199 | |
182 | 200 | #ifndef F_OPEN |
215 | 233 | #endif |
216 | 234 | |
217 | 235 | /* Diagnostic functions */ |
218 | #ifdef DEBUG | |
236 | #ifdef ZLIB_DEBUG | |
219 | 237 | # include <stdio.h> |
220 | 238 | extern int ZLIB_INTERNAL z_verbose; |
221 | 239 | extern void ZLIB_INTERNAL z_error OF((char *m)); |
0 | 0 | /* |
1 | * Copyright (c) Tony Bybell 1999-2016. | |
1 | * Copyright (c) Tony Bybell 1999-2017. | |
2 | 2 | * |
3 | 3 | * This program is free software; you can redistribute it and/or |
4 | 4 | * modify it under the terms of the GNU General Public License |
3501 | 3501 | char *namex; |
3502 | 3502 | int was_packed = HIER_DEPACK_ALLOC; |
3503 | 3503 | |
3504 | int row = 0, bit = 0; | |
3505 | int row2 = 0, bit2 = 0; | |
3506 | int is_2d = 0; | |
3507 | int iy, offsety; | |
3508 | char *namey; | |
3509 | char sep2d = ':'; | |
3510 | ||
3504 | 3511 | namex = hier_decompress_flagged(n[0]->nname, &was_packed); |
3505 | 3512 | |
3506 | 3513 | offset = strlen(namex); |
3510 | 3517 | } |
3511 | 3518 | if(ix>-1) offset=ix; |
3512 | 3519 | |
3513 | nam=(char *)wave_alloca(offset+40); | |
3520 | if(ix>3) /* is_2d is for handling 2-d stored in 1-d vector */ | |
3521 | { | |
3522 | if(namex[ix-1]==']') | |
3523 | { | |
3524 | int j = ix-2; | |
3525 | for(;j>=0;j--) | |
3526 | { | |
3527 | if(namex[j]=='[') break; | |
3528 | } | |
3529 | ||
3530 | if(j>-1) | |
3531 | { | |
3532 | int items = sscanf(namex+j, "[%d][%d]", &row, &bit); | |
3533 | if(items == 2) | |
3534 | { | |
3535 | /* printf(">> %d %d (items = %d)\n", row, bit, items); */ | |
3536 | ||
3537 | offset = j; | |
3538 | is_2d = 1; | |
3539 | } | |
3540 | } | |
3541 | } | |
3542 | } | |
3543 | ||
3544 | nam=(char *)wave_alloca(offset+50); /* to handle [a:b][c:d] case */ | |
3514 | 3545 | memcpy(nam, namex, offset); |
3515 | 3546 | if(was_packed) { free_2(namex); } |
3516 | 3547 | |
3548 | if(is_2d) | |
3549 | { | |
3550 | is_2d = 0; | |
3551 | namey = hier_decompress_flagged(n[nodepnt-1]->nname, &was_packed); | |
3552 | ||
3553 | offsety = strlen(namey); | |
3554 | for(iy=offsety-1;iy>=0;iy--) | |
3555 | { | |
3556 | if(namey[iy]=='[') break; | |
3557 | } | |
3558 | /* if(iy>-1) offsety=iy; not needed as in above as gets overwritten below by offsety = j */ | |
3559 | if(iy>3) | |
3560 | { | |
3561 | if(namey[iy-1]==']') | |
3562 | { | |
3563 | int j = iy-2; | |
3564 | for(;j>=0;j--) | |
3565 | { | |
3566 | if(namey[j]=='[') break; | |
3567 | } | |
3568 | ||
3569 | if(j>-1) | |
3570 | { | |
3571 | int items = sscanf(namey+j, "[%d][%d]", &row2, &bit2); | |
3572 | if(items == 2) | |
3573 | { | |
3574 | int rowabs, bitabs, width2d; | |
3575 | /* printf(">> %d %d (items = %d)\n", row2, bit2, items); */ | |
3576 | ||
3577 | offsety = j; | |
3578 | is_2d = (offset == offsety) && !memcmp(nam, namey, offsety); | |
3579 | ||
3580 | rowabs = (row2 > row) ? (row2 - row + 1) : (row - row2 + 1); | |
3581 | bitabs = (bit2 > bit) ? (bit2 - bit + 1) : (bit - bit2 + 1); | |
3582 | width2d = rowabs * bitabs; | |
3583 | sep2d = (width2d == nodepnt) ? ':' : '|'; | |
3584 | } | |
3585 | } | |
3586 | } | |
3587 | } | |
3588 | ||
3589 | if(was_packed) { free_2(namey); } | |
3590 | } | |
3591 | ||
3592 | ||
3517 | 3593 | if(direction) |
3518 | 3594 | { |
3519 | sprintf(nam+offset, "[%d%s%d]", n[0]->expansion->actual, (bitblast_delta!=0) ? ":" : "|", n[nodepnt-1]->expansion->actual); | |
3595 | if(!is_2d) | |
3596 | { | |
3597 | sprintf(nam+offset, "[%d%s%d]", n[0]->expansion->actual, (bitblast_delta!=0) ? ":" : "|", n[nodepnt-1]->expansion->actual); | |
3598 | } | |
3599 | else | |
3600 | { | |
3601 | if(row == row2) | |
3602 | { | |
3603 | if(bit == bit2) | |
3604 | { | |
3605 | sprintf(nam+offset, "[%d][%d]", row, bit); | |
3606 | } | |
3607 | else | |
3608 | { | |
3609 | sprintf(nam+offset, "[%d][%d%c%d]", row, bit, sep2d, bit2); | |
3610 | } | |
3611 | } | |
3612 | else | |
3613 | { | |
3614 | if(bit == bit2) | |
3615 | { | |
3616 | sprintf(nam+offset, "[%d%c%d][%d]", row, sep2d, row2, bit); | |
3617 | } | |
3618 | else | |
3619 | { | |
3620 | sprintf(nam+offset, "[%d%c%d][%d%c%d]", row, sep2d, row2, bit, sep2d, bit2); | |
3621 | } | |
3622 | } | |
3623 | } | |
3520 | 3624 | } |
3521 | 3625 | else |
3522 | 3626 | { |
3523 | sprintf(nam+offset, "[%d%s%d]", n[nodepnt-1]->expansion->actual, (bitblast_delta!=0) ? ":" : "|", n[0]->expansion->actual); | |
3627 | if(!is_2d) | |
3628 | { | |
3629 | sprintf(nam+offset, "[%d%s%d]", n[nodepnt-1]->expansion->actual, (bitblast_delta!=0) ? ":" : "|", n[0]->expansion->actual); | |
3630 | } | |
3631 | else | |
3632 | { | |
3633 | if(row == row2) | |
3634 | { | |
3635 | if(bit == bit2) | |
3636 | { | |
3637 | sprintf(nam+offset, "[%d][%d]", row, bit); | |
3638 | } | |
3639 | else | |
3640 | { | |
3641 | sprintf(nam+offset, "[%d][%d%c%d]", row, bit2, sep2d, bit); | |
3642 | } | |
3643 | } | |
3644 | else | |
3645 | { | |
3646 | if(bit == bit2) | |
3647 | { | |
3648 | sprintf(nam+offset, "[%d%c%d][%d]", row2, sep2d, row, bit); | |
3649 | } | |
3650 | else | |
3651 | { | |
3652 | sprintf(nam+offset, "[%d%c%d][%d%c%d]", row2, sep2d, row, bit2, sep2d, bit); | |
3653 | } | |
3654 | } | |
3655 | } | |
3524 | 3656 | } |
3525 | 3657 | |
3526 | 3658 | strcpy(b->name=(char *)malloc_2(offset + strlen(nam+offset)+1), nam); |
182 | 182 | |
183 | 183 | GLOBALS->regex_which_search_c_1=(int)((intptr_t)which); |
184 | 184 | GLOBALS->regex_mutex_search_c_1[GLOBALS->regex_which_search_c_1] = 1; /* mark our choice */ |
185 | ||
186 | 185 | |
187 | 186 | DEBUG(printf("picked: %s\n", regex_name[GLOBALS->regex_which_search_c_1])); |
188 | 187 | } |
949 | 948 | GtkTooltips *tooltips; |
950 | 949 | GtkAdjustment *adj; |
951 | 950 | GtkWidget *align; |
951 | int cached_which = GLOBALS->regex_which_search_c_1; | |
952 | 952 | |
953 | 953 | /* fix problem where ungrab doesn't occur if button pressed + simultaneous accelerator key occurs */ |
954 | 954 | if(GLOBALS->in_button_press_wavewindow_c_1) { gdk_pointer_ungrab(GDK_CURRENT_TIME); } |
1096 | 1096 | gtk_widget_show (GLOBALS->menuitem_search[i]); |
1097 | 1097 | gtkwave_signal_connect(GTK_OBJECT (GLOBALS->menuitem_search[i]), "activate", GTK_SIGNAL_FUNC(regex_clicked), (void *)((intptr_t)i)); |
1098 | 1098 | GLOBALS->regex_mutex_search_c_1[i]=0; |
1099 | gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (GLOBALS->menuitem_search[i]), FALSE); // | |
1099 | 1100 | } |
1100 | 1101 | |
1101 | GLOBALS->regex_mutex_search_c_1[0]=1; /* "range" */ | |
1102 | GLOBALS->regex_which_search_c_1 = cached_which; | |
1103 | if((GLOBALS->regex_which_search_c_1<0)||(GLOBALS->regex_which_search_c_1>4)) GLOBALS->regex_which_search_c_1 = 0; | |
1104 | GLOBALS->regex_mutex_search_c_1[GLOBALS->regex_which_search_c_1]=1; /* configure for "range", etc */ | |
1105 | gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (GLOBALS->menuitem_search[GLOBALS->regex_which_search_c_1]), TRUE); | |
1102 | 1106 | |
1103 | 1107 | optionmenu = gtk_option_menu_new (); |
1104 | 1108 | gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu); |
0 | 0 | /* |
1 | * Copyright (c) Tony Bybell 1999-2014. | |
1 | * Copyright (c) Tony Bybell 1999-2017. | |
2 | 2 | * |
3 | 3 | * This program is free software; you can redistribute it and/or |
4 | 4 | * modify it under the terms of the GNU General Public License |
1554 | 1554 | { |
1555 | 1555 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) |
1556 | 1556 | { |
1557 | v->msi = v->size-1; v->lsi = 0; | |
1557 | if((v->msi-v->lsi+1) > v->size) /* if() is 2d add */ | |
1558 | { | |
1559 | v->msi = v->size-1; v->lsi = 0; | |
1560 | } | |
1558 | 1561 | /* all this formerly was goto err; */ |
1559 | 1562 | } |
1560 | 1563 | else |
1567 | 1570 | { |
1568 | 1571 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) |
1569 | 1572 | { |
1570 | v->lsi = v->size-1; v->msi = 0; | |
1573 | if((v->lsi-v->msi+1) > v->size) /* if() is 2d add */ | |
1574 | { | |
1575 | v->lsi = v->size-1; v->msi = 0; | |
1576 | } | |
1571 | 1577 | /* all this formerly was goto err; */ |
1572 | 1578 | } |
1573 | 1579 | else |
2306 | 2312 | /* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */ |
2307 | 2313 | { |
2308 | 2314 | sprintf(str+slen-1,"[%d:%d]",v->msi,v->lsi); |
2315 | /* 2d add */ | |
2316 | if((v->msi>v->lsi)&&((v->msi-v->lsi+1)!=v->size)) | |
2317 | { | |
2318 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) | |
2319 | { | |
2320 | v->msi = v->size-1; v->lsi = 0; | |
2321 | } | |
2322 | } | |
2323 | else | |
2324 | if((v->lsi>=v->msi)&&((v->lsi-v->msi+1)!=v->size)) | |
2325 | { | |
2326 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) | |
2327 | { | |
2328 | v->lsi = v->size-1; v->msi = 0; | |
2329 | } | |
2330 | } | |
2309 | 2331 | } |
2310 | 2332 | else |
2311 | 2333 | { |
0 | 0 | /* |
1 | * Copyright (c) Tony Bybell 1999-2011. | |
1 | * Copyright (c) Tony Bybell 1999-2017. | |
2 | 2 | * |
3 | 3 | * This program is free software; you can redistribute it and/or |
4 | 4 | * modify it under the terms of the GNU General Public License |
1502 | 1502 | { |
1503 | 1503 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) |
1504 | 1504 | { |
1505 | v->msi = v->size-1; v->lsi = 0; | |
1505 | if((v->msi-v->lsi+1) > v->size) /* if() is 2d add */ | |
1506 | { | |
1507 | v->msi = v->size-1; v->lsi = 0; | |
1508 | } | |
1506 | 1509 | /* all this formerly was goto err; */ |
1507 | 1510 | } |
1508 | 1511 | else |
1515 | 1518 | { |
1516 | 1519 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) |
1517 | 1520 | { |
1518 | v->lsi = v->size-1; v->msi = 0; | |
1521 | if((v->lsi-v->msi+1) > v->size) /* if() is 2d add */ | |
1522 | { | |
1523 | v->lsi = v->size-1; v->msi = 0; | |
1524 | } | |
1519 | 1525 | /* all this formerly was goto err; */ |
1520 | 1526 | } |
1521 | 1527 | else |
2157 | 2163 | /* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */ |
2158 | 2164 | { |
2159 | 2165 | sprintf(str+slen-1,"[%d:%d]",v->msi,v->lsi); |
2166 | /* 2d add */ | |
2167 | if((v->msi>v->lsi)&&((v->msi-v->lsi+1)!=v->size)) | |
2168 | { | |
2169 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) | |
2170 | { | |
2171 | v->msi = v->size-1; v->lsi = 0; | |
2172 | } | |
2173 | } | |
2174 | else | |
2175 | if((v->lsi>=v->msi)&&((v->lsi-v->msi+1)!=v->size)) | |
2176 | { | |
2177 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) | |
2178 | { | |
2179 | v->lsi = v->size-1; v->msi = 0; | |
2180 | } | |
2181 | } | |
2160 | 2182 | } |
2161 | 2183 | else |
2162 | 2184 | { |
0 | 0 | /* |
1 | * Copyright (c) Tony Bybell 1999-2014. | |
1 | * Copyright (c) Tony Bybell 1999-2017. | |
2 | 2 | * |
3 | 3 | * This program is free software; you can redistribute it and/or |
4 | 4 | * modify it under the terms of the GNU General Public License |
1900 | 1900 | { |
1901 | 1901 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) |
1902 | 1902 | { |
1903 | v->msi = v->size-1; v->lsi = 0; | |
1903 | if((v->msi-v->lsi+1) > v->size) /* if() is 2d add */ | |
1904 | { | |
1905 | v->msi = v->size-1; v->lsi = 0; | |
1906 | } | |
1904 | 1907 | /* all this formerly was goto err; */ |
1905 | 1908 | } |
1906 | 1909 | else |
1913 | 1916 | { |
1914 | 1917 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) |
1915 | 1918 | { |
1916 | v->lsi = v->size-1; v->msi = 0; | |
1919 | if((v->lsi-v->msi+1) > v->size) /* if() is 2d add */ | |
1920 | { | |
1921 | v->lsi = v->size-1; v->msi = 0; | |
1922 | } | |
1917 | 1923 | /* all this formerly was goto err; */ |
1918 | 1924 | } |
1919 | 1925 | else |
2539 | 2545 | /* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */ |
2540 | 2546 | { |
2541 | 2547 | sprintf(str+slen-1,"[%d:%d]",v->msi,v->lsi); |
2548 | /* 2d add */ | |
2549 | if((v->msi>v->lsi)&&((v->msi-v->lsi+1)!=v->size)) | |
2550 | { | |
2551 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) | |
2552 | { | |
2553 | v->msi = v->size-1; v->lsi = 0; | |
2554 | } | |
2555 | } | |
2556 | else | |
2557 | if((v->lsi>=v->msi)&&((v->lsi-v->msi+1)!=v->size)) | |
2558 | { | |
2559 | if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER)) | |
2560 | { | |
2561 | v->lsi = v->size-1; v->msi = 0; | |
2562 | } | |
2563 | } | |
2542 | 2564 | } |
2543 | 2565 | else |
2544 | 2566 | { |