* Load SCRIPTVAL files (*.vlo) directly from their files rather than an intermediate memory buffer

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2531 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-10-05 18:16:02 +00:00
parent 3ebad628ca
commit 7f24fb3bfb
4 changed files with 54 additions and 24 deletions

View File

@ -900,8 +900,11 @@ static BOOL dataScriptLoad(const char *pBuffer, UDWORD size, void **ppData)
}
// Load a script variable values file
static BOOL dataScriptLoadVals(const char *pBuffer, UDWORD size, void **ppData)
static BOOL dataScriptLoadVals(const char* fileName, void **ppData)
{
BOOL success;
PHYSFS_file* fileHandle;
*ppData = NULL;
// don't load anything if a saved game is being loaded
@ -910,16 +913,23 @@ static BOOL dataScriptLoadVals(const char *pBuffer, UDWORD size, void **ppData)
return TRUE;
}
debug(LOG_WZ, "Loading script data %s",GetLastResourceFilename());
debug(LOG_WZ, "Loading script data %s", GetLastResourceFilename());
if (!scrvLoad(pBuffer, size))
fileHandle = PHYSFS_openRead(fileName);
if (fileHandle == NULL)
{
debug(LOG_ERROR, "Script %s did not compile", GetLastResourceFilename());
return FALSE;
}
*ppData = NULL;
return TRUE;
success = scrvLoad(fileHandle);
if (!success)
debug(LOG_ERROR, "Script %s did not compile", GetLastResourceFilename());
PHYSFS_close(fileHandle);
return success;
}
// New reduced resource type ... specially for PSX
@ -968,7 +978,6 @@ static const RES_TYPE_MIN_BUF BufferResourceTypes[] =
{"RFUNC", bufferRFUNCLoad, NULL},
{"SMSG", bufferSMSGLoad, dataSMSGRelease},
{"SCRIPT", dataScriptLoad, (RES_FREE)scriptFreeCode},
{"SCRIPTVAL", dataScriptLoadVals, NULL},
{"IMD", dataIMDBufferLoad, (RES_FREE)iV_IMDRelease},
};
@ -989,6 +998,7 @@ static const RES_TYPE_MIN_FILE FileResourceTypes[] =
{"TERTILES", dataTERTILESLoad, dataTERTILESRelease},
{"IMG", dataIMGLoad, dataIMGRelease},
{"TEXPAGE", dataTexPageLoad, dataImageRelease},
{"SCRIPTVAL", dataScriptLoadVals, NULL},
{"STR_RES", dataStrResLoad, dataStrResRelease},
};

View File

@ -26,6 +26,7 @@
#define _scriptvals_h
#include "basedef.h"
#include <physfs.h>
// The possible types of initialisation values
typedef enum _init_type
@ -53,7 +54,7 @@ typedef struct _array_indexes
} ARRAY_INDEXES;
/* Set the current input buffer for the lexer */
extern void scrvSetInputBuffer(const char *pBuffer, UDWORD size);
extern void scrvSetInputFile(PHYSFS_file* fileHandle);
extern void scrvGetErrorData(int *pLine, char **ppText);
@ -112,7 +113,7 @@ extern void scrvShutDown(void);
extern void scrvReset(void);
// Load a script value file
extern BOOL scrvLoad(const char *pData, UDWORD size);
extern BOOL scrvLoad(PHYSFS_file* fileHandle);
// Link any object types to the actual pointer values
//extern BOOL scrvLinkValues(void);

View File

@ -31,6 +31,8 @@
#include "lib/script/script.h"
#include "src/scriptvals.h"
#include <physfs.h>
/* Get the Yacc definitions */
#include "scriptvals_parser.tab.h"
@ -46,19 +48,37 @@ static UDWORD currText=0;
// Note if we are in a comment
static BOOL inComment = FALSE;
/* Pointer to the input buffer */
static const char *pInputBuffer = NULL;
static const 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 { \
buf[0] = EOF; result = YY_NULL; \
}
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; \
} \
}
static inline int PHYSFS_getc()
{
char read_char;
if (PHYSFS_eof(pReadFile))
return EOF;
if (PHYSFS_read(pReadFile, &read_char, 1, 1) != 1)
return EOF;
return read_char;
}
#undef scrv_getc
#define scrv_getc() (pInputBuffer != pEndBuffer ? *(pInputBuffer++) : EOF)
#define scrv_getc PHYSFS_getc
%}
@ -150,11 +170,10 @@ FALSE { scrv_lval.bval = FALSE; return BOOLEAN_T; }
%%
/* Set the current input buffer for the lexer */
void scrvSetInputBuffer(const char *pBuffer, UDWORD size)
/* Set the current input file for the lexer */
void scrvSetInputFile(PHYSFS_file* fileHandle)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
pReadFile = fileHandle;
/* Reset the lexer in case it's been used before */
scrv__flush_buffer(YY_CURRENT_BUFFER);

View File

@ -828,9 +828,9 @@ BOOL scrvLookUpArray(const char *pIdent, UDWORD *pIndex)
// Load a script value file
BOOL scrvLoad(const char *pData, UDWORD size)
BOOL scrvLoad(PHYSFS_file* fileHandle)
{
scrvSetInputBuffer(pData, size);
scrvSetInputFile(fileHandle);
if (scrv_parse() != 0)
{