diff --git a/parser.y b/parser.y index 759efd3..1125e76 100644 --- a/parser.y +++ b/parser.y @@ -8,8 +8,8 @@ int integer; double fp; char *string; - struct { double width; double height; } size; - struct { int first; int last; } range; + page_size_t size; + range_t range; } %token INTEGER diff --git a/scanner.l b/scanner.l index 81abb0c..1227f6e 100644 --- a/scanner.l +++ b/scanner.l @@ -1,5 +1,5 @@ /* -$Id: scanner.l,v 1.9 2001/12/30 08:29:50 eric Exp $ +$Id: scanner.l,v 1.10 2001/12/30 09:09:08 eric Exp $ */ %option case-insensitive @@ -8,9 +8,9 @@ $Id: scanner.l,v 1.9 2001/12/30 08:29:50 eric Exp $ %{ #include #include -#include "parser.tab.h" #include "type.h" #include "semantics.h" +#include "parser.tab.h" #ifdef SCANNER_DEBUG #define LDBG(x) printf x diff --git a/semantics.c b/semantics.c index 5186a66..08adb36 100644 --- a/semantics.c +++ b/semantics.c @@ -1,24 +1,55 @@ +#include +#include #include #include "type.h" -#include "parser.tab.h" #include "semantics.h" +#include "parser.tab.h" FILE *yyin; int line; /* line number in spec file */ -int input_count; /* total input pages in spec */ -int output_count; /* total output pages in spec */ +int input_page_count; /* total input pages in spec */ +int output_page_count; /* total output pages in spec */ + + +input_context_t *current_input_context; void input_push_context (input_context_type_t type) { + input_context_t *new_input_context; + + new_input_context = malloc (sizeof (input_context_t)); + if (! new_input_context) + { + fprintf (stderr, "failed to calloc an input context\n"); + return; + } + + if (current_input_context) + { + memcpy (new_input_context, current_input_context, sizeof (input_context_t)); + new_input_context->page_count = 0; + } + else + memset (new_input_context, 0, sizeof (input_context_t)); + + new_input_context->parent_input_context = current_input_context; + current_input_context = new_input_context; }; void input_pop_context (void) { + if (! current_input_context) + { + fprintf (stderr, "failed to pop an input context\n"); + return; + } + + current_input_context = current_input_context->parent_input_context; }; void input_set_file (char *name) @@ -27,20 +58,25 @@ void input_set_file (char *name) void input_images (int first, int last) { - input_count += ((last - first) + 1); + input_page_count += ((last - first) + 1); if (first == last) printf ("image %d\n", first); else - printf ("iamges %d..%d\n", first, last); + printf ("images %d..%d\n", first, last); } + +void output_push_context (void) +{ +}; + void output_set_file (char *name) { }; void output_pages (int first, int last) { - output_count += ((last - first) + 1); + output_page_count += ((last - first) + 1); if (first == last) printf ("page %d\n", first); else @@ -67,8 +103,20 @@ boolean parse_spec_file (char *fn) line = 1; + input_push_context (INPUT_CONTEXT_ALL); /* create initial input context */ + output_push_context (); /* create initial output context */ + yyparse (); + if (input_page_count != output_page_count) + { + fprintf (stderr, "input page count %d != output page count %d\n", + input_page_count, output_page_count); + goto fail; + } + + fprintf (stderr, "%d pages specified\n", input_page_count); + result = 1; fail: diff --git a/semantics.h b/semantics.h index ffb40d4..f7e583f 100644 --- a/semantics.h +++ b/semantics.h @@ -1,3 +1,23 @@ +typedef struct +{ + double width; + double height; +} page_size_t; + +typedef struct +{ + int first; + int last; + } range_t; + +typedef struct +{ + double left; + double right; + double top; + double bottom; +} crop_t; + typedef enum { INPUT_CONTEXT_ALL, @@ -6,11 +26,44 @@ typedef enum } input_context_type_t; +typedef struct +{ + boolean has_size; + page_size_t size; + + boolean has_rotation; + int rotation; + + boolean has_crop; + crop_t crop; +} input_modifiers_t; + + +typedef enum +{ + INPUT_MODIFIER_ALL, + INPUT_MODIFIER_ODD, + INPUT_MODIFIER_EVEN, + INPUT_MODIFIER_TYPE_COUNT /* must be last */ +} input_modifier_type_t; + + +typedef struct input_context_t +{ + struct input_context_t *parent_input_context; + + int page_count; /* how many pages reference this context, + including those from subcontexts */ + + input_modifiers_t modifiers [INPUT_MODIFIER_TYPE_COUNT]; +} input_context_t; + + extern int line; /* line number in spec file */ -extern int input_count; /* total input pages in spec */ -extern int output_count; /* total output pages in spec */ +extern int input_page_count; /* total input pages in spec */ +extern int output_page_count; /* total output pages in spec */ boolean parse_spec_file (char *fn); diff --git a/t2p.c b/t2p.c index 6d61b11..8b91c2d 100644 --- a/t2p.c +++ b/t2p.c @@ -1,7 +1,7 @@ /* * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 * Main program - * $Id: t2p.c,v 1.4 2001/12/30 08:29:50 eric Exp $ + * $Id: t2p.c,v 1.5 2001/12/30 09:09:08 eric Exp $ * Copyright 2001 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -28,8 +28,8 @@ #include "type.h" #include "bitblt.h" -#include "parser.tab.h" #include "semantics.h" +#include "parser.tab.h" #include "tiff2pdf.h" diff --git a/tumble.c b/tumble.c index 0cd9b33..d0c7332 100644 --- a/tumble.c +++ b/tumble.c @@ -1,7 +1,7 @@ /* * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 * Main program - * $Id: tumble.c,v 1.4 2001/12/30 08:29:50 eric Exp $ + * $Id: tumble.c,v 1.5 2001/12/30 09:09:08 eric Exp $ * Copyright 2001 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -28,8 +28,8 @@ #include "type.h" #include "bitblt.h" -#include "parser.tab.h" #include "semantics.h" +#include "parser.tab.h" #include "tiff2pdf.h"