Sun, 30 Dec 2001 17:09:08 +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 FILE *yyin;
11 int line; /* line number in spec file */
14 int input_page_count; /* total input pages in spec */
15 int output_page_count; /* total output pages in spec */
18 input_context_t *current_input_context;
21 void input_push_context (input_context_type_t type)
22 {
23 input_context_t *new_input_context;
25 new_input_context = malloc (sizeof (input_context_t));
26 if (! new_input_context)
27 {
28 fprintf (stderr, "failed to calloc an input context\n");
29 return;
30 }
32 if (current_input_context)
33 {
34 memcpy (new_input_context, current_input_context, sizeof (input_context_t));
35 new_input_context->page_count = 0;
36 }
37 else
38 memset (new_input_context, 0, sizeof (input_context_t));
40 new_input_context->parent_input_context = current_input_context;
41 current_input_context = new_input_context;
42 };
44 void input_pop_context (void)
45 {
46 if (! current_input_context)
47 {
48 fprintf (stderr, "failed to pop an input context\n");
49 return;
50 }
52 current_input_context = current_input_context->parent_input_context;
53 };
55 void input_set_file (char *name)
56 {
57 };
59 void input_images (int first, int last)
60 {
61 input_page_count += ((last - first) + 1);
62 if (first == last)
63 printf ("image %d\n", first);
64 else
65 printf ("images %d..%d\n", first, last);
66 }
69 void output_push_context (void)
70 {
71 };
73 void output_set_file (char *name)
74 {
75 };
77 void output_pages (int first, int last)
78 {
79 output_page_count += ((last - first) + 1);
80 if (first == last)
81 printf ("page %d\n", first);
82 else
83 printf ("pages %d..%d\n", first, last);
84 }
87 void yyerror (char *s)
88 {
89 fprintf (stderr, "%d: %s\n", line, s);
90 }
93 boolean parse_spec_file (char *fn)
94 {
95 boolean result = 0;
97 yyin = fopen (fn, "r");
98 if (! yyin)
99 {
100 fprintf (stderr, "can't open spec file '%s'\n", fn);
101 goto fail;
102 }
104 line = 1;
106 input_push_context (INPUT_CONTEXT_ALL); /* create initial input context */
107 output_push_context (); /* create initial output context */
109 yyparse ();
111 if (input_page_count != output_page_count)
112 {
113 fprintf (stderr, "input page count %d != output page count %d\n",
114 input_page_count, output_page_count);
115 goto fail;
116 }
118 fprintf (stderr, "%d pages specified\n", input_page_count);
120 result = 1;
122 fail:
123 if (yyin)
124 fclose (yyin);
126 return (result);
127 }