Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
194efb8abbe72ae41d9fe5d579b6ada754a1185f
[simgrid.git] / src / xbt / graphxml.l
1 /* Validating XML processor for graphxml.dtd.
2  * Generated 2006/03/21 13:43:39.
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.47 2006/03/21 11:12:57 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_graphxml_flexml_skeleton[] =
51  "$" "Id: skel,v 1.28 2006/03/21 12:04:13 legranda Exp $";
52 const char rcs_graphxml_flexml[] =
53  "$" "Id: flexml.pl,v 1.47 2006/03/21 11:12:57 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_graphxml_node_name A_graphxml_node_name;
71 AT_graphxml_edge_source A_graphxml_edge_source;
72 AT_graphxml_edge_isDirected A_graphxml_edge_isDirected;
73 AT_graphxml_edge_target A_graphxml_edge_target;
74 AT_graphxml_node_label A_graphxml_node_label;
75 AT_graphxml_edge_label A_graphxml_edge_label;
76 AT_graphxml_edge_name A_graphxml_edge_name;
77 AT_graphxml_edge_length A_graphxml_edge_length;
78
79 /* XML state. */
80 #ifdef FLEX_DEBUG
81 # define ENTER(state)   debug_enter(state,#state)
82 # define LEAVE          debug_leave()
83 # define SET(state)     debug_set(state,#state)
84   static void debug_enter(int, const char*);
85   static void debug_leave(void);
86   static void debug_set(int, const char*);
87 #else
88 # define ENTER(state)   (yy_push_state(state))
89 # define LEAVE          (yy_pop_state())
90 # define SET(state)     BEGIN(state)
91 #endif
92
93 /* Generic actions. */
94 #define SKIP    /*skip*/
95 #define SUCCEED        CLEANUP; return 0
96
97 #define FAIL    return fail
98 static int fail(const char*, ...);
99 const char * graphxml_parse_err_msg(void);
100
101 /* Cleanup */
102 static void cleanup(void);
103 #define CLEANUP  cleanup()
104
105 /* Text buffer stack handling. */
106 char bufferstack[FLEXML_BUFFERSTACKSIZE];
107 static char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE;
108 typedef struct BufferLast_s {
109   struct BufferLast_s *old; char* saved; char new1[1];
110 } BufferLast;
111 #ifdef FLEXML_HasMixed
112 static BufferLast* last = (BufferLast*)0;
113 #endif
114 static char* next = bufferstack;
115
116 #define BUFFERSET(P)  (P = next)
117 #define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
118 #define BUFFERDONE    (BUFFERPUTC('\0'))
119
120 #define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
121 static void bufferliteral(char c, const char** pp, char* text)
122 {
123   char *s = strchr(text,c), *e = strrchr(text,c);
124   assert(s <= e); BUFFERSET(*pp);
125   while (++s<e) {
126     if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
127     else BUFFERPUTC(*s);
128   }
129   BUFFERDONE;
130 }
131
132 #ifdef FLEXML_HasMixed
133 static void pushbuffer(char* p)
134 {
135   BufferLast* l = (BufferLast*)next;
136   assert(next < limit);
137   l->old = last;
138   l->saved = p;
139   next = l->new1;
140   last = l;
141 }
142
143 static char* popbuffer(void)
144 {
145   BufferLast* l = last;
146   assert(last != (BufferLast*)0);
147   last = l->old;
148   next = (char*)l;
149   return l->saved;
150 }
151 #endif
152
153 /* General internal entities are `unput' back onto the input stream... */
154 #define ENTITYTEXT(T) \
155   { char *s = (T), *e = s+strlen(s);\
156     while (--e >= s) { unput(*e); }}
157 %}
158
159 /* Flex standard options. */
160 %option stack
161 %option noyy_top_state
162 %option noinput
163 %option noreject
164 %option noyymore
165 %option noyywrap
166
167 /* Flex user-requested options. */
168 %option yylineno
169 %option nounput
170
171 /* XML character classes (currently restricted to ASCII). */
172
173 /* "Common syntactic structures." */
174 S               [ \t\n\r\f]+
175 s               [ \t\n\r\f]*
176
177 /* "Names and Tokens." */
178 NameChar        [A-Za-z0-9.:_-]
179 Name            [A-Za-z_:]{NameChar}*
180 Names           {Name}({S}{Name})*
181 Nmtoken         ({NameChar})+
182 Nmtokens        {Nmtoken}({S}{Nmtoken})*
183
184 /* Miscellaneous. */
185 VersionNum      [a-zA-Z0-9_.:-]+
186 Eq              {s}"="{s}
187 Literal         \'[^'']*\'|\"[^""]*\"
188
189 /* Parser states (flex `exclusive start conditions'):
190  *
191  * PROLOG       the XML prolog of the document before <?xml...>
192  * DOCTYPE      the XML prolog of the document after <?xml...>
193  * EPILOG       after the root element
194  * INCOMMENT    inside an XML comment <!--....-->
195  * INPI         inside an XML PI <?...?>
196  * VALUE1       inside a '...'-delimited literal
197  * VALUE2       inside a "..."-delimited literal
198  * CDATA        inside a <![CDATA[...] ]> section.
199  * ROOT_<tag>   expect root element <tag>
200  * AL_<tag>     inside the attribute list for <tag>
201  * IN_<tag>     inside a <tag> with element contents (ready for end tag)
202  * IMPOSSIBLE   dummy to permit disabling rules; must be last
203  */
204 %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
205 %x ROOT_graphxml_graph AL_graphxml_graph S_graphxml_graph S_graphxml_graph_1 S_graphxml_graph_2 S_graphxml_graph_3 S_graphxml_graph_4 S_graphxml_graph_5 E_graphxml_graph
206 %x ROOT_graphxml_node AL_graphxml_node E_graphxml_node
207 %x ROOT_graphxml_edge AL_graphxml_edge E_graphxml_edge
208 %x IMPOSSIBLE
209
210 %{
211 /* State names. */
212 const char* *graphxml_statenames=NULL;
213 %}
214
215 %%
216
217  /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
218  SET(PROLOG);
219   /* FleXML_init */
220   next = bufferstack;
221   if(!graphxml_statenames) {graphxml_statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*));
222   graphxml_statenames[PROLOG] = NULL;
223   graphxml_statenames[DOCTYPE] = NULL;
224   graphxml_statenames[EPILOG] = NULL;
225   graphxml_statenames[INCOMMENT] = NULL;
226   graphxml_statenames[INPI] = NULL;
227   graphxml_statenames[VALUE1] = NULL;
228   graphxml_statenames[VALUE2] = NULL;
229   graphxml_statenames[CDATA] = NULL;
230   graphxml_statenames[ROOT_graphxml_graph] = NULL;
231   graphxml_statenames[AL_graphxml_graph] = NULL;
232   graphxml_statenames[S_graphxml_graph] = "graph";
233   graphxml_statenames[S_graphxml_graph_1] = "graph";
234   graphxml_statenames[S_graphxml_graph_2] = "graph";
235   graphxml_statenames[S_graphxml_graph_3] = "graph";
236   graphxml_statenames[S_graphxml_graph_4] = "graph";
237   graphxml_statenames[S_graphxml_graph_5] = "graph";
238   graphxml_statenames[E_graphxml_graph] = "graph";
239   graphxml_statenames[ROOT_graphxml_node] = NULL;
240   graphxml_statenames[AL_graphxml_node] = NULL;
241   graphxml_statenames[E_graphxml_node] = "node";
242   graphxml_statenames[ROOT_graphxml_edge] = NULL;
243   graphxml_statenames[AL_graphxml_edge] = NULL;
244   graphxml_statenames[E_graphxml_edge] = "edge";
245   }
246
247  /* COMMENTS and PIs: handled uniformly for efficiency. */
248
249 <ROOT_graphxml_graph,AL_graphxml_graph,S_graphxml_graph,S_graphxml_graph_1,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph_4,S_graphxml_graph_5,E_graphxml_graph,ROOT_graphxml_node,AL_graphxml_node,E_graphxml_node,ROOT_graphxml_edge,AL_graphxml_edge,E_graphxml_edge,PROLOG,DOCTYPE,EPILOG>{
250  "<!--" ENTER(INCOMMENT);
251  "<?" ENTER(INPI);
252 }
253 <INCOMMENT>{
254  "-->"          LEAVE;
255  "--"           |
256  .              |
257  \n             SKIP;
258  <<EOF>>        FAIL("EOF in comment.");
259 }
260 <INPI>{
261  "?>"           LEAVE;
262  .              |
263  \n             SKIP;
264  <<EOF>>        FAIL("EOF in PI (processing instruction).");
265 }
266
267  /* SPACES: skipped uniformly */
268
269 <ROOT_graphxml_graph,AL_graphxml_graph,S_graphxml_graph,S_graphxml_graph_1,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph_4,S_graphxml_graph_5,E_graphxml_graph,ROOT_graphxml_node,AL_graphxml_node,E_graphxml_node,ROOT_graphxml_edge,AL_graphxml_edge,E_graphxml_edge,PROLOG,DOCTYPE,EPILOG>{S} SKIP;
270
271  /* PROLOG: determine root element and process it. */
272
273 <PROLOG>{
274  "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE); 
275  "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
276 }
277
278 <PROLOG,DOCTYPE>{
279  "<!DOCTYPE"{S}"edge"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_edge);
280  "<!DOCTYPE"{S}"node"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_node);
281  "<!DOCTYPE"{S}"graph"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_graph);
282  "<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
283  .              FAIL("Unexpected character `%c' in prolog.", yytext[0]);
284  <<EOF>>        FAIL("EOF in prolog.");
285 }
286
287  /* RULES DERIVED FROM DTD. */
288
289  /* <!-- Small DTD for xbt graphs. -->  */
290
291 <ROOT_graphxml_graph>"<graph"{s} {
292   ENTER(AL_graphxml_graph);
293   }
294
295 <AL_graphxml_graph>{
296  ">" {
297   LEAVE; STag_graphxml_graph();pcdata = NULL; ENTER(S_graphxml_graph);
298  }
299  "/>" {
300   LEAVE; STag_graphxml_graph(); pcdata = NULL; ETag_graphxml_graph();
301   switch (YY_START) {
302    case ROOT_graphxml_graph: SET(EPILOG); break;
303   }
304  }
305  .       FAIL("Unexpected character `%c' in attribute list of graph element.", yytext[0]);
306  {Name} FAIL("Bad attribute `%s' in `graph' element start tag.",yytext);
307  <<EOF>> FAIL("EOF in attribute list of `graph' element.");
308 }
309
310 <S_graphxml_graph_1,E_graphxml_graph,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph>{
311  "</graph"{s}">" {
312   LEAVE;
313   ETag_graphxml_graph();
314   switch (YY_START) {
315    case ROOT_graphxml_graph: SET(EPILOG); break;
316   }
317  }
318  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</graph>' expected.",yytext);
319  .       FAIL("Unexpected character `%c': `</graph>' expected.",yytext[0]);
320  <<EOF>> FAIL("Premature EOF: `</graph>' expected.");
321 }
322
323  /*     label           CDATA                ""
324   *     name            CDATA                #REQUIRED
325   * >  */
326
327 <ROOT_graphxml_node,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph>"<node"{s} {
328   A_graphxml_node_label = NULL;
329   A_graphxml_node_name = NULL;
330   ENTER(AL_graphxml_node);
331   }
332
333 <AL_graphxml_node>{
334  "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_label);
335  "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_label);
336
337  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_name);
338  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_name);
339
340  ">" {
341   if (!A_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
342   LEAVE; STag_graphxml_node();pcdata = NULL; ENTER(E_graphxml_node);
343  }
344  "/>" {
345   if (!A_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
346   LEAVE; STag_graphxml_node(); pcdata = NULL; ETag_graphxml_node();
347   switch (YY_START) {
348    case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
349    case ROOT_graphxml_node: SET(EPILOG); break;
350   }
351  }
352  .       FAIL("Unexpected character `%c' in attribute list of node element.", yytext[0]);
353  {Name} FAIL("Bad attribute `%s' in `node' element start tag.",yytext);
354  <<EOF>> FAIL("EOF in attribute list of `node' element.");
355 }
356
357 <E_graphxml_node>{
358  "</node"{s}">" {
359   LEAVE;
360   ETag_graphxml_node();
361   switch (YY_START) {
362    case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
363    case ROOT_graphxml_node: SET(EPILOG); break;
364   }
365  }
366  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</node>' expected.",yytext);
367  .       FAIL("Unexpected character `%c': `</node>' expected.",yytext[0]);
368  <<EOF>> FAIL("Premature EOF: `</node>' expected.");
369 }
370
371  /*     label           CDATA                ""
372   *     name       CDATA        #IMPLIED
373   *     source     CDATA        #REQUIRED
374   *     target     CDATA        #REQUIRED
375   *     length     CDATA        "0.0"
376   *     isDirected (true|false) "true"
377   * >  */
378
379 <ROOT_graphxml_edge,S_graphxml_graph_1,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph_4,S_graphxml_graph>"<edge"{s} {
380   A_graphxml_edge_label = NULL;
381   A_graphxml_edge_name = NULL;
382   A_graphxml_edge_source = NULL;
383   A_graphxml_edge_target = NULL;
384   A_graphxml_edge_length = "0.0";
385   A_graphxml_edge_isDirected = A_graphxml_edge_isDirected_true;
386   ENTER(AL_graphxml_edge);
387   }
388
389 <AL_graphxml_edge>{
390  "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_label);
391  "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_label);
392
393  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_name);
394  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_name);
395
396  "source"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_source);
397  "source"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_source);
398
399  "target"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_target);
400  "target"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_target);
401
402  "length"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_length);
403  "length"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_length);
404
405  "isDirected"{Eq}"'true'" |
406  "isDirected"{Eq}"\"true\"" A_graphxml_edge_isDirected = A_graphxml_edge_isDirected_true;
407  "isDirected"{Eq}"'false'" |
408  "isDirected"{Eq}"\"false\"" A_graphxml_edge_isDirected = A_graphxml_edge_isDirected_false;
409
410  ">" {
411   if (!A_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
412   if (!A_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
413   LEAVE; STag_graphxml_edge();pcdata = NULL; ENTER(E_graphxml_edge);
414  }
415  "/>" {
416   if (!A_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
417   if (!A_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
418   LEAVE; STag_graphxml_edge(); pcdata = NULL; ETag_graphxml_edge();
419   switch (YY_START) {
420    case S_graphxml_graph_1: case S_graphxml_graph_3: case S_graphxml_graph_5: case S_graphxml_graph_4: case S_graphxml_graph: SET(S_graphxml_graph_5); break;
421    case ROOT_graphxml_edge: SET(EPILOG); break;
422   }
423  }
424  .       FAIL("Unexpected character `%c' in attribute list of edge element.", yytext[0]);
425  {Name} FAIL("Bad attribute `%s' in `edge' element start tag.",yytext);
426  <<EOF>> FAIL("EOF in attribute list of `edge' element.");
427 }
428
429 <E_graphxml_edge>{
430  "</edge"{s}">" {
431   LEAVE;
432   ETag_graphxml_edge();
433   switch (YY_START) {
434    case S_graphxml_graph_1: case S_graphxml_graph_3: case S_graphxml_graph_5: case S_graphxml_graph_4: case S_graphxml_graph: SET(S_graphxml_graph_5); break;
435    case ROOT_graphxml_edge: SET(EPILOG); break;
436   }
437  }
438  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</edge>' expected.",yytext);
439  .       FAIL("Unexpected character `%c': `</edge>' expected.",yytext[0]);
440  <<EOF>> FAIL("Premature EOF: `</edge>' expected.");
441 }
442
443  /* EPILOG: after the root element. */
444
445 <EPILOG>{
446  . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
447  <<EOF>>        SUCCEED;
448 }
449
450  /* CHARACTER DATA. */
451
452 <IMPOSSIBLE,VALUE1,VALUE2>{
453  /* Non-defined standard entities... */
454 "&amp;"  BUFFERPUTC('&');
455 "&lt;"   BUFFERPUTC('<');
456 "&gt;"   BUFFERPUTC('>');
457 "&apos;" BUFFERPUTC('\'');
458 "&quot;" BUFFERPUTC('"');
459
460  /* Character entities. */
461  "&#"[[:digit:]]+";"    BUFFERPUTC((unsigned char)atoi(yytext+2));
462  "&#x"[[:xdigit:]]+";"  BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
463 }
464
465 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
466  "\n"           |
467  "\r"           |
468  "\r\n"         |
469  "\n\r"         BUFFERPUTC('\n');
470 }
471
472 <IMPOSSIBLE>{
473  "<![CDATA["    ENTER(CDATA);
474  "]""]>"                FAIL("Unexpected `]""]>' in character data.");
475 }
476
477 <VALUE1>{
478  \'             BUFFERDONE; LEAVE;
479  <<EOF>>        FAIL("EOF in literal (\"'\" expected).");
480 }
481
482 <VALUE2>{
483  \"             BUFFERDONE; LEAVE;
484  <<EOF>>        FAIL("EOF in literal (`\"' expected).");
485 }
486
487 <IMPOSSIBLE,VALUE1,VALUE2>{
488  [^<&]          BUFFERPUTC(yytext[0]);
489  [<&]           FAIL("Spurious `%c' in character data.",yytext[0]);
490 }
491
492 <CDATA>{
493  "]""]>"                LEAVE;
494  /* "]""]"              BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
495  .              BUFFERPUTC(yytext[0]);
496  <<EOF>>        FAIL("EOF in CDATA section.");
497 }
498
499  /* Impossible rules to avoid warnings from flex(1). */
500  /* Ideally, this should be replaced by code in flexml.pl that
501     generates just the states not covered by other rules. */
502 <*>{
503  .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
504 }
505
506 %%
507
508 /* Element context stack lookup. */
509 int graphxml_element_context(int i)
510 {
511   return (0<i && i<yy_start_stack_depth
512           ? yy_start_stack[yy_start_stack_ptr - i]
513           : 0);
514 }
515
516 #ifdef FLEX_DEBUG
517 void print_yy_stack(char* fmt, ...)
518 {
519   int i = 0; va_list ap; va_start(ap, fmt);
520   vfprintf(stderr, fmt, ap);
521   for (i=1; i<yy_start_stack_ptr; i++)
522     fprintf(stderr, "%s/", graphxml_statenames[yy_start_stack[i] ]);
523   fprintf(stderr,"%s\n", graphxml_statenames[YY_START]);
524   va_end(ap);
525 }
526
527 static void debug_enter(int state, const char* statename) {
528   yy_push_state(state);
529   if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
530 }
531
532 static void debug_leave(void) {
533   if (yy_flex_debug) print_yy_stack("--LEAVE : ");
534   yy_pop_state();
535 }
536
537 static void debug_set(int state, const char* statename) {
538   BEGIN(state);
539   if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
540 }
541 #endif
542
543 enum {flexml_max_err_msg_size = 512};
544
545 static char flexml_err_msg[flexml_max_err_msg_size];
546 const char * graphxml_parse_err_msg()
547 {
548     return flexml_err_msg;
549 }
550
551 static void reset_graphxml_parse_err_msg()
552 {
553     flexml_err_msg[0] = '\0';
554 }
555
556
557 static void cleanup(void)
558 {
559     if (graphxml_statenames) {
560         free(graphxml_statenames);
561         graphxml_statenames = NULL;
562     }
563 }
564
565
566 static int fail(const char* fmt, ...)
567 {
568     int chars_left, used;
569     va_list ap; va_start(ap, fmt);
570 #ifdef FLEXML_yylineno
571     used = sprintf(flexml_err_msg,
572                    "Invalid XML (XML input line %d, state %d): ",
573                    yylineno, YY_START);
574 #else
575     used = sprintf(flexml_err_msg,
576                    "Invalid XML (state %d): ",
577                    YY_START);
578 #endif
579     chars_left = flexml_max_err_msg_size - used - 1;
580     vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
581     va_end(ap);
582
583 #ifndef FLEXML_quiet_parser
584     /* print directly to sdterr */
585     fprintf(stderr, "%s\n", flexml_err_msg);
586     flexml_err_msg[0] = '\0';
587 #endif
588
589     cleanup();
590
591     return 1;
592 }