semantics.c

Mon, 26 Aug 2002 06:03:55 +0000

author
eric
date
Mon, 26 Aug 2002 06:03:55 +0000
changeset 48
3d0be1c1c1b2
parent 45
23ef95d6ff07
child 49
be20d7e8466f
permissions
-rw-r--r--

now use C99 stdint.h and stdbool.h

eric@48 1 #include <stdbool.h>
eric@48 2 #include <stdint.h>
eric@18 3 #include <stdlib.h>
eric@18 4 #include <string.h>
eric@16 5 #include <stdio.h>
eric@16 6
eric@18 7 #include "semantics.h"
eric@16 8 #include "parser.tab.h"
eric@44 9 #include "t2p.h"
eric@16 10
eric@16 11
eric@22 12 typedef struct
eric@22 13 {
eric@48 14 bool has_page_size;
eric@32 15 page_size_t page_size;
eric@22 16
eric@48 17 bool has_rotation;
eric@22 18 int rotation;
eric@22 19
eric@48 20 bool has_crop;
eric@22 21 crop_t crop;
eric@22 22 } input_modifiers_t;
eric@22 23
eric@22 24
eric@22 25 typedef struct input_context_t
eric@22 26 {
eric@22 27 struct input_context_t *parent;
eric@22 28 struct input_context_t *next;
eric@22 29
eric@22 30 int image_count; /* how many pages reference this context,
eric@22 31 including those from subcontexts */
eric@22 32
eric@22 33 char *input_file;
eric@22 34
eric@22 35 input_modifiers_t modifiers [INPUT_MODIFIER_TYPE_COUNT];
eric@22 36 } input_context_t;
eric@22 37
eric@22 38
eric@22 39 typedef struct input_image_t
eric@22 40 {
eric@22 41 struct input_image_t *next;
eric@22 42 input_context_t *input_context;
eric@22 43 range_t range;
eric@22 44 } input_image_t;
eric@22 45
eric@22 46
eric@22 47 typedef struct output_context_t
eric@22 48 {
eric@22 49 struct output_context_t *parent;
eric@22 50 struct output_context_t *next;
eric@22 51
eric@22 52 int page_count; /* how many pages reference this context,
eric@22 53 including those from subcontexts */
eric@22 54
eric@22 55 char *output_file;
eric@30 56 pdf_file_attributes_t file_attributes;
eric@30 57
eric@22 58 bookmark_t *first_bookmark;
eric@22 59 bookmark_t *last_bookmark;
eric@25 60
eric@48 61 bool has_page_label;
eric@25 62 page_label_t page_label;
eric@22 63 } output_context_t;
eric@22 64
eric@22 65
eric@22 66 typedef struct output_page_t
eric@22 67 {
eric@22 68 struct output_page_t *next;
eric@22 69 output_context_t *output_context;
eric@22 70 range_t range;
eric@22 71 bookmark_t *bookmark_list;
eric@22 72 } output_page_t;
eric@22 73
eric@22 74
eric@36 75 #undef SEMANTIC_DEBUG
eric@36 76
eric@19 77 #ifdef SEMANTIC_DEBUG
eric@19 78 #define SDBG(x) printf x
eric@19 79 #else
eric@19 80 #define SDBG(x)
eric@19 81 #endif
eric@19 82
eric@19 83
eric@16 84 FILE *yyin;
eric@16 85 int line; /* line number in spec file */
eric@16 86
eric@24 87 int bookmark_level;
eric@16 88
eric@20 89 input_context_t *first_input_context;
eric@20 90 input_context_t *last_input_context;
eric@20 91
eric@20 92 input_modifier_type_t current_modifier_context;
eric@18 93
eric@20 94 input_image_t *first_input_image;
eric@20 95 input_image_t *last_input_image;
eric@18 96
eric@20 97 output_context_t *first_output_context;
eric@20 98 output_context_t *last_output_context;
eric@20 99
eric@20 100 output_page_t *first_output_page;
eric@20 101 output_page_t *last_output_page;
eric@16 102
eric@16 103
eric@19 104 void input_push_context (void)
eric@16 105 {
eric@18 106 input_context_t *new_input_context;
eric@18 107
eric@18 108 new_input_context = malloc (sizeof (input_context_t));
eric@18 109 if (! new_input_context)
eric@18 110 {
eric@20 111 fprintf (stderr, "failed to malloc an input context\n");
eric@18 112 return;
eric@18 113 }
eric@18 114
eric@20 115 if (last_input_context)
eric@18 116 {
eric@20 117 memcpy (new_input_context, last_input_context, sizeof (input_context_t));
eric@20 118 new_input_context->image_count = 0;
eric@18 119 }
eric@18 120 else
eric@20 121 {
eric@20 122 memset (new_input_context, 0, sizeof (input_context_t));
eric@20 123 first_input_context = new_input_context;
eric@20 124 }
eric@18 125
eric@20 126 new_input_context->parent = last_input_context;
eric@20 127 last_input_context = new_input_context;
eric@16 128 };
eric@16 129
eric@16 130 void input_pop_context (void)
eric@16 131 {
eric@20 132 if (! last_input_context)
eric@18 133 {
eric@18 134 fprintf (stderr, "failed to pop an input context\n");
eric@18 135 return;
eric@18 136 }
eric@18 137
eric@20 138 last_input_context = last_input_context->parent;
eric@16 139 };
eric@16 140
eric@19 141 void input_set_modifier_context (input_modifier_type_t type)
eric@19 142 {
eric@19 143 current_modifier_context = type;
eric@19 144 #ifdef SEMANTIC_DEBUG
eric@19 145 SDBG(("modifier type "));
eric@19 146 switch (type)
eric@19 147 {
eric@19 148 case INPUT_MODIFIER_ALL: SDBG(("all")); break;
eric@19 149 case INPUT_MODIFIER_ODD: SDBG(("odd")); break;
eric@19 150 case INPUT_MODIFIER_EVEN: SDBG(("even")); break;
eric@19 151 default: SDBG(("unknown %d", type));
eric@19 152 }
eric@19 153 SDBG(("\n"));
eric@19 154 #endif /* SEMANTIC_DEBUG */
eric@19 155 }
eric@19 156
eric@22 157 static void input_clone (void)
eric@20 158 {
eric@20 159 input_context_t *new_input_context;
eric@20 160
eric@20 161 if (! last_input_context->image_count)
eric@20 162 return;
eric@20 163
eric@20 164 new_input_context = malloc (sizeof (input_context_t));
eric@20 165 if (! new_input_context)
eric@20 166 {
eric@20 167 fprintf (stderr, "failed to malloc an input context\n");
eric@20 168 return;
eric@20 169 }
eric@20 170
eric@20 171 memcpy (new_input_context, last_input_context, sizeof (input_context_t));
eric@20 172 new_input_context->image_count = 0;
eric@20 173 last_input_context->next = new_input_context;
eric@45 174 last_input_context = new_input_context;
eric@20 175 }
eric@20 176
eric@16 177 void input_set_file (char *name)
eric@16 178 {
eric@20 179 input_clone ();
eric@20 180 last_input_context->input_file = name;
eric@16 181 };
eric@16 182
eric@19 183 void input_set_rotation (int rotation)
eric@19 184 {
eric@20 185 last_input_context->modifiers [current_modifier_context].has_rotation = 1;
eric@20 186 last_input_context->modifiers [current_modifier_context].rotation = rotation;
eric@19 187 SDBG(("rotation %d\n", rotation));
eric@19 188 }
eric@19 189
eric@32 190 void input_set_page_size (page_size_t size)
eric@32 191 {
eric@32 192 last_input_context->modifiers [current_modifier_context].has_page_size = 1;
eric@32 193 last_input_context->modifiers [current_modifier_context].page_size = size;
eric@32 194 SDBG(("page size %f, %f\n", size.width, size.height));
eric@32 195 }
eric@32 196
eric@22 197 static void increment_input_image_count (int count)
eric@16 198 {
eric@20 199 input_context_t *context;
eric@20 200
eric@20 201 for (context = last_input_context; context; context = context->parent)
eric@20 202 context->image_count += count;
eric@20 203 }
eric@20 204
eric@20 205 void input_images (range_t range)
eric@20 206 {
eric@20 207 input_image_t *new_image;
eric@20 208 int count = ((range.last - range.first) + 1);
eric@20 209
eric@19 210 #ifdef SEMANTIC_DEBUG
eric@20 211 if (range.first == range.last)
eric@20 212 SDBG(("image %d\n", range.first));
eric@16 213 else
eric@20 214 SDBG(("images %d..%d\n", range.first, range.last));
eric@19 215 #endif /* SEMANTIC_DEBUG */
eric@20 216
eric@20 217 new_image = calloc (1, sizeof (input_image_t));
eric@20 218 if (! new_image)
eric@20 219 {
eric@20 220 fprintf (stderr, "failed to malloc an input image struct\n");
eric@20 221 return;
eric@20 222 }
eric@20 223 if (first_input_image)
eric@20 224 {
eric@20 225 last_input_image->next = new_image;
eric@20 226 last_input_image = new_image;
eric@20 227 }
eric@20 228 else
eric@20 229 {
eric@20 230 first_input_image = last_input_image = new_image;
eric@20 231 }
eric@20 232 new_image->range = range;
eric@20 233 new_image->input_context = last_input_context;
eric@20 234 increment_input_image_count (count);
eric@16 235 }
eric@16 236
eric@18 237
eric@18 238 void output_push_context (void)
eric@18 239 {
eric@20 240 output_context_t *new_output_context;
eric@20 241
eric@20 242 new_output_context = malloc (sizeof (output_context_t));
eric@20 243 if (! new_output_context)
eric@20 244 {
eric@20 245 fprintf (stderr, "failed to malloc an output context\n");
eric@20 246 return;
eric@20 247 }
eric@20 248
eric@20 249 if (last_output_context)
eric@20 250 {
eric@20 251 memcpy (new_output_context, last_output_context, sizeof (output_context_t));
eric@20 252 new_output_context->page_count = 0;
eric@21 253 new_output_context->first_bookmark = NULL;
eric@21 254 new_output_context->last_bookmark = NULL;
eric@20 255 }
eric@20 256 else
eric@20 257 {
eric@20 258 memset (new_output_context, 0, sizeof (output_context_t));
eric@20 259 first_output_context = new_output_context;
eric@20 260 }
eric@20 261
eric@20 262 new_output_context->parent = last_output_context;
eric@20 263 last_output_context = new_output_context;
eric@18 264 };
eric@18 265
eric@20 266 void output_pop_context (void)
eric@20 267 {
eric@20 268 if (! last_output_context)
eric@20 269 {
eric@20 270 fprintf (stderr, "failed to pop an output context\n");
eric@20 271 return;
eric@20 272 }
eric@20 273
eric@20 274 last_output_context = last_output_context->parent;
eric@20 275 };
eric@20 276
eric@22 277 static void output_clone (void)
eric@20 278 {
eric@20 279 output_context_t *new_output_context;
eric@20 280
eric@20 281 if (! last_output_context->page_count)
eric@20 282 return;
eric@20 283
eric@20 284 new_output_context = malloc (sizeof (output_context_t));
eric@20 285 if (! new_output_context)
eric@20 286 {
eric@20 287 fprintf (stderr, "failed to malloc an output context\n");
eric@20 288 return;
eric@20 289 }
eric@20 290
eric@20 291 memcpy (new_output_context, last_output_context, sizeof (output_context_t));
eric@20 292 new_output_context->page_count = 0;
eric@20 293 last_output_context->next = new_output_context;
eric@20 294 }
eric@20 295
eric@16 296 void output_set_file (char *name)
eric@16 297 {
eric@20 298 output_clone ();
eric@20 299 last_output_context->output_file = name;
eric@30 300 last_output_context->file_attributes.author = NULL;
eric@30 301 last_output_context->file_attributes.creator = NULL;
eric@30 302 last_output_context->file_attributes.title = NULL;
eric@30 303 last_output_context->file_attributes.subject = NULL;
eric@30 304 last_output_context->file_attributes.keywords = NULL;
eric@16 305 };
eric@16 306
eric@30 307 void output_set_author (char *author)
eric@30 308 {
eric@30 309 last_output_context->file_attributes.author = author;
eric@30 310 }
eric@30 311
eric@30 312 void output_set_creator (char *creator)
eric@30 313 {
eric@30 314 last_output_context->file_attributes.creator = creator;
eric@30 315 }
eric@30 316
eric@30 317 void output_set_title (char *title)
eric@30 318 {
eric@30 319 last_output_context->file_attributes.title = title;
eric@30 320 }
eric@30 321
eric@30 322 void output_set_subject (char *subject)
eric@30 323 {
eric@30 324 last_output_context->file_attributes.subject = subject;
eric@30 325 }
eric@30 326
eric@30 327 void output_set_keywords (char *keywords)
eric@30 328 {
eric@30 329 last_output_context->file_attributes.keywords = keywords;
eric@30 330 }
eric@30 331
eric@20 332 void output_set_bookmark (char *name)
eric@16 333 {
eric@20 334 bookmark_t *new_bookmark;
eric@20 335
eric@20 336 /* As the language is defined (parser.y), a bookmark can only appear
eric@20 337 at the beginning of a context! */
eric@20 338 if (last_output_context->page_count)
eric@20 339 {
eric@20 340 fprintf (stderr, "internal error, bookmark not at beginning of context\n");
eric@20 341 exit (2);
eric@20 342 }
eric@20 343
eric@20 344 new_bookmark = calloc (1, sizeof (bookmark_t));
eric@20 345 if (! new_bookmark)
eric@20 346 {
eric@20 347 fprintf (stderr, "failed to calloc a bookmark\n");
eric@20 348 return;
eric@20 349 }
eric@20 350
eric@24 351 new_bookmark->level = bookmark_level;
eric@20 352 new_bookmark->name = name;
eric@20 353 if (last_output_context->first_bookmark)
eric@20 354 last_output_context->last_bookmark->next = new_bookmark;
eric@20 355 else
eric@20 356 last_output_context->first_bookmark = new_bookmark;
eric@20 357 last_output_context->last_bookmark = new_bookmark;
eric@20 358 }
eric@20 359
eric@25 360 void output_set_page_label (page_label_t label)
eric@20 361 {
eric@20 362 output_clone ();
eric@25 363 last_output_context->has_page_label = 1;
eric@25 364 last_output_context->page_label = label;
eric@20 365 }
eric@20 366
eric@22 367 static void increment_output_page_count (int count)
eric@20 368 {
eric@20 369 output_context_t *context;
eric@20 370
eric@20 371 for (context = last_output_context; context; context = context->parent)
eric@20 372 context->page_count += count;
eric@20 373 }
eric@20 374
eric@21 375
eric@20 376 void output_pages (range_t range)
eric@20 377 {
eric@20 378 output_page_t *new_page;
eric@21 379 output_context_t *context;
eric@20 380 int count = ((range.last - range.first) + 1);
eric@20 381
eric@19 382 #ifdef SEMANTIC_DEBUG
eric@20 383 if (range.first == range.last)
eric@20 384 SDBG(("page %d\n", range.first));
eric@16 385 else
eric@20 386 SDBG(("pages %d..%d\n", range.first, range.last));
eric@19 387 #endif /* SEMANTIC_DEBUG */
eric@20 388
eric@20 389 new_page = calloc (1, sizeof (output_page_t));
eric@20 390 if (! new_page)
eric@20 391 {
eric@20 392 fprintf (stderr, "failed to malloc an output page struct\n");
eric@20 393 return;
eric@20 394 }
eric@20 395 if (first_output_page)
eric@20 396 {
eric@20 397 last_output_page->next = new_page;
eric@20 398 last_output_page = new_page;
eric@20 399 }
eric@20 400 else
eric@20 401 {
eric@20 402 first_output_page = last_output_page = new_page;
eric@20 403 }
eric@20 404 new_page->range = range;
eric@20 405 new_page->output_context = last_output_context;
eric@20 406
eric@21 407 /* transfer bookmarks from context(s) to page */
eric@21 408 for (context = last_output_context; context; context = context->parent)
eric@21 409 if (context->first_bookmark)
eric@21 410 {
eric@21 411 context->last_bookmark->next = new_page->bookmark_list;
eric@21 412 new_page->bookmark_list = context->first_bookmark;
eric@21 413 context->first_bookmark = NULL;
eric@21 414 context->last_bookmark = NULL;
eric@21 415 }
eric@20 416
eric@20 417 increment_output_page_count (count);
eric@16 418 }
eric@16 419
eric@16 420
eric@16 421 void yyerror (char *s)
eric@16 422 {
eric@16 423 fprintf (stderr, "%d: %s\n", line, s);
eric@16 424 }
eric@16 425
eric@16 426
eric@22 427 static char *get_input_file (input_context_t *context)
eric@20 428 {
eric@20 429 for (; context; context = context->parent)
eric@20 430 if (context->input_file)
eric@20 431 return (context->input_file);
eric@20 432 fprintf (stderr, "no input file name found\n");
eric@20 433 exit (2);
eric@20 434 }
eric@20 435
eric@48 436 static bool get_input_rotation (input_context_t *context,
eric@48 437 input_modifier_type_t type,
eric@48 438 int *rotation)
eric@20 439 {
eric@20 440 for (; context; context = context->parent)
eric@20 441 {
eric@20 442 if (context->modifiers [type].has_rotation)
eric@32 443 {
eric@32 444 * rotation = context->modifiers [type].rotation;
eric@32 445 return (1);
eric@32 446 }
eric@20 447 if (context->modifiers [INPUT_MODIFIER_ALL].has_rotation)
eric@32 448 {
eric@32 449 * rotation = context->modifiers [INPUT_MODIFIER_ALL].rotation;
eric@32 450 return (1);
eric@32 451 }
eric@32 452 }
eric@32 453 return (0); /* default */
eric@32 454 }
eric@32 455
eric@48 456 static bool get_input_page_size (input_context_t *context,
eric@48 457 input_modifier_type_t type,
eric@48 458 page_size_t *page_size)
eric@32 459 {
eric@32 460 for (; context; context = context->parent)
eric@32 461 {
eric@32 462 if (context->modifiers [type].has_page_size)
eric@32 463 {
eric@32 464 * page_size = context->modifiers [type].page_size;
eric@32 465 return (1);
eric@32 466 }
eric@32 467 if (context->modifiers [INPUT_MODIFIER_ALL].has_page_size)
eric@32 468 {
eric@32 469 * page_size = context->modifiers [INPUT_MODIFIER_ALL].page_size;
eric@32 470 return (1);
eric@32 471 }
eric@20 472 }
eric@20 473 return (0); /* default */
eric@20 474 }
eric@20 475
eric@22 476 static char *get_output_file (output_context_t *context)
eric@20 477 {
eric@20 478 for (; context; context = context->parent)
eric@20 479 if (context->output_file)
eric@20 480 return (context->output_file);
eric@30 481 fprintf (stderr, "no output file found\n");
eric@30 482 exit (2);
eric@30 483 }
eric@30 484
eric@30 485 static pdf_file_attributes_t *get_output_file_attributes (output_context_t *context)
eric@30 486 {
eric@30 487 for (; context; context = context->parent)
eric@30 488 if (context->output_file)
eric@30 489 return (& context->file_attributes);
eric@30 490 fprintf (stderr, "no output file found\n");
eric@20 491 exit (2);
eric@20 492 }
eric@20 493
eric@25 494 static page_label_t *get_output_page_label (output_context_t *context)
eric@20 495 {
eric@20 496 for (; context; context = context->parent)
eric@25 497 if (context->has_page_label)
eric@25 498 return (& context->page_label);
eric@20 499 return (NULL); /* default */
eric@20 500 }
eric@20 501
eric@20 502
eric@20 503 #ifdef SEMANTIC_DEBUG
eric@20 504 void dump_input_tree (void)
eric@20 505 {
eric@20 506 input_image_t *image;
eric@20 507 int i;
eric@20 508
eric@20 509 printf ("input images:\n");
eric@20 510 for (image = first_input_image; image; image = image->next)
eric@20 511 for (i = image->range.first; i <= image->range.last; i++)
eric@20 512 {
eric@20 513 input_modifier_type_t parity = (i % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
eric@48 514 bool has_rotation, has_page_size;
eric@32 515 int rotation;
eric@32 516 page_size_t page_size;
eric@32 517
eric@32 518 has_rotation = get_input_rotation (image->input_context,
eric@32 519 parity,
eric@32 520 & rotation);
eric@32 521 has_page_size = get_input_page_size (image->input_context,
eric@32 522 parity,
eric@32 523 & page_size);
eric@32 524 printf ("file '%s' image %d",
eric@20 525 get_input_file (image->input_context),
eric@32 526 i);
eric@32 527 if (has_rotation)
eric@32 528 printf (" rotation %d", rotation);
eric@32 529 if (has_page_size)
eric@32 530 printf (" size %f, %f", page_size.width, page_size.height);
eric@32 531 printf ("\n");
eric@45 532 printf ("context: %08x\n", image->input_context);
eric@20 533 }
eric@20 534 }
eric@20 535
eric@20 536 void dump_output_tree (void)
eric@20 537 {
eric@20 538 int i;
eric@20 539 output_page_t *page;
eric@20 540 bookmark_t *bookmark;
eric@20 541
eric@20 542 printf ("output pages:\n");
eric@20 543 for (page = first_output_page; page; page = page->next)
eric@20 544 {
eric@20 545 if (page->bookmark_list)
eric@20 546 {
eric@20 547 for (bookmark = page->bookmark_list; bookmark; bookmark = bookmark->next)
eric@25 548 printf ("bookmark %d \"%s\"\n", bookmark->level, bookmark->name);
eric@20 549 }
eric@20 550 for (i = page->range.first; i <= page->range.last; i++)
eric@20 551 {
eric@25 552 page_label_t *label = get_output_page_label (page->output_context);
eric@25 553 printf ("file \"%s\" ", get_output_file (page->output_context));
eric@25 554 if (label)
eric@25 555 {
eric@25 556 printf ("label ");
eric@25 557 if (label->prefix)
eric@25 558 printf ("\"%s\" ", label->prefix);
eric@25 559 if (label->style)
eric@25 560 printf ("'%c' ", label->style);
eric@25 561 }
eric@20 562 printf ("page %d\n", i);
eric@20 563 }
eric@20 564 }
eric@20 565 }
eric@20 566 #endif /* SEMANTIC_DEBUG */
eric@20 567
eric@25 568
eric@25 569 static inline int range_count (range_t range)
eric@25 570 {
eric@25 571 return ((range.last - range.first) + 1);
eric@25 572 }
eric@25 573
eric@25 574
eric@48 575 bool parse_spec_file (char *fn)
eric@16 576 {
eric@48 577 bool result = 0;
eric@16 578
eric@16 579 yyin = fopen (fn, "r");
eric@16 580 if (! yyin)
eric@16 581 {
eric@16 582 fprintf (stderr, "can't open spec file '%s'\n", fn);
eric@16 583 goto fail;
eric@16 584 }
eric@16 585
eric@16 586 line = 1;
eric@16 587
eric@20 588 input_push_context (); /* create root input context */
eric@20 589 input_push_context (); /* create inital input context */
eric@20 590
eric@20 591 output_push_context (); /* create root output context */
eric@18 592 output_push_context (); /* create initial output context */
eric@18 593
eric@16 594 yyparse ();
eric@16 595
eric@20 596 if (first_input_context->image_count != first_output_context->page_count)
eric@18 597 {
eric@20 598 fprintf (stderr, "input image count %d != output page count %d\n",
eric@20 599 first_input_context->image_count,
eric@20 600 first_output_context->page_count);
eric@18 601 goto fail;
eric@18 602 }
eric@18 603
eric@20 604 fprintf (stderr, "%d pages specified\n", first_input_context->image_count);
eric@18 605
eric@16 606 result = 1;
eric@16 607
eric@20 608 #ifdef SEMANTIC_DEBUG
eric@20 609 dump_input_tree ();
eric@20 610 dump_output_tree ();
eric@20 611 #endif /* SEMANTIC_DEBUG */
eric@20 612
eric@16 613 fail:
eric@16 614 if (yyin)
eric@16 615 fclose (yyin);
eric@16 616
eric@16 617 return (result);
eric@16 618 }
eric@26 619
eric@26 620
eric@48 621 bool process_specs (void)
eric@26 622 {
eric@26 623 input_image_t *image = NULL;
eric@26 624 output_page_t *page = NULL;
eric@26 625 int i = 0;
eric@26 626 int p = 0;
eric@26 627 int page_index = 0;
eric@26 628 input_attributes_t input_attributes;
eric@26 629 input_modifier_type_t parity;
eric@26 630 page_label_t *page_label;
eric@26 631
eric@26 632 for (;;)
eric@26 633 {
eric@26 634 if ((! image) || (i >= range_count (image->range)))
eric@26 635 {
eric@26 636 if (image)
eric@26 637 image = image->next;
eric@26 638 else
eric@26 639 image = first_input_image;
eric@26 640 if (! image)
eric@26 641 return (0);
eric@26 642 i = 0;
eric@26 643 if (! open_tiff_input_file (get_input_file (image->input_context)))
eric@26 644 return (0);
eric@26 645 }
eric@26 646
eric@26 647 if ((! page) || (p >= range_count (page->range)))
eric@26 648 {
eric@26 649 if (page)
eric@26 650 page = page->next;
eric@26 651 else
eric@26 652 page = first_output_page;
eric@26 653 p = 0;
eric@30 654 if (! open_pdf_output_file (get_output_file (page->output_context),
eric@30 655 get_output_file_attributes (page->output_context)))
eric@26 656 return (0);
eric@26 657 page_label = get_output_page_label (page->output_context);
eric@26 658 process_page_numbers (page_index,
eric@26 659 range_count (page->range),
eric@26 660 page->range.first,
eric@26 661 page_label);
eric@26 662 }
eric@26 663
eric@26 664 parity = ((image->range.first + i) % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
eric@26 665
eric@26 666 memset (& input_attributes, 0, sizeof (input_attributes));
eric@32 667
eric@32 668 input_attributes.rotation = 0;
eric@32 669 input_attributes.has_rotation = get_input_rotation (image->input_context,
eric@32 670 parity,
eric@32 671 & input_attributes.rotation);
eric@32 672
eric@32 673 input_attributes.has_page_size = get_input_page_size (image->input_context,
eric@32 674 parity,
eric@32 675 & input_attributes.page_size);
eric@26 676
eric@26 677 process_page (image->range.first + i,
eric@26 678 input_attributes,
eric@26 679 page->bookmark_list);
eric@26 680 i++;
eric@26 681 p++;
eric@26 682 page_index++;
eric@26 683 }
eric@26 684
eric@26 685 return (1);
eric@26 686 }