2008-03-19 21:09:53 +00:00
|
|
|
/*
|
|
|
|
** parse_xlat.cpp
|
|
|
|
** Translation definition compiler
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2008 Randy Heit
|
|
|
|
** Copyright 2008 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "tarray.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "info.h"
|
|
|
|
#include "gi.h"
|
2008-04-08 15:07:09 +00:00
|
|
|
#include "parsecontext.h"
|
2008-03-19 21:09:53 +00:00
|
|
|
#include "xlat_parser.h"
|
|
|
|
#include "xlat.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Token types not used in the grammar
|
|
|
|
enum
|
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
XLAT_INCLUDE=128,
|
|
|
|
XLAT_STRING,
|
2008-04-08 17:25:19 +00:00
|
|
|
XLAT_FLOATVAL, // floats are not used by the grammar
|
2008-03-19 21:09:53 +00:00
|
|
|
};
|
|
|
|
|
2008-04-08 15:07:09 +00:00
|
|
|
DEFINE_TOKEN_TRANS(XLAT_)
|
2008-03-19 21:09:53 +00:00
|
|
|
|
|
|
|
|
2008-04-08 15:07:09 +00:00
|
|
|
static FString LastTranslator;
|
|
|
|
TAutoGrowArray<FLineTrans> SimpleLineTranslations;
|
|
|
|
FBoomTranslator Boomish[MAX_BOOMISH];
|
|
|
|
int NumBoomish;
|
|
|
|
TAutoGrowArray<FSectorTrans> SectorTranslations;
|
|
|
|
TArray<FSectorMask> SectorMasks;
|
|
|
|
|
2008-03-19 21:09:53 +00:00
|
|
|
|
|
|
|
struct SpecialArgs
|
|
|
|
{
|
|
|
|
int addflags;
|
|
|
|
int args[5];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ListFilter
|
|
|
|
{
|
|
|
|
WORD filter;
|
|
|
|
BYTE value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MoreFilters
|
|
|
|
{
|
|
|
|
MoreFilters *next;
|
|
|
|
ListFilter filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MoreLines
|
|
|
|
{
|
|
|
|
MoreLines *next;
|
|
|
|
FBoomArg arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ParseBoomArg
|
|
|
|
{
|
|
|
|
BYTE constant;
|
|
|
|
WORD mask;
|
|
|
|
MoreFilters *filters;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-08 15:07:09 +00:00
|
|
|
struct XlatParseContext : public FParseContext
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
XlatParseContext(void *parser, ParseFunc parse, int *tt)
|
|
|
|
: FParseContext(parser, parse, tt)
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
bool FindToken (char *tok, int *type)
|
|
|
|
{
|
2008-05-12 17:14:38 +00:00
|
|
|
static const char *tokens[] =
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
"arg2", "arg3", "arg4", "arg5", "bitmask", "clear",
|
|
|
|
"define", "enum", "flags", "include", "lineid",
|
2008-05-22 19:35:38 +00:00
|
|
|
"maxlinespecial", "nobitmask", "sector", "tag"
|
2008-03-19 21:09:53 +00:00
|
|
|
};
|
|
|
|
static const short types[] =
|
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
XLAT_ARG2, XLAT_ARG3, XLAT_ARG4, XLAT_ARG5, XLAT_BITMASK, XLAT_CLEAR,
|
|
|
|
XLAT_DEFINE, XLAT_ENUM, XLAT_FLAGS, XLAT_INCLUDE, XLAT_TAG,
|
2008-05-22 19:35:38 +00:00
|
|
|
XLAT_MAXLINESPECIAL, XLAT_NOBITMASK, XLAT_SECTOR, XLAT_TAG
|
2008-03-19 21:09:53 +00:00
|
|
|
};
|
|
|
|
|
2008-05-12 17:14:38 +00:00
|
|
|
int min = 0, max = countof(tokens) - 1;
|
2008-03-19 21:09:53 +00:00
|
|
|
|
2008-04-08 15:07:09 +00:00
|
|
|
while (min <= max)
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
int mid = (min + max) / 2;
|
|
|
|
int lexval = stricmp (tok, tokens[mid]);
|
|
|
|
if (lexval == 0)
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
*type = types[mid];
|
|
|
|
return true;
|
2008-03-19 21:09:53 +00:00
|
|
|
}
|
2008-04-08 15:07:09 +00:00
|
|
|
else if (lexval > 0)
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
min = mid + 1;
|
2008-03-19 21:09:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-08 15:07:09 +00:00
|
|
|
max = mid - 1;
|
2008-03-19 21:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-08 15:07:09 +00:00
|
|
|
return false;
|
2008-03-19 21:09:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "xlat_parser.c"
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-03-23 14:18:27 +00:00
|
|
|
void P_LoadTranslator(const char *lumpname)
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-03-23 14:18:27 +00:00
|
|
|
// Only read the lump if it differs from the previous one.
|
|
|
|
if (LastTranslator.CompareNoCase(lumpname))
|
2008-03-19 21:09:53 +00:00
|
|
|
{
|
2008-03-23 14:18:27 +00:00
|
|
|
// Clear the old data before parsing the lump.
|
|
|
|
SimpleLineTranslations.Clear();
|
|
|
|
NumBoomish = 0;
|
|
|
|
SectorTranslations.Clear();
|
|
|
|
SectorMasks.Clear();
|
|
|
|
|
|
|
|
void *pParser = XlatParseAlloc(malloc);
|
|
|
|
|
2008-04-08 15:07:09 +00:00
|
|
|
XlatParseContext context(pParser, XlatParse, TokenTrans);
|
2008-03-23 14:18:27 +00:00
|
|
|
|
2008-04-08 15:07:09 +00:00
|
|
|
context.ParseLump(lumpname);
|
|
|
|
FParseToken tok;
|
2008-03-23 14:18:27 +00:00
|
|
|
tok.val=0;
|
|
|
|
XlatParse(pParser, 0, tok, &context);
|
|
|
|
XlatParseFree(pParser, free);
|
|
|
|
LastTranslator = lumpname;
|
2008-03-19 21:09:53 +00:00
|
|
|
}
|
|
|
|
}
|