1
//------------------------------------------------------------------------
2
// HELPER : Unix/FLTK Little Helpers...
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
7
// Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
//------------------------------------------------------------------------
33
int HelperCaseCmp(const char *A, const char *B)
35
for (; *A && *B; A++, B++)
37
if (toupper(*A) != toupper(*B))
38
return (toupper(*A) - toupper(*B));
41
return (*A) ? 1 : (*B) ? -1 : 0;
48
// Like the above routine, but compares no more than 'len' characters
49
// at the start of each string.
51
int HelperCaseCmpLen(const char *A, const char *B, int len)
53
for (; *A && *B && (len > 0); A++, B++, len--)
55
if (toupper(*A) != toupper(*B))
56
return (toupper(*A) - toupper(*B));
62
return (*A) ? 1 : (*B) ? -1 : 0;
69
// Be sure to handle the result overflowing (it WILL happen !).
71
unsigned int HelperGetMillis()
74
unsigned long ticks = GetTickCount();
76
return (unsigned int) ticks;
80
gettimeofday(&tm, NULL);
82
return (unsigned int) ((tm.tv_sec * 1000) + (tm.tv_usec / 1000));
88
// HelperFilenameValid
90
boolean_g HelperFilenameValid(const char *filename)
95
int len = strlen(filename);
101
// check drive letter
102
if (len >= 2 && filename[1] == ':')
104
if (! isalpha(filename[0]))
112
switch (filename[len - 1])
129
boolean_g HelperHasExt(const char *filename)
131
int A = strlen(filename) - 1;
133
if (A > 0 && filename[A] == '.')
138
if (filename[A] == '.')
141
if (filename[A] == '/')
145
if (filename[A] == '\\' || filename[A] == ':')
156
boolean_g HelperCheckExt(const char *filename, const char *ext)
158
int A = strlen(filename) - 1;
159
int B = strlen(ext) - 1;
161
for (; B >= 0; B--, A--)
166
if (toupper(filename[A]) != toupper(ext[B]))
170
return (A >= 1) && (filename[A] == '.');
176
// Returns NULL if the filename was NULL, otherwise returns a pointer
177
// to a static buffer containing the new filename.
179
char *HelperReplaceExt(const char *filename, const char *ext)
182
static char buffer[512];
184
if (! filename || filename[0] == 0)
187
strcpy(buffer, filename);
189
int len = strlen(buffer);
191
if (HelperHasExt(filename))
193
dot_pos = strrchr(buffer, '.');
200
if (len > 0 && buffer[len-1] != '.')
211
// Computes an output filename given an input one. Returns NULL if
212
// the filename was NULL, otherwise returns a pointer to a static
213
// buffer containing the new filename.
215
char *HelperGuessOutput(const char *filename)
218
static char buffer[512];
220
if (! filename || filename[0] == 0)
223
strcpy(buffer, filename);
225
dot_pos = strrchr(buffer, '.');
230
dot_pos = buffer + strlen(buffer);
232
// check for existing modification ("_b" etc) and update it when
233
// found rather than getting level_b_b_b_b.wad :)
237
if (dot_pos > buffer && dot_pos[0] == '_' &&
238
('a' <= dot_pos[1] && dot_pos[1] <= 'z'))
240
if (dot_pos[1] == 'z')
247
strcat(buffer, "_b");
250
strcat(buffer, ".wad");
257
boolean_g HelperFileExists(const char *filename)
259
FILE *fp = fopen(filename, "rb");