Mon, 31 Dec 2001 02:33:50 +0000
*** empty log message ***
eric@18 | 1 | #include <stdlib.h> |
eric@18 | 2 | #include <string.h> |
eric@16 | 3 | #include <stdio.h> |
eric@16 | 4 | |
eric@16 | 5 | #include "type.h" |
eric@18 | 6 | #include "semantics.h" |
eric@16 | 7 | #include "parser.tab.h" |
eric@16 | 8 | |
eric@16 | 9 | |
eric@19 | 10 | #define SEMANTIC_DEBUG |
eric@19 | 11 | #ifdef SEMANTIC_DEBUG |
eric@19 | 12 | #define SDBG(x) printf x |
eric@19 | 13 | #else |
eric@19 | 14 | #define SDBG(x) |
eric@19 | 15 | #endif |
eric@19 | 16 | |
eric@19 | 17 | |
eric@16 | 18 | FILE *yyin; |
eric@16 | 19 | int line; /* line number in spec file */ |
eric@16 | 20 | |
eric@16 | 21 | |
eric@18 | 22 | int input_page_count; /* total input pages in spec */ |
eric@18 | 23 | int output_page_count; /* total output pages in spec */ |
eric@18 | 24 | |
eric@18 | 25 | |
eric@18 | 26 | input_context_t *current_input_context; |
eric@19 | 27 | input_modifier_type_t current_modifier_context; |
eric@16 | 28 | |
eric@16 | 29 | |
eric@19 | 30 | void input_push_context (void) |
eric@16 | 31 | { |
eric@18 | 32 | input_context_t *new_input_context; |
eric@18 | 33 | |
eric@18 | 34 | new_input_context = malloc (sizeof (input_context_t)); |
eric@18 | 35 | if (! new_input_context) |
eric@18 | 36 | { |
eric@18 | 37 | fprintf (stderr, "failed to calloc an input context\n"); |
eric@18 | 38 | return; |
eric@18 | 39 | } |
eric@18 | 40 | |
eric@18 | 41 | if (current_input_context) |
eric@18 | 42 | { |
eric@18 | 43 | memcpy (new_input_context, current_input_context, sizeof (input_context_t)); |
eric@18 | 44 | new_input_context->page_count = 0; |
eric@18 | 45 | } |
eric@18 | 46 | else |
eric@18 | 47 | memset (new_input_context, 0, sizeof (input_context_t)); |
eric@18 | 48 | |
eric@18 | 49 | new_input_context->parent_input_context = current_input_context; |
eric@18 | 50 | current_input_context = new_input_context; |
eric@16 | 51 | }; |
eric@16 | 52 | |
eric@16 | 53 | void input_pop_context (void) |
eric@16 | 54 | { |
eric@18 | 55 | if (! current_input_context) |
eric@18 | 56 | { |
eric@18 | 57 | fprintf (stderr, "failed to pop an input context\n"); |
eric@18 | 58 | return; |
eric@18 | 59 | } |
eric@18 | 60 | |
eric@18 | 61 | current_input_context = current_input_context->parent_input_context; |
eric@16 | 62 | }; |
eric@16 | 63 | |
eric@19 | 64 | void input_set_modifier_context (input_modifier_type_t type) |
eric@19 | 65 | { |
eric@19 | 66 | current_modifier_context = type; |
eric@19 | 67 | #ifdef SEMANTIC_DEBUG |
eric@19 | 68 | SDBG(("modifier type ")); |
eric@19 | 69 | switch (type) |
eric@19 | 70 | { |
eric@19 | 71 | case INPUT_MODIFIER_ALL: SDBG(("all")); break; |
eric@19 | 72 | case INPUT_MODIFIER_ODD: SDBG(("odd")); break; |
eric@19 | 73 | case INPUT_MODIFIER_EVEN: SDBG(("even")); break; |
eric@19 | 74 | default: SDBG(("unknown %d", type)); |
eric@19 | 75 | } |
eric@19 | 76 | SDBG(("\n")); |
eric@19 | 77 | #endif /* SEMANTIC_DEBUG */ |
eric@19 | 78 | } |
eric@19 | 79 | |
eric@16 | 80 | void input_set_file (char *name) |
eric@16 | 81 | { |
eric@16 | 82 | }; |
eric@16 | 83 | |
eric@19 | 84 | void input_set_rotation (int rotation) |
eric@19 | 85 | { |
eric@19 | 86 | current_input_context->modifiers [current_modifier_context].has_rotation = 1; |
eric@19 | 87 | current_input_context->modifiers [current_modifier_context].rotation = rotation; |
eric@19 | 88 | SDBG(("rotation %d\n", rotation)); |
eric@19 | 89 | } |
eric@19 | 90 | |
eric@16 | 91 | void input_images (int first, int last) |
eric@16 | 92 | { |
eric@18 | 93 | input_page_count += ((last - first) + 1); |
eric@19 | 94 | #ifdef SEMANTIC_DEBUG |
eric@16 | 95 | if (first == last) |
eric@19 | 96 | SDBG(("image %d\n", first)); |
eric@16 | 97 | else |
eric@19 | 98 | SDBG(("images %d..%d\n", first, last)); |
eric@19 | 99 | #endif /* SEMANTIC_DEBUG */ |
eric@16 | 100 | } |
eric@16 | 101 | |
eric@18 | 102 | |
eric@18 | 103 | void output_push_context (void) |
eric@18 | 104 | { |
eric@18 | 105 | }; |
eric@18 | 106 | |
eric@16 | 107 | void output_set_file (char *name) |
eric@16 | 108 | { |
eric@16 | 109 | }; |
eric@16 | 110 | |
eric@16 | 111 | void output_pages (int first, int last) |
eric@16 | 112 | { |
eric@18 | 113 | output_page_count += ((last - first) + 1); |
eric@19 | 114 | #ifdef SEMANTIC_DEBUG |
eric@16 | 115 | if (first == last) |
eric@19 | 116 | SDBG(("page %d\n", first)); |
eric@16 | 117 | else |
eric@19 | 118 | SDBG(("pages %d..%d\n", first, last)); |
eric@19 | 119 | #endif /* SEMANTIC_DEBUG */ |
eric@16 | 120 | } |
eric@16 | 121 | |
eric@16 | 122 | |
eric@16 | 123 | void yyerror (char *s) |
eric@16 | 124 | { |
eric@16 | 125 | fprintf (stderr, "%d: %s\n", line, s); |
eric@16 | 126 | } |
eric@16 | 127 | |
eric@16 | 128 | |
eric@16 | 129 | boolean parse_spec_file (char *fn) |
eric@16 | 130 | { |
eric@16 | 131 | boolean result = 0; |
eric@16 | 132 | |
eric@16 | 133 | yyin = fopen (fn, "r"); |
eric@16 | 134 | if (! yyin) |
eric@16 | 135 | { |
eric@16 | 136 | fprintf (stderr, "can't open spec file '%s'\n", fn); |
eric@16 | 137 | goto fail; |
eric@16 | 138 | } |
eric@16 | 139 | |
eric@16 | 140 | line = 1; |
eric@16 | 141 | |
eric@19 | 142 | input_push_context (); /* create initial input context */ |
eric@18 | 143 | output_push_context (); /* create initial output context */ |
eric@18 | 144 | |
eric@16 | 145 | yyparse (); |
eric@16 | 146 | |
eric@18 | 147 | if (input_page_count != output_page_count) |
eric@18 | 148 | { |
eric@18 | 149 | fprintf (stderr, "input page count %d != output page count %d\n", |
eric@18 | 150 | input_page_count, output_page_count); |
eric@18 | 151 | goto fail; |
eric@18 | 152 | } |
eric@18 | 153 | |
eric@18 | 154 | fprintf (stderr, "%d pages specified\n", input_page_count); |
eric@18 | 155 | |
eric@16 | 156 | result = 1; |
eric@16 | 157 | |
eric@16 | 158 | fail: |
eric@16 | 159 | if (yyin) |
eric@16 | 160 | fclose (yyin); |
eric@16 | 161 | |
eric@16 | 162 | return (result); |
eric@16 | 163 | } |