Add ROS_ARCH environment variable
[reactos.git] / reactos / tools / rbuild / exception.cpp
index efb4951..d19179a 100644 (file)
@@ -1,6 +1,21 @@
-
+/*
+ * Copyright (C) 2005 Casper S. Hornstrup
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 #include "pch.h"
-
 #include "rbuild.h"
 
 using std::string;
@@ -11,25 +26,35 @@ Exception::Exception ()
 
 Exception::Exception ( const string& message )
 {
-       Message = message;
+       _e = message;
+}
+
+Exception::Exception ( const char* format, ...)
+{
+       va_list args;
+       va_start ( args, format);
+       _e = ssvprintf ( format, args);
+       va_end ( args );
 }
 
-Exception::Exception ( const char* format,
-                       ...)
+void Exception::SetMessage ( 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::SetMessageV ( const char* message, va_list args )
+{
+       _e = ssvprintf ( message, args);
+}
+
+
+MissingArgumentException::MissingArgumentException ( const string& argument )
+       : Exception ( "Argument '%s' is missing",
+                     argument.c_str () )
 {
-       Message = ssvprintf ( message,
-                             args);
 }
 
 
@@ -39,30 +64,36 @@ OutOfMemoryException::OutOfMemoryException ()
 }
 
 
-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,
-                                                       ... )
+InvalidDateException::InvalidDateException ( const string& filename)
+       : Exception ( "File '%s' has an invalid date.",
+                    filename.c_str() )
+{
+       Filename = filename;
+}
+
+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 () );
 }
 
 
@@ -82,49 +113,15 @@ AccessDeniedException::AccessDeniedException ( const string& filename)
 }
 
 
-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 ())
 {
 }
 
@@ -132,10 +129,11 @@ InvalidAttributeValueException::InvalidAttributeValueException (
        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 () )
 {
        
 }
@@ -156,9 +154,10 @@ UnknownBackendException::UnknownBackendException ( const string& name )
 
 UnknownModuleTypeException::UnknownModuleTypeException ( const string& location,
                                                          int moduletype )
-       : InvalidBuildFileException ( location,
-                                     "module type requested: %i",
-                                     moduletype )
+       : XMLInvalidBuildFileException (
+               location,
+               "module type requested: %i",
+               moduletype )
 {
 }
 
@@ -172,3 +171,14 @@ InvocationFailedException::InvocationFailedException ( const std::string& comman
        Command = command;
        ExitCode = exitcode;
 }
+
+
+UnsupportedBuildToolException::UnsupportedBuildToolException ( const std::string& buildTool,
+                                                               const std::string& version )
+       : Exception ( "Build tool '%s' with version '%s' is unsupported. Please upgrade your build tool.",
+                     buildTool.c_str (),
+                     version.c_str () )
+{
+       BuildTool = buildTool;
+       Version  = version;
+}