summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-github@circlestorm.org>2019-08-08 10:38:06 +0200
committerGitHub <noreply@github.com>2019-08-08 10:38:06 +0200
commit74a3e05bfa71e17f5b28d5f64d35e1cbe1b71a6a (patch)
treef544b536b2bb85755a8e71c3f64bc4d0b4320c68 /tools
parent340f2f6ef64ba91c5e9576a2a097657e28186ec7 (diff)
Remove BUILDFIXED and MAKEFIXED. (#375)
Remove BUILDFIXED support. Split out MAKEFIXED into a separate 'makefixed' util that is easy to use if we want to regenerate/verify inffixed.h.
Diffstat (limited to 'tools')
-rw-r--r--tools/makefixed.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/tools/makefixed.c b/tools/makefixed.c
new file mode 100644
index 0000000..0f983bd
--- /dev/null
+++ b/tools/makefixed.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include "zbuild.h"
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+
+// Build and return state with length and distance decoding tables and index sizes set to fixed code decoding.
+void ZLIB_INTERNAL buildfixedtables(struct inflate_state *state) {
+ static code *lenfix, *distfix;
+ static code fixed[544];
+
+ // build fixed huffman tables
+ unsigned sym, bits;
+ static code *next;
+
+ // literal/length table
+ sym = 0;
+ while (sym < 144) state->lens[sym++] = 8;
+ while (sym < 256) state->lens[sym++] = 9;
+ while (sym < 280) state->lens[sym++] = 7;
+ while (sym < 288) state->lens[sym++] = 8;
+ next = fixed;
+ lenfix = next;
+ bits = 9;
+ zng_inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
+
+ // distance table
+ sym = 0;
+ while (sym < 32) state->lens[sym++] = 5;
+ distfix = next;
+ bits = 5;
+ zng_inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
+
+ state->lencode = lenfix;
+ state->lenbits = 9;
+ state->distcode = distfix;
+ state->distbits = 5;
+}
+
+
+// Create fixed tables on the fly and write out a inffixed.h file that is #include'd above.
+// makefixed() writes those tables to stdout, which would be piped to inffixed.h.
+void makefixed(void) {
+ unsigned low, size;
+ struct inflate_state state;
+
+ buildfixedtables(&state);
+ puts(" /* inffixed.h -- table for decoding fixed codes");
+ puts(" * Generated automatically by makefixed().");
+ puts(" */");
+ puts("");
+ puts(" /* WARNING: this file should *not* be used by applications.");
+ puts(" It is part of the implementation of this library and is");
+ puts(" subject to change. Applications should only use zlib.h.");
+ puts(" */");
+ puts("");
+ size = 1U << 9;
+ printf(" static const code lenfix[%u] = {", size);
+ low = 0;
+ for (;;) {
+ if ((low % 7) == 0)
+ printf("\n ");
+ printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
+ state.lencode[low].bits, state.lencode[low].val);
+ if (++low == size)
+ break;
+ putchar(',');
+ }
+ puts("\n };");
+ size = 1U << 5;
+ printf("\n static const code distfix[%u] = {", size);
+ low = 0;
+ for (;;) {
+ if ((low % 6) == 0)
+ printf("\n ");
+ printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, state.distcode[low].val);
+ if (++low == size)
+ break;
+ putchar(',');
+ }
+ puts("\n };");
+}
+
+// The output of this application can be piped out to recreate inffixed.h
+int main(void) {
+ makefixed();
+ return 0;
+}
+