* Now load the "STR_RES" resource type directly from a file rather than an intermediate memory buffer

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1760 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-05-29 18:12:02 +00:00
parent 9cecbdcb0d
commit 6cb536c0d1
5 changed files with 36 additions and 20 deletions

View File

@ -385,15 +385,24 @@ char *strresGetString(STR_RES *psRes, UDWORD id)
/* Load a string resource file */
BOOL strresLoad(STR_RES *psRes, char *pData, UDWORD size)
BOOL strresLoad(STR_RES* psRes, const char* fileName)
{
psCurrRes = psRes;
strresSetInputBuffer(pData, size);
if (strres_parse() != 0)
PHYSFS_file* fileHandle = PHYSFS_openRead(fileName);
if (!fileHandle)
{
debug(LOG_ERROR, "strresLoadFile: PHYSFS_openRead(\"%s\") failed with error: %s\n", fileName, PHYSFS_getLastError());
return FALSE;
}
strresSetInputFile(fileHandle);
if (strres_parse() != 0)
{
PHYSFS_close(fileHandle);
return FALSE;
}
PHYSFS_close(fileHandle);
return TRUE;
}

View File

@ -80,7 +80,7 @@ extern BOOL strresGetIDString(STR_RES *psRes, char *pIDStr, char **ppStoredID);
extern char *strresGetString(STR_RES *psRes, UDWORD id);
/* Load a string resource file */
extern BOOL strresLoad(STR_RES *psRes, char *pData, UDWORD size);
extern BOOL strresLoad(STR_RES* psRes, const char* fileName);
/* Return the the length of a char */
extern UDWORD stringLen(const char *pStr);

View File

@ -37,6 +37,8 @@
#include "lib/framework/strres.h"
#include "lib/framework/strresly.h"
#include <physfs.h>
/* Get the Yacc definitions */
#include "strres_parser.tab.h"
@ -52,16 +54,21 @@ static UDWORD currText=0;
// Note if in a comment
static BOOL inComment;
/* Pointer to the input buffer */
static char *pInputBuffer = NULL;
static char *pEndBuffer = NULL;
/* Handle to the input file */
static PHYSFS_file* pReadFile = NULL;
#define YY_INPUT(buf,result,max_size) \
if (pInputBuffer != pEndBuffer) { \
buf[0] = *(pInputBuffer++); result = 1; \
} else { \
if (PHYSFS_eof(pReadFile)) \
{ \
buf[0] = EOF; result = YY_NULL; \
} \
else { \
result = PHYSFS_read(pReadFile, buf, 1, max_size); \
if (result == -1) \
{ \
buf[0] = EOF; result = YY_NULL; \
}
} \
}
%}
%option nounput
@ -113,14 +120,12 @@ static char *pEndBuffer = NULL;
%%
/* Set the current input buffer for the lexer */
void strresSetInputBuffer(char *pBuffer, UDWORD size)
/* Set the current input file for the lexer */
void strresSetInputFile(PHYSFS_file* fileHandle)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
pReadFile = fileHandle;
/* Reset the lexer incase it's been used before */
// YY_FLUSH_BUFFER;
yy_flush_buffer( YY_CURRENT_BUFFER );
}

View File

@ -23,6 +23,8 @@
#ifndef _strresly_h
#define _strresly_h
#include <physfs.h>
/* Maximum number of characters in a directory entry */
#define FILE_MAXCHAR 255
@ -33,7 +35,7 @@
extern STR_RES *psCurrRes;
/* Set the current input buffer for the lexer - used by strresLoad */
extern void strresSetInputBuffer(char *pBuffer, UDWORD size);
extern void strresSetInputFile(PHYSFS_file* fileHandle);
/* Give access to the line number and current text for error messages */
extern void strresGetErrorData(int *pLine, char **ppText);

View File

@ -1025,7 +1025,7 @@ static void dataAnimRelease( void *pData )
}
/* Load a string resource file */
static BOOL dataStrResLoad(char *pBuffer, UDWORD size, void **ppData)
static BOOL dataStrResLoad(const char* fileName, void** ppData)
{
// recreate the string resource if it was freed by a WRF release
if (psStringRes == NULL)
@ -1036,7 +1036,7 @@ static BOOL dataStrResLoad(char *pBuffer, UDWORD size, void **ppData)
}
}
if (!strresLoad(psStringRes, pBuffer, size))
if (!strresLoad(psStringRes, fileName))
{
return FALSE;
}
@ -1155,7 +1155,6 @@ static const RES_TYPE_MIN_BUF BufferResourceTypes[] =
{"SMSG", bufferSMSGLoad, dataSMSGRelease},
{"SCRIPT", dataScriptLoad, (RES_FREE)scriptFreeCode},
{"SCRIPTVAL", dataScriptLoadVals, NULL},
{"STR_RES", dataStrResLoad, dataStrResRelease},
{"IMD", dataIMDBufferLoad, (RES_FREE)iV_IMDRelease},
};
@ -1176,6 +1175,7 @@ static const RES_TYPE_MIN_FILE FileResourceTypes[] =
{"TERTILES", dataTERTILESLoad, dataTERTILESRelease}, // freed by 3d shutdow},// Tertiles Files. This version used when running with hardware renderer.
{"IMG", dataIMGLoad, dataIMGRelease},
{"TEXPAGE", dataTexPageLoad, dataTexPageRelease},
{"STR_RES", dataStrResLoad, dataStrResRelease},
};
/* Pass all the data loading functions to the framework library */