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
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* resource.l
|
|
|
|
*
|
|
|
|
* Lex file for parsing res 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/resly.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Get the Yacc definitions */
|
2007-01-09 13:13:58 -08:00
|
|
|
#include "resource_parser.tab.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 10:34:56 -07:00
|
|
|
extern void res_error(const char* msg);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-09-16 07:05:01 -07:00
|
|
|
/* Maximum length for any TEXT_T value */
|
2007-06-28 10:47:08 -07:00
|
|
|
#define YYLMAX 8192
|
|
|
|
|
|
|
|
/* Store for any string values */
|
2008-05-12 10:50:49 -07:00
|
|
|
static char aText[TEXT_BUFFERS][YYLMAX];
|
|
|
|
static UDWORD currText = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 10:23:33 -07:00
|
|
|
#include "lib/framework/lexer_input.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 10:23:33 -07:00
|
|
|
#ifndef yyextra
|
|
|
|
# define yyextra yyget_extra()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
2008-05-12 10:04:32 -07:00
|
|
|
%option yylineno noyywrap nounput
|
2007-06-28 10:47:08 -07:00
|
|
|
%option prefix="res_"
|
|
|
|
|
|
|
|
%x COMMENT
|
|
|
|
%x QUOTE
|
|
|
|
%x SLCOMMENT
|
|
|
|
|
|
|
|
%%
|
|
|
|
/* Match to key words */
|
|
|
|
directory { return DIRECTORY; }
|
|
|
|
file { return FILETOKEN; }
|
|
|
|
|
|
|
|
/* Match text values */
|
|
|
|
[a-zA-Z][-0-9_a-zA-Z]* {
|
2008-05-12 10:41:00 -07:00
|
|
|
strlcpy(aText[currText], yytext, sizeof(aText[currText]));
|
2007-06-28 10:47:08 -07:00
|
|
|
res_lval.sval = aText[currText];
|
|
|
|
currText = (currText + 1) % TEXT_BUFFERS;
|
|
|
|
return TEXT_T;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Match quoted text */
|
2008-05-12 10:38:45 -07:00
|
|
|
\"\" {
|
|
|
|
aText[currText][0] = '\0';
|
|
|
|
aText[currText][1] = '\0';
|
|
|
|
res_lval.sval = aText[currText];
|
|
|
|
currText = (currText + 1) % TEXT_BUFFERS;
|
|
|
|
return QTEXT_T;
|
|
|
|
}
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
\" { BEGIN QUOTE; }
|
|
|
|
<QUOTE>\" { BEGIN 0; }
|
|
|
|
<QUOTE>\n { res_error("Unexpected end of line in string"); }
|
|
|
|
<QUOTE>[^\"\n]* {
|
2008-05-12 10:41:00 -07:00
|
|
|
strlcpy(aText[currText], yytext, sizeof(aText[currText]));
|
2007-06-28 10:47:08 -07:00
|
|
|
res_lval.sval = aText[currText];
|
|
|
|
currText = (currText + 1) % TEXT_BUFFERS;
|
|
|
|
return QTEXT_T;
|
|
|
|
}
|
|
|
|
/* Skip white space */
|
|
|
|
[ \t\n\x0d\x0a] ;
|
|
|
|
|
|
|
|
/* Strip comments */
|
2008-05-12 10:04:32 -07:00
|
|
|
"/*" { BEGIN COMMENT; }
|
2007-06-28 10:47:08 -07:00
|
|
|
<COMMENT>"*/" |
|
2008-05-12 10:04:32 -07:00
|
|
|
<COMMENT>"*/"\n { 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 */
|
2008-05-12 10:41:00 -07:00
|
|
|
. return yytext[0];
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
2008-05-12 10:23:33 -07:00
|
|
|
static YY_EXTRA_TYPE pBuffer = NULL;
|
|
|
|
|
|
|
|
void yyset_extra(YY_EXTRA_TYPE user_defined)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2008-05-12 10:23:33 -07:00
|
|
|
pBuffer = user_defined;
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 10:23:33 -07:00
|
|
|
YY_EXTRA_TYPE yyget_extra()
|
|
|
|
{
|
|
|
|
return pBuffer;
|
2007-06-28 10:47:08 -07: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 res_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
|