Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I don't think it does what it should now but at least it looks better and
[simgrid.git] / src / surf / surfxml.l
1 /* Validating XML processor for surfxml.dtd.
2  * Generated 2005/08/16 14:42:02.
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.44 2005/02/23 23:08:16 mquinson 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_flexml_skeleton[] =
51  "$" "Id: skel,v 1.26 2005/02/23 22:22:20 wdowling Exp $";
52 const char rcs_flexml[] =
53  "$" "Id: flexml.pl,v 1.44 2005/02/23 23:08:16 mquinson 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_network_link_bandwidth A_network_link_bandwidth;
71 AT_cpu_name A_cpu_name;
72 AT_process_kill_time A_process_kill_time;
73 AT_network_link_state A_network_link_state;
74 AT_argument_value A_argument_value;
75 AT_cpu_availability_file A_cpu_availability_file;
76 AT_process_host A_process_host;
77 AT_route_impact_on_src A_route_impact_on_src;
78 AT_route_src A_route_src;
79 AT_network_link_latency_file A_network_link_latency_file;
80 AT_cpu_max_outgoing_rate A_cpu_max_outgoing_rate;
81 AT_route_impact_on_dst_with_other_send A_route_impact_on_dst_with_other_send;
82 AT_cpu_interference_send_recv A_cpu_interference_send_recv;
83 AT_cpu_availability A_cpu_availability;
84 AT_route_impact_on_dst A_route_impact_on_dst;
85 AT_cpu_interference_recv A_cpu_interference_recv;
86 AT_route_impact_on_src_with_other_recv A_route_impact_on_src_with_other_recv;
87 AT_network_link_name A_network_link_name;
88 AT_route_element_name A_route_element_name;
89 AT_cpu_power A_cpu_power;
90 AT_process_start_time A_process_start_time;
91 AT_include_file A_include_file;
92 AT_process_function A_process_function;
93 AT_network_link_sharing_policy A_network_link_sharing_policy;
94 AT_route_dst A_route_dst;
95 AT_cpu_state A_cpu_state;
96 AT_network_link_latency A_network_link_latency;
97 AT_network_link_state_file A_network_link_state_file;
98 AT_cpu_interference_send A_cpu_interference_send;
99 AT_cpu_state_file A_cpu_state_file;
100 AT_network_link_bandwidth_file A_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 * 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 char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE;
131 typedef struct BufferLast_s {
132   struct BufferLast_s *old; char* saved; char new1[1];
133 } BufferLast;
134 BufferLast* last = (BufferLast*)0;
135 char* next = bufferstack;
136
137 #define BUFFERSET(P)  (P = next)
138 #define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
139 #define BUFFERDONE    (BUFFERPUTC('\0'))
140
141 #define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
142 static void bufferliteral(char c, const char** pp, char* text)
143 {
144   char *s = strchr(text,c), *e = strrchr(text,c);
145   assert(s <= e); BUFFERSET(*pp);
146   while (++s<e) {
147     if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
148     else BUFFERPUTC(*s);
149   }
150   BUFFERDONE;
151 }
152
153 #ifdef FLEXML_HasMixed
154 static void pushbuffer(char* p)
155 {
156   BufferLast* l = (BufferLast*)next;
157   assert(next < limit);
158   l->old = last;
159   l->saved = p;
160   next = l->new1;
161   last = l;
162 }
163
164 static char* popbuffer(void)
165 {
166   BufferLast* l = last;
167   assert(last != (BufferLast*)0);
168   last = l->old;
169   next = (char*)l;
170   return l->saved;
171 }
172 #endif
173
174 /* General internal entities are `unput' back onto the input stream... */
175 #define ENTITYTEXT(T) \
176   { char *s = (T), *e = s+strlen(s);\
177     while (--e >= s) { unput(*e); }}
178 %}
179
180 /* Flex standard options. */
181 %option stack
182 %option noyy_top_state
183 %option noinput
184 %option noreject
185 %option noyymore
186 %option noyywrap
187
188 /* Flex user-requested options. */
189 %option yylineno
190 %option nounput
191
192 /* XML character classes (currently restricted to ASCII). */
193
194 /* "Common syntactic structures." */
195 S               [ \t\n\r\f]+
196 s               [ \t\n\r\f]*
197
198 /* "Names and Tokens." */
199 NameChar        [A-Za-z0-9.:_-]
200 Name            [A-Za-z_:]{NameChar}*
201 Names           {Name}({S}{Name})*
202 Nmtoken         ({NameChar})+
203 Nmtokens        {Nmtoken}({S}{Nmtoken})*
204
205 /* Miscellaneous. */
206 VersionNum      [a-zA-Z0-9_.:-]+
207 Eq              {s}"="{s}
208 Literal         \'[^'']*\'|\"[^""]*\"
209
210 /* Parser states (flex `exclusive start conditions'):
211  *
212  * PROLOG       the XML prolog of the document before <?xml...>
213  * DOCTYPE      the XML prolog of the document after <?xml...>
214  * EPILOG       after the root element
215  * INCOMMENT    inside an XML comment <!--....-->
216  * INPI         inside an XML PI <?...?>
217  * VALUE1       inside a '...'-delimited literal
218  * VALUE2       inside a "..."-delimited literal
219  * CDATA        inside a <![CDATA[...]]> section.
220  * ROOT_<tag>   expect root element <tag>
221  * AL_<tag>     inside the attribute list for <tag>
222  * IN_<tag>     inside a <tag> with element contents (ready for end tag)
223  * IMPOSSIBLE   dummy to permit disabling rules; must be last
224  */
225 %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
226 %x ROOT_platform_description AL_platform_description S_platform_description S_platform_description_1 S_platform_description_2 E_platform_description
227 %x ROOT_include AL_include S_include S_include_1 S_include_2 E_include
228 %x ROOT_cpu AL_cpu E_cpu
229 %x ROOT_network_link AL_network_link E_network_link
230 %x ROOT_route AL_route S_route S_route_1 S_route_2 E_route
231 %x ROOT_route_element AL_route_element E_route_element
232 %x ROOT_process AL_process S_process S_process_1 S_process_2 E_process
233 %x ROOT_argument AL_argument E_argument
234 %x IMPOSSIBLE
235
236 %{
237 /* State names. */
238 const char* *statenames=NULL;
239 %}
240
241 %%
242
243  /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
244  SET(PROLOG);
245   /* FleXML_init */
246   next = bufferstack;
247   if(!statenames) {statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*));
248   statenames[PROLOG] = NULL;
249   statenames[DOCTYPE] = NULL;
250   statenames[EPILOG] = NULL;
251   statenames[INCOMMENT] = NULL;
252   statenames[INPI] = NULL;
253   statenames[VALUE1] = NULL;
254   statenames[VALUE2] = NULL;
255   statenames[CDATA] = NULL;
256   statenames[ROOT_platform_description] = NULL;
257   statenames[AL_platform_description] = NULL;
258   statenames[S_platform_description] = "platform_description";
259   statenames[S_platform_description_1] = "platform_description";
260   statenames[S_platform_description_2] = "platform_description";
261   statenames[E_platform_description] = "platform_description";
262   statenames[ROOT_include] = NULL;
263   statenames[AL_include] = NULL;
264   statenames[S_include] = "include";
265   statenames[S_include_1] = "include";
266   statenames[S_include_2] = "include";
267   statenames[E_include] = "include";
268   statenames[ROOT_cpu] = NULL;
269   statenames[AL_cpu] = NULL;
270   statenames[E_cpu] = "cpu";
271   statenames[ROOT_network_link] = NULL;
272   statenames[AL_network_link] = NULL;
273   statenames[E_network_link] = "network_link";
274   statenames[ROOT_route] = NULL;
275   statenames[AL_route] = NULL;
276   statenames[S_route] = "route";
277   statenames[S_route_1] = "route";
278   statenames[S_route_2] = "route";
279   statenames[E_route] = "route";
280   statenames[ROOT_route_element] = NULL;
281   statenames[AL_route_element] = NULL;
282   statenames[E_route_element] = "route_element";
283   statenames[ROOT_process] = NULL;
284   statenames[AL_process] = NULL;
285   statenames[S_process] = "process";
286   statenames[S_process_1] = "process";
287   statenames[S_process_2] = "process";
288   statenames[E_process] = "process";
289   statenames[ROOT_argument] = NULL;
290   statenames[AL_argument] = NULL;
291   statenames[E_argument] = "argument";
292   }
293
294  /* COMMENTS and PIs: handled uniformly for efficiency. */
295
296 <ROOT_platform_description,AL_platform_description,S_platform_description,S_platform_description_1,S_platform_description_2,E_platform_description,ROOT_include,AL_include,S_include,S_include_1,S_include_2,E_include,ROOT_cpu,AL_cpu,E_cpu,ROOT_network_link,AL_network_link,E_network_link,ROOT_route,AL_route,S_route,S_route_1,S_route_2,E_route,ROOT_route_element,AL_route_element,E_route_element,ROOT_process,AL_process,S_process,S_process_1,S_process_2,E_process,ROOT_argument,AL_argument,E_argument,PROLOG,DOCTYPE,EPILOG>{
297  "<!--" ENTER(INCOMMENT);
298  "<?" ENTER(INPI);
299 }
300 <INCOMMENT>{
301  "-->"          LEAVE;
302  "--"           |
303  .              |
304  \n             SKIP;
305  <<EOF>>        FAIL("EOF in comment.");
306 }
307 <INPI>{
308  "?>"           LEAVE;
309  .              |
310  \n             SKIP;
311  <<EOF>>        FAIL("EOF in PI (processing instruction).");
312 }
313
314  /* SPACES: skipped uniformly */
315
316 <ROOT_platform_description,AL_platform_description,S_platform_description,S_platform_description_1,S_platform_description_2,E_platform_description,ROOT_include,AL_include,S_include,S_include_1,S_include_2,E_include,ROOT_cpu,AL_cpu,E_cpu,ROOT_network_link,AL_network_link,E_network_link,ROOT_route,AL_route,S_route,S_route_1,S_route_2,E_route,ROOT_route_element,AL_route_element,E_route_element,ROOT_process,AL_process,S_process,S_process_1,S_process_2,E_process,ROOT_argument,AL_argument,E_argument,PROLOG,DOCTYPE,EPILOG>{S} SKIP;
317
318  /* PROLOG: determine root element and process it. */
319
320 <PROLOG>{
321  "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE); 
322  "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
323 }
324
325 <PROLOG,DOCTYPE>{
326  "<!DOCTYPE"{S}"argument"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_argument);
327  "<!DOCTYPE"{S}"route_element"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_route_element);
328  "<!DOCTYPE"{S}"cpu"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_cpu);
329  "<!DOCTYPE"{S}"include"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_include);
330  "<!DOCTYPE"{S}"route"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_route);
331  "<!DOCTYPE"{S}"platform_description"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_platform_description);
332  "<!DOCTYPE"{S}"network_link"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_network_link);
333  "<!DOCTYPE"{S}"process"{S}SYSTEM{S}("'surfxml.dtd'"|"\"surfxml.dtd\""){s}">" SET(ROOT_process);
334  "<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
335  .              FAIL("Unexpected character `%c' in prolog.", yytext[0]);
336  <<EOF>>        FAIL("EOF in prolog.");
337 }
338
339  /* RULES DERIVED FROM DTD. */
340
341  /* <!-- Small DTD for SURF based tools. -->  */
342
343 <ROOT_platform_description>"<platform_description"{s} {
344   ENTER(AL_platform_description);
345   }
346
347 <AL_platform_description>{
348  ">" {
349   LEAVE; STag_platform_description();pcdata = NULL; ENTER(S_platform_description);
350  }
351  "/>" {
352   LEAVE; STag_platform_description(); pcdata = NULL; ETag_platform_description();
353   switch (YY_START) {
354    case ROOT_platform_description: SET(EPILOG); break;
355   }
356  }
357  .       FAIL("Unexpected character `%c' in attribute list of platform_description element.", yytext[0]);
358  {Name} FAIL("Bad attribute `%s' in `platform_description' element start tag.",yytext);
359  <<EOF>> FAIL("EOF in attribute list of `platform_description' element.");
360 }
361
362 <E_platform_description,S_platform_description_2,S_platform_description>{
363  "</platform_description"{s}">" {
364   LEAVE;
365   ETag_platform_description();
366   switch (YY_START) {
367    case ROOT_platform_description: SET(EPILOG); break;
368   }
369  }
370  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</platform_description>' expected.",yytext);
371  .       FAIL("Unexpected character `%c': `</platform_description>' expected.",yytext[0]);
372  <<EOF>> FAIL("Premature EOF: `</platform_description>' expected.");
373 }
374
375 <ROOT_include,S_platform_description_2,S_include,S_include_2,S_platform_description_1,S_include_1,S_platform_description>"<include"{s} {
376   A_include_file = NULL;
377   ENTER(AL_include);
378   }
379
380 <AL_include>{
381  "file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_include_file);
382  "file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_include_file);
383
384  ">" {
385   if (!A_include_file) FAIL("Required attribute `file' not set for `include' element.");
386   LEAVE; STag_include();pcdata = NULL; ENTER(S_include);
387  }
388  "/>" {
389   if (!A_include_file) FAIL("Required attribute `file' not set for `include' element.");
390   LEAVE; STag_include(); pcdata = NULL; ETag_include();
391   switch (YY_START) {
392    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
393    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
394    case ROOT_include: SET(EPILOG); break;
395   }
396  }
397  .       FAIL("Unexpected character `%c' in attribute list of include element.", yytext[0]);
398  {Name} FAIL("Bad attribute `%s' in `include' element start tag.",yytext);
399  <<EOF>> FAIL("EOF in attribute list of `include' element.");
400 }
401
402 <E_include,S_include,S_include_2>{
403  "</include"{s}">" {
404   LEAVE;
405   ETag_include();
406   switch (YY_START) {
407    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
408    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
409    case ROOT_include: SET(EPILOG); break;
410   }
411  }
412  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</include>' expected.",yytext);
413  .       FAIL("Unexpected character `%c': `</include>' expected.",yytext[0]);
414  <<EOF>> FAIL("Premature EOF: `</include>' expected.");
415 }
416
417 <ROOT_cpu,S_platform_description_2,S_include,S_include_2,S_platform_description_1,S_include_1,S_platform_description>"<cpu"{s} {
418   A_cpu_name = NULL;
419   A_cpu_power = NULL;
420   A_cpu_availability = "1.0";
421   A_cpu_availability_file = NULL;
422   A_cpu_state = A_cpu_state_ON;
423   A_cpu_state_file = NULL;
424   A_cpu_interference_send = "1.0";
425   A_cpu_interference_recv = "1.0";
426   A_cpu_interference_send_recv = "1.0";
427   A_cpu_max_outgoing_rate = "-1.0";
428   ENTER(AL_cpu);
429   }
430
431 <AL_cpu>{
432  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_name);
433  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_name);
434
435  "power"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_power);
436  "power"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_power);
437
438  "availability"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_availability);
439  "availability"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_availability);
440
441  "availability_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_availability_file);
442  "availability_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_availability_file);
443
444  "state"{Eq}"'ON'" |
445  "state"{Eq}"\"ON\"" A_cpu_state = A_cpu_state_ON;
446  "state"{Eq}"'OFF'" |
447  "state"{Eq}"\"OFF\"" A_cpu_state = A_cpu_state_OFF;
448
449  "state_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_state_file);
450  "state_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_state_file);
451
452  "interference_send"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_interference_send);
453  "interference_send"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_interference_send);
454
455  "interference_recv"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_interference_recv);
456  "interference_recv"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_interference_recv);
457
458  "interference_send_recv"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_interference_send_recv);
459  "interference_send_recv"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_interference_send_recv);
460
461  "max_outgoing_rate"{Eq}\' ENTER(VALUE1); BUFFERSET(A_cpu_max_outgoing_rate);
462  "max_outgoing_rate"{Eq}\" ENTER(VALUE2); BUFFERSET(A_cpu_max_outgoing_rate);
463
464  ">" {
465   if (!A_cpu_name) FAIL("Required attribute `name' not set for `cpu' element.");
466   if (!A_cpu_power) FAIL("Required attribute `power' not set for `cpu' element.");
467   LEAVE; STag_cpu();pcdata = NULL; ENTER(E_cpu);
468  }
469  "/>" {
470   if (!A_cpu_name) FAIL("Required attribute `name' not set for `cpu' element.");
471   if (!A_cpu_power) FAIL("Required attribute `power' not set for `cpu' element.");
472   LEAVE; STag_cpu(); pcdata = NULL; ETag_cpu();
473   switch (YY_START) {
474    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
475    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
476    case ROOT_cpu: SET(EPILOG); break;
477   }
478  }
479  .       FAIL("Unexpected character `%c' in attribute list of cpu element.", yytext[0]);
480  {Name} FAIL("Bad attribute `%s' in `cpu' element start tag.",yytext);
481  <<EOF>> FAIL("EOF in attribute list of `cpu' element.");
482 }
483
484 <E_cpu>{
485  "</cpu"{s}">" {
486   LEAVE;
487   ETag_cpu();
488   switch (YY_START) {
489    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
490    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
491    case ROOT_cpu: SET(EPILOG); break;
492   }
493  }
494  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</cpu>' expected.",yytext);
495  .       FAIL("Unexpected character `%c': `</cpu>' expected.",yytext[0]);
496  <<EOF>> FAIL("Premature EOF: `</cpu>' expected.");
497 }
498
499 <ROOT_network_link,S_platform_description_2,S_include,S_include_2,S_platform_description_1,S_include_1,S_platform_description>"<network_link"{s} {
500   A_network_link_name = NULL;
501   A_network_link_bandwidth = NULL;
502   A_network_link_bandwidth_file = NULL;
503   A_network_link_latency = "0.0";
504   A_network_link_latency_file = NULL;
505   A_network_link_state = A_network_link_state_ON;
506   A_network_link_state_file = NULL;
507   A_network_link_sharing_policy = A_network_link_sharing_policy_SHARED;
508   ENTER(AL_network_link);
509   }
510
511 <AL_network_link>{
512  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_network_link_name);
513  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_network_link_name);
514
515  "bandwidth"{Eq}\' ENTER(VALUE1); BUFFERSET(A_network_link_bandwidth);
516  "bandwidth"{Eq}\" ENTER(VALUE2); BUFFERSET(A_network_link_bandwidth);
517
518  "bandwidth_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_network_link_bandwidth_file);
519  "bandwidth_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_network_link_bandwidth_file);
520
521  "latency"{Eq}\' ENTER(VALUE1); BUFFERSET(A_network_link_latency);
522  "latency"{Eq}\" ENTER(VALUE2); BUFFERSET(A_network_link_latency);
523
524  "latency_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_network_link_latency_file);
525  "latency_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_network_link_latency_file);
526
527  "state"{Eq}"'ON'" |
528  "state"{Eq}"\"ON\"" A_network_link_state = A_network_link_state_ON;
529  "state"{Eq}"'OFF'" |
530  "state"{Eq}"\"OFF\"" A_network_link_state = A_network_link_state_OFF;
531
532  "state_file"{Eq}\' ENTER(VALUE1); BUFFERSET(A_network_link_state_file);
533  "state_file"{Eq}\" ENTER(VALUE2); BUFFERSET(A_network_link_state_file);
534
535  "sharing_policy"{Eq}"'SHARED'" |
536  "sharing_policy"{Eq}"\"SHARED\"" A_network_link_sharing_policy = A_network_link_sharing_policy_SHARED;
537  "sharing_policy"{Eq}"'FATPIPE'" |
538  "sharing_policy"{Eq}"\"FATPIPE\"" A_network_link_sharing_policy = A_network_link_sharing_policy_FATPIPE;
539
540  ">" {
541   if (!A_network_link_name) FAIL("Required attribute `name' not set for `network_link' element.");
542   if (!A_network_link_bandwidth) FAIL("Required attribute `bandwidth' not set for `network_link' element.");
543   LEAVE; STag_network_link();pcdata = NULL; ENTER(E_network_link);
544  }
545  "/>" {
546   if (!A_network_link_name) FAIL("Required attribute `name' not set for `network_link' element.");
547   if (!A_network_link_bandwidth) FAIL("Required attribute `bandwidth' not set for `network_link' element.");
548   LEAVE; STag_network_link(); pcdata = NULL; ETag_network_link();
549   switch (YY_START) {
550    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
551    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
552    case ROOT_network_link: SET(EPILOG); break;
553   }
554  }
555  .       FAIL("Unexpected character `%c' in attribute list of network_link element.", yytext[0]);
556  {Name} FAIL("Bad attribute `%s' in `network_link' element start tag.",yytext);
557  <<EOF>> FAIL("EOF in attribute list of `network_link' element.");
558 }
559
560 <E_network_link>{
561  "</network_link"{s}">" {
562   LEAVE;
563   ETag_network_link();
564   switch (YY_START) {
565    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
566    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
567    case ROOT_network_link: SET(EPILOG); break;
568   }
569  }
570  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</network_link>' expected.",yytext);
571  .       FAIL("Unexpected character `%c': `</network_link>' expected.",yytext[0]);
572  <<EOF>> FAIL("Premature EOF: `</network_link>' expected.");
573 }
574
575 <ROOT_route,S_platform_description_2,S_include,S_include_2,S_platform_description_1,S_include_1,S_platform_description>"<route"{s} {
576   A_route_src = NULL;
577   A_route_dst = NULL;
578   A_route_impact_on_src = "0.0";
579   A_route_impact_on_dst = "0.0";
580   A_route_impact_on_src_with_other_recv = "0.0";
581   A_route_impact_on_dst_with_other_send = "0.0";
582   ENTER(AL_route);
583   }
584
585 <AL_route>{
586  "src"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_src);
587  "src"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_src);
588
589  "dst"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_dst);
590  "dst"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_dst);
591
592  "impact_on_src"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_impact_on_src);
593  "impact_on_src"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_impact_on_src);
594
595  "impact_on_dst"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_impact_on_dst);
596  "impact_on_dst"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_impact_on_dst);
597
598  "impact_on_src_with_other_recv"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_impact_on_src_with_other_recv);
599  "impact_on_src_with_other_recv"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_impact_on_src_with_other_recv);
600
601  "impact_on_dst_with_other_send"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_impact_on_dst_with_other_send);
602  "impact_on_dst_with_other_send"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_impact_on_dst_with_other_send);
603
604  ">" {
605   if (!A_route_src) FAIL("Required attribute `src' not set for `route' element.");
606   if (!A_route_dst) FAIL("Required attribute `dst' not set for `route' element.");
607   LEAVE; STag_route();pcdata = NULL; ENTER(S_route);
608  }
609  "/>" {
610   if (!A_route_src) FAIL("Required attribute `src' not set for `route' element.");
611   if (!A_route_dst) FAIL("Required attribute `dst' not set for `route' element.");
612   LEAVE; STag_route(); pcdata = NULL; ETag_route();
613   switch (YY_START) {
614    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
615    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
616    case ROOT_route: SET(EPILOG); break;
617   }
618  }
619  .       FAIL("Unexpected character `%c' in attribute list of route element.", yytext[0]);
620  {Name} FAIL("Bad attribute `%s' in `route' element start tag.",yytext);
621  <<EOF>> FAIL("EOF in attribute list of `route' element.");
622 }
623
624 <S_route,S_route_2,E_route>{
625  "</route"{s}">" {
626   LEAVE;
627   ETag_route();
628   switch (YY_START) {
629    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
630    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
631    case ROOT_route: SET(EPILOG); break;
632   }
633  }
634  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</route>' expected.",yytext);
635  .       FAIL("Unexpected character `%c': `</route>' expected.",yytext[0]);
636  <<EOF>> FAIL("Premature EOF: `</route>' expected.");
637 }
638
639 <ROOT_route_element,S_route_1,S_route,S_route_2>"<route_element"{s} {
640   A_route_element_name = NULL;
641   ENTER(AL_route_element);
642   }
643
644 <AL_route_element>{
645  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_route_element_name);
646  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_route_element_name);
647
648  ">" {
649   if (!A_route_element_name) FAIL("Required attribute `name' not set for `route_element' element.");
650   LEAVE; STag_route_element();pcdata = NULL; ENTER(E_route_element);
651  }
652  "/>" {
653   if (!A_route_element_name) FAIL("Required attribute `name' not set for `route_element' element.");
654   LEAVE; STag_route_element(); pcdata = NULL; ETag_route_element();
655   switch (YY_START) {
656    case S_route_1: case S_route: case S_route_2: SET(S_route_2); break;
657    case ROOT_route_element: SET(EPILOG); break;
658   }
659  }
660  .       FAIL("Unexpected character `%c' in attribute list of route_element element.", yytext[0]);
661  {Name} FAIL("Bad attribute `%s' in `route_element' element start tag.",yytext);
662  <<EOF>> FAIL("EOF in attribute list of `route_element' element.");
663 }
664
665 <E_route_element>{
666  "</route_element"{s}">" {
667   LEAVE;
668   ETag_route_element();
669   switch (YY_START) {
670    case S_route_1: case S_route: case S_route_2: SET(S_route_2); break;
671    case ROOT_route_element: SET(EPILOG); break;
672   }
673  }
674  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</route_element>' expected.",yytext);
675  .       FAIL("Unexpected character `%c': `</route_element>' expected.",yytext[0]);
676  <<EOF>> FAIL("Premature EOF: `</route_element>' expected.");
677 }
678
679 <ROOT_process,S_platform_description_2,S_include,S_include_2,S_platform_description_1,S_include_1,S_platform_description>"<process"{s} {
680   A_process_host = NULL;
681   A_process_function = NULL;
682   A_process_start_time = "-1.0";
683   A_process_kill_time = "-1.0";
684   ENTER(AL_process);
685   }
686
687 <AL_process>{
688  "host"{Eq}\' ENTER(VALUE1); BUFFERSET(A_process_host);
689  "host"{Eq}\" ENTER(VALUE2); BUFFERSET(A_process_host);
690
691  "function"{Eq}\' ENTER(VALUE1); BUFFERSET(A_process_function);
692  "function"{Eq}\" ENTER(VALUE2); BUFFERSET(A_process_function);
693
694  "start_time"{Eq}\' ENTER(VALUE1); BUFFERSET(A_process_start_time);
695  "start_time"{Eq}\" ENTER(VALUE2); BUFFERSET(A_process_start_time);
696
697  "kill_time"{Eq}\' ENTER(VALUE1); BUFFERSET(A_process_kill_time);
698  "kill_time"{Eq}\" ENTER(VALUE2); BUFFERSET(A_process_kill_time);
699
700  ">" {
701   if (!A_process_host) FAIL("Required attribute `host' not set for `process' element.");
702   if (!A_process_function) FAIL("Required attribute `function' not set for `process' element.");
703   LEAVE; STag_process();pcdata = NULL; ENTER(S_process);
704  }
705  "/>" {
706   if (!A_process_host) FAIL("Required attribute `host' not set for `process' element.");
707   if (!A_process_function) FAIL("Required attribute `function' not set for `process' element.");
708   LEAVE; STag_process(); pcdata = NULL; ETag_process();
709   switch (YY_START) {
710    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
711    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
712    case ROOT_process: SET(EPILOG); break;
713   }
714  }
715  .       FAIL("Unexpected character `%c' in attribute list of process element.", yytext[0]);
716  {Name} FAIL("Bad attribute `%s' in `process' element start tag.",yytext);
717  <<EOF>> FAIL("EOF in attribute list of `process' element.");
718 }
719
720 <S_process,E_process,S_process_2>{
721  "</process"{s}">" {
722   LEAVE;
723   ETag_process();
724   switch (YY_START) {
725    case S_platform_description_2: case S_platform_description_1: case S_platform_description: SET(S_platform_description_2); break;
726    case S_include: case S_include_2: case S_include_1: SET(S_include_2); break;
727    case ROOT_process: SET(EPILOG); break;
728   }
729  }
730  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</process>' expected.",yytext);
731  .       FAIL("Unexpected character `%c': `</process>' expected.",yytext[0]);
732  <<EOF>> FAIL("Premature EOF: `</process>' expected.");
733 }
734
735 <ROOT_argument,S_process_1,S_process,S_process_2>"<argument"{s} {
736   A_argument_value = NULL;
737   ENTER(AL_argument);
738   }
739
740 <AL_argument>{
741  "value"{Eq}\' ENTER(VALUE1); BUFFERSET(A_argument_value);
742  "value"{Eq}\" ENTER(VALUE2); BUFFERSET(A_argument_value);
743
744  ">" {
745   if (!A_argument_value) FAIL("Required attribute `value' not set for `argument' element.");
746   LEAVE; STag_argument();pcdata = NULL; ENTER(E_argument);
747  }
748  "/>" {
749   if (!A_argument_value) FAIL("Required attribute `value' not set for `argument' element.");
750   LEAVE; STag_argument(); pcdata = NULL; ETag_argument();
751   switch (YY_START) {
752    case ROOT_argument: SET(EPILOG); break;
753    case S_process_1: case S_process: case S_process_2: SET(S_process_2); break;
754   }
755  }
756  .       FAIL("Unexpected character `%c' in attribute list of argument element.", yytext[0]);
757  {Name} FAIL("Bad attribute `%s' in `argument' element start tag.",yytext);
758  <<EOF>> FAIL("EOF in attribute list of `argument' element.");
759 }
760
761 <E_argument>{
762  "</argument"{s}">" {
763   LEAVE;
764   ETag_argument();
765   switch (YY_START) {
766    case ROOT_argument: SET(EPILOG); break;
767    case S_process_1: case S_process: case S_process_2: SET(S_process_2); break;
768   }
769  }
770  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</argument>' expected.",yytext);
771  .       FAIL("Unexpected character `%c': `</argument>' expected.",yytext[0]);
772  <<EOF>> FAIL("Premature EOF: `</argument>' expected.");
773 }
774
775  /* EPILOG: after the root element. */
776
777 <EPILOG>{
778  . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
779  <<EOF>>        SUCCEED;
780 }
781
782  /* CHARACTER DATA. */
783
784 <IMPOSSIBLE,VALUE1,VALUE2>{
785  /* Non-defined standard entities... */
786 "&amp;"  BUFFERPUTC('&');
787 "&lt;"   BUFFERPUTC('<');
788 "&gt;"   BUFFERPUTC('>');
789 "&apos;" BUFFERPUTC('\'');
790 "&quot;" BUFFERPUTC('"');
791
792  /* Character entities. */
793  "&#"[[:digit:]]+";"    BUFFERPUTC((unsigned char)atoi(yytext+2));
794  "&#x"[[:xdigit:]]+";"  BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
795 }
796
797 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
798  "\n"           |
799  "\r"           |
800  "\r\n"         |
801  "\n\r"         BUFFERPUTC('\n');
802 }
803
804 <IMPOSSIBLE>{
805  "<![CDATA["    ENTER(CDATA);
806  "]""]>"                FAIL("Unexpected `]""]>' in character data.");
807 }
808
809 <VALUE1>{
810  \'             BUFFERDONE; LEAVE;
811  <<EOF>>        FAIL("EOF in literal (\"'\" expected).");
812 }
813
814 <VALUE2>{
815  \"             BUFFERDONE; LEAVE;
816  <<EOF>>        FAIL("EOF in literal (`\"' expected).");
817 }
818
819 <IMPOSSIBLE,VALUE1,VALUE2>{
820  [^<&]          BUFFERPUTC(yytext[0]);
821  [<&]           FAIL("Spurious `%c' in character data.",yytext[0]);
822 }
823
824 <CDATA>{
825  "]""]>"                LEAVE;
826  /* "]""]"              BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
827  .              BUFFERPUTC(yytext[0]);
828  <<EOF>>        FAIL("EOF in CDATA section.");
829 }
830
831  /* Impossible rules to avoid warnings from flex(1). */
832  /* Ideally, this should be replaced by code in flexml.pl that
833     generates just the states not covered by other rules. */
834 <*>{
835  .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
836 }
837
838 %%
839
840 /* Element context stack lookup. */
841 int element_context(int i)
842 {
843   return (0<i && i<yy_start_stack_depth
844           ? yy_start_stack[yy_start_stack_ptr - i]
845           : 0);
846 }
847
848 #ifdef FLEX_DEBUG
849 void print_yy_stack(char* fmt, ...)
850 {
851   int i = 0; va_list ap; va_start(ap, fmt);
852   vfprintf(stderr, fmt, ap);
853   for (i=1; i<yy_start_stack_ptr; i++)
854     fprintf(stderr, "%s/", statenames[yy_start_stack[i] ]);
855   fprintf(stderr,"%s\n", statenames[YY_START]);
856   va_end(ap);
857 }
858
859 static void debug_enter(int state, const char* statename) {
860   yy_push_state(state);
861   if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
862 }
863
864 static void debug_leave(void) {
865   if (yy_flex_debug) print_yy_stack("--LEAVE : ");
866   yy_pop_state();
867 }
868
869 static void debug_set(int state, const char* statename) {
870   BEGIN(state);
871   if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
872 }
873 #endif
874
875 enum {flexml_max_err_msg_size = 512};
876
877 static char flexml_err_msg[flexml_max_err_msg_size];
878 const char * parse_err_msg()
879 {
880     return flexml_err_msg;
881 }
882
883 static void reset_parse_err_msg()
884 {
885     flexml_err_msg[0] = '\0';
886 }
887
888
889 static void cleanup(void)
890 {
891     if (statenames) {
892         free(statenames);
893         statenames = NULL;
894     }
895 }
896
897
898 static int fail(const char* fmt, ...)
899 {
900     int chars_left, used;
901     va_list ap; va_start(ap, fmt);
902 #ifdef FLEXML_yylineno
903     used = sprintf(flexml_err_msg,
904                    "Invalid XML (XML input line %d, state %d): ",
905                    yylineno, YY_START);
906 #else
907     used = sprintf(flexml_err_msg,
908                    "Invalid XML (state %d): ",
909                    YY_START);
910 #endif
911     chars_left = flexml_max_err_msg_size - used - 1;
912     vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
913     va_end(ap);
914
915 #ifndef FLEXML_quiet_parser
916     /* print directly to sdterr */
917     fprintf(stderr, "%s\n", flexml_err_msg);
918     flexml_err_msg[0] = '\0';
919 #endif
920
921     cleanup();
922
923     return 1;
924 }