/* Validating XML processor for xbt/graphxml.dtd. * Generated 2007/08/09 10:57:49. * * This program was generated with the FleXML XML processor generator. * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved. * FleXML is Copyright (C) 2003-2006 Martin Quinson. All rights reserved. * (Id: flexml.pl,v 1.61 2006/09/13 16:34:33 wdowling Exp). * * There are two, intertwined parts to this program, part A and part B. * * Part A * ------ * * Some parts, here collectively called "Part A", are found in the * FleXML package. They are Copyright (C) 1999-2005 Kristoffer Rose * and Copyright (C) 2003-2006 Martin Quinson. All rights reserved. * * You can redistribute, use, perform, display and/or modify "Part A" * provided the following two conditions hold: * * 1. The program is distributed WITHOUT ANY WARRANTY from the author of * FleXML; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. * * 2. The program distribution conditions do not in any way affect the * distribution conditions of the FleXML system used to generate this * file or any version of FleXML derived from that system. * * Notice that these are explicit rights granted to you for files * generated by the FleXML system. For your rights in connection with * the FleXML system itself please consult the GNU General Public License. * * Part B * ------ * * The other parts, here collectively called "Part B", and which came * from the DTD used by FleXML to generate this program, can be * distributed (or not, as the case may be) under the terms of whoever * wrote them, provided these terms respect and obey the two conditions * above under the heading "Part A". * * The author of and contributors to FleXML specifically disclaim * any copyright interest in "Part B", unless "Part B" was written * by the author of or contributors to FleXML. * */ %{ /* Version strings. */ const char rcs_graphxml_flexml_skeleton[] = "$" "Id: skel,v 1.38 2006/09/12 18:05:45 wdowling Exp $"; const char rcs_graphxml_flexml[] = "$" "Id: flexml.pl,v 1.61 2006/09/13 16:34:33 wdowling Exp $"; /* ANSI headers. */ #include #include #include #include #include #include #ifndef FLEXML_INDEXSTACKSIZE #define FLEXML_INDEXSTACKSIZE 1000 #endif /* Generated definitions. */ #define FLEXML_yylineno #ifndef FLEXML_BUFFERSTACKSIZE #define FLEXML_BUFFERSTACKSIZE 1000000 #endif #define FLEXML_NEED_BUFFERLIT /* XML processor api. */ /* FleXML-provided data. */ int graphxml_pcdata_ix; extern char *graphxml_bufferstack; #define graphxml_pcdata (graphxml_bufferstack + graphxml_pcdata_ix) AT_graphxml_node_name AX_graphxml_node_name; #define A_graphxml_node_name (graphxml_bufferstack + AX_graphxml_node_name) AT_graphxml_edge_source AX_graphxml_edge_source; #define A_graphxml_edge_source (graphxml_bufferstack + AX_graphxml_edge_source) AT_graphxml_node_position_y AX_graphxml_node_position_y; #define A_graphxml_node_position_y (graphxml_bufferstack + AX_graphxml_node_position_y) AT_graphxml_node_position_x AX_graphxml_node_position_x; #define A_graphxml_node_position_x (graphxml_bufferstack + AX_graphxml_node_position_x) AT_graphxml_edge_data AX_graphxml_edge_data; #define A_graphxml_edge_data (graphxml_bufferstack + AX_graphxml_edge_data) AT_graphxml_edge_target AX_graphxml_edge_target; #define A_graphxml_edge_target (graphxml_bufferstack + AX_graphxml_edge_target) AT_graphxml_graph_isDirected AX_graphxml_graph_isDirected; #define A_graphxml_graph_isDirected AX_graphxml_graph_isDirected AT_graphxml_node_label AX_graphxml_node_label; #define A_graphxml_node_label (graphxml_bufferstack + AX_graphxml_node_label) AT_graphxml_node_data AX_graphxml_node_data; #define A_graphxml_node_data (graphxml_bufferstack + AX_graphxml_node_data) AT_graphxml_edge_label AX_graphxml_edge_label; #define A_graphxml_edge_label (graphxml_bufferstack + AX_graphxml_edge_label) AT_graphxml_edge_length AX_graphxml_edge_length; #define A_graphxml_edge_length (graphxml_bufferstack + AX_graphxml_edge_length) AT_graphxml_edge_name AX_graphxml_edge_name; #define A_graphxml_edge_name (graphxml_bufferstack + AX_graphxml_edge_name) /* XML state. */ #ifdef FLEX_DEBUG # define ENTER(state) debug_enter(state,#state) # define LEAVE debug_leave() # define SET(state) debug_set(state,#state) static void debug_enter(int, const char*); static void debug_leave(void); static void debug_set(int, const char*); #else # define ENTER(state) (yy_push_state(state)) # define LEAVE (yy_pop_state()) # define SET(state) BEGIN(state) #endif /* Generic actions. */ #define SKIP /*skip*/ #define SUCCEED CLEANUP; return 0 #define FAIL return fail static int fail(const char*, ...); enum {flexml_max_err_msg_size = 512}; static char flexml_err_msg[flexml_max_err_msg_size]; const char * graphxml_parse_err_msg() { return flexml_err_msg; } static void reset_graphxml_parse_err_msg() { flexml_err_msg[0] = '\0'; } /* Cleanup */ static void cleanup(void); #define CLEANUP cleanup() /* Text buffer stack handling. */ char *graphxml_bufferstack = NULL; static int blimit = FLEXML_BUFFERSTACKSIZE; static int bnext = 1; static int *indexstack = NULL; static int ilimit = FLEXML_INDEXSTACKSIZE; static int inext = 1; #define BUFFERSET(P) (P = bnext) #define BUFFERPUTC(C) (ck_blimit(), graphxml_bufferstack[bnext++] = (C)) #define BUFFERDONE (BUFFERPUTC('\0')) #define BUFFERLITERAL(C, P) graphxml_bufferliteral(C, &(P), yytext) /* after this is called, there are at least 2 slots left in the stack */ static int ck_blimit() { if (bnext >= blimit) { blimit += FLEXML_BUFFERSTACKSIZE + 2; { char *temp = (char *) realloc(graphxml_bufferstack, blimit); assert(temp); graphxml_bufferstack = temp; } } return 0; } /* after this is called, there are at least 2 slots left in the stack */ static int ck_ilimit() { if (inext >= ilimit) { ilimit += FLEXML_INDEXSTACKSIZE + 2; { int *temp = (int *) realloc(indexstack, ilimit); assert(temp); indexstack = temp; } } return 0; } #ifdef FLEXML_NEED_BUFFERLIT static void graphxml_bufferliteral(char c, int* pp, const char* text) { const char *s = (c ? strchr(text,c) : text-1), *e = strrchr(text,c); assert(s <= e); BUFFERSET(*pp); while (++s= 2); bnext = indexstack[--inext]; return indexstack[--inext]; } /* General internal entities are `unput' back onto the input stream... */ #define ENTITYTEXT(T) \ { char *s = (T), *e = s+strlen(s);\ while (--e >= s) { unput(*e); }} %} /* Flex standard options. */ %option stack %option noyy_top_state %option noinput %option noreject %option noyymore %option noyywrap /* Flex user-requested options. */ %option yylineno %option nounput /* XML character classes (currently restricted to ASCII). */ /* "Common syntactic structures." */ S [ \t\n\r\f]+ s [ \t\n\r\f]* /* "Names and Tokens." */ NameChar [A-Za-z0-9.:_-] Name [A-Za-z_:]{NameChar}* Names {Name}({S}{Name})* Nmtoken ({NameChar})+ Nmtokens {Nmtoken}({S}{Nmtoken})* /* Miscellaneous. */ VersionNum [a-zA-Z0-9_.:-]+ Eq {s}"="{s} Literal \'[^'']*\'|\"[^""]*\" /* Parser states (flex `exclusive start conditions'): * * PROLOG the XML prolog of the document before * DOCTYPE the XML prolog of the document after * EPILOG after the root element * INCOMMENT inside an XML comment * INPI inside an XML PI * VALUE1 inside a '...'-delimited literal * VALUE2 inside a "..."-delimited literal * CDATA inside a section. * ROOT_ expect root element * AL_ inside the attribute list for * IN_ inside a with element contents (ready for end tag) * IMPOSSIBLE dummy to permit disabling rules; must be last */ %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA %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 %x ROOT_graphxml_node AL_graphxml_node E_graphxml_node %x ROOT_graphxml_edge AL_graphxml_edge E_graphxml_edge %x IMPOSSIBLE %{ /* State names. */ const char* *graphxml_statenames=NULL; %} %% /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */ SET(PROLOG); reset_graphxml_parse_err_msg(); graphxml_bufferstack = (char *) malloc(FLEXML_BUFFERSTACKSIZE); assert(graphxml_bufferstack); #ifdef FLEX_DEBUG { int i; for (i = 0; i < blimit; i++) { graphxml_bufferstack[i] = '\377'; } } #endif graphxml_bufferstack[0] = '\0'; indexstack = (int *) malloc(FLEXML_INDEXSTACKSIZE * sizeof(int)); assert(indexstack); indexstack[0] = 0; /* FleXML_init */ bnext = inext = 1; graphxml_bufferliteral('\0', &bnext, "-1.0"); graphxml_bufferliteral('\0', &bnext, "-1.0"); graphxml_bufferliteral('\0', &bnext, "-1.0"); if(!graphxml_statenames) {graphxml_statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*)); graphxml_statenames[PROLOG] = NULL; graphxml_statenames[DOCTYPE] = NULL; graphxml_statenames[EPILOG] = NULL; graphxml_statenames[INCOMMENT] = NULL; graphxml_statenames[INPI] = NULL; graphxml_statenames[VALUE1] = NULL; graphxml_statenames[VALUE2] = NULL; graphxml_statenames[CDATA] = NULL; graphxml_statenames[ROOT_graphxml_graph] = NULL; graphxml_statenames[AL_graphxml_graph] = NULL; graphxml_statenames[S_graphxml_graph] = "graph"; graphxml_statenames[S_graphxml_graph_1] = "graph"; graphxml_statenames[S_graphxml_graph_2] = "graph"; graphxml_statenames[S_graphxml_graph_3] = "graph"; graphxml_statenames[S_graphxml_graph_4] = "graph"; graphxml_statenames[S_graphxml_graph_5] = "graph"; graphxml_statenames[E_graphxml_graph] = "graph"; graphxml_statenames[ROOT_graphxml_node] = NULL; graphxml_statenames[AL_graphxml_node] = NULL; graphxml_statenames[E_graphxml_node] = "node"; graphxml_statenames[ROOT_graphxml_edge] = NULL; graphxml_statenames[AL_graphxml_edge] = NULL; graphxml_statenames[E_graphxml_edge] = "edge"; } /* COMMENTS and PIs: handled uniformly for efficiency. */ { "" LEAVE; "--" | . | \n SKIP; <> FAIL("EOF in comment."); } { "?>" LEAVE; . | \n SKIP; <> FAIL("EOF in PI (processing instruction)."); } /* SPACES: skipped uniformly */ {S} SKIP; /* PROLOG: determine root element and process it. */ { "" SET(DOCTYPE); "]*">" FAIL("Bad declaration %s.",yytext); } { "" SET(ROOT_graphxml_edge); "" SET(ROOT_graphxml_node); "" SET(ROOT_graphxml_graph); "-][^>]*">" FAIL("Bad declaration %s.",yytext); . FAIL("Unexpected character `%c' in prolog.", yytext[0]); <> FAIL("EOF in prolog."); } /* RULES DERIVED FROM DTD. */ /* */ /* isDirected (true|false) "true" * > */ "{ "isDirected"{Eq}"'true'" | "isDirected"{Eq}"\"true\"" A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_true; "isDirected"{Eq}"'false'" | "isDirected"{Eq}"\"false\"" A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_false; ">" { LEAVE; STag_graphxml_graph();graphxml_pcdata_ix = 0; ENTER(S_graphxml_graph); } "/>" { LEAVE; STag_graphxml_graph(); graphxml_pcdata_ix = 0; ETag_graphxml_graph(); popbuffer(); /* attribute */ switch (YY_START) { case ROOT_graphxml_graph: SET(EPILOG); break; } } . FAIL("Unexpected character `%c' in attribute list of graph element.", yytext[0]); {Name} FAIL("Bad attribute `%s' in `graph' element start tag.",yytext); <> FAIL("EOF in attribute list of `graph' element."); } { "" { LEAVE; ETag_graphxml_graph(); popbuffer(); /* attribute */ switch (YY_START) { case ROOT_graphxml_graph: SET(EPILOG); break; } } "" FAIL("Unexpected end-tag `%s': `' expected.",yytext); . FAIL("Unexpected character `%c': `' expected.",yytext[0]); <> FAIL("Premature EOF: `' expected."); } /* label CDATA "" * name CDATA #REQUIRED * data CDATA "" * position_x CDATA "-1.0" * position_y CDATA "-1.0" * > */ "{ "label"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_label); "label"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_label); "name"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_name); "name"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_name); "data"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_data); "data"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_data); "position_x"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_position_x); "position_x"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_position_x); "position_y"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_position_y); "position_y"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_position_y); ">" { if (!AX_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element."); LEAVE; STag_graphxml_node();graphxml_pcdata_ix = 0; ENTER(E_graphxml_node); } "/>" { if (!AX_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element."); LEAVE; STag_graphxml_node(); graphxml_pcdata_ix = 0; ETag_graphxml_node(); popbuffer(); /* attribute */ switch (YY_START) { case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break; case ROOT_graphxml_node: SET(EPILOG); break; } } . FAIL("Unexpected character `%c' in attribute list of node element.", yytext[0]); {Name} FAIL("Bad attribute `%s' in `node' element start tag.",yytext); <> FAIL("EOF in attribute list of `node' element."); } { "" { LEAVE; ETag_graphxml_node(); popbuffer(); /* attribute */ switch (YY_START) { case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break; case ROOT_graphxml_node: SET(EPILOG); break; } } "" FAIL("Unexpected end-tag `%s': `' expected.",yytext); . FAIL("Unexpected character `%c': `' expected.",yytext[0]); <> FAIL("Premature EOF: `' expected."); } /* label CDATA "" * name CDATA #IMPLIED * source CDATA #REQUIRED * target CDATA #REQUIRED * length CDATA "-1.0" * data CDATA "" * > */ "{ "label"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_label); "label"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_label); "name"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_name); "name"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_name); "source"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_source); "source"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_source); "target"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_target); "target"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_target); "length"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_length); "length"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_length); "data"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_data); "data"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_data); ">" { if (!AX_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element."); if (!AX_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element."); LEAVE; STag_graphxml_edge();graphxml_pcdata_ix = 0; ENTER(E_graphxml_edge); } "/>" { if (!AX_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element."); if (!AX_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element."); LEAVE; STag_graphxml_edge(); graphxml_pcdata_ix = 0; ETag_graphxml_edge(); popbuffer(); /* attribute */ switch (YY_START) { 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; case ROOT_graphxml_edge: SET(EPILOG); break; } } . FAIL("Unexpected character `%c' in attribute list of edge element.", yytext[0]); {Name} FAIL("Bad attribute `%s' in `edge' element start tag.",yytext); <> FAIL("EOF in attribute list of `edge' element."); } { "" { LEAVE; ETag_graphxml_edge(); popbuffer(); /* attribute */ switch (YY_START) { 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; case ROOT_graphxml_edge: SET(EPILOG); break; } } "" FAIL("Unexpected end-tag `%s': `' expected.",yytext); . FAIL("Unexpected character `%c': `' expected.",yytext[0]); <> FAIL("Premature EOF: `' expected."); } /* EPILOG: after the root element. */ { . {SET(PROLOG); yyless(0); CLEANUP; return -1;} <> SUCCEED; } /* CHARACTER DATA. */ { /* Non-defined standard entities... */ "&" BUFFERPUTC('&'); "<" BUFFERPUTC('<'); ">" BUFFERPUTC('>'); "'" BUFFERPUTC('\''); """ BUFFERPUTC('"'); /* Character entities. */ "&#"[[:digit:]]+";" BUFFERPUTC((unsigned char)atoi(yytext+2)); "&#x"[[:xdigit:]]+";" BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16)); } { "\n" | "\r" | "\r\n" | "\n\r" BUFFERPUTC('\n'); } { "" FAIL("Unexpected `]""]>' in character data."); } { \' BUFFERDONE; LEAVE; <> FAIL("EOF in literal (\"'\" expected)."); } { \" BUFFERDONE; LEAVE; <> FAIL("EOF in literal (`\"' expected)."); } { [^<&] BUFFERPUTC(yytext[0]); [<&] FAIL("Spurious `%c' in character data.",yytext[0]); } { "]""]>" LEAVE; /* "]""]" BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */ . BUFFERPUTC(yytext[0]); <> FAIL("EOF in CDATA section."); } /* Impossible rules to avoid warnings from flex(1). */ /* Ideally, this should be replaced by code in flexml.pl that generates just the states not covered by other rules. */ <*>{ .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]); } %% /* Element context stack lookup. */ int graphxml_element_context(int i) { return (0