Make scriptvals_lexer.l non-reentrant as Flex 2.5.4 (used on Windows) doesn't support %option reentrant

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5024 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-05-10 18:42:59 +00:00
parent 8049b92179
commit 3fae4ebae3
2 changed files with 103 additions and 95 deletions

View File

@ -46,13 +46,13 @@ static UDWORD currText=0;
#include "lib/framework/lexer_input.h"
// Forward declarations to suppress warnings due to -Wmissing-declarations
extern int scrv_get_column(yyscan_t yyscanner);
extern void scrv_set_column(int column_no, yyscan_t yyscanner);
#ifndef yyextra
# define yyextra yyget_extra()
#endif
%}
%option reentrant bison-bridge
%option bison-bridge
%option yylineno noyywrap nounput
%option warn nodefault
%option prefix="scrv_"
@ -114,7 +114,7 @@ FALSE { yylval->bval = false; return BOOLEAN_T; }
/* Match quoted text */
\" { BEGIN QUOTE; }
<QUOTE>\" { BEGIN 0; }
<QUOTE>\n { scrv_error(yyscanner, "Unexpected end of line in string"); }
<QUOTE>\n { scrv_error("Unexpected end of line in string"); }
<QUOTE>[^\"\n]* {
strcpy(aText[currText], yytext);
yylval->sval = aText[currText];
@ -142,6 +142,18 @@ FALSE { yylval->bval = false; return BOOLEAN_T; }
%%
static YY_EXTRA_TYPE pBuffer = NULL;
void yyset_extra(YY_EXTRA_TYPE user_defined)
{
pBuffer = user_defined;
}
YY_EXTRA_TYPE yyget_extra()
{
return pBuffer;
}
/* Older GNU Flex versions don't define yylex_destroy()
* (and neither define a subminor version)
*/

View File

@ -53,7 +53,7 @@ static SCRIPT_CONTEXT *psCurrContext;
static ARRAY_INDEXES sCurrArrayIndexes;
// check that an array index is valid
static BOOL scrvCheckArrayIndex(yyscan_t yyscanner, SDWORD base, ARRAY_INDEXES *psIndexes, UDWORD *pIndex)
static BOOL scrvCheckArrayIndex(SDWORD base, ARRAY_INDEXES *psIndexes, UDWORD *pIndex)
{
SDWORD i, size;
@ -64,13 +64,13 @@ static BOOL scrvCheckArrayIndex(yyscan_t yyscanner, SDWORD base, ARRAY_INDEXES *
if (base < 0 || base >= psCurrScript->numArrays)
{
yyerror(yyscanner, "Array index out of range");
yyerror("Array index out of range");
return false;
}
if (psIndexes->dimensions != psCurrScript->psArrayInfo[base].dimensions)
{
yyerror(yyscanner, "Invalid number of dimensions for array initialiser");
yyerror("Invalid number of dimensions for array initialiser");
return false;
}
@ -79,7 +79,7 @@ static BOOL scrvCheckArrayIndex(yyscan_t yyscanner, SDWORD base, ARRAY_INDEXES *
if ((psIndexes->elements[i] < 0) ||
(psIndexes->elements[i] >= psCurrScript->psArrayInfo[base].elements[i]))
{
yyerror(yyscanner, "Invalid index for dimension %d", i);
yyerror("Invalid index for dimension %d", i);
return false;
}
}
@ -103,8 +103,6 @@ static BOOL scrvCheckArrayIndex(yyscan_t yyscanner, SDWORD base, ARRAY_INDEXES *
%defines
%error-verbose
%pure-parser
%parse-param {yyscan_t yyscanner}
%lex-param {yyscan_t yyscanner}
%union {
BOOL bval;
@ -147,12 +145,12 @@ script_entry: script_name RUN
{
if (!eventNewContext(psCurrScript, CR_RELEASE, &psCurrContext))
{
yyerror(yyscanner, "Couldn't create context");
yyerror("Couldn't create context");
YYABORT;
}
if (!scrvAddContext($1, psCurrContext, SCRV_EXEC))
{
yyerror(yyscanner, "Couldn't store context");
yyerror("Couldn't store context");
YYABORT;
}
}
@ -167,12 +165,12 @@ script_entry: script_name RUN
{
if (!eventNewContext(psCurrScript, CR_NORELEASE, &psCurrContext))
{
yyerror(yyscanner, "Couldn't create context");
yyerror("Couldn't create context");
YYABORT;
}
if (!scrvAddContext($3, psCurrContext, SCRV_NOEXEC))
{
yyerror(yyscanner, "Couldn't store context");
yyerror("Couldn't store context");
YYABORT;
}
}
@ -212,7 +210,7 @@ script_name: SCRIPT QTEXT
if (!psCurrScript)
{
yyerror(yyscanner, "Script file %s not found", stringname);
yyerror("Script file %s not found", stringname);
YYABORT;
}
@ -242,20 +240,20 @@ var_init: var_entry TYPE var_value
if ($3.type != IT_INDEX ||
!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
break;
case ST_DROID:
if ($3.type != IT_INDEX)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj)
{
yyerror(yyscanner, "Droid id %d not found", (UDWORD)$3.index);
yyerror("Droid id %d not found", (UDWORD)$3.index);
YYABORT;
}
@ -263,14 +261,14 @@ var_init: var_entry TYPE var_value
if (psObj->type != OBJ_DROID)
{
yyerror(yyscanner, "Object id %d is not a droid", (UDWORD)$3.index);
yyerror("Object id %d is not a droid", (UDWORD)$3.index);
YYABORT;
}
else
{
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
}
@ -279,13 +277,13 @@ var_init: var_entry TYPE var_value
case ST_STRUCTURE:
if ($3.type != IT_INDEX)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj)
{
yyerror(yyscanner, "Structure id %d not found", (UDWORD)$3.index);
yyerror("Structure id %d not found", (UDWORD)$3.index);
YYABORT;
}
@ -293,14 +291,14 @@ var_init: var_entry TYPE var_value
if (psObj->type != OBJ_STRUCTURE)
{
yyerror(yyscanner, "Object id %d is not a structure", (UDWORD)$3.index);
yyerror("Object id %d is not a structure", (UDWORD)$3.index);
YYABORT;
}
else
{
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
}
@ -308,13 +306,13 @@ var_init: var_entry TYPE var_value
case ST_FEATURE:
if ($3.type != IT_INDEX)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj)
{
yyerror(yyscanner, "Feature id %d not found", (UDWORD)$3.index);
yyerror("Feature id %d not found", (UDWORD)$3.index);
YYABORT;
}
@ -322,14 +320,14 @@ var_init: var_entry TYPE var_value
if (psObj->type != OBJ_FEATURE)
{
yyerror(yyscanner, "Object id %d is not a feature", (UDWORD)$3.index);
yyerror("Object id %d is not a feature", (UDWORD)$3.index);
YYABORT;
}
else
{
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
}
@ -337,7 +335,7 @@ var_init: var_entry TYPE var_value
case ST_FEATURESTAT:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
@ -345,12 +343,12 @@ var_init: var_entry TYPE var_value
if (data.v.ival == -1)
{
yyerror(yyscanner, "Feature Stat %s not found", $3.pString);
yyerror("Feature Stat %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
@ -359,213 +357,213 @@ var_init: var_entry TYPE var_value
if ($3.type != IT_BOOL ||
!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
break;
case ST_BODY:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_BODY, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "body component %s not found", $3.pString);
yyerror("body component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_PROPULSION:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_PROPULSION, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Propulsion component %s not found", $3.pString);
yyerror("Propulsion component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_ECM:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_ECM, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "ECM component %s not found", $3.pString);
yyerror("ECM component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_SENSOR:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_SENSOR, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Sensor component %s not found", $3.pString);
yyerror("Sensor component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_CONSTRUCT:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_CONSTRUCT, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Construct component %s not found", $3.pString);
yyerror("Construct component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_REPAIR:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_REPAIRUNIT, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Repair component %s not found", $3.pString);
yyerror("Repair component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_BRAIN:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_BRAIN, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Brain component %s not found", $3.pString);
yyerror("Brain component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_WEAPON:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getCompFromResName(COMP_WEAPON, $3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Weapon component %s not found", $3.pString);
yyerror("Weapon component %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_TEMPLATE:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.oval = getTemplateFromTranslatedNameNoPlayer($3.pString); /* store pointer to the template */
if (data.v.oval == NULL)
{
yyerror(yyscanner, "Template %s not found", $3.pString);
yyerror("Template %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_STRUCTURESTAT:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.ival = getStructStatFromName($3.pString);
if (data.v.ival == -1)
{
yyerror(yyscanner, "Structure Stat %s not found", $3.pString);
yyerror("Structure Stat %s not found", $3.pString);
YYABORT;
}
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_STRUCTUREID:
if ($3.type != IT_INDEX)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj)
{
yyerror(yyscanner, "Structure id %d not found", (UDWORD)$3.index);
yyerror("Structure id %d not found", (UDWORD)$3.index);
YYABORT;
}
data.v.ival = $3.index; /* store structure id */
if (psObj->type != OBJ_STRUCTURE)
{
yyerror(yyscanner, "Object id %d is not a structure", (UDWORD)$3.index);
yyerror("Object id %d is not a structure", (UDWORD)$3.index);
YYABORT;
}
else
{
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
}
@ -573,26 +571,26 @@ var_init: var_entry TYPE var_value
case ST_DROIDID:
if ($3.type != IT_INDEX)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj)
{
yyerror(yyscanner, "Droid id %d not found", (UDWORD)$3.index);
yyerror("Droid id %d not found", (UDWORD)$3.index);
YYABORT;
}
data.v.ival = $3.index; /* store id*/
if (psObj->type != OBJ_DROID)
{
yyerror(yyscanner, "Object id %d is not a droid", (UDWORD)$3.index);
yyerror("Object id %d is not a droid", (UDWORD)$3.index);
YYABORT;
}
else
{
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
}
@ -600,36 +598,36 @@ var_init: var_entry TYPE var_value
case ST_INTMESSAGE:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.oval = getViewData($3.pString); /* store pointer to the intelligence message */
if (data.v.oval == NULL)
{
yyerror(yyscanner, "Message %s not found", $3.pString);
yyerror("Message %s not found", $3.pString);
YYABORT;
}
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_TEXTSTRING:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
if (!scrvGetString($3.pString, &pString))
{
yyerror(yyscanner, "String %s not found", $3.pString);
yyerror("String %s not found", $3.pString);
YYABORT;
}
data.v.sval = pString;
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
@ -639,20 +637,20 @@ var_init: var_entry TYPE var_value
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
// just check the level exists
psLevel = levFindDataSet($3.pString);
if (psLevel == NULL)
{
yyerror(yyscanner, "Level %s not found", $3.pString);
yyerror("Level %s not found", $3.pString);
YYABORT;
}
data.v.sval = psLevel->pName; /* store string pointer */
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
}
@ -660,7 +658,7 @@ var_init: var_entry TYPE var_value
case ST_SOUND:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
/* find audio id */
@ -674,30 +672,30 @@ var_init: var_entry TYPE var_value
data.v.ival = compIndex;
if (!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
case ST_RESEARCH:
if ($3.type != IT_STRING)
{
yyerror(yyscanner, "Typemismatch for variable %d", $1);
yyerror("Typemismatch for variable %d", $1);
YYABORT;
}
data.v.oval = getResearch($3.pString, true); /* store pointer */
if (data.v.oval == NULL)
{
yyerror(yyscanner, "Research %s not found", $3.pString);
yyerror("Research %s not found", $3.pString);
YYABORT;
}
if(!eventSetContextVar(psCurrContext, $1, &data))
{
yyerror(yyscanner, "Set Value Failed for %u", $1);
yyerror("Set Value Failed for %u", $1);
YYABORT;
}
break;
default:
yyerror(yyscanner, "Unknown type: %s", asTypeTable[$2].pIdent);
yyerror("Unknown type: %s", asTypeTable[$2].pIdent);
YYABORT;
break;
}
@ -721,7 +719,7 @@ array_index_list: array_index
{
if ($1->dimensions >= VAR_MAX_DIMENSIONS)
{
yyerror(yyscanner, "Too many dimensions for array");
yyerror("Too many dimensions for array");
YYABORT;
}
$1->elements[$1->dimensions] = $3;
@ -738,7 +736,7 @@ var_entry: VAR
{
UDWORD index;
if (!scrvCheckArrayIndex(yyscanner, $1, $2, &index))
if (!scrvCheckArrayIndex($1, $2, &index))
{
YYABORT;
}
@ -837,22 +835,20 @@ BOOL scrvLoad(PHYSFS_file* fileHandle)
{
bool retval;
lexerinput_t input;
yyscan_t scanner;
scrv_lex_init(&scanner);
input.type = LEXINPUT_PHYSFS;
input.input.physfsfile = fileHandle;
scrv_set_extra(&input, scanner);
scrv_set_extra(&input);
retval = (scrv_parse(scanner) == 0);
scrv_lex_destroy(scanner);
retval = (scrv_parse() == 0);
scrv_lex_destroy();
return retval;
}
/* A simple error reporting routine */
void yyerror(yyscan_t yyscanner, const char* fmt, ...)
void yyerror(const char* fmt, ...)
{
char* txtBuf;
size_t size;
@ -869,5 +865,5 @@ void yyerror(yyscan_t yyscanner, const char* fmt, ...)
va_end(args);
debug(LOG_ERROR, "VLO parse error: %s at line %d, text: '%s'",
txtBuf, scrv_get_lineno(yyscanner), scrv_get_text(yyscanner));
txtBuf, scrv_get_lineno(), scrv_get_text());
}