Mark ChangeLog
[official-gcc.git] / zlib / maketree.c
blob949d786418513e2c492ebeb53a9a67673158e49f
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 */
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 */
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. */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "zutil.h"
21 #include "inftrees.h"
23 /* simplify the use of the inflate_huft type with some defines */
24 #define exop word.what.Exop
25 #define bits word.what.Bits
27 /* generate initialization table for an inflate_huft structure array */
28 void maketree(uInt b, inflate_huft *t)
30 int i, e;
32 i = 0;
33 while (1)
35 e = t[i].exop;
36 if (e && (e & (16+64)) == 0) /* table pointer */
38 fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
39 exit(1);
41 if (i % 4 == 0)
42 printf("\n ");
43 printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
44 if (++i == (1<<b))
45 break;
46 putchar(',');
48 puts("");
51 /* create the fixed tables in C initialization syntax */
52 void main(void)
54 int r;
55 uInt bl, bd;
56 inflate_huft *tl, *td;
57 z_stream z;
59 z.zalloc = zcalloc;
60 z.opaque = (voidpf)0;
61 z.zfree = zcfree;
62 r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
63 if (r)
65 fprintf(stderr, "inflate_trees_fixed error %d\n", r);
66 return;
68 puts("/* inffixed.h -- table for decoding fixed codes");
69 puts(" * Generated automatically by the maketree.c program");
70 puts(" */");
71 puts("");
72 puts("/* WARNING: this file should *not* be used by applications. It is");
73 puts(" part of the implementation of the compression library and is");
74 puts(" subject to change. Applications should only use zlib.h.");
75 puts(" */");
76 puts("");
77 printf("local uInt fixed_bl = %d;\n", bl);
78 printf("local uInt fixed_bd = %d;\n", bd);
79 printf("local inflate_huft fixed_tl[] = {");
80 maketree(bl, tl);
81 puts(" };");
82 printf("local inflate_huft fixed_td[] = {");
83 maketree(bd, td);
84 puts(" };");