* Make the level parser state enum a typedef (LEVELPARSER_STATE)

* When lev_error() gets called do __not__ ASSERT, use debug(LOG_ERROR, ... instead as the return value of false will be used as an indicator of failure anyway (no need to abort as it will cause the --selftest to always fail)
 * Accept empty input files for the .lev parser


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5285 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-06-21 17:32:03 +00:00
parent 57cb40c1ed
commit 76192b6534
1 changed files with 9 additions and 5 deletions

View File

@ -72,7 +72,7 @@ char *pLevToken;
SDWORD levVal; SDWORD levVal;
static SDWORD levelLoadType; static SDWORD levelLoadType;
// modes for the parser // modes for the parser
enum typedef enum
{ {
LP_START, // no input received LP_START, // no input received
LP_LEVEL, // level token received LP_LEVEL, // level token received
@ -83,7 +83,7 @@ enum
LP_WAITDATA, // defining level data, waiting for data token LP_WAITDATA, // defining level data, waiting for data token
LP_DATA, // data token received LP_DATA, // data token received
LP_GAME, // game token received LP_GAME, // game token received
}; } LEVELPARSER_STATE;
// initialise the level system // initialise the level system
@ -129,7 +129,7 @@ void levShutDown(void)
// error report function for the level parser // error report function for the level parser
void lev_error(const char* msg) void lev_error(const char* msg)
{ {
ASSERT(!"level parse error", "Level File parse error: `%s` at line `%d` text `%s`", msg, lev_get_lineno(), lev_get_text()); debug(LOG_ERROR, "Level File parse error: `%s` at line `%d` text `%s`", msg, lev_get_lineno(), lev_get_text());
} }
/** Find a level dataset with the given name. /** Find a level dataset with the given name.
@ -157,7 +157,8 @@ LEVEL_DATASET* levFindDataSet(const char* name)
BOOL levParse(const char* buffer, size_t size, searchPathMode datadir) BOOL levParse(const char* buffer, size_t size, searchPathMode datadir)
{ {
lexerinput_t input; lexerinput_t input;
SDWORD token, state, currData=0; LEVELPARSER_STATE state;
int token, currData = -1;
LEVEL_DATASET *psDataSet = NULL; LEVEL_DATASET *psDataSet = NULL;
input.type = LEXINPUT_BUFFER; input.type = LEXINPUT_BUFFER;
@ -431,7 +432,10 @@ BOOL levParse(const char* buffer, size_t size, searchPathMode datadir)
lev_lex_destroy(); lev_lex_destroy();
if (state != LP_WAITDATA || currData == 0) // Accept empty files when parsing (indicated by currData < 0)
if (currData >= 0
&& (state != LP_WAITDATA
|| currData == 0))
{ {
lev_error("Unexpected end of file"); lev_error("Unexpected end of file");
return false; return false;