\r
string working_directory;\r
\r
-class XMLInclude\r
+XMLIncludes::~XMLIncludes()\r
{\r
-public:\r
- XMLElement *e;\r
- Path path;\r
-\r
- XMLInclude ( XMLElement* e_, const Path& path_ )\r
- : e(e_), path(path_)\r
- {\r
- }\r
-};\r
-\r
-class XMLIncludes : public vector<XMLInclude*>\r
-{\r
-public:\r
- ~XMLIncludes()\r
- {\r
- for ( size_t i = 0; i < this->size(); i++ )\r
- delete (*this)[i];\r
- }\r
-};\r
+ for ( size_t i = 0; i < this->size(); i++ )\r
+ delete (*this)[i];\r
+}\r
\r
void\r
InitWorkingDirectory()\r
return tmp;\r
}\r
\r
-/*static*/ string\r
+string\r
+Path::RelativeFromWorkingDirectory ()\r
+{\r
+ string out = "";\r
+ for ( size_t i = 0; i < path.size(); i++ )\r
+ {\r
+ out += "/" + path[i];\r
+ }\r
+ return RelativeFromWorkingDirectory ( out );\r
+}\r
+\r
+string\r
Path::RelativeFromWorkingDirectory ( const string& path )\r
{\r
vector<string> vwork, vpath, vout;\r
return out;\r
}\r
\r
-/*static*/ void\r
+void\r
Path::Split ( vector<string>& out,\r
const string& path,\r
bool include_last )\r
// it's parsed data. Keep calling this function until it returns NULL\r
// (no more data)\r
XMLElement*\r
-XMLParse(XMLFile& f,\r
- XMLIncludes* includes,\r
- const Path& path,\r
- bool* pend_tag = NULL )\r
+XMLParse ( XMLFile& f,\r
+ XMLIncludes* includes,\r
+ const Path& path,\r
+ bool* pend_tag = NULL )\r
{\r
string token;\r
if ( !f.get_token(token) )\r
bool end_tag, is_include = false;\r
\r
while ( token[0] != '<'\r
- || !strncmp ( token.c_str(), "<!--", 4 )\r
- || !strncmp ( token.c_str(), "<?", 2 ) )\r
+ || !strncmp ( token.c_str (), "<!--", 4 )\r
+ || !strncmp ( token.c_str (), "<?", 2 ) )\r
{\r
if ( token[0] != '<' )\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"expecting xml tag, not '%s'",\r
- token.c_str() );\r
+ token.c_str () );\r
if ( !f.get_token(token) )\r
return NULL;\r
}\r
\r
- XMLElement* e = new XMLElement ( f.Location() );\r
+ XMLElement* e = new XMLElement ( f.Location () );\r
bool bNeedEnd = e->Parse ( token, end_tag );\r
\r
if ( e->name == "xi:include" && includes )\r
{\r
- includes->push_back ( new XMLInclude ( e, path ) );\r
+ XMLAttribute* att;\r
+ att = e->GetAttribute ( "href", true );\r
+ assert ( att );\r
+ string includeFile ( path.Fixup ( att->value, true ) );\r
+ string topIncludeFile ( Path::RelativeFromWorkingDirectory ( includeFile ) );\r
+ includes->push_back ( new XMLInclude ( e, path, topIncludeFile ) );\r
is_include = true;\r
}\r
\r
else if ( end_tag )\r
{\r
delete e;\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"end tag '%s' not expected",\r
token.c_str() );\r
return NULL;\r
return e;\r
}\r
bool bThisMixingErrorReported = false;\r
- while ( f.more_tokens() )\r
+ while ( f.more_tokens () )\r
{\r
- if ( f.next_is_text() )\r
+ if ( f.next_is_text () )\r
{\r
- if ( !f.get_token ( token ) || !token.size() )\r
+ if ( !f.get_token ( token ) || token.size () == 0 )\r
{\r
throw InvalidBuildFileException (\r
f.Location(),\r
}\r
if ( e->subElements.size() && !bThisMixingErrorReported )\r
{\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"mixing of inner text with sub elements" );\r
bThisMixingErrorReported = true;\r
}\r
- if ( strchr ( token.c_str(), '>' ) )\r
+ if ( strchr ( token.c_str (), '>' ) )\r
{\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"invalid symbol '>'" );\r
}\r
- if ( e->value.size() )\r
+ if ( e->value.size() > 0 )\r
{\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"multiple instances of inner text" );\r
e->value += " " + token;\r
}\r
if ( e->name != e2->name )\r
{\r
delete e2;\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"end tag name mismatch" );\r
break;\r
}\r
delete e2;\r
break;\r
}\r
- if ( e->value.size() && !bThisMixingErrorReported )\r
+ if ( e->value.size () > 0 && !bThisMixingErrorReported )\r
{\r
- throw XMLSyntaxErrorException ( f.Location(),\r
+ throw XMLSyntaxErrorException ( f.Location (),\r
"mixing of inner text with sub elements" );\r
bThisMixingErrorReported = true;\r
}\r
}\r
\r
XMLElement*\r
-XMLLoadInclude ( XMLElement* e, const Path& path, XMLIncludes& includes )\r
+XMLLoadInclude ( XMLInclude& include,\r
+ XMLIncludes& includes )\r
{\r
XMLAttribute* att;\r
- att = e->GetAttribute("href",true);\r
+ att = include.e->GetAttribute("href", true);\r
assert(att);\r
\r
- string file ( path.Fixup(att->value,true) );\r
+ string file ( include.path.Fixup(att->value, true) );\r
string top_file ( Path::RelativeFromWorkingDirectory ( file ) );\r
- e->attributes.push_back ( new XMLAttribute ( "top_href", top_file ) );\r
+ include.e->attributes.push_back ( new XMLAttribute ( "top_href", top_file ) );\r
XMLFile fInc;\r
if ( !fInc.open ( file ) )\r
{\r
+ include.fileExists = false;\r
// look for xi:fallback element\r
- for ( size_t i = 0; i < e->subElements.size(); i++ )\r
+ for ( size_t i = 0; i < include.e->subElements.size (); i++ )\r
{\r
- XMLElement* e2 = e->subElements[i];\r
+ XMLElement* e2 = include.e->subElements[i];\r
if ( e2->name == "xi:fallback" )\r
{\r
// now look for xi:include below...\r
- for ( i = 0; i < e2->subElements.size(); i++ )\r
+ for ( i = 0; i < e2->subElements.size (); i++ )\r
{\r
XMLElement* e3 = e2->subElements[i];\r
if ( e3->name == "xi:include" )\r
{\r
- return XMLLoadInclude ( e3, path, includes );\r
+ att = e3->GetAttribute ( "href", true );\r
+ assert ( att );\r
+ string includeFile ( include.path.Fixup ( att->value, true ) );\r
+ string topIncludeFile ( Path::RelativeFromWorkingDirectory ( includeFile ) );\r
+ XMLInclude* fallbackInclude = new XMLInclude ( e3, include.path, topIncludeFile );\r
+ return XMLLoadInclude ( *fallbackInclude, includes );\r
}\r
}\r
throw InvalidBuildFileException (\r
}\r
else\r
{\r
- XMLElement* new_e = new XMLElement ( e->location );\r
+ include.fileExists = true;\r
+ XMLElement* new_e = new XMLElement ( include.e->location );\r
new_e->name = "xi:included";\r
- Path path2 ( path, att->value );\r
+ Path path2 ( include.path, att->value );\r
XMLReadFile ( fInc, *new_e, includes, path2 );\r
return new_e;\r
}\r
}\r
\r
XMLElement*\r
-XMLLoadFile ( const string& filename, const Path& path )\r
+XMLLoadFile ( const string& filename,\r
+ const Path& path,\r
+ XMLIncludes& includes )\r
{\r
- XMLIncludes includes;\r
XMLFile f;\r
\r
if ( !f.open ( filename ) )\r
throw FileNotFoundException ( filename );\r
\r
- XMLElement* head = new XMLElement("(virtual)");\r
+ XMLElement* head = new XMLElement ( "(virtual)" );\r
\r
XMLReadFile ( f, *head, includes, path );\r
\r
- for ( size_t i = 0; i < includes.size(); i++ )\r
+ for ( size_t i = 0; i < includes.size (); i++ )\r
{\r
XMLElement* e = includes[i]->e;\r
- XMLElement* e2 = XMLLoadInclude ( includes[i]->e, includes[i]->path, includes );\r
+ XMLElement* e2 = XMLLoadInclude ( *includes[i], includes );\r
if ( !e2 )\r
{\r
throw FileNotFoundException (\r
- ssprintf("%s (referenced from %s)",\r
- e->GetAttribute("top_href",true)->value.c_str(),\r
- f.Location().c_str() ) );\r
+ ssprintf ( "%s (referenced from %s)",\r
+ e->GetAttribute ( "top_href", true )->value.c_str (),\r
+ f.Location ().c_str () ) );\r
}\r
XMLElement* parent = e->parentElement;\r
XMLElement** parent_container = NULL;\r
throw Exception ( "internal tool error: xi:include doesn't have a parent" );\r
return NULL;\r
}\r
- for ( size_t j = 0; j < parent->subElements.size(); j++ )\r
+ for ( size_t j = 0; j < parent->subElements.size (); j++ )\r
{\r
if ( parent->subElements[j] == e )\r
{\r
e2->name = e->name;\r
e2->attributes = e->attributes;\r
*parent_container = e2;\r
- e->attributes.resize(0);\r
+ e->attributes.resize ( 0 );\r
delete e;\r
}\r
return head;\r