* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include "pch.h"
-#ifndef MAX_PATH
-#define MAX_PATH _MAX_PATH
-#endif
+#ifdef _MSC_VER
+#pragma warning ( disable : 4786 )
+#endif//_MSC_VER
#ifdef WIN32
# include <direct.h>
#include <assert.h>
#include "XML.h"
-#include "exception.h"
#include "ssprintf.h"
+#ifndef MAX_PATH
+#define MAX_PATH _MAX_PATH
+#endif
+
using std::string;
using std::vector;
string working_directory;
+XMLException::XMLException (
+ const std::string& location,
+ const char* format, ... )
+{
+ va_list args;
+ va_start ( args, format );
+ SetExceptionV ( location, format, args );
+ va_end ( args );
+}
+
+void XMLException::SetExceptionV ( const std::string& location, const char* format, va_list args )
+{
+ _e = location + ": " + ssvprintf(format,args);
+}
+
+void XMLException::SetException ( const std::string& location, const char* format, ... )
+{
+ va_list args;
+ va_start ( args, format );
+ SetExceptionV ( location, format, args );
+ va_end ( args );
+}
+
XMLIncludes::~XMLIncludes()
{
for ( size_t i = 0; i < this->size(); i++ )
InitWorkingDirectory()
{
// store the current directory for path calculations
- working_directory.resize ( _MAX_PATH );
+ working_directory.resize ( MAX_PATH );
working_directory[0] = 0;
getcwd ( &working_directory[0], working_directory.size() );
working_directory.resize ( strlen ( working_directory.c_str() ) );
filelen ( FILE* f )
{
#ifdef WIN32
- return _filelengthi64 ( _fileno(f) );
+ return _filelengthi64 ( _fileno(f) );
#else
# ifdef __FreeBSD__
- struct stat file_stat;
- if ( fstat(fileno(f), &file_stat) != 0 )
+ struct stat file_stat;
+ if ( fstat(fileno(f), &file_stat) != 0 )
# else
- struct stat64 file_stat;
- if ( fstat64(fileno(f), &file_stat) != 0 )
+ struct stat64 file_stat;
+ if ( fstat64(fileno(f), &file_stat) != 0 )
# endif // __FreeBSD__
- return 0;
- return file_stat.st_size;
-
+ return 0;
+ return file_stat.st_size;
#endif // WIN32
}
}
void
-Path::Split ( vector<string>& out,
- const string& path,
- bool include_last )
+Path::Split (
+ vector<string>& out,
+ const string& path,
+ bool include_last )
{
string s ( path );
const char* prev = strtok ( &s[0], "/\\" );
}
bool
-XMLFile::open(const string& filename_)
+XMLFile::open ( const string& filename_ )
{
close();
FILE* f = fopen ( filename_.c_str(), "rb" );
}
bool
-XMLFile::more_tokens()
+XMLFile::more_tokens ()
{
return _p != _end;
}
// get_token() is used to return a token, and move the pointer
// past the token
bool
-XMLFile::get_token(string& token)
+XMLFile::get_token ( string& token )
{
const char* tokend;
if ( !strncmp ( _p, "<!--", 4 ) )
{
}
-XMLAttribute::XMLAttribute(const string& name_,
- const string& value_)
+XMLAttribute::XMLAttribute(
+ const string& name_,
+ const string& value_ )
: name(name_), value(value_)
{
}
return *this;
}
-XMLElement::XMLElement ( XMLFile* xmlFile,
- const string& location )
+XMLElement::XMLElement (
+ XMLFile* xmlFile,
+ const string& location )
: xmlFile ( xmlFile ),
location ( location ),
parentElement ( NULL )
// Return Value: returns true if you need to look for a </tag> for
// the one it just parsed...
bool
-XMLElement::Parse(const string& token,
- bool& end_tag)
+XMLElement::Parse (
+ const string& token,
+ bool& end_tag )
{
const char* p = token.c_str();
assert ( *p == '<' );
}
else if ( name[0] != '!' )
{
- throw XMLSyntaxErrorException ( location,
- "attributes must have values" );
+ throw XMLSyntaxErrorException (
+ location,
+ "attributes must have values" );
}
attributes.push_back ( new XMLAttribute ( attribute, value ) );
}
}
XMLAttribute*
-XMLElement::GetAttribute ( const string& attribute,
- bool required )
+XMLElement::GetAttribute (
+ const string& attribute,
+ bool required )
{
// this would be faster with a tree-based container, but our attribute
// lists are likely to stay so short as to not be an issue.
}
if ( required )
{
- throw RequiredAttributeNotFoundException ( location,
- attribute,
- name );
+ throw XMLRequiredAttributeNotFoundException (
+ location,
+ attribute,
+ name );
}
return NULL;
}
const XMLAttribute*
-XMLElement::GetAttribute ( const string& attribute,
- bool required ) const
+XMLElement::GetAttribute (
+ const string& attribute,
+ bool required ) const
{
// this would be faster with a tree-based container, but our attribute
// lists are likely to stay so short as to not be an issue.
}
if ( required )
{
- throw RequiredAttributeNotFoundException ( location,
- attribute,
- name );
+ throw XMLRequiredAttributeNotFoundException (
+ location,
+ attribute,
+ name );
}
return NULL;
}
+int
+XMLElement::FindElement ( const std::string& type, int prev ) const
+{
+ int done = subElements.size();
+ while ( ++prev < done )
+ {
+ XMLElement* e = subElements[prev];
+ if ( e->name == type )
+ return prev;
+ }
+ return -1;
+}
+
+int
+XMLElement::GetElements (
+ const std::string& type,
+ std::vector<XMLElement*>& v )
+{
+ int find = FindElement ( type );
+ v.resize ( 0 );
+ while ( find != -1 )
+ {
+ v.push_back ( subElements[find] );
+ find = FindElement ( type, find );
+ }
+ return v.size();
+}
+
+int
+XMLElement::GetElements (
+ const std::string& type,
+ std::vector<const XMLElement*>& v ) const
+{
+ int find = FindElement ( type );
+ v.resize ( 0 );
+ while ( find != -1 )
+ {
+ v.push_back ( subElements[find] );
+ find = FindElement ( type, find );
+ }
+ return v.size();
+}
+
// XMLParse()
// This function reads a "token" from the file loaded in XMLFile
// if it finds a tag that is non-singular, it parses sub-elements and/or
// it's parsed data. Keep calling this function until it returns NULL
// (no more data)
XMLElement*
-XMLParse ( XMLFile& f,
- XMLIncludes* includes,
- const Path& path,
- bool* pend_tag = NULL )
+XMLParse (
+ XMLFile& f,
+ XMLIncludes* includes,
+ const Path& path,
+ bool* pend_tag = NULL )
{
string token, location;
if ( !f.get_token(token,location) )
return NULL;
bool end_tag, is_include = false;
- while ( token[0] != '<'
- || !strncmp ( token.c_str (), "<!--", 4 )
- || !strncmp ( token.c_str (), "<?", 2 ) )
+ while
+ (
+ token[0] != '<'
+ || !strncmp ( token.c_str (), "<!--", 4 )
+ || !strncmp ( token.c_str (), "<?", 2 )
+ )
{
if ( token[0] != '<' )
- throw XMLSyntaxErrorException ( location,
- "expecting xml tag, not '%s'",
- token.c_str () );
- if ( !f.get_token(token,location) )
+ {
+ throw XMLSyntaxErrorException (
+ location,
+ "expecting xml tag, not '%s'",
+ token.c_str () );
+ }
+ if ( !f.get_token ( token, location ) )
return NULL;
}
- XMLElement* e = new XMLElement ( &f,
- location );
+ XMLElement* e = new XMLElement (
+ &f,
+ location );
bool bNeedEnd = e->Parse ( token, end_tag );
if ( e->name == "xi:include" && includes )
att = e->GetAttribute ( "href", true );
assert ( att );
string includeFile ( path.Fixup ( att->value, true ) );
- string topIncludeFile ( Path::RelativeFromWorkingDirectory ( includeFile ) );
- includes->push_back ( new XMLInclude ( e, path, topIncludeFile ) );
+ string topIncludeFile (
+ Path::RelativeFromWorkingDirectory ( includeFile ) );
+ includes->push_back (
+ new XMLInclude ( e, path, topIncludeFile ) );
is_include = true;
}
else if ( end_tag )
{
delete e;
- throw XMLSyntaxErrorException ( location,
- "end tag '%s' not expected",
- token.c_str() );
+ throw XMLSyntaxErrorException (
+ location,
+ "end tag '%s' not expected",
+ token.c_str() );
return NULL;
}
return e;
{
if ( !f.get_token ( token, location ) || token.size () == 0 )
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
location,
"internal tool error - get_token() failed when more_tokens() returned true" );
break;
}
if ( e->subElements.size() && !bThisMixingErrorReported )
{
- throw XMLSyntaxErrorException ( location,
- "mixing of inner text with sub elements" );
+ throw XMLSyntaxErrorException (
+ location,
+ "mixing of inner text with sub elements" );
bThisMixingErrorReported = true;
}
if ( strchr ( token.c_str (), '>' ) )
{
- throw XMLSyntaxErrorException ( location,
- "invalid symbol '>'" );
+ throw XMLSyntaxErrorException (
+ location,
+ "invalid symbol '>'" );
}
if ( e->value.size() > 0 )
{
- throw XMLSyntaxErrorException ( location,
- "multiple instances of inner text" );
+ throw XMLSyntaxErrorException (
+ location,
+ "multiple instances of inner text" );
e->value += " " + token;
}
else
}
else
{
- XMLElement* e2 = XMLParse ( f, is_include ? NULL : includes, path, &end_tag );
+ XMLElement* e2 = XMLParse (
+ f, is_include ? NULL : includes, path, &end_tag );
if ( !e2 )
{
string e_location = e->location;
string e_name = e->name;
delete e;
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
e_location,
"end of file found looking for end tag: </%s>",
e_name.c_str() );
{
string e_location = e->location;
delete e;
- throw XMLSyntaxErrorException ( e_location,
- "mixing of inner text with sub elements" );
+ throw XMLSyntaxErrorException (
+ e_location,
+ "mixing of inner text with sub elements" );
bThisMixingErrorReported = true;
}
e->AddSubElement ( e2 );
}
void
-XMLReadFile ( XMLFile& f, XMLElement& head, XMLIncludes& includes, const Path& path )
+XMLReadFile (
+ XMLFile& f,
+ XMLElement& head,
+ XMLIncludes& includes,
+ const Path& path )
{
for ( ;; )
{
}
XMLElement*
-XMLLoadInclude ( XMLInclude& include,
- XMLIncludes& includes )
+XMLLoadInclude (
+ XMLInclude& include,
+ XMLIncludes& includes )
{
XMLAttribute* att;
att = include.e->GetAttribute("href", true);
{
att = e3->GetAttribute ( "href", true );
assert ( att );
- string includeFile ( include.path.Fixup ( att->value, true ) );
- string topIncludeFile ( Path::RelativeFromWorkingDirectory ( includeFile ) );
- XMLInclude* fallbackInclude = new XMLInclude ( e3, include.path, topIncludeFile );
- return XMLLoadInclude ( *fallbackInclude, includes );
+ string includeFile (
+ include.path.Fixup ( att->value, true ) );
+ string topIncludeFile (
+ Path::RelativeFromWorkingDirectory ( includeFile ) );
+ XMLInclude* fallbackInclude =
+ new XMLInclude ( e3, include.path, topIncludeFile );
+ return XMLLoadInclude (
+ *fallbackInclude, includes );
}
}
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
e2->location,
"<xi:fallback> must have a <xi:include> sub-element" );
return NULL;
else
{
include.fileExists = true;
- XMLElement* new_e = new XMLElement ( fInc,
- include.e->location );
+ XMLElement* new_e = new XMLElement (
+ fInc,
+ include.e->location );
new_e->name = "xi:included";
Path path2 ( include.path, att->value );
XMLReadFile ( *fInc, *new_e, includes, path2 );
XMLFile* f = new XMLFile();
if ( !f->open ( filename ) )
- throw FileNotFoundException ( filename );
+ {
+ throw XMLFileNotFoundException ( "(virtual)", filename );
+ return NULL;
+ }
- XMLElement* head = new XMLElement ( f,
- "(virtual)" );
+ XMLElement* head = new XMLElement ( f, "(virtual)" );
XMLReadFile ( *f, *head, includes, path );
XMLElement* e2 = XMLLoadInclude ( *includes[i], includes );
if ( !e2 )
{
- throw FileNotFoundException (
- ssprintf ( "%s (referenced from %s)",
- e->GetAttribute ( "top_href", true )->value.c_str (),
- f->Location ().c_str () ) );
+ throw XMLFileNotFoundException (
+ f->Location(),
+ e->GetAttribute ( "top_href", true )->value );
}
XMLElement* parent = e->parentElement;
XMLElement** parent_container = NULL;
if ( !parent )
{
+ string location = e->location;
delete e;
- throw Exception ( "internal tool error: xi:include doesn't have a parent" );
+ throw XMLException ( location, "internal tool error: xi:include doesn't have a parent" );
return NULL;
}
for ( size_t j = 0; j < parent->subElements.size (); j++ )
}
if ( !parent_container )
{
+ string location = e->location;
delete e;
- throw Exception ( "internal tool error: couldn't find xi:include in parent's sub-elements" );
+ throw XMLException ( location, "internal tool error: couldn't find xi:include in parent's sub-elements" );
return NULL;
}
// replace inclusion tree with the imported tree
#ifndef XML_H
#define XML_H
-#include "pch.h"
+#include <string>
+#include <vector>
+#include <stdarg.h>
class XMLElement;
#endif
filelen ( FILE* f );
+class XMLException
+{
+public:
+ XMLException ( const std::string& location, const char* format, ... );
+ const std::string& operator *() { return _e; }
+
+protected:
+ XMLException() {}
+ void SetExceptionV ( const std::string& location, const char* format, va_list args );
+ void SetException ( const std::string& location, const char* format, ... );
+
+private:
+ std::string _e;
+};
+
+class XMLSyntaxErrorException : public XMLException
+{
+public:
+ XMLSyntaxErrorException (
+ const std::string& location,
+ const char* format, ... )
+ {
+ va_list args;
+ va_start ( args, format );
+ SetExceptionV ( location, format, args );
+ va_end ( args );
+ }
+};
+
+class XMLRequiredAttributeNotFoundException : public XMLException
+{
+public:
+ XMLRequiredAttributeNotFoundException (
+ const std::string& location,
+ const std::string& attributeName,
+ const std::string& elementName )
+ {
+ SetException ( location, "Required attribute '%s' not found in element '%s'",
+ attributeName.c_str(),
+ elementName.c_str() );
+ }
+};
+
+class XMLInvalidBuildFileException : public XMLException
+{
+public:
+ XMLInvalidBuildFileException (
+ const std::string& location,
+ const char* format,
+ ... )
+ {
+ va_list args;
+ va_start ( args, format );
+ SetExceptionV ( location, format, args );
+ va_end ( args );
+ }
+};
+
+class XMLFileNotFoundException : public XMLException
+{
+public:
+ XMLFileNotFoundException (
+ const std::string& location,
+ const std::string& filename )
+ {
+ SetException ( location, "Can't open file '%s'", filename.c_str() );
+ }
+};
+
class Path
{
std::vector<std::string> path;
static std::string RelativeFromWorkingDirectory ( const std::string& path );
static std::string RelativeFromDirectory ( const std::string& path, const std::string& base_directory);
- static void Split ( std::vector<std::string>& out,
- const std::string& path,
- bool include_last );
+ static void Split (
+ std::vector<std::string>& out,
+ const std::string& path,
+ bool include_last );
};
class XMLInclude
std::string topIncludeFilename;
bool fileExists;
- XMLInclude ( XMLElement* e_, const Path& path_, const std::string topIncludeFilename_ )
- : e ( e_ ), path ( path_ ), topIncludeFilename ( topIncludeFilename_ )
+ XMLInclude (
+ XMLElement* e_,
+ const Path& path_,
+ const std::string topIncludeFilename_ )
+ : e ( e_ ),
+ path ( path_ ),
+ topIncludeFilename ( topIncludeFilename_ )
{
}
};
std::vector<XMLElement*> subElements;
std::string value;
- XMLElement ( XMLFile* xmlFile,
- const std::string& location );
+ XMLElement (
+ XMLFile* xmlFile,
+ const std::string& location );
+
~XMLElement();
- bool Parse(const std::string& token,
- bool& end_tag);
+
+ bool Parse (
+ const std::string& token,
+ bool& end_tag);
+
void AddSubElement ( XMLElement* e );
- XMLAttribute* GetAttribute ( const std::string& attribute,
- bool required);
- const XMLAttribute* GetAttribute ( const std::string& attribute,
- bool required) const;
+
+ XMLAttribute* GetAttribute (
+ const std::string& attribute,
+ bool required);
+
+ const XMLAttribute* GetAttribute (
+ const std::string& attribute,
+ bool required ) const;
+
+ int FindElement (
+ const std::string& type,
+ int prev = -1 ) const;
+
+ int GetElements (
+ const std::string& type,
+ std::vector<XMLElement*>& v );
+
+ int GetElements (
+ const std::string& type,
+ std::vector<const XMLElement*>& v ) const;
};
XMLElement*
-XMLLoadFile ( const std::string& filename,
- const Path& path,
- XMLIncludes& includes );
+XMLLoadFile (
+ const std::string& filename,
+ const Path& path,
+ XMLIncludes& includes );
#endif // XML_H
if ( invoke.invokeModule->type != BuildTool )
{
- throw InvalidBuildFileException ( module.node.location,
- "Only modules of type buildtool can be invoked." );
+ throw XMLInvalidBuildFileException (
+ module.node.location,
+ "Only modules of type buildtool can be invoked." );
}
string invokeTarget = module.GetInvocationTarget ( i );
{
if ( !IsSupportedModuleType ( module->type ) )
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node.location,
"<bootstrap> is not applicable for this module type." );
}
{
if (node.value.size () == 0)
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node.location,
"<compilerflag> is empty." );
}
Exception::Exception ( const string& message )
{
- Message = message;
+ _e = message;
}
-Exception::Exception ( const char* format,
- ...)
+Exception::Exception ( const char* format, ...)
{
va_list args;
- va_start ( args,
- format);
- Message = ssvprintf ( format,
- args);
+ va_start ( args, format);
+ _e = ssvprintf ( format, args);
va_end ( args );
}
-void Exception::SetMessage ( const char* message,
- va_list args)
+void Exception::SetMessage ( const char* format, ...)
{
- Message = ssvprintf ( message,
- args);
+ va_list args;
+ va_start ( args, format);
+ _e = ssvprintf ( format, args);
+ va_end ( args );
+}
+
+void Exception::SetMessageV ( const char* message, va_list args )
+{
+ _e = ssvprintf ( message, args);
}
}
-InvalidOperationException::InvalidOperationException ( const char* filename,
- const int linenumber )
+InvalidOperationException::InvalidOperationException (
+ const char* filename,
+ const int linenumber )
+ : Exception ( "%s:%d", filename, linenumber )
{
- Message = ssprintf ( "%s:%d",
- filename,
- linenumber );
}
-InvalidOperationException::InvalidOperationException ( const char* filename,
- const int linenumber,
- const char* message,
- ... )
+InvalidOperationException::InvalidOperationException (
+ const char* filename,
+ const int linenumber,
+ const char* message,
+ ... )
{
string errorMessage;
va_list args;
- va_start ( args,
- message );
- errorMessage = ssvprintf ( message,
- args );
+ va_start ( args, message );
+ errorMessage = ssvprintf ( message, args );
va_end ( args );
- Message = ssprintf ( "%s:%d %s",
- filename,
- linenumber,
- errorMessage.c_str () );
+ SetMessage (
+ "%s:%d %s",
+ filename,
+ linenumber,
+ errorMessage.c_str () );
}
}
-InvalidBuildFileException::InvalidBuildFileException ( const string& location,
- const char* message,
- ...)
-{
- va_list args;
- va_start ( args,
- message );
- SetLocationMessage ( location, message, args );
- va_end ( args );
-}
-
-InvalidBuildFileException::InvalidBuildFileException ()
-{
-}
-
-void
-InvalidBuildFileException::SetLocationMessage ( const std::string& location,
- const char* message,
- va_list args )
-{
- Message = location + ": " + ssvprintf ( message, args );
-}
-
-XMLSyntaxErrorException::XMLSyntaxErrorException ( const string& location,
- const char* message,
- ... )
-{
- va_list args;
- va_start ( args,
- message );
- SetLocationMessage ( location, message, args );
- va_end ( args );
-}
-
-
RequiredAttributeNotFoundException::RequiredAttributeNotFoundException (
const string& location,
const string& attributeName,
const string& elementName )
- : InvalidBuildFileException ( location,
- "Required attribute '%s' not found on '%s'.",
- attributeName.c_str (),
- elementName.c_str ())
+ : XMLInvalidBuildFileException (
+ location,
+ "Required attribute '%s' not found on '%s'.",
+ attributeName.c_str (),
+ elementName.c_str ())
{
}
const string& location,
const string& name,
const string& value )
- : InvalidBuildFileException ( location,
- "Attribute '%s' has an invalid value '%s'.",
- name.c_str (),
- value.c_str () )
+ : XMLInvalidBuildFileException (
+ location,
+ "Attribute '%s' has an invalid value '%s'.",
+ name.c_str (),
+ value.c_str () )
{
}
UnknownModuleTypeException::UnknownModuleTypeException ( const string& location,
int moduletype )
- : InvalidBuildFileException ( location,
- "module type requested: %i",
- moduletype )
+ : XMLInvalidBuildFileException (
+ location,
+ "module type requested: %i",
+ moduletype )
{
}
#define __EXCEPTION_H
#include "pch.h"
+#include "XML.h"
class Exception
{
Exception ( const std::string& message );
Exception ( const char* format,
...);
- std::string Message;
+ const std::string& operator *() { return _e; }
+
protected:
Exception ();
- void SetMessage ( const char* message,
- va_list args );
+ void SetMessage ( const char* message, ... );
+ void SetMessageV ( const char* message, va_list args );
+
+private:
+ std::string _e;
};
std::string Filename;
};
-class InvalidBuildFileException : public Exception
-{
-public:
- InvalidBuildFileException ( const std::string& location,
- const char* message,
- ...);
- void SetLocationMessage ( const std::string& location,
- const char* message,
- va_list args );
-protected:
- InvalidBuildFileException ();
-};
-
-
-class XMLSyntaxErrorException : public InvalidBuildFileException
-{
-public:
- XMLSyntaxErrorException ( const std::string& location,
- const char* message,
- ... );
-};
-
-class RequiredAttributeNotFoundException : public InvalidBuildFileException
+class RequiredAttributeNotFoundException : public XMLInvalidBuildFileException
{
public:
RequiredAttributeNotFoundException ( const std::string& location,
};
-class InvalidAttributeValueException : public InvalidBuildFileException
+class InvalidAttributeValueException : public XMLInvalidBuildFileException
{
public:
InvalidAttributeValueException ( const std::string& location,
UnknownBackendException ( const std::string& name );
};
-class UnknownModuleTypeException : public InvalidBuildFileException
+class UnknownModuleTypeException : public XMLInvalidBuildFileException
{
public:
UnknownModuleTypeException ( const std::string& location,
Include::ProcessXML()
{
const XMLAttribute* att;
- att = node->GetAttribute ( "base",
- false );
+ att = node->GetAttribute ( "base", false );
if ( att )
{
if ( !module )
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node->location,
"'base' attribute illegal from global <include>" );
bool referenceResolved = false;
}
}
if ( !referenceResolved )
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node->location,
"<include> attribute 'base' references non-existant project or module '%s'",
att->value.c_str() );
{
if ( node.value.size () == 0 )
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node.location,
"<linkerflag> is empty." );
}
}
}
if ( !referenceResolved )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"<linkerscript> attribute 'base' references non-existant project or module '%s'",
att->value.c_str() );
+ }
directory = NormalizeFilename ( basePath + sSep + node.value );
}
else
const string& att_value )
{
if ( !att_value.size() )
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
location,
"<directory> tag has empty 'name' attribute" );
if ( strpbrk ( att_value.c_str (), "/\\?*:<>|" ) )
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
location,
"<directory> tag has invalid characters in 'name' attribute" );
if ( !path.size() )
if ( type == Alias )
{
if ( aliasedModuleName == name )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"module '%s' cannot link against itself",
name.c_str() );
- const Module* m = project.LocateModule ( aliasedModuleName );
+ }
+ const Module* m = project.LocateModule ( aliasedModuleName );
if ( !m )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"module '%s' trying to alias non-existant module '%s'",
name.c_str(),
aliasedModuleName.c_str() );
+ }
}
size_t i;
if ( !stricmp ( att->value.c_str(), "true" ) )
first = true;
else if ( stricmp ( att->value.c_str(), "false" ) )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"attribute 'first' of <file> element can only be 'true' or 'false'" );
+ }
}
string switches = "";
att = e.GetAttribute ( "switches", false );
else if ( e.name == "invoke" )
{
if ( parseContext.ifData )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<invoke> is not a valid sub-element of <if>" );
+ }
invocations.push_back ( new Invoke ( e, *this ) );
subs_invalid = false;
}
else if ( e.name == "dependency" )
{
if ( parseContext.ifData )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<dependency> is not a valid sub-element of <if>" );
+ }
dependencies.push_back ( new Dependency ( e, *this ) );
subs_invalid = true;
}
else if ( e.name == "importlibrary" )
{
if ( parseContext.ifData )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<importlibrary> is not a valid sub-element of <if>" );
+ }
if ( importLibrary )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"Only one <importlibrary> is valid per module" );
+ }
importLibrary = new ImportLibrary ( e, *this );
subs_invalid = true;
}
else if ( e.name == "linkerscript" )
{
if ( linkerScript )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"Only one <linkerscript> is valid per module" );
+ }
linkerScript = new LinkerScript ( project, this, e );
subs_invalid = true;
}
}
else if ( e.name == "property" )
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
e.location,
"<property> is not a valid sub-element of <module>" );
}
else if ( e.name == "pch" )
{
if ( parseContext.ifData )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<pch> is not a valid sub-element of <if>" );
+ }
if ( pch )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"Only one <pch> is valid per module" );
+ }
pch = new PchFile (
e, *this, File ( FixSeparator ( path + cSep + e.value ), false, "", true ) );
subs_invalid = true;
{
if ( autoRegister != NULL)
{
- throw InvalidBuildFileException ( e.location,
- "there can be only one <%s> element for a module",
- e.name.c_str() );
+ throw XMLInvalidBuildFileException (
+ e.location,
+ "there can be only one <%s> element for a module",
+ e.name.c_str() );
}
autoRegister = new AutoRegister ( project, this, e );
subs_invalid = true;
}
if ( subs_invalid && e.subElements.size() > 0 )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<%s> cannot have sub-elements",
e.name.c_str() );
+ }
for ( size_t i = 0; i < e.subElements.size (); i++ )
ProcessXMLSubElement ( *e.subElements[i], subpath, parseContext );
parseContext.ifData = pOldIf;
importedModule(_module.project.LocateModule(_name))
{
if ( module.name == name )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"module '%s' cannot link against itself",
name.c_str() );
+ }
if ( !importedModule )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"module '%s' trying to import non-existant module '%s'",
module.name.c_str(),
name.c_str() );
+ }
}
void
Library::ProcessXML()
{
if ( !module.project.LocateModule ( name ) )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"module '%s' is trying to link against non-existant module '%s'",
module.name.c_str(),
name.c_str() );
+ }
}
{
invokeModule = module.project.LocateModule ( att->value );
if ( invokeModule == NULL )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
node.location,
"module '%s' is trying to invoke non-existant module '%s'",
module.name.c_str(),
att->value.c_str() );
+ }
}
for ( size_t i = 0; i < node.subElements.size (); i++ )
ProcessXMLSubElementOutput ( *e.subElements[i] );
}
if ( subs_invalid && e.subElements.size() > 0 )
- throw InvalidBuildFileException ( e.location,
- "<%s> cannot have sub-elements",
- e.name.c_str() );
+ {
+ throw XMLInvalidBuildFileException (
+ e.location,
+ "<%s> cannot have sub-elements",
+ e.name.c_str() );
+ }
}
void
bool subs_invalid = false;
if ( e.name == "inputfile" && e.value.size () > 0 )
{
- input.push_back ( new InvokeFile ( e, FixSeparator ( module.path + cSep + e.value ) ) );
+ input.push_back ( new InvokeFile (
+ e, FixSeparator ( module.path + cSep + e.value ) ) );
subs_invalid = true;
}
if ( subs_invalid && e.subElements.size() > 0 )
- throw InvalidBuildFileException ( e.location,
- "<%s> cannot have sub-elements",
- e.name.c_str() );
+ {
+ throw XMLInvalidBuildFileException (
+ e.location,
+ "<%s> cannot have sub-elements",
+ e.name.c_str() );
+ }
}
void
bool subs_invalid = false;
if ( e.name == "outputfile" && e.value.size () > 0 )
{
- output.push_back ( new InvokeFile ( e, FixSeparator ( module.path + cSep + e.value ) ) );
+ output.push_back ( new InvokeFile (
+ e, FixSeparator ( module.path + cSep + e.value ) ) );
subs_invalid = true;
}
if ( subs_invalid && e.subElements.size() > 0 )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<%s> cannot have sub-elements",
e.name.c_str() );
+ }
}
void
{
dependencyModule = module.project.LocateModule ( node.value );
if ( dependencyModule == NULL )
- throw InvalidBuildFileException ( node.location,
- "module '%s' depend on non-existant module '%s'",
- module.name.c_str(),
- node.value.c_str() );
+ {
+ throw XMLInvalidBuildFileException (
+ node.location,
+ "module '%s' depend on non-existant module '%s'",
+ module.name.c_str(),
+ node.value.c_str() );
+ }
}
return DllInstall;
if ( type == "Both" )
return Both;
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node.location,
"<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
}
{
if ( !IsSupportedModuleType ( module->type ) )
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node.location,
"<autoregister> is not applicable for this module type." );
}
if (node == NULL)
node = head->subElements[0];
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node->location,
"Document contains no 'project' tag." );
}
if ( e.name == "module" )
{
if ( parseContext.ifData )
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
e.location,
"<module> is not a valid sub-element of <if>" );
Module* module = new Module ( *this, e, path );
if ( LocateModule ( module->name ) )
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node->location,
"module name conflict: '%s' (originally defined at %s)",
module->name.c_str(),
non_if_data.properties.push_back ( property );
}
if ( subs_invalid && e.subElements.size() )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<%s> cannot have sub-elements",
e.name.c_str() );
+ }
for ( size_t i = 0; i < e.subElements.size (); i++ )
ProcessXMLSubElement ( *e.subElements[i], subpath, parseContext );
}
static Configuration configuration;
bool
-ParseAutomaticDependencySwitch ( char switchChar2,
- char* switchStart )
+ParseAutomaticDependencySwitch (
+ char switchChar2,
+ char* switchStart )
{
switch ( switchChar2 )
{
}
bool
-ParseCompilationUnitSwitch ( char switchChar2,
- char* switchStart )
+ParseCompilationUnitSwitch (
+ char switchChar2,
+ char* switchStart )
{
switch ( switchChar2 )
{
}
bool
-ParseVCProjectSwitch ( char switchChar2,
- char* switchStart )
+ParseVCProjectSwitch (
+ char switchChar2,
+ char* switchStart )
{
switch ( switchChar2 )
{
{
case 'v':
if (switchChar2 == 's')
- return ParseVCProjectSwitch ( switchChar2,
- argv[index] );
+ {
+ return ParseVCProjectSwitch (
+ switchChar2,
+ argv[index] );
+ }
else
configuration.Verbose = true;
break;
configuration.CleanAsYouGo = true;
break;
case 'd':
- return ParseAutomaticDependencySwitch ( switchChar2,
- argv[index] );
+ return ParseAutomaticDependencySwitch (
+ switchChar2,
+ argv[index] );
case 'u':
- return ParseCompilationUnitSwitch ( switchChar2,
- argv[index] );
+ return ParseCompilationUnitSwitch (
+ switchChar2,
+ argv[index] );
case 'r':
RootXmlFile = string(&argv[index][2]);
break;
case 'p':
return ParseProxyMakefileSwitch ( switchChar2 );
default:
- printf ( "Unknown switch -%c\n",
- switchChar );
+ printf (
+ "Unknown switch -%c\n",
+ switchChar );
return false;
}
return true;
printf ( "done\n" );
project.WriteConfigurationFile ();
project.ExecuteInvocations ();
- Backend* backend = Backend::Factory::Create ( BuildSystem,
- project,
- configuration );
+ Backend* backend = Backend::Factory::Create (
+ BuildSystem,
+ project,
+ configuration );
backend->Process ();
delete backend;
return 0;
}
- catch (Exception& ex)
+ catch ( Exception& ex )
+ {
+ printf ( "%s\n", (*ex).c_str () );
+ return 1;
+ }
+ catch ( XMLException& ex )
{
- printf ( "%s\n",
- ex.Message.c_str () );
+ printf ( "%s\n", (*ex).c_str () );
return 1;
}
}
# PROP Intermediate_Dir "Debug"\r
# PROP Target_Dir ""\r
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../lib/inflib" /I "../../include/reactos" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INFLIB_HOST" /YX /FD /GZ /c\r
# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
# ADD RSC /l 0x409 /d "_DEBUG"\r
BSC32=bscmake.exe\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\syssetupgenerator.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\testsupportcode.cpp\r
# End Source File\r
# Begin Source File\r
SOURCE=.\XML.h\r
# End Source File\r
# End Group\r
+# Begin Group "inflib"\r
+\r
+# PROP Default_Filter ""\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\builddep.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infcommon.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infcore.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infget.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infhost.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infhostgen.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infhostget.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infhostglue.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infhostput.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\inflib.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infpriv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\lib\inflib\infput.c\r
+# End Source File\r
+# End Group\r
# End Target\r
# End Project\r
subs_invalid = false;
}
if ( subs_invalid && e.subElements.size () > 0 )
- throw InvalidBuildFileException (
+ {
+ throw XMLInvalidBuildFileException (
e.location,
"<%s> cannot have sub-elements",
e.name.c_str() );
+ }
for ( size_t i = 0; i < e.subElements.size (); i++ )
ProcessXMLSubElement ( *e.subElements[i] );
}
{
if ( node.value.size () == 0 )
{
- throw InvalidBuildFileException (
+ throw XMLInvalidBuildFileException (
node.location,
"<symbol> is empty." );
}
if (test.Failed)
numberOfFailedTests++;
}
- catch (Exception& ex)
+ catch ( Exception& ex )
{
- printf("%s\n",
- ex.Message.c_str());
+ printf ( "%s\n", (*ex).c_str () );
+ numberOfFailedTests++;
+ }
+ catch ( XMLException& ex )
+ {
+ printf ( "%s\n", (*ex).c_str () );
numberOfFailedTests++;
}
}