changed g4_table_gen to generate both a header and a C source file (g4_tables.[ch]).

Wed, 12 Mar 2003 06:57:46 +0000

author
eric
date
Wed, 12 Mar 2003 06:57:46 +0000
changeset 99
26f7edf15ef4
parent 98
5fb9b9f7c2b8
child 100
5916a95e2b92

changed g4_table_gen to generate both a header and a C source file (g4_tables.[ch]).

Makefile file | annotate | diff | revisions
g4_table_gen.c file | annotate | diff | revisions
     1.1 --- a/Makefile	Wed Mar 12 06:40:34 2003 +0000
     1.2 +++ b/Makefile	Wed Mar 12 06:57:46 2003 +0000
     1.3 @@ -1,6 +1,6 @@
     1.4  # t2p: build a PDF file out of one or more TIFF Class F Group 4 files
     1.5  # Makefile
     1.6 -# $Id: Makefile,v 1.22 2003/03/11 22:39:22 eric Exp $
     1.7 +# $Id: Makefile,v 1.23 2003/03/11 22:57:46 eric Exp $
     1.8  # Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
     1.9  #
    1.10  # This program is free software; you can redistribute it and/or modify
    1.11 @@ -73,9 +73,9 @@
    1.12  DISTNAME = $(PACKAGE)-$(VERSION)
    1.13  
    1.14  
    1.15 -AUTO_CSRCS = scanner.c parser.tab.c bitblt_tables.c
    1.16 -AUTO_HDRS = parser.tab.h g4_tables.h
    1.17 -AUTO_MISC = parser.output bitblt_tables.h
    1.18 +AUTO_CSRCS = scanner.c parser.tab.c bitblt_tables.c g4_tables.c
    1.19 +AUTO_HDRS = parser.tab.h  bitblt_tables.h g4_tables.h
    1.20 +AUTO_MISC = parser.output
    1.21  
    1.22  
    1.23  -include Maketest
    1.24 @@ -85,7 +85,7 @@
    1.25  
    1.26  
    1.27  t2p: t2p.o scanner.o semantics.o parser.tab.o \
    1.28 -		bitblt.o bitblt_g4.o bitblt_tables.o \
    1.29 +		bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.o \
    1.30  		pdf.o pdf_util.o pdf_prim.o pdf_bookmark.o pdf_name_tree.o \
    1.31  		pdf_g4.o
    1.32  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
    1.33 @@ -103,7 +103,10 @@
    1.34  bitblt_table_gen: bitblt_table_gen.o
    1.35  
    1.36  g4_tables.h: g4_table_gen
    1.37 -	./g4_table_gen >g4_tables.h
    1.38 +	./g4_table_gen -h >g4_tables.h
    1.39 +
    1.40 +g4_tables.c: g4_table_gen
    1.41 +	./g4_table_gen -c >g4_tables.c
    1.42  
    1.43  g4_table_gen: g4_table_gen.o
    1.44  
     2.1 --- a/g4_table_gen.c	Wed Mar 12 06:40:34 2003 +0000
     2.2 +++ b/g4_table_gen.c	Wed Mar 12 06:57:46 2003 +0000
     2.3 @@ -4,7 +4,7 @@
     2.4   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     2.5   *
     2.6   * G4 table generator
     2.7 - * $Id: g4_table_gen.c,v 1.2 2003/03/05 12:44:33 eric Exp $
     2.8 + * $Id: g4_table_gen.c,v 1.3 2003/03/11 22:57:46 eric Exp $
     2.9   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    2.10   *
    2.11   * This program is free software; you can redistribute it and/or modify
    2.12 @@ -81,11 +81,19 @@
    2.13    };
    2.14  
    2.15  
    2.16 -void print_long_makeup_code (void)
    2.17 +void print_long_makeup_code (bool header)
    2.18  {
    2.19    int i;
    2.20  
    2.21 -  printf ("static g4_bits g4_long_makeup_code [12] =\n");
    2.22 +  if (header)
    2.23 +    printf ("extern ");
    2.24 +  printf ("const g4_bits g4_long_makeup_code [12]");
    2.25 +  if (header)
    2.26 +    {
    2.27 +      printf (";\n");
    2.28 +      return;
    2.29 +    }
    2.30 +  printf (" =\n");
    2.31    printf ("  {\n");
    2.32    for (i = 0; i < 12; i++)
    2.33      emit_code (4, long_makeup_code [i], i == 11, 1, i * 64 + 1792);
    2.34 @@ -125,11 +133,19 @@
    2.35    };
    2.36  
    2.37  
    2.38 -void print_makeup_code (void)
    2.39 +void print_makeup_code (bool header)
    2.40  {
    2.41    int i;
    2.42  
    2.43 -  printf ("static g4_bits g4_makeup_code [2] [27] =\n");
    2.44 +  if (header)
    2.45 +    printf ("extern ");
    2.46 +  printf ("const g4_bits g4_makeup_code [2] [27]");
    2.47 +  if (header)
    2.48 +    {
    2.49 +      printf (";\n");
    2.50 +      return;
    2.51 +    }
    2.52 +  printf (" =\n");
    2.53    printf ("  {\n");
    2.54    printf ("    {\n");
    2.55    printf ("      /* white */\n");
    2.56 @@ -214,11 +230,19 @@
    2.57    };
    2.58  
    2.59  
    2.60 -void print_h_code (void)
    2.61 +void print_h_code (bool header)
    2.62  {
    2.63    int i;
    2.64  
    2.65 -  printf ("static g4_bits g4_h_code [2] [64] =\n");
    2.66 +  if (header)
    2.67 +    printf ("extern ");
    2.68 +  printf ("const g4_bits g4_h_code [2] [64]");
    2.69 +  if (header)
    2.70 +    {
    2.71 +      printf (";\n");
    2.72 +      return;
    2.73 +    }
    2.74 +  printf (" =\n");
    2.75    printf ("  {\n");
    2.76    printf ("    {\n");
    2.77    printf ("      /* white */\n");
    2.78 @@ -246,11 +270,19 @@
    2.79    };
    2.80  
    2.81  
    2.82 -void print_v_code (void)
    2.83 +void print_v_code (bool header)
    2.84  {
    2.85    int i;
    2.86  
    2.87 -  printf ("static g4_bits g4_vert_code [7] =\n");
    2.88 +  if (header)
    2.89 +    printf ("extern ");
    2.90 +  printf ("const g4_bits g4_vert_code [7]");
    2.91 +  if (header)
    2.92 +    {
    2.93 +      printf (";\n");
    2.94 +      return;
    2.95 +    }
    2.96 +  printf ("=\n");
    2.97    printf ("  {\n");
    2.98    for (i = 0; i <= 6; i++)
    2.99      emit_code (4, v_code [i], i == 6, 1, i - 3);
   2.100 @@ -260,25 +292,51 @@
   2.101  
   2.102  int main (int argc, char *argv [])
   2.103  {
   2.104 +  bool header;
   2.105 +
   2.106 +  if (argc != 2)
   2.107 +    {
   2.108 +      fprintf (stderr, "wrong arg count\n");
   2.109 +      exit (2);
   2.110 +    }
   2.111 +  if (strcmp (argv [1], "-h") == 0)
   2.112 +    header = 1;
   2.113 +  else if (strcmp (argv [1], "-c") == 0)
   2.114 +    header = 0;
   2.115 +  else
   2.116 +    {
   2.117 +      fprintf (stderr, "wrong args\n");
   2.118 +      exit (2);
   2.119 +    }
   2.120 +
   2.121    printf ("/* This file is automatically generated; do not edit */\n");
   2.122    printf ("\n");
   2.123 -  printf ("typedef struct\n");
   2.124 -  printf ("{\n");
   2.125 -  printf ("  uint32_t count;\n");
   2.126 -  printf ("  uint32_t bits;\n");
   2.127 -  printf ("} g4_bits;\n");
   2.128 -  printf ("\n");
   2.129  
   2.130 -  print_long_makeup_code ();
   2.131 +  if (header)
   2.132 +    {
   2.133 +      printf ("typedef struct\n");
   2.134 +      printf ("{\n");
   2.135 +      printf ("  uint32_t count;\n");
   2.136 +      printf ("  uint32_t bits;\n");
   2.137 +      printf ("} g4_bits;\n");
   2.138 +    }
   2.139 +  else
   2.140 +    {
   2.141 +      printf ("#include <stdint.h>\n");
   2.142 +      printf ("#include \"g4_tables.h\"\n");
   2.143 +    }
   2.144    printf ("\n");
   2.145  
   2.146 -  print_makeup_code ();
   2.147 +  print_long_makeup_code (header);
   2.148    printf ("\n");
   2.149  
   2.150 -  print_h_code ();
   2.151 +  print_makeup_code (header);
   2.152    printf ("\n");
   2.153  
   2.154 -  print_v_code ();
   2.155 +  print_h_code (header);
   2.156 +  printf ("\n");
   2.157 +
   2.158 +  print_v_code (header);
   2.159  
   2.160    exit (0);
   2.161  }