Hex Artifact Content

Not logged in

Artifact e665ffa93f444da9a2b376dafee7ef416a8adf32:


0000: 2f 2a 20 6d 61 6b 65 74 72 65 65 2e 63 20 2d 2d  /* maketree.c --
0010: 20 6d 61 6b 65 20 69 6e 66 66 69 78 65 64 2e 68   make inffixed.h
0020: 20 74 61 62 6c 65 20 66 6f 72 20 64 65 63 6f 64   table for decod
0030: 69 6e 67 20 66 69 78 65 64 20 63 6f 64 65 73 0a  ing fixed codes.
0040: 20 2a 20 43 6f 70 79 72 69 67 68 74 20 28 43 29   * Copyright (C)
0050: 20 31 39 39 38 20 4d 61 72 6b 20 41 64 6c 65 72   1998 Mark Adler
0060: 0a 20 2a 20 46 6f 72 20 63 6f 6e 64 69 74 69 6f  . * For conditio
0070: 6e 73 20 6f 66 20 64 69 73 74 72 69 62 75 74 69  ns of distributi
0080: 6f 6e 20 61 6e 64 20 75 73 65 2c 20 73 65 65 20  on and use, see 
0090: 63 6f 70 79 72 69 67 68 74 20 6e 6f 74 69 63 65  copyright notice
00a0: 20 69 6e 20 7a 6c 69 62 2e 68 20 0a 20 2a 2f 0a   in zlib.h . */.
00b0: 0a 2f 2a 20 57 41 52 4e 49 4e 47 3a 20 74 68 69  ./* WARNING: thi
00c0: 73 20 66 69 6c 65 20 73 68 6f 75 6c 64 20 2a 6e  s file should *n
00d0: 6f 74 2a 20 62 65 20 75 73 65 64 20 62 79 20 61  ot* be used by a
00e0: 70 70 6c 69 63 61 74 69 6f 6e 73 2e 20 49 74 20  pplications. It 
00f0: 69 73 0a 20 20 20 70 61 72 74 20 6f 66 20 74 68  is.   part of th
0100: 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e  e implementation
0110: 20 6f 66 20 74 68 65 20 63 6f 6d 70 72 65 73 73   of the compress
0120: 69 6f 6e 20 6c 69 62 72 61 72 79 20 61 6e 64 20  ion library and 
0130: 69 73 0a 20 20 20 73 75 62 6a 65 63 74 20 74 6f  is.   subject to
0140: 20 63 68 61 6e 67 65 2e 20 41 70 70 6c 69 63 61   change. Applica
0150: 74 69 6f 6e 73 20 73 68 6f 75 6c 64 20 6f 6e 6c  tions should onl
0160: 79 20 75 73 65 20 7a 6c 69 62 2e 68 2e 0a 20 2a  y use zlib.h.. *
0170: 2f 0a 0a 2f 2a 20 54 68 69 73 20 70 72 6f 67 72  /../* This progr
0180: 61 6d 20 69 73 20 69 6e 63 6c 75 64 65 64 20 69  am is included i
0190: 6e 20 74 68 65 20 64 69 73 74 72 69 62 75 74 69  n the distributi
01a0: 6f 6e 20 66 6f 72 20 63 6f 6d 70 6c 65 74 65 6e  on for completen
01b0: 65 73 73 2e 0a 20 20 20 59 6f 75 20 64 6f 20 6e  ess..   You do n
01c0: 6f 74 20 6e 65 65 64 20 74 6f 20 63 6f 6d 70 69  ot need to compi
01d0: 6c 65 20 6f 72 20 72 75 6e 20 74 68 69 73 20 70  le or run this p
01e0: 72 6f 67 72 61 6d 20 73 69 6e 63 65 20 69 6e 66  rogram since inf
01f0: 66 69 78 65 64 2e 68 0a 20 20 20 69 73 20 61 6c  fixed.h.   is al
0200: 72 65 61 64 79 20 69 6e 63 6c 75 64 65 64 20 69  ready included i
0210: 6e 20 74 68 65 20 64 69 73 74 72 69 62 75 74 69  n the distributi
0220: 6f 6e 2e 20 20 54 6f 20 75 73 65 20 74 68 69 73  on.  To use this
0230: 20 70 72 6f 67 72 61 6d 0a 20 20 20 79 6f 75 20   program.   you 
0240: 6e 65 65 64 20 74 6f 20 63 6f 6d 70 69 6c 65 20  need to compile 
0250: 7a 6c 69 62 20 77 69 74 68 20 42 55 49 4c 44 46  zlib with BUILDF
0260: 49 58 45 44 20 64 65 66 69 6e 65 64 20 61 6e 64  IXED defined and
0270: 20 74 68 65 6e 20 63 6f 6d 70 69 6c 65 0a 20 20   then compile.  
0280: 20 61 6e 64 20 6c 69 6e 6b 20 74 68 69 73 20 70   and link this p
0290: 72 6f 67 72 61 6d 20 77 69 74 68 20 74 68 65 20  rogram with the 
02a0: 7a 6c 69 62 20 6c 69 62 72 61 72 79 2e 20 20 54  zlib library.  T
02b0: 68 65 6e 20 74 68 65 20 6f 75 74 70 75 74 20 6f  hen the output o
02c0: 66 0a 20 20 20 74 68 69 73 20 70 72 6f 67 72 61  f.   this progra
02d0: 6d 20 63 61 6e 20 62 65 20 70 69 70 65 64 20 74  m can be piped t
02e0: 6f 20 69 6e 66 66 69 78 65 64 2e 68 2e 20 2a 2f  o inffixed.h. */
02f0: 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69  ..#include <stdi
0300: 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73  o.h>.#include <s
0310: 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64  tdlib.h>.#includ
0320: 65 20 22 7a 75 74 69 6c 2e 68 22 0a 23 69 6e 63  e "zutil.h".#inc
0330: 6c 75 64 65 20 22 69 6e 66 74 72 65 65 73 2e 68  lude "inftrees.h
0340: 22 0a 0a 2f 2a 20 73 69 6d 70 6c 69 66 79 20 74  "../* simplify t
0350: 68 65 20 75 73 65 20 6f 66 20 74 68 65 20 69 6e  he use of the in
0360: 66 6c 61 74 65 5f 68 75 66 74 20 74 79 70 65 20  flate_huft type 
0370: 77 69 74 68 20 73 6f 6d 65 20 64 65 66 69 6e 65  with some define
0380: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 65 78 6f  s */.#define exo
0390: 70 20 77 6f 72 64 2e 77 68 61 74 2e 45 78 6f 70  p word.what.Exop
03a0: 0a 23 64 65 66 69 6e 65 20 62 69 74 73 20 77 6f  .#define bits wo
03b0: 72 64 2e 77 68 61 74 2e 42 69 74 73 0a 0a 2f 2a  rd.what.Bits../*
03c0: 20 67 65 6e 65 72 61 74 65 20 69 6e 69 74 69 61   generate initia
03d0: 6c 69 7a 61 74 69 6f 6e 20 74 61 62 6c 65 20 66  lization table f
03e0: 6f 72 20 61 6e 20 69 6e 66 6c 61 74 65 5f 68 75  or an inflate_hu
03f0: 66 74 20 73 74 72 75 63 74 75 72 65 20 61 72 72  ft structure arr
0400: 61 79 20 2a 2f 0a 76 6f 69 64 20 6d 61 6b 65 74  ay */.void maket
0410: 72 65 65 28 75 49 6e 74 20 62 2c 20 69 6e 66 6c  ree(uInt b, infl
0420: 61 74 65 5f 68 75 66 74 20 2a 74 29 0a 7b 0a 20  ate_huft *t).{. 
0430: 20 69 6e 74 20 69 2c 20 65 3b 0a 0a 20 20 69 20   int i, e;..  i 
0440: 3d 20 30 3b 0a 20 20 77 68 69 6c 65 20 28 31 29  = 0;.  while (1)
0450: 0a 20 20 7b 0a 20 20 20 20 65 20 3d 20 74 5b 69  .  {.    e = t[i
0460: 5d 2e 65 78 6f 70 3b 0a 20 20 20 20 69 66 20 28  ].exop;.    if (
0470: 65 20 26 26 20 28 65 20 26 20 28 31 36 2b 36 34  e && (e & (16+64
0480: 29 29 20 3d 3d 20 30 29 20 20 20 20 20 20 20 20  )) == 0)        
0490: 2f 2a 20 74 61 62 6c 65 20 70 6f 69 6e 74 65 72  /* table pointer
04a0: 20 2a 2f 0a 20 20 20 20 7b 0a 20 20 20 20 20 20   */.    {.      
04b0: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20  fprintf(stderr, 
04c0: 22 6d 61 6b 65 74 72 65 65 3a 20 63 61 6e 6e 6f  "maketree: canno
04d0: 74 20 69 6e 69 74 69 61 6c 69 7a 65 20 73 75 62  t initialize sub
04e0: 2d 74 61 62 6c 65 73 21 5c 6e 22 29 3b 0a 20 20  -tables!\n");.  
04f0: 20 20 20 20 65 78 69 74 28 31 29 3b 0a 20 20 20      exit(1);.   
0500: 20 7d 0a 20 20 20 20 69 66 20 28 69 20 25 20 34   }.    if (i % 4
0510: 20 3d 3d 20 30 29 0a 20 20 20 20 20 20 70 72 69   == 0).      pri
0520: 6e 74 66 28 22 5c 6e 20 20 20 22 29 3b 0a 20 20  ntf("\n   ");.  
0530: 20 20 70 72 69 6e 74 66 28 22 20 7b 7b 7b 25 75    printf(" {{{%u
0540: 2c 25 75 7d 7d 2c 25 75 7d 22 2c 20 74 5b 69 5d  ,%u}},%u}", t[i]
0550: 2e 65 78 6f 70 2c 20 74 5b 69 5d 2e 62 69 74 73  .exop, t[i].bits
0560: 2c 20 74 5b 69 5d 2e 62 61 73 65 29 3b 0a 20 20  , t[i].base);.  
0570: 20 20 69 66 20 28 2b 2b 69 20 3d 3d 20 28 31 3c    if (++i == (1<
0580: 3c 62 29 29 0a 20 20 20 20 20 20 62 72 65 61 6b  <b)).      break
0590: 3b 0a 20 20 20 20 70 75 74 63 68 61 72 28 27 2c  ;.    putchar(',
05a0: 27 29 3b 0a 20 20 7d 0a 20 20 70 75 74 73 28 22  ');.  }.  puts("
05b0: 22 29 3b 0a 7d 0a                                ");.}.