shithub: choc

Download patch

ref: 5f3eb6fee3165a44ca032c9642130dddb2128e1d
parent: 366f45c10a632443767cbda6f7b2f3d98a60d60b
author: Fabian Greffrath <fabian@greffrath.com>
date: Thu Sep 11 08:37:28 EDT 2014

improvements to the [STRINGS] section parser

- restructure DEH_ReadLine() to avoid use of "goto"
- bex_string_t type name ends in "_t"
- declare constant table as "static const"
- add magic comment *allow-extended-strings* and corresponding
  variable deh_allow_extended_strings
- fix logical error when no [STRINGS] section is registered to which
  corrent_section could be compared

--- a/src/deh_io.c
+++ b/src/deh_io.c
@@ -28,6 +28,7 @@
 
 #include "deh_defs.h"
 #include "deh_io.h"
+#include "deh_main.h"
 
 typedef enum
 {
@@ -229,6 +230,7 @@
 {
     int c;
     int pos;
+    boolean escaped = false;
 
     for (pos = 0;;)
     {
@@ -249,9 +251,8 @@
         }
 
         // extended string support
-        if (extended && c == '\\')
+        if (deh_allow_extended_strings && extended && c == '\\')
         {
-            escaped:
             c = DEH_GetChar(context);
 
             // "\n" in the middle of a string indicates an internal linefeed
@@ -266,20 +267,20 @@
             // each line that is to be continued with a backslash
             if (c == '\n')
             {
-                // blanks before the backslash are included in the string
-                // but indentation after the linefeed is not
-                do
-                {
-                    c = DEH_GetChar(context);
-                } while (isspace(c) && c != '\n');
-
-                // if the next non-space character after an escaped linefeed
-                // is another backslash, repeat again
-                if (c == '\\')
-                {
-                    goto escaped;
-                }
+                escaped = true;
+                continue;
             }
+        }
+
+        // blanks before the backslash are included in the string
+        // but indentation after the linefeed is not
+        if (escaped && isspace(c) && c != '\n')
+        {
+            continue;
+        }
+        else
+        {
+            escaped = false;
         }
 
         if (c == '\n')
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -33,6 +33,10 @@
 
 static boolean deh_initialized = false;
 
+// If true, we can parse [STRINGS] sections in BEX format.
+
+boolean deh_allow_extended_strings = false;
+
 // If true, we can do long string replacements.
 
 boolean deh_allow_long_strings = false;
@@ -220,6 +224,16 @@
     {
         deh_allow_long_cheats = true;
     }
+
+    // Allow magic comments to allow parsing [STRINGS] section
+    // that are usually only found in BEX format files. This allows
+    // for substitution of map and episode names when loading
+    // Freedoom/FreeDM IWADs.
+
+    if (strstr(comment, "*allow-extended-strings*") != NULL)
+    {
+        deh_allow_extended_strings = true;
+    }
 }
 
 // Parses a dehacked file by reading from the context
@@ -230,6 +244,7 @@
     char section_name[20];
     void *tag = NULL;
     char *line;
+    deh_section_t *bexstr;
     
     // Read the header and check it matches the signature
 
@@ -242,9 +257,13 @@
     
     for (;;) 
     {
+        // extended string support required?
+
+        bexstr = GetSectionByName("[STRINGS]");
+
         // read a new line
  
-        line = DEH_ReadLine(context, current_section == GetSectionByName("[STRINGS]"));
+        line = DEH_ReadLine(context, bexstr && current_section == bexstr);
 
         // end of file?
 
--- a/src/deh_main.h
+++ b/src/deh_main.h
@@ -39,6 +39,7 @@
 
 void DEH_Checksum(sha1_digest_t digest);
 
+extern boolean deh_allow_extended_strings;
 extern boolean deh_allow_long_strings;
 extern boolean deh_allow_long_cheats;
 extern boolean deh_apply_cheats;
--- a/src/doom/deh_bexstr.c
+++ b/src/doom/deh_bexstr.c
@@ -28,10 +28,10 @@
 typedef struct {
     char *macro;
     char *string;
-} bex_string;
+} bex_string_t;
 
 // mnemonic keys table
-static bex_string bex_stringtable[] = {
+static const bex_string_t bex_stringtable[] = {
     // part 1 - general initialization and prompts
     {"D_DEVSTR", D_DEVSTR},
     {"D_CDROM", D_CDROM},