foxygit / doom Log in
commit 1ecd11222f7da8e54cd7c37d754eecb3ad7f09be
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Sep 2 19:02:11 2006 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Sep 2 19:02:11 2006 +0000

    Allow loading dehacked 2.3 patches.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 595
---
 src/deh_main.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/src/deh_main.c b/src/deh_main.c
index 81eb960d..448d53fa 100644
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*-
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_main.c 559 2006-06-18 22:54:48Z fraggle $
+// $Id: deh_main.c 595 2006-09-02 19:02:11Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -69,7 +69,11 @@
 #include "deh_defs.h"
 #include "deh_io.h"

-static char deh_signature[] = "Patch File for DeHackEd v3.0\n";
+static char *deh_signatures[] =
+{
+    "Patch File for DeHackEd v2.3",
+    "Patch File for DeHackEd v3.0",
+};

 // deh_ammo.c:
 extern deh_section_t deh_section_ammo;
@@ -214,19 +218,31 @@ boolean DEH_ParseAssignment(char *line, char **variable_name, char **value)
     return true;
 }

-static boolean CheckSignature(deh_context_t *context)
+static boolean CheckSignatures(deh_context_t *context)
 {
     int i;
+    char *line;
+
+    // Read the first line

-    for (i=0; i<strlen(deh_signature); ++i)
+    line = DEH_ReadLine(context);
+
+    if (line == NULL)
     {
-        int c = DEH_GetChar(context);
+        return false;
+    }

-        if (c != deh_signature[i])
-            return false;
+    // Check all signatures to see if one matches
+
+    for (i=0; i<sizeof(deh_signatures) / sizeof(*deh_signatures); ++i)
+    {
+        if (!strcmp(deh_signatures[i], line))
+        {
+            return true;
+        }
     }

-    return true;
+    return false;
 }

 // Parses a dehacked file by reading from the context
@@ -240,9 +256,9 @@ static void DEH_ParseContext(deh_context_t *context)

     // Read the header and check it matches the signature

-    if (!CheckSignature(context))
+    if (!CheckSignatures(context))
     {
-        DEH_Error(context, "This is not a dehacked v3.0 patch file!");
+        DEH_Error(context, "This is not a valid dehacked patch file!");
     }

     // Read the file