foxygit / doom Log in
commit a8839cecaa12fc3d9afb2bad0863b7b97901bc4c
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Dec 25 21:51:24 2010 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Dec 25 21:51:24 2010 +0000

    Pass through all command line arguments specified to the setup tool to
    the game, to match Vanilla behavior (thanks AlexXav).

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 2227
---
 NEWS                |  2 ++
 setup/execute.c     | 55 +++++++++++++++++++++++++++++++++++------------------
 setup/execute.h     |  2 +-
 setup/mainmenu.c    |  2 +-
 setup/multiplayer.c |  4 ++--
 5 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/NEWS b/NEWS
index 0b198e02..c3289f3c 100644
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,8 @@
        removed from the title of the dialog box that appears on
        Windows when this happens.  This is desirable as not all such
        messages are actually errors (thanks Proteh).
+     * The setup tool now passes through all command line arguments
+       when launching the game (thanks AlexXav).

     Bugs fixed:
      * A workaround has been a bug in old versions of SDL_mixer
diff --git a/setup/execute.c b/setup/execute.c
index 8e753f60..69442b5d 100644
--- a/setup/execute.c
+++ b/setup/execute.c
@@ -101,6 +101,42 @@ static char *TempFile(char *s)
     return result;
 }

+static int ArgumentNeedsEscape(char *arg)
+{
+    char *p;
+
+    for (p = arg; *p != '\0'; ++p)
+    {
+        if (isspace(*p))
+        {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+// Arguments passed to the setup tool should be passed through to the
+// game when launching a game.  Calling this adds all arguments from
+// myargv to the output context.
+
+void PassThroughArguments(execute_context_t *context)
+{
+    int i;
+
+    for (i = 1; i < myargc; ++i)
+    {
+        if (ArgumentNeedsEscape(myargv[i]))
+        {
+            AddCmdLineParameter(context, "\"%s\"", myargv[i]);
+        }
+        else
+        {
+            AddCmdLineParameter(context, "%s", myargv[i]);
+        }
+    }
+}
+
 execute_context_t *NewExecuteContext(void)
 {
     execute_context_t *result;
@@ -119,25 +155,6 @@ execute_context_t *NewExecuteContext(void)
     return result;
 }

-void AddConfigParameters(execute_context_t *context)
-{
-    int p;
-
-    p = M_CheckParm("-config");
-
-    if (p > 0)
-    {
-        AddCmdLineParameter(context, "-config \"%s\"", myargv[p + 1]);
-    }
-
-    p = M_CheckParm("-extraconfig");
-
-    if (p > 0)
-    {
-        AddCmdLineParameter(context, "-extraconfig \"%s\"", myargv[p + 1]);
-    }
-}
-
 void AddCmdLineParameter(execute_context_t *context, char *s, ...)
 {
     va_list args;
diff --git a/setup/execute.h b/setup/execute.h
index 24711a16..25f1f10a 100644
--- a/setup/execute.h
+++ b/setup/execute.h
@@ -35,7 +35,7 @@ typedef struct execute_context_s execute_context_t;

 execute_context_t *NewExecuteContext(void);
 void AddCmdLineParameter(execute_context_t *context, char *s, ...);
-void AddConfigParameters(execute_context_t *context);
+void PassThroughArguments(execute_context_t *context);
 int ExecuteDoom(execute_context_t *context);
 int FindInstalledIWADs(void);

diff --git a/setup/mainmenu.c b/setup/mainmenu.c
index 1c341d78..ae8ab9b0 100644
--- a/setup/mainmenu.c
+++ b/setup/mainmenu.c
@@ -152,7 +152,7 @@ static void LaunchDoom(void *unused1, void *unused2)
     // Launch Doom

     exec = NewExecuteContext();
-    AddConfigParameters(exec);
+    PassThroughArguments(exec);
     ExecuteDoom(exec);

     exit(0);
diff --git a/setup/multiplayer.c b/setup/multiplayer.c
index 2cb961d7..eece16d4 100644
--- a/setup/multiplayer.c
+++ b/setup/multiplayer.c
@@ -265,7 +265,7 @@ static void StartGame(int multiplayer)
     TXT_Shutdown();

     M_SaveDefaults();
-    AddConfigParameters(exec);
+    PassThroughArguments(exec);

     ExecuteDoom(exec);

@@ -702,7 +702,7 @@ static void DoJoinGame(void *unused1, void *unused2)

     M_SaveDefaults();

-    AddConfigParameters(exec);
+    PassThroughArguments(exec);

     ExecuteDoom(exec);