219
219
// If BMAX needs to be larger than 16, then h and x[] should be uLong.
220
220
static final int BMAX=15; // maximum bit length of any code
222
static int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
224
int n, // number of codes (assumed <= 288)
225
int s, // number of simple-valued codes (0..s-1)
226
int[] d, // list of base values for non-simple codes
227
int[] e, // list of extra bits for non-simple codes
228
int[] t, // result: starting table
229
int[] m, // maximum lookup bits, returns actual
230
int[] hp,// space for trees
231
int[] hn,// hufts used in space
232
int[] v // working area: values in order of bit length
222
int[] hn = null; // hufts used in space
223
int[] v = null; // work area for huft_build
224
int[] c = null; // bit length count table
225
int[] r = null; // table entry for structure assignment
226
int[] u = null; // table stack
227
int[] x = null; // bit offsets, then code stack
229
private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
231
int n, // number of codes (assumed <= 288)
232
int s, // number of simple-valued codes (0..s-1)
233
int[] d, // list of base values for non-simple codes
234
int[] e, // list of extra bits for non-simple codes
235
int[] t, // result: starting table
236
int[] m, // maximum lookup bits, returns actual
237
int[] hp,// space for trees
238
int[] hn,// hufts used in space
239
int[] v // working area: values in order of bit length
234
241
// Given a list of code lengths and a maximum table size, make a set of
235
242
// tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
236
243
// if the given code set is incomplete (the tables are still built in this
412
416
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
415
static int inflate_trees_bits(int[] c, // 19 code lengths
416
int[] bb, // bits tree desired/actual depth
417
int[] tb, // bits tree result
418
int[] hp, // space for trees
419
ZStream z // for messages
422
int[] hn = new int[1]; // hufts used in space
423
int[] v=new int[19]; // work area for huft_build
425
r = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
427
if (r == Z_DATA_ERROR){
419
int inflate_trees_bits(int[] c, // 19 code lengths
420
int[] bb, // bits tree desired/actual depth
421
int[] tb, // bits tree result
422
int[] hp, // space for trees
423
ZStream z // for messages
428
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
430
if(result == Z_DATA_ERROR){
428
431
z.msg = "oversubscribed dynamic bit lengths tree";
430
else if (r == Z_BUF_ERROR || bb[0] == 0){
433
else if(result == Z_BUF_ERROR || bb[0] == 0){
431
434
z.msg = "incomplete dynamic bit lengths tree";
435
result = Z_DATA_ERROR;
437
static int inflate_trees_dynamic(int nl, // number of literal/length codes
440
int inflate_trees_dynamic(int nl, // number of literal/length codes
438
441
int nd, // number of distance codes
439
442
int[] c, // that many (total) code lengths
440
int[] bl, // literal desired/actual bit depth
441
int[] bd, // distance desired/actual bit depth
442
int[] tl, // literal/length tree result
443
int[] td, // distance tree result
444
int[] hp, // space for trees
445
ZStream z // for messages
448
int[] hn = new int[1]; // hufts used in space
449
int[] v=new int[288]; // work area for huft_build
443
int[] bl, // literal desired/actual bit depth
444
int[] bd, // distance desired/actual bit depth
445
int[] tl, // literal/length tree result
446
int[] td, // distance tree result
447
int[] hp, // space for trees
448
ZStream z // for messages
451
452
// build literal/length tree
452
r = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
453
if (r != Z_OK || bl[0] == 0){
454
if(r == Z_DATA_ERROR){
455
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
456
if (result != Z_OK || bl[0] == 0){
457
if(result == Z_DATA_ERROR){
455
458
z.msg = "oversubscribed literal/length tree";
457
else if (r != Z_MEM_ERROR){
460
else if (result != Z_MEM_ERROR){
458
461
z.msg = "incomplete literal/length tree";
462
result = Z_DATA_ERROR;
464
467
// build distance tree
465
r = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
469
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
467
if (r != Z_OK || (bd[0] == 0 && nl > 257)){
468
if (r == Z_DATA_ERROR){
471
if (result != Z_OK || (bd[0] == 0 && nl > 257)){
472
if (result == Z_DATA_ERROR){
469
473
z.msg = "oversubscribed distance tree";
471
else if (r == Z_BUF_ERROR) {
475
else if (result == Z_BUF_ERROR) {
472
476
z.msg = "incomplete distance tree";
477
result = Z_DATA_ERROR;
475
else if (r != Z_MEM_ERROR){
479
else if (result != Z_MEM_ERROR){
476
480
z.msg = "empty distance tree with lengths";
481
result = Z_DATA_ERROR;