* Use the lexer_input framework instead of a custom YY_INPUT implementation for strres_lexer.l
* Don't bother to check whether we're in a comment when reaching the end of a string resource file git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5083 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
fae3c7da53
commit
fdc48bfc94
|
@ -361,9 +361,11 @@ char *strresGetString(STR_RES *psRes, UDWORD id)
|
|||
BOOL strresLoad(STR_RES* psRes, const char* fileName)
|
||||
{
|
||||
bool retval = true;
|
||||
lexerinput_t input;
|
||||
|
||||
PHYSFS_file* fileHandle = PHYSFS_openRead(fileName);
|
||||
if (!fileHandle)
|
||||
input.type = LEXINPUT_PHYSFS;
|
||||
input.input.physfsfile = PHYSFS_openRead(fileName);
|
||||
if (!input.input.physfsfile)
|
||||
{
|
||||
debug(LOG_ERROR, "strresLoadFile: PHYSFS_openRead(\"%s\") failed with error: %s\n", fileName, PHYSFS_getLastError());
|
||||
return false;
|
||||
|
@ -372,11 +374,11 @@ BOOL strresLoad(STR_RES* psRes, const char* fileName)
|
|||
// Set string resource to operate on
|
||||
psCurrRes = psRes;
|
||||
|
||||
strresSetInputFile(fileHandle);
|
||||
strres_set_extra(&input);
|
||||
retval = (strres_parse() == 0);
|
||||
|
||||
strres_lex_destroy();
|
||||
PHYSFS_close(fileHandle);
|
||||
PHYSFS_close(input.input.physfsfile);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -43,29 +43,40 @@
|
|||
static char aText[TEXT_BUFFERS][YYLMAX];
|
||||
static UDWORD currText = 0;
|
||||
|
||||
// Note if in a comment
|
||||
static BOOL inComment;
|
||||
#include "lib/framework/lexer_input.h"
|
||||
|
||||
/* Handle to the input file */
|
||||
static PHYSFS_file* pReadFile = NULL;
|
||||
#ifndef yyextra
|
||||
# define yyextra yyget_extra()
|
||||
#endif
|
||||
|
||||
#define YY_INPUT(buf,result,max_size) \
|
||||
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; \
|
||||
} \
|
||||
/* Older GNU Flex versions don't define yyget_extra(), yyset_extra(),
|
||||
* yyget_text() and yyget_lineno().
|
||||
* (and neither define a subminor version)
|
||||
*/
|
||||
#if !defined(YY_FLEX_SUBMINOR_VERSION) || (YY_FLEX_SUBMINOR_VERSION < 9)
|
||||
# define yyget_extra res_get_extra
|
||||
# define yyset_extra res_set_extra
|
||||
# define yyget_lineno res_get_lineno
|
||||
# define yyget_text res_get_text
|
||||
extern void yyset_extra(YY_EXTRA_TYPE user_defined);
|
||||
extern YY_EXTRA_TYPE yyget_extra(void);
|
||||
extern int yyget_lineno(void);
|
||||
int yyget_lineno()
|
||||
{
|
||||
return yylineno;
|
||||
}
|
||||
|
||||
extern char* yyget_text(void);
|
||||
char* yyget_text()
|
||||
{
|
||||
return yytext;
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%option nounput
|
||||
%option yylineno noyywrap nounput
|
||||
%option prefix="strres_"
|
||||
%option yylineno
|
||||
|
||||
%x COMMENT
|
||||
%x QUOTE
|
||||
|
@ -96,9 +107,9 @@ static PHYSFS_file* pReadFile = NULL;
|
|||
[ \t\n\x0d\x0a] ;
|
||||
|
||||
/* Strip comments */
|
||||
"/*" { inComment=true; BEGIN COMMENT; }
|
||||
"/*" { BEGIN COMMENT; }
|
||||
<COMMENT>"*/" |
|
||||
<COMMENT>"*/"\n { inComment=false; BEGIN 0; }
|
||||
<COMMENT>"*/"\n { BEGIN 0; }
|
||||
<COMMENT>. |
|
||||
<COMMENT>\n ;
|
||||
|
||||
|
@ -112,13 +123,16 @@ static PHYSFS_file* pReadFile = NULL;
|
|||
|
||||
%%
|
||||
|
||||
/* Set the current input file for the lexer */
|
||||
void strresSetInputFile(PHYSFS_file* fileHandle)
|
||||
{
|
||||
pReadFile = fileHandle;
|
||||
static YY_EXTRA_TYPE pBuffer = NULL;
|
||||
|
||||
/* Reset the lexer incase it's been used before */
|
||||
yy_flush_buffer( YY_CURRENT_BUFFER );
|
||||
void yyset_extra(YY_EXTRA_TYPE user_defined)
|
||||
{
|
||||
pBuffer = user_defined;
|
||||
}
|
||||
|
||||
YY_EXTRA_TYPE yyget_extra()
|
||||
{
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
void strresGetErrorData(int *pLine, char **ppText)
|
||||
|
@ -127,18 +141,6 @@ void strresGetErrorData(int *pLine, char **ppText)
|
|||
*ppText = strres_text;
|
||||
}
|
||||
|
||||
int strres_wrap(void)
|
||||
{
|
||||
if (inComment)
|
||||
{
|
||||
debug( LOG_ERROR, "Warning: reched end of file in a comment" );
|
||||
abort();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Older GNU Flex versions don't define yylex_destroy()
|
||||
* (and neither define a subminor version)
|
||||
*/
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef _strresly_h
|
||||
#define _strresly_h
|
||||
|
||||
#include <physfs.h>
|
||||
#include "lib/framework/lexer_input.h"
|
||||
|
||||
/* Maximum number of TEXT items in any one Yacc rule */
|
||||
#define TEXT_BUFFERS 10
|
||||
|
@ -32,7 +32,7 @@
|
|||
extern STR_RES *psCurrRes;
|
||||
|
||||
/* Set the current input buffer for the lexer - used by strresLoad */
|
||||
extern void strresSetInputFile(PHYSFS_file* fileHandle);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue