foxygit / doom Log in
commit ef4c73fc8157ee3be6a41bf1f8bdce82657d715b
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun Jun 7 19:17:12 2015 -0400
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun Jun 7 19:17:12 2015 -0400

    textscreen: Refactor TXT_OpenURL() to simplify.

    In the Windows scenario we don't need to allocate any buffers; it's
    just a thin wrapper around ShellExecute().
---
 textscreen/txt_window.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c
index 41b8c8ef..48d01f79 100644
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -513,6 +513,15 @@ void TXT_SetWindowHelpURL(txt_window_t *window, char *help_url)
     window->help_url = help_url;
 }

+#ifdef _WIN32
+
+void TXT_OpenURL(char *url)
+{
+    ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
+}
+
+#else
+
 void TXT_OpenURL(char *url)
 {
     char *cmd;
@@ -523,7 +532,7 @@ void TXT_OpenURL(char *url)

 #if defined(__MACOSX__)
     TXT_snprintf(cmd, cmd_len, "open \"%s\"", url);
-#elif !defined(_WIN32)
+#else
     // The Unix situation sucks as usual, but the closest thing to a
     // standard that exists is the xdg-utils package.
     if (system("xdg-open --version 2>/dev/null") != 0)
@@ -536,14 +545,12 @@ void TXT_OpenURL(char *url)
     TXT_snprintf(cmd, cmd_len, "xdg-open \"%s\"", url);
 #endif

-#if defined(_WIN32)
-    ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
-#else
     system(cmd);
-#endif
     free(cmd);
 }

+#endif /* #ifndef _WIN32 */
+
 void TXT_OpenWindowHelpURL(txt_window_t *window)
 {
     if (window->help_url != NULL)