]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/zlib/maketree.c
regenerated
[wxWidgets.git] / src / zlib / maketree.c
... / ...
CommitLineData
1/* maketree.c -- make inffixed.h table for decoding fixed codes
2 * Copyright (C) 1998 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
9 */
10
11/* This program is included in the distribution for completeness.
12 You do not need to compile or run this program since inffixed.h
13 is already included in the distribution. To use this program
14 you need to compile zlib with BUILDFIXED defined and then compile
15 and link this program with the zlib library. Then the output of
16 this program can be piped to inffixed.h. */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include "zutil.h"
21#include "inftrees.h"
22
23/* simplify the use of the inflate_huft type with some defines */
24#define exop word.what.Exop
25#define bits word.what.Bits
26
27/* showtree is only used for debugging purposes */
28void showtree(uInt b, inflate_huft *t, int d)
29{
30 int i, e;
31 char p[2*d+1];
32
33 for (i = 0; i < 2*d; i++)
34 p[i] = ' ';
35 p[i] = 0;
36 printf("%s[%d]\n", p, 1<<b);
37 for (i = 0; i < (1<<b); i++)
38 {
39 e = t[i].exop;
40 if (e == 0) /* simple code */
41 printf("%s%d(%d): literal=%d\n", p, i, t[i].bits, t[i].base);
42 else if (e & 16) /* length */
43 printf("%s%d(%d): length/distance=%d+(%d)\n",
44 p, i, t[i].bits, t[i].base, e & 15);
45 else if ((e & 64) == 0) /* next table */
46 {
47 printf("%s%d(%d): *sub table*\n", p, i, t[i].bits);
48 showtree(e, t + t[i].base, d + 1);
49 }
50 else if (e & 32) /* end of block */
51 printf("%s%d(%d): end of block\n", p, i, t[i].bits);
52 else /* bad code */
53 printf("%s%d: bad code\n", p, i);
54 }
55}
56
57/* generate initialization table for an inflate_huft structure array */
58void maketree(uInt b, inflate_huft *t)
59{
60 int i, e;
61
62 i = 0;
63 while (1)
64 {
65 e = t[i].exop;
66 if (e && (e & (16+64)) == 0) /* table pointer */
67 {
68 fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
69 exit(1);
70 }
71 if (i % 5 == 0)
72 printf("\n ");
73 printf(" {{%u,%u},%u}", t[i].exop, t[i].bits, t[i].base);
74 if (++i == (1<<b))
75 break;
76 putchar(',');
77 }
78 puts("");
79}
80
81/* create the fixed tables in C initialization syntax */
82void main(void)
83{
84 int r;
85 uInt bl, bd;
86 inflate_huft *tl, *td;
87 z_stream z;
88
89 z.zalloc = zcalloc;
90 z.opaque = (voidpf)0;
91 z.zfree = zcfree;
92 r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
93 if (r)
94 {
95 fprintf(stderr, "inflate_trees_fixed error %d\n", r);
96 return;
97 }
98 /* puts("Literal/Length Tree:");
99 showtree(bl, tl, 1);
100 puts("Distance Tree:");
101 showtree(bd, td, 1); */
102 puts("/* inffixed.h -- table for decoding fixed codes");
103 puts(" * Generated automatically by the maketree.c program");
104 puts(" */");
105 puts("");
106 puts("/* WARNING: this file should *not* be used by applications. It is");
107 puts(" part of the implementation of the compression library and is");
108 puts(" subject to change. Applications should only use zlib.h.");
109 puts(" */");
110 puts("");
111 printf("local uInt fixed_bl = %d;\n", bl);
112 printf("local uInt fixed_bd = %d;\n", bd);
113 printf("local inflate_huft fixed_tl[] = {");
114 maketree(bl, tl);
115 puts(" };");
116 printf("local inflate_huft fixed_td[] = {");
117 maketree(bd, td);
118 puts(" };");
119}