diff --git a/reactos/tools/rbuild/exception.cpp b/reactos/tools/rbuild/exception.cpp new file mode 100644 index 00000000000..ec5a833645a --- /dev/null +++ b/reactos/tools/rbuild/exception.cpp @@ -0,0 +1,50 @@ +#ifdef _MSC_VER +#pragma warning ( disable : 4786 ) // identifier was truncated to '255' characters in the debug information +#endif//_MSC_VER + +#include +#include "rbuild.h" + +Exception::Exception() +{ +} + +Exception::Exception(string message) +{ + Message = message; +} + +Exception::Exception(const char* format, + ...) +{ + va_list args; + va_start(args, + format); + Message = ssvprintf(format, + args); + va_end(args); +} + +void Exception::SetMessage(const char* message, + va_list args) +{ + Message = ssvprintf(message, + args); +} + + +FileNotFoundException::FileNotFoundException(string filename) + : Exception ( "File '%s' not found.", filename.c_str() ) +{ + Filename = filename; +} + + +InvalidBuildFileException::InvalidBuildFileException(const char* message, + ...) +{ + va_list args; + va_start( args, message); + SetMessage(message, args); + va_end(args); +} diff --git a/reactos/tools/rbuild/exception.h b/reactos/tools/rbuild/exception.h new file mode 100644 index 00000000000..94a47e8cc48 --- /dev/null +++ b/reactos/tools/rbuild/exception.h @@ -0,0 +1,37 @@ +#ifndef __EXCEPTION_H +#define __EXCEPTION_H + +#include + +using std::string; + +class Exception +{ +public: + Exception(string message); + Exception(const char* format, + ...); + string Message; +protected: + Exception(); + void SetMessage(const char* message, + va_list args); +}; + + +class FileNotFoundException : public Exception +{ +public: + FileNotFoundException(string filename); + string Filename; +}; + + +class InvalidBuildFileException : public Exception +{ +public: + InvalidBuildFileException(const char* message, + ...); +}; + +#endif /* __EXCEPTION_H */ diff --git a/reactos/tools/rbuild/makefile b/reactos/tools/rbuild/makefile index 1d94f5babd9..8a0ae32ff24 100644 --- a/reactos/tools/rbuild/makefile +++ b/reactos/tools/rbuild/makefile @@ -4,7 +4,12 @@ TARGET = rbuild$(EXE_POSTFIX) all: $(TARGET) -BASE_OBJECTS = xml.o project.o module.o +BASE_OBJECTS = \ + exception.o \ + module.o \ + project.o \ + ssprintf.o \ + xml.o OBJECTS = $(BASE_OBJECTS) rbuild.o diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index bfd60363753..abc6d14a2ce 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -7,12 +7,44 @@ using std::string; using std::vector; +Project::Project(string filename) +{ + if ( !xmlfile.open ( filename ) ) + throw FileNotFoundException ( filename ); + ReadXml(); +} + Project::~Project() { for ( size_t i = 0; i < modules.size(); i++ ) delete modules[i]; } +void Project::ReadXml() +{ + Path path; + bool projectFound = false; + do + { + XMLElement* head = XMLParse ( xmlfile, path ); + if ( !head ) + throw InvalidBuildFileException ( "Document contains no 'project' tag." ); + + if ( head->name == "!--" ) + continue; // ignore comments + + if ( head->name != "project" ) + { + throw InvalidBuildFileException ( "Expected 'project', got '%s'.", + head->name.c_str()); + } + + this->ProcessXML ( *head, "." ); + delete head; + projectFound = true; + } while (!projectFound); +} + void Project::ProcessXML ( const XMLElement& e, const string& path ) { diff --git a/reactos/tools/rbuild/rbuild.cpp b/reactos/tools/rbuild/rbuild.cpp index 87004d2299e..51fff9beb77 100644 --- a/reactos/tools/rbuild/rbuild.cpp +++ b/reactos/tools/rbuild/rbuild.cpp @@ -17,40 +17,17 @@ main ( int argc, char** argv ) { InitWorkingDirectory(); - XMLFile f; - Path path; - string xml_file ( "ReactOS.xml" ); - if ( !f.open ( xml_file ) ) + try { - printf ( "couldn't open ReactOS.xml!\n" ); - return -1; - } - - vector xml_dependencies; - xml_dependencies.push_back ( xml_file ); - for ( ;; ) - { - XMLElement* head = XMLParse ( f, path ); - 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() ); - continue; - } - - Project* proj = new Project; - proj->ProcessXML ( *head, "." ); + string projectFilename ( "ReactOS.xml" ); + Project* project = new Project( projectFilename ); + Path path; // REM TODO FIXME actually do something with Project object... - printf ( "Found %d modules:\n", proj->modules.size() ); - for ( size_t i = 0; i < proj->modules.size(); i++ ) + printf ( "Found %d modules:\n", project->modules.size() ); + for ( size_t i = 0; i < project->modules.size(); i++ ) { - Module& m = *proj->modules[i]; + Module& m = *project->modules[i]; printf ( "\t%s in folder: %s\n", m.name.c_str(), m.path.c_str() ); @@ -74,10 +51,14 @@ main ( int argc, char** argv ) printf ( "\t\t%s\n", m.files[j]->name.c_str() ); } } + + delete project; - delete proj; - delete head; + return 0; + } + catch (Exception& ex) + { + printf ( ex.Message.c_str() ); + return 1; } - - return 0; } diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index d50dcaa362d..e133017a631 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -1,10 +1,11 @@ #ifndef __RBUILD_H #define __RBUILD_H -#include "XML.h" - #include #include +#include "ssprintf.h" +#include "exception.h" +#include "XML.h" class Project; class Module; @@ -16,8 +17,12 @@ public: std::string name; std::vector modules; - ~Project(); + Project ( string filename ); + ~Project (); void ProcessXML ( const XMLElement& e, const std::string& path ); +private: + void ReadXml (); + XMLFile xmlfile; }; class Module