home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / grfx_snd / tifflib / source / mkg3tab.c < prev    next >
C/C++ Source or Header  |  1993-02-28  |  4KB  |  150 lines

  1. #pragma warn -use
  2. static char     *sccsid = "@(#)TIFF/mkg3tab.c 1.03, Copyright (c) Sam Leffler, Dieter Linde, "__DATE__;
  3. #pragma warn .use
  4. /*
  5.  * Copyright (c) 1988, 1990 by Sam Leffler, Oct 8 1990
  6.  * All rights reserved.
  7.  *
  8.  */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <lin.h>
  12. #include "tiffio.h"
  13. #include "t4.h"
  14.  
  15. #define TABSIZE    8192
  16.  
  17. static char    *progname;
  18.  
  19. /****************************************************************************
  20.  *
  21.  */
  22. static void
  23. dumparray(
  24.     char    *name,
  25.            u_char    tab[TABSIZE]
  26.            )
  27. {
  28.            register int    i;
  29.         register char     *sep;
  30.  
  31.         printf("u_char\t%s[%d] = {\n", name, TABSIZE);
  32.         sep = "\t";
  33.         for (i = 0; i < TABSIZE; i++) {
  34.                 printf("%s%3u", sep, tab[i]);
  35.                 if (((i + 1) % 10) == 0) {
  36.                         printf(",\t/* %4d - %4d */\n", i - 9, i);
  37.                         sep = "\t";
  38.                 } 
  39.                 else
  40.                         sep = ", ";
  41.         }
  42.         if ((i - 1) % TABSIZE)
  43.                 putchar('\n');
  44.         printf("};\n");
  45. }
  46.  
  47. #define SIZEOF(a)    (sizeof(a) / sizeof(a[0]))
  48.  
  49. /****************************************************************************
  50.  *
  51.  */
  52. static void
  53. addcodes(
  54.            u_char        tab[TABSIZE],
  55.         int         n,
  56.         tableentry     *ttab
  57.         )
  58. {
  59.         int     i;
  60.  
  61.         for (i = 0; i < n; i++) {
  62.                 tableentry    *te = &ttab[i];
  63.                 int         code = te->code << (13 - te->length);
  64.  
  65.                 if (code >= TABSIZE) {
  66.                            fprintf(stderr, "%s: unexpected code %d (>=%d) %s(0x%x, %d, %d)\n", progname, code, TABSIZE, 
  67.                                te->tabid == TWTABLE ? "twtable" : 
  68.                                te->tabid == TBTABLE ? "tbtable" :
  69.                 te->tabid == MWTABLE ? "mwtable" : 
  70.                 te->tabid == MBTABLE ? "mbtable" : 
  71.                 te->tabid == EXTABLE ? "extable" : 
  72.                              "??? table", te->code, te->length, te->count);
  73.                         exit(-1);
  74.                 }
  75.                 if (tab[code] != 0xff) {
  76.                         printf("%s: code table collision %d %s(0x%x, %d, %d)\n", progname, code,
  77.                                 te->tabid == TWTABLE ? "twtable" :
  78.                                 te->tabid == TBTABLE ? "tbtable" :
  79.                                 te->tabid == MWTABLE ? "mwtable" :
  80.                                 te->tabid == MBTABLE ? "mbtable" :
  81.                                 te->tabid == EXTABLE ? "extable" :
  82.                                                      "??? table", te->code, te->length, te->count);
  83.                 } 
  84.                 else
  85.                         tab[code] = i;
  86.         }
  87. }
  88.  
  89. /****************************************************************************
  90.  *
  91.  */
  92. static void
  93. dumppointers(
  94.            tableentry    *tab,
  95.         int         n,
  96.         char         *which
  97.         )
  98. {
  99.         int     i;
  100.  
  101.         for (i = 0; i < n; i++)
  102.                 if (tab[i].tabid > 0)
  103.                         break;
  104.         printf("static  tableentry *g3m%stab = &TIFFFax3%scodes[%d];\n", which, which, i);
  105.         for (; i < n; i++)
  106.                 if (tab[i].tabid < 0)
  107.                         break;
  108.         printf("static  tableentry *g3t%stab = &TIFFFax3%scodes[%d];\n", which, which, i);
  109. }
  110.  
  111. /****************************************************************************
  112.  *
  113.  */
  114. static void
  115. bfill(
  116.            register u_char    *cp,
  117.         register int     n,
  118.         register int     v
  119.         )
  120. {
  121.         while (n-- > 0)
  122.                 *cp++ = v;
  123. }
  124.  
  125. #pragma warn -par
  126. /****************************************************************************
  127.  *
  128.  */
  129. void
  130. main(
  131.     int    argc,
  132.     char    *argv[]
  133.     )
  134. {
  135.         u_char    tab[TABSIZE];
  136.  
  137.         progname = ((int)strlen(argv[0]) == 0) ? "mkg3tab" : argv[0];
  138.  
  139.         bfill(tab, (int)sizeof(tab), 0xff);
  140.         addcodes(tab, (int)SIZEOF(TIFFFax3bcodes), TIFFFax3bcodes);
  141.         dumparray("TIFFFax3btab", tab);
  142.         dumppointers(TIFFFax3bcodes, (int)SIZEOF(TIFFFax3bcodes), "b");
  143.         bfill(tab, (int)sizeof(tab), 0xff);
  144.         addcodes(tab, (int)SIZEOF(TIFFFax3wcodes), TIFFFax3wcodes);
  145.         dumparray("TIFFFax3wtab", tab);
  146.         dumppointers(TIFFFax3wcodes, (int)SIZEOF(TIFFFax3wcodes), "w");
  147.         exit(0);
  148. }
  149. #pragma warn .par
  150.