diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:21:57 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:21:57 -0700 |
| commit | 13a294f044ef0a89b2dcbfbb5d4d4c792673348e (patch) | |
| tree | d9b377b4d8c00633c3da4e96659bfba9b08287f2 /trees.c | |
| parent | 7c2a874e50b871d04fbd19501f7b42cff55e5abc (diff) | |
| download | zlib-13a294f044ef0a89b2dcbfbb5d4d4c792673348e.tar.gz zlib-13a294f044ef0a89b2dcbfbb5d4d4c792673348e.tar.bz2 zlib-13a294f044ef0a89b2dcbfbb5d4d4c792673348e.zip | |
zlib 1.2.0.1v1.2.0.1
Diffstat (limited to 'trees.c')
| -rw-r--r-- | trees.c | 76 |
1 files changed, 38 insertions, 38 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | /* trees.c -- output deflated data using Huffman coding | 1 | /* trees.c -- output deflated data using Huffman coding |
| 2 | * Copyright (C) 1995-2003 Jean-loup Gailly | 2 | * Copyright (C) 1995-2003 Jean-loup Gailly |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | /* | 6 | /* |
| @@ -334,42 +334,42 @@ void gen_trees_header() | |||
| 334 | 334 | ||
| 335 | Assert (header != NULL, "Can't open trees.h"); | 335 | Assert (header != NULL, "Can't open trees.h"); |
| 336 | fprintf(header, | 336 | fprintf(header, |
| 337 | "/* header created automatically with -DGEN_TREES_H */\n\n"); | 337 | "/* header created automatically with -DGEN_TREES_H */\n\n"); |
| 338 | 338 | ||
| 339 | fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); | 339 | fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); |
| 340 | for (i = 0; i < L_CODES+2; i++) { | 340 | for (i = 0; i < L_CODES+2; i++) { |
| 341 | fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, | 341 | fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, |
| 342 | static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); | 342 | static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); |
| 343 | } | 343 | } |
| 344 | 344 | ||
| 345 | fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); | 345 | fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); |
| 346 | for (i = 0; i < D_CODES; i++) { | 346 | for (i = 0; i < D_CODES; i++) { |
| 347 | fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, | 347 | fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, |
| 348 | static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); | 348 | static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); | 351 | fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n"); |
| 352 | for (i = 0; i < DIST_CODE_LEN; i++) { | 352 | for (i = 0; i < DIST_CODE_LEN; i++) { |
| 353 | fprintf(header, "%2u%s", _dist_code[i], | 353 | fprintf(header, "%2u%s", _dist_code[i], |
| 354 | SEPARATOR(i, DIST_CODE_LEN-1, 20)); | 354 | SEPARATOR(i, DIST_CODE_LEN-1, 20)); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); | 357 | fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); |
| 358 | for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { | 358 | for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { |
| 359 | fprintf(header, "%2u%s", _length_code[i], | 359 | fprintf(header, "%2u%s", _length_code[i], |
| 360 | SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); | 360 | SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); | 363 | fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); |
| 364 | for (i = 0; i < LENGTH_CODES; i++) { | 364 | for (i = 0; i < LENGTH_CODES; i++) { |
| 365 | fprintf(header, "%1u%s", base_length[i], | 365 | fprintf(header, "%1u%s", base_length[i], |
| 366 | SEPARATOR(i, LENGTH_CODES-1, 20)); | 366 | SEPARATOR(i, LENGTH_CODES-1, 20)); |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | fprintf(header, "local const int base_dist[D_CODES] = {\n"); | 369 | fprintf(header, "local const int base_dist[D_CODES] = {\n"); |
| 370 | for (i = 0; i < D_CODES; i++) { | 370 | for (i = 0; i < D_CODES; i++) { |
| 371 | fprintf(header, "%5u%s", base_dist[i], | 371 | fprintf(header, "%5u%s", base_dist[i], |
| 372 | SEPARATOR(i, D_CODES-1, 10)); | 372 | SEPARATOR(i, D_CODES-1, 10)); |
| 373 | } | 373 | } |
| 374 | 374 | ||
| 375 | fclose(header); | 375 | fclose(header); |
| @@ -930,39 +930,39 @@ void _tr_flush_block(s, buf, stored_len, eof) | |||
| 930 | /* Build the Huffman trees unless a stored block is forced */ | 930 | /* Build the Huffman trees unless a stored block is forced */ |
| 931 | if (s->level > 0) { | 931 | if (s->level > 0) { |
| 932 | 932 | ||
| 933 | /* Check if the file is ascii or binary */ | 933 | /* Check if the file is ascii or binary */ |
| 934 | if (s->data_type == Z_UNKNOWN) set_data_type(s); | 934 | if (s->data_type == Z_UNKNOWN) set_data_type(s); |
| 935 | 935 | ||
| 936 | /* Construct the literal and distance trees */ | 936 | /* Construct the literal and distance trees */ |
| 937 | build_tree(s, (tree_desc *)(&(s->l_desc))); | 937 | build_tree(s, (tree_desc *)(&(s->l_desc))); |
| 938 | Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, | 938 | Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, |
| 939 | s->static_len)); | 939 | s->static_len)); |
| 940 | 940 | ||
| 941 | build_tree(s, (tree_desc *)(&(s->d_desc))); | 941 | build_tree(s, (tree_desc *)(&(s->d_desc))); |
| 942 | Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, | 942 | Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, |
| 943 | s->static_len)); | 943 | s->static_len)); |
| 944 | /* At this point, opt_len and static_len are the total bit lengths of | 944 | /* At this point, opt_len and static_len are the total bit lengths of |
| 945 | * the compressed block data, excluding the tree representations. | 945 | * the compressed block data, excluding the tree representations. |
| 946 | */ | 946 | */ |
| 947 | 947 | ||
| 948 | /* Build the bit length tree for the above two trees, and get the index | 948 | /* Build the bit length tree for the above two trees, and get the index |
| 949 | * in bl_order of the last bit length code to send. | 949 | * in bl_order of the last bit length code to send. |
| 950 | */ | 950 | */ |
| 951 | max_blindex = build_bl_tree(s); | 951 | max_blindex = build_bl_tree(s); |
| 952 | 952 | ||
| 953 | /* Determine the best encoding. Compute the block lengths in bytes. */ | 953 | /* Determine the best encoding. Compute the block lengths in bytes. */ |
| 954 | opt_lenb = (s->opt_len+3+7)>>3; | 954 | opt_lenb = (s->opt_len+3+7)>>3; |
| 955 | static_lenb = (s->static_len+3+7)>>3; | 955 | static_lenb = (s->static_len+3+7)>>3; |
| 956 | 956 | ||
| 957 | Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", | 957 | Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", |
| 958 | opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, | 958 | opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, |
| 959 | s->last_lit)); | 959 | s->last_lit)); |
| 960 | 960 | ||
| 961 | if (static_lenb <= opt_lenb) opt_lenb = static_lenb; | 961 | if (static_lenb <= opt_lenb) opt_lenb = static_lenb; |
| 962 | 962 | ||
| 963 | } else { | 963 | } else { |
| 964 | Assert(buf != (char*)0, "lost buf"); | 964 | Assert(buf != (char*)0, "lost buf"); |
| 965 | opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ | 965 | opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ |
| 966 | } | 966 | } |
| 967 | 967 | ||
| 968 | #ifdef FORCE_STORED | 968 | #ifdef FORCE_STORED |
| @@ -1199,7 +1199,7 @@ local void copy_block(s, buf, len, header) | |||
| 1199 | s->last_eob_len = 8; /* enough lookahead for inflate */ | 1199 | s->last_eob_len = 8; /* enough lookahead for inflate */ |
| 1200 | 1200 | ||
| 1201 | if (header) { | 1201 | if (header) { |
| 1202 | put_short(s, (ush)len); | 1202 | put_short(s, (ush)len); |
| 1203 | put_short(s, (ush)~len); | 1203 | put_short(s, (ush)~len); |
| 1204 | #ifdef DEBUG | 1204 | #ifdef DEBUG |
| 1205 | s->bits_sent += 2*16; | 1205 | s->bits_sent += 2*16; |
