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