From df2b793c0a3ee098d3b93cb3f8ed31c632dbcffd Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 11 Jan 2016 21:49:13 +0000 Subject: [PATCH] refactor console error output --- src/cmdline/CommandLine.cpp | 30 +++++++++++++------------- src/cmdline/RootCommands.cpp | 6 +++--- src/core/Console.cpp | 42 +++++++++++++++++++++++------------- src/core/Console.hpp | 13 +++++++---- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/cmdline/CommandLine.cpp b/src/cmdline/CommandLine.cpp index aeca7e203e..f985a87122 100644 --- a/src/cmdline/CommandLine.cpp +++ b/src/cmdline/CommandLine.cpp @@ -350,7 +350,7 @@ namespace CommandLine } else if (!firstOption) { - Console::WriteLineError("All options must be passed at the end of the command line."); + Console::Error::WriteLine("All options must be passed at the end of the command line."); return false; } else @@ -383,8 +383,8 @@ namespace CommandLine const CommandLineOptionDefinition * option = FindOption(options, optionName); if (option == nullptr) { - Console::WriteError("Unknown option: --"); - Console::WriteLineError(optionName); + Console::Error::Write("Unknown option: --"); + Console::Error::WriteLine(optionName); return false; } @@ -399,8 +399,8 @@ namespace CommandLine const char * valueString = nullptr; if (!argEnumerator->TryPopString(&valueString)) { - Console::WriteError("Expected value for option: "); - Console::WriteLineError(optionName); + Console::Error::Write("Expected value for option: "); + Console::Error::WriteLine(optionName); return false; } @@ -414,8 +414,8 @@ namespace CommandLine { if (option->Type == CMDLINE_TYPE_SWITCH) { - Console::WriteError("Option is a switch: "); - Console::WriteLineError(optionName); + Console::Error::Write("Option is a switch: "); + Console::Error::WriteLine(optionName); return false; } else @@ -442,9 +442,9 @@ namespace CommandLine option = FindOption(options, shortOption[0]); if (option == nullptr) { - Console::WriteError("Unknown option: -"); - Console::WriteError(shortOption[0]); - Console::WriteLineError(); + Console::Error::Write("Unknown option: -"); + Console::Error::Write(shortOption[0]); + Console::Error::WriteLine(); return false; } if (option->Type == CMDLINE_TYPE_SWITCH) @@ -469,9 +469,9 @@ namespace CommandLine const char * valueString = nullptr; if (!argEnumerator->TryPopString(&valueString)) { - Console::WriteError("Expected value for option: "); - Console::WriteError(option->ShortName); - Console::WriteLineError(); + Console::Error::Write("Expected value for option: "); + Console::Error::Write(option->ShortName); + Console::Error::WriteLine(); return false; } @@ -502,8 +502,8 @@ namespace CommandLine *((utf8 * *)option->OutAddress) = String::Duplicate(valueString); return true; default: - Console::WriteError("Unknown CMDLINE_TYPE for: "); - Console::WriteLineError(option->LongName); + Console::Error::Write("Unknown CMDLINE_TYPE for: "); + Console::Error::WriteLine(option->LongName); return false; } } diff --git a/src/cmdline/RootCommands.cpp b/src/cmdline/RootCommands.cpp index 45b360f748..9c9f24b851 100644 --- a/src/cmdline/RootCommands.cpp +++ b/src/cmdline/RootCommands.cpp @@ -163,7 +163,7 @@ exitcode_t HandleCommandEdit(CommandLineArgEnumerator * enumerator) const char * parkUri; if (!enumerator->TryPopString(&parkUri)) { - Console::WriteLineError("Expected path or URL to a saved park."); + Console::Error::WriteLine("Expected path or URL to a saved park."); return EXITCODE_FAIL; } String::Set(gOpenRCT2StartupActionPath, sizeof(gOpenRCT2StartupActionPath), parkUri); @@ -197,7 +197,7 @@ exitcode_t HandleCommandHost(CommandLineArgEnumerator * enumerator) const char * parkUri; if (!enumerator->TryPopString(&parkUri)) { - Console::WriteLineError("Expected path or URL to a saved park."); + Console::Error::WriteLine("Expected path or URL to a saved park."); return EXITCODE_FAIL; } @@ -220,7 +220,7 @@ exitcode_t HandleCommandJoin(CommandLineArgEnumerator * enumerator) const char * hostname; if (!enumerator->TryPopString(&hostname)) { - Console::WriteLineError("Expected a hostname or IP address to the server to connect to."); + Console::Error::WriteLine("Expected a hostname or IP address to the server to connect to."); return EXITCODE_FAIL; } diff --git a/src/core/Console.cpp b/src/core/Console.cpp index e4cde07de9..713e651378 100644 --- a/src/core/Console.cpp +++ b/src/core/Console.cpp @@ -44,24 +44,36 @@ namespace Console puts(str); } - void WriteError(char c) + namespace Error { - fputc(c, stderr); - } + void Write(char c) + { + fputc(c, stderr); + } - void WriteError(const utf8 * str) - { - fputs(str, stderr); - } + void Write(const utf8 * str) + { + fputs(str, stderr); + } - void WriteLineError() - { - fputs(platform_get_new_line(), stderr); - } + void WriteFormat(const utf8 * format, ...) + { + va_list args; - void WriteLineError(const utf8 * str) - { - fputs(str, stderr); - WriteLineError(); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + } + + void WriteLine() + { + fputs(platform_get_new_line(), stderr); + } + + void WriteLine(const utf8 * str) + { + fputs(str, stderr); + WriteLine(); + } } } \ No newline at end of file diff --git a/src/core/Console.hpp b/src/core/Console.hpp index b9e30309f6..36068ae204 100644 --- a/src/core/Console.hpp +++ b/src/core/Console.hpp @@ -13,8 +13,13 @@ namespace Console void WriteFormat(const utf8 * format, ...); void WriteLine(); void WriteLine(const utf8 * str); - void WriteError(char c); - void WriteError(const utf8 * str); - void WriteLineError(); - void WriteLineError(const utf8 * str); + + namespace Error + { + void Write(char c); + void Write(const utf8 * str); + void WriteFormat(const utf8 * format, ...); + void WriteLine(); + void WriteLine(const utf8 * str); + } }