Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
30b56c58796fec62e3e8d338d4c70dfba597ab67
[simgrid.git] / src / surf / surfxml.l
1 /* Validating XML processor for surfxml.dtd.
2  * Generated 2006/03/21 11:12:31.
3  *
4  * This program was generated with the FleXML XML processor generator.
5  * FleXML is Copyright © 1999-2005 Kristoffer Rose.  All rights reserved.
6  * (Id: flexml.pl,v 1.46 2006/03/21 08:24:12 legranda Exp).
7  * 
8  * There are two, intertwined parts to this program, part A and part B.
9  *
10  * Part A
11  * ------
12  * 
13  * Some parts, here collectively called "Part A", are found in the 
14  * FleXML package.  They are Copyright © 1999-2005 Kristoffer Rose. 
15  * All rights reserved.
16  *
17  * You can redistribute, use, perform, display and/or modify "Part A"
18  * provided the following two conditions hold:
19  *
20  * 1. The program is distributed WITHOUT ANY WARRANTY from the author of
21  *    FleXML; without even the implied warranty of MERCHANTABILITY or
22  *    FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * 2. The program distribution conditions do not in any way affect the
25  *    distribution conditions of the FleXML system used to generate this
26  *    file or any version of FleXML derived from that system.
27  *
28  * Notice that these are explicit rights granted to you for files
29  * generated by the FleXML system.  For your rights in connection with
30  * the FleXML system itself please consult the GNU General Public License.
31  * 
32  * Part B
33  * ------
34  * 
35  * The other parts, here collectively called "Part B", and which came 
36  * from the DTD used by FleXML to generate this program, can be 
37  * distributed (or not, as the case may be) under the terms of whoever
38  * wrote them, provided these terms respect and obey the two conditions 
39  * above under the heading "Part A".
40  *
41  * The author of and contributors to FleXML specifically disclaim
42  * any copyright interest in "Part B", unless "Part B" was written 
43  * by the author of or contributors to FleXML.
44  * 
45  */
46
47 %{
48
49 /* Version strings. */
50 const char rcs_surfxml_flexml_skeleton[] =
51  "$" "Id: skel,v 1.27 2006/03/21 08:24:12 legranda Exp $";
52 const char rcs_surfxml_flexml[] =
53  "$" "Id: flexml.pl,v 1.46 2006/03/21 08:24:12 legranda Exp $";
54
55 /* ANSI headers. */
56 #include <unistd.h>
57 #include <stdio.h>
58 #include <string.h>
59 #include <assert.h>
60 #include <stdarg.h>
61 #include <ctype.h>
62
63 /* Generated definitions. */
64 #define FLEXML_yylineno
65 #define FLEXML_BUFFERSTACKSIZE 1000000
66
67 /* XML processor api. */
68 /* FleXML-provided data. */
69 const char* pcdata;
70 AT_surfxml_network_link_bandwidth A_surfxml_network_link_bandwidth;
71 AT_surfxml_cpu_name A_surfxml_cpu_name;
72 AT_surfxml_process_kill_time A_surfxml_process_kill_time;
73 AT_surfxml_network_link_state A_surfxml_network_link_state;
74 AT_surfxml_argument_value A_surfxml_argument_value;
75 AT_surfxml_cpu_availability_file A_surfxml_cpu_availability_file;
76 AT_surfxml_process_host A_surfxml_process_host;
77 AT_surfxml_route_impact_on_src A_surfxml_route_impact_on_src;
78 AT_surfxml_route_src A_surfxml_route_src;
79 AT_surfxml_network_link_latency_file A_surfxml_network_link_latency_file;
80 AT_surfxml_cpu_max_outgoing_rate A_surfxml_cpu_max_outgoing_rate;
81 AT_surfxml_route_impact_on_dst_with_other_send A_surfxml_route_impact_on_dst_with_other_send;
82 AT_surfxml_cpu_interference_send_recv A_surfxml_cpu_interference_send_recv;
83 AT_surfxml_cpu_availability A_surfxml_cpu_availability;
84 AT_surfxml_route_impact_on_dst A_surfxml_route_impact_on_dst;
85 AT_surfxml_cpu_interference_recv A_surfxml_cpu_interference_recv;
86 AT_surfxml_route_impact_on_src_with_other_recv A_surfxml_route_impact_on_src_with_other_recv;
87 AT_surfxml_network_link_name A_surfxml_network_link_name;
88 AT_surfxml_route_element_name A_surfxml_route_element_name;
89 AT_surfxml_cpu_power A_surfxml_cpu_power;
90 AT_surfxml_process_start_time A_surfxml_process_start_time;
91 AT_surfxml_include_file A_surfxml_include_file;
92 AT_surfxml_process_function A_surfxml_process_function;
93 AT_surfxml_network_link_sharing_policy A_surfxml_network_link_sharing_policy;
94 AT_surfxml_route_dst A_surfxml_route_dst;
95 AT_surfxml_cpu_state A_surfxml_cpu_state;
96 AT_surfxml_network_link_latency A_surfxml_network_link_latency;
97 AT_surfxml_network_link_state_file A_surfxml_network_link_state_file;
98 AT_surfxml_cpu_interference_send A_surfxml_cpu_interference_send;
99 AT_surfxml_cpu_state_file A_surfxml_cpu_state_file;
100 AT_surfxml_network_link_bandwidth_file A_surfxml_network_link_bandwidth_file;
101
102 /* XML state. */
103 #ifdef FLEX_DEBUG
104 # define ENTER(state)   debug_enter(state,#state)
105 # define LEAVE          debug_leave()
106 # define SET(state)     debug_set(state,#state)
107   static void debug_enter(int, const char*);
108   static void debug_leave(void);
109   static void debug_set(int, const char*);
110 #else
111 # define ENTER(state)   (yy_push_state(state))
112 # define LEAVE          (yy_pop_state())
113 # define SET(state)     BEGIN(state)
114 #endif
115
116 /* Generic actions. */
117 #define SKIP    /*skip*/
118 #define SUCCEED        CLEANUP; return 0
119
120 #define FAIL    return fail
121 static int fail(const char*, ...);
122 const char * surfxml_parse_err_msg(void);
123
124 /* Cleanup */
125 static void cleanup(void);
126 #define CLEANUP  cleanup()
127
128 /* Text buffer stack handling. */
129 char bufferstack[FLEXML_BUFFERSTACKSIZE];
130 static char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE;
131 typedef struct BufferLast_s {
132   struct BufferLast_s *old; char* saved; char new1[1];
133 } BufferLast;
134 #ifdef FLEXML_HasMixed
135 static BufferLast* last = (BufferLast*)0;
136 #endif
137 static char* next = bufferstack;
138
139 #define BUFFERSET(P)  (P = next)
140 #define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
141 #define BUFFERDONE    (BUFFERPUTC('\0'))
142
143 #define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
144 static void bufferliteral(char c, const char** pp, char* text)
145 {
146   char *s = strchr(text,c), *e = strrchr(text,c);
147   assert(s <= e); BUFFERSET(*pp);
148   while (++s<e) {
149     if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
150     else BUFFERPUTC(*s);
151   }
152   BUFFERDONE;
153 }
154
155 #ifdef FLEXML_HasMixed
156 static void pushbuffer(char* p)
157 {
158   BufferLast* l = (BufferLast*)next;
159   assert(next < limit);
160   l->old = last;
161   l->saved = p;
162   next = l->new1;
163   last = l;
164 }
165
166 static char* popbuffer(void)
167 {
168   BufferLast* l = last;
169   assert(last != (BufferLast*)0);
170   last = l->old;
171   next = (char*)l;
172   return l->saved;
173 }
174 #endif
175
176 /* General internal entities are `unput' back onto the input stream... */
177 #define ENTITYTEXT(T) \
178   { char *s = (T), *e = s+strlen(s);\
179     while (--e >= s) { unput(*e); }}
180 %}
181
182 /* Flex standard options. */
183 %option stack
184 %option noyy_top_state
185 %option noinput
186 %option noreject
187 %option noyymore
188 %option noyywrap
189
190 /* Flex user-requested options. */
191 %option yylineno
192 %option nounput
193
194 /* XML character classes (currently restricted to ASCII). */
195
196 /* "Common syntactic structures." */
197 S               [ \t\n\r\f]+
198 s               [ \t\n\r\f]*
199
200 /* "Names and Tokens." */
201 NameChar        [A-Za-z0-9.:_-]
202 Name            [A-Za-z_:]{NameChar}*
203 Names           {Name}({S}{Name})*
204 Nmtoken         ({NameChar})+
205 Nmtokens        {Nmtoken}({S}{Nmtoken})*
206
207 /* Miscellaneous. */
208 VersionNum      [a-zA-Z0-9_.:-]+
209 Eq              {s}"="{s}
210 Literal         \'[^'']*\'|\"[^""]*\"
211
212 /* Parser states (flex `exclusive start conditions'):
213  *
214  * PROLOG       the XML prolog of the document before <?xml...>
215  * DOCTYPE      the XML prolog of the document after <?xml...>
216  * EPILOG       after the root element
217  * INCOMMENT    inside an XML comment <!--....-->
218  * INPI         inside an XML PI <?...?>
219  * VALUE1       inside a '...'-delimited literal
220  * VALUE2       inside a "..."-delimited literal
221  * CDATA        inside a <![CDATA[...]]> section.
222  * ROOT_<tag>   expect root element <tag>
223  * AL_<tag>     inside the attribute list for <tag>
224  * IN_<tag>     inside a <tag> with element contents (ready for end tag)
225  * IMPOSSIBLE   dummy to permit disabling rules; must be last
226  */
227 %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
228 %x ROOT_surfxml_platform_description AL_surfxml_platform_description S_surfxml_platform_description S_surfxml_platform_description_1 S_surfxml_platform_description_2 E_surfxml_platform_description
229 %x ROOT_surfxml_include AL_surfxml_include S_surfxml_include S_surfxml_include_1 S_surfxml_include_2 E_surfxml_include
230 %x ROOT_surfxml_cpu AL_surfxml_cpu E_surfxml_cpu
231 %x ROOT_surfxml_network_link AL_surfxml_network_link E_surfxml_network_link
232 %x ROOT_surfxml_route AL_surfxml_route S_surfxml_route S_surfxml_route_1 S_surfxml_route_2 E_surfxml_route
233 %x ROOT_surfxml_route_element AL_surfxml_route_element E_surfxml_route_element
234 %x ROOT_surfxml_process AL_surfxml_process S_surfxml_process S_surfxml_process_1 S_surfxml_process_2 E_surfxml_process
235 %x ROOT_surfxml_argument AL_surfxml_argument E_surfxml_argument
236 %x IMPOSSIBLE
237
238 %{
239 /* State names. */
240 const char* *surfxml_statenames=NULL;
241 %}
242
243 %%
244
245  /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
246  SET(PROLOG);
247   /* FleXML_init */
248   next = bufferstack;
249   if(!surfxml_statenames) {surfxml_statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*));
250   surfxml_statenames[PROLOG] = NULL;
251   surfxml_statenames[DOCTYPE] = NULL;
252   surfxml_statenames[EPILOG] = NULL;
253   surfxml_statenames[INCOMMENT] = NULL;
254   surfxml_statenames[INPI] = NULL;
255   surfxml_statenames[VALUE1] = NULL;
256   surfxml_statenames[VALUE2] = NULL;
257   surfxml_statenames[CDATA] = NULL;
258   surfxml_statenames[ROOT_surfxml_platform_description] = NULL;
259   surfxml_statenames[AL_surfxml_platform_description] = NULL;
260   surfxml_statenames[S_surfxml_platform_description] = "platform_description";
261   surfxml_statenames[S_surfxml_platform_description_1] = "platform_description";
262   surfxml_statenames[S_surfxml_platform_description_2] = "platform_description";
263   surfxml_statenames[E_surfxml_platform_description] = "platform_description";
264   surfxml_statenames[ROOT_surfxml_include] = NULL;
265   surfxml_statenames[AL_surfxml_include] = NULL;
266   surfxml_statenames[S_surfxml_include] = "include";
267   surfxml_statenames[S_surfxml_include_1] = "include";
268   surfxml_statenames[S_surfxml_include_2] = "include";
269   surfxml_statenames[E_surfxml_include] = "include";
270   surfxml_statenames[ROOT_surfxml_cpu] = NULL;
271   surfxml_statenames[AL_surfxml_cpu] = NULL;
272   surfxml_statenames[E_surfxml_cpu] = "cpu";
273   surfxml_statenames[ROOT_surfxml_network_link] = NULL;
274   surfxml_statenames[AL_surfxml_network_link] = NULL;
275   surfxml_statenames[E_surfxml_network_link] = "network_link";
276   surfxml_statenames[ROOT_surfxml_route] = NULL;
277   surfxml_statenames[AL_surfxml_route] = NULL;
278   surfxml_statenames[S_surfxml_route] = "route";
279   surfxml_statenames[S_surfxml_route_1] = "route";
280   surfxml_statenames[S_surfxml_route_2] = "route";
281   surfxml_statenames[E_surfxml_route] = "route";
282   surfxml_statenames[ROOT_surfxml_route_element] = NULL;
283   surfxml_statenames[AL_surfxml_route_element] = NULL;
284   surfxml_statenames[E_surfxml_route_element] = "route_element";
285   surfxml_statenames[ROOT_surfxml_process] = NULL;
286   surfxml_statenames[AL_surfxml_process] = NULL;
287   surfxml_statenames[S_surfxml_process] = "process";
288   surfxml_statenames[S_surfxml_process_1] = "process";
289   surfxml_statenames[S_surfxml_process_2] = "process";
290   surfxml_statenames[E_surfxml_process] = "process";
291   surfxml_statenames[ROOT_surfxml_argument] = NULL;
292   surfxml_statenames[AL_surfxml_argument] = NULL;
293   surfxml_statenames[E_surfxml_argument] = "argument";
294   }
295
296  /* COMMENTS and PIs: handled uniformly for efficiency. */
297
298 <ROOT_surfxml_platform_description,AL_surfxml_platform_description,S_surfxml_platform_description,S_surfxml_platform_description_1,S_surfxml_platform_description_2,E_surfxml_platform_description,ROOT_surfxml_include,AL_surfxml_include,S_surfxml_include,S_surfxml_include_1,S_surfxml_include_2,E_surfxml_include,ROOT_surfxml_cpu,AL_surfxml_cpu,E_surfxml_cpu,ROOT_surfxml_network_link,AL_surfxml_network_link,E_surfxml_network_link,ROOT_surfxml_route,AL_surfxml_route,S_surfxml_route,S_surfxml_route_1,S_surfxml_route_2,E_surfxml_route,ROOT_surfxml_route_element,AL_surfxml_route_element,E_surfxml_route_element,ROOT_surfxml_process,AL_surfxml_process,S_surfxml_process,S_surfxml_process_1,S_surfxml_process_2,E_surfxml_process,ROOT_surfxml_argument,AL_surfxml_argument,E_surfxml_argument,PROLOG,DOCTYPE,EPILOG>{
299  "<!--" ENTER(INCOMMENT);
300  "<?" ENTER(INPI);
301 }
302 <INCOMMENT>{
303  "-->"          LEAVE;
304  "--"           |
305  .              |
306  \n             SKIP;
307  <<EOF>>        FAIL("EOF in comment.");
308 }
309 <INPI>{
310  "?>"           LEAVE;
311  .              |
312  \n             SKIP;
313  <<EOF>>        FAIL("EOF in PI (processing instruction).");
314 }
315
316  /* SPACES: skipped uniformly */
317
318 <ROOT_surfxml_platform_description,AL_surfxml_platform_description,S_surfxml_platform_description,S_surfxml_platform_description_1,S_surfxml_platform_description_2,E_surfxml_platform_description,ROOT_surfxml_include,AL_surfxml_include,S_surfxml_include,S_surfxml_include_1,S_surfxml_include_2,E_surfxml_include,ROOT_surfxml_cpu,AL_surfxml_cpu,E_surfxml_cpu,ROOT_surfxml_network_link,AL_surfxml_network_link,E_surfxml_network_link,ROOT_surfxml_route,AL_surfxml_route,S_surfxml_route,S_surfxml_route_1,S_surfxml_route_2,E_surfxml_route,ROOT_surfxml_route_element,AL_surfxml_route_element,E_surfxml_route_element,ROOT_surfxml_process,AL_surfxml_process,S_surfxml_process,S_surfxml_process_1,S_surfxml_process_2,E_surfxml_process,ROOT_surfxml_argument,AL_surfxml_argument,E_surfxml_argument,PROLOG,DOCTYPE,EPILOG>{S} SKIP;
319
320  /* PROLOG: determine root element and process it. */
321
322 <PROLOG>{
323  "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE); 
324  "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
325 }
326
327 <PROLOG,DOCTYPE>{
328  "<!DOCTYPE"{S}"argument"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_argument);
329  "<!DOCTYPE"{S}"route_element"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_route_element);
330  "<!DOCTYPE"{S}"cpu"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_cpu);
331  "<!DOCTYPE"{S}"include"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_include);
332  "<!DOCTYPE"{S}"route"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_route);
333  "<!DOCTYPE"{S}"platform_description"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_platform_description);
334  "<!DOCTYPE"{S}"network_link"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_network_link);
335  "<!DOCTYPE"{S}"process"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_surfxml_process);
336  "<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
337  .              FAIL("Unexpected character `%c' in prolog.", yytext[0]);
338  <<EOF>>        FAIL("EOF in prolog.");
339 }
340
341  /* RULES DERIVED FROM DTD. */
342
343  /* <!-- Small DTD for SURF based tools. -->  */
344
345 <ROOT_surfxml_platform_description>"<platform_description"{s} {
346   ENTER(AL_surfxml_platform_description);
347   }
348
349 <AL_surfxml_platform_description>{
350  ">" {
351   LEAVE; STag_surfxml_platform_description();pcdata = NULL; ENTER(S_surfxml_platform_description);
352  }
353  "/>" {
354   LEAVE; STag_surfxml_platform_description(); pcdata = NULL; ETag_surfxml_platform_description();
355   switch (YY_START) {
356    case ROOT_surfxml_platform_description: SET(EPILOG); break;
357   }
358  }
359  .       FAIL("Unexpected character `%c' in attribute list of platform_description element.", yytext[0]);
360  {Name} FAIL("Bad attribute `%s' in `platform_description' element start tag.",yytext);
361  <<EOF>> FAIL("EOF in attribute list of `platform_description' element.");
362 }
363
364 <E_surfxml_platform_description,S_surfxml_platform_description_2,S_surfxml_platform_description>{
365  "</platform_description"{s}">" {
366   LEAVE;
367   ETag_surfxml_platform_description();
368   switch (YY_START) {
369    case ROOT_surfxml_platform_description: SET(EPILOG); break;
370   }
371  }
372  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</platform_description>' expected.",yytext);
373  .       FAIL("Unexpected character `%c': `</platform_description>' expected.",yytext[0]);
374  <<EOF>> FAIL("Premature EOF: `</platform_description>' expected.");
375 }
376
377 <ROOT_surfxml_include,S_surfxml_platform_description_2,S_surfxml_include,S_surfxml_include_2,S_surfxml_platform_description_1,S_surfxml_include_1,S_surfxml_platform_description>"<include"{s} {
378   A_surfxml_include_file = NULL;
379   ENTER(AL_surfxml_include);
380   }
381
382 <AL_surfxml_include>{
383  "file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_include_file);
384  "file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_include_file);
385
386  ">" {
387   if (!A_surfxml_include_file) FAIL("Required attribute `file' not set for `include' element.");
388   LEAVE; STag_surfxml_include();pcdata = NULL; ENTER(S_surfxml_include);
389  }
390  "/>" {
391   if (!A_surfxml_include_file) FAIL("Required attribute `file' not set for `include' element.");
392   LEAVE; STag_surfxml_include(); pcdata = NULL; ETag_surfxml_include();
393   switch (YY_START) {
394    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
395    case ROOT_surfxml_include: SET(EPILOG); break;
396    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
397   }
398  }
399  .       FAIL("Unexpected character `%c' in attribute list of include element.", yytext[0]);
400  {Name} FAIL("Bad attribute `%s' in `include' element start tag.",yytext);
401  <<EOF>> FAIL("EOF in attribute list of `include' element.");
402 }
403
404 <E_surfxml_include,S_surfxml_include,S_surfxml_include_2>{
405  "</include"{s}">" {
406   LEAVE;
407   ETag_surfxml_include();
408   switch (YY_START) {
409    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
410    case ROOT_surfxml_include: SET(EPILOG); break;
411    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
412   }
413  }
414  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</include>' expected.",yytext);
415  .       FAIL("Unexpected character `%c': `</include>' expected.",yytext[0]);
416  <<EOF>> FAIL("Premature EOF: `</include>' expected.");
417 }
418
419 <ROOT_surfxml_cpu,S_surfxml_platform_description_2,S_surfxml_include,S_surfxml_include_2,S_surfxml_platform_description_1,S_surfxml_include_1,S_surfxml_platform_description>"<cpu"{s} {
420   A_surfxml_cpu_name = NULL;
421   A_surfxml_cpu_power = NULL;
422   A_surfxml_cpu_availability = "1.0";
423   A_surfxml_cpu_availability_file = NULL;
424   A_surfxml_cpu_state = A_surfxml_cpu_state_ON;
425   A_surfxml_cpu_state_file = NULL;
426   A_surfxml_cpu_interference_send = "1.0";
427   A_surfxml_cpu_interference_recv = "1.0";
428   A_surfxml_cpu_interference_send_recv = "1.0";
429   A_surfxml_cpu_max_outgoing_rate = "-1.0";
430   ENTER(AL_surfxml_cpu);
431   }
432
433 <AL_surfxml_cpu>{
434  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_name);
435  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_name);
436
437  "power"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_power);
438  "power"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_power);
439
440  "availability"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_availability);
441  "availability"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_availability);
442
443  "availability_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_availability_file);
444  "availability_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_availability_file);
445
446  "state"{Eq}"'ON'" |
447  "state"{Eq}"\"ON\"" A_surfxml_cpu_state = A_surfxml_cpu_state_ON;
448  "state"{Eq}"'OFF'" |
449  "state"{Eq}"\"OFF\"" A_surfxml_cpu_state = A_surfxml_cpu_state_OFF;
450
451  "state_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_state_file);
452  "state_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_state_file);
453
454  "interference_send"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_interference_send);
455  "interference_send"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_interference_send);
456
457  "interference_recv"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_interference_recv);
458  "interference_recv"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_interference_recv);
459
460  "interference_send_recv"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_interference_send_recv);
461  "interference_send_recv"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_interference_send_recv);
462
463  "max_outgoing_rate"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_cpu_max_outgoing_rate);
464  "max_outgoing_rate"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_cpu_max_outgoing_rate);
465
466  ">" {
467   if (!A_surfxml_cpu_name) FAIL("Required attribute `name' not set for `cpu' element.");
468   if (!A_surfxml_cpu_power) FAIL("Required attribute `power' not set for `cpu' element.");
469   LEAVE; STag_surfxml_cpu();pcdata = NULL; ENTER(E_surfxml_cpu);
470  }
471  "/>" {
472   if (!A_surfxml_cpu_name) FAIL("Required attribute `name' not set for `cpu' element.");
473   if (!A_surfxml_cpu_power) FAIL("Required attribute `power' not set for `cpu' element.");
474   LEAVE; STag_surfxml_cpu(); pcdata = NULL; ETag_surfxml_cpu();
475   switch (YY_START) {
476    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
477    case ROOT_surfxml_cpu: SET(EPILOG); break;
478    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
479   }
480  }
481  .       FAIL("Unexpected character `%c' in attribute list of cpu element.", yytext[0]);
482  {Name} FAIL("Bad attribute `%s' in `cpu' element start tag.",yytext);
483  <<EOF>> FAIL("EOF in attribute list of `cpu' element.");
484 }
485
486 <E_surfxml_cpu>{
487  "</cpu"{s}">" {
488   LEAVE;
489   ETag_surfxml_cpu();
490   switch (YY_START) {
491    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
492    case ROOT_surfxml_cpu: SET(EPILOG); break;
493    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
494   }
495  }
496  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</cpu>' expected.",yytext);
497  .       FAIL("Unexpected character `%c': `</cpu>' expected.",yytext[0]);
498  <<EOF>> FAIL("Premature EOF: `</cpu>' expected.");
499 }
500
501 <ROOT_surfxml_network_link,S_surfxml_platform_description_2,S_surfxml_include,S_surfxml_include_2,S_surfxml_platform_description_1,S_surfxml_include_1,S_surfxml_platform_description>"<network_link"{s} {
502   A_surfxml_network_link_name = NULL;
503   A_surfxml_network_link_bandwidth = NULL;
504   A_surfxml_network_link_bandwidth_file = NULL;
505   A_surfxml_network_link_latency = "0.0";
506   A_surfxml_network_link_latency_file = NULL;
507   A_surfxml_network_link_state = A_surfxml_network_link_state_ON;
508   A_surfxml_network_link_state_file = NULL;
509   A_surfxml_network_link_sharing_policy = A_surfxml_network_link_sharing_policy_SHARED;
510   ENTER(AL_surfxml_network_link);
511   }
512
513 <AL_surfxml_network_link>{
514  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_network_link_name);
515  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_network_link_name);
516
517  "bandwidth"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_network_link_bandwidth);
518  "bandwidth"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_network_link_bandwidth);
519
520  "bandwidth_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_network_link_bandwidth_file);
521  "bandwidth_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_network_link_bandwidth_file);
522
523  "latency"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_network_link_latency);
524  "latency"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_network_link_latency);
525
526  "latency_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_network_link_latency_file);
527  "latency_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_network_link_latency_file);
528
529  "state"{Eq}"'ON'" |
530  "state"{Eq}"\"ON\"" A_surfxml_network_link_state = A_surfxml_network_link_state_ON;
531  "state"{Eq}"'OFF'" |
532  "state"{Eq}"\"OFF\"" A_surfxml_network_link_state = A_surfxml_network_link_state_OFF;
533
534  "state_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_network_link_state_file);
535  "state_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_network_link_state_file);
536
537  "sharing_policy"{Eq}"'SHARED'" |
538  "sharing_policy"{Eq}"\"SHARED\"" A_surfxml_network_link_sharing_policy = A_surfxml_network_link_sharing_policy_SHARED;
539  "sharing_policy"{Eq}"'FATPIPE'" |
540  "sharing_policy"{Eq}"\"FATPIPE\"" A_surfxml_network_link_sharing_policy = A_surfxml_network_link_sharing_policy_FATPIPE;
541
542  ">" {
543   if (!A_surfxml_network_link_name) FAIL("Required attribute `name' not set for `network_link' element.");
544   if (!A_surfxml_network_link_bandwidth) FAIL("Required attribute `bandwidth' not set for `network_link' element.");
545   LEAVE; STag_surfxml_network_link();pcdata = NULL; ENTER(E_surfxml_network_link);
546  }
547  "/>" {
548   if (!A_surfxml_network_link_name) FAIL("Required attribute `name' not set for `network_link' element.");
549   if (!A_surfxml_network_link_bandwidth) FAIL("Required attribute `bandwidth' not set for `network_link' element.");
550   LEAVE; STag_surfxml_network_link(); pcdata = NULL; ETag_surfxml_network_link();
551   switch (YY_START) {
552    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
553    case ROOT_surfxml_network_link: SET(EPILOG); break;
554    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
555   }
556  }
557  .       FAIL("Unexpected character `%c' in attribute list of network_link element.", yytext[0]);
558  {Name} FAIL("Bad attribute `%s' in `network_link' element start tag.",yytext);
559  <<EOF>> FAIL("EOF in attribute list of `network_link' element.");
560 }
561
562 <E_surfxml_network_link>{
563  "</network_link"{s}">" {
564   LEAVE;
565   ETag_surfxml_network_link();
566   switch (YY_START) {
567    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
568    case ROOT_surfxml_network_link: SET(EPILOG); break;
569    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
570   }
571  }
572  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</network_link>' expected.",yytext);
573  .       FAIL("Unexpected character `%c': `</network_link>' expected.",yytext[0]);
574  <<EOF>> FAIL("Premature EOF: `</network_link>' expected.");
575 }
576
577 <ROOT_surfxml_route,S_surfxml_platform_description_2,S_surfxml_include,S_surfxml_include_2,S_surfxml_platform_description_1,S_surfxml_include_1,S_surfxml_platform_description>"<route"{s} {
578   A_surfxml_route_src = NULL;
579   A_surfxml_route_dst = NULL;
580   A_surfxml_route_impact_on_src = "0.0";
581   A_surfxml_route_impact_on_dst = "0.0";
582   A_surfxml_route_impact_on_src_with_other_recv = "0.0";
583   A_surfxml_route_impact_on_dst_with_other_send = "0.0";
584   ENTER(AL_surfxml_route);
585   }
586
587 <AL_surfxml_route>{
588  "src"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_src);
589  "src"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_src);
590
591  "dst"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_dst);
592  "dst"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_dst);
593
594  "impact_on_src"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_impact_on_src);
595  "impact_on_src"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_impact_on_src);
596
597  "impact_on_dst"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_impact_on_dst);
598  "impact_on_dst"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_impact_on_dst);
599
600  "impact_on_src_with_other_recv"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_impact_on_src_with_other_recv);
601  "impact_on_src_with_other_recv"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_impact_on_src_with_other_recv);
602
603  "impact_on_dst_with_other_send"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_impact_on_dst_with_other_send);
604  "impact_on_dst_with_other_send"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_impact_on_dst_with_other_send);
605
606  ">" {
607   if (!A_surfxml_route_src) FAIL("Required attribute `src' not set for `route' element.");
608   if (!A_surfxml_route_dst) FAIL("Required attribute `dst' not set for `route' element.");
609   LEAVE; STag_surfxml_route();pcdata = NULL; ENTER(S_surfxml_route);
610  }
611  "/>" {
612   if (!A_surfxml_route_src) FAIL("Required attribute `src' not set for `route' element.");
613   if (!A_surfxml_route_dst) FAIL("Required attribute `dst' not set for `route' element.");
614   LEAVE; STag_surfxml_route(); pcdata = NULL; ETag_surfxml_route();
615   switch (YY_START) {
616    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
617    case ROOT_surfxml_route: SET(EPILOG); break;
618    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
619   }
620  }
621  .       FAIL("Unexpected character `%c' in attribute list of route element.", yytext[0]);
622  {Name} FAIL("Bad attribute `%s' in `route' element start tag.",yytext);
623  <<EOF>> FAIL("EOF in attribute list of `route' element.");
624 }
625
626 <S_surfxml_route,S_surfxml_route_2,E_surfxml_route>{
627  "</route"{s}">" {
628   LEAVE;
629   ETag_surfxml_route();
630   switch (YY_START) {
631    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
632    case ROOT_surfxml_route: SET(EPILOG); break;
633    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
634   }
635  }
636  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</route>' expected.",yytext);
637  .       FAIL("Unexpected character `%c': `</route>' expected.",yytext[0]);
638  <<EOF>> FAIL("Premature EOF: `</route>' expected.");
639 }
640
641 <ROOT_surfxml_route_element,S_surfxml_route_1,S_surfxml_route,S_surfxml_route_2>"<route_element"{s} {
642   A_surfxml_route_element_name = NULL;
643   ENTER(AL_surfxml_route_element);
644   }
645
646 <AL_surfxml_route_element>{
647  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_route_element_name);
648  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_route_element_name);
649
650  ">" {
651   if (!A_surfxml_route_element_name) FAIL("Required attribute `name' not set for `route_element' element.");
652   LEAVE; STag_surfxml_route_element();pcdata = NULL; ENTER(E_surfxml_route_element);
653  }
654  "/>" {
655   if (!A_surfxml_route_element_name) FAIL("Required attribute `name' not set for `route_element' element.");
656   LEAVE; STag_surfxml_route_element(); pcdata = NULL; ETag_surfxml_route_element();
657   switch (YY_START) {
658    case S_surfxml_route_1: case S_surfxml_route: case S_surfxml_route_2: SET(S_surfxml_route_2); break;
659    case ROOT_surfxml_route_element: SET(EPILOG); break;
660   }
661  }
662  .       FAIL("Unexpected character `%c' in attribute list of route_element element.", yytext[0]);
663  {Name} FAIL("Bad attribute `%s' in `route_element' element start tag.",yytext);
664  <<EOF>> FAIL("EOF in attribute list of `route_element' element.");
665 }
666
667 <E_surfxml_route_element>{
668  "</route_element"{s}">" {
669   LEAVE;
670   ETag_surfxml_route_element();
671   switch (YY_START) {
672    case S_surfxml_route_1: case S_surfxml_route: case S_surfxml_route_2: SET(S_surfxml_route_2); break;
673    case ROOT_surfxml_route_element: SET(EPILOG); break;
674   }
675  }
676  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</route_element>' expected.",yytext);
677  .       FAIL("Unexpected character `%c': `</route_element>' expected.",yytext[0]);
678  <<EOF>> FAIL("Premature EOF: `</route_element>' expected.");
679 }
680
681 <ROOT_surfxml_process,S_surfxml_platform_description_2,S_surfxml_include,S_surfxml_include_2,S_surfxml_platform_description_1,S_surfxml_include_1,S_surfxml_platform_description>"<process"{s} {
682   A_surfxml_process_host = NULL;
683   A_surfxml_process_function = NULL;
684   A_surfxml_process_start_time = "-1.0";
685   A_surfxml_process_kill_time = "-1.0";
686   ENTER(AL_surfxml_process);
687   }
688
689 <AL_surfxml_process>{
690  "host"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_process_host);
691  "host"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_process_host);
692
693  "function"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_process_function);
694  "function"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_process_function);
695
696  "start_time"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_process_start_time);
697  "start_time"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_process_start_time);
698
699  "kill_time"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_process_kill_time);
700  "kill_time"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_process_kill_time);
701
702  ">" {
703   if (!A_surfxml_process_host) FAIL("Required attribute `host' not set for `process' element.");
704   if (!A_surfxml_process_function) FAIL("Required attribute `function' not set for `process' element.");
705   LEAVE; STag_surfxml_process();pcdata = NULL; ENTER(S_surfxml_process);
706  }
707  "/>" {
708   if (!A_surfxml_process_host) FAIL("Required attribute `host' not set for `process' element.");
709   if (!A_surfxml_process_function) FAIL("Required attribute `function' not set for `process' element.");
710   LEAVE; STag_surfxml_process(); pcdata = NULL; ETag_surfxml_process();
711   switch (YY_START) {
712    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
713    case ROOT_surfxml_process: SET(EPILOG); break;
714    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
715   }
716  }
717  .       FAIL("Unexpected character `%c' in attribute list of process element.", yytext[0]);
718  {Name} FAIL("Bad attribute `%s' in `process' element start tag.",yytext);
719  <<EOF>> FAIL("EOF in attribute list of `process' element.");
720 }
721
722 <S_surfxml_process,E_surfxml_process,S_surfxml_process_2>{
723  "</process"{s}">" {
724   LEAVE;
725   ETag_surfxml_process();
726   switch (YY_START) {
727    case S_surfxml_platform_description_2: case S_surfxml_platform_description_1: case S_surfxml_platform_description: SET(S_surfxml_platform_description_2); break;
728    case ROOT_surfxml_process: SET(EPILOG); break;
729    case S_surfxml_include: case S_surfxml_include_2: case S_surfxml_include_1: SET(S_surfxml_include_2); break;
730   }
731  }
732  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</process>' expected.",yytext);
733  .       FAIL("Unexpected character `%c': `</process>' expected.",yytext[0]);
734  <<EOF>> FAIL("Premature EOF: `</process>' expected.");
735 }
736
737 <ROOT_surfxml_argument,S_surfxml_process_1,S_surfxml_process,S_surfxml_process_2>"<argument"{s} {
738   A_surfxml_argument_value = NULL;
739   ENTER(AL_surfxml_argument);
740   }
741
742 <AL_surfxml_argument>{
743  "value"{Eq}\' ENTER(VALUE1); BUFFERSET(A_surfxml_argument_value);
744  "value"{Eq}\" ENTER(VALUE2); BUFFERSET(A_surfxml_argument_value);
745
746  ">" {
747   if (!A_surfxml_argument_value) FAIL("Required attribute `value' not set for `argument' element.");
748   LEAVE; STag_surfxml_argument();pcdata = NULL; ENTER(E_surfxml_argument);
749  }
750  "/>" {
751   if (!A_surfxml_argument_value) FAIL("Required attribute `value' not set for `argument' element.");
752   LEAVE; STag_surfxml_argument(); pcdata = NULL; ETag_surfxml_argument();
753   switch (YY_START) {
754    case S_surfxml_process_1: case S_surfxml_process: case S_surfxml_process_2: SET(S_surfxml_process_2); break;
755    case ROOT_surfxml_argument: SET(EPILOG); break;
756   }
757  }
758  .       FAIL("Unexpected character `%c' in attribute list of argument element.", yytext[0]);
759  {Name} FAIL("Bad attribute `%s' in `argument' element start tag.",yytext);
760  <<EOF>> FAIL("EOF in attribute list of `argument' element.");
761 }
762
763 <E_surfxml_argument>{
764  "</argument"{s}">" {
765   LEAVE;
766   ETag_surfxml_argument();
767   switch (YY_START) {
768    case S_surfxml_process_1: case S_surfxml_process: case S_surfxml_process_2: SET(S_surfxml_process_2); break;
769    case ROOT_surfxml_argument: SET(EPILOG); break;
770   }
771  }
772  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</argument>' expected.",yytext);
773  .       FAIL("Unexpected character `%c': `</argument>' expected.",yytext[0]);
774  <<EOF>> FAIL("Premature EOF: `</argument>' expected.");
775 }
776
777  /* EPILOG: after the root element. */
778
779 <EPILOG>{
780  . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
781  <<EOF>>        SUCCEED;
782 }
783
784  /* CHARACTER DATA. */
785
786 <IMPOSSIBLE,VALUE1,VALUE2>{
787  /* Non-defined standard entities... */
788 "&amp;"  BUFFERPUTC('&');
789 "&lt;"   BUFFERPUTC('<');
790 "&gt;"   BUFFERPUTC('>');
791 "&apos;" BUFFERPUTC('\'');
792 "&quot;" BUFFERPUTC('"');
793
794  /* Character entities. */
795  "&#"[[:digit:]]+";"    BUFFERPUTC((unsigned char)atoi(yytext+2));
796  "&#x"[[:xdigit:]]+";"  BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
797 }
798
799 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
800  "\n"           |
801  "\r"           |
802  "\r\n"         |
803  "\n\r"         BUFFERPUTC('\n');
804 }
805
806 <IMPOSSIBLE>{
807  "<![CDATA["    ENTER(CDATA);
808  "]""]>"                FAIL("Unexpected `]""]>' in character data.");
809 }
810
811 <VALUE1>{
812  \'             BUFFERDONE; LEAVE;
813  <<EOF>>        FAIL("EOF in literal (\"'\" expected).");
814 }
815
816 <VALUE2>{
817  \"             BUFFERDONE; LEAVE;
818  <<EOF>>        FAIL("EOF in literal (`\"' expected).");
819 }
820
821 <IMPOSSIBLE,VALUE1,VALUE2>{
822  [^<&]          BUFFERPUTC(yytext[0]);
823  [<&]           FAIL("Spurious `%c' in character data.",yytext[0]);
824 }
825
826 <CDATA>{
827  "]""]>"                LEAVE;
828  /* "]""]"              BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
829  .              BUFFERPUTC(yytext[0]);
830  <<EOF>>        FAIL("EOF in CDATA section.");
831 }
832
833  /* Impossible rules to avoid warnings from flex(1). */
834  /* Ideally, this should be replaced by code in flexml.pl that
835     generates just the states not covered by other rules. */
836 <*>{
837  .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
838 }
839
840 %%
841
842 /* Element context stack lookup. */
843 int surfxml_element_context(int i)
844 {
845   return (0<i && i<yy_start_stack_depth
846           ? yy_start_stack[yy_start_stack_ptr - i]
847           : 0);
848 }
849
850 #ifdef FLEX_DEBUG
851 void print_yy_stack(char* fmt, ...)
852 {
853   int i = 0; va_list ap; va_start(ap, fmt);
854   vfprintf(stderr, fmt, ap);
855   for (i=1; i<yy_start_stack_ptr; i++)
856     fprintf(stderr, "%s/", surfxml_statenames[yy_start_stack[i] ]);
857   fprintf(stderr,"%s\n", surfxml_statenames[YY_START]);
858   va_end(ap);
859 }
860
861 static void debug_enter(int state, const char* statename) {
862   yy_push_state(state);
863   if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
864 }
865
866 static void debug_leave(void) {
867   if (yy_flex_debug) print_yy_stack("--LEAVE : ");
868   yy_pop_state();
869 }
870
871 static void debug_set(int state, const char* statename) {
872   BEGIN(state);
873   if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
874 }
875 #endif
876
877 enum {flexml_max_err_msg_size = 512};
878
879 static char flexml_err_msg[flexml_max_err_msg_size];
880 const char * surfxml_parse_err_msg()
881 {
882     return flexml_err_msg;
883 }
884
885 static void reset_surfxml_parse_err_msg()
886 {
887     flexml_err_msg[0] = '\0';
888 }
889
890
891 static void cleanup(void)
892 {
893     if (surfxml_statenames) {
894         free(surfxml_statenames);
895         surfxml_statenames = NULL;
896     }
897 }
898
899
900 static int fail(const char* fmt, ...)
901 {
902     int chars_left, used;
903     va_list ap; va_start(ap, fmt);
904 #ifdef FLEXML_yylineno
905     used = sprintf(flexml_err_msg,
906                    "Invalid XML (XML input line %d, state %d): ",
907                    yylineno, YY_START);
908 #else
909     used = sprintf(flexml_err_msg,
910                    "Invalid XML (state %d): ",
911                    YY_START);
912 #endif
913     chars_left = flexml_max_err_msg_size - used - 1;
914     vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
915     va_end(ap);
916
917 #ifndef FLEXML_quiet_parser
918     /* print directly to sdterr */
919     fprintf(stderr, "%s\n", flexml_err_msg);
920     flexml_err_msg[0] = '\0';
921 #endif
922
923     cleanup();
924
925     return 1;
926 }