summaryrefslogtreecommitdiff
path: root/src/m_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/m_misc.c')
-rw-r--r--src/m_misc.c89
1 files changed, 86 insertions, 3 deletions
diff --git a/src/m_misc.c b/src/m_misc.c
index 9a5fb84a..ed41b5f1 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -2,6 +2,7 @@
//-----------------------------------------------------------------------------
//
// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 1993-2008 Raven Software
// Copyright(C) 2005 Simon Howard
//
// This program is free software; you can redistribute it and/or
@@ -27,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
#include <errno.h>
@@ -42,10 +44,9 @@
#include <sys/types.h>
#endif
-#include "doomdef.h"
-#include "doomstat.h"
+#include "doomtype.h"
-#include "deh_main.h"
+#include "deh_str.h"
#include "i_swap.h"
#include "i_system.h"
@@ -206,3 +207,85 @@ boolean M_StrToInt(const char *str, int *result)
|| sscanf(str, " %d", result) == 1;
}
+void M_ExtractFileBase(char *path, char *dest)
+{
+ char* src;
+ int length;
+
+ src = path + strlen(path) - 1;
+
+ // back up until a \ or the start
+ while (src != path && *(src - 1) != DIR_SEPARATOR)
+ {
+ src--;
+ }
+
+ // copy up to eight characters
+ memset(dest, 0, 8);
+ length = 0;
+
+ while (*src != '\0' && *src != '.')
+ {
+ ++length;
+
+ if (length > 8)
+ {
+ I_Error ("Filename base of %s >8 chars", path);
+ }
+
+ *dest++ = toupper((int)*src++);
+ }
+}
+
+//---------------------------------------------------------------------------
+//
+// PROC M_ForceUppercase
+//
+// Change string to uppercase.
+//
+//---------------------------------------------------------------------------
+
+void M_ForceUppercase(char *text)
+{
+ char *p;
+
+ for (p = text; *p != '\0'; ++p)
+ {
+ *p = toupper(*p);
+ }
+}
+
+//
+// M_StrCaseStr
+//
+// Case-insensitive version of strstr()
+//
+
+char *M_StrCaseStr(char *haystack, char *needle)
+{
+ unsigned int haystack_len;
+ unsigned int needle_len;
+ unsigned int len;
+ unsigned int i;
+
+ haystack_len = strlen(haystack);
+ needle_len = strlen(needle);
+
+ if (haystack_len < needle_len)
+ {
+ return NULL;
+ }
+
+ len = haystack_len - needle_len;
+
+ for (i = 0; i <= len; ++i)
+ {
+ if (!strncasecmp(haystack + i, needle, needle_len))
+ {
+ return haystack + i;
+ }
+ }
+
+ return NULL;
+}
+