* Use the yyerror macro as provided by Bison instead of scrv_error (yyerror maps to the latter)

* Perform dynamic stack allocation instead of allocating 1kB in scrv_error


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5001 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-05-09 22:24:44 +00:00
parent b51af0be98
commit a4078601ea
1 changed files with 94 additions and 88 deletions

View File

@ -64,13 +64,13 @@ static BOOL scrvCheckArrayIndex(SDWORD base, ARRAY_INDEXES *psIndexes, UDWORD *p
if (base < 0 || base >= psCurrScript->numArrays) if (base < 0 || base >= psCurrScript->numArrays)
{ {
scrv_error("Array index out of range"); yyerror("Array index out of range");
return false; return false;
} }
if (psIndexes->dimensions != psCurrScript->psArrayInfo[base].dimensions) if (psIndexes->dimensions != psCurrScript->psArrayInfo[base].dimensions)
{ {
scrv_error("Invalid number of dimensions for array initialiser"); yyerror("Invalid number of dimensions for array initialiser");
return false; return false;
} }
@ -79,7 +79,7 @@ static BOOL scrvCheckArrayIndex(SDWORD base, ARRAY_INDEXES *psIndexes, UDWORD *p
if ((psIndexes->elements[i] < 0) || if ((psIndexes->elements[i] < 0) ||
(psIndexes->elements[i] >= psCurrScript->psArrayInfo[base].elements[i])) (psIndexes->elements[i] >= psCurrScript->psArrayInfo[base].elements[i]))
{ {
scrv_error("Invalid index for dimension %d", i); yyerror("Invalid index for dimension %d", i);
return false; return false;
} }
} }
@ -142,12 +142,12 @@ script_entry: script_name RUN
{ {
if (!eventNewContext(psCurrScript, CR_RELEASE, &psCurrContext)) if (!eventNewContext(psCurrScript, CR_RELEASE, &psCurrContext))
{ {
scrv_error("Couldn't create context"); yyerror("Couldn't create context");
YYABORT; YYABORT;
} }
if (!scrvAddContext($1, psCurrContext, SCRV_EXEC)) if (!scrvAddContext($1, psCurrContext, SCRV_EXEC))
{ {
scrv_error("Couldn't store context"); yyerror("Couldn't store context");
YYABORT; YYABORT;
} }
} }
@ -162,12 +162,12 @@ script_entry: script_name RUN
{ {
if (!eventNewContext(psCurrScript, CR_NORELEASE, &psCurrContext)) if (!eventNewContext(psCurrScript, CR_NORELEASE, &psCurrContext))
{ {
scrv_error("Couldn't create context"); yyerror("Couldn't create context");
YYABORT; YYABORT;
} }
if (!scrvAddContext($3, psCurrContext, SCRV_NOEXEC)) if (!scrvAddContext($3, psCurrContext, SCRV_NOEXEC))
{ {
scrv_error("Couldn't store context"); yyerror("Couldn't store context");
YYABORT; YYABORT;
} }
} }
@ -207,7 +207,7 @@ script_name: SCRIPT QTEXT
if (!psCurrScript) if (!psCurrScript)
{ {
scrv_error("Script file %s not found", stringname); yyerror("Script file %s not found", stringname);
YYABORT; YYABORT;
} }
@ -237,20 +237,20 @@ var_init: var_entry TYPE var_value
if ($3.type != IT_INDEX || if ($3.type != IT_INDEX ||
!eventSetContextVar(psCurrContext, $1, &data)) !eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_DROID: case ST_DROID:
if ($3.type != IT_INDEX) if ($3.type != IT_INDEX)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
psObj = getBaseObjFromId((UDWORD)$3.index); psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj) if (!psObj)
{ {
scrv_error("Droid id %d not found", (UDWORD)$3.index); yyerror("Droid id %d not found", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
@ -258,14 +258,14 @@ var_init: var_entry TYPE var_value
if (psObj->type != OBJ_DROID) if (psObj->type != OBJ_DROID)
{ {
scrv_error("Object id %d is not a droid", (UDWORD)$3.index); yyerror("Object id %d is not a droid", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
else else
{ {
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
} }
@ -274,13 +274,13 @@ var_init: var_entry TYPE var_value
case ST_STRUCTURE: case ST_STRUCTURE:
if ($3.type != IT_INDEX) if ($3.type != IT_INDEX)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
psObj = getBaseObjFromId((UDWORD)$3.index); psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj) if (!psObj)
{ {
scrv_error("Structure id %d not found", (UDWORD)$3.index); yyerror("Structure id %d not found", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
@ -288,14 +288,14 @@ var_init: var_entry TYPE var_value
if (psObj->type != OBJ_STRUCTURE) if (psObj->type != OBJ_STRUCTURE)
{ {
scrv_error("Object id %d is not a structure", (UDWORD)$3.index); yyerror("Object id %d is not a structure", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
else else
{ {
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
} }
@ -303,13 +303,13 @@ var_init: var_entry TYPE var_value
case ST_FEATURE: case ST_FEATURE:
if ($3.type != IT_INDEX) if ($3.type != IT_INDEX)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
psObj = getBaseObjFromId((UDWORD)$3.index); psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj) if (!psObj)
{ {
scrv_error("Feature id %d not found", (UDWORD)$3.index); yyerror("Feature id %d not found", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
@ -317,14 +317,14 @@ var_init: var_entry TYPE var_value
if (psObj->type != OBJ_FEATURE) if (psObj->type != OBJ_FEATURE)
{ {
scrv_error("Object id %d is not a feature", (UDWORD)$3.index); yyerror("Object id %d is not a feature", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
else else
{ {
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
} }
@ -332,7 +332,7 @@ var_init: var_entry TYPE var_value
case ST_FEATURESTAT: case ST_FEATURESTAT:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
@ -340,12 +340,12 @@ var_init: var_entry TYPE var_value
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Feature Stat %s not found", $3.pString); yyerror("Feature Stat %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
@ -354,213 +354,213 @@ var_init: var_entry TYPE var_value
if ($3.type != IT_BOOL || if ($3.type != IT_BOOL ||
!eventSetContextVar(psCurrContext, $1, &data)) !eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_BODY: case ST_BODY:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_BODY, $3.pString); data.v.ival = getCompFromResName(COMP_BODY, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("body component %s not found", $3.pString); yyerror("body component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_PROPULSION: case ST_PROPULSION:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_PROPULSION, $3.pString); data.v.ival = getCompFromResName(COMP_PROPULSION, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Propulsion component %s not found", $3.pString); yyerror("Propulsion component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_ECM: case ST_ECM:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_ECM, $3.pString); data.v.ival = getCompFromResName(COMP_ECM, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("ECM component %s not found", $3.pString); yyerror("ECM component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_SENSOR: case ST_SENSOR:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_SENSOR, $3.pString); data.v.ival = getCompFromResName(COMP_SENSOR, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Sensor component %s not found", $3.pString); yyerror("Sensor component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_CONSTRUCT: case ST_CONSTRUCT:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_CONSTRUCT, $3.pString); data.v.ival = getCompFromResName(COMP_CONSTRUCT, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Construct component %s not found", $3.pString); yyerror("Construct component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_REPAIR: case ST_REPAIR:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_REPAIRUNIT, $3.pString); data.v.ival = getCompFromResName(COMP_REPAIRUNIT, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Repair component %s not found", $3.pString); yyerror("Repair component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_BRAIN: case ST_BRAIN:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_BRAIN, $3.pString); data.v.ival = getCompFromResName(COMP_BRAIN, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Brain component %s not found", $3.pString); yyerror("Brain component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_WEAPON: case ST_WEAPON:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getCompFromResName(COMP_WEAPON, $3.pString); data.v.ival = getCompFromResName(COMP_WEAPON, $3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Weapon component %s not found", $3.pString); yyerror("Weapon component %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_TEMPLATE: case ST_TEMPLATE:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.oval = getTemplateFromTranslatedNameNoPlayer($3.pString); /* store pointer to the template */ data.v.oval = getTemplateFromTranslatedNameNoPlayer($3.pString); /* store pointer to the template */
if (data.v.oval == NULL) if (data.v.oval == NULL)
{ {
scrv_error("Template %s not found", $3.pString); yyerror("Template %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_STRUCTURESTAT: case ST_STRUCTURESTAT:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.ival = getStructStatFromName($3.pString); data.v.ival = getStructStatFromName($3.pString);
if (data.v.ival == -1) if (data.v.ival == -1)
{ {
scrv_error("Structure Stat %s not found", $3.pString); yyerror("Structure Stat %s not found", $3.pString);
YYABORT; YYABORT;
} }
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_STRUCTUREID: case ST_STRUCTUREID:
if ($3.type != IT_INDEX) if ($3.type != IT_INDEX)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
psObj = getBaseObjFromId((UDWORD)$3.index); psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj) if (!psObj)
{ {
scrv_error("Structure id %d not found", (UDWORD)$3.index); yyerror("Structure id %d not found", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
data.v.ival = $3.index; /* store structure id */ data.v.ival = $3.index; /* store structure id */
if (psObj->type != OBJ_STRUCTURE) if (psObj->type != OBJ_STRUCTURE)
{ {
scrv_error("Object id %d is not a structure", (UDWORD)$3.index); yyerror("Object id %d is not a structure", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
else else
{ {
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
} }
@ -568,26 +568,26 @@ var_init: var_entry TYPE var_value
case ST_DROIDID: case ST_DROIDID:
if ($3.type != IT_INDEX) if ($3.type != IT_INDEX)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
psObj = getBaseObjFromId((UDWORD)$3.index); psObj = getBaseObjFromId((UDWORD)$3.index);
if (!psObj) if (!psObj)
{ {
scrv_error("Droid id %d not found", (UDWORD)$3.index); yyerror("Droid id %d not found", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
data.v.ival = $3.index; /* store id*/ data.v.ival = $3.index; /* store id*/
if (psObj->type != OBJ_DROID) if (psObj->type != OBJ_DROID)
{ {
scrv_error("Object id %d is not a droid", (UDWORD)$3.index); yyerror("Object id %d is not a droid", (UDWORD)$3.index);
YYABORT; YYABORT;
} }
else else
{ {
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
} }
@ -595,36 +595,36 @@ var_init: var_entry TYPE var_value
case ST_INTMESSAGE: case ST_INTMESSAGE:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.oval = getViewData($3.pString); /* store pointer to the intelligence message */ data.v.oval = getViewData($3.pString); /* store pointer to the intelligence message */
if (data.v.oval == NULL) if (data.v.oval == NULL)
{ {
scrv_error("Message %s not found", $3.pString); yyerror("Message %s not found", $3.pString);
YYABORT; YYABORT;
} }
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_TEXTSTRING: case ST_TEXTSTRING:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
if (!scrvGetString($3.pString, &pString)) if (!scrvGetString($3.pString, &pString))
{ {
scrv_error("String %s not found", $3.pString); yyerror("String %s not found", $3.pString);
YYABORT; YYABORT;
} }
data.v.sval = pString; data.v.sval = pString;
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
@ -634,20 +634,20 @@ var_init: var_entry TYPE var_value
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
// just check the level exists // just check the level exists
psLevel = levFindDataSet($3.pString); psLevel = levFindDataSet($3.pString);
if (psLevel == NULL) if (psLevel == NULL)
{ {
scrv_error("Level %s not found", $3.pString); yyerror("Level %s not found", $3.pString);
YYABORT; YYABORT;
} }
data.v.sval = psLevel->pName; /* store string pointer */ data.v.sval = psLevel->pName; /* store string pointer */
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
} }
@ -655,7 +655,7 @@ var_init: var_entry TYPE var_value
case ST_SOUND: case ST_SOUND:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
/* find audio id */ /* find audio id */
@ -669,30 +669,30 @@ var_init: var_entry TYPE var_value
data.v.ival = compIndex; data.v.ival = compIndex;
if (!eventSetContextVar(psCurrContext, $1, &data)) if (!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
case ST_RESEARCH: case ST_RESEARCH:
if ($3.type != IT_STRING) if ($3.type != IT_STRING)
{ {
scrv_error("Typemismatch for variable %d", $1); yyerror("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.oval = getResearch($3.pString, true); /* store pointer */ data.v.oval = getResearch($3.pString, true); /* store pointer */
if (data.v.oval == NULL) if (data.v.oval == NULL)
{ {
scrv_error("Research %s not found", $3.pString); yyerror("Research %s not found", $3.pString);
YYABORT; YYABORT;
} }
if(!eventSetContextVar(psCurrContext, $1, &data)) if(!eventSetContextVar(psCurrContext, $1, &data))
{ {
scrv_error("Set Value Failed for %s", $1); yyerror("Set Value Failed for %s", $1);
YYABORT; YYABORT;
} }
break; break;
default: default:
scrv_error("Unknown type: %s", asTypeTable[$2].pIdent); yyerror("Unknown type: %s", asTypeTable[$2].pIdent);
YYABORT; YYABORT;
break; break;
} }
@ -716,7 +716,7 @@ array_index_list: array_index
{ {
if ($1->dimensions >= VAR_MAX_DIMENSIONS) if ($1->dimensions >= VAR_MAX_DIMENSIONS)
{ {
scrv_error("Too many dimensions for array"); yyerror("Too many dimensions for array");
YYABORT; YYABORT;
} }
$1->elements[$1->dimensions] = $3; $1->elements[$1->dimensions] = $3;
@ -843,19 +843,25 @@ BOOL scrvLoad(PHYSFS_file* fileHandle)
} }
/* A simple error reporting routine */ /* A simple error reporting routine */
void scrv_error(const char *pMessage,...) void yyerror(const char* fmt, ...)
{ {
int line; int line;
char *pText; char *pText;
char aTxtBuf[1024]; char* txtBuf;
size_t size;
va_list args; va_list args;
va_start(args, pMessage); va_start(args, fmt);
size = vsnprintf(NULL, 0, fmt, args);
va_end(args);
txtBuf = alloca(size + 1);
va_start(args, fmt);
vsprintf(txtBuf, fmt, args);
va_end(args);
vsprintf(aTxtBuf, pMessage, args);
scrvGetErrorData(&line, &pText); scrvGetErrorData(&line, &pText);
debug(LOG_ERROR, "VLO parse error: %s at line %d, token: %d, text: '%s'", debug(LOG_ERROR, "VLO parse error: %s at line %d, token: %d, text: '%s'",
aTxtBuf, line, scrv_char, pText); txtBuf, line, scrv_char, pText);
va_end(args);
} }