diff --git a/src/doomdef.h b/src/doomdef.h index 1e0abadaf..9c8197e07 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -70,6 +70,12 @@ enum TELEFRAG_DAMAGE = 1000000 }; +inline int Tics2Seconds(int tics) +{ + return tics / TICRATE; +} + + typedef float skill_t; diff --git a/src/gamedata/fonts/v_font.cpp b/src/gamedata/fonts/v_font.cpp index e11423c84..ecccaf17f 100644 --- a/src/gamedata/fonts/v_font.cpp +++ b/src/gamedata/fonts/v_font.cpp @@ -1745,3 +1745,33 @@ void V_ClearFonts() AlternativeSmallFont = OriginalSmallFont = CurrentConsoleFont = NewSmallFont = NewConsoleFont = SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = nullptr; } +//========================================================================== +// +// 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; +} + diff --git a/src/gamedata/fonts/v_font.h b/src/gamedata/fonts/v_font.h index 960476054..67c7318d4 100644 --- a/src/gamedata/fonts/v_font.h +++ b/src/gamedata/fonts/v_font.h @@ -190,6 +190,7 @@ PalEntry V_LogColorFromColorRange (EColorRange range); EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int boldcolor); FFont *V_GetFont(const char *fontname, const char *fontlumpname = nullptr); void V_InitFontColors(); +char* CleanseString(char* str); #endif //__V_FONT_H__ diff --git a/src/maploader/glnodes.cpp b/src/maploader/glnodes.cpp index fa6246952..185de68cf 100644 --- a/src/maploader/glnodes.cpp +++ b/src/maploader/glnodes.cpp @@ -1151,13 +1151,9 @@ UNSAFE_CCMD(clearnodecache) FString path = M_GetCachePath(false); path += "/"; - try + if (!ScanDirectory(list, path)) { - ScanDirectory(list, path); - } - catch (CRecoverableError &err) - { - Printf("%s\n", err.GetMessage()); + Printf("Unable to scan node cache directory %s\n", path); return; } diff --git a/src/utility/basictypes.h b/src/utility/basictypes.h index 5a57aa9c9..f279bf58c 100644 --- a/src/utility/basictypes.h +++ b/src/utility/basictypes.h @@ -6,17 +6,6 @@ typedef uint32_t BITFIELD; typedef int INTBOOL; -#if !defined(GUID_DEFINED) -#define GUID_DEFINED -typedef struct _GUID -{ - uint32_t Data1; - uint16_t Data2; - uint16_t Data3; - uint8_t Data4[8]; -} GUID; -#endif - // // fixed point, 32bit as 16.16. // diff --git a/src/utility/cmdlib.cpp b/src/utility/cmdlib.cpp index f26f067f2..efc590032 100644 --- a/src/utility/cmdlib.cpp +++ b/src/utility/cmdlib.cpp @@ -34,11 +34,7 @@ #include #endif #endif -#include "doomtype.h" #include "cmdlib.h" -#include "doomerrors.h" -#include "v_text.h" -#include "sc_man.h" #include #include @@ -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 &list, const char *dirpath) +bool ScanDirectory(TArray &list, const char *dirpath) { struct _finddata_t fileinfo; intptr_t handle; @@ -914,7 +846,7 @@ void ScanDirectory(TArray &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 &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 &list, const char *dirpath) // //========================================================================== -void ScanDirectory(TArray &list, const char *dirpath) +bool ScanDirectory(TArray &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 &list, const char *dirpath) } closedir(directory); + return true; } #else @@ -1004,7 +938,7 @@ void ScanDirectory(TArray &list, const char *dirpath) // //========================================================================== -void ScanDirectory(TArray &list, const char *dirpath) +bool ScanDirectory(TArray &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 &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 &list, const char *dirpath) } fts_close(fts); delete[] argv[0]; + return true; } #endif diff --git a/src/utility/cmdlib.h b/src/utility/cmdlib.h index d187b43cf..850e7fe69 100644 --- a/src/utility/cmdlib.h +++ b/src/utility/cmdlib.h @@ -4,16 +4,25 @@ #define __CMDLIB__ -#include "doomtype.h" -#include "doomdef.h" -#include "m_fixed.h" - #include #include #include #include #include #include +#include "zstring.h" + +#if !defined(GUID_DEFINED) +#define GUID_DEFINED +typedef struct _GUID +{ + uint32_t Data1; + uint16_t Data2; + uint16_t Data3; + uint8_t Data4[8]; +} GUID; +#endif + // the dec offsetof macro doesnt work very well... #define myoffsetof(type,identifier) ((size_t)&((type *)alignof(type))->identifier - alignof(type)) @@ -33,7 +42,6 @@ FString ExtractFilePath (const char *path); FString ExtractFileBase (const char *path, bool keep_extension=false); struct FScriptPosition; -int ParseHex(const char *str, FScriptPosition *sc = nullptr); bool IsNum (const char *str); // [RH] added char *copystring(const char *s); @@ -47,7 +55,6 @@ const char *myasctime (); int strbin (char *str); FString strbin1 (const char *start); -char *CleanseString (char *str); void CreatePath(const char * fn); @@ -60,14 +67,9 @@ struct FFileList bool isDirectory; }; -void ScanDirectory(TArray &list, const char *dirpath); +bool ScanDirectory(TArray &list, const char *dirpath); bool IsAbsPath(const char*); -inline int Tics2Seconds(int tics) -{ - return tics / TICRATE; -} - #endif diff --git a/src/utility/sc_man.cpp b/src/utility/sc_man.cpp index fe9089a4e..35b45e998 100644 --- a/src/utility/sc_man.cpp +++ b/src/utility/sc_man.cpp @@ -1259,4 +1259,37 @@ void FScriptPosition::Message (int severity, const char *message, ...) const color, type, FileName.GetChars(), ScriptLine, color, composed.GetChars()); } +//========================================================================== +// +// 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 { + sc->Message(MSG_WARNING, "Bad hex number: %s", hex); + return 0; + } + str++; + } + + return num; +} + diff --git a/src/utility/sc_man.h b/src/utility/sc_man.h index bf119827c..df391614f 100644 --- a/src/utility/sc_man.h +++ b/src/utility/sc_man.h @@ -185,5 +185,7 @@ struct FScriptPosition } }; +int ParseHex(const char* hex, FScriptPosition* sc); + #endif //__SC_MAN_H__ diff --git a/src/win32/i_specialpaths.cpp b/src/win32/i_specialpaths.cpp index d109d077c..d7e010360 100644 --- a/src/win32/i_specialpaths.cpp +++ b/src/win32/i_specialpaths.cpp @@ -38,6 +38,7 @@ #include #include "cmdlib.h" +#include "doomtype.h" #include "m_misc.h" #include "version.h" // for GAMENAME