- Copyright (C) 1997, 1999, 2006, 2009-2010 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1999, 2006, 2009-2012 Free Software Foundation, Inc.
Copyright (C) 1992-1993 Jean-loup Gailly
This program is free software; you can redistribute it and/or modify
Copyright (C) 1992-1993 Jean-loup Gailly
This program is free software; you can redistribute it and/or modify
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
/* The arguments must not have side effects. */
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
/* The arguments must not have side effects. */
- leaves[len] = (int)get_byte();
- if (max_leaves - (len == max_len) < leaves[len])
- gzip_error ("too many leaves in Huffman tree");
- max_leaves = (max_leaves - leaves[len] + 1) * 2 - 1;
- n += leaves[len];
+ leaves[len] = (int)get_byte();
+ if (max_leaves - (len == max_len) < leaves[len])
+ gzip_error ("too many leaves in Huffman tree");
+ max_leaves = (max_leaves - leaves[len] + 1) * 2 - 1;
+ n += leaves[len];
}
Trace((stderr, "orig_len %lu, max_len %d, leaves %d\n",
}
Trace((stderr, "orig_len %lu, max_len %d, leaves %d\n",
/* There are at least 2 and at most 256 leaves of length max_len.
* (Pack arbitrarily rejects empty files and files consisting of
* a single byte even repeated.) To fit the last leaf count in a
/* There are at least 2 and at most 256 leaves of length max_len.
* (Pack arbitrarily rejects empty files and files consisting of
* a single byte even repeated.) To fit the last leaf count in a
- /* Remember where the literals of this length start in literal[] : */
- lit_base[len] = base;
- /* And read the literals: */
- for (n = leaves[len]; n > 0; n--) {
- literal[base++] = (uch)get_byte();
- }
+ /* Remember where the literals of this length start in literal[] : */
+ lit_base[len] = base;
+ /* And read the literals: */
+ for (n = leaves[len]; n > 0; n--) {
+ literal[base++] = (uch)get_byte();
+ }
- /* The number of parent nodes at this level is half the total
- * number of nodes at parent level:
- */
- nodes >>= 1;
- parents[len] = nodes;
- /* Update lit_base by the appropriate bias to skip the parent nodes
- * (which are not represented in the literal array):
- */
- lit_base[len] -= nodes;
- /* Restore nodes to be parents+leaves: */
- nodes += leaves[len];
+ /* The number of parent nodes at this level is half the total
+ * number of nodes at parent level:
+ */
+ nodes >>= 1;
+ parents[len] = nodes;
+ /* Update lit_base by the appropriate bias to skip the parent nodes
+ * (which are not represented in the literal array):
+ */
+ lit_base[len] -= nodes;
+ /* Restore nodes to be parents+leaves: */
+ nodes += leaves[len];
}
/* Construct the prefix table, from shortest leaves to longest ones.
* The shortest code is all ones, so we start at the end of the table.
}
/* Construct the prefix table, from shortest leaves to longest ones.
* The shortest code is all ones, so we start at the end of the table.
peek_bits = MIN(max_len, MAX_PEEK);
prefixp = &prefix_len[1<<peek_bits];
for (len = 1; len <= peek_bits; len++) {
peek_bits = MIN(max_len, MAX_PEEK);
prefixp = &prefix_len[1<<peek_bits];
for (len = 1; len <= peek_bits; len++) {
- int prefixes = leaves[len] << (peek_bits-len); /* may be 0 */
- while (prefixes--) *--prefixp = (uch)len;
+ int prefixes = leaves[len] << (peek_bits-len); /* may be 0 */
+ while (prefixes--) *--prefixp = (uch)len;
- */
- look_bits(peek, peek_bits, peek_mask);
- len = prefix_len[peek];
- if (len > 0) {
- peek >>= peek_bits - len; /* discard the extra bits */
- } else {
- /* Code of more than peek_bits bits, we must traverse the tree */
- ulg mask = peek_mask;
- len = peek_bits;
- do {
+ */
+ look_bits(peek, peek_bits, peek_mask);
+ len = prefix_len[peek];
+ if (len > 0) {
+ peek >>= peek_bits - len; /* discard the extra bits */
+ } else {
+ /* Code of more than peek_bits bits, we must traverse the tree */
+ ulg mask = peek_mask;
+ len = peek_bits;
+ do {
- look_bits(peek, len, mask);
- } while (peek < (unsigned)parents[len]);
- /* loop as long as peek is a parent node */
- }
- /* At this point, peek is the next complete code, of len bits */
- if (peek == eob && len == max_len) break; /* end of file? */
- put_ubyte(literal[peek+lit_base[len]]);
- Tracev((stderr,"%02d %04x %c\n", len, peek,
- literal[peek+lit_base[len]]));
- skip_bits(len);
+ look_bits(peek, len, mask);
+ } while (peek < (unsigned)parents[len]);
+ /* loop as long as peek is a parent node */
+ }
+ /* At this point, peek is the next complete code, of len bits */
+ if (peek == eob && len == max_len) break; /* end of file? */
+ put_ubyte(literal[peek+lit_base[len]]);
+ Tracev((stderr,"%02d %04x %c\n", len, peek,
+ literal[peek+lit_base[len]]));
+ skip_bits(len);