- match cmdlib.cpp/.h with GZDoom.

This commit is contained in:
Christoph Oelckers 2020-04-11 23:39:40 +02:00
parent e2f5e8fe34
commit 6ef93ba514
32 changed files with 227 additions and 175 deletions

View file

@ -28,6 +28,7 @@ static_assert('\xff' == 255, "Char must be unsigned!");
#include "textures.h"
#include "c_cvars.h"
#include "cmdlib.h"
typedef int64_t coord_t;

View file

@ -984,11 +984,8 @@ static inline void append_ext_UNSAFE(char *outbuf, const char *ext)
////////// Paths //////////
int32_t Bcorrectfilename(char *filename, int32_t removefn);
////////// String manipulation //////////
char *Bstrtoken(char *s, const char *delim, char **ptrptr, int chop);
char *Bstrtolower(char *str);

View file

@ -52,105 +52,9 @@ void set_memerr_handler(void(*handlerfunc)(int32_t, const char *, const char *))
}
int32_t Bcorrectfilename(char *filename, int32_t removefn)
{
char *fn = Xstrdup(filename);
char *tokarr[64], *first, *next = NULL;
for (first=fn; *first; first++)
{
#ifdef _WIN32
if (*first == '\\') *first = '/';
#endif
}
int leadslash = (*fn == '/');
int trailslash = (first>fn && first[-1] == '/');
int ntok = 0;
first = fn;
do
{
char *token = Bstrtoken(first, "/", &next, 1);
first = NULL;
if (!token) break;
else if (token[0] == 0) continue;
else if (token[0] == '.' && token[1] == 0) continue;
else if (token[0] == '.' && token[1] == '.' && token[2] == 0) ntok = max(0,ntok-1);
else tokarr[ntok++] = token;
}
while (1);
if (!trailslash && removefn) { ntok = max(0,ntok-1); trailslash = 1; }
if (ntok == 0 && trailslash && leadslash) trailslash = 0;
first = filename;
if (leadslash) *(first++) = '/';
for (int i=0; i<ntok; i++)
{
if (i>0) *(first++) = '/';
for (char *token=tokarr[i]; *token; token++)
*(first++) = *token;
}
if (trailslash) *(first++) = '/';
*(first++) = 0;
Xfree(fn);
return 0;
}
char *Bstrtoken(char *s, const char *delim, char **ptrptr, int chop)
{
if (!ptrptr)
return NULL;
char *p = s ? s : *ptrptr;
if (!p)
return NULL;
while (*p != 0 && Bstrchr(delim, *p)) p++;
if (*p == 0)
{
*ptrptr = NULL;
return NULL;
}
char * const start = p;
while (*p != 0 && !Bstrchr(delim, *p)) p++;
if (*p == 0)
*ptrptr = NULL;
else
{
if (chop)
*(p++) = 0;
*ptrptr = p;
}
return start;
}
char *Bstrtolower(char *str)
{
if (!str)
return NULL;
int len = strlen(str);
if (len <= 0)
return str;
int i = 0;
do
{
*(str + i) = tolower(*(str + i));
i++;
} while (--len);
if (str) for (int i = 0; str[i]; i++) str[i] = tolower(str[i]);
return str;
}

View file

@ -35,6 +35,7 @@
#include <stdint.h>
//#include "doomtype.h"
#include "cmdlib.h"
#include "keydef.h"
#include "c_commandline.h"
#include "c_bind.h"

View file

@ -38,6 +38,7 @@
#include "zstring.h"
#include "c_bind.h"
#include "gamecontrol.h"
#include "cmdlib.h"
//=============================================================================
//

View file

@ -39,6 +39,7 @@
#include "name.h"
#include "m_swap.h"
#include "gamecontrol.h"
#include "cmdlib.h"
//==========================================================================
//

View file

@ -75,8 +75,6 @@ MapRecord userMapRecord; // stand-in for the user map.
FStartupInfo RazeStartupInfo;
FMemArena dump; // this is for memory blocks than cannot be deallocated without some huge effort. Put them in here so that they do not register on shutdown.
FString progdir;
void C_CON_SetAliases();
InputState inputState;
void SetClipshapes();

View file

@ -37,6 +37,7 @@
#include "m_joy.h"
#include "gameconfigfile.h"
#include "d_event.h"
#include "cmdlib.h"
// MACROS ------------------------------------------------------------------

View file

@ -35,6 +35,7 @@
#include "v_draw.h"
#include "gstrings.h"
#include "v_font.h"
#include "cmdlib.h"
void M_DrawConText (int color, int x, int y, const char *str);

View file

@ -36,6 +36,7 @@
#include "v_video.h"
#include "templates.h"
#include "r_videoscale.h"
#include "cmdlib.h"
#include "console/c_console.h"
#include "menu/menu.h"

View file

@ -581,7 +581,6 @@ TArray<GrpInfo> ParseAllGrpInfos(TArray<FileEntry>& filelist)
{
TArray<GrpInfo> groups;
TMap<FString, uint32_t> CRCMap;
extern FString progdir;
// This opens the base resource only for reading the grpinfo from it which we need before setting up the game state.
std::unique_ptr<FResourceFile> engine_res;
FString baseres = progdir + ENGINERES_FILE;

View file

@ -35,6 +35,7 @@
#include "s_soundinternal.h"
#include "sc_man.h"
#include "templates.h"
#include "cmdlib.h"
FReverbField ReverbFields[] =

View file

@ -19,11 +19,6 @@
#define GCCNOWARN
#endif
template <typename T, size_t N>
char(&_ArraySizeHelper(T(&array)[N]))[N];
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
using INTBOOL = int;
#endif

View file

@ -34,27 +34,24 @@
*/
#ifdef _WIN32
#include <direct.h>
#include <io.h>
#else
#include <dirent.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#if !defined(__sun)
#include <fts.h>
#endif
#endif
#include "cmdlib.h"
#include "compat.h"
#include "i_system.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
/*
progdir will hold the path up to the game directory, including the slash
extern FString progdir;
f:\quake\
/raid/quake/
gamedir will hold progdir + the game directory (id1, id2, etc)
*/
FString progdir;
//==========================================================================
//
@ -75,7 +72,78 @@ static inline bool IsSeperator (int c)
return false;
}
//==========================================================================
//==========================================================================
//
// FixPathSeperator
//
// Convert backslashes to forward slashes.
//
//==========================================================================
void FixPathSeperator (char *path)
{
while (*path)
{
if (*path == '\\')
*path = '/';
path++;
}
}
//==========================================================================
//
// copystring
//
// Replacement for strdup that uses new instead of malloc.
//
//==========================================================================
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;
}
//==========================================================================
//
// ReplaceString
//
// Do not use in new code.
//
//==========================================================================
void ReplaceString (char **ptr, const char *str)
{
if (*ptr)
{
if (*ptr == str)
return;
delete[] *ptr;
}
*ptr = copystring (str);
}
/*
=============================================================================
MISC FUNCTIONS
=============================================================================
*/
//==========================================================================
//
// FileExists
//
@ -821,6 +889,68 @@ FString NicePath(const char *path)
}
//==========================================================================
//
// ScanDirectory
//
//==========================================================================
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath)
{
findstate_t find;
FString dirmatch;
dirmatch << dirpath << "*";
auto handle = I_FindFirst(dirmatch.GetChars(), &find);
if (handle == ((void*)(-1)))
{
return false;
}
else
{
do
{
auto attr = I_FindAttr(&find);
if (attr & FA_HIDDEN)
{
// Skip hidden files and directories. (Prevents SVN bookkeeping
// info from being included.)
continue;
}
auto fn = I_FindName(&find);
if (attr & FA_DIREC)
{
if (fn[0] == '.' &&
(fn[1] == '\0' ||
(fn[1] == '.' && fn[2] == '\0')))
{
// Do not record . and .. directories.
continue;
}
FFileList* fl = &list[list.Reserve(1)];
fl->Filename << dirpath << fn;
fl->isDirectory = true;
FString newdir = fl->Filename;
newdir << "/";
ScanDirectory(list, newdir);
}
else
{
FFileList* fl = &list[list.Reserve(1)];
fl->Filename << dirpath << fn;
fl->isDirectory = false;
}
}
while (I_FindNext(handle, &find) == 0);
I_FindClose(handle);
}
return true;
}
//==========================================================================
//
//
@ -843,10 +973,62 @@ bool IsAbsPath(const char *name)
//
//==========================================================================
void NormalizeFileName(FString &str)
void NormalizeFileName(FString& str)
{
auto strp = str.LockBuffer();
Bcorrectfilename(strp, false);
str.UnlockBuffer();
FixPathSeperator(str);
auto splits = str.Split("/");
for (unsigned i = 1; i < splits.Size(); i++)
{
if (splits[i].Compare(".") == 0)
{
splits.Delete(i);
i--;
}
if (splits[i].Compare("..") == 0 && splits[i - 1].Compare("..") != 0)
{
splits.Delete(i);
splits.Delete(i - 1);
i -= 2;
if (i < 1) i = 1;
}
}
str = splits[0];
for (unsigned i = 1; i < splits.Size(); i++)
{
str << "/" << splits[i];
}
}
//==========================================================================
//
//
//
//==========================================================================
FString M_ZLibError(int zerr)
{
if (zerr >= 0)
{
return "OK";
}
else if (zerr < -6)
{
FString out;
out.Format("%d", zerr);
return out;
}
else
{
static const char* errs[6] =
{
"Errno",
"Stream Error",
"Data Error",
"Memory Error",
"Buffer Error",
"Version Error"
};
return errs[-zerr - 1];
}
}

View file

@ -10,6 +10,7 @@
#include <errno.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include "zstring.h"
#if !defined(GUID_DEFINED)
@ -38,6 +39,7 @@ bool GetFileInfo(const char* pathname, size_t* size, time_t* time);
extern FString progdir;
void FixPathSeperator (char *path);
static void inline FixPathSeperator (FString &path) { path.ReplaceChars('\\', '/'); }
void DefaultExtension (FString &path, const char *extension);
@ -50,6 +52,9 @@ FString StripExtension(const char* path);
struct FScriptPosition;
bool IsNum (const char *str); // [RH] added
char *copystring(const char *s);
void ReplaceString (char **ptr, const char *str);
bool CheckWildcards (const char *pattern, const char *text);
void FormatGUID (char *buffer, size_t buffsize, const GUID &guid);
@ -70,7 +75,9 @@ struct FFileList
bool isDirectory;
};
bool ScanDirectory(TArray<FFileList> &list, const char *dirpath);
bool IsAbsPath(const char*);
FString M_ZLibError(int zerrnum);
inline int32_t Scale(int32_t a, int32_t b, int32_t c)
{

View file

@ -43,6 +43,7 @@
#include "files.h"
#include "templates.h"
#include "zstring.h"
#include "cmdlib.h"
//==========================================================================
//
@ -89,36 +90,6 @@ void DecompressorBase::SetOwnsReader()
File = &OwnedFile;
}
//
// M_ZlibError
//
FString M_ZLibError(int zerr)
{
if (zerr >= 0)
{
return "OK";
}
else if (zerr < -6)
{
FString out;
out.Format("%d", zerr);
return out;
}
else
{
static const char* errs[6] =
{
"Errno",
"Stream Error",
"Data Error",
"Memory Error",
"Buffer Error",
"Version Error"
};
return errs[-zerr - 1];
}
}
//==========================================================================
//
// DecompressorZ

View file

@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "network.h"
#include "menu/menu.h"
#include "palette.h"
#include "cmdlib.h"
BEGIN_DUKE_NS

View file

@ -5214,8 +5214,6 @@ repeatcase:
}
tempbuf[i+1] = '\0';
Bcorrectfilename(tempbuf,0);
mapList[j * MAXLEVELS + k].SetFileName(tempbuf);
C_SkipComments();

View file

@ -2003,7 +2003,6 @@ static void Net_ReceiveUserMapName(uint8_t *pbuf, int32_t packbufleng)
Bstrcpy(boardfilename, (char *)pbuf + 1);
boardfilename[packbufleng - 1] = 0;
Bcorrectfilename(boardfilename, 0);
if (boardfilename[0] != 0)
{
if (fileSystem.FileExists(boardfilename))
@ -4854,8 +4853,6 @@ void Net_SendUserMapName(void)
packbuf[0] = PACKET_USER_MAP;
Bcorrectfilename(boardfilename, 0);
// user map name is sent with a NUL at the end
int32_t j = Bstrlen(boardfilename) + 1;

View file

@ -1731,8 +1731,6 @@ int G_EnterLevel(int gameMode)
if (Menu_HaveUserMap())
{
Bcorrectfilename(boardfilename, 0);
int levelNum = G_FindLevelByFile(boardfilename);
if (levelNum != -1)

View file

@ -63,6 +63,7 @@
#include "basics.h"
#include "zstring.h"
#include "printf.h"
#include "cmdlib.h"
#include <time.h>
#include <zlib.h>

View file

@ -86,6 +86,7 @@
#include "menu.h"
#include "c_buttons.h"
#include "gamecontrol.h"
#include "cmdlib.h"
// Compensate for w32api's lack
#ifndef GET_XBUTTON_WPARAM

View file

@ -42,6 +42,7 @@
#include "gameconfigfile.h"
#include "m_argv.h"
#include "keydef.h"
#include "cmdlib.h"
// MACROS ------------------------------------------------------------------

View file

@ -45,7 +45,6 @@
#include "version.h" // for GAMENAME
// Stuff that needs to be set up later.
extern FString progdir;
static bool batchrun;
// Vanilla MinGW does not have folder ids

View file

@ -79,6 +79,7 @@
#include "v_font.h"
#include "i_system.h"
#include "textures/bitmap.h"
#include "cmdlib.h"
extern bool batchrun;
// MACROS ------------------------------------------------------------------

View file

@ -437,9 +437,7 @@ void FXInputController::SetDefaultConfig()
FString FXInputController::GetIdentifier()
{
char id[16];
snprintf(id, countof(id), "XI:%d", Index);
return id;
return FStringf("XI:%d", Index);
}
//==========================================================================

View file

@ -47,6 +47,7 @@
#include "m_argv.h"
#include "s_music.h"
#include "printf.h"
#include "cmdlib.h"
// MACROS ------------------------------------------------------------------

View file

@ -48,6 +48,7 @@
#include "m_argv.h"
#include "printf.h"
#include "win32basevideo.h"
#include "cmdlib.h"
#include "gl/system/gl_framebuffer.h"

View file

@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "net.h"
#include "mmulti.h"
#include "palette.h"
#include "cmdlib.h"
BEGIN_RR_NS

View file

@ -2293,8 +2293,6 @@ ifvar:
}
tempbuf[i+1] = '\0';
Bcorrectfilename(tempbuf,0);
mapList[j *MAXLEVELS+k].SetFileName(tempbuf);
C_SkipComments();

View file

@ -3158,8 +3158,6 @@ void Net_SendUserMapName(void)
packbuf[0] = PACKET_USER_MAP;
Bcorrectfilename(boardfilename,0);
// user map name is sent with a NUL at the end
j = Bstrlen(boardfilename)+1;
Bmemcpy(&packbuf[1], boardfilename, j);
@ -3181,7 +3179,6 @@ void Net_ReceiveUserMapName(uint8_t *pbuf, int32_t packbufleng)
{
Bstrcpy(boardfilename,(char *)pbuf+1);
boardfilename[packbufleng-1] = 0;
Bcorrectfilename(boardfilename,0);
if (boardfilename[0] != 0)
{
if (fileSystem.FileExists(boardfilename))

View file

@ -2296,8 +2296,6 @@ int G_EnterLevel(int gameMode)
if (Menu_HaveUserMap())
{
Bcorrectfilename(boardfilename,0);
int levelNum = G_FindLevelByFile(boardfilename);
if (levelNum != MAXLEVELS*MAXVOLUMES)