semantics.c

changeset 25
139b91f9a224
parent 24
6575fcfbdb1b
child 26
4368c5fd9242
     1.1 --- a/semantics.c	Mon Dec 31 08:25:04 2001 +0000
     1.2 +++ b/semantics.c	Mon Dec 31 16:44:24 2001 +0000
     1.3 @@ -5,6 +5,7 @@
     1.4  #include "type.h"
     1.5  #include "semantics.h"
     1.6  #include "parser.tab.h"
     1.7 +#include "tiff2pdf.h"
     1.8  
     1.9  
    1.10  typedef struct
    1.11 @@ -53,7 +54,9 @@
    1.12    char *output_file;
    1.13    bookmark_t *first_bookmark;
    1.14    bookmark_t *last_bookmark;
    1.15 -  char *page_number_format;
    1.16 +
    1.17 +  boolean has_page_label;
    1.18 +  page_label_t page_label;
    1.19  } output_context_t;
    1.20  
    1.21  
    1.22 @@ -312,10 +315,11 @@
    1.23    last_output_context->last_bookmark = new_bookmark;
    1.24  }
    1.25  
    1.26 -void output_set_page_number_format (char *format)
    1.27 +void output_set_page_label (page_label_t label)
    1.28  {
    1.29    output_clone ();
    1.30 -  last_output_context->page_number_format = format;
    1.31 +  last_output_context->has_page_label = 1;
    1.32 +  last_output_context->page_label = label;
    1.33  }
    1.34  
    1.35  static void increment_output_page_count (int count)
    1.36 @@ -408,11 +412,11 @@
    1.37    exit (2);
    1.38  }
    1.39  
    1.40 -static char *get_output_page_number_format (output_context_t *context)
    1.41 +static page_label_t *get_output_page_label (output_context_t *context)
    1.42  {
    1.43    for (; context; context = context->parent)
    1.44 -    if (context->page_number_format)
    1.45 -      return (context->page_number_format);
    1.46 +    if (context->has_page_label)
    1.47 +      return (& context->page_label);
    1.48    return (NULL);  /* default */
    1.49  }
    1.50  
    1.51 @@ -447,18 +451,87 @@
    1.52        if (page->bookmark_list)
    1.53  	{
    1.54  	  for (bookmark = page->bookmark_list; bookmark; bookmark = bookmark->next)
    1.55 -	    printf ("bookmark %d '%s'\n", bookmark->level, bookmark->name);
    1.56 +	    printf ("bookmark %d \"%s\"\n", bookmark->level, bookmark->name);
    1.57  	}
    1.58        for (i = page->range.first; i <= page->range.last; i++)
    1.59  	{
    1.60 -	  printf ("file '%s' ", get_output_file (page->output_context));
    1.61 -	  printf ("format '%s' ", get_output_page_number_format (page->output_context));
    1.62 +	  page_label_t *label = get_output_page_label (page->output_context);
    1.63 +	  printf ("file \"%s\" ", get_output_file (page->output_context));
    1.64 +	  if (label)
    1.65 +	    {
    1.66 +	      printf ("label ");
    1.67 +	      if (label->prefix)
    1.68 +		printf ("\"%s\" ", label->prefix);
    1.69 +	      if (label->style)
    1.70 +		printf ("'%c' ", label->style);
    1.71 +	    }
    1.72  	  printf ("page %d\n", i);
    1.73  	}
    1.74      }
    1.75  }
    1.76  #endif /* SEMANTIC_DEBUG */
    1.77  
    1.78 +
    1.79 +static inline int range_count (range_t range)
    1.80 +{
    1.81 +  return ((range.last - range.first) + 1);
    1.82 +}
    1.83 +
    1.84 +
    1.85 +void doit (void)
    1.86 +{
    1.87 +  input_image_t *image = NULL;
    1.88 +  output_page_t *page = NULL;
    1.89 +  int i = 0;
    1.90 +  int p = 0;
    1.91 +  int page_index = 0;
    1.92 +  input_attributes_t input_attributes;
    1.93 +  input_modifier_type_t parity;
    1.94 +  page_label_t *page_label;
    1.95 +
    1.96 +  for (;;)
    1.97 +    {
    1.98 +      if ((! image) || (i >= range_count (image->range)))
    1.99 +	{
   1.100 +	  if (image)
   1.101 +	    image = image->next;
   1.102 +	  else
   1.103 +	    image = first_input_image;
   1.104 +	  if (! image)
   1.105 +	    return;
   1.106 +	  i = 0;
   1.107 +	}
   1.108 +
   1.109 +      if ((! page) || (p >= range_count (page->range)))
   1.110 +	{
   1.111 +	  if (page)
   1.112 +	    page = page->next;
   1.113 +	  else
   1.114 +	    page = first_output_page;
   1.115 +	  p = 0;
   1.116 +	  page_label = get_output_page_label (page->output_context);
   1.117 +	  process_page_numbers (page_index,
   1.118 +				range_count (page->range),
   1.119 +				page->range.first,
   1.120 +				page_label);
   1.121 +	}
   1.122 +
   1.123 +      parity = ((image->range.first + i) % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
   1.124 +
   1.125 +      memset (& input_attributes, 0, sizeof (input_attributes));
   1.126 +      input_attributes.rotation = get_input_rotation (image->input_context,
   1.127 +						      parity);;
   1.128 +
   1.129 +      process_page (image->range.first + i,
   1.130 +		    input_attributes,
   1.131 +		    page->bookmark_list);
   1.132 +      i++;
   1.133 +      p++;
   1.134 +      page_index++;
   1.135 +    }
   1.136 +}
   1.137 +
   1.138 +
   1.139  boolean parse_spec_file (char *fn)
   1.140  {
   1.141    boolean result = 0;