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