Exception handling. Added: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp Added: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/makefile Modified: branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp 2005-01-04 20:10:11 UTC (rev 12796) +++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp 2005-01-04 20:37:48 UTC (rev 12797) @@ -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 <stdarg.h> +#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); +} _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h --- branches/xmlbuildsystem/reactos/tools/rbuild/exception.h 2005-01-04 20:10:11 UTC (rev 12796) +++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.h 2005-01-04 20:37:48 UTC (rev 12797) @@ -0,0 +1,37 @@
+#ifndef __EXCEPTION_H +#define __EXCEPTION_H + +#include <string> + +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 */ _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/makefile --- branches/xmlbuildsystem/reactos/tools/rbuild/makefile 2005-01-04 20:10:11 UTC (rev 12796) +++ branches/xmlbuildsystem/reactos/tools/rbuild/makefile 2005-01-04 20:37:48 UTC (rev 12797) @@ -4,7 +4,12 @@
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
_____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp 2005-01-04 20:10:11 UTC (rev 12796) +++ branches/xmlbuildsystem/reactos/tools/rbuild/project.cpp 2005-01-04 20:37:48 UTC (rev 12797) @@ -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 ) { _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp 2005-01-04 20:10:11 UTC (rev 12796) +++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.cpp 2005-01-04 20:37:48 UTC (rev 12797) @@ -17,40 +17,17 @@
{ 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; - } + string projectFilename ( "ReactOS.xml" ); + Project* project = new Project( projectFilename );
- vector<string> 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, "." ); - + 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 @@ printf ( "\t\t%s\n", m.files[j]->name.c_str() ); } } + + delete project;
- delete proj; - delete head; + return 0; } - - return 0; + catch (Exception& ex) + { + printf ( ex.Message.c_str() ); + return 1; + } } _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h --- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-01-04 20:10:11 UTC (rev 12796) +++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-01-04 20:37:48 UTC (rev 12797) @@ -1,10 +1,11 @@
#ifndef __RBUILD_H #define __RBUILD_H
-#include "XML.h" - #include <string> #include <vector> +#include "ssprintf.h" +#include "exception.h" +#include "XML.h"
class Project; class Module; @@ -16,8 +17,12 @@ std::string name; std::vector<Module*> modules;
- ~Project(); + Project ( string filename ); + ~Project (); void ProcessXML ( const XMLElement& e, const std::string& path ); +private: + void ReadXml (); + XMLFile xmlfile; };
class Module