added match_suffix() to input handlers.

Thu, 20 Mar 2003 14:55:28 +0000

author
eric
date
Thu, 20 Mar 2003 14:55:28 +0000
changeset 151
83a99cc69861
parent 150
17531d20e477
child 152
e69798068425

added match_suffix() to input handlers.

tumble.c file | annotate | diff | revisions
tumble_input.c file | annotate | diff | revisions
tumble_input.h file | annotate | diff | revisions
tumble_jpeg.c file | annotate | diff | revisions
tumble_tiff.c file | annotate | diff | revisions
     1.1 diff -r 17531d20e477 -r 83a99cc69861 tumble.c
     1.2 --- a/tumble.c	Thu Mar 20 08:32:16 2003 +0000
     1.3 +++ b/tumble.c	Thu Mar 20 14:55:28 2003 +0000
     1.4 @@ -2,7 +2,7 @@
     1.5   * tumble: build a PDF file from image files
     1.6   *
     1.7   * Main program
     1.8 - * $Id: tumble.c,v 1.39 2003/03/20 00:26:18 eric Exp $
     1.9 + * $Id: tumble.c,v 1.40 2003/03/20 06:55:27 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 @@ -224,10 +224,7 @@
    1.14    int len = strlen (in_fn);
    1.15  
    1.16    p = strrchr (in_fn, '.');
    1.17 -  if (p && ((strcasecmp (p, ".tif") == 0) ||
    1.18 -	    (strcasecmp (p, ".tiff") == 0) ||
    1.19 -	    (strcasecmp (p, ".jpg") == 0) ||
    1.20 -	    (strcasecmp (p, ".jpeg") == 0)))
    1.21 +  if (p && match_input_suffix (p))
    1.22      return (p - in_fn);
    1.23    return (len);
    1.24  }
     2.1 diff -r 17531d20e477 -r 83a99cc69861 tumble_input.c
     2.2 --- a/tumble_input.c	Thu Mar 20 08:32:16 2003 +0000
     2.3 +++ b/tumble_input.c	Thu Mar 20 14:55:28 2003 +0000
     2.4 @@ -2,7 +2,7 @@
     2.5   * tumble: build a PDF file from image files
     2.6   *
     2.7   * Input handler dispatch
     2.8 - * $Id: tumble_input.c,v 1.2 2003/03/19 23:02:28 eric Exp $
     2.9 + * $Id: tumble_input.c,v 1.3 2003/03/20 06:55:27 eric Exp $
    2.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    2.11   *
    2.12   * This program is free software; you can redistribute it and/or modify
    2.13 @@ -57,6 +57,15 @@
    2.14  }
    2.15  
    2.16  
    2.17 +bool match_input_suffix (char *suffix)
    2.18 +{
    2.19 +  int i;
    2.20 +  for (i = 0; i < input_handler_count; i++)
    2.21 +    if (input_handlers [i]->match_suffix (suffix))
    2.22 +      return (1);
    2.23 +  return (0);
    2.24 +}
    2.25 +
    2.26  bool open_input_file (char *name)
    2.27  {
    2.28    int i;
     3.1 diff -r 17531d20e477 -r 83a99cc69861 tumble_input.h
     3.2 --- a/tumble_input.h	Thu Mar 20 08:32:16 2003 +0000
     3.3 +++ b/tumble_input.h	Thu Mar 20 14:55:28 2003 +0000
     3.4 @@ -1,7 +1,7 @@
     3.5  /*
     3.6   * tumble: build a PDF file from image files
     3.7   *
     3.8 - * $Id: tumble_input.h,v 1.1 2003/03/19 22:54:08 eric Exp $
     3.9 + * $Id: tumble_input.h,v 1.2 2003/03/20 06:55:27 eric Exp $
    3.10   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    3.11   *
    3.12   * This program is free software; you can redistribute it and/or modify
    3.13 @@ -32,6 +32,7 @@
    3.14  
    3.15  typedef struct
    3.16  {
    3.17 +  bool (*match_suffix) (char *suffix);
    3.18    bool (*open_input_file) (FILE *f, char *name);
    3.19    bool (*close_input_file) (void);
    3.20    bool (*last_input_page) (void);
    3.21 @@ -48,6 +49,7 @@
    3.22  void install_input_handler (input_handler_t *handler);
    3.23  
    3.24  
    3.25 +bool match_input_suffix (char *suffix);
    3.26  bool open_input_file (char *name);
    3.27  bool close_input_file (void);
    3.28  bool last_input_page (void);
     4.1 diff -r 17531d20e477 -r 83a99cc69861 tumble_jpeg.c
     4.2 --- a/tumble_jpeg.c	Thu Mar 20 08:32:16 2003 +0000
     4.3 +++ b/tumble_jpeg.c	Thu Mar 20 14:55:28 2003 +0000
     4.4 @@ -1,7 +1,7 @@
     4.5  /*
     4.6   * tumble: build a PDF file from image files
     4.7   *
     4.8 - * $Id: tumble_jpeg.c,v 1.3 2003/03/20 00:32:16 eric Exp $
     4.9 + * $Id: tumble_jpeg.c,v 1.4 2003/03/20 06:55:27 eric Exp $
    4.10   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    4.11   *
    4.12   * This program is free software; you can redistribute it and/or modify
    4.13 @@ -24,6 +24,7 @@
    4.14  #include <stdbool.h>
    4.15  #include <stdint.h>
    4.16  #include <stdio.h>
    4.17 +#include <strings.h>  /* strcasecmp() is a BSDism */
    4.18  #include <jpeglib.h>
    4.19  
    4.20  
    4.21 @@ -40,13 +41,19 @@
    4.22  static struct jpeg_error_mgr jerr;
    4.23  
    4.24  
    4.25 -bool close_jpeg_input_file (void)
    4.26 +static bool match_jpeg_suffix (char *suffix)
    4.27 +{
    4.28 +  return ((strcasecmp (suffix, ".jpg") == 0) ||
    4.29 +	  (strcasecmp (suffix, ".jpeg") == 0));
    4.30 +}
    4.31 +
    4.32 +static bool close_jpeg_input_file (void)
    4.33  {
    4.34    return (1);
    4.35  }
    4.36  
    4.37  
    4.38 -bool open_jpeg_input_file (FILE *f, char *name)
    4.39 +static bool open_jpeg_input_file (FILE *f, char *name)
    4.40  {
    4.41    uint8_t buf [2];
    4.42    size_t l;
    4.43 @@ -75,15 +82,15 @@
    4.44  }
    4.45  
    4.46  
    4.47 -bool last_jpeg_input_page (void)
    4.48 +static bool last_jpeg_input_page (void)
    4.49  {
    4.50    return (1);
    4.51  }
    4.52  
    4.53  
    4.54 -bool get_jpeg_image_info (int image,
    4.55 -			  input_attributes_t input_attributes,
    4.56 -			  image_info_t *image_info)
    4.57 +static bool get_jpeg_image_info (int image,
    4.58 +				 input_attributes_t input_attributes,
    4.59 +				 image_info_t *image_info)
    4.60  {
    4.61    double unit;
    4.62  
    4.63 @@ -155,10 +162,10 @@
    4.64  }
    4.65  
    4.66  
    4.67 -bool process_jpeg_image (int image,  /* range 1 .. n */
    4.68 -			 input_attributes_t input_attributes,
    4.69 -			 image_info_t *image_info,
    4.70 -			 pdf_page_handle page)
    4.71 +static bool process_jpeg_image (int image,  /* range 1 .. n */
    4.72 +				input_attributes_t input_attributes,
    4.73 +				image_info_t *image_info,
    4.74 +				pdf_page_handle page)
    4.75  {
    4.76    pdf_write_jpeg_image (page,
    4.77  			0, 0,  /* x, y */
    4.78 @@ -175,6 +182,7 @@
    4.79  
    4.80  input_handler_t jpeg_handler =
    4.81    {
    4.82 +    match_jpeg_suffix,
    4.83      open_jpeg_input_file,
    4.84      close_jpeg_input_file,
    4.85      last_jpeg_input_page,
     5.1 diff -r 17531d20e477 -r 83a99cc69861 tumble_tiff.c
     5.2 --- a/tumble_tiff.c	Thu Mar 20 08:32:16 2003 +0000
     5.3 +++ b/tumble_tiff.c	Thu Mar 20 14:55:28 2003 +0000
     5.4 @@ -1,7 +1,7 @@
     5.5  /*
     5.6   * tumble: build a PDF file from image files
     5.7   *
     5.8 - * $Id: tumble_tiff.c,v 1.3 2003/03/20 00:20:52 eric Exp $
     5.9 + * $Id: tumble_tiff.c,v 1.4 2003/03/20 06:55:28 eric Exp $
    5.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    5.11   *
    5.12   * This program is free software; you can redistribute it and/or modify
    5.13 @@ -25,7 +25,7 @@
    5.14  #include <stdint.h>
    5.15  #include <stdio.h>
    5.16  #include <stdlib.h>
    5.17 -#include <string.h>
    5.18 +#include <strings.h>  /* strcasecmp() is a BSDism */
    5.19  
    5.20  #include <tiffio.h>
    5.21  #define TIFF_REVERSE_BITS
    5.22 @@ -44,14 +44,21 @@
    5.23  #define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0)
    5.24  
    5.25  
    5.26 -bool close_tiff_input_file (void)
    5.27 +static bool match_tiff_suffix (char *suffix)
    5.28 +{
    5.29 +  return ((strcasecmp (suffix, ".tif") == 0) ||
    5.30 +	  (strcasecmp (suffix, ".tiff") == 0));
    5.31 +}
    5.32 +
    5.33 +
    5.34 +static bool close_tiff_input_file (void)
    5.35  {
    5.36    TIFFClose (tiff_in);
    5.37    return (1);
    5.38  }
    5.39  
    5.40  
    5.41 -bool open_tiff_input_file (FILE *f, char *name)
    5.42 +static bool open_tiff_input_file (FILE *f, char *name)
    5.43  {
    5.44    uint8_t buf [2];
    5.45    size_t l;
    5.46 @@ -75,15 +82,15 @@
    5.47  }
    5.48  
    5.49  
    5.50 -bool last_tiff_input_page (void)
    5.51 +static bool last_tiff_input_page (void)
    5.52  {
    5.53    return (TIFFLastDirectory (tiff_in));
    5.54  }
    5.55  
    5.56  
    5.57 -bool get_tiff_image_info (int image,
    5.58 -			  input_attributes_t input_attributes,
    5.59 -			  image_info_t *image_info)
    5.60 +static bool get_tiff_image_info (int image,
    5.61 +				 input_attributes_t input_attributes,
    5.62 +				 image_info_t *image_info)
    5.63  {
    5.64    uint32_t image_height, image_width;
    5.65    uint16_t samples_per_pixel;
    5.66 @@ -250,10 +257,10 @@
    5.67  }
    5.68  
    5.69  
    5.70 -bool process_tiff_image (int image,  /* range 1 .. n */
    5.71 -			 input_attributes_t input_attributes,
    5.72 -			 image_info_t *image_info,
    5.73 -			 pdf_page_handle page)
    5.74 +static bool process_tiff_image (int image,  /* range 1 .. n */
    5.75 +				input_attributes_t input_attributes,
    5.76 +				image_info_t *image_info,
    5.77 +				pdf_page_handle page)
    5.78  {
    5.79    bool result = 0;
    5.80    Rect rect;
    5.81 @@ -333,6 +340,7 @@
    5.82  
    5.83  input_handler_t tiff_handler =
    5.84    {
    5.85 +    match_tiff_suffix,
    5.86      open_tiff_input_file,
    5.87      close_tiff_input_file,
    5.88      last_tiff_input_page,