file & line # reporting on xml syntax errors
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/XML.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/XML.h
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/XML.cpp
--- branches/xmlbuildsystem/reactos/tools/rbuild/XML.cpp	2005-01-06 01:35:01 UTC (rev 12843)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/XML.cpp	2005-01-06 02:06:44 UTC (rev 12844)
@@ -7,7 +7,8 @@
 #include <assert.h>
 
 #include "XML.h"
-#include "rbuild.h"
+#include "exception.h"
+#include "ssprintf.h"
 
 using std::string;
 using std::vector;
@@ -274,6 +275,19 @@
 	return true;
 }
 
+string
+XMLFile::Location() const
+{
+	int line = 1;
+	const char* p = strchr ( _buf.c_str(), '\n' );
+	while ( p && p < _p )
+	{
+		++line;
+		p = strchr ( p+1, '\n' );
+	}
+	return ssprintf ( "%s(%i)",_filename.c_str(), line );
+}
+
 XMLAttribute::XMLAttribute()
 {
 }
@@ -445,7 +459,9 @@
 	while ( token[0] != '<' || !strncmp ( token.c_str(), "<!--", 4 ) )
 	{
 		if ( token[0] != '<' )
-			printf ( "syntax error: expecting xml tag, not '%s'\n", token.c_str() );
+			throw XMLSyntaxErrorException ( f.Location(),
+			                                "expecting xml tag, not '%s'",
+			                                token.c_str() );
 		if ( !f.get_token(token) )
 			return NULL;
 	}
@@ -464,7 +480,10 @@
 		e->attributes.push_back ( new XMLAttribute ( "top_href", top_file ) );
 		XMLFile fInc;
 		if ( !fInc.open ( file ) )
-			throw FileNotFoundException ( file );
+			throw FileNotFoundException (
+				ssprintf("%s (referenced from %s)",
+					file.c_str(),
+					f.Location().c_str() ) );
 		else
 		{
 			Path path2 ( path, att->value );
@@ -485,7 +504,9 @@
 		else if ( end_tag )
 		{
 			delete e;
-			printf ( "syntax error: end tag '%s' not expected\n", token.c_str() );
+			throw XMLSyntaxErrorException ( f.Location(),
+			                                "end tag '%s' not expected",
+			                                token.c_str() );
 			return NULL;
 		}
 		return e;
@@ -497,17 +518,24 @@
 		{
 			if ( !f.get_token ( token ) || !token.size() )
 			{
-				printf ( "internal tool error - get_token() failed when more_tokens() returned true\n" );
+				throw Exception ( "internal tool error - get_token() failed when more_tokens() returned true" );
 				break;
 			}
 			if ( e->subElements.size() && !bThisMixingErrorReported )
 			{
-				printf ( "syntax error: mixing of inner text with sub elements\n" );
+				throw XMLSyntaxErrorException ( f.Location(),
+				                                "mixing of inner text with sub elements" );
 				bThisMixingErrorReported = true;
 			}
+			if ( strchr ( token.c_str(), '>' ) )
+			{
+				throw XMLSyntaxErrorException ( f.Location(),
+				                                "invalid symbol '>'" );
+			}
 			if ( e->value.size() )
 			{
-				printf ( "syntax error: multiple instances of inner text\n" );
+				throw XMLSyntaxErrorException ( f.Location(),
+				                                "multiple instances of inner text" );
 				e->value += " " + token;
 			}
 			else
@@ -519,13 +547,15 @@
 			if ( end_tag )
 			{
 				if ( e->name != e2->name )
-					printf ( "syntax error: end tag name mismatch\n" );
+					throw XMLSyntaxErrorException ( f.Location(),
+					                                "end tag name mismatch" );
 				delete e2;
 				break;
 			}
 			if ( e->value.size() && !bThisMixingErrorReported )
 			{
-				printf ( "syntax error: mixing of inner text with sub elements\n" );
+				throw XMLSyntaxErrorException ( f.Location(),
+				                                "mixing of inner text with sub elements" );
 				bThisMixingErrorReported = true;
 			}
 			e->AddSubElement ( e2 );

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/XML.h
--- branches/xmlbuildsystem/reactos/tools/rbuild/XML.h	2005-01-06 01:35:01 UTC (rev 12843)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/XML.h	2005-01-06 02:06:44 UTC (rev 12844)
@@ -35,6 +35,7 @@
 	bool more_tokens();
 	bool get_token(std::string& token);
 	const std::string& filename() { return _filename; }
+	std::string Location() const;
 
 private:
 	std::string _buf, _filename;

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp
--- branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp	2005-01-06 01:35:01 UTC (rev 12843)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp	2005-01-06 02:06:44 UTC (rev 12844)
@@ -56,7 +56,22 @@
 	va_end(args);
 }
 
+InvalidBuildFileException::InvalidBuildFileException()
+{
+}
 
+
+XMLSyntaxErrorException::XMLSyntaxErrorException ( const std::string& location,
+	                                               const char* message,
+	                                               ... )
+{
+	va_list args;
+	va_start ( args, message );
+	Message = location + ": " + ssvprintf ( message, args );
+	va_end ( args );
+}
+
+
 RequiredAttributeNotFoundException::RequiredAttributeNotFoundException(const std::string& attributeName,
                                                                        const std::string& elementName)
 	: InvalidBuildFileException ( "Required attribute '%s' not found on '%s'.",

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h
--- branches/xmlbuildsystem/reactos/tools/rbuild/exception.h	2005-01-06 01:35:01 UTC (rev 12843)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.h	2005-01-06 02:06:44 UTC (rev 12844)
@@ -36,11 +36,22 @@
 class InvalidBuildFileException : public Exception
 {
 public:
-	InvalidBuildFileException(const char* message,
-	                          ...);
+	InvalidBuildFileException ( const char* message,
+	                            ...);
+protected:
+	InvalidBuildFileException();
 };
 
 
+class XMLSyntaxErrorException : public InvalidBuildFileException
+{
+public:
+	XMLSyntaxErrorException ( const std::string& location,
+	                          const char* message,
+	                          ... );
+};
+
+
 class RequiredAttributeNotFoundException : public InvalidBuildFileException
 {
 public: