svn path=/branches/xmlbuildsystem/; revision=12844
#include <assert.h>\r
\r
#include "XML.h"\r
#include <assert.h>\r
\r
#include "XML.h"\r
+#include "exception.h"\r
+#include "ssprintf.h"\r
\r
using std::string;\r
using std::vector;\r
\r
using std::string;\r
using std::vector;\r
+string\r
+XMLFile::Location() const\r
+{\r
+ int line = 1;\r
+ const char* p = strchr ( _buf.c_str(), '\n' );\r
+ while ( p && p < _p )\r
+ {\r
+ ++line;\r
+ p = strchr ( p+1, '\n' );\r
+ }\r
+ return ssprintf ( "%s(%i)",_filename.c_str(), line );\r
+}\r
+\r
XMLAttribute::XMLAttribute()\r
{\r
}\r
XMLAttribute::XMLAttribute()\r
{\r
}\r
while ( token[0] != '<' || !strncmp ( token.c_str(), "<!--", 4 ) )\r
{\r
if ( token[0] != '<' )\r
while ( token[0] != '<' || !strncmp ( token.c_str(), "<!--", 4 ) )\r
{\r
if ( token[0] != '<' )\r
- printf ( "syntax error: expecting xml tag, not '%s'\n", token.c_str() );\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "expecting xml tag, not '%s'",\r
+ token.c_str() );\r
if ( !f.get_token(token) )\r
return NULL;\r
}\r
if ( !f.get_token(token) )\r
return NULL;\r
}\r
e->attributes.push_back ( new XMLAttribute ( "top_href", top_file ) );\r
XMLFile fInc;\r
if ( !fInc.open ( file ) )\r
e->attributes.push_back ( new XMLAttribute ( "top_href", top_file ) );\r
XMLFile fInc;\r
if ( !fInc.open ( file ) )\r
- throw FileNotFoundException ( file );\r
+ throw FileNotFoundException (\r
+ ssprintf("%s (referenced from %s)",\r
+ file.c_str(),\r
+ f.Location().c_str() ) );\r
else\r
{\r
Path path2 ( path, att->value );\r
else\r
{\r
Path path2 ( path, att->value );\r
else if ( end_tag )\r
{\r
delete e;\r
else if ( end_tag )\r
{\r
delete e;\r
- printf ( "syntax error: end tag '%s' not expected\n", token.c_str() );\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "end tag '%s' not expected",\r
+ token.c_str() );\r
return NULL;\r
}\r
return e;\r
return NULL;\r
}\r
return e;\r
{\r
if ( !f.get_token ( token ) || !token.size() )\r
{\r
{\r
if ( !f.get_token ( token ) || !token.size() )\r
{\r
- printf ( "internal tool error - get_token() failed when more_tokens() returned true\n" );\r
+ throw Exception ( "internal tool error - get_token() failed when more_tokens() returned true" );\r
break;\r
}\r
if ( e->subElements.size() && !bThisMixingErrorReported )\r
{\r
break;\r
}\r
if ( e->subElements.size() && !bThisMixingErrorReported )\r
{\r
- printf ( "syntax error: mixing of inner text with sub elements\n" );\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "mixing of inner text with sub elements" );\r
bThisMixingErrorReported = true;\r
}\r
bThisMixingErrorReported = true;\r
}\r
+ if ( strchr ( token.c_str(), '>' ) )\r
+ {\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "invalid symbol '>'" );\r
+ }\r
if ( e->value.size() )\r
{\r
if ( e->value.size() )\r
{\r
- printf ( "syntax error: multiple instances of inner text\n" );\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "multiple instances of inner text" );\r
e->value += " " + token;\r
}\r
else\r
e->value += " " + token;\r
}\r
else\r
if ( end_tag )\r
{\r
if ( e->name != e2->name )\r
if ( end_tag )\r
{\r
if ( e->name != e2->name )\r
- printf ( "syntax error: end tag name mismatch\n" );\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "end tag name mismatch" );\r
delete e2;\r
break;\r
}\r
if ( e->value.size() && !bThisMixingErrorReported )\r
{\r
delete e2;\r
break;\r
}\r
if ( e->value.size() && !bThisMixingErrorReported )\r
{\r
- printf ( "syntax error: mixing of inner text with sub elements\n" );\r
+ throw XMLSyntaxErrorException ( f.Location(),\r
+ "mixing of inner text with sub elements" );\r
bThisMixingErrorReported = true;\r
}\r
e->AddSubElement ( e2 );\r
bThisMixingErrorReported = true;\r
}\r
e->AddSubElement ( e2 );\r
bool more_tokens();\r
bool get_token(std::string& token);\r
const std::string& filename() { return _filename; }\r
bool more_tokens();\r
bool get_token(std::string& token);\r
const std::string& filename() { return _filename; }\r
+ std::string Location() const;\r
\r
private:\r
std::string _buf, _filename;\r
\r
private:\r
std::string _buf, _filename;\r
+InvalidBuildFileException::InvalidBuildFileException()\r
+{\r
+}\r
+\r
+\r
+XMLSyntaxErrorException::XMLSyntaxErrorException ( const std::string& location,\r
+ const char* message,\r
+ ... )\r
+{\r
+ va_list args;\r
+ va_start ( args, message );\r
+ Message = location + ": " + ssvprintf ( message, args );\r
+ va_end ( args );\r
+}\r
+\r
\r
RequiredAttributeNotFoundException::RequiredAttributeNotFoundException(const std::string& attributeName,\r
const std::string& elementName)\r
\r
RequiredAttributeNotFoundException::RequiredAttributeNotFoundException(const std::string& attributeName,\r
const std::string& elementName)\r
class InvalidBuildFileException : public Exception\r
{\r
public:\r
class InvalidBuildFileException : public Exception\r
{\r
public:\r
- InvalidBuildFileException(const char* message,\r
- ...);\r
+ InvalidBuildFileException ( const char* message,\r
+ ...);\r
+protected:\r
+ InvalidBuildFileException();\r
+};\r
+\r
+\r
+class XMLSyntaxErrorException : public InvalidBuildFileException\r
+{\r
+public:\r
+ XMLSyntaxErrorException ( const std::string& location,\r
+ const char* message,\r
+ ... );\r