* Use yytext instead of strres_text

* Get rid of lexer function strresGetErrorData and use strres_get_lineno() and strres_get_text() instead
 * Don't call abort() in function strres_error as the parser will return an error anyway (causing strresLoad to return false)


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5084 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-05-12 18:35:36 +00:00
parent fdc48bfc94
commit dfaf3cea17
4 changed files with 22 additions and 38 deletions

View File

@ -360,7 +360,7 @@ char *strresGetString(STR_RES *psRes, UDWORD id)
/* Load a string resource file */ /* Load a string resource file */
BOOL strresLoad(STR_RES* psRes, const char* fileName) BOOL strresLoad(STR_RES* psRes, const char* fileName)
{ {
bool retval = true; bool retval;
lexerinput_t input; lexerinput_t input;
input.type = LEXINPUT_PHYSFS; input.type = LEXINPUT_PHYSFS;

View File

@ -86,7 +86,7 @@ char* yyget_text()
/* Match text values */ /* Match text values */
[a-zA-Z][-0-9_a-zA-Z]* { [a-zA-Z][-0-9_a-zA-Z]* {
strlcpy(aText[currText], strres_text, sizeof(aText[currText])); strlcpy(aText[currText], yytext, sizeof(aText[currText]));
strres_lval.sval = aText[currText]; strres_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS; currText = (currText + 1) % TEXT_BUFFERS;
return TEXT_T; return TEXT_T;
@ -97,7 +97,7 @@ char* yyget_text()
<QUOTE>\" { BEGIN 0; } <QUOTE>\" { BEGIN 0; }
<QUOTE>\n { strres_error("Unexpected end of line in string"); } <QUOTE>\n { strres_error("Unexpected end of line in string"); }
<QUOTE>[^\"\n]* { <QUOTE>[^\"\n]* {
strlcpy(aText[currText], strres_text, sizeof(aText[currText])); strlcpy(aText[currText], yytext, sizeof(aText[currText]));
strres_lval.sval = aText[currText]; strres_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS; currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT_T; return QTEXT_T;
@ -119,7 +119,7 @@ char* yyget_text()
<SLCOMMENT>[^\n]* ; <SLCOMMENT>[^\n]* ;
/* Match anything that's been missed and pass it as a char */ /* Match anything that's been missed and pass it as a char */
. return strres_text[0]; . return yytext[0];
%% %%
@ -135,12 +135,6 @@ YY_EXTRA_TYPE yyget_extra()
return pBuffer; return pBuffer;
} }
void strresGetErrorData(int *pLine, char **ppText)
{
*pLine = strres_lineno;
*ppText = strres_text;
}
/* Older GNU Flex versions don't define yylex_destroy() /* Older GNU Flex versions don't define yylex_destroy()
* (and neither define a subminor version) * (and neither define a subminor version)
*/ */

View File

@ -28,15 +28,12 @@
#include "lib/framework/strresly.h" #include "lib/framework/strresly.h"
extern int strres_lex(void); extern int strres_lex(void);
extern int strres_get_lineno(void);
extern char* strres_get_text(void);
void yyerror(const char* msg) void yyerror(const char* msg)
{ {
int line; debug(LOG_ERROR, "STRRES file parse error:\n%s at line %d\nText: '%s'", msg, strres_get_lineno(), strres_get_text());
char *pText;
strresGetErrorData(&line, &pText);
debug(LOG_ERROR, "STRRES file parse error:\n%s at line %d\nText: '%s'", msg, line, pText);
abort();
} }
%} %}
@ -73,8 +70,4 @@ line: TEXT_T QTEXT_T
YYABORT; YYABORT;
} }
} }
; ;
%%

View File

@ -34,9 +34,6 @@ extern STR_RES *psCurrRes;
/* Set the current input buffer for the lexer - used by strresLoad */ /* Set the current input buffer for the lexer - used by strresLoad */
extern void strres_set_extra(YY_EXTRA_TYPE user_defined); extern void strres_set_extra(YY_EXTRA_TYPE user_defined);
/* Give access to the line number and current text for error messages */
extern void strresGetErrorData(int *pLine, char **ppText);
/* Call the yacc parser */ /* Call the yacc parser */
extern int strres_parse(void); extern int strres_parse(void);