2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* StrRes.l
|
|
|
|
*
|
|
|
|
* Lex file for parsing string resource files
|
|
|
|
*/
|
|
|
|
|
2007-10-27 10:30:49 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2007-10-27 09:18:52 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Allow frame header files to be singly included */
|
|
|
|
#define FRAME_LIB_INCLUDE
|
|
|
|
|
2006-09-23 10:24:55 -07:00
|
|
|
#include "lib/framework/strres.h"
|
|
|
|
#include "lib/framework/strresly.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-05-29 11:12:02 -07:00
|
|
|
#include <physfs.h>
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Get the Yacc definitions */
|
2007-01-09 13:13:58 -08:00
|
|
|
#include "strres_parser.tab.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-02-28 22:12:28 -08:00
|
|
|
void strres_error(const char *pMessage,...);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Maximum length for any TEXT_T value */
|
2007-09-16 07:05:01 -07:00
|
|
|
#define YYLMAX 8192
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Store for any string values */
|
2006-11-03 13:35:50 -08:00
|
|
|
extern char aText[TEXT_BUFFERS][YYLMAX];
|
2007-06-28 10:47:08 -07:00
|
|
|
static UDWORD currText=0;
|
|
|
|
|
|
|
|
// Note if in a comment
|
|
|
|
static BOOL inComment;
|
|
|
|
|
2007-05-29 11:12:02 -07:00
|
|
|
/* Handle to the input file */
|
|
|
|
static PHYSFS_file* pReadFile = NULL;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
#define YY_INPUT(buf,result,max_size) \
|
2007-05-29 11:12:02 -07:00
|
|
|
if (PHYSFS_eof(pReadFile)) \
|
|
|
|
{ \
|
|
|
|
buf[0] = EOF; result = YY_NULL; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
result = PHYSFS_read(pReadFile, buf, 1, max_size); \
|
|
|
|
if (result == -1) \
|
|
|
|
{ \
|
2007-06-28 10:47:08 -07:00
|
|
|
buf[0] = EOF; result = YY_NULL; \
|
2007-05-29 11:12:02 -07:00
|
|
|
} \
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
%}
|
|
|
|
|
|
|
|
%option nounput
|
|
|
|
%option prefix="strres_"
|
|
|
|
%option yylineno
|
|
|
|
|
|
|
|
%x COMMENT
|
|
|
|
%x QUOTE
|
|
|
|
%x SLCOMMENT
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
/* Match text values */
|
|
|
|
[a-zA-Z][-0-9_a-zA-Z]* {
|
2007-10-27 09:18:52 -07:00
|
|
|
strlcpy(aText[currText], strres_text, sizeof(aText[currText]));
|
2007-06-28 10:47:08 -07:00
|
|
|
strres_lval.sval = aText[currText];
|
|
|
|
currText = (currText + 1) % TEXT_BUFFERS;
|
|
|
|
return TEXT_T;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Match quoted text */
|
|
|
|
\" { BEGIN QUOTE; }
|
|
|
|
<QUOTE>\" { BEGIN 0; }
|
|
|
|
<QUOTE>\n { strres_error("Unexpected end of line in string"); }
|
|
|
|
<QUOTE>[^\"\n]* {
|
2007-10-27 09:18:52 -07:00
|
|
|
strlcpy(aText[currText], strres_text, sizeof(aText[currText]));
|
2007-06-28 10:47:08 -07:00
|
|
|
strres_lval.sval = aText[currText];
|
|
|
|
currText = (currText + 1) % TEXT_BUFFERS;
|
|
|
|
return QTEXT_T;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip white space */
|
|
|
|
[ \t\n\x0d\x0a] ;
|
|
|
|
|
|
|
|
/* Strip comments */
|
2008-03-24 09:51:17 -07:00
|
|
|
"/*" { inComment=true; BEGIN COMMENT; }
|
2007-06-28 10:47:08 -07:00
|
|
|
<COMMENT>"*/" |
|
2008-03-24 09:51:17 -07:00
|
|
|
<COMMENT>"*/"\n { inComment=false; BEGIN 0; }
|
2007-06-28 10:47:08 -07:00
|
|
|
<COMMENT>. |
|
|
|
|
<COMMENT>\n ;
|
|
|
|
|
|
|
|
/* Strip single line comments */
|
|
|
|
"//" { BEGIN SLCOMMENT; }
|
|
|
|
<SLCOMMENT>\n { BEGIN 0; }
|
|
|
|
<SLCOMMENT>[^\n]* ;
|
|
|
|
|
|
|
|
/* Match anything that's been missed and pass it as a char */
|
|
|
|
. return strres_text[0];
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2007-05-29 11:12:02 -07:00
|
|
|
/* Set the current input file for the lexer */
|
|
|
|
void strresSetInputFile(PHYSFS_file* fileHandle)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-05-29 11:12:02 -07:00
|
|
|
pReadFile = fileHandle;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Reset the lexer incase it's been used before */
|
|
|
|
yy_flush_buffer( YY_CURRENT_BUFFER );
|
|
|
|
}
|
|
|
|
|
|
|
|
void strresGetErrorData(int *pLine, char **ppText)
|
|
|
|
{
|
|
|
|
*pLine = strres_lineno;
|
|
|
|
*ppText = strres_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
int strres_wrap(void)
|
|
|
|
{
|
|
|
|
if (inComment)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_ERROR, "Warning: reched end of file in a comment" );
|
|
|
|
abort();
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-01-09 13:13:58 -08:00
|
|
|
|
2008-03-27 10:09:16 -07:00
|
|
|
/* Older GNU Flex versions don't define yylex_destroy()
|
|
|
|
* (and neither define a subminor version)
|
|
|
|
*/
|
2008-03-28 04:05:19 -07:00
|
|
|
#if !defined(YY_FLEX_SUBMINOR_VERSION) || (YY_FLEX_SUBMINOR_VERSION < 9)
|
2008-03-27 10:09:16 -07:00
|
|
|
int strres_lex_destroy(void)
|
|
|
|
{
|
2008-03-28 04:05:19 -07:00
|
|
|
/* For non-reentrant C scanner only. */
|
|
|
|
yy_delete_buffer(YY_CURRENT_BUFFER);
|
|
|
|
yy_init = 1;
|
2008-03-27 10:09:16 -07:00
|
|
|
}
|
|
|
|
#endif
|