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