From 54a3bf9bbeffbd6f67ffb5166f1bbb6ca44bd412 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Mon, 31 Dec 2001 02:33:50 +0000 Subject: [PATCH] *** empty log message *** --- parser.y | 24 ++++++++++-------------- semantics.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ semantics.h | 12 +++--------- 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/parser.y b/parser.y index 1125e76..ef9d410 100644 --- a/parser.y +++ b/parser.y @@ -77,16 +77,13 @@ input_file_clause: FILE_KEYWORD STRING ';' { input_set_file ($2) } ; image_clause: - IMAGE INTEGER ';' { input_images ($2, $2); } - | IMAGE INTEGER modifier_clause_list ';' { input_images ($2, $2); } ; + IMAGE INTEGER ';' { input_images ($2, $2); } ; images_clause: - IMAGES image_ranges ';' - | IMAGES image_ranges modifier_clause_list ';' - | IMAGES image_ranges part_clauses ';' ; + IMAGES image_ranges ';' ; rotate_clause: - ROTATE INTEGER ';' ; + ROTATE INTEGER ';' { input_set_rotation ($2) }; unit: /* empty */ /* default to INCH */ { $$ = 25.4; } @@ -124,20 +121,19 @@ modifier_clauses: modifier_clause_list: '{' modifier_clauses '}' ; -part: - EVEN | ODD | ALL ; - part_clause: - part modifier_clause_list; - -part_clauses: - part_clause - | part_clauses part_clause; + ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); } + modifier_clause_list ';' + { input_set_modifier_context (INPUT_MODIFIER_ALL); } + | EVEN { input_set_modifier_context (INPUT_MODIFIER_ODD); } + modifier_clause_list ';' + { input_set_modifier_context (INPUT_MODIFIER_ALL); } ; input_clause: input_file_clause | image_clause | images_clause + | part_clause | modifier_clause | input_clause_list ; diff --git a/semantics.c b/semantics.c index 08adb36..7660d7f 100644 --- a/semantics.c +++ b/semantics.c @@ -7,6 +7,14 @@ #include "parser.tab.h" +#define SEMANTIC_DEBUG +#ifdef SEMANTIC_DEBUG +#define SDBG(x) printf x +#else +#define SDBG(x) +#endif + + FILE *yyin; int line; /* line number in spec file */ @@ -16,9 +24,10 @@ int output_page_count; /* total output pages in spec */ input_context_t *current_input_context; +input_modifier_type_t current_modifier_context; -void input_push_context (input_context_type_t type) +void input_push_context (void) { input_context_t *new_input_context; @@ -52,17 +61,42 @@ void input_pop_context (void) current_input_context = current_input_context->parent_input_context; }; +void input_set_modifier_context (input_modifier_type_t type) +{ + current_modifier_context = type; +#ifdef SEMANTIC_DEBUG + SDBG(("modifier type ")); + switch (type) + { + case INPUT_MODIFIER_ALL: SDBG(("all")); break; + case INPUT_MODIFIER_ODD: SDBG(("odd")); break; + case INPUT_MODIFIER_EVEN: SDBG(("even")); break; + default: SDBG(("unknown %d", type)); + } + SDBG(("\n")); +#endif /* SEMANTIC_DEBUG */ +} + void input_set_file (char *name) { }; +void input_set_rotation (int rotation) +{ + current_input_context->modifiers [current_modifier_context].has_rotation = 1; + current_input_context->modifiers [current_modifier_context].rotation = rotation; + SDBG(("rotation %d\n", rotation)); +} + void input_images (int first, int last) { input_page_count += ((last - first) + 1); +#ifdef SEMANTIC_DEBUG if (first == last) - printf ("image %d\n", first); + SDBG(("image %d\n", first)); else - printf ("images %d..%d\n", first, last); + SDBG(("images %d..%d\n", first, last)); +#endif /* SEMANTIC_DEBUG */ } @@ -77,10 +111,12 @@ void output_set_file (char *name) void output_pages (int first, int last) { output_page_count += ((last - first) + 1); +#ifdef SEMANTIC_DEBUG if (first == last) - printf ("page %d\n", first); + SDBG(("page %d\n", first)); else - printf ("pages %d..%d\n", first, last); + SDBG(("pages %d..%d\n", first, last)); +#endif /* SEMANTIC_DEBUG */ } @@ -103,7 +139,7 @@ boolean parse_spec_file (char *fn) line = 1; - input_push_context (INPUT_CONTEXT_ALL); /* create initial input context */ + input_push_context (); /* create initial input context */ output_push_context (); /* create initial output context */ yyparse (); diff --git a/semantics.h b/semantics.h index f7e583f..c91c38e 100644 --- a/semantics.h +++ b/semantics.h @@ -18,14 +18,6 @@ typedef struct double bottom; } crop_t; -typedef enum -{ - INPUT_CONTEXT_ALL, - INPUT_CONTEXT_ODD, - INPUT_CONTEXT_EVEN -} input_context_type_t; - - typedef struct { boolean has_size; @@ -70,9 +62,11 @@ boolean parse_spec_file (char *fn); /* semantic routines for input statements */ -void input_push_context (input_context_type_t type); +void input_push_context (void); void input_pop_context (void); +void input_set_modifier_context (input_modifier_type_t type); void input_set_file (char *name); +void input_set_rotation (int rotation); void input_images (int first, int last); /* semantic routines for output statements */