2008-01-27 11:25:03 +00:00
|
|
|
// cmdlib.c (mostly borrowed from the Q2 source)
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
2009-02-08 23:01:13 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
2008-01-27 11:25:03 +00:00
|
|
|
#endif
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "i_system.h"
|
2009-02-21 17:07:32 +00:00
|
|
|
#include "v_text.h"
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
progdir will hold the path up to the game directory, including the slash
|
|
|
|
|
|
|
|
f:\quake\
|
|
|
|
/raid/quake/
|
|
|
|
|
|
|
|
gamedir will hold progdir + the game directory (id1, id2, etc)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
Update to ZDoom r905:
- Added Martin Howe's morph system update.
- Added support for defining composite textures in HIRESTEX. It is not fully tested
and right now can't do much more than the old TEXTUREx method.
- Added a few NULL pointer checks to the texture code.
- Made duplicate class names in DECORATE non-fatal. There is really no stability
concern here and the worst that can happen is that the wrong actor is spawned.
This was a constant hassle when testing with WADs that contain duplicate resources.
- Removed some GCC warnings.
- Fixed: MinGW doesn't have _get_pgmptr(), so it couldn't compile i_main.cpp.
- Fixed: MOD_WAVETABLE and MOD_SWSYNTH are not defined by w32api, so MinGW
failed compiling the new MIDI code.
- Fixed: LocalSndInfo and LocalSndSeq in S_Start() need to be const char
pointers, since "" is a constant.
- Fixed: parsecontext.h was missing a newline at the end of the file.
- Fixed: Timidity::Channel::mono, rpn, and nrpn were not initialized. In
particular, this meant that every channel was almost certainly in mono mode,
which can sound pretty bad if the song isn't meant to be played that way.
- Added bank numbers to the MIDI precaching for Timidity, since I guess I do
need to care about banks, if even the Duke MIDIs use various banks.
- Fixed: snd_midiprecache only exists in Win32 builds, so gameconfigfile.cpp
shouldn't unconditionally link against it.
- Fixed: pre_resample() was still disabled, and it left two samples at the end
of the new wave data uninitialized.
- Moved the xmap table from timidity/tables.cpp to playmidi.cpp. Now I can get
rid of timidity/tables.cpp, which conflicts in name with the main Doom
tables.cpp. (And interestingly, VC++ automatically renamed the object file,
so I wasn't aware of the problem with GCC.)
- Added a Gets function to the FileReader class which I planned to use
to enable Timidity to read its config and sound patches from Zips.
I put this on hold though after finding out that the sound quality
isn't even near that of Timidity++.
- GCC-Fixes (FString::GetChars() for Printf calls)
- Added a dummy Weapon.NOLMS flag so that Skulltag weapons using this flag
can be loaded
- Changed the MIDIStreamer to send the all notes off controller to each
channel when restarting the song, rather than emitting a single note off
event which only has 1 in 127 chance of being for a note that's playing
on that channel. Then I decided it would probably be a good idea to reset
all the controllers as well.
- Increasing the size of the internal Timidity stream buffer from 1/14 sec
(copied from the OPL player) improved its sound dramatically, so apparently
Timidity has issues with short stream buffers. It's now at 1/2 sec in
length. However, there seems to be something weird going on with
corazonazul_ff6boss.mid near the beginning where it stops and immediately
restarts a guitar on the exact same note.
- Added a new sound debugging cvar: snd_drawoutput, which can show various
oscilloscopes and spectrums.
- Eliminated some more global variables (onmobj, DoRipping, LastRipped,
MissileActor, bulletpitch and linetarget.)
- Internal TiMidity now plays music. Unfortunately, it doesn't sound right. :(
- Changed the progdir global variable into an FString.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@90 b0f79afe-0144-0410-b225-9a4edf0717df
2008-04-12 18:59:23 +00:00
|
|
|
FString progdir;
|
2008-01-27 11:25:03 +00:00
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// IsSeperator
|
|
|
|
//
|
|
|
|
// Returns true if the character is a path seperator.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
static inline bool IsSeperator (int c)
|
|
|
|
{
|
|
|
|
if (c == '/')
|
|
|
|
return true;
|
|
|
|
#ifdef WIN32
|
|
|
|
if (c == '\\' || c == ':')
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FixPathSeperator
|
|
|
|
//
|
|
|
|
// Convert backslashes to forward slashes.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
void FixPathSeperator (char *path)
|
|
|
|
{
|
|
|
|
while (*path)
|
|
|
|
{
|
|
|
|
if (*path == '\\')
|
|
|
|
*path = '/';
|
|
|
|
path++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// copystring
|
|
|
|
//
|
|
|
|
// Replacement for strdup that uses new instead of malloc.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
char *copystring (const char *s)
|
|
|
|
{
|
|
|
|
char *b;
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
size_t len = strlen (s) + 1;
|
|
|
|
b = new char[len];
|
|
|
|
memcpy (b, s, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b = new char[1];
|
|
|
|
b[0] = '\0';
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ReplaceString
|
|
|
|
//
|
|
|
|
// Do not use in new code.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-01-27 11:25:03 +00:00
|
|
|
|
|
|
|
void ReplaceString (char **ptr, const char *str)
|
|
|
|
{
|
|
|
|
if (*ptr)
|
|
|
|
{
|
|
|
|
if (*ptr == str)
|
|
|
|
return;
|
|
|
|
delete[] *ptr;
|
|
|
|
}
|
|
|
|
*ptr = copystring (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
MISC FUNCTIONS
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Q_filelength
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
int Q_filelength (FILE *f)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
int end;
|
|
|
|
|
|
|
|
pos = ftell (f);
|
|
|
|
fseek (f, 0, SEEK_END);
|
|
|
|
end = ftell (f);
|
|
|
|
fseek (f, pos, SEEK_SET);
|
|
|
|
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FileExists
|
|
|
|
//
|
|
|
|
// Returns true if the given path exists and is a readable file.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
bool FileExists (const char *filename)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
// [RH] Empty filenames are never there
|
2009-09-02 06:19:49 +00:00
|
|
|
if (filename == NULL || *filename == 0)
|
2008-01-27 11:25:03 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
f = fopen (filename, "r");
|
|
|
|
if (!f)
|
|
|
|
return false;
|
|
|
|
fclose (f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DirEntryExists
|
|
|
|
//
|
|
|
|
// Returns true if the given path exists, be it a directory or a file.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool DirEntryExists(const char *pathname)
|
|
|
|
{
|
|
|
|
if (pathname == NULL || *pathname == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
struct stat info;
|
|
|
|
return stat(pathname, &info) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DefaultExtension -- char array version
|
|
|
|
//
|
|
|
|
// Appends the extension to a pathname if it does not already have one.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
void DefaultExtension (char *path, const char *extension)
|
|
|
|
{
|
|
|
|
char *src;
|
|
|
|
//
|
|
|
|
// if path doesn't have a .EXT, append extension
|
|
|
|
// (extension should include the .)
|
|
|
|
//
|
|
|
|
src = path + strlen(path) - 1;
|
|
|
|
|
|
|
|
while (src != path && !IsSeperator(*src))
|
|
|
|
{
|
|
|
|
if (*src == '.')
|
|
|
|
return; // it has an extension
|
|
|
|
src--;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat (path, extension);
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DefaultExtension -- FString version
|
|
|
|
//
|
|
|
|
// Appends the extension to a pathname if it does not already have one.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
void DefaultExtension (FString &path, const char *extension)
|
|
|
|
{
|
|
|
|
const char *src = &path[int(path.Len())-1];
|
|
|
|
|
|
|
|
while (src != &path[0] && !IsSeperator(*src))
|
|
|
|
{
|
|
|
|
if (*src == '.')
|
|
|
|
return; // it has an extension
|
|
|
|
src--;
|
|
|
|
}
|
|
|
|
|
|
|
|
path += extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ExtractFilePath
|
|
|
|
//
|
|
|
|
// Returns the directory part of a pathname.
|
|
|
|
//
|
2008-01-27 11:25:03 +00:00
|
|
|
// FIXME: should include the slash, otherwise
|
|
|
|
// backing to an empty path will be wrong when appending a slash
|
2009-09-02 06:19:49 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
FString ExtractFilePath (const char *path)
|
|
|
|
{
|
|
|
|
const char *src;
|
|
|
|
|
|
|
|
src = path + strlen(path) - 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// back up until a \ or the start
|
|
|
|
//
|
|
|
|
while (src != path && !IsSeperator(*(src-1)))
|
|
|
|
src--;
|
|
|
|
|
|
|
|
return FString(path, src - path);
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ExtractFileBase
|
|
|
|
//
|
|
|
|
// Returns the file part of a pathname, optionally including the extension.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
FString ExtractFileBase (const char *path, bool include_extension)
|
|
|
|
{
|
|
|
|
const char *src, *dot;
|
|
|
|
|
|
|
|
src = path + strlen(path) - 1;
|
|
|
|
|
|
|
|
if (src >= path)
|
|
|
|
{
|
|
|
|
// back up until a / or the start
|
|
|
|
while (src != path && !IsSeperator(*(src-1)))
|
|
|
|
src--;
|
|
|
|
|
|
|
|
// Check for files with drive specification but no path
|
|
|
|
#if defined(_WIN32) || defined(DOS)
|
|
|
|
if (src == path && src[0] != 0)
|
|
|
|
{
|
|
|
|
if (src[1] == ':')
|
|
|
|
src += 2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!include_extension)
|
|
|
|
{
|
|
|
|
dot = src;
|
|
|
|
while (*dot && *dot != '.')
|
|
|
|
{
|
|
|
|
dot++;
|
|
|
|
}
|
|
|
|
return FString(src, dot - src);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FString(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ParseHex
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-08-22 07:36:50 +00:00
|
|
|
int ParseHex (const char *hex)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
2008-08-22 07:36:50 +00:00
|
|
|
const char *str;
|
2008-01-27 11:25:03 +00:00
|
|
|
int num;
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
str = hex;
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
num <<= 4;
|
|
|
|
if (*str >= '0' && *str <= '9')
|
|
|
|
num += *str-'0';
|
|
|
|
else if (*str >= 'a' && *str <= 'f')
|
|
|
|
num += 10 + *str-'a';
|
|
|
|
else if (*str >= 'A' && *str <= 'F')
|
|
|
|
num += 10 + *str-'A';
|
|
|
|
else {
|
|
|
|
Printf ("Bad hex number: %s\n",hex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ParseNum
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-01-27 11:25:03 +00:00
|
|
|
|
2008-08-22 07:36:50 +00:00
|
|
|
int ParseNum (const char *str)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
|
|
|
if (str[0] == '$')
|
|
|
|
return ParseHex (str+1);
|
|
|
|
if (str[0] == '0' && str[1] == 'x')
|
|
|
|
return ParseHex (str+2);
|
|
|
|
return atol (str);
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// IsNum
|
|
|
|
//
|
2008-01-27 11:25:03 +00:00
|
|
|
// [RH] Returns true if the specified string is a valid decimal number
|
2009-09-02 06:19:49 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-01-27 11:25:03 +00:00
|
|
|
|
2008-08-22 07:36:50 +00:00
|
|
|
bool IsNum (const char *str)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (((*str < '0') || (*str > '9')) && (*str != '-'))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CheckWildcards
|
|
|
|
//
|
2008-01-27 11:25:03 +00:00
|
|
|
// [RH] Checks if text matches the wildcard pattern using ? or *
|
2009-09-02 06:19:49 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-01-27 11:25:03 +00:00
|
|
|
|
|
|
|
bool CheckWildcards (const char *pattern, const char *text)
|
|
|
|
{
|
|
|
|
if (pattern == NULL || text == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
while (*pattern)
|
|
|
|
{
|
|
|
|
if (*pattern == '*')
|
|
|
|
{
|
|
|
|
char stop = tolower (*++pattern);
|
|
|
|
while (*text && tolower(*text) != stop)
|
|
|
|
{
|
|
|
|
text++;
|
|
|
|
}
|
|
|
|
if (*text && tolower(*text) == stop)
|
|
|
|
{
|
|
|
|
if (CheckWildcards (pattern, text++))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
pattern--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*pattern == '?' || tolower(*pattern) == tolower(*text))
|
|
|
|
{
|
|
|
|
pattern++;
|
|
|
|
text++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (*pattern | *text) == 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FormatGUID
|
|
|
|
//
|
2008-01-27 11:25:03 +00:00
|
|
|
// [RH] Print a GUID to a text buffer using the standard format.
|
2009-09-02 06:19:49 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-01-27 11:25:03 +00:00
|
|
|
|
Update to ZDoom r1083. Not fully tested yet!
- Converted most sprintf (and all wsprintf) calls to either mysnprintf or
FStrings, depending on the situation.
- Changed the strings in the wbstartstruct to be FStrings.
- Changed myvsnprintf() to output nothing if count is greater than INT_MAX.
This is so that I can use a series of mysnprintf() calls and advance the
pointer for each one. Once the pointer goes beyond the end of the buffer,
the count will go negative, but since it's an unsigned type it will be
seen as excessively huge instead. This should not be a problem, as there's
no reason for ZDoom to be using text buffers larger than 2 GB anywhere.
- Ripped out the disabled bit from FGameConfigFile::MigrateOldConfig().
- Changed CalcMapName() to return an FString instead of a pointer to a static
buffer.
- Changed startmap in d_main.cpp into an FString.
- Changed CheckWarpTransMap() to take an FString& as the first argument.
- Changed d_mapname in g_level.cpp into an FString.
- Changed DoSubstitution() in ct_chat.cpp to place the substitutions in an
FString.
- Fixed: The MAPINFO parser wrote into the string buffer to construct a map
name when given a Hexen map number. This was fine with the old scanner
code, but only a happy coincidence prevents it from crashing with the new
code.
- Added the 'B' conversion specifier to StringFormat::VWorker() for printing
binary numbers.
- Added CMake support for building with MinGW, MSYS, and NMake. Linux support
is probably broken until I get around to booting into Linux again. Niceties
provided over the existing Makefiles they're replacing:
* All command-line builds can use the same build system, rather than having
a separate one for MinGW and another for Linux.
* Microsoft's NMake tool is supported as a target.
* Progress meters.
* Parallel makes work from a fresh checkout without needing to be primed
first with a single-threaded make.
* Porting to other architectures should be simplified, whenever that day
comes.
- Replaced the makewad tool with zipdir. This handles the dependency tracking
itself instead of generating an external makefile to do it, since I couldn't
figure out how to generate a makefile with an external tool and include it
with a CMake-generated makefile. Where makewad used a master list of files
to generate the package file, zipdir just zips the entire contents of one or
more directories.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@138 b0f79afe-0144-0410-b225-9a4edf0717df
2008-07-23 18:35:55 +00:00
|
|
|
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
Update to ZDoom r1083. Not fully tested yet!
- Converted most sprintf (and all wsprintf) calls to either mysnprintf or
FStrings, depending on the situation.
- Changed the strings in the wbstartstruct to be FStrings.
- Changed myvsnprintf() to output nothing if count is greater than INT_MAX.
This is so that I can use a series of mysnprintf() calls and advance the
pointer for each one. Once the pointer goes beyond the end of the buffer,
the count will go negative, but since it's an unsigned type it will be
seen as excessively huge instead. This should not be a problem, as there's
no reason for ZDoom to be using text buffers larger than 2 GB anywhere.
- Ripped out the disabled bit from FGameConfigFile::MigrateOldConfig().
- Changed CalcMapName() to return an FString instead of a pointer to a static
buffer.
- Changed startmap in d_main.cpp into an FString.
- Changed CheckWarpTransMap() to take an FString& as the first argument.
- Changed d_mapname in g_level.cpp into an FString.
- Changed DoSubstitution() in ct_chat.cpp to place the substitutions in an
FString.
- Fixed: The MAPINFO parser wrote into the string buffer to construct a map
name when given a Hexen map number. This was fine with the old scanner
code, but only a happy coincidence prevents it from crashing with the new
code.
- Added the 'B' conversion specifier to StringFormat::VWorker() for printing
binary numbers.
- Added CMake support for building with MinGW, MSYS, and NMake. Linux support
is probably broken until I get around to booting into Linux again. Niceties
provided over the existing Makefiles they're replacing:
* All command-line builds can use the same build system, rather than having
a separate one for MinGW and another for Linux.
* Microsoft's NMake tool is supported as a target.
* Progress meters.
* Parallel makes work from a fresh checkout without needing to be primed
first with a single-threaded make.
* Porting to other architectures should be simplified, whenever that day
comes.
- Replaced the makewad tool with zipdir. This handles the dependency tracking
itself instead of generating an external makefile to do it, since I couldn't
figure out how to generate a makefile with an external tool and include it
with a CMake-generated makefile. Where makewad used a master list of files
to generate the package file, zipdir just zips the entire contents of one or
more directories.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@138 b0f79afe-0144-0410-b225-9a4edf0717df
2008-07-23 18:35:55 +00:00
|
|
|
mysnprintf (buffer, buffsize, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
2008-01-27 11:25:03 +00:00
|
|
|
(uint32)guid.Data1, guid.Data2, guid.Data3,
|
|
|
|
guid.Data4[0], guid.Data4[1],
|
|
|
|
guid.Data4[2], guid.Data4[3],
|
|
|
|
guid.Data4[4], guid.Data4[5],
|
|
|
|
guid.Data4[6], guid.Data4[7]);
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// myasctime
|
|
|
|
//
|
2008-01-27 11:25:03 +00:00
|
|
|
// [RH] Returns the current local time as ASCII, even if it's too early
|
2009-09-02 06:19:49 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-01-27 11:25:03 +00:00
|
|
|
const char *myasctime ()
|
|
|
|
{
|
|
|
|
time_t clock;
|
|
|
|
struct tm *lt;
|
|
|
|
|
|
|
|
time (&clock);
|
|
|
|
lt = localtime (&clock);
|
|
|
|
if (lt != NULL)
|
|
|
|
{
|
|
|
|
return asctime (lt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "Pre Jan 01 00:00:00 1970\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CreatePath
|
|
|
|
//
|
|
|
|
// Creates a directory including all levels necessary
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2009-02-08 23:01:13 +00:00
|
|
|
#ifdef _WIN32
|
Update to ZDoom r1616:
- Removed HaveFocus variable in preference of using GetForegroundWindow().
- Added Raw Input keyboard handling.
- Split DirectInput keyboard handling into a separate file and class. I also
switched it to buffered input, and the pause key seems to be properly
cooked, so I don't need to look for it with WM_KEYDOWN/UP. Tab doesn't
need to be special-cased either, because buffered input never passes on
the Tab key when you press Alt+Tab. I have no idea why I special-cased
Num Lock, but it seems to be working fine. By setting the exclusive mode
to background, I can also avoid special code for releasing all keys when
the window loses focus, because I'll still receive those events while the
window is in the background.
- Fixed: The Heretic "take weapons" cheat did not remove all the weapons at
once. This is because destroying one weapon has a potential to destroy a
sister weapon as well. If the sister weapon is the next one in line (as it
typically is), it would process that one, not realizing it was no longer
part of the inventory, and stop because its Inventory link was NULL.
- Recoverable errors that are caught during the demo loop no longer shut off
the menu.
- Specifying non-existent directories with -savedir or the save_dir cvar now
attempts to create them.
- I_CheckNativeMouse() now checks the foreground window to determine if the
mouse should be grabbed. This fixes the case where you start the game in
the background and it grabs the mouse anyway.
- Changed raw mouse grabbing to call ShowCursor() directly instead of through
SetCursorState(), since changing the pointer isn't working with it
(probably due to the lack of legacy mouse messages), and the others work
fine by setting an invisible cursor.
- Fixed: Raw mouse input passes wheel movements in an unsigned field, but the
value is signed, so it requires a cast to use it.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@333 b0f79afe-0144-0410-b225-9a4edf0717df
2009-05-27 22:16:34 +00:00
|
|
|
void DoCreatePath(const char *fn)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
2009-02-08 23:01:13 +00:00
|
|
|
char drive[_MAX_DRIVE];
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char p[PATH_MAX];
|
|
|
|
int i;
|
2008-01-27 11:25:03 +00:00
|
|
|
|
|
|
|
_splitpath(fn,drive,path,NULL,NULL);
|
|
|
|
_makepath(p,drive,path,NULL,NULL);
|
|
|
|
i=(int)strlen(p);
|
|
|
|
if (p[i-1]=='/' || p[i-1]=='\\') p[i-1]=0;
|
|
|
|
if (*path) DoCreatePath(p);
|
|
|
|
_mkdir(p);
|
|
|
|
}
|
|
|
|
|
Update to ZDoom r1616:
- Removed HaveFocus variable in preference of using GetForegroundWindow().
- Added Raw Input keyboard handling.
- Split DirectInput keyboard handling into a separate file and class. I also
switched it to buffered input, and the pause key seems to be properly
cooked, so I don't need to look for it with WM_KEYDOWN/UP. Tab doesn't
need to be special-cased either, because buffered input never passes on
the Tab key when you press Alt+Tab. I have no idea why I special-cased
Num Lock, but it seems to be working fine. By setting the exclusive mode
to background, I can also avoid special code for releasing all keys when
the window loses focus, because I'll still receive those events while the
window is in the background.
- Fixed: The Heretic "take weapons" cheat did not remove all the weapons at
once. This is because destroying one weapon has a potential to destroy a
sister weapon as well. If the sister weapon is the next one in line (as it
typically is), it would process that one, not realizing it was no longer
part of the inventory, and stop because its Inventory link was NULL.
- Recoverable errors that are caught during the demo loop no longer shut off
the menu.
- Specifying non-existent directories with -savedir or the save_dir cvar now
attempts to create them.
- I_CheckNativeMouse() now checks the foreground window to determine if the
mouse should be grabbed. This fixes the case where you start the game in
the background and it grabs the mouse anyway.
- Changed raw mouse grabbing to call ShowCursor() directly instead of through
SetCursorState(), since changing the pointer isn't working with it
(probably due to the lack of legacy mouse messages), and the others work
fine by setting an invisible cursor.
- Fixed: Raw mouse input passes wheel movements in an unsigned field, but the
value is signed, so it requires a cast to use it.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@333 b0f79afe-0144-0410-b225-9a4edf0717df
2009-05-27 22:16:34 +00:00
|
|
|
void CreatePath(const char *fn)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
|
|
|
char c = fn[strlen(fn)-1];
|
|
|
|
|
Update to ZDoom r1616:
- Removed HaveFocus variable in preference of using GetForegroundWindow().
- Added Raw Input keyboard handling.
- Split DirectInput keyboard handling into a separate file and class. I also
switched it to buffered input, and the pause key seems to be properly
cooked, so I don't need to look for it with WM_KEYDOWN/UP. Tab doesn't
need to be special-cased either, because buffered input never passes on
the Tab key when you press Alt+Tab. I have no idea why I special-cased
Num Lock, but it seems to be working fine. By setting the exclusive mode
to background, I can also avoid special code for releasing all keys when
the window loses focus, because I'll still receive those events while the
window is in the background.
- Fixed: The Heretic "take weapons" cheat did not remove all the weapons at
once. This is because destroying one weapon has a potential to destroy a
sister weapon as well. If the sister weapon is the next one in line (as it
typically is), it would process that one, not realizing it was no longer
part of the inventory, and stop because its Inventory link was NULL.
- Recoverable errors that are caught during the demo loop no longer shut off
the menu.
- Specifying non-existent directories with -savedir or the save_dir cvar now
attempts to create them.
- I_CheckNativeMouse() now checks the foreground window to determine if the
mouse should be grabbed. This fixes the case where you start the game in
the background and it grabs the mouse anyway.
- Changed raw mouse grabbing to call ShowCursor() directly instead of through
SetCursorState(), since changing the pointer isn't working with it
(probably due to the lack of legacy mouse messages), and the others work
fine by setting an invisible cursor.
- Fixed: Raw mouse input passes wheel movements in an unsigned field, but the
value is signed, so it requires a cast to use it.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@333 b0f79afe-0144-0410-b225-9a4edf0717df
2009-05-27 22:16:34 +00:00
|
|
|
if (c != '\\' && c != '/')
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
Update to ZDoom r1616:
- Removed HaveFocus variable in preference of using GetForegroundWindow().
- Added Raw Input keyboard handling.
- Split DirectInput keyboard handling into a separate file and class. I also
switched it to buffered input, and the pause key seems to be properly
cooked, so I don't need to look for it with WM_KEYDOWN/UP. Tab doesn't
need to be special-cased either, because buffered input never passes on
the Tab key when you press Alt+Tab. I have no idea why I special-cased
Num Lock, but it seems to be working fine. By setting the exclusive mode
to background, I can also avoid special code for releasing all keys when
the window loses focus, because I'll still receive those events while the
window is in the background.
- Fixed: The Heretic "take weapons" cheat did not remove all the weapons at
once. This is because destroying one weapon has a potential to destroy a
sister weapon as well. If the sister weapon is the next one in line (as it
typically is), it would process that one, not realizing it was no longer
part of the inventory, and stop because its Inventory link was NULL.
- Recoverable errors that are caught during the demo loop no longer shut off
the menu.
- Specifying non-existent directories with -savedir or the save_dir cvar now
attempts to create them.
- I_CheckNativeMouse() now checks the foreground window to determine if the
mouse should be grabbed. This fixes the case where you start the game in
the background and it grabs the mouse anyway.
- Changed raw mouse grabbing to call ShowCursor() directly instead of through
SetCursorState(), since changing the pointer isn't working with it
(probably due to the lack of legacy mouse messages), and the others work
fine by setting an invisible cursor.
- Fixed: Raw mouse input passes wheel movements in an unsigned field, but the
value is signed, so it requires a cast to use it.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@333 b0f79afe-0144-0410-b225-9a4edf0717df
2009-05-27 22:16:34 +00:00
|
|
|
FString name(fn);
|
|
|
|
name += '/';
|
2008-01-27 11:25:03 +00:00
|
|
|
DoCreatePath(name);
|
|
|
|
}
|
Update to ZDoom r1616:
- Removed HaveFocus variable in preference of using GetForegroundWindow().
- Added Raw Input keyboard handling.
- Split DirectInput keyboard handling into a separate file and class. I also
switched it to buffered input, and the pause key seems to be properly
cooked, so I don't need to look for it with WM_KEYDOWN/UP. Tab doesn't
need to be special-cased either, because buffered input never passes on
the Tab key when you press Alt+Tab. I have no idea why I special-cased
Num Lock, but it seems to be working fine. By setting the exclusive mode
to background, I can also avoid special code for releasing all keys when
the window loses focus, because I'll still receive those events while the
window is in the background.
- Fixed: The Heretic "take weapons" cheat did not remove all the weapons at
once. This is because destroying one weapon has a potential to destroy a
sister weapon as well. If the sister weapon is the next one in line (as it
typically is), it would process that one, not realizing it was no longer
part of the inventory, and stop because its Inventory link was NULL.
- Recoverable errors that are caught during the demo loop no longer shut off
the menu.
- Specifying non-existent directories with -savedir or the save_dir cvar now
attempts to create them.
- I_CheckNativeMouse() now checks the foreground window to determine if the
mouse should be grabbed. This fixes the case where you start the game in
the background and it grabs the mouse anyway.
- Changed raw mouse grabbing to call ShowCursor() directly instead of through
SetCursorState(), since changing the pointer isn't working with it
(probably due to the lack of legacy mouse messages), and the others work
fine by setting an invisible cursor.
- Fixed: Raw mouse input passes wheel movements in an unsigned field, but the
value is signed, so it requires a cast to use it.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@333 b0f79afe-0144-0410-b225-9a4edf0717df
2009-05-27 22:16:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DoCreatePath(fn);
|
|
|
|
}
|
2008-01-27 11:25:03 +00:00
|
|
|
}
|
2009-02-08 23:01:13 +00:00
|
|
|
#else
|
|
|
|
void CreatePath(const char *fn)
|
|
|
|
{
|
|
|
|
char *copy, *p;
|
|
|
|
|
|
|
|
if (fn[0] == '/' && fn[1] == '\0')
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p = copy = strdup(fn);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
p = strchr(p + 1, '/');
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
printf("%s\n", copy);
|
|
|
|
if (mkdir(copy, 0755) == -1)
|
|
|
|
{ // failed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
} while (p);
|
|
|
|
free(copy);
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-27 11:25:03 +00:00
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// strbin1 -- In-place version
|
|
|
|
//
|
2008-01-27 11:25:03 +00:00
|
|
|
// [RH] Replaces the escape sequences in a string with actual escaped characters.
|
2008-01-27 15:34:47 +00:00
|
|
|
// This operation is done in-place. The result is the new length of the string.
|
2009-09-02 06:19:49 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-01-27 11:25:03 +00:00
|
|
|
|
2008-01-27 15:34:47 +00:00
|
|
|
int strbin (char *str)
|
2008-01-27 11:25:03 +00:00
|
|
|
{
|
2008-01-27 15:34:47 +00:00
|
|
|
char *start = str;
|
2008-01-27 11:25:03 +00:00
|
|
|
char *p = str, c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while ( (c = *p++) ) {
|
|
|
|
if (c != '\\') {
|
|
|
|
*str++ = c;
|
|
|
|
} else {
|
|
|
|
switch (*p) {
|
|
|
|
case 'a':
|
|
|
|
*str++ = '\a';
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
*str++ = '\b';
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
*str++ = '\034'; // TEXTCOLOR_ESCAPE
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
*str++ = '\f';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
*str++ = '\n';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
*str++ = '\t';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
*str++ = '\r';
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
*str++ = '\v';
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
*str++ = '\?';
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
c = 0;
|
|
|
|
p++;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
c <<= 4;
|
|
|
|
if (*p >= '0' && *p <= '9')
|
|
|
|
c += *p-'0';
|
|
|
|
else if (*p >= 'a' && *p <= 'f')
|
|
|
|
c += 10 + *p-'a';
|
|
|
|
else if (*p >= 'A' && *p <= 'F')
|
|
|
|
c += 10 + *p-'A';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*str++ = c;
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
c = 0;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
c <<= 3;
|
|
|
|
if (*p >= '0' && *p <= '7')
|
|
|
|
c += *p-'0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*str++ = c;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*str++ = *p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*str = 0;
|
Update to ZDoom r1585:
- Added ACS GetChar function.
- Added Gez's submission for polyobjects being able to crush corpses but made
it an explicit MAPINFO option only.
- Changed APlayerPawn::DamageFade to a PalEntry from 3 floats.
- Removed #pragma warnings from cmdlib.h and fixed the places where they were
still triggered.
These #pragmas were responsible for >90% of the GCC warnings that were not
listed in VC++.
- Fixed one bug in the process: DSeqNode::m_Atten was never adjusted when the
parameter handling of the sound functions for attenuation was changed.
Changed m_Atten to a float and fixed the SNDSEQ parser to set proper values.
Also added the option to specify attenuation with direct values in addition
to the predefined names.
- fixed a few Heretic actors:
* The pod generator's attacksound was wrong
* The teleglitter generators need different flags if they are supposed to work
with z-aware spawning of the glitter.
* The knight's axes need the THRUGHOST flag.
- Fixed non-POD passing in G_BuildSaveName() and other things GCC warned
about.
- Added support for imploded zips.
- Fixed: Some missile spawning functions ignored the FastSpeed setting.
- Fixed: P_CheckSwitchRange tried to access a line's backsector without
checking if it is valid.
- Fixed: Fast projectile could not be frozen by the Time freezer.
- Added several new ACS functions: GetActorMomX/Y/Z, GetActorViewHeight,
SetActivator, SetActivatorToTarget.
- Added Species property for actors and separated Hexen's Demon1 and Demon2
into different species.
- Added handling for UDMF user keys.
- Added support for ACS functions that can be defined without recompiling ACC.
- Fixed: The short lump name for embedded files must be cleared so that they
are not found by a normal lump search.
- Added AProp_Notarget actor property.
- Fixed: TraceBleed was missing a NULL pointer check,
- Fixed: P_RandomChaseDir could crash for friendly monsters that belong to
a player which left the game.
- Changed A_PodGrow so that it plays the generator's attack sound instead of
"misc/podgrow".
- Added transference of a select few flags from PowerProtection to its owner.
- Added actor type parameters to A_PodPain() and A_MakePod().
- The savegame path is now passed through NicePath(), since it's user-
specifiable.
- Added save_dir cvar. When non-empty, it controls where savegames go.
- SBARINFO update:
* Added the ability to center things with fullscreenoffsets enabled. Due
to some limitations the syntax is [-]<integer> [+ center].
* Fixed: the translucent flag on drawinventorybar didn't work quite right.
* Fixed: Extremely minor inaccuracy in the Doom SBarInfo code. The
fullscreen inventory bar wasn't scaled correctly.
- fixed: The CHECKSWITCHRANGE line flag was ignored for one sided lines.
- Added more compatibility settings, submitted by Gez.
- Fixed: Doom's fullscreen HUD was limited to 6 keys.
- Made 'next endgame' work again for cases where it is supposed to be
the same as 'next endgame4'.
- GCC nitpick fix: Classes being used as template parameters may not be
defined locally in a function. Fixed FWadFile::SetNamespace for that.
- Improved error reporting for incorrect textures in maps.
- Fixed: When music was stopped this was not set in the global music state.
- Fixed: Friendly monsters did not target enemy players in deathmatch.
- Fixed: Completely empty patches (8 0-bytes) could not be handled by the
texture manager. They now get assigned a new FEmptyTexture object
that is just a 1x1 pixel transparent texture.
- Fixed: Multiple namespace markers of the same type were no longer detected.
- Fixed sprite renaming.
- Maps defined with Hexen-style MAPINFOs now run their scripts in the proper
order.
- Fixed: FWadCollection::CheckNumForName() read the lump each iteration before
checking for the end marker. On 32-bit systems, this is -1, but on 64-bit
systems, it is a very large integer that is highly unlikely to be in mapped
memory.
git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@325 b0f79afe-0144-0410-b225-9a4edf0717df
2009-05-15 18:02:01 +00:00
|
|
|
return int(str - start);
|
2008-01-27 11:25:03 +00:00
|
|
|
}
|
2008-11-10 23:32:39 +00:00
|
|
|
|
2009-09-02 06:19:49 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// strbin1 -- String-creating version
|
|
|
|
//
|
2008-12-07 17:48:36 +00:00
|
|
|
// [RH] Replaces the escape sequences in a string with actual escaped characters.
|
2009-09-02 06:19:49 +00:00
|
|
|
// This operation is done in-place.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-12-07 17:48:36 +00:00
|
|
|
|
|
|
|
FString strbin1 (const char *start)
|
|
|
|
{
|
|
|
|
FString result;
|
|
|
|
const char *p = start;
|
|
|
|
char c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while ( (c = *p++) ) {
|
|
|
|
if (c != '\\') {
|
|
|
|
result << c;
|
|
|
|
} else {
|
|
|
|
switch (*p) {
|
|
|
|
case 'a':
|
|
|
|
result << '\a';
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
result << '\b';
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
result << '\034'; // TEXTCOLOR_ESCAPE
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
result << '\f';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
result << '\n';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
result << '\t';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
result << '\r';
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
result << '\v';
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
result << '\?';
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
c = 0;
|
|
|
|
p++;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
c <<= 4;
|
|
|
|
if (*p >= '0' && *p <= '9')
|
|
|
|
c += *p-'0';
|
|
|
|
else if (*p >= 'a' && *p <= 'f')
|
|
|
|
c += 10 + *p-'a';
|
|
|
|
else if (*p >= 'A' && *p <= 'F')
|
|
|
|
c += 10 + *p-'A';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
result << c;
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
c = 0;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
c <<= 3;
|
|
|
|
if (*p >= '0' && *p <= '7')
|
|
|
|
c += *p-'0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
result << c;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result << *p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-21 17:07:32 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CleanseString
|
|
|
|
//
|
|
|
|
// Does some mild sanity checking on a string: If it ends with an incomplete
|
|
|
|
// color escape, the escape is removed.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void CleanseString(char *str)
|
|
|
|
{
|
|
|
|
char *escape = strrchr(str, TEXTCOLOR_ESCAPE);
|
|
|
|
if (escape != NULL)
|
|
|
|
{
|
|
|
|
if (escape[1] == '\0')
|
|
|
|
{
|
|
|
|
*escape = '\0';
|
|
|
|
}
|
|
|
|
else if (escape[1] == '[')
|
|
|
|
{
|
|
|
|
char *close = strchr(escape + 2, ']');
|
|
|
|
if (close == NULL)
|
|
|
|
{
|
|
|
|
*escape = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-07 16:38:02 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ExpandEnvVars
|
|
|
|
//
|
|
|
|
// Expands environment variable references in a string. Intended primarily
|
|
|
|
// for use with IWAD search paths in config files.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-11-10 23:32:39 +00:00
|
|
|
|
2008-12-07 16:38:02 +00:00
|
|
|
FString ExpandEnvVars(const char *searchpathstring)
|
2008-11-10 23:32:39 +00:00
|
|
|
{
|
2008-12-07 16:38:02 +00:00
|
|
|
static const char envvarnamechars[] =
|
|
|
|
"01234567890"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"_"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz";
|
2008-11-10 23:32:39 +00:00
|
|
|
|
2008-12-07 16:38:02 +00:00
|
|
|
if (searchpathstring == NULL)
|
|
|
|
return FString("");
|
|
|
|
|
|
|
|
const char *dollar = strchr(searchpathstring, '$');
|
|
|
|
if (dollar == NULL)
|
|
|
|
{
|
|
|
|
return FString(searchpathstring);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nextchars = searchpathstring;
|
|
|
|
FString out = FString(searchpathstring, dollar - searchpathstring);
|
|
|
|
while ( (dollar != NULL) && (*nextchars != 0) )
|
|
|
|
{
|
|
|
|
size_t length = strspn(dollar + 1, envvarnamechars);
|
|
|
|
if (length != 0)
|
|
|
|
{
|
|
|
|
FString varname = FString(dollar + 1, length);
|
|
|
|
if (stricmp(varname, "progdir") == 0)
|
|
|
|
{
|
|
|
|
out += progdir;
|
2008-11-10 23:32:39 +00:00
|
|
|
}
|
2008-12-07 16:38:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *varvalue = getenv(varname);
|
|
|
|
if ( (varvalue != NULL) && (strlen(varvalue) != 0) )
|
|
|
|
{
|
|
|
|
out += varvalue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out += '$';
|
|
|
|
}
|
|
|
|
nextchars = dollar + length + 1;
|
|
|
|
dollar = strchr(nextchars, '$');
|
|
|
|
if (dollar != NULL)
|
|
|
|
{
|
|
|
|
out += FString(nextchars, dollar - nextchars);
|
2008-11-10 23:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-07 16:38:02 +00:00
|
|
|
if (*nextchars != 0)
|
|
|
|
{
|
|
|
|
out += nextchars;
|
|
|
|
}
|
|
|
|
return out;
|
2008-11-10 23:32:39 +00:00
|
|
|
}
|
2008-12-07 17:48:36 +00:00
|
|
|
|
2009-02-08 23:01:13 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// NicePath
|
|
|
|
//
|
|
|
|
// Handles paths with leading ~ characters on Unix as well as environment
|
|
|
|
// variable substitution. On Windows, this is identical to ExpandEnvVars.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FString NicePath(const char *path)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return ExpandEnvVars(path);
|
|
|
|
#else
|
|
|
|
if (path == NULL || *path == '\0')
|
|
|
|
{
|
|
|
|
return FString("");
|
|
|
|
}
|
|
|
|
if (*path != '~')
|
|
|
|
{
|
|
|
|
return ExpandEnvVars(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
passwd *pwstruct;
|
|
|
|
const char *slash;
|
|
|
|
|
|
|
|
if (path[1] == '/' || path[1] == '\0')
|
|
|
|
{ // Get my home directory
|
|
|
|
pwstruct = getpwuid(getuid());
|
|
|
|
slash = path + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Get somebody else's home directory
|
|
|
|
slash = strchr(path, '/');
|
|
|
|
if (slash == NULL)
|
|
|
|
{
|
|
|
|
slash = path + strlen(path);
|
|
|
|
}
|
|
|
|
FString who(path, slash - path);
|
|
|
|
pwstruct = getpwnam(who);
|
|
|
|
}
|
|
|
|
if (pwstruct == NULL)
|
|
|
|
{
|
|
|
|
return ExpandEnvVars(path);
|
|
|
|
}
|
|
|
|
FString where(pwstruct->pw_dir);
|
|
|
|
if (*slash != '\0')
|
|
|
|
{
|
|
|
|
where += ExpandEnvVars(slash);
|
|
|
|
}
|
|
|
|
return where;
|
|
|
|
#endif
|
|
|
|
}
|