Sun, 30 Dec 2001 17:09:08 +0000
*** empty log message ***
parser.y | file | annotate | diff | revisions | |
scanner.l | file | annotate | diff | revisions | |
semantics.c | file | annotate | diff | revisions | |
semantics.h | file | annotate | diff | revisions | |
t2p.c | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions |
1.1 --- a/parser.y Sun Dec 30 16:29:50 2001 +0000 1.2 +++ b/parser.y Sun Dec 30 17:09:08 2001 +0000 1.3 @@ -8,8 +8,8 @@ 1.4 int integer; 1.5 double fp; 1.6 char *string; 1.7 - struct { double width; double height; } size; 1.8 - struct { int first; int last; } range; 1.9 + page_size_t size; 1.10 + range_t range; 1.11 } 1.12 1.13 %token <integer> INTEGER
2.1 --- a/scanner.l Sun Dec 30 16:29:50 2001 +0000 2.2 +++ b/scanner.l Sun Dec 30 17:09:08 2001 +0000 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 -$Id: scanner.l,v 1.9 2001/12/30 08:29:50 eric Exp $ 2.6 +$Id: scanner.l,v 1.10 2001/12/30 09:09:08 eric Exp $ 2.7 */ 2.8 2.9 %option case-insensitive 2.10 @@ -8,9 +8,9 @@ 2.11 %{ 2.12 #include <stdio.h> 2.13 #include <string.h> 2.14 -#include "parser.tab.h" 2.15 #include "type.h" 2.16 #include "semantics.h" 2.17 +#include "parser.tab.h" 2.18 2.19 #ifdef SCANNER_DEBUG 2.20 #define LDBG(x) printf x
3.1 --- a/semantics.c Sun Dec 30 16:29:50 2001 +0000 3.2 +++ b/semantics.c Sun Dec 30 17:09:08 2001 +0000 3.3 @@ -1,24 +1,55 @@ 3.4 +#include <stdlib.h> 3.5 +#include <string.h> 3.6 #include <stdio.h> 3.7 3.8 #include "type.h" 3.9 +#include "semantics.h" 3.10 #include "parser.tab.h" 3.11 -#include "semantics.h" 3.12 3.13 3.14 FILE *yyin; 3.15 int line; /* line number in spec file */ 3.16 3.17 3.18 -int input_count; /* total input pages in spec */ 3.19 -int output_count; /* total output pages in spec */ 3.20 +int input_page_count; /* total input pages in spec */ 3.21 +int output_page_count; /* total output pages in spec */ 3.22 + 3.23 + 3.24 +input_context_t *current_input_context; 3.25 3.26 3.27 void input_push_context (input_context_type_t type) 3.28 { 3.29 + input_context_t *new_input_context; 3.30 + 3.31 + new_input_context = malloc (sizeof (input_context_t)); 3.32 + if (! new_input_context) 3.33 + { 3.34 + fprintf (stderr, "failed to calloc an input context\n"); 3.35 + return; 3.36 + } 3.37 + 3.38 + if (current_input_context) 3.39 + { 3.40 + memcpy (new_input_context, current_input_context, sizeof (input_context_t)); 3.41 + new_input_context->page_count = 0; 3.42 + } 3.43 + else 3.44 + memset (new_input_context, 0, sizeof (input_context_t)); 3.45 + 3.46 + new_input_context->parent_input_context = current_input_context; 3.47 + current_input_context = new_input_context; 3.48 }; 3.49 3.50 void input_pop_context (void) 3.51 { 3.52 + if (! current_input_context) 3.53 + { 3.54 + fprintf (stderr, "failed to pop an input context\n"); 3.55 + return; 3.56 + } 3.57 + 3.58 + current_input_context = current_input_context->parent_input_context; 3.59 }; 3.60 3.61 void input_set_file (char *name) 3.62 @@ -27,20 +58,25 @@ 3.63 3.64 void input_images (int first, int last) 3.65 { 3.66 - input_count += ((last - first) + 1); 3.67 + input_page_count += ((last - first) + 1); 3.68 if (first == last) 3.69 printf ("image %d\n", first); 3.70 else 3.71 - printf ("iamges %d..%d\n", first, last); 3.72 + printf ("images %d..%d\n", first, last); 3.73 } 3.74 3.75 + 3.76 +void output_push_context (void) 3.77 +{ 3.78 +}; 3.79 + 3.80 void output_set_file (char *name) 3.81 { 3.82 }; 3.83 3.84 void output_pages (int first, int last) 3.85 { 3.86 - output_count += ((last - first) + 1); 3.87 + output_page_count += ((last - first) + 1); 3.88 if (first == last) 3.89 printf ("page %d\n", first); 3.90 else 3.91 @@ -67,8 +103,20 @@ 3.92 3.93 line = 1; 3.94 3.95 + input_push_context (INPUT_CONTEXT_ALL); /* create initial input context */ 3.96 + output_push_context (); /* create initial output context */ 3.97 + 3.98 yyparse (); 3.99 3.100 + if (input_page_count != output_page_count) 3.101 + { 3.102 + fprintf (stderr, "input page count %d != output page count %d\n", 3.103 + input_page_count, output_page_count); 3.104 + goto fail; 3.105 + } 3.106 + 3.107 + fprintf (stderr, "%d pages specified\n", input_page_count); 3.108 + 3.109 result = 1; 3.110 3.111 fail:
4.1 --- a/semantics.h Sun Dec 30 16:29:50 2001 +0000 4.2 +++ b/semantics.h Sun Dec 30 17:09:08 2001 +0000 4.3 @@ -1,3 +1,23 @@ 4.4 +typedef struct 4.5 +{ 4.6 + double width; 4.7 + double height; 4.8 +} page_size_t; 4.9 + 4.10 +typedef struct 4.11 +{ 4.12 + int first; 4.13 + int last; 4.14 + } range_t; 4.15 + 4.16 +typedef struct 4.17 +{ 4.18 + double left; 4.19 + double right; 4.20 + double top; 4.21 + double bottom; 4.22 +} crop_t; 4.23 + 4.24 typedef enum 4.25 { 4.26 INPUT_CONTEXT_ALL, 4.27 @@ -6,11 +26,44 @@ 4.28 } input_context_type_t; 4.29 4.30 4.31 +typedef struct 4.32 +{ 4.33 + boolean has_size; 4.34 + page_size_t size; 4.35 + 4.36 + boolean has_rotation; 4.37 + int rotation; 4.38 + 4.39 + boolean has_crop; 4.40 + crop_t crop; 4.41 +} input_modifiers_t; 4.42 + 4.43 + 4.44 +typedef enum 4.45 +{ 4.46 + INPUT_MODIFIER_ALL, 4.47 + INPUT_MODIFIER_ODD, 4.48 + INPUT_MODIFIER_EVEN, 4.49 + INPUT_MODIFIER_TYPE_COUNT /* must be last */ 4.50 +} input_modifier_type_t; 4.51 + 4.52 + 4.53 +typedef struct input_context_t 4.54 +{ 4.55 + struct input_context_t *parent_input_context; 4.56 + 4.57 + int page_count; /* how many pages reference this context, 4.58 + including those from subcontexts */ 4.59 + 4.60 + input_modifiers_t modifiers [INPUT_MODIFIER_TYPE_COUNT]; 4.61 +} input_context_t; 4.62 + 4.63 + 4.64 extern int line; /* line number in spec file */ 4.65 4.66 4.67 -extern int input_count; /* total input pages in spec */ 4.68 -extern int output_count; /* total output pages in spec */ 4.69 +extern int input_page_count; /* total input pages in spec */ 4.70 +extern int output_page_count; /* total output pages in spec */ 4.71 4.72 4.73 boolean parse_spec_file (char *fn);
5.1 --- a/t2p.c Sun Dec 30 16:29:50 2001 +0000 5.2 +++ b/t2p.c Sun Dec 30 17:09:08 2001 +0000 5.3 @@ -1,7 +1,7 @@ 5.4 /* 5.5 * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 5.6 * Main program 5.7 - * $Id: t2p.c,v 1.4 2001/12/30 08:29:50 eric Exp $ 5.8 + * $Id: t2p.c,v 1.5 2001/12/30 09:09:08 eric Exp $ 5.9 * Copyright 2001 Eric Smith <eric@brouhaha.com> 5.10 * 5.11 * This program is free software; you can redistribute it and/or modify 5.12 @@ -28,8 +28,8 @@ 5.13 5.14 #include "type.h" 5.15 #include "bitblt.h" 5.16 +#include "semantics.h" 5.17 #include "parser.tab.h" 5.18 -#include "semantics.h" 5.19 #include "tiff2pdf.h" 5.20 5.21
6.1 --- a/tumble.c Sun Dec 30 16:29:50 2001 +0000 6.2 +++ b/tumble.c Sun Dec 30 17:09:08 2001 +0000 6.3 @@ -1,7 +1,7 @@ 6.4 /* 6.5 * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 6.6 * Main program 6.7 - * $Id: tumble.c,v 1.4 2001/12/30 08:29:50 eric Exp $ 6.8 + * $Id: tumble.c,v 1.5 2001/12/30 09:09:08 eric Exp $ 6.9 * Copyright 2001 Eric Smith <eric@brouhaha.com> 6.10 * 6.11 * This program is free software; you can redistribute it and/or modify 6.12 @@ -28,8 +28,8 @@ 6.13 6.14 #include "type.h" 6.15 #include "bitblt.h" 6.16 +#include "semantics.h" 6.17 #include "parser.tab.h" 6.18 -#include "semantics.h" 6.19 #include "tiff2pdf.h" 6.20 6.21