* Rename function levError to lev_error (bison/yacc #defines yyerror to lev_error)

* In function lev_error use ASSERT always (even in non-debug builds as it will still output a message there)
 * Don't use a single function levGetErrorData for retrieving the line no & piece of text being parsed, instead use two functions levGetErrorLine and levGetErrorText


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4822 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-04-27 15:59:03 +00:00
parent fecc2a50d1
commit f7dd7eafba
3 changed files with 34 additions and 39 deletions

View File

@ -93,7 +93,7 @@ miss_clear return LTK_MCLEAR;
/* Match quoted text */ /* Match quoted text */
\" { BEGIN QUOTE; } \" { BEGIN QUOTE; }
<QUOTE>\" { BEGIN 0; } <QUOTE>\" { BEGIN 0; }
<QUOTE>\n { levError("Unexpected end of line in string"); } <QUOTE>\n { lev_error("Unexpected end of line in string"); }
<QUOTE>[^\"]* { <QUOTE>[^\"]* {
strlcpy(aText, lev_text, sizeof(aText)); strlcpy(aText, lev_text, sizeof(aText));
pLevToken = aText; pLevToken = aText;
@ -134,10 +134,14 @@ void levSetInputBuffer(char *pBuffer, UDWORD size)
inComment = false; inComment = false;
} }
void levGetErrorData(int *pLine, char **ppText) int levGetErrorLine()
{ {
*pLine = lev_lineno; return lev_lineno;
*ppText = lev_text; }
const char* levGetErrorText()
{
return lev_text;
} }
int lev_wrap(void) int lev_wrap(void)

View File

@ -52,7 +52,7 @@ extern char *pLevToken;
extern SDWORD levVal; extern SDWORD levVal;
// error report function for the level parser // error report function for the level parser
extern void levError(const char *pError); extern void lev_error(const char* msg);
// the lexer function // the lexer function
extern int lev_lex(void); extern int lev_lex(void);
@ -61,6 +61,7 @@ extern int lev_lex_destroy(void);
/* Set the current input buffer for the lexer */ /* Set the current input buffer for the lexer */
extern void levSetInputBuffer(char *pBuffer, UDWORD size); extern void levSetInputBuffer(char *pBuffer, UDWORD size);
extern void levGetErrorData(int *pLine, char **ppText); extern int levGetErrorLine(void);
extern const char* levGetErrorText(void);
#endif // __INCLUDED_SRC_LEVELINT_H__ #endif // __INCLUDED_SRC_LEVELINT_H__

View File

@ -123,18 +123,9 @@ void levShutDown(void)
// error report function for the level parser // error report function for the level parser
void levError(const char *pError) void lev_error(const char* msg)
{ {
char *pText; ASSERT(!"level parse error", "Level File parse error: `%s` at line `%d` text `%s`", msg, levGetErrorLine(), levGetErrorText());
int line;
levGetErrorData(&line, &pText);
#ifdef DEBUG
ASSERT( false, "Level File parse error:\n%s at line %d text %s\n", pError, line, pText );
#else
debug( LOG_ERROR, "Level File parse error:\n%s at line %d text %s\n", pError, line, pText );
#endif
} }
/** Find a level dataset with the given name. /** Find a level dataset with the given name.
@ -187,7 +178,8 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
psDataSet = (LEVEL_DATASET*)malloc(sizeof(LEVEL_DATASET)); psDataSet = (LEVEL_DATASET*)malloc(sizeof(LEVEL_DATASET));
if (!psDataSet) if (!psDataSet)
{ {
levError("Out of memory"); debug(LOG_ERROR, "Out of memory");
abort();
return false; return false;
} }
memset(psDataSet, 0, sizeof(LEVEL_DATASET)); memset(psDataSet, 0, sizeof(LEVEL_DATASET));
@ -237,7 +229,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
state = LP_LEVEL; state = LP_LEVEL;
@ -250,7 +242,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
@ -261,7 +253,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
@ -274,7 +266,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
{ {
if (levVal < MULTI_TYPE_START) if (levVal < MULTI_TYPE_START)
{ {
levError("invalid type number"); lev_error("invalid type number");
return false; return false;
} }
@ -282,7 +274,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
state = LP_LEVELDONE; state = LP_LEVELDONE;
@ -294,7 +286,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
@ -314,14 +306,14 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
psDataSet->type == LDS_MKEEP_LIMBO psDataSet->type == LDS_MKEEP_LIMBO
) )
{ {
levError("Missing dataset command"); lev_error("Missing dataset command");
return false; return false;
} }
state = LP_DATA; state = LP_DATA;
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
@ -333,7 +325,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
@ -347,13 +339,13 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
if (psFoundData == NULL) if (psFoundData == NULL)
{ {
levError("Cannot find full data set for camchange"); lev_error("Cannot find full data set for camchange");
return false; return false;
} }
if (psFoundData->type != LDS_CAMSTART) if (psFoundData->type != LDS_CAMSTART)
{ {
levError("Invalid data set name for cam change"); lev_error("Invalid data set name for cam change");
return false; return false;
} }
psFoundData->psChange = psDataSet; psFoundData->psChange = psDataSet;
@ -362,8 +354,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
psDataSet->pName = strdup(pLevToken); psDataSet->pName = strdup(pLevToken);
if (psDataSet->pName == NULL) if (psDataSet->pName == NULL)
{ {
debug(LOG_ERROR, "levParse: Out of memory!"); debug(LOG_ERROR, "Out of memory!");
levError("Out of memory");
abort(); abort();
return false; return false;
} }
@ -377,14 +368,14 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
if (psDataSet->psBaseData == NULL) if (psDataSet->psBaseData == NULL)
{ {
levError("Unknown dataset"); lev_error("Unknown dataset");
return false; return false;
} }
state = LP_WAITDATA; state = LP_WAITDATA;
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
@ -393,7 +384,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
{ {
if (currData >= LEVEL_MAXFILES) if (currData >= LEVEL_MAXFILES)
{ {
levError("Too many data files"); lev_error("Too many data files");
return false; return false;
} }
@ -407,8 +398,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
psDataSet->apDataFiles[currData] = strdup(pLevToken); psDataSet->apDataFiles[currData] = strdup(pLevToken);
if (psDataSet->apDataFiles[currData] == NULL) if (psDataSet->apDataFiles[currData] == NULL)
{ {
debug(LOG_ERROR, "levParse: Out of memory!"); debug(LOG_ERROR, "Out of memory!");
levError("Out of memory");
abort(); abort();
return false; return false;
} }
@ -420,12 +410,12 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
} }
else else
{ {
levError("Syntax Error"); lev_error("Syntax Error");
return false; return false;
} }
break; break;
default: default:
levError("Unexpected token"); lev_error("Unexpected token");
break; break;
} }
} }
@ -434,7 +424,7 @@ BOOL levParse(char *pBuffer, SDWORD size, searchPathMode datadir)
if (state != LP_WAITDATA || currData == 0) if (state != LP_WAITDATA || currData == 0)
{ {
levError("Unexpected end of file"); lev_error("Unexpected end of file");
return false; return false;
} }