%{
/*
 * resource.y
 *
 * Yacc file for parsing RES files
 */

int res_lex (void);

/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE

// directory printfs
#define DEBUG_GROUP0

#include <string.h>

#include "types.h"
#include "debug.h"
#include "resly.h"
#include "frameresource.h"

/*
 * A simple error reporting routine
 */

void res_error(const char *pMessage,...)
{
	int	line;
	char	*pText;

	resGetErrorData(&line, &pText);
	DBERROR(("RES file parse error:\n%s at line %d\nText: '%s'\n",
			  pMessage, line, pText));
}

%}

%name-prefix="res_"

%union {
	STRING  *sval;
}

	/* value tokens */
%token <sval> TEXT
%token <sval> QTEXT			/* Text with double quotes surrounding it */

	/* keywords */
%token DIRECTORY
%token FILETOKEN

%%

res_file:			res_line
				|	res_file res_line
				;

res_line:			dir_line
				|	file_line
				;

dir_line:			DIRECTORY QTEXT		{
											UDWORD len;

											// set a new input directory
											DBP0(("directory: %s\n", $2));
											if ($2[1] == ':' ||
												$2[0] == '\\')
											{
												// the new dir is rooted
												strcpy(aCurrResDir, $2);
											}
											else
											{
												strcpy(aCurrResDir, aResDir);
												strcpy(aCurrResDir + strlen(aResDir),
													   $2);
											}
											if (strlen($2) > 0)
											{
												// Add a trailing '\\'
												len = strlen(aCurrResDir);
												aCurrResDir[len] = '\\';
												aCurrResDir[len+1] = 0;
//												DBP0(("aCurrResDir: %s\n", aCurrResDir));
											}
										}
				;


file_line:			FILETOKEN TEXT QTEXT
										{
											/* load a data file */
											DBP1(("file: %s %s\n", $2, $3));
											if (!resLoadFile($2, $3))
											{
												YYABORT;
											}
										}
				;

%%




