1.1 --- a/t2p.c Thu Mar 13 08:03:11 2003 +0000 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,732 +0,0 @@ 1.4 -/* 1.5 - * t2p: Create a PDF file from the contents of one or more TIFF 1.6 - * bilevel image files. The images in the resulting PDF file 1.7 - * will be compressed using ITU-T T.6 (G4) fax encoding. 1.8 - * 1.9 - * Main program 1.10 - * $Id: t2p.c,v 1.31 2003/03/12 23:59:10 eric Exp $ 1.11 - * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.12 - * 1.13 - * This program is free software; you can redistribute it and/or modify 1.14 - * it under the terms of the GNU General Public License version 2 as 1.15 - * published by the Free Software Foundation. Note that permission is 1.16 - * not granted to redistribute this program under the terms of any 1.17 - * other version of the General Public License. 1.18 - * 1.19 - * This program is distributed in the hope that it will be useful, 1.20 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.21 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.22 - * GNU General Public License for more details. 1.23 - * 1.24 - * You should have received a copy of the GNU General Public License 1.25 - * along with this program; if not, write to the Free Software 1.26 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.27 - */ 1.28 - 1.29 - 1.30 -#include <stdarg.h> 1.31 -#include <stdbool.h> 1.32 -#include <stdint.h> 1.33 -#include <stdio.h> 1.34 -#include <stdlib.h> 1.35 -#include <string.h> 1.36 -#include <unistd.h> 1.37 - 1.38 -#include <tiffio.h> 1.39 -#define TIFF_REVERSE_BITS 1.40 - 1.41 -#include "bitblt.h" 1.42 -#include "semantics.h" 1.43 -#include "parser.tab.h" 1.44 -#include "t2p.h" 1.45 -#include "pdf.h" 1.46 - 1.47 - 1.48 -#define MAX_INPUT_FILES 5000 1.49 - 1.50 -#define POINTS_PER_INCH 72 1.51 - 1.52 -/* page size limited by Acrobat Reader to 45 inches on a side */ 1.53 -#define PAGE_MAX_INCHES 45 1.54 -#define PAGE_MAX_POINTS (PAGE_MAX_INCHES * POINTS_PER_INCH) 1.55 - 1.56 - 1.57 -typedef struct output_file_t 1.58 -{ 1.59 - struct output_file_t *next; 1.60 - char *name; 1.61 - pdf_file_handle pdf; 1.62 -} output_file_t; 1.63 - 1.64 - 1.65 -int verbose; 1.66 - 1.67 - 1.68 -char *in_filename; 1.69 -TIFF *in; 1.70 -output_file_t *output_files; 1.71 -output_file_t *out; 1.72 - 1.73 - 1.74 -char *progname; 1.75 - 1.76 - 1.77 -bool close_tiff_input_file (void); 1.78 -bool close_pdf_output_files (void); 1.79 - 1.80 - 1.81 -void usage (void) 1.82 -{ 1.83 - fprintf (stderr, "\n"); 1.84 - fprintf (stderr, "t2p - Copyright 2001-2003 Eric Smith <eric@brouhaha.com>\n"); 1.85 - fprintf (stderr, "http://www.brouhaha.com/~eric/software/t2p/\n"); 1.86 - fprintf (stderr, "\n"); 1.87 - fprintf (stderr, "usage:\n"); 1.88 - fprintf (stderr, " %s [options] -s spec\n", progname); 1.89 - fprintf (stderr, " %s [options] <input.tif>... -o <output.pdf>\n", progname); 1.90 - fprintf (stderr, "options:\n"); 1.91 - fprintf (stderr, " -v verbose\n"); 1.92 - fprintf (stderr, " -b fmt create bookmarks\n"); 1.93 - fprintf (stderr, "bookmark format:\n"); 1.94 - fprintf (stderr, " %%F file name (sans suffix)\n"); 1.95 - fprintf (stderr, " %%p page number\n"); 1.96 -} 1.97 - 1.98 - 1.99 -/* generate fatal error message to stderr, doesn't return */ 1.100 -void fatal (int ret, char *format, ...) 1.101 -{ 1.102 - va_list ap; 1.103 - 1.104 - fprintf (stderr, "fatal error"); 1.105 - if (format) 1.106 - { 1.107 - fprintf (stderr, ": "); 1.108 - va_start (ap, format); 1.109 - vfprintf (stderr, format, ap); 1.110 - va_end (ap); 1.111 - } 1.112 - else 1.113 - fprintf (stderr, "\n"); 1.114 - if (ret == 1) 1.115 - usage (); 1.116 - close_tiff_input_file (); 1.117 - close_pdf_output_files (); 1.118 - exit (ret); 1.119 -} 1.120 - 1.121 - 1.122 -bool close_tiff_input_file (void) 1.123 -{ 1.124 - if (in) 1.125 - { 1.126 - free (in_filename); 1.127 - TIFFClose (in); 1.128 - } 1.129 - in = NULL; 1.130 - in_filename = NULL; 1.131 - return (1); 1.132 -} 1.133 - 1.134 - 1.135 -bool open_tiff_input_file (char *name) 1.136 -{ 1.137 - if (in) 1.138 - { 1.139 - if (strcmp (name, in_filename) == 0) 1.140 - return (1); 1.141 - close_tiff_input_file (); 1.142 - } 1.143 - in_filename = strdup (name); 1.144 - if (! in_filename) 1.145 - { 1.146 - fprintf (stderr, "can't strdup input filename '%s'\n", name); 1.147 - return (0); 1.148 - } 1.149 - in = TIFFOpen (name, "r"); 1.150 - if (! in) 1.151 - { 1.152 - fprintf (stderr, "can't open input file '%s'\n", name); 1.153 - free (in_filename); 1.154 - return (0); 1.155 - } 1.156 - return (1); 1.157 -} 1.158 - 1.159 - 1.160 -bool close_pdf_output_files (void) 1.161 -{ 1.162 - output_file_t *o, *n; 1.163 - 1.164 - for (o = output_files; o; o = n) 1.165 - { 1.166 - n = o->next; 1.167 - pdf_close (o->pdf); 1.168 - free (o->name); 1.169 - free (o); 1.170 - } 1.171 - out = NULL; 1.172 - output_files = NULL; 1.173 - return (1); 1.174 -} 1.175 - 1.176 -bool open_pdf_output_file (char *name, 1.177 - pdf_file_attributes_t *attributes) 1.178 -{ 1.179 - output_file_t *o; 1.180 - 1.181 - if (out && (strcmp (name, out->name) == 0)) 1.182 - return (1); 1.183 - for (o = output_files; o; o = o->next) 1.184 - if (strcmp (name, o->name) == 0) 1.185 - { 1.186 - out = o; 1.187 - return (1); 1.188 - } 1.189 - o = calloc (1, sizeof (output_file_t)); 1.190 - if (! o) 1.191 - { 1.192 - fprintf (stderr, "can't calloc output file struct for '%s'\n", name); 1.193 - return (0); 1.194 - } 1.195 - 1.196 - o->name = strdup (name); 1.197 - if (! o->name) 1.198 - { 1.199 - fprintf (stderr, "can't strdup output filename '%s'\n", name); 1.200 - free (o); 1.201 - return (0); 1.202 - } 1.203 - 1.204 - o->pdf = pdf_create (name, (attributes->has_bookmarks ? 1.205 - PDF_PAGE_MODE_USE_OUTLINES : 1.206 - PDF_PAGE_MODE_USE_NONE)); 1.207 - if (! o->pdf) 1.208 - { 1.209 - fprintf (stderr, "can't open output file '%s'\n", name); 1.210 - free (o->name); 1.211 - free (o); 1.212 - return (0); 1.213 - } 1.214 - 1.215 - if (attributes->author) 1.216 - pdf_set_author (o->pdf, attributes->author); 1.217 - if (attributes->creator) 1.218 - pdf_set_creator (o->pdf, attributes->creator); 1.219 - if (attributes->title) 1.220 - pdf_set_title (o->pdf, attributes->title); 1.221 - if (attributes->subject) 1.222 - pdf_set_subject (o->pdf, attributes->subject); 1.223 - if (attributes->keywords) 1.224 - pdf_set_keywords (o->pdf, attributes->keywords); 1.225 - 1.226 - /* prepend new output file onto list */ 1.227 - o->next = output_files; 1.228 - output_files = o; 1.229 - 1.230 - out = o; 1.231 - return (1); 1.232 -} 1.233 - 1.234 - 1.235 -void process_page_numbers (int page_index, 1.236 - int count, 1.237 - int base, 1.238 - page_label_t *page_label) 1.239 -{ 1.240 -} 1.241 - 1.242 - 1.243 -/* frees original! */ 1.244 -static Bitmap *resize_bitmap (Bitmap *src, 1.245 - double x_resolution, 1.246 - double y_resolution, 1.247 - input_attributes_t input_attributes) 1.248 -{ 1.249 - Rect src_rect; 1.250 - Point dest_min; 1.251 - Bitmap *dest; 1.252 - 1.253 - int width_pixels = input_attributes.page_size.width * x_resolution; 1.254 - int height_pixels = input_attributes.page_size.height * y_resolution; 1.255 - 1.256 - src_rect.min.x = (rect_width (& src->rect) - width_pixels) / 2; 1.257 - src_rect.min.y = (rect_height (& src->rect) - height_pixels) / 2; 1.258 - src_rect.max.x = src_rect.min.x + width_pixels; 1.259 - src_rect.max.y = src_rect.min.y + height_pixels; 1.260 - 1.261 - dest_min.x = 0; 1.262 - dest_min.y = 0; 1.263 - 1.264 - dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC, 0); 1.265 - free_bitmap (src); 1.266 - return (dest); 1.267 -} 1.268 - 1.269 - 1.270 -/* "in place" rotation */ 1.271 -static void rotate_bitmap (Bitmap *src, 1.272 - input_attributes_t input_attributes) 1.273 -{ 1.274 - switch (input_attributes.rotation) 1.275 - { 1.276 - case 0: break; 1.277 - case 90: rot_90 (src); break; 1.278 - case 180: rot_180 (src); break; 1.279 - case 270: rot_270 (src); break; 1.280 - default: 1.281 - fprintf (stderr, "rotation must be 0, 90, 180, or 270\n"); 1.282 - } 1.283 -} 1.284 - 1.285 - 1.286 -#define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0) 1.287 - 1.288 - 1.289 -bool last_tiff_page (void) 1.290 -{ 1.291 - return (TIFFLastDirectory (in)); 1.292 -} 1.293 - 1.294 - 1.295 -bool process_tiff_page (int image, /* range 1 .. n */ 1.296 - input_attributes_t input_attributes, 1.297 - bookmark_t *bookmarks) 1.298 -{ 1.299 - int result = 0; 1.300 - 1.301 - uint32_t image_length, image_width; 1.302 - uint32_t dest_image_length, dest_image_width; 1.303 -#ifdef CHECK_DEPTH 1.304 - uint32_t image_depth; 1.305 -#endif 1.306 - 1.307 - uint16_t samples_per_pixel; 1.308 - uint16_t bits_per_sample; 1.309 - uint16_t planar_config; 1.310 - 1.311 - uint16_t resolution_unit; 1.312 - float x_resolution, y_resolution; 1.313 - double dest_x_resolution, dest_y_resolution; 1.314 - 1.315 - double width_points, height_points; /* really 1/72 inch units rather than 1.316 - points */ 1.317 - 1.318 - Rect rect; 1.319 - Bitmap *bitmap = NULL; 1.320 - 1.321 - int row; 1.322 - 1.323 - pdf_page_handle page; 1.324 - 1.325 - if (! TIFFSetDirectory (in, image - 1)) 1.326 - { 1.327 - fprintf (stderr, "can't find page %d of input file\n", image); 1.328 - goto fail; 1.329 - } 1.330 - if (1 != TIFFGetField (in, TIFFTAG_IMAGELENGTH, & image_length)) 1.331 - { 1.332 - fprintf (stderr, "can't get image length\n"); 1.333 - goto fail; 1.334 - } 1.335 - if (1 != TIFFGetField (in, TIFFTAG_IMAGEWIDTH, & image_width)) 1.336 - { 1.337 - fprintf (stderr, "can't get image width\n"); 1.338 - goto fail; 1.339 - } 1.340 - 1.341 - if (1 != TIFFGetField (in, TIFFTAG_SAMPLESPERPIXEL, & samples_per_pixel)) 1.342 - { 1.343 - fprintf (stderr, "can't get samples per pixel\n"); 1.344 - goto fail; 1.345 - } 1.346 - 1.347 -#ifdef CHECK_DEPTH 1.348 - if (1 != TIFFGetField (in, TIFFTAG_IMAGEDEPTH, & image_depth)) 1.349 - { 1.350 - fprintf (stderr, "can't get image depth\n"); 1.351 - goto fail; 1.352 - } 1.353 -#endif 1.354 - 1.355 - if (1 != TIFFGetField (in, TIFFTAG_BITSPERSAMPLE, & bits_per_sample)) 1.356 - { 1.357 - fprintf (stderr, "can't get bits per sample\n"); 1.358 - goto fail; 1.359 - } 1.360 - 1.361 - if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) 1.362 - planar_config = 1; 1.363 - 1.364 - if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) 1.365 - resolution_unit = 2; 1.366 - if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) 1.367 - x_resolution = 300; 1.368 - if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) 1.369 - y_resolution = 300; 1.370 - 1.371 - if (samples_per_pixel != 1) 1.372 - { 1.373 - fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel); 1.374 - goto fail; 1.375 - } 1.376 - 1.377 -#ifdef CHECK_DEPTH 1.378 - if (image_depth != 1) 1.379 - { 1.380 - fprintf (stderr, "image depth %u, must be 1\n", image_depth); 1.381 - goto fail; 1.382 - } 1.383 -#endif 1.384 - 1.385 - if (bits_per_sample != 1) 1.386 - { 1.387 - fprintf (stderr, "bits per sample %u, must be 1\n", bits_per_sample); 1.388 - goto fail; 1.389 - } 1.390 - 1.391 - if (planar_config != 1) 1.392 - { 1.393 - fprintf (stderr, "planar config %u, must be 1\n", planar_config); 1.394 - goto fail; 1.395 - } 1.396 - 1.397 - if (input_attributes.has_resolution) 1.398 - { 1.399 - x_resolution = input_attributes.x_resolution; 1.400 - y_resolution = input_attributes.y_resolution; 1.401 - } 1.402 - 1.403 - if ((input_attributes.rotation == 90) || (input_attributes.rotation == 270)) 1.404 - { 1.405 - dest_image_width = image_length; 1.406 - dest_image_length = image_width; 1.407 - dest_x_resolution = y_resolution; 1.408 - dest_y_resolution = x_resolution; 1.409 - SWAP (double, width_points, height_points); /* $$$ not yet set!!! */ 1.410 - } 1.411 - else 1.412 - { 1.413 - dest_image_width = image_width; 1.414 - dest_image_length = image_length; 1.415 - dest_x_resolution = x_resolution; 1.416 - dest_y_resolution = y_resolution; 1.417 - } 1.418 - 1.419 - rect.min.x = 0; 1.420 - rect.min.y = 0; 1.421 - rect.max.x = image_width; 1.422 - rect.max.y = image_length; 1.423 - 1.424 - bitmap = create_bitmap (& rect); 1.425 - 1.426 - if (! bitmap) 1.427 - { 1.428 - fprintf (stderr, "can't allocate bitmap\n"); 1.429 - goto fail; 1.430 - } 1.431 - 1.432 - for (row = 0; row < image_length; row++) 1.433 - if (1 != TIFFReadScanline (in, 1.434 - bitmap->bits + row * bitmap->row_words, 1.435 - row, 1.436 - 0)) 1.437 - { 1.438 - fprintf (stderr, "can't read TIFF scanline\n"); 1.439 - goto fail; 1.440 - } 1.441 - 1.442 -#ifdef TIFF_REVERSE_BITS 1.443 - reverse_bits ((uint8_t *) bitmap->bits, 1.444 - image_length * bitmap->row_words * sizeof (word_t)); 1.445 -#endif /* TIFF_REVERSE_BITS */ 1.446 - 1.447 -#if 0 1.448 - if (input_attributes.has_page_size) 1.449 - bitmap = resize_bitmap (bitmap, 1.450 - x_resolution, 1.451 - y_resolution, 1.452 - input_attributes); 1.453 -#endif 1.454 - 1.455 - rotate_bitmap (bitmap, 1.456 - input_attributes); 1.457 - 1.458 - width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; 1.459 - height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; 1.460 - 1.461 - if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 1.462 - { 1.463 - fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 1.464 - goto fail; 1.465 - } 1.466 - 1.467 - page = pdf_new_page (out->pdf, width_points, height_points); 1.468 - 1.469 -#if 0 1.470 - pdf_write_text (page); 1.471 -#else 1.472 - pdf_write_g4_fax_image (page, 1.473 - 0, 0, /* x, y */ 1.474 - width_points, height_points, 1.475 - bitmap, 1.476 - 0, /* ImageMask */ 1.477 - 0, 0, 0, /* r, g, b */ 1.478 - 0); /* BlackIs1 */ 1.479 -#endif 1.480 - 1.481 - while (bookmarks) 1.482 - { 1.483 - /* $$$ need to handle level here */ 1.484 - pdf_new_bookmark (NULL, bookmarks->name, 0, page); 1.485 - bookmarks = bookmarks->next; 1.486 - } 1.487 - 1.488 - result = 1; 1.489 - 1.490 - fail: 1.491 - if (bitmap) 1.492 - free_bitmap (bitmap); 1.493 - 1.494 - return (result); 1.495 -} 1.496 - 1.497 - 1.498 -#if 0 1.499 -bool process_jpeg_page (int image, /* range 1 .. n */ 1.500 - input_attributes_t input_attributes, 1.501 - bookmark_t *bookmarks) 1.502 -{ 1.503 - int result = 0; 1.504 - FILE *f; 1.505 - pdf_page_handle page; 1.506 - 1.507 - f = fopen (filename, "rb"); 1.508 - if (! f) 1.509 - fatal ("error opening input file '%s'\n", filename); 1.510 - 1.511 - page = pdf_new_page (out->pdf, width_points, height_points); 1.512 - 1.513 - pdf_write_jpeg_image (page, 1.514 - 0, 0, /* x, y */ 1.515 - width_points, height_points, 1.516 - f); 1.517 - 1.518 - return (result); 1.519 -} 1.520 -#endif 1.521 - 1.522 - 1.523 -bool process_page (int image, /* range 1 .. n */ 1.524 - input_attributes_t input_attributes, 1.525 - bookmark_t *bookmarks) 1.526 -{ 1.527 - int result = 0; 1.528 - 1.529 - result = process_tiff_page (image, input_attributes, bookmarks); 1.530 - 1.531 - return (result); 1.532 -} 1.533 - 1.534 - 1.535 -#define MAX_BOOKMARK_NAME_LEN 500 1.536 - 1.537 - 1.538 -static int filename_length_without_suffix (char *in_fn) 1.539 -{ 1.540 - char *p; 1.541 - int len = strlen (in_fn); 1.542 - 1.543 - p = strrchr (in_fn, '.'); 1.544 - if (p && ((strcasecmp (p, ".tif") == 0) || 1.545 - (strcasecmp (p, ".tiff") == 0))) 1.546 - return (p - in_fn); 1.547 - return (len); 1.548 -} 1.549 - 1.550 - 1.551 -/* $$$ this function should ensure that it doesn't overflow the name string! */ 1.552 -static void generate_bookmark_name (char *name, 1.553 - char *bookmark_fmt, 1.554 - char *in_fn, 1.555 - int page) 1.556 -{ 1.557 - bool meta = 0; 1.558 - int len; 1.559 - 1.560 - while (*bookmark_fmt) 1.561 - { 1.562 - if (meta) 1.563 - { 1.564 - meta = 0; 1.565 - switch (*bookmark_fmt) 1.566 - { 1.567 - case '%': 1.568 - *(name++) = '%'; 1.569 - break; 1.570 - case 'F': 1.571 - len = filename_length_without_suffix (in_fn); 1.572 - strncpy (name, in_fn, len); 1.573 - name += len; 1.574 - break; 1.575 - case 'p': 1.576 - sprintf (name, "%d", page); 1.577 - name += strlen (name); 1.578 - break; 1.579 - default: 1.580 - break; 1.581 - } 1.582 - } 1.583 - else 1.584 - switch (*bookmark_fmt) 1.585 - { 1.586 - case '%': 1.587 - meta = 1; 1.588 - break; 1.589 - default: 1.590 - *(name++) = *bookmark_fmt; 1.591 - } 1.592 - bookmark_fmt++; 1.593 - } 1.594 - *name = '\0'; 1.595 -} 1.596 - 1.597 - 1.598 -void main_args (char *out_fn, 1.599 - int inf_count, 1.600 - char **in_fn, 1.601 - char *bookmark_fmt) 1.602 -{ 1.603 - int i, ip; 1.604 - input_attributes_t input_attributes; 1.605 - pdf_file_attributes_t output_attributes; 1.606 - bookmark_t bookmark; 1.607 - char bookmark_name [MAX_BOOKMARK_NAME_LEN]; 1.608 - 1.609 - bookmark.next = NULL; 1.610 - bookmark.level = 1; 1.611 - bookmark.name = & bookmark_name [0]; 1.612 - 1.613 - memset (& input_attributes, 0, sizeof (input_attributes)); 1.614 - memset (& output_attributes, 0, sizeof (output_attributes)); 1.615 - 1.616 - output_attributes.has_bookmarks = (bookmark_fmt != NULL); 1.617 - 1.618 - if (! open_pdf_output_file (out_fn, & output_attributes)) 1.619 - fatal (3, "error opening output file \"%s\"\n", out_fn); 1.620 - for (i = 0; i < inf_count; i++) 1.621 - { 1.622 - if (! open_tiff_input_file (in_fn [i])) 1.623 - fatal (3, "error opening input file \"%s\"\n", in_fn [i]); 1.624 - for (ip = 1;; ip++) 1.625 - { 1.626 - fprintf (stderr, "processing page %d of file \"%s\"\r", ip, in_fn [i]); 1.627 - if (bookmark_fmt) 1.628 - generate_bookmark_name (& bookmark_name [0], 1.629 - bookmark_fmt, 1.630 - in_fn [i], 1.631 - ip); 1.632 - if (! process_page (ip, input_attributes, 1.633 - bookmark_fmt ? & bookmark : NULL)) 1.634 - fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); 1.635 - if (last_tiff_page ()) 1.636 - break; 1.637 - } 1.638 - if (verbose) 1.639 - fprintf (stderr, "processed %d pages of input file \"%s\"\n", ip, in_fn [i]); 1.640 - if (! close_tiff_input_file ()) 1.641 - fatal (3, "error closing input file \"%s\"\n", in_fn [i]); 1.642 - } 1.643 - if (! close_pdf_output_files ()) 1.644 - fatal (3, "error closing output file \"%s\"\n", out_fn); 1.645 -} 1.646 - 1.647 - 1.648 -void main_spec (char *spec_fn) 1.649 -{ 1.650 - if (! parse_spec_file (spec_fn)) 1.651 - fatal (2, "error parsing spec file\n"); 1.652 - if (! process_specs ()) 1.653 - fatal (3, "error processing spec file\n"); 1.654 -} 1.655 - 1.656 - 1.657 -int main (int argc, char *argv[]) 1.658 -{ 1.659 - char *spec_fn = NULL; 1.660 - char *out_fn = NULL; 1.661 - char *bookmark_fmt = NULL; 1.662 - int inf_count = 0; 1.663 - char *in_fn [MAX_INPUT_FILES]; 1.664 - 1.665 - progname = argv [0]; 1.666 - 1.667 - pdf_init (); 1.668 - 1.669 - while (--argc) 1.670 - { 1.671 - if (argv [1][0] == '-') 1.672 - { 1.673 - if (strcmp (argv [1], "-v") == 0) 1.674 - verbose++; 1.675 - else if (strcmp (argv [1], "-o") == 0) 1.676 - { 1.677 - if (argc) 1.678 - { 1.679 - argc--; 1.680 - argv++; 1.681 - out_fn = argv [1]; 1.682 - } 1.683 - else 1.684 - fatal (1, "missing filename after \"-o\" option\n"); 1.685 - } 1.686 - else if (strcmp (argv [1], "-s") == 0) 1.687 - { 1.688 - if (argc) 1.689 - { 1.690 - argc--; 1.691 - argv++; 1.692 - spec_fn = argv [1]; 1.693 - } 1.694 - else 1.695 - fatal (1, "missing filename after \"-s\" option\n"); 1.696 - } 1.697 - else if (strcmp (argv [1], "-b") == 0) 1.698 - { 1.699 - if (argc) 1.700 - { 1.701 - argc--; 1.702 - argv++; 1.703 - bookmark_fmt = argv [1]; 1.704 - } 1.705 - else 1.706 - fatal (1, "missing format string after \"-b\" option\n"); 1.707 - } 1.708 - else 1.709 - fatal (1, "unrecognized option \"%s\"\n", argv [1]); 1.710 - } 1.711 - else if (inf_count < MAX_INPUT_FILES) 1.712 - in_fn [inf_count++] = argv [1]; 1.713 - else 1.714 - fatal (1, "exceeded maximum of %d input files\n", MAX_INPUT_FILES); 1.715 - argv++; 1.716 - } 1.717 - 1.718 - if (! ((! out_fn) ^ (! spec_fn))) 1.719 - fatal (1, "either a spec file or an output file (but not both) must be specified\n"); 1.720 - 1.721 - if (out_fn && ! inf_count) 1.722 - fatal (1, "no input files specified\n"); 1.723 - 1.724 - if (spec_fn && inf_count) 1.725 - fatal (1, "if spec file is provided, input files can't be specified as arguments\n"); 1.726 - 1.727 - if (spec_fn) 1.728 - main_spec (spec_fn); 1.729 - else 1.730 - main_args (out_fn, inf_count, in_fn, bookmark_fmt); 1.731 - 1.732 - close_tiff_input_file (); 1.733 - close_pdf_output_files (); 1.734 - exit (0); 1.735 -}