- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# maketree.c

    00001 /* maketree.c -- make inffixed.h table for decoding fixed codes
    00002  * Copyright (C) 1995-2002 Mark Adler
    00003  * For conditions of distribution and use, see copyright notice in zlib.h
    00004  */
    00005
    00006 /* WARNING: this file should *not* be used by applications. It is
    00007    part of the implementation of the compression library and is
    00008    subject to change. Applications should only use zlib.h.
    00009  */
    00010
    00011 /* This program is included in the distribution for completeness.
    00012    You do not need to compile or run this program since inffixed.h
    00013    is already included in the distribution.  To use this program
    00014    you need to compile zlib with BUILDFIXED defined and then compile
    00015    and link this program with the zlib library.  Then the output of
    00016    this program can be piped to inffixed.h. */
    00017
    00018 #include <stdio.h>
    00019 #include <stdlib.h>
    00020 #include "zutil.h"
    00021 #include "inftrees.h"
    00022
    00023 /* simplify the use of the inflate_huft type with some defines */
    00024 #define exop word.what.Exop
    00025 #define bits word.what.Bits
    00026
    00027 /* generate initialization table for an inflate_huft structure array */
    00028 void maketree(uInt b, inflate_huft *t)
    00029 {
    00030   int i, e;
    00031
    00032   i = 0;
    00033   while (1)
    00034   {
    00035     e = t[i].exop;
    00036     if (e && (e & (16+64)) == 0)        /* table pointer */
    00037     {
    00038       fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
    00039       exit(1);
    00040     }
    00041     if (i % 4 == 0)
    00042       printf("\n   ");
    00043     printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
    00044     if (++i == (1<<b))
    00045       break;
    00046     putchar(',');
    00047   }
    00048   puts("");
    00049 }
    00050
    00051 /* create the fixed tables in C initialization syntax */
    00052 void main(void)
    00053 {
    00054   int r;
    00055   uInt bl, bd;
    00056   inflate_huft *tl, *td;
    00057   z_stream z;
    00058
    00059   z.zalloc = zcalloc;
    00060   z.opaque = (voidpf)0;
    00061   z.zfree = zcfree;
    00062   r = inflate_trees_fixed(&bl, &bd, &tl, &td, &z);
    00063   if (r)
    00064   {
    00065     fprintf(stderr, "inflate_trees_fixed error %d\n", r);
    00066     return;
    00067   }
    00068   puts("/* inffixed.h -- table for decoding fixed codes");
    00069   puts(" * Generated automatically by the maketree.c program");
    00070   puts(" */");
    00071   puts("");
    00072   puts("/* WARNING: this file should *not* be used by applications. It is");
    00073   puts("   part of the implementation of the compression library and is");
    00074   puts("   subject to change. Applications should only use zlib.h.");
    00075   puts(" */");
    00076   puts("");
    00077   printf("local uInt fixed_bl = %d;\n", bl);
    00078   printf("local uInt fixed_bd = %d;\n", bd);
    00079   printf("local inflate_huft fixed_tl[] = {");
    00080   maketree(bl, tl);
    00081   puts("  };");
    00082   printf("local inflate_huft fixed_td[] = {");
    00083   maketree(bd, td);
    00084   puts("  };");
    00085 }