2006-02-24 04:48:15 +00:00
|
|
|
// cmdlib.c (mostly borrowed from the Q2 source)
|
|
|
|
|
2006-10-09 15:55:47 +00:00
|
|
|
#ifdef _WIN32
|
2006-02-24 04:48:15 +00:00
|
|
|
#include <direct.h>
|
2010-08-27 15:20:05 +00:00
|
|
|
#include <io.h>
|
2009-02-08 02:52:43 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
2010-08-27 15:20:05 +00:00
|
|
|
#if !defined(__sun)
|
|
|
|
#include <fts.h>
|
|
|
|
#endif
|
2006-10-09 15:55:47 +00:00
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "doomtype.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "i_system.h"
|
2009-02-20 00:53:25 +00:00
|
|
|
#include "v_text.h"
|
|
|
|
|
2006-02-24 04:48:15 +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)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
FString progdir;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// IsSeperator
|
|
|
|
//
|
|
|
|
// Returns true if the character is a path seperator.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FixPathSeperator
|
|
|
|
//
|
|
|
|
// Convert backslashes to forward slashes.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
void FixPathSeperator (char *path)
|
|
|
|
{
|
|
|
|
while (*path)
|
|
|
|
{
|
|
|
|
if (*path == '\\')
|
|
|
|
*path = '/';
|
|
|
|
path++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// copystring
|
|
|
|
//
|
|
|
|
// Replacement for strdup that uses new instead of malloc.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +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;
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:20:51 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// ncopystring
|
|
|
|
//
|
|
|
|
// If the string has no content, returns NULL. Otherwise, returns a copy.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
char *ncopystring (const char *string)
|
|
|
|
{
|
|
|
|
if (string == NULL || string[0] == 0)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return copystring (string);
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ReplaceString
|
|
|
|
//
|
|
|
|
// Do not use in new code.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Q_filelength
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FileExists
|
|
|
|
//
|
|
|
|
// Returns true if the given path exists and is a readable file.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
bool FileExists (const char *filename)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-13 00:08:33 +00:00
|
|
|
struct stat buff;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// [RH] Empty filenames are never there
|
2009-09-02 03:47:48 +00:00
|
|
|
if (filename == NULL || *filename == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
|
2010-03-13 00:08:33 +00:00
|
|
|
return stat(filename, &buff) == 0 && !(buff.st_mode & S_IFDIR);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:47:48 +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.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DefaultExtension -- FString version
|
|
|
|
//
|
|
|
|
// Appends the extension to a pathname if it does not already have one.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-05-03 22:45:01 +00:00
|
|
|
void DefaultExtension (FString &path, const char *extension)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-16 02:50:18 +00:00
|
|
|
const char *src = &path[int(path.Len())-1];
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
while (src != &path[0] && !IsSeperator(*src))
|
|
|
|
{
|
|
|
|
if (*src == '.')
|
|
|
|
return; // it has an extension
|
|
|
|
src--;
|
|
|
|
}
|
|
|
|
|
|
|
|
path += extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ExtractFilePath
|
|
|
|
//
|
|
|
|
// Returns the directory part of a pathname.
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// FIXME: should include the slash, otherwise
|
|
|
|
// backing to an empty path will be wrong when appending a slash
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-07-08 02:17:35 +00:00
|
|
|
FString ExtractFilePath (const char *path)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
const char *src;
|
|
|
|
|
|
|
|
src = path + strlen(path) - 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// back up until a \ or the start
|
|
|
|
//
|
|
|
|
while (src != path && !IsSeperator(*(src-1)))
|
|
|
|
src--;
|
|
|
|
|
2006-07-08 02:17:35 +00:00
|
|
|
return FString(path, src - path);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ExtractFileBase
|
|
|
|
//
|
|
|
|
// Returns the file part of a pathname, optionally including the extension.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-07-08 02:17:35 +00:00
|
|
|
FString ExtractFileBase (const char *path, bool include_extension)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-08 02:17:35 +00:00
|
|
|
const char *src, *dot;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-07-08 02:17:35 +00:00
|
|
|
if (!include_extension)
|
|
|
|
{
|
|
|
|
dot = src;
|
|
|
|
while (*dot && *dot != '.')
|
|
|
|
{
|
|
|
|
dot++;
|
|
|
|
}
|
|
|
|
return FString(src, dot - src);
|
|
|
|
}
|
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-08 02:17:35 +00:00
|
|
|
return FString(src);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-08 02:17:35 +00:00
|
|
|
return FString();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ParseHex
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-08-16 08:11:39 +00:00
|
|
|
int ParseHex (const char *hex)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-16 08:11:39 +00:00
|
|
|
const char *str;
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ParseNum
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-08-16 08:11:39 +00:00
|
|
|
int ParseNum (const char *str)
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// IsNum
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// [RH] Returns true if the specified string is a valid decimal number
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-08-16 08:11:39 +00:00
|
|
|
bool IsNum (const char *str)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (((*str < '0') || (*str > '9')) && (*str != '-'))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CheckWildcards
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// [RH] Checks if text matches the wildcard pattern using ? or *
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FormatGUID
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// [RH] Print a GUID to a text buffer using the standard format.
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
About a week's worth of changes here. As a heads-up, I wouldn't be
surprised if this doesn't build in Linux right now. The CMakeLists.txt
were checked with MinGW and NMake, but how they fair under Linux is an
unknown to me at this time.
- 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.
- Added the gdtoa package from netlib's fp library so that ZDoom's printf-style
formatting can be entirely independant of the CRT.
SVN r1082 (trunk)
2008-07-23 04:57:26 +00:00
|
|
|
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
About a week's worth of changes here. As a heads-up, I wouldn't be
surprised if this doesn't build in Linux right now. The CMakeLists.txt
were checked with MinGW and NMake, but how they fair under Linux is an
unknown to me at this time.
- 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.
- Added the gdtoa package from netlib's fp library so that ZDoom's printf-style
formatting can be entirely independant of the CRT.
SVN r1082 (trunk)
2008-07-23 04:57:26 +00:00
|
|
|
mysnprintf (buffer, buffsize, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
2006-09-14 00:17:10 +00:00
|
|
|
(uint32)guid.Data1, guid.Data2, guid.Data3,
|
2006-02-24 04:48:15 +00:00
|
|
|
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 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// myasctime
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// [RH] Returns the current local time as ASCII, even if it's too early
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-12-29 03:38:37 +00:00
|
|
|
const char *myasctime ()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
2006-05-14 14:30:13 +00:00
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CreatePath
|
|
|
|
//
|
|
|
|
// Creates a directory including all levels necessary
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2009-02-08 02:52:43 +00:00
|
|
|
#ifdef _WIN32
|
2009-05-26 01:05:01 +00:00
|
|
|
void DoCreatePath(const char *fn)
|
2006-05-14 14:30:13 +00:00
|
|
|
{
|
2009-02-08 02:52:43 +00:00
|
|
|
char drive[_MAX_DRIVE];
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char p[PATH_MAX];
|
|
|
|
int i;
|
2006-05-14 14:30:13 +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);
|
2006-09-14 00:02:31 +00:00
|
|
|
_mkdir(p);
|
2006-05-14 14:30:13 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 01:05:01 +00:00
|
|
|
void CreatePath(const char *fn)
|
2006-05-14 14:30:13 +00:00
|
|
|
{
|
|
|
|
char c = fn[strlen(fn)-1];
|
|
|
|
|
2009-05-26 01:05:01 +00:00
|
|
|
if (c != '\\' && c != '/')
|
2006-05-14 14:30:13 +00:00
|
|
|
{
|
2009-05-26 01:05:01 +00:00
|
|
|
FString name(fn);
|
|
|
|
name += '/';
|
2006-05-14 14:30:13 +00:00
|
|
|
DoCreatePath(name);
|
|
|
|
}
|
2009-05-26 01:05:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DoCreatePath(fn);
|
|
|
|
}
|
2006-05-14 14:30:13 +00:00
|
|
|
}
|
2009-02-08 02:52:43 +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';
|
|
|
|
}
|
2009-09-09 17:12:47 +00:00
|
|
|
struct stat info;
|
|
|
|
if (stat(copy, &info) == 0)
|
|
|
|
{
|
|
|
|
if (info.st_mode & S_IFDIR)
|
|
|
|
goto exists;
|
|
|
|
}
|
2009-02-08 02:52:43 +00:00
|
|
|
if (mkdir(copy, 0755) == -1)
|
|
|
|
{ // failed
|
2013-05-12 18:37:31 +00:00
|
|
|
free(copy);
|
2009-02-08 02:52:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 17:12:47 +00:00
|
|
|
exists: if (p != NULL)
|
2009-02-08 02:52:43 +00:00
|
|
|
{
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
} while (p);
|
|
|
|
free(copy);
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-29 04:51:16 +00:00
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
2012-03-08 21:37:34 +00:00
|
|
|
// strbin -- In-place version
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
2006-11-29 04:51:16 +00:00
|
|
|
// [RH] Replaces the escape sequences in a string with actual escaped characters.
|
- Updated lempar.c to v1.31.
- Added .txt files to the list of types (wad, zip, and pk3) that can be
loaded without listing them after -file.
- Fonts that are created by the ACS setfont command to wrap a texture now
support animated textures.
- FON2 fonts can now use their full palette for CR_UNTRANSLATED when drawn
with the hardware 2D path instead of being restricted to the game palette.
- Fixed: Toggling vid_vsync would reset the displayed fullscreen gamma to 1
on a Radeon 9000.
- Added back the off-by-one palette handling, but in a much more limited
scope than before. The skipped entry is assumed to always be at 248, and
it is assumed that all Shader Model 1.4 cards suffer from this. That's
because all SM1.4 cards are based on variants of the ATI R200 core, and the
RV250 in a Radeon 9000 craps up like this. I see no reason to assume that
other flavors of the R200 are any different. (Interesting note: With the
Radeon 9000, D3DTADDRESS_CLAMP is an invalid address mode when using the
debug Direct3D 9 runtime, but it works perfectly fine with the retail
Direct3D 9 runtime.) (Insight: The R200 probably uses bytes for all its
math inside pixel shaders. That would explain perfectly why I can't use
constants greater than 1 with PS1.4 and why it can't do an exact mapping to
every entry in the color palette.
- Fixed: The software shaded drawer did not work for 2D, because its selected
"color"map was replaced with the identitymap before being used.
- Fixed: I cannot use Printf to output messages before the framebuffer was
completely setup, meaning that Shader Model 1.4 cards could not change
resolution.
- I have decided to let remap palettes specify variable alpha values for
their colors. D3DFB no longer forces them to 255.
- Updated re2c to version 0.12.3.
- Fixed: A_Wander used threshold as a timer, when it should have used
reactiontime.
- Fixed: A_CustomRailgun would not fire at all for actors without a target
when the aim parameter was disabled.
- Made the warp command work in multiplayer, again courtesy of Karate Chris.
- Fixed: Trying to spawn a bot while not in a game made for a crashing time.
(Patch courtesy of Karate Chris.)
- Removed some floating point math from hu_scores.cpp that somebody's GCC
gave warnings for (not mine, though).
- Fixed: The SBarInfo drawbar command crashed if the sprite image was
unavailable.
- Fixed: FString::operator=(const char *) did not release its old buffer when
being assigned to the null string.
- The scanner no longer has an upper limit on the length of strings it
accepts, though short strings will be faster than long ones.
- Moved all the text scanning functions into a class. Mainly, this means that
multiple script scanner states can be stored without being forced to do so
recursively. I think I might be taking advantage of that in the near
future. Possibly. Maybe.
- Removed some potential buffer overflows from the decal parser.
- Applied Blzut3's SBARINFO update #9:
* Fixed: When using even length values in drawnumber it would cap to a 98
value instead of a 99 as intended.
* The SBarInfo parser can now accept negatives for coordinates. This
doesn't allow much right now, but later I plan to add better fullscreen
hud support in which the negatives will be more useful. This also cleans
up the source a bit since all calls for (x, y) coordinates are with the
function getCoordinates().
- Added support for stencilling actors.
- Added support for non-black colors specified with DTA_ColorOverlay to the
software renderer.
- Fixed: The inverse, gold, red, and green fixed colormaps each allocated
space for 32 different colormaps, even though each only used the first one.
- Added two new blending flags to make reverse subtract blending more useful:
STYLEF_InvertSource and STYLEF_InvertOverlay. These invert the color that
gets blended with the background, since that seems like a good idea for
reverse subtraction. They also work with the other two blending operations.
- Added subtract and reverse subtract blending operations to the renderer.
Since the ERenderStyle enumeration was getting rather unwieldy, I converted
it into a new FRenderStyle structure that lets each parameter of the
blending equation be set separately. This simplified the set up for the
blend quite a bit, and it means a number of new combinations are available
by setting the parameters properly.
SVN r710 (trunk)
2008-01-25 23:57:44 +00:00
|
|
|
// This operation is done in-place. The result is the new length of the string.
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-11-29 04:51:16 +00:00
|
|
|
|
- Updated lempar.c to v1.31.
- Added .txt files to the list of types (wad, zip, and pk3) that can be
loaded without listing them after -file.
- Fonts that are created by the ACS setfont command to wrap a texture now
support animated textures.
- FON2 fonts can now use their full palette for CR_UNTRANSLATED when drawn
with the hardware 2D path instead of being restricted to the game palette.
- Fixed: Toggling vid_vsync would reset the displayed fullscreen gamma to 1
on a Radeon 9000.
- Added back the off-by-one palette handling, but in a much more limited
scope than before. The skipped entry is assumed to always be at 248, and
it is assumed that all Shader Model 1.4 cards suffer from this. That's
because all SM1.4 cards are based on variants of the ATI R200 core, and the
RV250 in a Radeon 9000 craps up like this. I see no reason to assume that
other flavors of the R200 are any different. (Interesting note: With the
Radeon 9000, D3DTADDRESS_CLAMP is an invalid address mode when using the
debug Direct3D 9 runtime, but it works perfectly fine with the retail
Direct3D 9 runtime.) (Insight: The R200 probably uses bytes for all its
math inside pixel shaders. That would explain perfectly why I can't use
constants greater than 1 with PS1.4 and why it can't do an exact mapping to
every entry in the color palette.
- Fixed: The software shaded drawer did not work for 2D, because its selected
"color"map was replaced with the identitymap before being used.
- Fixed: I cannot use Printf to output messages before the framebuffer was
completely setup, meaning that Shader Model 1.4 cards could not change
resolution.
- I have decided to let remap palettes specify variable alpha values for
their colors. D3DFB no longer forces them to 255.
- Updated re2c to version 0.12.3.
- Fixed: A_Wander used threshold as a timer, when it should have used
reactiontime.
- Fixed: A_CustomRailgun would not fire at all for actors without a target
when the aim parameter was disabled.
- Made the warp command work in multiplayer, again courtesy of Karate Chris.
- Fixed: Trying to spawn a bot while not in a game made for a crashing time.
(Patch courtesy of Karate Chris.)
- Removed some floating point math from hu_scores.cpp that somebody's GCC
gave warnings for (not mine, though).
- Fixed: The SBarInfo drawbar command crashed if the sprite image was
unavailable.
- Fixed: FString::operator=(const char *) did not release its old buffer when
being assigned to the null string.
- The scanner no longer has an upper limit on the length of strings it
accepts, though short strings will be faster than long ones.
- Moved all the text scanning functions into a class. Mainly, this means that
multiple script scanner states can be stored without being forced to do so
recursively. I think I might be taking advantage of that in the near
future. Possibly. Maybe.
- Removed some potential buffer overflows from the decal parser.
- Applied Blzut3's SBARINFO update #9:
* Fixed: When using even length values in drawnumber it would cap to a 98
value instead of a 99 as intended.
* The SBarInfo parser can now accept negatives for coordinates. This
doesn't allow much right now, but later I plan to add better fullscreen
hud support in which the negatives will be more useful. This also cleans
up the source a bit since all calls for (x, y) coordinates are with the
function getCoordinates().
- Added support for stencilling actors.
- Added support for non-black colors specified with DTA_ColorOverlay to the
software renderer.
- Fixed: The inverse, gold, red, and green fixed colormaps each allocated
space for 32 different colormaps, even though each only used the first one.
- Added two new blending flags to make reverse subtract blending more useful:
STYLEF_InvertSource and STYLEF_InvertOverlay. These invert the color that
gets blended with the background, since that seems like a good idea for
reverse subtraction. They also work with the other two blending operations.
- Added subtract and reverse subtract blending operations to the renderer.
Since the ERenderStyle enumeration was getting rather unwieldy, I converted
it into a new FRenderStyle structure that lets each parameter of the
blending equation be set separately. This simplified the set up for the
blend quite a bit, and it means a number of new combinations are available
by setting the parameters properly.
SVN r710 (trunk)
2008-01-25 23:57:44 +00:00
|
|
|
int strbin (char *str)
|
2006-11-29 04:51:16 +00:00
|
|
|
{
|
2008-01-26 04:47:58 +00:00
|
|
|
char *start = str;
|
2006-11-29 04:51:16 +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;
|
2012-05-06 03:16:11 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
p++;
|
2006-11-29 04:51:16 +00:00
|
|
|
if (*p >= '0' && *p <= '9')
|
2012-05-06 03:16:11 +00:00
|
|
|
c = (c << 4) + *p-'0';
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (*p >= 'a' && *p <= 'f')
|
2012-05-06 03:16:11 +00:00
|
|
|
c = (c << 4) + 10 + *p-'a';
|
2006-11-29 04:51:16 +00:00
|
|
|
else if (*p >= 'A' && *p <= 'F')
|
2012-05-06 03:16:11 +00:00
|
|
|
c = (c << 4) + 10 + *p-'A';
|
2006-11-29 04:51:16 +00:00
|
|
|
else
|
2012-05-06 03:16:11 +00:00
|
|
|
{
|
|
|
|
p--;
|
2006-11-29 04:51:16 +00:00
|
|
|
break;
|
2012-05-06 03:16:11 +00:00
|
|
|
}
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
|
|
|
*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;
|
2009-05-15 10:39:40 +00:00
|
|
|
return int(str - start);
|
2006-11-29 04:51:16 +00:00
|
|
|
}
|
2008-12-07 00:50:04 +00:00
|
|
|
|
2009-09-02 03:47:48 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// strbin1 -- String-creating version
|
|
|
|
//
|
2008-12-07 17:50:03 +00:00
|
|
|
// [RH] Replaces the escape sequences in a string with actual escaped characters.
|
2012-03-08 21:37:34 +00:00
|
|
|
// The result is a new string.
|
2009-09-02 03:47:48 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-12-07 17:50:03 +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;
|
2012-05-06 03:16:11 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
p++;
|
2008-12-07 17:50:03 +00:00
|
|
|
if (*p >= '0' && *p <= '9')
|
2012-05-06 03:16:11 +00:00
|
|
|
c = (c << 4) + *p-'0';
|
2008-12-07 17:50:03 +00:00
|
|
|
else if (*p >= 'a' && *p <= 'f')
|
2012-05-06 03:16:11 +00:00
|
|
|
c = (c << 4) + 10 + *p-'a';
|
2008-12-07 17:50:03 +00:00
|
|
|
else if (*p >= 'A' && *p <= 'F')
|
2012-05-06 03:16:11 +00:00
|
|
|
c = (c << 4) + 10 + *p-'A';
|
2008-12-07 17:50:03 +00:00
|
|
|
else
|
2012-05-06 03:16:11 +00:00
|
|
|
{
|
|
|
|
p--;
|
2008-12-07 17:50:03 +00:00
|
|
|
break;
|
2012-05-06 03:16:11 +00:00
|
|
|
}
|
2008-12-07 17:50:03 +00:00
|
|
|
}
|
|
|
|
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-20 00:53:25 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CleanseString
|
|
|
|
//
|
|
|
|
// Does some mild sanity checking on a string: If it ends with an incomplete
|
|
|
|
// color escape, the escape is removed.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
char *CleanseString(char *str)
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
return str;
|
2009-02-20 00:53:25 +00:00
|
|
|
}
|
|
|
|
|
2008-12-07 00:50:04 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ExpandEnvVars
|
|
|
|
//
|
|
|
|
// Expands environment variable references in a string. Intended primarily
|
|
|
|
// for use with IWAD search paths in config files.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FString ExpandEnvVars(const char *searchpathstring)
|
|
|
|
{
|
|
|
|
static const char envvarnamechars[] =
|
|
|
|
"01234567890"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"_"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*nextchars != 0)
|
|
|
|
{
|
|
|
|
out += nextchars;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2008-12-07 17:50:03 +00:00
|
|
|
|
2009-02-08 02:52:43 +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
|
|
|
|
}
|
2010-08-27 15:20:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ScanDirectory
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|
|
|
{
|
|
|
|
struct _finddata_t fileinfo;
|
|
|
|
intptr_t handle;
|
|
|
|
FString dirmatch;
|
|
|
|
|
|
|
|
dirmatch << dirpath << "*";
|
|
|
|
|
|
|
|
if ((handle = _findfirst(dirmatch, &fileinfo)) == -1)
|
|
|
|
{
|
|
|
|
I_Error("Could not scan '%s': %s\n", dirpath, strerror(errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (fileinfo.attrib & _A_HIDDEN)
|
|
|
|
{
|
|
|
|
// Skip hidden files and directories. (Prevents SVN bookkeeping
|
|
|
|
// info from being included.)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileinfo.attrib & _A_SUBDIR)
|
|
|
|
{
|
|
|
|
if (fileinfo.name[0] == '.' &&
|
|
|
|
(fileinfo.name[1] == '\0' ||
|
|
|
|
(fileinfo.name[1] == '.' && fileinfo.name[2] == '\0')))
|
|
|
|
{
|
|
|
|
// Do not record . and .. directories.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FFileList *fl = &list[list.Reserve(1)];
|
|
|
|
fl->Filename << dirpath << fileinfo.name;
|
|
|
|
fl->isDirectory = true;
|
|
|
|
FString newdir = fl->Filename;
|
|
|
|
newdir << "/";
|
|
|
|
ScanDirectory(list, newdir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FFileList *fl = &list[list.Reserve(1)];
|
|
|
|
fl->Filename << dirpath << fileinfo.name;
|
|
|
|
fl->isDirectory = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (_findnext(handle, &fileinfo) == 0);
|
|
|
|
_findclose(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__sun) || defined(linux)
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ScanDirectory
|
|
|
|
// Solaris version
|
|
|
|
//
|
|
|
|
// Given NULL-terminated array of directory paths, create trees for them.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|
|
|
{
|
|
|
|
DIR *directory = opendir(dirpath);
|
|
|
|
if(directory == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct dirent *file;
|
|
|
|
while((file = readdir(directory)) != NULL)
|
|
|
|
{
|
|
|
|
if(file->d_name[0] == '.') //File is hidden or ./.. directory so ignore it.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
FFileList *fl = &list[list.Reserve(1)];
|
|
|
|
fl->Filename << dirpath << file->d_name;
|
|
|
|
|
|
|
|
struct stat fileStat;
|
|
|
|
stat(fl->Filename, &fileStat);
|
|
|
|
fl->isDirectory = S_ISDIR(fileStat.st_mode);
|
|
|
|
|
|
|
|
if(fl->isDirectory)
|
|
|
|
{
|
|
|
|
FString newdir = fl->Filename;
|
|
|
|
newdir += "/";
|
|
|
|
ScanDirectory(list, newdir);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ScanDirectory
|
|
|
|
// 4.4BSD version
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|
|
|
{
|
2010-09-18 20:13:56 +00:00
|
|
|
char * const argv[] = {new char[strlen(dirpath)+1], NULL };
|
|
|
|
memcpy(argv[0], dirpath, strlen(dirpath)+1);
|
2010-08-27 15:20:05 +00:00
|
|
|
FTS *fts;
|
|
|
|
FTSENT *ent;
|
|
|
|
|
|
|
|
fts = fts_open(argv, FTS_LOGICAL, NULL);
|
|
|
|
if (fts == NULL)
|
|
|
|
{
|
|
|
|
I_Error("Failed to start directory traversal: %s\n", strerror(errno));
|
2010-09-18 20:13:56 +00:00
|
|
|
delete[] argv[0];
|
2010-08-27 15:20:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while ((ent = fts_read(fts)) != NULL)
|
|
|
|
{
|
|
|
|
if (ent->fts_info == FTS_D && ent->fts_name[0] == '.')
|
|
|
|
{
|
|
|
|
// Skip hidden directories. (Prevents SVN bookkeeping
|
|
|
|
// info from being included.)
|
|
|
|
fts_set(fts, ent, FTS_SKIP);
|
|
|
|
}
|
|
|
|
if (ent->fts_info == FTS_D && ent->fts_level == 0)
|
|
|
|
{
|
|
|
|
FFileList *fl = &list[list.Reserve(1)];
|
|
|
|
fl->Filename = ent->fts_path;
|
|
|
|
fl->isDirectory = true;
|
|
|
|
}
|
|
|
|
if (ent->fts_info == FTS_F)
|
|
|
|
{
|
|
|
|
// We're only interested in remembering files.
|
|
|
|
FFileList *fl = &list[list.Reserve(1)];
|
|
|
|
fl->Filename = ent->fts_path;
|
|
|
|
fl->isDirectory = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fts_close(fts);
|
2010-09-18 20:13:56 +00:00
|
|
|
delete[] argv[0];
|
2010-08-27 15:20:05 +00:00
|
|
|
}
|
|
|
|
#endif
|