handle xml comments and added handling for some possible error conditions
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp
--- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp	2005-01-04 14:02:04 UTC (rev 12787)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp	2005-01-04 14:27:27 UTC (rev 12788)
@@ -234,8 +234,16 @@
 XMLFile::get_token(string& token)
 {
 	const char* tokend;
-	if ( *_p == '<' )
+	if ( !strncmp ( _p, "<!--", 4 ) )
 	{
+		tokend = strstr ( _p, "-->" );
+		if ( !tokend )
+			tokend = _end;
+		else
+			tokend += 3;
+	}
+	else if ( *_p == '<' )
+	{
 		tokend = strchr ( _p, '>' );
 		if ( !tokend )
 			tokend = _end;
@@ -301,8 +309,17 @@
 {
 	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 @@
 	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 @@
 		}
 		return e;
 	}
+	bool bThisMixingErrorReported = false;
 	while ( f.more_tokens() )
 	{
 		if ( f.next_is_text() )
@@ -467,8 +492,11 @@
 				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 @@
 				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 @@
 		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() );