- 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.
This commit is contained in:
Christoph Oelckers 2020-04-11 12:19:28 +02:00
parent 58afc3d5b2
commit c623b04170
16 changed files with 62 additions and 80 deletions

View file

@ -35,7 +35,7 @@
#define __C_CONSOLE__
#include <stdarg.h>
#include "basictypes.h"
#include "basics.h"
struct event_t;

View file

@ -24,7 +24,7 @@
#define __D_EVENT_H__
#include "basictypes.h"
#include "basics.h"
#include <functional>

View file

@ -28,6 +28,7 @@
#include "tarray.h"
#include "name.h"
#include "zstring.h"
#include "cmdlib.h"
class PClassActor;
typedef TMap<int, PClassActor *> FClassMap;
@ -51,7 +52,7 @@ typedef TMap<int, PClassActor *> FClassMap;
#define FORCE_PACKED
#endif
#include "basictypes.h"
#include "basics.h"
extern bool batchrun;

View file

@ -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

View file

@ -39,6 +39,7 @@
#include "image.h"
#include "w_wad.h"
#include "files.h"
#include "cmdlib.h"
FMemArena FImageSource::ImageArena(32768);
TArray<FImageSource *>FImageSource::ImageForLump;

View file

@ -24,7 +24,7 @@
#ifndef __M_MISC__
#define __M_MISC__
#include "basictypes.h"
#include "basics.h"
#include "zstring.h"
class FConfigFile;

View file

@ -1,7 +1,7 @@
#ifndef _PORTALS_H_
#define _PORTALS_H_
#include "basictypes.h"
#include "basics.h"
#include "m_bbox.h"
struct FPortalGroupArray;

View file

@ -1,7 +1,7 @@
#ifndef R_RENDER
#define R_RENDER
#include "basictypes.h"
#include "basics.h"
struct RenderContext
{

View file

@ -1,12 +1,8 @@
#ifndef __BASICTYPES_H
#define __BASICTYPES_H
#ifndef __BASICS_H
#define __BASICS_H
#include <stddef.h>
#include <stdint.h>
#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

View file

@ -36,15 +36,11 @@
#include <string.h>
#include <ctype.h>
#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<uint8_t> 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<uint8_t> 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<uint8_t>& 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)
{

View file

@ -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<uint8_t> &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:

View file

@ -40,7 +40,7 @@
#include <stdio.h>
#include <stdint.h>
#include <functional>
#include "basictypes.h"
#include "basics.h"
#include "m_swap.h"
#include "tarray.h"

View file

@ -33,7 +33,7 @@
*/
#include <zlib.h>
#include "basictypes.h"
#include "basics.h"
// zlib includes some CRC32 stuff, so just use that

View file

@ -36,7 +36,7 @@
#define __M_RANDOM__
#include <stdio.h>
#include "basictypes.h"
#include "basics.h"
#include "sfmt/SFMT.h"
class FSerializer;

View file

@ -36,6 +36,7 @@
#include "name.h"
#include "c_dispatch.h"
#include "c_console.h"
#include "cmdlib.h"
// MACROS ------------------------------------------------------------------

View file

@ -1,7 +1,7 @@
#ifndef X86_H
#define X86_H
#include "basictypes.h"
#include "basics.h"
struct CPUInfo // 92 bytes
{