2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
2010-07-26 16:36:29 -07:00
|
|
|
Copyright (C) 2005-2010 Warzone 2100 Project
|
2007-01-15 12:09:25 -08:00
|
|
|
|
|
|
|
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 RES (*.wrf) files
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
|
2008-05-12 10:34:56 -07:00
|
|
|
extern int res_lex(void);
|
|
|
|
extern int res_get_lineno(void);
|
|
|
|
extern char* res_get_text(void);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Allow frame header files to be singly included */
|
|
|
|
#define FRAME_LIB_INCLUDE
|
|
|
|
|
2007-10-27 07:35:35 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-02-10 09:23:09 -08:00
|
|
|
#include "lib/framework/string_ext.h"
|
2006-09-23 11:38:12 -07:00
|
|
|
#include "lib/framework/frameresource.h"
|
2006-09-23 10:24:55 -07:00
|
|
|
#include "lib/framework/resly.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-05-12 10:34:56 -07:00
|
|
|
extern void yyerror(const char* msg);
|
|
|
|
void yyerror(const char* msg)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2008-05-12 10:34:56 -07:00
|
|
|
debug(LOG_ERROR, "RES file parse error:\n%s at line %d\nText: '%s'\n", msg, res_get_lineno(), res_get_text());
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%name-prefix="res_"
|
|
|
|
|
|
|
|
%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:00:09 -07:00
|
|
|
%destructor {
|
2008-05-27 14:37:54 -07:00
|
|
|
#ifndef WZ_OS_WIN
|
2008-05-12 11:00:09 -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:00:09 -07:00
|
|
|
} TEXT_T QTEXT_T
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* keywords */
|
|
|
|
%token DIRECTORY
|
|
|
|
%token FILETOKEN
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
res_file: res_line
|
|
|
|
| res_file res_line
|
|
|
|
;
|
|
|
|
|
|
|
|
res_line: dir_line
|
|
|
|
| file_line
|
|
|
|
;
|
|
|
|
|
2008-05-12 11:03:26 -07:00
|
|
|
dir_line: DIRECTORY QTEXT_T
|
|
|
|
{
|
|
|
|
UDWORD len;
|
|
|
|
|
|
|
|
// set a new input directory
|
|
|
|
debug(LOG_NEVER, "directory: %s", $2);
|
|
|
|
if (strncmp($2, "/:", strlen("/:")) == 0)
|
|
|
|
{
|
|
|
|
// the new dir is rooted
|
2008-05-25 06:46:49 -07:00
|
|
|
sstrcpy(aCurrResDir, $2);
|
2008-05-12 11:03:26 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-25 06:46:49 -07:00
|
|
|
sstrcpy(aCurrResDir, aResDir);
|
|
|
|
sstrcat(aCurrResDir, $2);
|
2008-05-12 11:03:26 -07:00
|
|
|
}
|
|
|
|
if (strlen($2) > 0)
|
|
|
|
{
|
|
|
|
// Add a trailing '/'
|
|
|
|
len = strlen(aCurrResDir);
|
|
|
|
aCurrResDir[len] = '/';
|
|
|
|
aCurrResDir[len+1] = 0;
|
|
|
|
debug(LOG_NEVER, "Current resource directory: %s", aCurrResDir);
|
|
|
|
}
|
|
|
|
free($2);
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
file_line: FILETOKEN TEXT_T QTEXT_T
|
2008-05-12 11:03:26 -07:00
|
|
|
{
|
|
|
|
bool succes;
|
|
|
|
/* load a data file */
|
|
|
|
debug(LOG_NEVER, "file: %s %s", $2, $3);
|
|
|
|
succes = resLoadFile($2, $3);
|
|
|
|
free($2);
|
|
|
|
free($3);
|
|
|
|
|
|
|
|
if (!succes)
|
|
|
|
{
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
;
|