1.1 --- a/t2p.c Mon Dec 31 16:44:24 2001 +0000 1.2 +++ b/t2p.c Tue Jan 01 03:44:40 2002 +0000 1.3 @@ -1,7 +1,7 @@ 1.4 /* 1.5 * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 1.6 * Main program 1.7 - * $Id: t2p.c,v 1.7 2001/12/31 08:44:24 eric Exp $ 1.8 + * $Id: t2p.c,v 1.8 2001/12/31 19:44:40 eric Exp $ 1.9 * Copyright 2001 Eric Smith <eric@brouhaha.com> 1.10 * 1.11 * This program is free software; you can redistribute it and/or modify 1.12 @@ -33,49 +33,115 @@ 1.13 #include "tiff2pdf.h" 1.14 1.15 1.16 +typedef struct output_file_t 1.17 +{ 1.18 + struct output_file_t *next; 1.19 + char *name; 1.20 + panda_pdf *pdf; 1.21 +} output_file_t; 1.22 + 1.23 + 1.24 +char *in_filename; 1.25 TIFF *in; 1.26 -panda_pdf *out; 1.27 +output_file_t *output_files; 1.28 +output_file_t *out; 1.29 +/* panda_pdf *out; */ 1.30 1.31 1.32 boolean close_tiff_input_file (void) 1.33 { 1.34 if (in) 1.35 - TIFFClose (in); 1.36 + { 1.37 + free (in_filename); 1.38 + TIFFClose (in); 1.39 + } 1.40 in = NULL; 1.41 + in_filename = NULL; 1.42 return (1); 1.43 } 1.44 1.45 boolean open_tiff_input_file (char *name) 1.46 { 1.47 if (in) 1.48 - close_tiff_input_file (); 1.49 + { 1.50 + if (strcmp (name, in_filename) == 0) 1.51 + return (1); 1.52 + close_tiff_input_file (); 1.53 + } 1.54 + in_filename = strdup (name); 1.55 + if (! in_filename) 1.56 + { 1.57 + fprintf (stderr, "can't strdup input filename '%s'\n", name); 1.58 + return (0); 1.59 + } 1.60 in = TIFFOpen (name, "r"); 1.61 if (! in) 1.62 { 1.63 fprintf (stderr, "can't open input file '%s'\n", name); 1.64 + free (in_filename); 1.65 return (0); 1.66 } 1.67 return (1); 1.68 } 1.69 1.70 1.71 -boolean close_pdf_output_file (void) 1.72 +boolean close_pdf_output_files (void) 1.73 { 1.74 - if (out) 1.75 - panda_close (out); 1.76 + output_file_t *o, *n; 1.77 + 1.78 + for (o = output_files; o; o = n) 1.79 + { 1.80 + n = o->next; 1.81 + panda_close (o->pdf); 1.82 + free (o->name); 1.83 + free (o); 1.84 + } 1.85 out = NULL; 1.86 + output_files = NULL; 1.87 return (1); 1.88 } 1.89 1.90 boolean open_pdf_output_file (char *name) 1.91 { 1.92 - if (out) 1.93 - close_pdf_output_file (); 1.94 - out = panda_open (name, "w"); 1.95 - if (! out) 1.96 + output_file_t *o; 1.97 + 1.98 + if (out && (strcmp (name, out->name) == 0)) 1.99 + return (1); 1.100 + for (o = output_files; o; o = o->next) 1.101 + if (strcmp (name, o->name) == 0) 1.102 + { 1.103 + out = o; 1.104 + return (1); 1.105 + } 1.106 + o = calloc (1, sizeof (output_file_t)); 1.107 + if (! 0) 1.108 { 1.109 + fprintf (stderr, "can't calloc output file struct for '%s'\n", name); 1.110 + return (0); 1.111 + } 1.112 + 1.113 + o->name = strdup (name); 1.114 + if (! o->name) 1.115 + { 1.116 + fprintf (stderr, "can't strdup output filename '%s'\n", name); 1.117 + free (o); 1.118 return (0); 1.119 } 1.120 + 1.121 + o->pdf = panda_open (name, "w"); 1.122 + if (! o->pdf) 1.123 + { 1.124 + fprintf (stderr, "can't open output file '%s'\n", name); 1.125 + free (o->name); 1.126 + free (o); 1.127 + return (0); 1.128 + } 1.129 + 1.130 + /* prepend new output file onto list */ 1.131 + o->next = output_files; 1.132 + output_files = o; 1.133 + 1.134 + out = o; 1.135 return (1); 1.136 } 1.137 1.138 @@ -178,19 +244,19 @@ 1.139 } 1.140 1.141 #if 0 1.142 - TIFFSetField (out, TIFFTAG_IMAGELENGTH, image_length); 1.143 - TIFFSetField (out, TIFFTAG_IMAGEWIDTH, image_width); 1.144 - TIFFSetField (out, TIFFTAG_PLANARCONFIG, planar_config); 1.145 + TIFFSetField (out->pdf, TIFFTAG_IMAGELENGTH, image_length); 1.146 + TIFFSetField (out->pdf, TIFFTAG_IMAGEWIDTH, image_width); 1.147 + TIFFSetField (out->pdf, TIFFTAG_PLANARCONFIG, planar_config); 1.148 1.149 - TIFFSetField (out, TIFFTAG_ROWSPERSTRIP, image_length); 1.150 + TIFFSetField (out->pdf, TIFFTAG_ROWSPERSTRIP, image_length); 1.151 1.152 - TIFFSetField (out, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 1.153 - TIFFSetField (out, TIFFTAG_XRESOLUTION, x_resolution); 1.154 - TIFFSetField (out, TIFFTAG_YRESOLUTION, y_resolution); 1.155 + TIFFSetField (out->pdf, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 1.156 + TIFFSetField (out->pdf, TIFFTAG_XRESOLUTION, x_resolution); 1.157 + TIFFSetField (out->pdf, TIFFTAG_YRESOLUTION, y_resolution); 1.158 1.159 - TIFFSetField (out, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 1.160 - TIFFSetField (out, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 1.161 - TIFFSetField (out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 1.162 + TIFFSetField (out->pdf, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 1.163 + TIFFSetField (out->pdf, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 1.164 + TIFFSetField (out->pdf, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 1.165 #endif 1.166 1.167 buffer = _TIFFmalloc (TIFFScanlineSize (in)); 1.168 @@ -204,7 +270,7 @@ 1.169 { 1.170 TIFFReadScanline (in, buffer, row, 0); 1.171 #if 0 1.172 - TIFFWriteScanline (out, buffer, row, 0); 1.173 + TIFFWriteScanline (out->pdf, buffer, row, 0); 1.174 #endif 1.175 } 1.176 1.177 @@ -231,10 +297,19 @@ 1.178 } 1.179 1.180 if (! parse_spec_file (argv [1])) 1.181 - goto fail; 1.182 + { 1.183 + result = 2; 1.184 + goto fail; 1.185 + } 1.186 + 1.187 + if (! process_specs ()) 1.188 + { 1.189 + result = 3; 1.190 + goto fail; 1.191 + } 1.192 1.193 fail: 1.194 close_tiff_input_file (); 1.195 - close_pdf_output_file (); 1.196 + close_pdf_output_files (); 1.197 return (result); 1.198 }