shithub: choc

Download patch

ref: ef4c73fc8157ee3be6a41bf1f8bdce82657d715b
parent: f69c5a10071b9ac231fd2edfeb49fa6afd7c3948
author: Simon Howard <fraggle@soulsphere.org>
date: Sun Jun 7 15:17:12 EDT 2015

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().

--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -513,8 +513,17 @@
     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;
     size_t cmd_len;
 
@@ -523,7 +532,7 @@
 
 #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,13 +545,11 @@
     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)
 {