bitblt_table_gen.c

changeset 97
f2e13c2ff575
parent 78
74b6b230f85d
child 98
5fb9b9f7c2b8
     1.1 --- a/bitblt_table_gen.c	Wed Mar 12 06:02:46 2003 +0000
     1.2 +++ b/bitblt_table_gen.c	Wed Mar 12 06:39:22 2003 +0000
     1.3 @@ -4,7 +4,7 @@
     1.4   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.5   *
     1.6   * bitblt table generator
     1.7 - * $Id: bitblt_table_gen.c,v 1.4 2003/03/05 12:44:33 eric Exp $
     1.8 + * $Id: bitblt_table_gen.c,v 1.5 2003/03/11 22:39:22 eric Exp $
     1.9   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    1.10   *
    1.11   * This program is free software; you can redistribute it and/or modify
    1.12 @@ -24,13 +24,23 @@
    1.13   */
    1.14  
    1.15  
    1.16 +#include <stdbool.h>
    1.17  #include <stdio.h>
    1.18 +#include <stdlib.h>
    1.19  
    1.20 -void gen_bit_reverse_table (void)
    1.21 +void gen_bit_reverse_table (bool header)
    1.22  {
    1.23    int i, j;
    1.24  
    1.25 -  printf ("static const uint8_t bit_reverse_byte [0x100] =\n");
    1.26 +  if (header)
    1.27 +    printf ("extern ");
    1.28 +  printf ("const uint8_t bit_reverse_byte [0x100]");
    1.29 +  if (header)
    1.30 +    {
    1.31 +      printf (";\n");
    1.32 +      return;
    1.33 +    }
    1.34 +  printf (" =\n");
    1.35    printf ("{\n");
    1.36    for (i = 0; i < 0x100; i++)
    1.37      {
    1.38 @@ -73,11 +83,19 @@
    1.39  }
    1.40  
    1.41  
    1.42 -void gen_run_length_table (int val, char *name)
    1.43 +void gen_run_length_table (bool header, int val, char *name)
    1.44  {
    1.45    int i, j;
    1.46  
    1.47 -  printf ("static const uint8_t %s [8][256] =\n", name);
    1.48 +  if (header)
    1.49 +    printf ("extern ");
    1.50 +  printf ("const uint8_t %s [8][256]", name);
    1.51 +  if (header)
    1.52 +    {
    1.53 +      printf (";\n");
    1.54 +      return;
    1.55 +    }
    1.56 +  printf (" =\n");
    1.57    printf ("{\n");
    1.58    for (i = 0; i < 8; i++)
    1.59      {
    1.60 @@ -105,15 +123,38 @@
    1.61  
    1.62  int main (int argc, char *argv[])
    1.63  {
    1.64 +  bool header;
    1.65 +
    1.66 +  if (argc != 2)
    1.67 +    {
    1.68 +      fprintf (stderr, "wrong arg count\n");
    1.69 +      exit (2);
    1.70 +    }
    1.71 +  if (strcmp (argv [1], "-h") == 0)
    1.72 +    header = 1;
    1.73 +  else if (strcmp (argv [1], "-c") == 0)
    1.74 +    header = 0;
    1.75 +  else
    1.76 +    {
    1.77 +      fprintf (stderr, "wrong args\n");
    1.78 +      exit (2);
    1.79 +    }
    1.80 +
    1.81    printf ("/* This file is automatically generated; do not edit */\n");
    1.82    printf ("\n");
    1.83  
    1.84 -  gen_bit_reverse_table ();
    1.85 +  if (! header)
    1.86 +    {
    1.87 +      printf ("#include <stdint.h>\n");
    1.88 +      printf ("#include \"bitblt_tables.h\"\n");
    1.89 +      printf ("\n");
    1.90 +    }
    1.91 +
    1.92 +  gen_bit_reverse_table (header);
    1.93    printf ("\n");
    1.94  
    1.95 -  gen_run_length_table (0, "rle_tab");
    1.96 +  gen_run_length_table (header, 0, "rle_tab");
    1.97    printf ("\n");
    1.98  
    1.99    return (0);
   1.100  }
   1.101 -