Hi there. Not much to see here.
1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2006 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * ============================
19 * @brief Utility functons
24 * Returns a pointer to the extension in a file name
26 const char *UTIL_GetExtension(const char *file)
28 int len = strlen(file);
31 for (i=len-1; i>=0; i--)
33 if (file[i] == '/' || file[i] == '\\')
36 if ((file[i] == '.') && (i != len-1))
38 return (const char *)&(file[i+1]);
46 * Removes whitespace characters from left side of string
48 void UTIL_TrimLeft(char *buffer)
50 // Let's think of this as our iterator
53 // Make sure the buffer isn't null
56 // Add up number of whitespace characters
60 // If whitespace chars in buffer then adjust string so first non-whitespace char is at start of buffer
62 memmove(buffer, i, (strlen(i) + 1) * sizeof(char));
66 //:TODO: this should skip string literals
67 void UTIL_TrimComments(char *buffer)
70 size_t len = strlen(buffer);
73 for (int i=(int)len-1; i>=0; i--)
77 if (++num_sc >= 2 && i==0)
90 //size_t won't go below 0, manually break out
98 * Removes whitespace characters from right side of string
100 void UTIL_TrimRight(char *buffer)
102 // Make sure buffer isn't null
105 // Loop through buffer backwards while replacing whitespace chars with null chars
106 for (int i = (int)strlen(buffer) - 1; i >= 0; i--)
108 if (isspace(buffer[i]))
117 * Breaks a string at the first space until it reaches a nonspace
119 void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2)
122 size_t len = strlen(str);
124 for (start=0; start<len; start++)
126 if (!isspace(str[start]))
131 for (end=start; end<len; end++)
133 if (isspace(str[end]))
138 for (i=start; i<end; i++,c++)
146 for (start=end; start<len; start++)
148 if (!isspace(str[start]))
152 for (c=0; start<len; start++,c++)
156 buf2[c] = str[start];
161 bool UTIL_PathCmp(const char *path1, const char *path2)
163 size_t pos1 = 0, pos2 = 0;
167 if (path1[pos1] == '\0' || path2[pos2] == '\0')
169 return (path1[pos1] == path2[pos2]);
172 if (path1[pos1] == PATH_SEP_CHAR)
174 if (path2[pos2] != PATH_SEP_CHAR)
176 //look for extra path chars
177 while (path1[++pos1])
179 if (path1[pos1] != PATH_SEP_CHAR)
182 while (path2[++pos2])
184 if (path2[pos2] != PATH_SEP_CHAR)
190 //if we're at a different non-alphanumeric, the next character MUST Match
191 if (!isalpha(path1[pos1]) && (path1[pos1] != path2[pos2]))
195 if (toupper(path1[pos1]) != toupper(path2[pos2]))
197 if (path1[pos1] != path2[pos2])