mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-22 04:21:23 +00:00
Make tokenizer keep a copy of string in normal memory
This commit is contained in:
parent
a8a92a57a7
commit
8c7fe2ae95
7 changed files with 28 additions and 13 deletions
|
@ -552,7 +552,7 @@ void *M_Memcpy(void* dest, const void* src, size_t n);
|
|||
char *va(const char *format, ...) FUNCPRINTF;
|
||||
char *M_GetToken(const char *inputString);
|
||||
void M_UnGetToken(void);
|
||||
void M_TokenizerOpen(const char *inputString);
|
||||
void M_TokenizerOpen(const char *inputString, size_t len);
|
||||
void M_TokenizerClose(void);
|
||||
const char *M_TokenizerRead(UINT32 i);
|
||||
const char *M_TokenizerReadZDoom(UINT32 i);
|
||||
|
|
|
@ -1978,9 +1978,9 @@ void M_UnGetToken(void)
|
|||
|
||||
static tokenizer_t *globalTokenizer = NULL;
|
||||
|
||||
void M_TokenizerOpen(const char *inputString)
|
||||
void M_TokenizerOpen(const char *inputString, size_t len)
|
||||
{
|
||||
globalTokenizer = Tokenizer_Open(inputString, 2);
|
||||
globalTokenizer = Tokenizer_Open(inputString, len, 2);
|
||||
}
|
||||
|
||||
void M_TokenizerClose(void)
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
#include "m_tokenizer.h"
|
||||
#include "z_zone.h"
|
||||
|
||||
tokenizer_t *Tokenizer_Open(const char *inputString, unsigned numTokens)
|
||||
tokenizer_t *Tokenizer_Open(const char *inputString, size_t len, unsigned numTokens)
|
||||
{
|
||||
tokenizer_t *tokenizer = Z_Malloc(sizeof(tokenizer_t), PU_STATIC, NULL);
|
||||
|
||||
tokenizer->input = inputString;
|
||||
tokenizer->zdup = malloc(len);
|
||||
|
||||
tokenizer->input = M_Memcpy(tokenizer->zdup, inputString, len);
|
||||
tokenizer->startPos = 0;
|
||||
tokenizer->endPos = 0;
|
||||
tokenizer->inputLength = 0;
|
||||
|
@ -51,6 +53,7 @@ void Tokenizer_Close(tokenizer_t *tokenizer)
|
|||
Z_Free(tokenizer->token[i]);
|
||||
Z_Free(tokenizer->capacity);
|
||||
Z_Free(tokenizer->token);
|
||||
free(tokenizer->zdup);
|
||||
Z_Free(tokenizer);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
typedef struct Tokenizer
|
||||
{
|
||||
void *zdup;
|
||||
const char *input;
|
||||
unsigned numTokens;
|
||||
UINT32 *capacity;
|
||||
|
@ -29,7 +30,7 @@ typedef struct Tokenizer
|
|||
const char *(*get)(struct Tokenizer*, UINT32);
|
||||
} tokenizer_t;
|
||||
|
||||
tokenizer_t *Tokenizer_Open(const char *inputString, unsigned numTokens);
|
||||
tokenizer_t *Tokenizer_Open(const char *inputString, size_t len, unsigned numTokens);
|
||||
void Tokenizer_Close(tokenizer_t *tokenizer);
|
||||
|
||||
const char *Tokenizer_Read(tokenizer_t *tokenizer, UINT32 i);
|
||||
|
|
|
@ -1525,6 +1525,12 @@ static boolean TextmapCount(size_t size)
|
|||
numvertexes = 0;
|
||||
numsectors = 0;
|
||||
|
||||
if(!tkn)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, "No text in lump!\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Look for namespace at the beginning.
|
||||
if (!fastcmp(tkn, "namespace"))
|
||||
{
|
||||
|
@ -3109,7 +3115,12 @@ static boolean P_LoadMapData(const virtres_t *virt)
|
|||
if (udmf) // Count how many entries for each type we got in textmap.
|
||||
{
|
||||
virtlump_t *textmap = vres_Find(virt, "TEXTMAP");
|
||||
M_TokenizerOpen((char *)textmap->data);
|
||||
if (textmap->size == 0)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, "Emtpy TEXTMAP Lump!\n");
|
||||
return false;
|
||||
}
|
||||
M_TokenizerOpen((char *)textmap->data, textmap->size);
|
||||
if (!TextmapCount(textmap->size))
|
||||
{
|
||||
M_TokenizerClose();
|
||||
|
|
|
@ -784,9 +784,9 @@ static struct PaletteRemapParseResult *PaletteRemap_ParseString(tokenizer_t *sc)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(const char *translation)
|
||||
static struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(const char *translation, size_t len)
|
||||
{
|
||||
tokenizer_t *sc = Tokenizer_Open(translation, 1);
|
||||
tokenizer_t *sc = Tokenizer_Open(translation, len, 1);
|
||||
struct PaletteRemapParseResult *result = PaletteRemap_ParseString(sc);
|
||||
Tokenizer_Close(sc);
|
||||
return result;
|
||||
|
@ -918,7 +918,7 @@ void R_ParseTrnslate(INT32 wadNum, UINT16 lumpnum)
|
|||
text[lumpLength] = '\0';
|
||||
Z_Free(lumpData);
|
||||
|
||||
sc = Tokenizer_Open(text, 1);
|
||||
sc = Tokenizer_Open(text, lumpLength, 1);
|
||||
tkn = sc->get(sc, 0);
|
||||
|
||||
struct NewTranslation *list = NULL;
|
||||
|
@ -963,7 +963,7 @@ void R_ParseTrnslate(INT32 wadNum, UINT16 lumpnum)
|
|||
|
||||
// Parse all of the translations
|
||||
do {
|
||||
struct PaletteRemapParseResult *parse_result = PaletteRemap_ParseTranslation(tkn);
|
||||
struct PaletteRemapParseResult *parse_result = PaletteRemap_ParseTranslation(tkn, strlen(tkn));
|
||||
if (parse_result->error)
|
||||
{
|
||||
PrintError(name, "%s", parse_result->error);
|
||||
|
|
|
@ -2704,7 +2704,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
|
|||
UINT8 *wadData = W_CacheLumpNum(lumpnum, PU_LEVEL);
|
||||
filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
|
||||
numlumps = ((wadinfo_t *)wadData)->numlumps;
|
||||
vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
|
||||
vlumps = Z_Calloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
|
||||
|
||||
// Build the lumps.
|
||||
for (i = 0; i < numlumps; i++)
|
||||
|
@ -2728,7 +2728,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
|
|||
break;
|
||||
numlumps++;
|
||||
|
||||
vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
|
||||
vlumps = Z_Calloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL);
|
||||
for (i = 0; i < numlumps; i++, lumpnum++)
|
||||
{
|
||||
vlumps[i].size = W_LumpLength(lumpnum);
|
||||
|
|
Loading…
Reference in a new issue