From 76b675e9f02b9ae6d8c969298a24b846e322c649 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Jun 2019 23:30:46 -0400 Subject: [PATCH] Common/MsgHandler: Make default message handler and translator's internally linked Previously these functions were declared without the static specifier, giving them external linkage, which isn't really ideal. Instead, we can place these functions up by the relevant file-scope variables and place them inside an anonymous namespace with said variables, giving them internal linkage. --- Source/Core/Common/MsgHandler.cpp | 62 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/Source/Core/Common/MsgHandler.cpp b/Source/Core/Common/MsgHandler.cpp index 01a51a7e3f..2c36172cd2 100644 --- a/Source/Core/Common/MsgHandler.cpp +++ b/Source/Core/Common/MsgHandler.cpp @@ -19,12 +19,38 @@ #include "Common/Logging/Log.h" #include "Common/StringUtil.h" -bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgType style); -static MsgAlertHandler msg_handler = DefaultMsgHandler; -static bool AlertEnabled = true; +namespace +{ +// Default non library dependent panic alert +bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgType style) +{ +#ifdef _WIN32 + int window_style = MB_ICONINFORMATION; + if (style == MsgType::Question) + window_style = MB_ICONQUESTION; + if (style == MsgType::Warning) + window_style = MB_ICONWARNING; -std::string DefaultStringTranslator(const char* text); -static StringTranslator str_translator = DefaultStringTranslator; + return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), + window_style | (yes_no ? MB_YESNO : MB_OK)); +#else + fmt::print(stderr, "{}\n", text); + + // Return no to any question (which will in general crash the emulator) + return false; +#endif +} + +// Default (non) translator +std::string DefaultStringTranslator(const char* text) +{ + return text; +} + +MsgAlertHandler msg_handler = DefaultMsgHandler; +StringTranslator str_translator = DefaultStringTranslator; +bool AlertEnabled = true; +} // Anonymous namespace // Select which of these functions that are used for message boxes. If // Qt is enabled we will use QtMsgAlertHandler() that is defined in Main.cpp @@ -100,29 +126,3 @@ bool MsgAlert(bool yes_no, MsgType style, const char* format, ...) return true; } - -// Default non library dependent panic alert -bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, MsgType style) -{ -#ifdef _WIN32 - int window_style = MB_ICONINFORMATION; - if (style == MsgType::Question) - window_style = MB_ICONQUESTION; - if (style == MsgType::Warning) - window_style = MB_ICONWARNING; - - return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), - window_style | (yes_no ? MB_YESNO : MB_OK)); -#else - fmt::print(stderr, "{}\n", text); - - // Return no to any question (which will in general crash the emulator) - return false; -#endif -} - -// Default (non) translator -std::string DefaultStringTranslator(const char* text) -{ - return text; -}