From c623b041700e584fe7bddf6b60274c0408d56952 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 12:19:28 +0200 Subject: [PATCH] - copied some fixes for overlong config entries from Raze. - renamed basictypes.h to basics.h to keep the file name in line with Raze and make comparisons easier. --- src/console/c_console.h | 2 +- src/d_event.h | 2 +- src/doomtype.h | 3 +- src/gamedata/gi.h | 2 +- src/gamedata/textures/image.cpp | 1 + src/m_misc.h | 2 +- src/playsim/portal.h | 2 +- src/rendering/gl_load/gl_interface.h | 2 +- src/utility/{basictypes.h => basics.h} | 10 ++- src/utility/configfile.cpp | 99 +++++++++++--------------- src/utility/configfile.h | 8 +-- src/utility/files.h | 2 +- src/utility/m_crc32.h | 2 +- src/utility/m_random.h | 2 +- src/utility/name.cpp | 1 + src/utility/x86.h | 2 +- 16 files changed, 62 insertions(+), 80 deletions(-) rename src/utility/{basictypes.h => basics.h} (88%) diff --git a/src/console/c_console.h b/src/console/c_console.h index 276c8b7933..eea8c98ca7 100644 --- a/src/console/c_console.h +++ b/src/console/c_console.h @@ -35,7 +35,7 @@ #define __C_CONSOLE__ #include -#include "basictypes.h" +#include "basics.h" struct event_t; diff --git a/src/d_event.h b/src/d_event.h index ef54c3a0ff..82fd978ed2 100644 --- a/src/d_event.h +++ b/src/d_event.h @@ -24,7 +24,7 @@ #define __D_EVENT_H__ -#include "basictypes.h" +#include "basics.h" #include diff --git a/src/doomtype.h b/src/doomtype.h index ce644f7374..c73a039082 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -28,6 +28,7 @@ #include "tarray.h" #include "name.h" #include "zstring.h" +#include "cmdlib.h" class PClassActor; typedef TMap FClassMap; @@ -51,7 +52,7 @@ typedef TMap FClassMap; #define FORCE_PACKED #endif -#include "basictypes.h" +#include "basics.h" extern bool batchrun; diff --git a/src/gamedata/gi.h b/src/gamedata/gi.h index 5d5f061e3b..65a9c64d2c 100644 --- a/src/gamedata/gi.h +++ b/src/gamedata/gi.h @@ -34,7 +34,7 @@ #ifndef __GI_H__ #define __GI_H__ -#include "basictypes.h" +#include "basics.h" #include "zstring.h" // Flags are not user configurable and only depend on the standard IWADs diff --git a/src/gamedata/textures/image.cpp b/src/gamedata/textures/image.cpp index 9c524c56be..6a47446519 100644 --- a/src/gamedata/textures/image.cpp +++ b/src/gamedata/textures/image.cpp @@ -39,6 +39,7 @@ #include "image.h" #include "w_wad.h" #include "files.h" +#include "cmdlib.h" FMemArena FImageSource::ImageArena(32768); TArrayFImageSource::ImageForLump; diff --git a/src/m_misc.h b/src/m_misc.h index 8a0b9ef7b2..e135398b33 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -24,7 +24,7 @@ #ifndef __M_MISC__ #define __M_MISC__ -#include "basictypes.h" +#include "basics.h" #include "zstring.h" class FConfigFile; diff --git a/src/playsim/portal.h b/src/playsim/portal.h index b5e2b7a1b6..9d3873b718 100644 --- a/src/playsim/portal.h +++ b/src/playsim/portal.h @@ -1,7 +1,7 @@ #ifndef _PORTALS_H_ #define _PORTALS_H_ -#include "basictypes.h" +#include "basics.h" #include "m_bbox.h" struct FPortalGroupArray; diff --git a/src/rendering/gl_load/gl_interface.h b/src/rendering/gl_load/gl_interface.h index f1f5801275..bcec2817f8 100644 --- a/src/rendering/gl_load/gl_interface.h +++ b/src/rendering/gl_load/gl_interface.h @@ -1,7 +1,7 @@ #ifndef R_RENDER #define R_RENDER -#include "basictypes.h" +#include "basics.h" struct RenderContext { diff --git a/src/utility/basictypes.h b/src/utility/basics.h similarity index 88% rename from src/utility/basictypes.h rename to src/utility/basics.h index 57e4bb5c57..2c5fb6f982 100644 --- a/src/utility/basictypes.h +++ b/src/utility/basics.h @@ -1,12 +1,8 @@ -#ifndef __BASICTYPES_H -#define __BASICTYPES_H +#ifndef __BASICS_H +#define __BASICS_H #include #include -#include "cmdlib.h" - -typedef uint32_t BITFIELD; -typedef int INTBOOL; // // fixed point, 32bit as 16.16. @@ -46,4 +42,6 @@ typedef uint32_t angle_t; #endif #endif +using INTBOOL = int; +using BITFIELD = uint32_t; #endif diff --git a/src/utility/configfile.cpp b/src/utility/configfile.cpp index 2dc016e9e4..52bb4bcae0 100644 --- a/src/utility/configfile.cpp +++ b/src/utility/configfile.cpp @@ -36,15 +36,11 @@ #include #include -#include "doomtype.h" #include "configfile.h" #include "files.h" -#include "m_random.h" #define READBUFFERSIZE 256 -static FRandom pr_endtag; - //==================================================================== // // FConfigFile Constructor @@ -621,15 +617,15 @@ void FConfigFile::LoadConfigFile () // //==================================================================== -bool FConfigFile::ReadConfig (void *file) +bool FConfigFile::ReadConfig (FileReader *file) { - uint8_t readbuf[READBUFFERSIZE]; + TArray readbuf; FConfigSection *section = NULL; ClearConfig (); - while (ReadLine ((char*)readbuf, READBUFFERSIZE, file) != NULL) + while (ReadLine (readbuf, file) != NULL) { - uint8_t *start = readbuf; + uint8_t *start = readbuf.Data(); uint8_t *equalpt; uint8_t *endpt; @@ -643,25 +639,17 @@ bool FConfigFile::ReadConfig (void *file) { continue; } - // Do not process tail of long line - const bool longline = (READBUFFERSIZE - 1) == strlen((char*)readbuf) && '\n' != readbuf[READBUFFERSIZE - 2]; - if (longline) + + // Remove white space at end of line + endpt = start + strlen ((char*)start) - 1; + while (endpt > start && *endpt <= ' ') { - endpt = start + READBUFFERSIZE - 2; - } - else - { - // Remove white space at end of line - endpt = start + strlen ((char*)start) - 1; - while (endpt > start && *endpt <= ' ') - { - endpt--; - } - // Remove line feed '\n' character - endpt[1] = 0; - if (endpt <= start) - continue; // Nothing here + endpt--; } + // Remove line feed '\n' character + endpt[1] = 0; + if (endpt <= start) + continue; // Nothing here if (*start == '[') { // Section header @@ -697,31 +685,6 @@ bool FConfigFile::ReadConfig (void *file) { ReadMultiLineValue (file, section, (char*)start, (char*)whiteprobe + 3); } - else if (longline) - { - const FString key = (char*)start; - FString value = (char*)whiteprobe; - - while (ReadLine ((char*)readbuf, READBUFFERSIZE, file) != NULL) - { - const size_t endpos = (0 == readbuf[0]) ? 0 : (strlen((char*)readbuf) - 1); - const bool endofline = '\n' == readbuf[endpos]; - - if (endofline) - { - readbuf[endpos] = 0; - } - - value += (char*)readbuf; - - if (endofline) - { - break; - } - } - - NewConfigEntry (section, key.GetChars(), value.GetChars()); - } else { NewConfigEntry (section, (char*)start, (char*)whiteprobe); @@ -746,18 +709,18 @@ bool FConfigFile::ReadConfig (void *file) // //==================================================================== -FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(void *file, FConfigSection *section, const char *key, const char *endtag) +FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(FileReader *file, FConfigSection *section, const char *key, const char *endtag) { - char readbuf[READBUFFERSIZE]; + TArray readbuf; FString value; size_t endlen = strlen(endtag); // Keep on reading lines until we reach a line that matches >>>endtag - while (ReadLine(readbuf, READBUFFERSIZE, file) != NULL) + while (ReadLine(readbuf, file) != NULL) { // Does the start of this line match the endtag? if (readbuf[0] == '>' && readbuf[1] == '>' && readbuf[2] == '>' && - strncmp(readbuf + 3, endtag, endlen) == 0) + strncmp((char*)readbuf.Data() + 3, endtag, endlen) == 0) { // Is there nothing but line break characters after the match? size_t i; for (i = endlen + 3; readbuf[i] != '\0'; ++i) @@ -785,9 +748,28 @@ FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(void *file, FConfigSe // //==================================================================== -char *FConfigFile::ReadLine (char *string, int n, void *file) const +uint8_t *FConfigFile::ReadLine(TArray& string, FileReader* file) const { - return ((FileReader *)file)->Gets (string, n); + uint8_t byte; + string.Clear(); + while (file->Read(&byte, 1)) + { + if (byte == 0) + { + break; + } + if (byte != '\r') + { + string.Push(byte); + if (byte == '\n') + { + break; + } + } + } + if (string.Size() == 0) return nullptr; + string.Push(0); + return string.Data(); } //==================================================================== @@ -863,11 +845,10 @@ const char *FConfigFile::GenerateEndTag(const char *value) // isn't in the value. We create the sequences by generating two // 64-bit random numbers and Base64 encoding the first 15 bytes // from them. - union { uint64_t rand_num[2]; uint8_t rand_bytes[16]; }; + union { uint16_t rand_num[8]; uint8_t rand_bytes[16]; }; do { - rand_num[0] = pr_endtag.GenRand64(); - rand_num[1] = pr_endtag.GenRand64(); + for (auto &r : rand_num) r = (uint16_t)rand(); for (int i = 0; i < 5; ++i) { diff --git a/src/utility/configfile.h b/src/utility/configfile.h index ab68664306..cc484a3c24 100644 --- a/src/utility/configfile.h +++ b/src/utility/configfile.h @@ -76,8 +76,8 @@ public: protected: virtual void WriteCommentHeader (FileWriter *file) const; - virtual char *ReadLine (char *string, int n, void *file) const; - bool ReadConfig (void *file); + uint8_t *ReadLine (TArray &string, FileReader *file) const; + bool ReadConfig (FileReader *file); static const char *GenerateEndTag(const char *value); void RenameSection(const char *oldname, const char *newname) const; @@ -103,7 +103,7 @@ private: //char Name[1]; // + length of name }; - FConfigSection *Sections; + FConfigSection* Sections = nullptr; FConfigSection **LastSectionPtr; FConfigSection *CurrentSection; FConfigEntry *CurrentEntry; @@ -113,7 +113,7 @@ private: FConfigEntry *FindEntry (FConfigSection *section, const char *key) const; FConfigSection *NewConfigSection (const char *name); FConfigEntry *NewConfigEntry (FConfigSection *section, const char *key, const char *value); - FConfigEntry *ReadMultiLineValue (void *file, FConfigSection *section, const char *key, const char *terminator); + FConfigEntry *ReadMultiLineValue (FileReader *file, FConfigSection *section, const char *key, const char *terminator); void SetSectionNote (FConfigSection *section, const char *note); public: diff --git a/src/utility/files.h b/src/utility/files.h index ec4b15223d..a5ce834eca 100644 --- a/src/utility/files.h +++ b/src/utility/files.h @@ -40,7 +40,7 @@ #include #include #include -#include "basictypes.h" +#include "basics.h" #include "m_swap.h" #include "tarray.h" diff --git a/src/utility/m_crc32.h b/src/utility/m_crc32.h index 0d6a439db8..a39e189eae 100644 --- a/src/utility/m_crc32.h +++ b/src/utility/m_crc32.h @@ -33,7 +33,7 @@ */ #include -#include "basictypes.h" +#include "basics.h" // zlib includes some CRC32 stuff, so just use that diff --git a/src/utility/m_random.h b/src/utility/m_random.h index 250d88d133..c6f89a7b1a 100644 --- a/src/utility/m_random.h +++ b/src/utility/m_random.h @@ -36,7 +36,7 @@ #define __M_RANDOM__ #include -#include "basictypes.h" +#include "basics.h" #include "sfmt/SFMT.h" class FSerializer; diff --git a/src/utility/name.cpp b/src/utility/name.cpp index ecedcf0f31..de56772c40 100644 --- a/src/utility/name.cpp +++ b/src/utility/name.cpp @@ -36,6 +36,7 @@ #include "name.h" #include "c_dispatch.h" #include "c_console.h" +#include "cmdlib.h" // MACROS ------------------------------------------------------------------ diff --git a/src/utility/x86.h b/src/utility/x86.h index 13152e0d76..aa3ce23bcb 100644 --- a/src/utility/x86.h +++ b/src/utility/x86.h @@ -1,7 +1,7 @@ #ifndef X86_H #define X86_H -#include "basictypes.h" +#include "basics.h" struct CPUInfo // 92 bytes {