diff options
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Console/MainAr.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/7zip/UI/Console/MainAr.cpp | 113 |
1 files changed, 78 insertions, 35 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Console/MainAr.cpp b/3rdparty/lzma/CPP/7zip/UI/Console/MainAr.cpp index 25f4bd0df44..d30a96e4be2 100644 --- a/3rdparty/lzma/CPP/7zip/UI/Console/MainAr.cpp +++ b/3rdparty/lzma/CPP/7zip/UI/Console/MainAr.cpp @@ -2,11 +2,11 @@ #include "StdAfx.h" -#include "Common/MyException.h" -#include "Common/StdOutStream.h" +#include "../../../Common/MyException.h" +#include "../../../Common/StdOutStream.h" -#include "Windows/Error.h" -#include "Windows/NtCheck.h" +#include "../../../Windows/ErrorMsg.h" +#include "../../../Windows/NtCheck.h" #include "../Common/ArchiveCommandLine.h" #include "../Common/ExitCode.h" @@ -15,35 +15,52 @@ using namespace NWindows; -CStdOutStream *g_StdStream = 0; +CStdOutStream *g_StdStream = NULL; +CStdOutStream *g_ErrStream = NULL; extern int Main2( #ifndef _WIN32 - int numArgs, const char *args[] + int numArgs, char *args[] #endif ); -static const char *kExceptionErrorMessage = "\n\nError:\n"; -static const char *kUserBreak = "\nBreak signaled\n"; -static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required memory!\n"; -static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n"; +static const char *kException_CmdLine_Error_Message = "Command Line Error:"; +static const char *kExceptionErrorMessage = "ERROR:"; +static const char *kUserBreakMessage = "Break signaled"; +static const char *kMemoryExceptionMessage = "ERROR: Can't allocate required memory!"; +static const char *kUnknownExceptionMessage = "Unknown Error"; static const char *kInternalExceptionMessage = "\n\nInternal Error #"; -#define NT_CHECK_FAIL_ACTION (*g_StdStream) << "Unsupported Windows version"; return NExitCode::kFatalError; +static void FlushStreams() +{ + if (g_StdStream) + g_StdStream->Flush(); +} + +static void PrintError(const char *message) +{ + FlushStreams(); + if (g_ErrStream) + *g_ErrStream << "\n\n" << message << endl; +} + +#define NT_CHECK_FAIL_ACTION *g_StdStream << "Unsupported Windows version"; return NExitCode::kFatalError; int MY_CDECL main ( #ifndef _WIN32 - int numArgs, const char *args[] + int numArgs, char *args[] #endif ) { + g_ErrStream = &g_StdErr; g_StdStream = &g_StdOut; NT_CHECK NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; int res = 0; + try { res = Main2( @@ -54,71 +71,97 @@ int MY_CDECL main } catch(const CNewException &) { - (*g_StdStream) << kMemoryExceptionMessage; + PrintError(kMemoryExceptionMessage); return (NExitCode::kMemoryError); } catch(const NConsoleClose::CCtrlBreakException &) { - (*g_StdStream) << endl << kUserBreak; + PrintError(kUserBreakMessage); return (NExitCode::kUserBreak); } - catch(const CArchiveCommandLineException &e) + catch(const CArcCmdLineException &e) { - (*g_StdStream) << kExceptionErrorMessage << e << endl; + PrintError(kException_CmdLine_Error_Message); + if (g_ErrStream) + *g_ErrStream << e << endl; return (NExitCode::kUserError); } catch(const CSystemException &systemError) { if (systemError.ErrorCode == E_OUTOFMEMORY) { - (*g_StdStream) << kMemoryExceptionMessage; + PrintError(kMemoryExceptionMessage); return (NExitCode::kMemoryError); } if (systemError.ErrorCode == E_ABORT) { - (*g_StdStream) << endl << kUserBreak; + PrintError(kUserBreakMessage); return (NExitCode::kUserBreak); } - (*g_StdStream) << endl << endl << "System error:" << endl << - NError::MyFormatMessageW(systemError.ErrorCode) << endl; + if (g_ErrStream) + { + PrintError("System ERROR:"); + *g_ErrStream << NError::MyFormatMessage(systemError.ErrorCode) << endl; + } return (NExitCode::kFatalError); } catch(NExitCode::EEnum &exitCode) { - (*g_StdStream) << kInternalExceptionMessage << exitCode << endl; + FlushStreams(); + if (g_ErrStream) + *g_ErrStream << kInternalExceptionMessage << exitCode << endl; return (exitCode); } - /* - catch(const NExitCode::CMultipleErrors &multipleErrors) - { - (*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl; - return (NExitCode::kFatalError); - } - */ catch(const UString &s) { - (*g_StdStream) << kExceptionErrorMessage << s << endl; + if (g_ErrStream) + { + PrintError(kExceptionErrorMessage); + *g_ErrStream << s << endl; + } return (NExitCode::kFatalError); } catch(const AString &s) { - (*g_StdStream) << kExceptionErrorMessage << s << endl; + if (g_ErrStream) + { + PrintError(kExceptionErrorMessage); + *g_ErrStream << s << endl; + } return (NExitCode::kFatalError); } catch(const char *s) { - (*g_StdStream) << kExceptionErrorMessage << s << endl; + if (g_ErrStream) + { + PrintError(kExceptionErrorMessage); + *g_ErrStream << s << endl; + } return (NExitCode::kFatalError); } - catch(int t) + catch(const wchar_t *s) { - (*g_StdStream) << kInternalExceptionMessage << t << endl; + if (g_ErrStream) + { + PrintError(kExceptionErrorMessage); + *g_ErrStream << s << endl; + } return (NExitCode::kFatalError); } + catch(int t) + { + if (g_ErrStream) + { + FlushStreams(); + *g_ErrStream << kInternalExceptionMessage << t << endl; + return (NExitCode::kFatalError); + } + } catch(...) { - (*g_StdStream) << kUnknownExceptionMessage; + PrintError(kUnknownExceptionMessage); return (NExitCode::kFatalError); } - return res; + + return res; } |