From b6ce86818c0b56fe2ee0a5953a4d4a09fa0811ef Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Tue, 4 Jan 2005 14:27:27 +0000 Subject: [PATCH] handle xml comments and added handling for some possible error conditions svn path=/branches/xmlbuildsystem/; revision=12788 --- reactos/tools/rbuild/rbuild.cpp | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/reactos/tools/rbuild/rbuild.cpp b/reactos/tools/rbuild/rbuild.cpp index 20f5d21cbaf..9564ae5aaf6 100644 --- a/reactos/tools/rbuild/rbuild.cpp +++ b/reactos/tools/rbuild/rbuild.cpp @@ -234,7 +234,15 @@ bool XMLFile::get_token(string& token) { const char* tokend; - if ( *_p == '<' ) + if ( !strncmp ( _p, "" ); + if ( !tokend ) + tokend = _end; + else + tokend += 3; + } + else if ( *_p == '<' ) { tokend = strchr ( _p, '>' ); if ( !tokend ) @@ -301,8 +309,17 @@ XMLElement::Parse(const string& token, { const char* p = token.c_str(); assert ( *p == '<' ); - p++; + ++p; p += strspn ( p, WS ); + + // check if this is a comment + if ( !strncmp ( p, "!--", 3 ) ) + { + name = "!--"; + end_tag = false; + return false; // never look for end tag to a comment + } + end_tag = ( *p == '/' ); if ( end_tag ) { @@ -415,9 +432,16 @@ XMLParse(XMLFile& f, string token; if ( !f.get_token(token) ) return NULL; - XMLElement* e = new XMLElement; bool end_tag; + while ( token[0] != '<' ) + { + printf ( "syntax error: expecting xml tag, not '%s'\n", token.c_str() ); + if ( !f.get_token(token) ) + return NULL; + } + + XMLElement* e = new XMLElement; bool bNeedEnd = e->Parse ( token, end_tag ); if ( e->name == "xi:include" ) @@ -458,6 +482,7 @@ XMLParse(XMLFile& f, } return e; } + bool bThisMixingErrorReported = false; while ( f.more_tokens() ) { if ( f.next_is_text() ) @@ -467,8 +492,11 @@ XMLParse(XMLFile& f, printf ( "internal tool error - get_token() failed when more_tokens() returned true\n" ); break; } - if ( e->subElements.size() ) + if ( e->subElements.size() && !bThisMixingErrorReported ) + { printf ( "syntax error: mixing of inner text with sub elements\n" ); + bThisMixingErrorReported = true; + } if ( e->value.size() ) { printf ( "syntax error: multiple instances of inner text\n" ); @@ -487,6 +515,11 @@ XMLParse(XMLFile& f, delete e2; break; } + if ( e->value.size() && !bThisMixingErrorReported ) + { + printf ( "syntax error: mixing of inner text with sub elements\n" ); + bThisMixingErrorReported = true; + } e->AddSubElement ( e2 ); } } @@ -558,6 +591,9 @@ main ( int argc, char** argv ) if ( !head ) break; // end of file + if ( head->name == "!--" ) + continue; // ignore comments + if ( head->name != "project" ) { printf ( "error: expecting 'project', got '%s'\n", head->name.c_str() );