Debian Codegraph @

src/lib/static_tables.c

raw symbols SCIP
1 /*
2 Build and output length and distance decoding tables for fixed code
3 decoding.
4 */
5 #include <stdio.h>
6
7 #include "static_tables.h"
8
9 void gen_static_table9(struct inflate_state FAR *state, code *fixed, code *distfix, code *lenfix) {
10 unsigned sym, bits;
11 static code *next;
12
13 /* literal/length table */
14 sym = 0;
15 while (sym < 144) state->lens[sym++] = 8;
16 while (sym < 256) state->lens[sym++] = 9;
17 while (sym < 280) state->lens[sym++] = 7;
18 while (sym < 288) state->lens[sym++] = 8;
19 next = fixed;
20 lenfix = next;
21 bits = 9;
22 inflate_table9(LENS, state->lens, 288, &(next), &(bits), state->work);
23
24 /* distance table */
25 sym = 0;
26 while (sym < 32) state->lens[sym++] = 5;
27 distfix = next;
28 bits = 5;
29 inflate_table9(DISTS, state->lens, 32, &(next), &(bits), state->work);
30 }
31
32 #ifdef GEN_TREES_H
33 /*
34 Write out the inflate_tree.h.
35 makefixed() writes those tables to stdout, which would be piped to inflate_tree.h.
36 */
37 void make_inflate_tree() {
38 unsigned sym, bits, low, size;
39 static code *lenfix, *distfix;
40 struct inflate_state state;
41 static code fixed[544];
42
43 gen_static_table9(&state, fixed, distfix, lenfix);
44
45 FILE *header = fopen("inflate_tree.h", "w");
46
47 /* write tables */
48 fprintf(header, " /* inflate_fixed9.h -- table for decoding deflate64 fixed codes\n");
49 fprintf(header, " * Generated automatically by makefixed9().\n");
50 fprintf(header, " */\n\n");
51 fprintf(header, " /* WARNING: this file should *not* be used by applications.\n");
52 fprintf(header, " It is part of the implementation of this library and is\n");
53 fprintf(header, " subject to change.\n");
54 fprintf(header, " */\n\n");
55 size = 1U << 9;
56 fprintf(header, " static const code lenfix[%u] = {", size);
57 low = 0;
58 for (;;) {
59 if ((low % 6) == 0) fprintf(header, "\n ");
60 fprintf(header, "{%u,%u,%d}", lenfix[low].op, lenfix[low].bits,
61 lenfix[low].val);
62 if (++low == size) break;
63 fprintf(header, ",");
64 }
65 fprintf(header, "\n };");
66 size = 1U << 5;
67 fprintf(header, "\n static const code distfix[%u] = {", size);
68 low = 0;
69 for (;;) {
70 if ((low % 5) == 0) fprintf(header, "\n ");
71 fprintf(header, "{%u,%u,%d}", distfix[low].op, distfix[low].bits,
72 distfix[low].val);
73 if (++low == size) break;
74 fprintf(header, ",");
75 }
76 fprintf(header, "\n };\n");
77 }
78
79
80 int main(int argc, char* argv[]) {
81 make_inflate_tree();
82 make_deflate_tree();
83 }
84 #endif /* GEN_TREES_H */