Logo AND Algorithmique Numérique Distribuée

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