foxygit / doom Log in
commit 59a80b5a902d51d03fb079b0ec5560d450f92731
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Mar 29 23:56:44 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Mar 30 00:24:44 2014 -0400

    heretic: Make -playdemo cope with paths.

    Vanilla Heretic makes you specify the demo name to play by giving
    the plain lump name, eg. heretic -playdemo mydemo to load mydemo.lmp.
    It doesn't work if you specify the extension or the full file path.
    As a convenience and to match the behavior of Chocolate Doom, allow
    paths and extensions.

    This fixes half of #301.
---
 src/heretic/d_main.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 7a5517f2..316a30b8 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -812,6 +812,7 @@ void D_DoomMain(void)
     GameMission_t gamemission;
     int p;
     char file[256];
+    char demolumpname[9];

     I_PrintBanner(PACKAGE_STRING);

@@ -1005,9 +1006,26 @@ void D_DoomMain(void)

     if (p)
     {
-        DEH_snprintf(file, sizeof(file), "%s.lmp", myargv[p + 1]);
-        D_AddFile(file);
-        DEH_printf("Playing demo %s.lmp.\n", myargv[p + 1]);
+        if (!M_StringEndsWith(myargv[p + 1], ".lmp"))
+        {
+            DEH_snprintf(file, sizeof(file), "%s.lmp", myargv[p + 1]);
+        }
+        else
+        {
+            M_StringCopy(file, myargv[p + 1], sizeof(file));
+        }
+
+        if (D_AddFile(file))
+        {
+            M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
+                         sizeof(demolumpname));
+
+            DEH_printf("Playing demo %s.\n", file);
+        }
+        else
+        {
+            M_StringCopy(demolumpname, myargv[p + 1], sizeof(demolumpname));
+        }
     }

     if (W_CheckNumForName(DEH_String("E2M1")) == -1)
@@ -1137,14 +1155,14 @@ void D_DoomMain(void)
     if (p)
     {
         singledemo = true;      // Quit after one demo
-        G_DeferedPlayDemo(myargv[p + 1]);
+        G_DeferedPlayDemo(demolumpname);
         D_DoomLoop();           // Never returns
     }

     p = M_CheckParmWithArgs("-timedemo", 1);
     if (p)
     {
-        G_TimeDemo(myargv[p + 1]);
+        G_TimeDemo(demolumpname);
         D_DoomLoop();           // Never returns
     }