1*10465441SEvalZero /* maketree.c -- make inffixed.h table for decoding fixed codes
2*10465441SEvalZero * Copyright (C) 1995-2002 Mark Adler
3*10465441SEvalZero * For conditions of distribution and use, see copyright notice in zlib.h
4*10465441SEvalZero */
5*10465441SEvalZero
6*10465441SEvalZero /* WARNING: this file should *not* be used by applications. It is
7*10465441SEvalZero part of the implementation of the compression library and is
8*10465441SEvalZero subject to change. Applications should only use zlib.h.
9*10465441SEvalZero */
10*10465441SEvalZero
11*10465441SEvalZero /* This program is included in the distribution for completeness.
12*10465441SEvalZero You do not need to compile or run this program since inffixed.h
13*10465441SEvalZero is already included in the distribution. To use this program
14*10465441SEvalZero you need to compile zlib with BUILDFIXED defined and then compile
15*10465441SEvalZero and link this program with the zlib library. Then the output of
16*10465441SEvalZero this program can be piped to inffixed.h. */
17*10465441SEvalZero
18*10465441SEvalZero #include <stdio.h>
19*10465441SEvalZero #include <stdlib.h>
20*10465441SEvalZero #include "zutil.h"
21*10465441SEvalZero #include "inftrees.h"
22*10465441SEvalZero
23*10465441SEvalZero /* simplify the use of the inflate_huft type with some defines */
24*10465441SEvalZero #define exop word.what.Exop
25*10465441SEvalZero #define bits word.what.Bits
26*10465441SEvalZero
27*10465441SEvalZero /* generate initialization table for an inflate_huft structure array */
maketree(uInt b,inflate_huft * t)28*10465441SEvalZero void maketree(uInt b, inflate_huft *t)
29*10465441SEvalZero {
30*10465441SEvalZero int i, e;
31*10465441SEvalZero
32*10465441SEvalZero i = 0;
33*10465441SEvalZero while (1)
34*10465441SEvalZero {
35*10465441SEvalZero e = t[i].exop;
36*10465441SEvalZero if (e && (e & (16+64)) == 0) /* table pointer */
37*10465441SEvalZero {
38*10465441SEvalZero fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
39*10465441SEvalZero exit(1);
40*10465441SEvalZero }
41*10465441SEvalZero if (i % 4 == 0)
42*10465441SEvalZero printf("\n ");
43*10465441SEvalZero printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
44*10465441SEvalZero if (++i == (1<<b))
45*10465441SEvalZero break;
46*10465441SEvalZero putchar(',');
47*10465441SEvalZero }
48*10465441SEvalZero puts("");
49*10465441SEvalZero }
50*10465441SEvalZero
51*10465441SEvalZero /* create the fixed tables in C initialization syntax */
main(void)52*10465441SEvalZero void main(void)
53*10465441SEvalZero {
54*10465441SEvalZero int r;
55*10465441SEvalZero uInt bl, bd;
56*10465441SEvalZero inflate_huft *tl, *td;
57*10465441SEvalZero z_stream z;
58*10465441SEvalZero
59*10465441SEvalZero z.zalloc = zcalloc;
60*10465441SEvalZero z.opaque = (voidpf)0;
61*10465441SEvalZero z.zfree = zcfree;
62*10465441SEvalZero r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
63*10465441SEvalZero if (r)
64*10465441SEvalZero {
65*10465441SEvalZero fprintf(stderr, "inflate_trees_fixed error %d\n", r);
66*10465441SEvalZero return;
67*10465441SEvalZero }
68*10465441SEvalZero puts("/* inffixed.h -- table for decoding fixed codes");
69*10465441SEvalZero puts(" * Generated automatically by the maketree.c program");
70*10465441SEvalZero puts(" */");
71*10465441SEvalZero puts("");
72*10465441SEvalZero puts("/* WARNING: this file should *not* be used by applications. It is");
73*10465441SEvalZero puts(" part of the implementation of the compression library and is");
74*10465441SEvalZero puts(" subject to change. Applications should only use zlib.h.");
75*10465441SEvalZero puts(" */");
76*10465441SEvalZero puts("");
77*10465441SEvalZero printf("local uInt fixed_bl = %d;\n", bl);
78*10465441SEvalZero printf("local uInt fixed_bd = %d;\n", bd);
79*10465441SEvalZero printf("local inflate_huft fixed_tl[] = {");
80*10465441SEvalZero maketree(bl, tl);
81*10465441SEvalZero puts(" };");
82*10465441SEvalZero printf("local inflate_huft fixed_td[] = {");
83*10465441SEvalZero maketree(bd, td);
84*10465441SEvalZero puts(" };");
85*10465441SEvalZero }
86