1.1 diff -r 3fe049d83e22 -r 752599b50ff3 tumble_input.c 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/tumble_input.c Thu Mar 20 06:54:08 2003 +0000 1.4 @@ -0,0 +1,140 @@ 1.5 +/* 1.6 + * tumble: build a PDF file from image files 1.7 + * 1.8 + * Input handler dispatch 1.9 + * $Id: tumble_input.c,v 1.1 2003/03/19 22:54:08 eric Exp $ 1.10 + * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.11 + * 1.12 + * This program is free software; you can redistribute it and/or modify 1.13 + * it under the terms of the GNU General Public License version 2 as 1.14 + * published by the Free Software Foundation. Note that permission is 1.15 + * not granted to redistribute this program under the terms of any 1.16 + * other version of the General Public License. 1.17 + * 1.18 + * This program is distributed in the hope that it will be useful, 1.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.21 + * GNU General Public License for more details. 1.22 + * 1.23 + * You should have received a copy of the GNU General Public License 1.24 + * along with this program; if not, write to the Free Software 1.25 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.26 + */ 1.27 + 1.28 + 1.29 +#include <stdbool.h> 1.30 +#include <stdint.h> 1.31 +#include <stdio.h> 1.32 +#include <stdlib.h> 1.33 +#include <string.h> 1.34 + 1.35 + 1.36 +#include "semantics.h" 1.37 +#include "tumble.h" 1.38 +#include "bitblt.h" 1.39 +#include "pdf.h" 1.40 +#include "tumble_input.h" 1.41 + 1.42 + 1.43 +#define MAX_INPUT_HANDLERS 10 1.44 + 1.45 +static int input_handler_count = 0; 1.46 + 1.47 +static input_handler_t *input_handlers [MAX_INPUT_HANDLERS]; 1.48 + 1.49 + 1.50 +static char *in_filename; 1.51 +static FILE *in; 1.52 +static input_handler_t *current_input_handler; 1.53 + 1.54 + 1.55 +void install_input_handler (input_handler_t *handler) 1.56 +{ 1.57 + if (input_handler_count >= MAX_INPUT_HANDLERS) 1.58 + fprintf (stderr, "Too many input handlers, table only has room for %d\n", MAX_INPUT_HANDLERS); 1.59 + else 1.60 + input_handlers [input_handler_count++] = handler; 1.61 +} 1.62 + 1.63 + 1.64 +bool open_input_file (char *name) 1.65 +{ 1.66 + int i; 1.67 + 1.68 + if (in) 1.69 + { 1.70 + if (strcmp (name, in_filename) == 0) 1.71 + return (1); 1.72 + close_input_file (); 1.73 + } 1.74 + in_filename = strdup (name); 1.75 + if (! in_filename) 1.76 + { 1.77 + fprintf (stderr, "can't strdup input filename '%s'\n", name); 1.78 + goto fail; 1.79 + } 1.80 + 1.81 + in = fopen (name, "rb"); 1.82 + if (! in) 1.83 + goto fail; 1.84 + 1.85 + for (i = 0; i < input_handler_count; i++) 1.86 + { 1.87 + if (input_handlers [i]->open_input_file (in, name)) 1.88 + break; 1.89 + } 1.90 + if (i >= input_handler_count) 1.91 + { 1.92 + fprintf (stderr, "unrecognized format for input file '%s'\n", name); 1.93 + goto fail; 1.94 + } 1.95 + current_input_handler = input_handlers [i]; 1.96 + return (1); 1.97 + 1.98 + fail: 1.99 + if (in) 1.100 + fclose (in); 1.101 + in = NULL; 1.102 + return (0); 1.103 +} 1.104 + 1.105 + 1.106 +bool close_input_file (void) 1.107 +{ 1.108 + bool result; 1.109 + 1.110 + result = current_input_handler->close_input_file (); 1.111 + if (in_filename) 1.112 + free (in_filename); 1.113 + fclose (in); 1.114 + in = NULL; 1.115 + 1.116 + return (result); 1.117 +} 1.118 + 1.119 + 1.120 +bool last_input_page (void) 1.121 +{ 1.122 + return (current_input_handler->last_input_page ()); 1.123 +} 1.124 + 1.125 + 1.126 +bool get_image_info (int image, 1.127 + input_attributes_t input_attributes, 1.128 + image_info_t *image_info) 1.129 +{ 1.130 + return (current_input_handler->get_image_info (image, 1.131 + input_attributes, 1.132 + image_info)); 1.133 +} 1.134 + 1.135 +bool process_image (int image, 1.136 + input_attributes_t input_attributes, 1.137 + image_info_t *image_info, 1.138 + pdf_page_handle page) 1.139 +{ 1.140 + return (current_input_handler->process_image (image, 1.141 + input_attributes, 1.142 + image_info, 1.143 + page)); 1.144 +}