shithub: choc

Download patch

ref: 5af0b0450d5e7ae30ec6cef585f1f5c4ef4dddce
parent: f1d79f495d4ad394c87d7fc11132c120736658fa
author: Simon Howard <fraggle@gmail.com>
date: Fri Sep 20 19:50:44 EDT 2013

Set setup tool title so that it it shows the name of the correct game
being configured, not just always "Chocolate Doom".

Subversion-branch: /branches/v2-branch
Subversion-revision: 2669

--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -296,6 +296,61 @@
     return NULL;
 }
 
+//
+// String replace function.
+// Returns a Z_Malloc()ed string.
+//
+
+char *M_StringReplace(char *haystack, char *needle, char *replacement)
+{
+    char *result, *p, *dst;
+    size_t needle_len = strlen(needle);
+    int n;
+
+    // Count number of occurrences of 'p':
+
+    for (p = haystack, n = 0;; ++n)
+    {
+        p = strstr(p, needle);
+
+        if (p == NULL)
+        {
+            break;
+        }
+
+        p += needle_len;
+    }
+
+    // Construct new string.
+
+    result = Z_Malloc(strlen(haystack)
+                      + (strlen(replacement) - needle_len) * n
+                      + 1,
+                      PU_STATIC, NULL);
+
+    dst = result;
+    p = haystack;
+
+    while (*p != '\0')
+    {
+        if (!strncmp(p, needle, needle_len))
+        {
+            strcpy(dst, replacement);
+            dst += strlen(replacement);
+            p += needle_len;
+        }
+        else
+        {
+            *dst = *p;
+            ++dst;
+            ++p;
+        }
+    }
+    *dst = '\0';
+
+    return result;
+}
+
 #ifdef _WIN32
 
 char *M_OEMToUTF8(const char *oem)
--- a/src/m_misc.h
+++ b/src/m_misc.h
@@ -43,6 +43,7 @@
 void M_ExtractFileBase(char *path, char *dest);
 void M_ForceUppercase(char *text);
 char *M_StrCaseStr(char *haystack, char *needle);
+char *M_StringReplace(char *haystack, char *needle, char *replacement);
 char *M_OEMToUTF8(const char *ansi);
 
 #endif
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -31,6 +31,8 @@
 #include "m_argv.h"
 #include "m_config.h"
 #include "m_controls.h"
+#include "m_misc.h"
+#include "z_zone.h"
 
 #include "setup_icon.c"
 #include "mode.h"
@@ -316,6 +318,20 @@
     free(mask);
 }
 
+static void SetWindowTitle(void)
+{
+    char *title;
+
+    title = M_StringReplace(PACKAGE_NAME " Setup ver " PACKAGE_VERSION,
+                            "Doom",
+                            GetGameTitle());
+
+
+    TXT_SetDesktopTitle(title);
+
+    Z_Free(title);
+}
+
 // Initialize the textscreen library.
 
 static void InitTextscreen(void)
@@ -328,8 +344,8 @@
         exit(-1);
     }
 
-    TXT_SetDesktopTitle(PACKAGE_NAME " Setup ver " PACKAGE_VERSION);
     SetIcon();
+    SetWindowTitle();
 }
 
 // Restart the textscreen library.  Used when the video_driver variable
@@ -354,6 +370,7 @@
 
 static void MissionSet(void)
 {
+    SetWindowTitle();
     InitConfig();
     MainMenu();
 }
--- a/src/setup/mode.c
+++ b/src/setup/mode.c
@@ -112,6 +112,7 @@
 static int detailLevel = 0;
 static char *savedir = NULL;
 static char *executable = NULL;
+static char *game_title = "Doom";
 static char *back_flat = "F_PAVE01";
 static int comport = 0;
 static char *nickname = NULL;
@@ -223,6 +224,7 @@
     iwads = D_FindAllIWADs(config->mask);
     gamemission = config->mission;
     SetExecutable(config);
+    game_title = config->label;
     M_SetConfigFilenames(config->config_file, config->extra_config_file);
 }
 
@@ -372,6 +374,11 @@
 char *GetExecutableName(void)
 {
     return executable;
+}
+
+char *GetGameTitle(void)
+{
+    return game_title;
 }
 
 iwad_t **GetIwads(void)
--- a/src/setup/mode.h
+++ b/src/setup/mode.h
@@ -31,6 +31,7 @@
 void SetupMission(GameSelectCallback callback);
 void InitBindings(void);
 char *GetExecutableName(void);
+char *GetGameTitle(void);
 iwad_t **GetIwads(void);
 
 #endif /* #ifndef SETUP_MODE_H */