shithub: choc

Download patch

ref: 7dce8d5c99ddcb2a0dd8d12cd1ea86e5a6523f63
parent: 098632eacf994311f735ab9ef41548dfcc23abf4
parent: 3cba305fc282eacac3525c382ff4745fd5e87fde
author: Simon Howard <fraggle@soulsphere.org>
date: Wed Sep 30 09:41:46 EDT 2020

Merge pull request #1298 from mfrancis95/normaliseslashes

Run M_NormalizeSlashes on paths

--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -661,3 +661,46 @@
 
 #endif
 
+//
+// M_NormalizeSlashes
+//
+// Remove trailing slashes, translate backslashes to slashes
+// The string to normalize is passed and returned in str
+//
+// killough 11/98: rewritten
+//
+// [STRIFE] - haleyjd 20110210: Borrowed from Eternity and adapted to respect
+// the DIR_SEPARATOR define used by Choco Doom. This routine originated in
+// BOOM.
+//
+void M_NormalizeSlashes(char *str)
+{
+    char *p;
+
+    // Convert all slashes/backslashes to DIR_SEPARATOR
+    for (p = str; *p; p++)
+    {
+        if ((*p == '/' || *p == '\\') && *p != DIR_SEPARATOR)
+        {
+            *p = DIR_SEPARATOR;
+        }
+    }
+
+    // Remove trailing slashes
+    while (p > str && *--p == DIR_SEPARATOR)
+    {
+        *p = 0;
+    }
+
+    // Collapse multiple slashes
+    for (p = str; (*str++ = *p); )
+    {
+        if (*p++ == DIR_SEPARATOR)
+        {
+            while (*p == DIR_SEPARATOR)
+            {
+                p++;
+            }
+        }
+    }
+}
\ No newline at end of file
--- a/src/m_misc.h
+++ b/src/m_misc.h
@@ -50,6 +50,7 @@
 int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args);
 int M_snprintf(char *buf, size_t buf_len, const char *s, ...) PRINTF_ATTR(3, 4);
 char *M_OEMToUTF8(const char *ansi);
+void M_NormalizeSlashes(char *str);
 
 #endif
 
--- a/src/strife/m_saves.c
+++ b/src/strife/m_saves.c
@@ -362,40 +362,6 @@
 }
 
 //
-// M_NormalizeSlashes
-//
-// Remove trailing slashes, translate backslashes to slashes
-// The string to normalize is passed and returned in str
-//
-// killough 11/98: rewritten
-//
-// [STRIFE] - haleyjd 20110210: Borrowed from Eternity and adapted to respect 
-// the DIR_SEPARATOR define used by Choco Doom. This routine originated in
-// BOOM.
-//
-void M_NormalizeSlashes(char *str)
-{
-    char *p;
-   
-    // Convert all slashes/backslashes to DIR_SEPARATOR
-    for(p = str; *p; p++)
-    {
-        if((*p == '/' || *p == '\\') && *p != DIR_SEPARATOR)
-            *p = DIR_SEPARATOR;
-    }
-
-    // Remove trailing slashes
-    while(p > str && *--p == DIR_SEPARATOR)
-        *p = 0;
-
-    // Collapse multiple slashes
-    for(p = str; (*str++ = *p); )
-        if(*p++ == DIR_SEPARATOR)
-            while(*p == DIR_SEPARATOR)
-                p++;
-}
-
-//
 // M_SafeFilePath
 //
 // haleyjd 20110210 - original routine.
--- a/src/strife/m_saves.h
+++ b/src/strife/m_saves.h
@@ -42,7 +42,6 @@
 
 // Custom Utilities for Filepath Handling
 void *M_Calloc(size_t n1, size_t n2);
-void  M_NormalizeSlashes(char *str);
 int   M_StringAlloc(char **str, int numstrs, size_t extra, const char *str1, ...);
 char *M_SafeFilePath(const char *basepath, const char *newcomponent);
 char  M_GetFilePath(const char *fn, char *dest, size_t len);