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
|
|
|
%{
|
2008-05-12 11:09:25 -07:00
|
|
|
/** @file
|
2007-06-28 10:47:08 -07:00
|
|
|
*
|
2008-05-12 11:09:25 -07:00
|
|
|
* Parser for string resource files
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
|
2006-09-23 10:24:55 -07:00
|
|
|
#include "lib/framework/frame.h"
|
|
|
|
#include "lib/framework/strres.h"
|
|
|
|
#include "lib/framework/strresly.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 11:35:36 -07:00
|
|
|
extern int strres_lex(void);
|
|
|
|
extern int strres_get_lineno(void);
|
|
|
|
extern char* strres_get_text(void);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 11:09:25 -07:00
|
|
|
void yyerror(const char* msg)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2008-05-12 11:35:36 -07:00
|
|
|
debug(LOG_ERROR, "STRRES file parse error:\n%s at line %d\nText: '%s'", msg, strres_get_lineno(), strres_get_text());
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2008-07-24 07:16:27 -07:00
|
|
|
// Forward declaration to allow pointers to this type
|
|
|
|
struct STR_RES;
|
|
|
|
|
|
|
|
#define YYPARSE_PARAM psStrRes
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
%}
|
|
|
|
|
|
|
|
%name-prefix="strres_"
|
|
|
|
|
|
|
|
%union {
|
2006-11-03 13:35:50 -08:00
|
|
|
char *sval;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* value tokens */
|
|
|
|
%token <sval> TEXT_T
|
|
|
|
%token <sval> QTEXT_T /* Text with double quotes surrounding it */
|
|
|
|
|
2008-05-12 11:47:25 -07:00
|
|
|
// Rule types
|
|
|
|
%type <sval> string
|
|
|
|
|
|
|
|
%destructor {
|
2008-05-27 14:37:54 -07:00
|
|
|
#ifndef WZ_OS_WIN
|
2008-05-12 11:47:25 -07:00
|
|
|
// Force type checking by the compiler
|
|
|
|
char * const s = $$;
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
free(s);
|
2008-05-27 14:37:54 -07:00
|
|
|
#endif
|
2008-05-12 11:47:25 -07:00
|
|
|
} TEXT_T QTEXT_T string
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
%%
|
|
|
|
|
|
|
|
file: line
|
|
|
|
| file line
|
|
|
|
;
|
|
|
|
|
2008-05-12 11:47:25 -07:00
|
|
|
line: TEXT_T string
|
2008-05-12 11:35:36 -07:00
|
|
|
{
|
|
|
|
/* Pass the text string to the string manager */
|
2008-07-24 07:16:27 -07:00
|
|
|
const bool success = strresStoreString((struct STR_RES*)psStrRes, $1, $2);
|
2008-05-12 11:47:25 -07:00
|
|
|
|
|
|
|
// Clean up our tokens
|
|
|
|
free($1);
|
|
|
|
free($2);
|
|
|
|
|
|
|
|
if (!success)
|
2008-05-12 11:35:36 -07:00
|
|
|
{
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
}
|
2008-05-12 11:47:25 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
string: QTEXT_T
|
|
|
|
| '_' '(' QTEXT_T ')'
|
2008-05-12 11:35:36 -07:00
|
|
|
{
|
2008-05-12 11:47:25 -07:00
|
|
|
$$ = strdup(gettext($3));
|
|
|
|
free($3);
|
2008-05-12 11:35:36 -07:00
|
|
|
}
|