- removed all Doom specific dependencies from cmdlib.cpp/h.
This meant moving CleanseString and ParseHex elsewhere and removing the I_Error call from ScanDirectory.
This commit is contained in:
parent
38fec546a7
commit
3cfda930ea
10 changed files with 100 additions and 106 deletions
|
|
@ -34,11 +34,7 @@
|
|||
#include <fts.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "doomtype.h"
|
||||
#include "cmdlib.h"
|
||||
#include "doomerrors.h"
|
||||
#include "v_text.h"
|
||||
#include "sc_man.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -299,40 +295,6 @@ FString ExtractFileBase (const char *path, bool include_extension)
|
|||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ParseHex
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int ParseHex (const char *hex, FScriptPosition *sc)
|
||||
{
|
||||
const char *str;
|
||||
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 {
|
||||
if (!sc) Printf ("Bad hex number: %s\n",hex);
|
||||
else sc->Message(MSG_WARNING, "Bad hex number: %s", hex);
|
||||
return 0;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// IsNum
|
||||
|
|
@ -408,7 +370,7 @@ bool CheckWildcards (const char *pattern, const char *text)
|
|||
|
||||
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid)
|
||||
{
|
||||
mysnprintf (buffer, buffsize, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
||||
snprintf (buffer, buffsize, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
||||
(uint32_t)guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1],
|
||||
guid.Data4[2], guid.Data4[3],
|
||||
|
|
@ -463,7 +425,7 @@ void DoCreatePath(const char *fn)
|
|||
return;
|
||||
}
|
||||
|
||||
char path[PATH_MAX];
|
||||
char path[_MAX_PATH];
|
||||
_makepath_s(path, sizeof path, drive, dir, nullptr, nullptr);
|
||||
|
||||
if ('\0' == *path)
|
||||
|
|
@ -746,36 +708,6 @@ FString strbin1 (const char *start)
|
|||
return result;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// CleanseString
|
||||
//
|
||||
// Does some mild sanity checking on a string: If it ends with an incomplete
|
||||
// color escape, the escape is removed.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
char *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';
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ExpandEnvVars
|
||||
|
|
@ -904,7 +836,7 @@ FString NicePath(const char *path)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
||||
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
||||
{
|
||||
struct _finddata_t fileinfo;
|
||||
intptr_t handle;
|
||||
|
|
@ -914,7 +846,7 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
|
||||
if ((handle = _findfirst(dirmatch, &fileinfo)) == -1)
|
||||
{
|
||||
I_Error("Could not scan '%s': %s\n", dirpath, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -954,6 +886,7 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
while (_findnext(handle, &fileinfo) == 0);
|
||||
_findclose(handle);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#elif defined(__sun) || defined(__linux__)
|
||||
|
|
@ -967,11 +900,11 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
||||
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
||||
{
|
||||
DIR *directory = opendir(dirpath);
|
||||
if(directory == NULL)
|
||||
return;
|
||||
return false;
|
||||
|
||||
struct dirent *file;
|
||||
while((file = readdir(directory)) != NULL)
|
||||
|
|
@ -993,6 +926,7 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
}
|
||||
|
||||
closedir(directory);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
@ -1004,7 +938,7 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
||||
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
||||
{
|
||||
char * const argv[] = {new char[strlen(dirpath)+1], NULL };
|
||||
memcpy(argv[0], dirpath, strlen(dirpath)+1);
|
||||
|
|
@ -1014,9 +948,8 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
fts = fts_open(argv, FTS_LOGICAL, NULL);
|
||||
if (fts == NULL)
|
||||
{
|
||||
I_Error("Failed to start directory traversal: %s\n", strerror(errno));
|
||||
delete[] argv[0];
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
while ((ent = fts_read(fts)) != NULL)
|
||||
{
|
||||
|
|
@ -1042,6 +975,7 @@ void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
|
|||
}
|
||||
fts_close(fts);
|
||||
delete[] argv[0];
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue