Codebase list gtkwave / 9fbfe33
New upstream version 3.3.83 Dr. Tobias Quathamer 6 years ago
36 changed file(s) with 2056 addition(s) and 1069 deletion(s). Raw diff Collapse all Expand all
15991599 3.3.82 02jul17 Get sys_fst working with VCS VPI.
16001600 Added string concatenations for vectors.
16011601 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.
00 ##########################################################################
11
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.
33 Portions of GTKWave are Copyright (C) 1999-2017 Udi Finkelstein.
44 Context support is Copyright (C) 2007-2017 Kermin Elliott Fleming.
55 Trace group support is Copyright (C) 2009-2017 Donald Baltus.
00 #! /bin/sh
11 # 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.
33 #
44 # Report bugs to <bybell@rocketmail.com>.
55 #
579579 # Identity of this package.
580580 PACKAGE_NAME='gtkwave'
581581 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'
584584 PACKAGE_BUGREPORT='bybell@rocketmail.com'
585585 PACKAGE_URL=''
586586
13821382 # Omit some internal or obsolete options to make the list less imposing.
13831383 # This message is too long to be a string in the A/UX 3.1 sh.
13841384 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.
13861386
13871387 Usage: $0 [OPTION]... [VAR=VALUE]...
13881388
14481448
14491449 if test -n "$ac_init_help"; then
14501450 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:";;
14521452 esac
14531453 cat <<\_ACEOF
14541454
15941594 test -n "$ac_init_help" && exit $ac_status
15951595 if $ac_init_version; then
15961596 cat <<\_ACEOF
1597 gtkwave configure 3.3.82
1597 gtkwave configure 3.3.83
15981598 generated by GNU Autoconf 2.69
15991599
16001600 Copyright (C) 2012 Free Software Foundation, Inc.
22382238 This file contains any messages produced by compilers while
22392239 running configure, to aid debugging if configure makes a mistake.
22402240
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
22422242 generated by GNU Autoconf 2.69. Invocation command line was
22432243
22442244 $ $0 $@
31053105
31063106 # Define the identity of the package.
31073107 PACKAGE='gtkwave'
3108 VERSION='3.3.82'
3108 VERSION='3.3.83'
31093109
31103110
31113111 cat >>confdefs.h <<_ACEOF
1099610996 # report actual input values of CONFIG_FILES etc. instead of their
1099710997 # values after options handling.
1099810998 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
1100011000 generated by GNU Autoconf 2.69. Invocation command line was
1100111001
1100211002 CONFIG_FILES = $CONFIG_FILES
1106211062 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
1106311063 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
1106411064 ac_cs_version="\\
11065 gtkwave config.status 3.3.82
11065 gtkwave config.status 3.3.83
1106611066 configured by $0, generated by GNU Autoconf 2.69,
1106711067 with options \\"\$ac_cs_config\\"
1106811068
11 # Process this file with autoconf to produce a configure script.
22
33 AC_PREREQ(2.59)
4 AC_INIT(gtkwave, 3.3.82, bybell@rocketmail.com)
4 AC_INIT(gtkwave, 3.3.83, bybell@rocketmail.com)
55 AC_CONFIG_SRCDIR([src/vcd.c])
66 AM_INIT_AUTOMAKE
77 AC_CONFIG_HEADER([config.h])
77 <key>CFBundleExecutable</key>
88 <string>gtkwave</string>
99 <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>
1111 <key>CFBundleIconFile</key>
1212 <string>gtkwave.icns</string>
1313 <key>CFBundleIdentifier</key>
1717 <key>CFBundlePackageType</key>
1818 <string>APPL</string>
1919 <key>CFBundleShortVersionString</key>
20 <string>3.3.82</string>
20 <string>3.3.83</string>
2121 <key>CFBundleSignature</key>
2222 <string>????</string>
2323 <key>CFBundleVersion</key>
24 <string>3.3.82</string>
24 <string>3.3.83</string>
2525 <key>NSHumanReadableCopyright</key>
2626 <string>Copyright 1999 - 2017 Tony Bybell, GNU General Public License.</string>
2727 <key>LSMinimumSystemVersion</key>
18491849 eptr rc=NULL;
18501850 exptr exp1;
18511851
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
18521857 if(n->mv.mvlfac) import_trace(n);
18531858
18541859 if(!n->extvals)
18961901 if(namex[i]=='[') break;
18971902 }
18981903 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 }
18991936
19001937 nam=(char *)wave_alloca(offset+20+30);
19011938 memcpy(nam, namex, offset);
19491986 for(i=0;i<width;i++)
19501987 {
19511988 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 }
19532006 #ifdef WAVE_ARRAY_SUPPORT
19542007 if(n->array_height)
19552008 {
20522105 int actual;
20532106 nptr np;
20542107 char *nam;
2055 int offset, len;
2108 int offset, len, width;
20562109 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;
20572115
20582116 if(n->mv.mvlfac) import_trace(n);
20592117
20692127
20702128 if(n->lsi > n->msi)
20712129 {
2130 width = n->lsi - n->msi + 1;
20722131 rgh = n->lsi; lft = n->msi;
20732132 actual = n->msi + bit;
20742133 }
20752134 else
20762135 {
2136 width = n->msi - n->lsi + 1;
20772137 rgh = n->msi; lft = n->lsi;
20782138 actual = n->msi - bit;
20792139 }
20922152 {
20932153 namex = n->nname;
20942154 }
2155
20952156 offset = strlen(namex);
20962157 for(i=offset-1;i>=0;i--)
20972158 {
20982159 if(namex[i]=='[') break;
20992160 }
21002161 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 }
21012194
21022195 nam=(char *)wave_alloca(offset+20);
21032196 memcpy(nam, namex, offset);
21492242 DEBUG(fprintf(stderr, "Extracting: (%d to %d) for offset #%d over %d entries.\n", n->msi, n->lsi, bit, n->numhist));
21502243
21512244 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
21532268 #ifdef WAVE_ARRAY_SUPPORT
21542269 if(n->array_height)
21552270 {
205205 #endif
206206
207207 #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)
209209 {
210210 #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)
212212 {
213213 static char sbuff[65537];
214214 #endif
215215 char * rc;
216216 int vt, vt_len;
217
218 *patched_len = 0; /* zero says is ok, otherwise size overrides msi/lsi */
217219
218220 #ifndef WAVE_FSDB_READER_IS_PRESENT
219221 for(;;)
307309 {
308310 lb = colon = rb = NULL;
309311 }
312 if(pnt[1] == '[') esc = pnt; /* pretend we're escaped to handle 2d */
310313 }
311314 else if(pnt[0] == ':')
312315 {
386389 ? (GLOBALS->extload_node_block[i].msi - GLOBALS->extload_node_block[i].lsi + 1)
387390 : (GLOBALS->extload_node_block[i].lsi - GLOBALS->extload_node_block[i].msi + 1);
388391
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 */
390393 {
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 }
393404 }
394405 }
395406 else
634645 char *fnam;
635646 int flen;
636647 int longest_nam_candidate = 0;
648 int patched_len = 0;
637649
638650 i = GLOBALS->extload_i;
639651
640652 if(i<0)
641653 {
642654 #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);
644656 flen = strlen(fnam);
645657
646658 if(GLOBALS->extload_hlen)
650662 *(GLOBALS->extload_namecache[0 & F_NAME_MODULUS]+GLOBALS->extload_hlen) = '.';
651663 strcpy(GLOBALS->extload_namecache[0 & F_NAME_MODULUS]+GLOBALS->extload_hlen+1, fnam);
652664 GLOBALS->extload_namecache_lens[0 & F_NAME_MODULUS]=GLOBALS->extload_hlen + 1 + flen;
665 GLOBALS->extload_namecache_patched[0 & F_NAME_MODULUS]=patched_len;
653666 }
654667 else
655668 {
656669 GLOBALS->extload_namecache[0 & F_NAME_MODULUS]=malloc_2(GLOBALS->extload_namecache_max[0 & F_NAME_MODULUS]=flen+1);
657670 strcpy(GLOBALS->extload_namecache[0 & F_NAME_MODULUS], fnam);
658671 GLOBALS->extload_namecache_lens[0 & F_NAME_MODULUS] = flen;
672 GLOBALS->extload_namecache_patched[0 & F_NAME_MODULUS]=patched_len;
659673 }
660674 #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);
662676 flen = strlen(fnam);
663677
664678 GLOBALS->extload_namecache[0 & F_NAME_MODULUS]=malloc_2(GLOBALS->extload_namecache_max[0 & F_NAME_MODULUS]=flen+1);
665679 strcpy(GLOBALS->extload_namecache[0 & F_NAME_MODULUS], fnam);
666680 GLOBALS->extload_namecache_lens[0 & F_NAME_MODULUS] = flen;
681 GLOBALS->extload_namecache_patched[0 & F_NAME_MODULUS]=patched_len;
667682 #endif
668683 }
669684 else
673688 if(i!=(GLOBALS->numfacs-1))
674689 {
675690 #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);
677692 flen = strlen(fnam);
678693
679694 if(GLOBALS->extload_hlen)
688703 *(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS]+GLOBALS->extload_hlen) = '.';
689704 strcpy(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS]+GLOBALS->extload_hlen+1, fnam);
690705 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;
691707 }
692708 else
693709 {
698714 }
699715 strcpy(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS], fnam);
700716 GLOBALS->extload_namecache_lens[(i+1)&F_NAME_MODULUS] = flen;
717 GLOBALS->extload_namecache_patched[(i+1)&F_NAME_MODULUS] = patched_len;
701718 }
702719 #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);
704721 flen = strlen(fnam);
705722
706723 if(GLOBALS->extload_namecache_max[(i+1)&F_NAME_MODULUS] < (flen+1))
709726 }
710727 strcpy(GLOBALS->extload_namecache[(i+1)&F_NAME_MODULUS], fnam);
711728 GLOBALS->extload_namecache_lens[(i+1)&F_NAME_MODULUS] = flen;
729 GLOBALS->extload_namecache_patched[(i+1)&F_NAME_MODULUS] = patched_len;
712730 #endif
713731 }
714732
717735 if((f->len>1)&& (!(f->flags&(VZT_RD_SYM_F_INTEGER|VZT_RD_SYM_F_DOUBLE|VZT_RD_SYM_F_STRING))) )
718736 {
719737 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 }
720743 longest_nam_candidate = len;
721744
722745 if(!GLOBALS->do_hier_compress)
891914 static void extload_hiertree_callback(void *pnt)
892915 {
893916 static int tree_end = 0;
917 int patched_len = 0;
894918
895919 char *s = (char *)pnt;
896920
899923 switch(s[0])
900924 {
901925 case 'S':
902 case 'U': get_varname(s, NULL, NULL, -1);
926 case 'U': get_varname(s, NULL, NULL, -1, &patched_len);
903927 GLOBALS->extload_hlen = GLOBALS->fst_scope_name ? strlen(GLOBALS->fst_scope_name) : 0;
904928 break;
905929
10361060 }
10371061
10381062 #else
1063 int patched_len = 0;
10391064
10401065 last_modification_check();
10411066 sprintf(sbuff, "%s -info %s 2>&1", EXTLOAD_PATH, fname);
11751200 GLOBALS->extload_namecache=(char **)calloc_2(F_NAME_MODULUS+1, sizeof(char *));
11761201 GLOBALS->extload_namecache_max=(int *)calloc_2(F_NAME_MODULUS+1, sizeof(int));
11771202 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));
11781204 GLOBALS->extload_sym_block = (struct symbol *)calloc_2(GLOBALS->numfacs, sizeof(struct symbol));
11791205 GLOBALS->extload_node_block=(struct Node *)calloc_2(GLOBALS->numfacs,sizeof(struct Node));
11801206 GLOBALS->extload_idcodes=(unsigned int *)calloc_2(GLOBALS->numfacs, sizeof(unsigned int));
12201246 free_2(GLOBALS->extload_namecache); GLOBALS->extload_namecache = NULL;
12211247 free_2(GLOBALS->extload_namecache_max); GLOBALS->extload_namecache_max = NULL;
12221248 free_2(GLOBALS->extload_namecache_lens); GLOBALS->extload_namecache_lens = NULL;
1249 free_2(GLOBALS->extload_namecache_patched); GLOBALS->extload_namecache_patched = NULL;
12231250
12241251 fstReaderClose(GLOBALS->extload_xc); /* corresponds to fstReaderOpenForUtilitiesOnly() */
12251252
12421269 {
12431270 process_extload_variable();
12441271 }
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 */
12461273
12471274 decorated_module_cleanup(); /* ...also now in gtk2_treesearch.c */
12481275 iter_through_comp_name_table();
00 /*
1 * Copyright (c) Tony Bybell 2009-2016.
1 * Copyright (c) Tony Bybell 2009-2017.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
629629 unsigned char nvt, nvd, ndt;
630630 int longest_nam_candidate = 0;
631631 char *fnam;
632 int len_subst = 0;
632633
633634 h = extractNextVar(GLOBALS->fst_fst_c_1, &msb, &lsb, &nnam, &name_len, &nnam_max);
634635 if(!h)
685686 }
686687 else
687688 {
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
688697 node_block[i].msi = msb;
689698 node_block[i].lsi = lsb;
690699 }
812821 if((f->len>1)&& (!(f->flags&(VZT_RD_SYM_F_INTEGER|VZT_RD_SYM_F_DOUBLE|VZT_RD_SYM_F_STRING))) )
813822 {
814823 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
815831 longest_nam_candidate = len;
816832
817833 if(!GLOBALS->do_hier_compress)
00 /*
1 * Copyright (c) Kermin Elliott Fleming 2007-2016.
1 * Copyright (c) Kermin Elliott Fleming 2007-2017.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
247247 NULL, /* extload_namecache */
248248 NULL, /* extload_namecache_max */
249249 NULL, /* extload_namecache_lens */
250 NULL, /* extload_namecache_patched */
250251 NULL, /* extload_sym_block */
251252 NULL, /* extload_node_block */
252253 NULL, /* extload_xc */
19301931 strcpy2_into_new_context(new_globals, &new_globals->pFileChooseFilterName, &GLOBALS->pFileChooseFilterName);
19311932 #endif
19321933
1934 /* search.c */
1935 new_globals->regex_which_search_c_1 = GLOBALS->regex_which_search_c_1; /* preserve search type */
1936
19331937 /* ttranslate.c */
19341938 strcpy2_into_new_context(new_globals, &new_globals->ttranslate_args, &GLOBALS->ttranslate_args);
19351939
248248 char **extload_namecache;
249249 int *extload_namecache_max;
250250 int *extload_namecache_lens;
251 int *extload_namecache_patched;
251252 struct symbol *extload_sym_block;
252253 struct Node *extload_node_block;
253254 void *extload_xc;
00 ZLIB DATA COMPRESSION LIBRARY
11
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
33 thread safe. The data format used by the zlib library is described by RFCs
44 (Request for Comments) 1950 to 1952 in the files
55 http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
3030 issue of Dr. Dobb's Journal; a copy of the article is available at
3131 http://marknelson.us/1997/01/01/zlib-engine/ .
3232
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.
3434
3535 Unsupported third party contributions are provided in directory contrib/ .
3636
8383
8484 Copyright notice:
8585
86 (C) 1995-2013 Jean-loup Gailly and Mark Adler
86 (C) 1995-2017 Jean-loup Gailly and Mark Adler
8787
8888 This software is provided 'as-is', without any express or implied
8989 warranty. In no event will the authors be held liable for any damages
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
66
77 #include "zutil.h"
88
9 #define local static
10
119 local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
1210
13 #define BASE 65521 /* largest prime smaller than 65536 */
11 #define BASE 65521U /* largest prime smaller than 65536 */
1412 #define NMAX 5552
1513 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
1614
6159 #endif
6260
6361 /* ========================================================================= */
64 uLong ZEXPORT adler32(adler, buf, len)
62 uLong ZEXPORT adler32_z(adler, buf, len)
6563 uLong adler;
6664 const Bytef *buf;
67 uInt len;
65 z_size_t len;
6866 {
6967 unsigned long sum2;
7068 unsigned n;
132130 }
133131
134132 /* ========================================================================= */
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 /* ========================================================================= */
135142 local uLong adler32_combine_(adler1, adler2, len2)
136143 uLong adler1;
137144 uLong adler2;
155162 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
156163 if (sum1 >= BASE) sum1 -= BASE;
157164 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);
159166 if (sum2 >= BASE) sum2 -= BASE;
160167 return sum1 | (sum2 << 16);
161168 }
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
2727 {
2828 z_stream stream;
2929 int err;
30 const uInt max = (uInt)-1;
31 uLong left;
3032
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;
4035
4136 stream.zalloc = (alloc_func)0;
4237 stream.zfree = (free_func)0;
4540 err = deflateInit(&stream, level);
4641 if (err != Z_OK) return err;
4742
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
5360 *destLen = stream.total_out;
54
55 err = deflateEnd(&stream);
56 return err;
61 deflateEnd(&stream);
62 return err == Z_STREAM_END ? Z_OK : err;
5763 }
5864
5965 /* ===========================================================================
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 *
44 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
2929
3030 #include "zutil.h" /* for STDC and FAR definitions */
3131
32 #define local static
33
3432 /* Definitions for doing the crc four data bytes at a time. */
3533 #if !defined(NOBYFOUR) && defined(Z_U4)
3634 # define BYFOUR
3735 #endif
3836 #ifdef BYFOUR
3937 local unsigned long crc32_little OF((unsigned long,
40 const unsigned char FAR *, unsigned));
38 const unsigned char FAR *, z_size_t));
4139 local unsigned long crc32_big OF((unsigned long,
42 const unsigned char FAR *, unsigned));
40 const unsigned char FAR *, z_size_t));
4341 # define TBLS 8
4442 #else
4543 # define TBLS 1
200198 #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
201199
202200 /* ========================================================================= */
203 unsigned long ZEXPORT crc32(crc, buf, len)
201 unsigned long ZEXPORT crc32_z(crc, buf, len)
204202 unsigned long crc;
205203 const unsigned char FAR *buf;
206 uInt len;
204 z_size_t len;
207205 {
208206 if (buf == Z_NULL) return 0UL;
209207
234232 return crc ^ 0xffffffffUL;
235233 }
236234
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
237244 #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 */
238257
239258 /* ========================================================================= */
240259 #define DOLIT4 c ^= *buf4++; \
246265 local unsigned long crc32_little(crc, buf, len)
247266 unsigned long crc;
248267 const unsigned char FAR *buf;
249 unsigned len;
268 z_size_t len;
250269 {
251270 register z_crc_t c;
252271 register const z_crc_t FAR *buf4;
277296 }
278297
279298 /* ========================================================================= */
280 #define DOBIG4 c ^= *++buf4; \
299 #define DOBIG4 c ^= *buf4++; \
281300 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
282301 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
283302 #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
286305 local unsigned long crc32_big(crc, buf, len)
287306 unsigned long crc;
288307 const unsigned char FAR *buf;
289 unsigned len;
308 z_size_t len;
290309 {
291310 register z_crc_t c;
292311 register const z_crc_t FAR *buf4;
299318 }
300319
301320 buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
302 buf4--;
303321 while (len >= 32) {
304322 DOBIG32;
305323 len -= 32;
308326 DOBIG4;
309327 len -= 4;
310328 }
311 buf4++;
312329 buf = (const unsigned char FAR *)buf4;
313330
314331 if (len) do {
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
5151 #include "deflate.h"
5252
5353 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 ";
5555 /*
5656 If you use the zlib library in a product, an acknowledgment is welcome
5757 in the documentation of your product. If for some reason you cannot
7272 typedef block_state (*compress_func) OF((deflate_state *s, int flush));
7373 /* Compression function. Returns the block state after the call. */
7474
75 local int deflateStateCheck OF((z_streamp strm));
76 local void slide_hash OF((deflate_state *s));
7577 local void fill_window OF((deflate_state *s));
7678 local block_state deflate_stored OF((deflate_state *s, int flush));
7779 local block_state deflate_fast OF((deflate_state *s, int flush));
8385 local void lm_init OF((deflate_state *s));
8486 local void putShortMSB OF((deflate_state *s, uInt b));
8587 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));
8789 #ifdef ASMV
90 # pragma message("Assembler code may have bugs -- use at your own risk")
8891 void match_init OF((void)); /* asm code initialization */
8992 uInt longest_match OF((deflate_state *s, IPos cur_match));
9093 #else
9194 local uInt longest_match OF((deflate_state *s, IPos cur_match));
9295 #endif
9396
94 #ifdef DEBUG
97 #ifdef ZLIB_DEBUG
9598 local void check_match OF((deflate_state *s, IPos start, IPos match,
9699 int length));
97100 #endif
147150 * meaning.
148151 */
149152
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
157153 /* 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))
159155
160156 /* ===========================================================================
161157 * 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.
165161 */
166162 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
167163
172168 * the previous length of the hash chain.
173169 * If this file is compiled with -DFASTEST, the compression level is forced
174170 * 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).
178174 */
179175 #ifdef FASTEST
180176 #define INSERT_STRING(s, str, match_head) \
195191 #define CLEAR_HASH(s) \
196192 s->head[s->hash_size-1] = NIL; \
197193 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 }
198225
199226 /* ========================================================================= */
200227 int ZEXPORT deflateInit_(strm, level, version, stream_size)
269296 #endif
270297 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
271298 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
272 strategy < 0 || strategy > Z_FIXED) {
299 strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
273300 return Z_STREAM_ERROR;
274301 }
275302 if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
277304 if (s == Z_NULL) return Z_MEM_ERROR;
278305 strm->state = (struct internal_state FAR *)s;
279306 s->strm = strm;
307 s->status = INIT_STATE; /* to pass state test in deflateReset() */
280308
281309 s->wrap = wrap;
282310 s->gzhead = Z_NULL;
283 s->w_bits = windowBits;
311 s->w_bits = (uInt)windowBits;
284312 s->w_size = 1 << s->w_bits;
285313 s->w_mask = s->w_size - 1;
286314
287 s->hash_bits = memLevel + 7;
315 s->hash_bits = (uInt)memLevel + 7;
288316 s->hash_size = 1 << s->hash_bits;
289317 s->hash_mask = s->hash_size - 1;
290318 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
318346 return deflateReset(strm);
319347 }
320348
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
321374 /* ========================================================================= */
322375 int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
323376 z_streamp strm;
330383 unsigned avail;
331384 z_const unsigned char *next;
332385
333 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
386 if (deflateStateCheck(strm) || dictionary == Z_NULL)
334387 return Z_STREAM_ERROR;
335388 s = strm->state;
336389 wrap = s->wrap;
388441 }
389442
390443 /* ========================================================================= */
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 /* ========================================================================= */
391466 int ZEXPORT deflateResetKeep (strm)
392467 z_streamp strm;
393468 {
394469 deflate_state *s;
395470
396 if (strm == Z_NULL || strm->state == Z_NULL ||
397 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
471 if (deflateStateCheck(strm)) {
398472 return Z_STREAM_ERROR;
399473 }
400474
409483 if (s->wrap < 0) {
410484 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
411485 }
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;
413491 strm->adler =
414492 #ifdef GZIP
415493 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
439517 z_streamp strm;
440518 gz_headerp head;
441519 {
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;
444522 strm->state->gzhead = head;
445523 return Z_OK;
446524 }
451529 int *bits;
452530 z_streamp strm;
453531 {
454 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
532 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
455533 if (pending != Z_NULL)
456534 *pending = strm->state->pending;
457535 if (bits != Z_NULL)
468546 deflate_state *s;
469547 int put;
470548
471 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
549 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
472550 s = strm->state;
473551 if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
474552 return Z_BUF_ERROR;
493571 {
494572 deflate_state *s;
495573 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;
499576 s = strm->state;
500577
501578 #ifdef FASTEST
509586 func = configuration_table[s->level].func;
510587
511588 if ((strategy != s->strategy || func != configuration_table[level].func) &&
512 strm->total_in != 0) {
589 s->high_water) {
513590 /* 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;
517596 }
518597 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 }
519605 s->level = level;
520606 s->max_lazy_match = configuration_table[level].max_lazy;
521607 s->good_match = configuration_table[level].good_length;
523609 s->max_chain_length = configuration_table[level].max_chain;
524610 }
525611 s->strategy = strategy;
526 return err;
612 return Z_OK;
527613 }
528614
529615 /* ========================================================================= */
536622 {
537623 deflate_state *s;
538624
539 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
625 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
540626 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;
543629 s->nice_match = nice_length;
544 s->max_chain_length = max_chain;
630 s->max_chain_length = (uInt)max_chain;
545631 return Z_OK;
546632 }
547633
568654 {
569655 deflate_state *s;
570656 uLong complen, wraplen;
571 Bytef *str;
572657
573658 /* conservative upper bound for compressed data */
574659 complen = sourceLen +
575660 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
576661
577662 /* if can't get parameters, return conservative bound plus zlib wrapper */
578 if (strm == Z_NULL || strm->state == Z_NULL)
663 if (deflateStateCheck(strm))
579664 return complen + 6;
580665
581666 /* compute wrapper length */
587672 case 1: /* zlib wrapper */
588673 wraplen = 6 + (s->strstart ? 4 : 0);
589674 break;
675 #ifdef GZIP
590676 case 2: /* gzip wrapper */
591677 wraplen = 18;
592678 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
679 Bytef *str;
593680 if (s->gzhead->extra != Z_NULL)
594681 wraplen += 2 + s->gzhead->extra_len;
595682 str = s->gzhead->name;
606693 wraplen += 2;
607694 }
608695 break;
696 #endif
609697 default: /* for compiler happiness */
610698 wraplen = 6;
611699 }
633721 }
634722
635723 /* =========================================================================
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()).
640728 */
641729 local void flush_pending(strm)
642730 z_streamp strm;
653741 strm->next_out += len;
654742 s->pending_out += len;
655743 strm->total_out += len;
656 strm->avail_out -= len;
657 s->pending -= len;
744 strm->avail_out -= len;
745 s->pending -= len;
658746 if (s->pending == 0) {
659747 s->pending_out = s->pending_buf;
660748 }
661749 }
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)
662760
663761 /* ========================================================================= */
664762 int ZEXPORT deflate (strm, flush)
668766 int old_flush; /* value of flush param for previous deflate call */
669767 deflate_state *s;
670768
671 if (strm == Z_NULL || strm->state == Z_NULL ||
672 flush > Z_BLOCK || flush < 0) {
769 if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
673770 return Z_STREAM_ERROR;
674771 }
675772 s = strm->state;
676773
677774 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) ||
679776 (s->status == FINISH_STATE && flush != Z_FINISH)) {
680777 ERR_RETURN(strm, Z_STREAM_ERROR);
681778 }
682779 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
683780
684 s->strm = strm; /* just in case */
685781 old_flush = s->last_flush;
686782 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
867783
868784 /* Flush as much pending output as possible */
869785 if (s->pending != 0) {
893809 ERR_RETURN(strm, Z_BUF_ERROR);
894810 }
895811
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
896993 /* Start a new block or continue the current one.
897994 */
898995 if (strm->avail_in != 0 || s->lookahead != 0 ||
899996 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
900997 block_state bstate;
901998
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);
9051003
9061004 if (bstate == finish_started || bstate == finish_done) {
9071005 s->status = FINISH_STATE;
9431041 }
9441042 }
9451043 }
946 Assert(strm->avail_out > 0, "bug2");
9471044
9481045 if (flush != Z_FINISH) return Z_OK;
9491046 if (s->wrap <= 0) return Z_STREAM_END;
9801077 {
9811078 int status;
9821079
983 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1080 if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
9841081
9851082 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 }
9951083
9961084 /* Deallocate in reverse order of allocations: */
9971085 TRY_FREE(strm, strm->state->pending_buf);
10221110 ushf *overlay;
10231111
10241112
1025 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
1113 if (deflateStateCheck(source) || dest == Z_NULL) {
10261114 return Z_STREAM_ERROR;
10271115 }
10281116
10721160 * allocating a large strm->next_in buffer and copying from it.
10731161 * (See also flush_pending()).
10741162 */
1075 local int read_buf(strm, buf, size)
1163 local unsigned read_buf(strm, buf, size)
10761164 z_streamp strm;
10771165 Bytef *buf;
10781166 unsigned size;
10961184 strm->next_in += len;
10971185 strm->total_in += len;
10981186
1099 return (int)len;
1187 return len;
11001188 }
11011189
11021190 /* ===========================================================================
11501238 {
11511239 unsigned chain_length = s->max_chain_length;/* max hash chain length */
11521240 register Bytef *scan = s->window + s->strstart; /* current string */
1153 register Bytef *match; /* matched string */
1241 register Bytef *match; /* matched string */
11541242 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 */
11561244 int nice_match = s->nice_match; /* stop if match long enough */
11571245 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
11581246 s->strstart - (IPos)MAX_DIST(s) : NIL;
11871275 /* Do not look for matches beyond the end of the input. This is necessary
11881276 * to make deflate deterministic.
11891277 */
1190 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
1278 if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
11911279
11921280 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
11931281
13481436
13491437 #endif /* FASTEST */
13501438
1351 #ifdef DEBUG
1439 #ifdef ZLIB_DEBUG
1440
1441 #define EQUAL 0
1442 /* result of memcmp for equal strings */
1443
13521444 /* ===========================================================================
13531445 * Check that the match at match_start is indeed a match.
13541446 */
13741466 }
13751467 #else
13761468 # define check_match(s, start, match, length)
1377 #endif /* DEBUG */
1469 #endif /* ZLIB_DEBUG */
13781470
13791471 /* ===========================================================================
13801472 * Fill the window when the lookahead becomes insufficient.
13891481 local void fill_window(s)
13901482 deflate_state *s;
13911483 {
1392 register unsigned n, m;
1393 register Posf *p;
1484 unsigned n;
13941485 unsigned more; /* Amount of free space at the end of the window. */
13951486 uInt wsize = s->w_size;
13961487
14171508 */
14181509 if (s->strstart >= wsize+MAX_DIST(s)) {
14191510
1420 zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1511 zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more);
14211512 s->match_start -= wsize;
14221513 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
14231514 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);
14491516 more += wsize;
14501517 }
14511518 if (s->strm->avail_in == 0) break;
15511618 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
15521619 }
15531620
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
15541627 /* ===========================================================================
15551628 * Copy without compression as much as possible from the input stream, return
15561629 * 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.
15621641 */
15631642 local block_state deflate_stored(s, flush)
15641643 deflate_state *s;
15651644 int flush;
15661645 {
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.
15691649 */
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.
16051662 */
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)
16131764 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;
16181814 }
16191815
16201816 /* ===========================================================================
18912087 prev == *++scan && prev == *++scan &&
18922088 prev == *++scan && prev == *++scan &&
18932089 scan < strend);
1894 s->match_length = MAX_MATCH - (int)(strend - scan);
2090 s->match_length = MAX_MATCH - (uInt)(strend - scan);
18952091 if (s->match_length > s->lookahead)
18962092 s->match_length = s->lookahead;
18972093 }
00 /* deflate.h -- internal compression state
1 * Copyright (C) 1995-2012 Jean-loup Gailly
1 * Copyright (C) 1995-2016 Jean-loup Gailly
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
5050 #define Buf_size 16
5151 /* size of bit buffer in bi_buf */
5252
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 */
6063 /* Stream status */
6164
6265
8285 typedef struct tree_desc_s {
8386 ct_data *dyn_tree; /* the dynamic tree */
8487 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 */
8689 } FAR tree_desc;
8790
8891 typedef ush Pos;
99102 Bytef *pending_buf; /* output still pending */
100103 ulg pending_buf_size; /* size of pending_buf */
101104 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 */
103106 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
104107 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 */
106109 Byte method; /* can only be DEFLATED */
107110 int last_flush; /* value of flush param for previous deflate call */
108111
248251 uInt matches; /* number of string matches in current block */
249252 uInt insert; /* bytes at end of window left to insert */
250253
251 #ifdef DEBUG
254 #ifdef ZLIB_DEBUG
252255 ulg compressed_len; /* total bit length of compressed file mod 2^32 */
253256 ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
254257 #endif
274277 /* Output a byte on the stream.
275278 * IN assertion: there is enough room in pending_buf.
276279 */
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);}
278281
279282
280283 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
308311 * used.
309312 */
310313
311 #ifndef DEBUG
314 #ifndef ZLIB_DEBUG
312315 /* Inline versions of _tr_tally for speed: */
313316
314317 #if defined(GEN_TREES_H) || !defined(STDC)
327330 flush = (s->last_lit == s->lit_bufsize-1); \
328331 }
329332 # 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); \
332335 s->d_buf[s->last_lit] = dist; \
333336 s->l_buf[s->last_lit++] = len; \
334337 dist--; \
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
2424 # include <stdlib.h>
2525 # include <limits.h>
2626 #endif
27
28 #ifndef _POSIX_SOURCE
29 # define _POSIX_SOURCE
30 #endif
2731 #include <fcntl.h>
2832
2933 #ifdef _WIN32
3236
3337 #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
3438 # include <io.h>
39 #endif
40
41 #if defined(_WIN32) || defined(__CYGWIN__)
42 # define WIDECHAR
3543 #endif
3644
3745 #ifdef WINAPI_FAMILY
94102 # endif
95103 #endif
96104
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
100107 the result is assured to fit in the space provided */
101 #ifdef _MSC_VER
108 #if defined(_MSC_VER) && _MSC_VER < 1900
102109 # define snprintf _snprintf
103110 #endif
104111
105112 #ifndef local
106113 # define local static
107114 #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) */
109118
110119 /* gz* functions always use library allocation functions */
111120 #ifndef STDC
169178 char *path; /* path or fd for error messages */
170179 unsigned size; /* buffer size, zero if not allocated yet */
171180 unsigned want; /* requested buffer size, default is GZBUFSIZE */
172 unsigned char *in; /* input buffer */
181 unsigned char *in; /* input buffer (double-sized when writing) */
173182 unsigned char *out; /* output buffer (double-sized when reading) */
174183 int direct; /* 0 if processing gzip, 1 if transparent */
175184 /* just for reading */
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
55 #include "gzguts.h"
66
7 #if defined(_WIN32) && !defined(__BORLANDC__)
7 #if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
88 # define LSEEK _lseeki64
99 #else
1010 #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
9393 const char *mode;
9494 {
9595 gz_statep state;
96 size_t len;
96 z_size_t len;
9797 int oflag;
9898 #ifdef O_CLOEXEC
9999 int cloexec = 0;
187187 }
188188
189189 /* save the path name for error messages */
190 #ifdef _WIN32
190 #ifdef WIDECHAR
191191 if (fd == -2) {
192192 len = wcstombs(NULL, path, 0);
193 if (len == (size_t)-1)
193 if (len == (z_size_t)-1)
194194 len = 0;
195195 }
196196 else
201201 free(state);
202202 return NULL;
203203 }
204 #ifdef _WIN32
204 #ifdef WIDECHAR
205205 if (fd == -2)
206206 if (len)
207207 wcstombs(state->path, path, len + 1);
210210 else
211211 #endif
212212 #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);
214214 #else
215215 strcpy(state->path, path);
216216 #endif
238238
239239 /* open the file with the appropriate flags (or just use fd) */
240240 state->fd = fd > -1 ? fd : (
241 #ifdef _WIN32
241 #ifdef WIDECHAR
242242 fd == -2 ? _wopen(path, oflag, 0666) :
243243 #endif
244244 open((const char *)path, oflag, 0666));
247247 free(state);
248248 return NULL;
249249 }
250 if (state->mode == GZ_APPEND)
250 if (state->mode == GZ_APPEND) {
251 LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
251252 state->mode = GZ_WRITE; /* simplify later checks */
253 }
252254
253255 /* save the current position for rewinding (only if reading) */
254256 if (state->mode == GZ_READ) {
290292 if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
291293 return NULL;
292294 #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);
294296 #else
295297 sprintf(path, "<fd:%d>", fd); /* for debugging */
296298 #endif
300302 }
301303
302304 /* -- see zlib.h -- */
303 #ifdef _WIN32
305 #ifdef WIDECHAR
304306 gzFile ZEXPORT gzopen_w(path, mode)
305307 const wchar_t *path;
306308 const char *mode;
328330 return -1;
329331
330332 /* check and set requested size */
333 if ((size << 1) < size)
334 return -1; /* need to be able to double it */
331335 if (size < 2)
332336 size = 2; /* need two bytes to check magic header */
333337 state->want = size;
603607 return;
604608 }
605609 #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);
608612 #else
609613 strcpy(state->msg, state->path);
610614 strcat(state->msg, ": ");
611615 strcat(state->msg, msg);
612616 #endif
613 return;
614617 }
615618
616619 #ifndef INT_MAX
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
1111 local int gz_decomp OF((gz_statep));
1212 local int gz_fetch OF((gz_statep));
1313 local int gz_skip OF((gz_statep, z_off64_t));
14 local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
1415
1516 /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
1617 state->fd, and update state->eof, state->err, and state->msg as appropriate.
2324 unsigned *have;
2425 {
2526 int ret;
27 unsigned get, max = ((unsigned)-1 >> 2) + 1;
2628
2729 *have = 0;
2830 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);
3035 if (ret <= 0)
3136 break;
32 *have += ret;
37 *have += (unsigned)ret;
3338 } while (*have < len);
3439 if (ret < 0) {
3540 gz_error(state, Z_ERRNO, zstrerror());
9398 state->in = (unsigned char *)malloc(state->want);
9499 state->out = (unsigned char *)malloc(state->want << 1);
95100 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);
100103 gz_error(state, Z_MEM_ERROR, "out of memory");
101104 return -1;
102105 }
283286 return 0;
284287 }
285288
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;
289295 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;
313300
314301 /* if len is zero, avoid unnecessary operations */
315302 if (len == 0)
319306 if (state->seek) {
320307 state->seek = 0;
321308 if (gz_skip(state, state->skip) == -1)
322 return -1;
309 return 0;
323310 }
324311
325312 /* get len bytes to buf, or less than len if at the end */
326313 got = 0;
327314 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
328320 /* first just try copying data from the output buffer */
329321 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;
331324 memcpy(buf, state->x.next, n);
332325 state->x.next += n;
333326 state->x.have -= n;
334327 }
335328
336329 /* 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) {
338331 state->past = 1; /* tried to read past end */
339332 break;
340333 }
341334
342335 /* need output data -- for small len or new stream load up our output
343336 buffer */
344 else if (state->how == LOOK || len < (state->size << 1)) {
337 else if (state->how == LOOK || n < (state->size << 1)) {
345338 /* get more output, looking for header if required */
346339 if (gz_fetch(state) == -1)
347 return -1;
340 return 0;
348341 continue; /* no progress yet -- go back to copy above */
349342 /* the copy above assures that we will leave with space in the
350343 output buffer, allowing at least one gzungetc() to succeed */
352345
353346 /* large len -- read directly into user buffer */
354347 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;
357350 }
358351
359352 /* large len -- decompress directly into user buffer */
360353 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;
363356 if (gz_decomp(state) == -1)
364 return -1;
357 return 0;
365358 n = state->x.have;
366359 state->x.have = 0;
367360 }
373366 state->x.pos += n;
374367 } while (len);
375368
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;
378438 }
379439
380440 /* -- see zlib.h -- */
407467 return *(state->x.next)++;
408468 }
409469
410 /* nothing there -- try gzread() */
411 ret = gzread(file, buf, 1);
470 /* nothing there -- try gz_read() */
471 ret = gz_read(state, buf, 1);
412472 return ret < 1 ? -1 : buf[0];
413473 }
414474
450510 if (state->x.have == 0) {
451511 state->x.have = 1;
452512 state->x.next = state->out + (state->size << 1) - 1;
453 state->x.next[0] = c;
513 state->x.next[0] = (unsigned char)c;
454514 state->x.pos--;
455515 state->past = 0;
456516 return c;
472532 }
473533 state->x.have++;
474534 state->x.next--;
475 state->x.next[0] = c;
535 state->x.next[0] = (unsigned char)c;
476536 state->x.pos--;
477537 state->past = 0;
478538 return c;
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
88 local int gz_init OF((gz_statep));
99 local int gz_comp OF((gz_statep, int));
1010 local int gz_zero OF((gz_statep, z_off64_t));
11 local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
1112
1213 /* 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. */
1416 local int gz_init(state)
1517 gz_statep state;
1618 {
1719 int ret;
1820 z_streamp strm = &(state->strm);
1921
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);
2224 if (state->in == NULL) {
2325 gz_error(state, Z_MEM_ERROR, "out of memory");
2426 return -1;
4648 gz_error(state, Z_MEM_ERROR, "out of memory");
4749 return -1;
4850 }
51 strm->next_in = NULL;
4952 }
5053
5154 /* mark state as initialized */
6164 }
6265
6366 /* 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. */
6972 local int gz_comp(state, flush)
7073 gz_statep state;
7174 int flush;
7275 {
73 int ret, got;
74 unsigned have;
76 int ret, writ;
77 unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
7578 z_streamp strm = &(state->strm);
7679
7780 /* allocate memory if this is the first time through */
8083
8184 /* write directly if requested */
8285 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 }
8996 return 0;
9097 }
9198
96103 doing Z_FINISH then don't write until we get to Z_STREAM_END */
97104 if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
98105 (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;
104115 }
105116 if (strm->avail_out == 0) {
106117 strm->avail_out = state->size;
107118 strm->next_out = state->out;
119 state->x.next = state->out;
108120 }
109 state->x.next = strm->next_out;
110121 }
111122
112123 /* compress */
128139 return 0;
129140 }
130141
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. */
132144 local int gz_zero(state, len)
133145 gz_statep state;
134146 z_off64_t len;
160172 return 0;
161173 }
162174
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;
166179 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;
189183
190184 /* if len is zero, avoid unnecessary operations */
191185 if (len == 0)
208202 do {
209203 unsigned have, copy;
210204
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);
214209 copy = state->size - have;
215210 if (copy > len)
216211 copy = len;
217212 memcpy(state->in + have, buf, copy);
218 strm->avail_in += copy;
213 state->strm.avail_in += copy;
219214 state->x.pos += copy;
220215 buf = (const char *)buf + copy;
221216 len -= copy;
225220 }
226221 else {
227222 /* 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)
229224 return 0;
230225
231226 /* 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;
241300 }
242301
243302 /* -- see zlib.h -- */
274333 strm->next_in = state->in;
275334 have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
276335 if (have < state->size) {
277 state->in[have] = c;
336 state->in[have] = (unsigned char)c;
278337 strm->avail_in++;
279338 state->x.pos++;
280339 return c & 0xff;
282341 }
283342
284343 /* 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)
287346 return -1;
288347 return c & 0xff;
289348 }
294353 const char *str;
295354 {
296355 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;
298367
299368 /* write string */
300 len = (unsigned)strlen(str);
301 ret = gzwrite(file, str, len);
369 len = strlen(str);
370 ret = gz_write(state, str, len);
302371 return ret == 0 && len != 0 ? -1 : ret;
303372 }
304373
308377 /* -- see zlib.h -- */
309378 int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
310379 {
311 int size, len;
380 int len;
381 unsigned left;
382 char *next;
312383 gz_statep state;
313384 z_streamp strm;
314385
315386 /* get internal structure */
316387 if (file == NULL)
317 return -1;
388 return Z_STREAM_ERROR;
318389 state = (gz_statep)file;
319390 strm = &(state->strm);
320391
321392 /* check that we're writing and that there's no error */
322393 if (state->mode != GZ_WRITE || state->err != Z_OK)
323 return 0;
394 return Z_STREAM_ERROR;
324395
325396 /* make sure we have some buffer space */
326397 if (state->size == 0 && gz_init(state) == -1)
327 return 0;
398 return state->err;
328399
329400 /* check for seek request */
330401 if (state->seek) {
331402 state->seek = 0;
332403 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;
343414 #ifdef NO_vsnprintf
344415 # 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;
348419 # else
349 len = vsprintf((char *)(state->in), format, va);
420 len = vsprintf(next, format, va);
350421 # endif
351422 #else
352423 # 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);
355426 # else
356 len = vsnprintf((char *)(state->in), size, format, va);
427 len = vsnprintf(next, state->size, format, va);
357428 # endif
358429 #endif
359430
360431 /* 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;
367437 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 }
368447 return len;
369448 }
370449
389468 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
390469 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
391470 {
392 int size, len;
471 unsigned len, left;
472 char *next;
393473 gz_statep state;
394474 z_streamp strm;
395475
396476 /* get internal structure */
397477 if (file == NULL)
398 return -1;
478 return Z_STREAM_ERROR;
399479 state = (gz_statep)file;
400480 strm = &(state->strm);
401481
402482 /* check that can really pass pointer in ints */
403483 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;
409489
410490 /* make sure we have some buffer space */
411491 if (state->size == 0 && gz_init(state) == -1)
412 return 0;
492 return state->error;
413493
414494 /* check for seek request */
415495 if (state->seek) {
416496 state->seek = 0;
417497 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;
428508 #ifdef NO_snprintf
429509 # 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);
432512 for (len = 0; len < size; len++)
433 if (state->in[len] == 0) break;
513 if (next[len] == 0)
514 break;
434515 # 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);
437518 # endif
438519 #else
439520 # 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);
443524 # 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);
447527 # endif
448528 #endif
449529
450530 /* 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;
457536 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;
459547 }
460548
461549 #endif
469557
470558 /* get internal structure */
471559 if (file == NULL)
472 return -1;
560 return Z_STREAM_ERROR;
473561 state = (gz_statep)file;
474562
475563 /* check that we're writing and that there's no error */
484572 if (state->seek) {
485573 state->seek = 0;
486574 if (gz_zero(state, state->skip) == -1)
487 return -1;
575 return state->err;
488576 }
489577
490578 /* compress remaining data with requested flush */
491 gz_comp(state, flush);
579 (void)gz_comp(state, flush);
492580 return state->err;
493581 }
494582
519607 if (state->seek) {
520608 state->seek = 0;
521609 if (gz_zero(state, state->skip) == -1)
522 return -1;
610 return state->err;
523611 }
524612
525613 /* change compression parameters for subsequent input */
526614 if (state->size) {
527615 /* 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)
529617 return state->err;
530618 deflateParams(strm, level, strategy);
531619 }
00 /* infback.c -- inflate using a call-back interface
1 * Copyright (C) 1995-2011 Mark Adler
1 * Copyright (C) 1995-2016 Mark Adler
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
6060 Tracev((stderr, "inflate: allocated\n"));
6161 strm->state = (struct internal_state FAR *)state;
6262 state->dmax = 32768U;
63 state->wbits = windowBits;
63 state->wbits = (uInt)windowBits;
6464 state->wsize = 1U << windowBits;
6565 state->window = window;
6666 state->wnext = 0;
00 /* inffast.c -- fast decoding
1 * Copyright (C) 1995-2008, 2010, 2013 Mark Adler
1 * Copyright (C) 1995-2017 Mark Adler
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
77 #include "inflate.h"
88 #include "inffast.h"
99
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")
2612 #else
27 # define OFF 1
28 # define PUP(a) *++(a)
29 #endif
3013
3114 /*
3215 Decode literal, length, and distance codes and write out the resulting
9578
9679 /* copy state to local variables */
9780 state = (struct inflate_state FAR *)strm->state;
98 in = strm->next_in - OFF;
81 in = strm->next_in;
9982 last = in + (strm->avail_in - 5);
100 out = strm->next_out - OFF;
83 out = strm->next_out;
10184 beg = out - (start - strm->avail_out);
10285 end = out + (strm->avail_out - 257);
10386 #ifdef INFLATE_STRICT
118101 input data or output space */
119102 do {
120103 if (bits < 15) {
121 hold += (unsigned long)(PUP(in)) << bits;
104 hold += (unsigned long)(*in++) << bits;
122105 bits += 8;
123 hold += (unsigned long)(PUP(in)) << bits;
106 hold += (unsigned long)(*in++) << bits;
124107 bits += 8;
125108 }
126109 here = lcode[hold & lmask];
133116 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
134117 "inflate: literal '%c'\n" :
135118 "inflate: literal 0x%02x\n", here.val));
136 PUP(out) = (unsigned char)(here.val);
119 *out++ = (unsigned char)(here.val);
137120 }
138121 else if (op & 16) { /* length base */
139122 len = (unsigned)(here.val);
140123 op &= 15; /* number of extra bits */
141124 if (op) {
142125 if (bits < op) {
143 hold += (unsigned long)(PUP(in)) << bits;
126 hold += (unsigned long)(*in++) << bits;
144127 bits += 8;
145128 }
146129 len += (unsigned)hold & ((1U << op) - 1);
149132 }
150133 Tracevv((stderr, "inflate: length %u\n", len));
151134 if (bits < 15) {
152 hold += (unsigned long)(PUP(in)) << bits;
135 hold += (unsigned long)(*in++) << bits;
153136 bits += 8;
154 hold += (unsigned long)(PUP(in)) << bits;
137 hold += (unsigned long)(*in++) << bits;
155138 bits += 8;
156139 }
157140 here = dcode[hold & dmask];
164147 dist = (unsigned)(here.val);
165148 op &= 15; /* number of extra bits */
166149 if (bits < op) {
167 hold += (unsigned long)(PUP(in)) << bits;
150 hold += (unsigned long)(*in++) << bits;
168151 bits += 8;
169152 if (bits < op) {
170 hold += (unsigned long)(PUP(in)) << bits;
153 hold += (unsigned long)(*in++) << bits;
171154 bits += 8;
172155 }
173156 }
195178 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
196179 if (len <= op - whave) {
197180 do {
198 PUP(out) = 0;
181 *out++ = 0;
199182 } while (--len);
200183 continue;
201184 }
202185 len -= op - whave;
203186 do {
204 PUP(out) = 0;
187 *out++ = 0;
205188 } while (--op > whave);
206189 if (op == 0) {
207190 from = out - dist;
208191 do {
209 PUP(out) = PUP(from);
192 *out++ = *from++;
210193 } while (--len);
211194 continue;
212195 }
213196 #endif
214197 }
215 from = window - OFF;
198 from = window;
216199 if (wnext == 0) { /* very common case */
217200 from += wsize - op;
218201 if (op < len) { /* some from window */
219202 len -= op;
220203 do {
221 PUP(out) = PUP(from);
204 *out++ = *from++;
222205 } while (--op);
223206 from = out - dist; /* rest from output */
224207 }
229212 if (op < len) { /* some from end of window */
230213 len -= op;
231214 do {
232 PUP(out) = PUP(from);
215 *out++ = *from++;
233216 } while (--op);
234 from = window - OFF;
217 from = window;
235218 if (wnext < len) { /* some from start of window */
236219 op = wnext;
237220 len -= op;
238221 do {
239 PUP(out) = PUP(from);
222 *out++ = *from++;
240223 } while (--op);
241224 from = out - dist; /* rest from output */
242225 }
247230 if (op < len) { /* some from window */
248231 len -= op;
249232 do {
250 PUP(out) = PUP(from);
233 *out++ = *from++;
251234 } while (--op);
252235 from = out - dist; /* rest from output */
253236 }
254237 }
255238 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++;
259242 len -= 3;
260243 }
261244 if (len) {
262 PUP(out) = PUP(from);
245 *out++ = *from++;
263246 if (len > 1)
264 PUP(out) = PUP(from);
247 *out++ = *from++;
265248 }
266249 }
267250 else {
268251 from = out - dist; /* copy direct from output */
269252 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++;
273256 len -= 3;
274257 } while (len > 2);
275258 if (len) {
276 PUP(out) = PUP(from);
259 *out++ = *from++;
277260 if (len > 1)
278 PUP(out) = PUP(from);
261 *out++ = *from++;
279262 }
280263 }
281264 }
312295 hold &= (1U << bits) - 1;
313296
314297 /* 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;
317300 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
318301 strm->avail_out = (unsigned)(out < end ?
319302 257 + (end - out) : 257 - (out - end));
00 /* inflate.c -- zlib decompression
1 * Copyright (C) 1995-2012 Mark Adler
1 * Copyright (C) 1995-2016 Mark Adler
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
9191 #endif
9292
9393 /* function prototypes */
94 local int inflateStateCheck OF((z_streamp strm));
9495 local void fixedtables OF((struct inflate_state FAR *state));
9596 local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
9697 unsigned copy));
100101 local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
101102 unsigned len));
102103
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
103118 int ZEXPORT inflateResetKeep(strm)
104119 z_streamp strm;
105120 {
106121 struct inflate_state FAR *state;
107122
108 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
123 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
109124 state = (struct inflate_state FAR *)strm->state;
110125 strm->total_in = strm->total_out = state->total = 0;
111126 strm->msg = Z_NULL;
130145 {
131146 struct inflate_state FAR *state;
132147
133 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
148 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
134149 state = (struct inflate_state FAR *)strm->state;
135150 state->wsize = 0;
136151 state->whave = 0;
146161 struct inflate_state FAR *state;
147162
148163 /* get the state */
149 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
164 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
150165 state = (struct inflate_state FAR *)strm->state;
151166
152167 /* extract wrap request from windowBits parameter */
155170 windowBits = -windowBits;
156171 }
157172 else {
158 wrap = (windowBits >> 4) + 1;
173 wrap = (windowBits >> 4) + 5;
159174 #ifdef GUNZIP
160175 if (windowBits < 48)
161176 windowBits &= 15;
209224 if (state == Z_NULL) return Z_MEM_ERROR;
210225 Tracev((stderr, "inflate: allocated\n"));
211226 strm->state = (struct internal_state FAR *)state;
227 state->strm = strm;
212228 state->window = Z_NULL;
229 state->mode = HEAD; /* to pass state test in inflateReset2() */
213230 ret = inflateReset2(strm, windowBits);
214231 if (ret != Z_OK) {
215232 ZFREE(strm, state);
233250 {
234251 struct inflate_state FAR *state;
235252
236 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
253 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
237254 state = (struct inflate_state FAR *)strm->state;
238255 if (bits < 0) {
239256 state->hold = 0;
240257 state->bits = 0;
241258 return Z_OK;
242259 }
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;
244261 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;
247264 return Z_OK;
248265 }
249266
624641 static const unsigned short order[19] = /* permutation of code lengths */
625642 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
626643
627 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
644 if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
628645 (strm->next_in == Z_NULL && strm->avail_in != 0))
629646 return Z_STREAM_ERROR;
630647
644661 NEEDBITS(16);
645662 #ifdef GUNZIP
646663 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
664 if (state->wbits == 0)
665 state->wbits = 15;
647666 state->check = crc32(0L, Z_NULL, 0);
648667 CRC2(state->check, hold);
649668 INITBITS();
671690 len = BITS(4) + 8;
672691 if (state->wbits == 0)
673692 state->wbits = len;
674 else if (len > state->wbits) {
693 if (len > 15 || len > state->wbits) {
675694 strm->msg = (char *)"invalid window size";
676695 state->mode = BAD;
677696 break;
698717 }
699718 if (state->head != Z_NULL)
700719 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);
702722 INITBITS();
703723 state->mode = TIME;
704724 case TIME:
705725 NEEDBITS(32);
706726 if (state->head != Z_NULL)
707727 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);
709730 INITBITS();
710731 state->mode = OS;
711732 case OS:
714735 state->head->xflags = (int)(hold & 0xff);
715736 state->head->os = (int)(hold >> 8);
716737 }
717 if (state->flags & 0x0200) CRC2(state->check, hold);
738 if ((state->flags & 0x0200) && (state->wrap & 4))
739 CRC2(state->check, hold);
718740 INITBITS();
719741 state->mode = EXLEN;
720742 case EXLEN:
723745 state->length = (unsigned)(hold);
724746 if (state->head != Z_NULL)
725747 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);
727750 INITBITS();
728751 }
729752 else if (state->head != Z_NULL)
741764 len + copy > state->head->extra_max ?
742765 state->head->extra_max - len : copy);
743766 }
744 if (state->flags & 0x0200)
767 if ((state->flags & 0x0200) && (state->wrap & 4))
745768 state->check = crc32(state->check, next, copy);
746769 have -= copy;
747770 next += copy;
760783 if (state->head != Z_NULL &&
761784 state->head->name != Z_NULL &&
762785 state->length < state->head->name_max)
763 state->head->name[state->length++] = len;
786 state->head->name[state->length++] = (Bytef)len;
764787 } while (len && copy < have);
765 if (state->flags & 0x0200)
788 if ((state->flags & 0x0200) && (state->wrap & 4))
766789 state->check = crc32(state->check, next, copy);
767790 have -= copy;
768791 next += copy;
781804 if (state->head != Z_NULL &&
782805 state->head->comment != Z_NULL &&
783806 state->length < state->head->comm_max)
784 state->head->comment[state->length++] = len;
807 state->head->comment[state->length++] = (Bytef)len;
785808 } while (len && copy < have);
786 if (state->flags & 0x0200)
809 if ((state->flags & 0x0200) && (state->wrap & 4))
787810 state->check = crc32(state->check, next, copy);
788811 have -= copy;
789812 next += copy;
795818 case HCRC:
796819 if (state->flags & 0x0200) {
797820 NEEDBITS(16);
798 if (hold != (state->check & 0xffff)) {
821 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
799822 strm->msg = (char *)"header crc mismatch";
800823 state->mode = BAD;
801824 break;
11761199 out -= left;
11771200 strm->total_out += out;
11781201 state->total += out;
1179 if (out)
1202 if ((state->wrap & 4) && out)
11801203 strm->adler = state->check =
11811204 UPDATE(state->check, put - out, out);
11821205 out = left;
1183 if ((
1206 if ((state->wrap & 4) && (
11841207 #ifdef GUNZIP
11851208 state->flags ? hold :
11861209 #endif
12391262 strm->total_in += in;
12401263 strm->total_out += out;
12411264 state->total += out;
1242 if (state->wrap && out)
1265 if ((state->wrap & 4) && out)
12431266 strm->adler = state->check =
12441267 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) +
12461269 (state->mode == TYPE ? 128 : 0) +
12471270 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
12481271 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
12541277 z_streamp strm;
12551278 {
12561279 struct inflate_state FAR *state;
1257 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1280 if (inflateStateCheck(strm))
12581281 return Z_STREAM_ERROR;
12591282 state = (struct inflate_state FAR *)strm->state;
12601283 if (state->window != Z_NULL) ZFREE(strm, state->window);
12721295 struct inflate_state FAR *state;
12731296
12741297 /* check state */
1275 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1298 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
12761299 state = (struct inflate_state FAR *)strm->state;
12771300
12781301 /* copy dictionary */
12971320 int ret;
12981321
12991322 /* check state */
1300 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1323 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
13011324 state = (struct inflate_state FAR *)strm->state;
13021325 if (state->wrap != 0 && state->mode != DICT)
13031326 return Z_STREAM_ERROR;
13291352 struct inflate_state FAR *state;
13301353
13311354 /* check state */
1332 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1355 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
13331356 state = (struct inflate_state FAR *)strm->state;
13341357 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
13351358
13821405 struct inflate_state FAR *state;
13831406
13841407 /* check parameters */
1385 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1408 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
13861409 state = (struct inflate_state FAR *)strm->state;
13871410 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
13881411
14291452 {
14301453 struct inflate_state FAR *state;
14311454
1432 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1455 if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
14331456 state = (struct inflate_state FAR *)strm->state;
14341457 return state->mode == STORED && state->bits == 0;
14351458 }
14441467 unsigned wsize;
14451468
14461469 /* 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)
14491471 return Z_STREAM_ERROR;
14501472 state = (struct inflate_state FAR *)source->state;
14511473
14661488 /* copy state */
14671489 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
14681490 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1491 copy->strm = dest;
14691492 if (state->lencode >= state->codes &&
14701493 state->lencode <= state->codes + ENOUGH - 1) {
14711494 copy->lencode = copy->codes + (state->lencode - state->codes);
14871510 {
14881511 struct inflate_state FAR *state;
14891512
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
14921516 state->sane = !subvert;
1493 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
14941517 return Z_OK;
14951518 #else
1519 (void)subvert;
14961520 state->sane = 1;
14971521 return Z_DATA_ERROR;
14981522 #endif
14991523 }
15001524
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
15011540 long ZEXPORT inflateMark(strm)
15021541 z_streamp strm;
15031542 {
15041543 struct inflate_state FAR *state;
15051544
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) +
15091549 (state->mode == COPY ? state->length :
15101550 (state->mode == MATCH ? state->was - state->length : 0));
15111551 }
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 }
00 /* inflate.h -- internal inflate state definition
1 * Copyright (C) 1995-2009 Mark Adler
1 * Copyright (C) 1995-2016 Mark Adler
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
1717
1818 /* Possible inflate modes between inflate() calls */
1919 typedef enum {
20 HEAD, /* i: waiting for magic header */
20 HEAD = 16180, /* i: waiting for magic header */
2121 FLAGS, /* i: waiting for method and flags (gzip) */
2222 TIME, /* i: waiting for modification time (gzip) */
2323 OS, /* i: waiting for extra flags and operating system (gzip) */
7676 CHECK -> LENGTH -> DONE
7777 */
7878
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. */
8081 struct inflate_state {
82 z_streamp strm; /* pointer back to this zlib stream */
8183 inflate_mode mode; /* current inflate mode */
8284 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 */
8487 int havedict; /* true if dictionary provided */
8588 int flags; /* gzip header method and flags (0 if zlib) */
8689 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
00 /* inftrees.c -- generate Huffman trees for efficient decoding
1 * Copyright (C) 1995-2013 Mark Adler
1 * Copyright (C) 1995-2017 Mark Adler
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
88 #define MAXBITS 15
99
1010 const char inflate_copyright[] =
11 " inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
11 " inflate 1.2.11 Copyright 1995-2017 Mark Adler ";
1212 /*
1313 If you use the zlib library in a product, an acknowledgment is welcome
1414 in the documentation of your product. If for some reason you cannot
5353 code FAR *next; /* next available space in table */
5454 const unsigned short FAR *base; /* base value table to use */
5555 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 */
5757 unsigned short count[MAXBITS+1]; /* number of codes of each length */
5858 unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
5959 static const unsigned short lbase[31] = { /* Length codes 257..285 base */
6161 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
6262 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
6363 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};
6565 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
6666 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
6767 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
180180 switch (type) {
181181 case CODES:
182182 base = extra = work; /* dummy value--not used */
183 end = 19;
183 match = 20;
184184 break;
185185 case LENS:
186186 base = lbase;
187 base -= 257;
188187 extra = lext;
189 extra -= 257;
190 end = 256;
188 match = 257;
191189 break;
192 default: /* DISTS */
190 default: /* DISTS */
193191 base = dbase;
194192 extra = dext;
195 end = -1;
193 match = 0;
196194 }
197195
198196 /* initialize state for loop */
215213 for (;;) {
216214 /* create table entry */
217215 here.bits = (unsigned char)(len - drop);
218 if ((int)(work[sym]) < end) {
216 if (work[sym] + 1U < match) {
219217 here.op = (unsigned char)0;
220218 here.val = work[sym];
221219 }
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];
225223 }
226224 else {
227225 here.op = (unsigned char)(32 + 64); /* end of block */
00 /* trees.c -- output deflated data using Huffman coding
1 * Copyright (C) 1995-2012 Jean-loup Gailly
1 * Copyright (C) 1995-2017 Jean-loup Gailly
22 * detect_data_type() function provided freely by Cosmin Truta, 2006
33 * For conditions of distribution and use, see copyright notice in zlib.h
44 */
3535
3636 #include "deflate.h"
3737
38 #ifdef DEBUG
38 #ifdef ZLIB_DEBUG
3939 # include <ctype.h>
4040 #endif
4141
121121 int max_length; /* max bit length for the codes */
122122 };
123123
124 local static_tree_desc static_l_desc =
124 local const static_tree_desc static_l_desc =
125125 {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
126126
127 local static_tree_desc static_d_desc =
127 local const static_tree_desc static_d_desc =
128128 {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
129129
130 local static_tree_desc static_bl_desc =
130 local const static_tree_desc static_bl_desc =
131131 {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
132132
133133 /* ===========================================================================
151151 local unsigned bi_reverse OF((unsigned value, int length));
152152 local void bi_windup OF((deflate_state *s));
153153 local void bi_flush OF((deflate_state *s));
154 local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
155 int header));
156154
157155 #ifdef GEN_TREES_H
158156 local void gen_trees_header OF((void));
159157 #endif
160158
161 #ifndef DEBUG
159 #ifndef ZLIB_DEBUG
162160 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
163161 /* Send a code of the given tree. c and tree must not have side effects */
164162
165 #else /* DEBUG */
163 #else /* !ZLIB_DEBUG */
166164 # define send_code(s, c, tree) \
167165 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
168166 send_bits(s, tree[c].Code, tree[c].Len); }
181179 * Send a value on a given number of bits.
182180 * IN assertion: length <= 16 and value fits in length bits.
183181 */
184 #ifdef DEBUG
182 #ifdef ZLIB_DEBUG
185183 local void send_bits OF((deflate_state *s, int value, int length));
186184
187185 local void send_bits(s, value, length)
207205 s->bi_valid += length;
208206 }
209207 }
210 #else /* !DEBUG */
208 #else /* !ZLIB_DEBUG */
211209
212210 #define send_bits(s, value, length) \
213211 { int len = length;\
214212 if (s->bi_valid > (int)Buf_size - len) {\
215 int val = value;\
213 int val = (int)value;\
216214 s->bi_buf |= (ush)val << s->bi_valid;\
217215 put_short(s, s->bi_buf);\
218216 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
222220 s->bi_valid += len;\
223221 }\
224222 }
225 #endif /* DEBUG */
223 #endif /* ZLIB_DEBUG */
226224
227225
228226 /* the arguments must not have side effects */
316314 * Genererate the file trees.h describing the static trees.
317315 */
318316 #ifdef GEN_TREES_H
319 # ifndef DEBUG
317 # ifndef ZLIB_DEBUG
320318 # include <stdio.h>
321319 # endif
322320
393391
394392 s->bi_buf = 0;
395393 s->bi_valid = 0;
396 #ifdef DEBUG
394 #ifdef ZLIB_DEBUG
397395 s->compressed_len = 0L;
398396 s->bits_sent = 0L;
399397 #endif
521519 xbits = 0;
522520 if (n >= base) xbits = extra[n-base];
523521 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);
526524 }
527525 if (overflow == 0) return;
528526
529 Trace((stderr,"\nbit length overflow\n"));
527 Tracev((stderr,"\nbit length overflow\n"));
530528 /* This happens for example on obj2 and pic of the Calgary corpus */
531529
532530 /* Find the first bit length which could increase: */
553551 m = s->heap[--h];
554552 if (m > max_code) continue;
555553 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;
559556 tree[m].Len = (ush)bits;
560557 }
561558 n--;
577574 ushf *bl_count; /* number of codes at each bit length */
578575 {
579576 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 */
581578 int bits; /* bit index */
582579 int n; /* code index */
583580
585582 * without bit reversal.
586583 */
587584 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;
589587 }
590588 /* Check that the bit counts in bl_count are consistent. The last code
591589 * must be all ones.
598596 int len = tree[n].Len;
599597 if (len == 0) continue;
600598 /* 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);
602600
603601 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
604602 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
820818 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
821819 }
822820 /* 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;
824822 Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
825823 s->opt_len, s->static_len));
826824
868866 int last; /* one if this is the last block for a file */
869867 {
870868 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
872875 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
873876 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
876880 }
877881
878882 /* ===========================================================================
893897 {
894898 send_bits(s, STATIC_TREES<<1, 3);
895899 send_code(s, END_BLOCK, static_ltree);
896 #ifdef DEBUG
900 #ifdef ZLIB_DEBUG
897901 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
898902 #endif
899903 bi_flush(s);
901905
902906 /* ===========================================================================
903907 * 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.
905909 */
906910 void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
907911 deflate_state *s;
973977 send_bits(s, (STATIC_TREES<<1)+last, 3);
974978 compress_block(s, (const ct_data *)static_ltree,
975979 (const ct_data *)static_dtree);
976 #ifdef DEBUG
980 #ifdef ZLIB_DEBUG
977981 s->compressed_len += 3 + s->static_len;
978982 #endif
979983 } else {
982986 max_blindex+1);
983987 compress_block(s, (const ct_data *)s->dyn_ltree,
984988 (const ct_data *)s->dyn_dtree);
985 #ifdef DEBUG
989 #ifdef ZLIB_DEBUG
986990 s->compressed_len += 3 + s->opt_len;
987991 #endif
988992 }
994998
995999 if (last) {
9961000 bi_windup(s);
997 #ifdef DEBUG
1001 #ifdef ZLIB_DEBUG
9981002 s->compressed_len += 7; /* align on byte boundary */
9991003 #endif
10001004 }
10891093 send_code(s, code, dtree); /* send the distance code */
10901094 extra = extra_dbits[code];
10911095 if (extra != 0) {
1092 dist -= base_dist[code];
1096 dist -= (unsigned)base_dist[code];
10931097 send_bits(s, dist, extra); /* send the extra distance bits */
10941098 }
10951099 } /* literal or match pair ? */
11921196 }
11931197 s->bi_buf = 0;
11941198 s->bi_valid = 0;
1195 #ifdef DEBUG
1199 #ifdef ZLIB_DEBUG
11961200 s->bits_sent = (s->bits_sent+7) & ~7;
11971201 #endif
11981202 }
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 }
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
88 #include "zlib.h"
99
1010 /* ===========================================================================
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.
1820
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.
2225 */
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
2385 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
2486 Bytef *dest;
2587 uLongf *destLen;
2688 const Bytef *source;
2789 uLong sourceLen;
2890 {
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);
5892 }
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
1616 #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
1717 # define Z_PREFIX_SET
1818
19 /* all linked symbols */
19 /* all linked symbols and init macros */
2020 # define _dist_code z__dist_code
2121 # define _length_code z__length_code
2222 # define _tr_align z__tr_align
2828 # define adler32 z_adler32
2929 # define adler32_combine z_adler32_combine
3030 # define adler32_combine64 z_adler32_combine64
31 # define adler32_z z_adler32_z
3132 # ifndef Z_SOLO
3233 # define compress z_compress
3334 # define compress2 z_compress2
3637 # define crc32 z_crc32
3738 # define crc32_combine z_crc32_combine
3839 # define crc32_combine64 z_crc32_combine64
40 # define crc32_z z_crc32_z
3941 # define deflate z_deflate
4042 # define deflateBound z_deflateBound
4143 # define deflateCopy z_deflateCopy
4244 # define deflateEnd z_deflateEnd
45 # define deflateGetDictionary z_deflateGetDictionary
46 # define deflateInit z_deflateInit
47 # define deflateInit2 z_deflateInit2
4348 # define deflateInit2_ z_deflateInit2_
4449 # define deflateInit_ z_deflateInit_
4550 # define deflateParams z_deflateParams
6671 # define gzeof z_gzeof
6772 # define gzerror z_gzerror
6873 # define gzflush z_gzflush
74 # define gzfread z_gzfread
75 # define gzfwrite z_gzfwrite
6976 # define gzgetc z_gzgetc
7077 # define gzgetc_ z_gzgetc_
7178 # define gzgets z_gzgets
7784 # define gzopen_w z_gzopen_w
7885 # endif
7986 # define gzprintf z_gzprintf
80 # define gzvprintf z_gzvprintf
8187 # define gzputc z_gzputc
8288 # define gzputs z_gzputs
8389 # define gzread z_gzread
8894 # define gztell z_gztell
8995 # define gztell64 z_gztell64
9096 # define gzungetc z_gzungetc
97 # define gzvprintf z_gzvprintf
9198 # define gzwrite z_gzwrite
9299 # endif
93100 # define inflate z_inflate
94101 # define inflateBack z_inflateBack
95102 # define inflateBackEnd z_inflateBackEnd
103 # define inflateBackInit z_inflateBackInit
96104 # define inflateBackInit_ z_inflateBackInit_
105 # define inflateCodesUsed z_inflateCodesUsed
97106 # define inflateCopy z_inflateCopy
98107 # define inflateEnd z_inflateEnd
108 # define inflateGetDictionary z_inflateGetDictionary
99109 # define inflateGetHeader z_inflateGetHeader
110 # define inflateInit z_inflateInit
111 # define inflateInit2 z_inflateInit2
100112 # define inflateInit2_ z_inflateInit2_
101113 # define inflateInit_ z_inflateInit_
102114 # define inflateMark z_inflateMark
103115 # define inflatePrime z_inflatePrime
104116 # define inflateReset z_inflateReset
105117 # define inflateReset2 z_inflateReset2
118 # define inflateResetKeep z_inflateResetKeep
106119 # define inflateSetDictionary z_inflateSetDictionary
107 # define inflateGetDictionary z_inflateGetDictionary
108120 # define inflateSync z_inflateSync
109121 # define inflateSyncPoint z_inflateSyncPoint
110122 # define inflateUndermine z_inflateUndermine
111 # define inflateResetKeep z_inflateResetKeep
123 # define inflateValidate z_inflateValidate
112124 # define inflate_copyright z_inflate_copyright
113125 # define inflate_fast z_inflate_fast
114126 # define inflate_table z_inflate_table
115127 # ifndef Z_SOLO
116128 # define uncompress z_uncompress
129 # define uncompress2 z_uncompress2
117130 # endif
118131 # define zError z_zError
119132 # ifndef Z_SOLO
223236 # define z_const
224237 #endif
225238
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
229252 #endif
230253
231254 /* Maximum value for memLevel in deflateInit2 */
255278 Of course this will generally degrade compression (there's no free lunch).
256279
257280 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
259282 for small objects.
260283 */
261284
00 /* 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
44
55 This software is provided 'as-is', without any express or implied
66 warranty. In no event will the authors be held liable for any damages
3636 extern "C" {
3737 #endif
3838
39 #define ZLIB_VERSION "1.2.8"
40 #define ZLIB_VERNUM 0x1280
39 #define ZLIB_VERSION "1.2.11"
40 #define ZLIB_VERNUM 0x12b0
4141 #define ZLIB_VER_MAJOR 1
4242 #define ZLIB_VER_MINOR 2
43 #define ZLIB_VER_REVISION 8
43 #define ZLIB_VER_REVISION 11
4444 #define ZLIB_VER_SUBREVISION 0
4545
4646 /*
6464 with "gz". The gzip format is different from the zlib format. gzip is a
6565 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
6666
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.
6869
6970 The zlib format was designed to be compact and fast for use in memory
7071 and on communications channels. The gzip format was designed for single-
7374
7475 The library does not install any signal handler. The decoder checks
7576 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.
7778 */
7879
7980 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
8687 uInt avail_in; /* number of bytes available at next_in */
8788 uLong total_in; /* total number of input bytes read so far */
8889
89 Bytef *next_out; /* next output byte should be put there */
90 Bytef *next_out; /* next output byte will go here */
9091 uInt avail_out; /* remaining free space at next_out */
9192 uLong total_out; /* total number of bytes output so far */
9293
9798 free_func zfree; /* used to free the internal state */
9899 voidpf opaque; /* private data object passed to zalloc and zfree */
99100
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 */
102104 uLong reserved; /* reserved for future use */
103105 } z_stream;
104106
141143
142144 zalloc must return Z_NULL if there is not enough memory for the object.
143145 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().
145149
146150 On 16-bit systems, the functions zalloc and zfree must be able to allocate
147151 exactly 65536 bytes, but will not be required to allocate more than this if
154158
155159 The fields total_in and total_out can be used for statistics or progress
156160 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
158162 if the decompressor wants to decompress everything in a single step).
159163 */
160164
199203 #define Z_TEXT 1
200204 #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
201205 #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() */
203207
204208 #define Z_DEFLATED 8
205209 /* The deflate compression method (the only one supported in this version) */
257261 enough room in the output buffer), next_in and avail_in are updated and
258262 processing will resume at this point for the next call of deflate().
259263
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
261265 accordingly. This action is forced if the parameter flush is non zero.
262266 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.
265269
266270 Before the call of deflate(), the application should ensure that at least
267271 one of the actions is possible, by providing more input and/or consuming more
270274 output when it wants, for example when the output buffer is full (avail_out
271275 == 0), or after each call of deflate(). If deflate returns Z_OK and with
272276 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.
274280
275281 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
276282 decide how much data to accumulate before producing output, in order to
291297 input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
292298 This completes the current deflate block and follows it with an empty fixed
293299 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.
296302
297303 If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
298304 for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
318324
319325 If the parameter flush is set to Z_FINISH, pending input is processed,
320326 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.)
335344
336345 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.
340349
341350 deflate() returns Z_OK if some progress has been made (more input
342351 processed or more output produced), Z_STREAM_END if all input has been
343352 consumed and all output has been produced (only when flush is set to
344353 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.
349359 */
350360
351361
368378
369379 Initializes the internal stream state for decompression. The fields
370380 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.
377386
378387 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
379388 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
380389 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
381390 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.
388396 */
389397
390398
400408
401409 - Decompress more input starting at next_in and update next_in and avail_in
402410 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
407416 accordingly. inflate() provides as much output as possible, until there is
408417 no more input data or no more space in the output buffer (see below about
409418 the flush parameter).
410419
411420 Before the call of inflate(), the application should ensure that at least
412421 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
414425 application can consume the uncompressed output when it wants, for example
415426 when the output buffer is full (avail_out == 0), or after each call of
416427 inflate(). If inflate returns Z_OK and with zero avail_out, it must be
427438 gets to the end of that block, or when it runs out of data.
428439
429440 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
431442 number of unused bits in the last byte taken from strm->next_in, plus 64 if
432443 inflate() is currently decoding the last block in the deflate stream, plus
433444 128 if inflate() returned immediately after decoding an end-of-block code or
453464 this case all pending input is processed and all pending output is flushed;
454465 avail_out must be large enough to hold all of the uncompressed data for the
455466 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
457468 required to perform an inflation in one step. However it may be used to
458469 inform inflate that a faster approach can be used for the single inflate()
459470 call. Z_FINISH also informs inflate to not maintain a sliding window if the
475486 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
476487 strm->adler to the Adler-32 checksum of all output produced so far (that is,
477488 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
479490 checksum is equal to that saved by the compressor and returns Z_STREAM_END
480491 only if the checksum is correct.
481492
482493 inflate() can decompress and check either zlib-wrapped or gzip-wrapped
483494 deflate data. The header type is detected automatically, if requested when
484495 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
488497 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.
490500
491501 inflate() returns Z_OK if some progress has been made (more input processed
492502 or more output produced), Z_STREAM_END if the end of the compressed data has
493503 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
494504 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
495505 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
500512 inflate() can be called again with more input and more output space to
501513 continue decompressing. If Z_DATA_ERROR is returned, the application may
502514 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.
504516 */
505517
506518
510522 This function discards any unprocessed input and does not flush any pending
511523 output.
512524
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.
516527 */
517528
518529
543554 compression at the expense of memory usage. The default value is 15 if
544555 deflateInit is used instead.
545556
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
546565 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
547566 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.
549568
550569 windowBits can also be greater than 15 for optional gzip encoding. Add
551570 16 to windowBits to write a simple gzip header and trailer around the
552571 compressed data instead of a zlib wrapper. The gzip header will have no
553572 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.
556580
557581 The memLevel parameter specifies how much memory should be allocated
558582 for the internal compression state. memLevel=1 uses minimum memory but is
613637 addition, the current implementation of deflate will use at most the window
614638 size minus 262 bytes of the provided dictionary.
615639
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
617641 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
619643 applies to the whole dictionary even if only a subset of the dictionary is
620644 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.
622646
623647 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
624648 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
625649 inconsistent (for example if deflate has already been called for this stream
626650 or if not at a block boundary for raw deflate). deflateSetDictionary does
627651 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.
628674 */
629675
630676 ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
647693
648694 ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
649695 /*
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.
654700
655701 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
656702 stream state was inconsistent (such as zalloc or state being Z_NULL).
661707 int strategy));
662708 /*
663709 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
665711 used to switch between compression and straight copy of the input data, or
666712 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.
678740 */
679741
680742 ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
792854 is for use with other formats that use the deflate compressed data format
793855 such as zip. Those formats provide their own check values. If a custom
794856 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
796858 the uncompressed data as is done in the zlib, gzip, and zip formats. For
797859 most applications, the zlib format should be used as is. Note that comments
798860 above on the use in deflateInit2() applies to the magnitude of windowBits.
801863 32 to windowBits to enable zlib and gzip decoding with automatic header
802864 detection, or add 16 to decode only the gzip format (the zlib format will
803865 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.
805870
806871 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
807872 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
822887 Initializes the decompression dictionary from the given uncompressed byte
823888 sequence. This function must be called immediately after a call of inflate,
824889 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.
826891 The compressor and decompressor must use exactly the same dictionary (see
827892 deflateSetDictionary). For raw inflate, this function can be called at any
828893 time to set the dictionary. If the provided dictionary is smaller than the
833898 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
834899 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
835900 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
837902 perform any decompression: this will be done by subsequent calls of
838903 inflate().
839904 */
891956 ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
892957 /*
893958 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
895960 stream will keep attributes that may have been set by inflateInit2.
896961
897962 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
903968 /*
904969 This function is the same as inflateReset, but it also permits changing
905970 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.
907974
908975 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
909976 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
9551022 location in the input stream can be determined from avail_in and data_type
9561023 as noted in the description for the Z_BLOCK flush parameter for inflate.
9571024
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
9591026 source stream state was inconsistent.
9601027 */
9611028
10471114 This routine would normally be used in a utility that reads zip or gzip
10481115 files and writes out uncompressed files. The utility would decode the
10491116 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.
10531120
10541121 inflateBack() uses two subroutines supplied by the caller that are then
10551122 called by inflateBack() for input and output. inflateBack() calls those
10581125 parameters and return types are defined above in the in_func and out_func
10591126 typedefs. inflateBack() will call in(in_desc, &buf) which should return the
10601127 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
10671134 inflateBackInit(), which is also the buffer that out() uses to write from.
10681135 The length written by out() will be at most the window size. Any non-zero
10691136 amount of input may be provided by in().
10911158 using strm->next_in which will be Z_NULL only if in() returned an error. If
10921159 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
10931160 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()
10951162 cannot return Z_OK.
10961163 */
10971164
11131180 7.6: size of z_off_t
11141181
11151182 Compiler, assembler, and debug options:
1116 8: DEBUG
1183 8: ZLIB_DEBUG
11171184 9: ASMV or ASMINF -- use ASM code
11181185 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
11191186 11: 0 (reserved)
11631230 the byte length of the source buffer. Upon entry, destLen is the total size
11641231 of the destination buffer, which must be at least the value returned by
11651232 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.
11671235
11681236 compress returns Z_OK if success, Z_MEM_ERROR if there was not
11691237 enough memory, Z_BUF_ERROR if there was not enough room in the output
11791247 length of the source buffer. Upon entry, destLen is the total size of the
11801248 destination buffer, which must be at least the value returned by
11811249 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1182 compressed buffer.
1250 compressed data.
11831251
11841252 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
11851253 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
12021270 uncompressed data. (The size of the uncompressed data must have been saved
12031271 previously by the compressor and transmitted to the decompressor by some
12041272 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.
12061274
12071275 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
12081276 enough memory, Z_BUF_ERROR if there was not enough room in the output
12091277 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
12101278 the case where there is not enough room, uncompress() will fill the output
12111279 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.
12121288 */
12131289
12141290 /* gzip file access functions */
12891365 default buffer size is 8192 bytes. This function must be called after
12901366 gzopen() or gzdopen(), and before any other calls that read or write the
12911367 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).
12961371
12971372 The new buffer size also affects the maximum length for gzprintf().
12981373
13031378 ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
13041379 /*
13051380 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.
13101387 */
13111388
13121389 ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
13341411 case.
13351412
13361413 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.
13381443 */
13391444
13401445 ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
13451450 error.
13461451 */
13471452
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
13481467 ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
13491468 /*
13501469 Converts, formats, and writes the arguments to the compressed file under
13511470 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().
13611480 */
13621481
13631482 ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
14171536 If the flush parameter is Z_FINISH, the remaining data is written and the
14181537 gzip stream is completed in the output. If gzwrite() is called again, a new
14191538 gzip stream will be started in the output. gzread() is able to read such
1420 concatented gzip streams.
1539 concatenated gzip streams.
14211540
14221541 gzflush should be called only when strictly necessary because it will
14231542 degrade compression if called too often.
15711690 return the updated checksum. If buf is Z_NULL, this function returns the
15721691 required initial value for the checksum.
15731692
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
15751694 much faster.
15761695
15771696 Usage example:
15821701 adler = adler32(adler, buffer, length);
15831702 }
15841703 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.
15851710 */
15861711
15871712 /*
16111736 crc = crc32(crc, buffer, length);
16121737 }
16131738 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.
16141745 */
16151746
16161747 /*
16431774 unsigned char FAR *window,
16441775 const char *version,
16451776 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
16591806
16601807 #ifndef Z_SOLO
16611808
16751822 #ifdef Z_PREFIX_SET
16761823 # undef z_gzgetc
16771824 # 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))
16791826 #else
16801827 # 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))
16821829 #endif
16831830
16841831 /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
17361883
17371884 #endif /* !Z_SOLO */
17381885
1739 /* hack for buggy compilers */
1740 #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1741 struct internal_state {int dummy;};
1742 #endif
1743
17441886 /* undocumented functions */
17451887 ZEXTERN const char * ZEXPORT zError OF((int));
17461888 ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
17471889 ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
17481890 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));
17491893 ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
17501894 ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
1751 #if defined(_WIN32) && !defined(Z_SOLO)
1895 #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO)
17521896 ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
17531897 const char *mode));
17541898 #endif
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
99 # include "gzguts.h"
1010 #endif
1111
12 #ifndef NO_DUMMY_DECL
13 struct internal_state {int dummy;}; /* for buggy compilers */
14 #endif
15
1612 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 };
2724
2825
2926 const char * ZEXPORT zlibVersion()
6057 case 8: flags += 2 << 6; break;
6158 default: flags += 3 << 6;
6259 }
63 #ifdef DEBUG
60 #ifdef ZLIB_DEBUG
6461 flags += 1 << 8;
6562 #endif
6663 #if defined(ASMV) || defined(ASMINF)
114111 return flags;
115112 }
116113
117 #ifdef DEBUG
118
114 #ifdef ZLIB_DEBUG
115 #include <stdlib.h>
119116 # ifndef verbose
120117 # define verbose 0
121118 # endif
218215
219216 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
220217 {
221 voidpf buf = opaque; /* just to make some compilers happy */
218 voidpf buf;
222219 ulg bsize = (ulg)items*size;
220
221 (void)opaque;
223222
224223 /* If we allocate less than 65520 bytes, we assume that farmalloc
225224 * will return a usable pointer which doesn't have to be normalized.
243242 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
244243 {
245244 int n;
245
246 (void)opaque;
247
246248 if (*(ush*)&ptr != 0) { /* object < 64K */
247249 farfree(ptr);
248250 return;
258260 next_ptr--;
259261 return;
260262 }
261 ptr = opaque; /* just to make some compilers happy */
262263 Assert(0, "zcfree: ptr not found");
263264 }
264265
277278
278279 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
279280 {
280 if (opaque) opaque = 0; /* to make compiler happy */
281 (void)opaque;
281282 return _halloc((long)items, size);
282283 }
283284
284285 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
285286 {
286 if (opaque) opaque = 0; /* to make compiler happy */
287 (void)opaque;
287288 _hfree(ptr);
288289 }
289290
305306 unsigned items;
306307 unsigned size;
307308 {
308 if (opaque) items += size - size; /* make compiler happy */
309 (void)opaque;
309310 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
310311 (voidpf)calloc(items, size);
311312 }
314315 voidpf opaque;
315316 voidpf ptr;
316317 {
318 (void)opaque;
317319 free(ptr);
318 if (opaque) return; /* make compiler happy */
319320 }
320321
321322 #endif /* MY_ZCALLOC */
00 /* 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
22 * For conditions of distribution and use, see copyright notice in zlib.h
33 */
44
3535 #ifndef local
3636 # define local static
3737 #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) */
3941
4042 typedef unsigned char uch;
4143 typedef uch FAR uchf;
9799 #endif
98100
99101 #ifdef AMIGA
100 # define OS_CODE 0x01
102 # define OS_CODE 1
101103 #endif
102104
103105 #if defined(VAXC) || defined(VMS)
104 # define OS_CODE 0x02
106 # define OS_CODE 2
105107 # define F_OPEN(name, mode) \
106108 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
107109 #endif
108110
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
109121 #if defined(ATARI) || defined(atarist)
110 # define OS_CODE 0x05
122 # define OS_CODE 5
111123 #endif
112124
113125 #ifdef OS2
114 # define OS_CODE 0x06
126 # define OS_CODE 6
115127 # if defined(M_I86) && !defined(Z_SOLO)
116128 # include <malloc.h>
117129 # endif
118130 #endif
119131
120132 #if defined(MACOS) || defined(TARGET_OS_MAC)
121 # define OS_CODE 0x07
133 # define OS_CODE 7
122134 # ifndef Z_SOLO
123135 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
124136 # include <unix.h> /* for fdopen */
130142 # endif
131143 #endif
132144
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
145163 #endif
146164
147165 #if defined(_BEOS_) || defined(RISCOS)
176194 /* common defaults */
177195
178196 #ifndef OS_CODE
179 # define OS_CODE 0x03 /* assume Unix */
197 # define OS_CODE 3 /* assume Unix */
180198 #endif
181199
182200 #ifndef F_OPEN
215233 #endif
216234
217235 /* Diagnostic functions */
218 #ifdef DEBUG
236 #ifdef ZLIB_DEBUG
219237 # include <stdio.h>
220238 extern int ZLIB_INTERNAL z_verbose;
221239 extern void ZLIB_INTERNAL z_error OF((char *m));
00 /*
1 * Copyright (c) Tony Bybell 1999-2016.
1 * Copyright (c) Tony Bybell 1999-2017.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
35013501 char *namex;
35023502 int was_packed = HIER_DEPACK_ALLOC;
35033503
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
35043511 namex = hier_decompress_flagged(n[0]->nname, &was_packed);
35053512
35063513 offset = strlen(namex);
35103517 }
35113518 if(ix>-1) offset=ix;
35123519
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 */
35143545 memcpy(nam, namex, offset);
35153546 if(was_packed) { free_2(namex); }
35163547
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
35173593 if(direction)
35183594 {
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 }
35203624 }
35213625 else
35223626 {
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 }
35243656 }
35253657
35263658 strcpy(b->name=(char *)malloc_2(offset + strlen(nam+offset)+1), nam);
182182
183183 GLOBALS->regex_which_search_c_1=(int)((intptr_t)which);
184184 GLOBALS->regex_mutex_search_c_1[GLOBALS->regex_which_search_c_1] = 1; /* mark our choice */
185
186185
187186 DEBUG(printf("picked: %s\n", regex_name[GLOBALS->regex_which_search_c_1]));
188187 }
949948 GtkTooltips *tooltips;
950949 GtkAdjustment *adj;
951950 GtkWidget *align;
951 int cached_which = GLOBALS->regex_which_search_c_1;
952952
953953 /* fix problem where ungrab doesn't occur if button pressed + simultaneous accelerator key occurs */
954954 if(GLOBALS->in_button_press_wavewindow_c_1) { gdk_pointer_ungrab(GDK_CURRENT_TIME); }
10961096 gtk_widget_show (GLOBALS->menuitem_search[i]);
10971097 gtkwave_signal_connect(GTK_OBJECT (GLOBALS->menuitem_search[i]), "activate", GTK_SIGNAL_FUNC(regex_clicked), (void *)((intptr_t)i));
10981098 GLOBALS->regex_mutex_search_c_1[i]=0;
1099 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (GLOBALS->menuitem_search[i]), FALSE); //
10991100 }
11001101
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);
11021106
11031107 optionmenu = gtk_option_menu_new ();
11041108 gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
00 /*
1 * Copyright (c) Tony Bybell 1999-2014.
1 * Copyright (c) Tony Bybell 1999-2017.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
15541554 {
15551555 if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
15561556 {
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 }
15581561 /* all this formerly was goto err; */
15591562 }
15601563 else
15671570 {
15681571 if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
15691572 {
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 }
15711577 /* all this formerly was goto err; */
15721578 }
15731579 else
23062312 /* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */
23072313 {
23082314 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 }
23092331 }
23102332 else
23112333 {
00 /*
1 * Copyright (c) Tony Bybell 1999-2011.
1 * Copyright (c) Tony Bybell 1999-2017.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
15021502 {
15031503 if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
15041504 {
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 }
15061509 /* all this formerly was goto err; */
15071510 }
15081511 else
15151518 {
15161519 if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
15171520 {
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 }
15191525 /* all this formerly was goto err; */
15201526 }
15211527 else
21572163 /* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */
21582164 {
21592165 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 }
21602182 }
21612183 else
21622184 {
00 /*
1 * Copyright (c) Tony Bybell 1999-2014.
1 * Copyright (c) Tony Bybell 1999-2017.
22 *
33 * This program is free software; you can redistribute it and/or
44 * modify it under the terms of the GNU General Public License
19001900 {
19011901 if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
19021902 {
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 }
19041907 /* all this formerly was goto err; */
19051908 }
19061909 else
19131916 {
19141917 if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
19151918 {
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 }
19171923 /* all this formerly was goto err; */
19181924 }
19191925 else
25392545 /* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */
25402546 {
25412547 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 }
25422564 }
25432565 else
25442566 {