g4_table_gen.c

changeset 99
26f7edf15ef4
parent 78
74b6b230f85d
child 125
e2ef1c2f9eca
     1.1 diff -r 5fb9b9f7c2b8 -r 26f7edf15ef4 g4_table_gen.c
     1.2 --- a/g4_table_gen.c	Wed Mar 12 06:40:34 2003 +0000
     1.3 +++ b/g4_table_gen.c	Wed Mar 12 06:57:46 2003 +0000
     1.4 @@ -4,7 +4,7 @@
     1.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.6   *
     1.7   * G4 table generator
     1.8 - * $Id: g4_table_gen.c,v 1.2 2003/03/05 12:44:33 eric Exp $
     1.9 + * $Id: g4_table_gen.c,v 1.3 2003/03/11 22:57:46 eric Exp $
    1.10   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    1.11   *
    1.12   * This program is free software; you can redistribute it and/or modify
    1.13 @@ -81,11 +81,19 @@
    1.14    };
    1.15  
    1.16  
    1.17 -void print_long_makeup_code (void)
    1.18 +void print_long_makeup_code (bool header)
    1.19  {
    1.20    int i;
    1.21  
    1.22 -  printf ("static g4_bits g4_long_makeup_code [12] =\n");
    1.23 +  if (header)
    1.24 +    printf ("extern ");
    1.25 +  printf ("const g4_bits g4_long_makeup_code [12]");
    1.26 +  if (header)
    1.27 +    {
    1.28 +      printf (";\n");
    1.29 +      return;
    1.30 +    }
    1.31 +  printf (" =\n");
    1.32    printf ("  {\n");
    1.33    for (i = 0; i < 12; i++)
    1.34      emit_code (4, long_makeup_code [i], i == 11, 1, i * 64 + 1792);
    1.35 @@ -125,11 +133,19 @@
    1.36    };
    1.37  
    1.38  
    1.39 -void print_makeup_code (void)
    1.40 +void print_makeup_code (bool header)
    1.41  {
    1.42    int i;
    1.43  
    1.44 -  printf ("static g4_bits g4_makeup_code [2] [27] =\n");
    1.45 +  if (header)
    1.46 +    printf ("extern ");
    1.47 +  printf ("const g4_bits g4_makeup_code [2] [27]");
    1.48 +  if (header)
    1.49 +    {
    1.50 +      printf (";\n");
    1.51 +      return;
    1.52 +    }
    1.53 +  printf (" =\n");
    1.54    printf ("  {\n");
    1.55    printf ("    {\n");
    1.56    printf ("      /* white */\n");
    1.57 @@ -214,11 +230,19 @@
    1.58    };
    1.59  
    1.60  
    1.61 -void print_h_code (void)
    1.62 +void print_h_code (bool header)
    1.63  {
    1.64    int i;
    1.65  
    1.66 -  printf ("static g4_bits g4_h_code [2] [64] =\n");
    1.67 +  if (header)
    1.68 +    printf ("extern ");
    1.69 +  printf ("const g4_bits g4_h_code [2] [64]");
    1.70 +  if (header)
    1.71 +    {
    1.72 +      printf (";\n");
    1.73 +      return;
    1.74 +    }
    1.75 +  printf (" =\n");
    1.76    printf ("  {\n");
    1.77    printf ("    {\n");
    1.78    printf ("      /* white */\n");
    1.79 @@ -246,11 +270,19 @@
    1.80    };
    1.81  
    1.82  
    1.83 -void print_v_code (void)
    1.84 +void print_v_code (bool header)
    1.85  {
    1.86    int i;
    1.87  
    1.88 -  printf ("static g4_bits g4_vert_code [7] =\n");
    1.89 +  if (header)
    1.90 +    printf ("extern ");
    1.91 +  printf ("const g4_bits g4_vert_code [7]");
    1.92 +  if (header)
    1.93 +    {
    1.94 +      printf (";\n");
    1.95 +      return;
    1.96 +    }
    1.97 +  printf ("=\n");
    1.98    printf ("  {\n");
    1.99    for (i = 0; i <= 6; i++)
   1.100      emit_code (4, v_code [i], i == 6, 1, i - 3);
   1.101 @@ -260,25 +292,51 @@
   1.102  
   1.103  int main (int argc, char *argv [])
   1.104  {
   1.105 +  bool header;
   1.106 +
   1.107 +  if (argc != 2)
   1.108 +    {
   1.109 +      fprintf (stderr, "wrong arg count\n");
   1.110 +      exit (2);
   1.111 +    }
   1.112 +  if (strcmp (argv [1], "-h") == 0)
   1.113 +    header = 1;
   1.114 +  else if (strcmp (argv [1], "-c") == 0)
   1.115 +    header = 0;
   1.116 +  else
   1.117 +    {
   1.118 +      fprintf (stderr, "wrong args\n");
   1.119 +      exit (2);
   1.120 +    }
   1.121 +
   1.122    printf ("/* This file is automatically generated; do not edit */\n");
   1.123    printf ("\n");
   1.124 -  printf ("typedef struct\n");
   1.125 -  printf ("{\n");
   1.126 -  printf ("  uint32_t count;\n");
   1.127 -  printf ("  uint32_t bits;\n");
   1.128 -  printf ("} g4_bits;\n");
   1.129 -  printf ("\n");
   1.130  
   1.131 -  print_long_makeup_code ();
   1.132 +  if (header)
   1.133 +    {
   1.134 +      printf ("typedef struct\n");
   1.135 +      printf ("{\n");
   1.136 +      printf ("  uint32_t count;\n");
   1.137 +      printf ("  uint32_t bits;\n");
   1.138 +      printf ("} g4_bits;\n");
   1.139 +    }
   1.140 +  else
   1.141 +    {
   1.142 +      printf ("#include <stdint.h>\n");
   1.143 +      printf ("#include \"g4_tables.h\"\n");
   1.144 +    }
   1.145    printf ("\n");
   1.146  
   1.147 -  print_makeup_code ();
   1.148 +  print_long_makeup_code (header);
   1.149    printf ("\n");
   1.150  
   1.151 -  print_h_code ();
   1.152 +  print_makeup_code (header);
   1.153    printf ("\n");
   1.154  
   1.155 -  print_v_code ();
   1.156 +  print_h_code (header);
   1.157 +  printf ("\n");
   1.158 +
   1.159 +  print_v_code (header);
   1.160  
   1.161    exit (0);
   1.162  }