UFO: Alien Invasion
|
Handles definition of entities, parsing them from entities.ufo. More...
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <math.h>
#include "shared.h"
#include "parse.h"
#include "entitiesdef.h"
Go to the source code of this file.
Macros | |
#define | ED_MAX_KEYS_PER_ENT 32 |
#define | ED_MAX_TOKEN_LEN 512 |
#define | ED_MAX_ERR_LEN 512 |
#define | ED_RETURN_ERROR(...) |
write an error message and exit the current function returning ED_ERROR More... | |
#define | ED_TEST_RETURN_ERROR(condition,...) |
test a condition, write an error message and exit the current function with ED_ERROR More... | |
#define | ED_PASS_ERROR(function_call) |
if the function returns ED_ERROR, then the function that the macro is in also returns ED_ERROR. Note that the called function is expected to set lastErr, probably by using the ED_TEST_RETURN_ERROR macro More... | |
#define | ED_PASS_ERROR_EXTRAMSG(function_call,...) |
if the function returns ED_ERROR, then the function that the macro is in also returns ED_ERROR. Note that the called function is expected to set lastErr, probably by using the ED_TEST_RETURN_ERROR macro. this macro then appends extra detail to the message to give context More... | |
Functions | |
static int | ED_AllocEntityDef (entityKeyDef_t *newKeyDefs, int numKeyDefs, int entityIndex) |
allocate space for key defs etc, pointers for which are stored in the entityDef_t More... | |
static entityKeyDef_t * | ED_FindKeyDefInArray (entityKeyDef_t keyDefs[], int numDefs, const char *name, int parseMode) |
search for an existing keyDef to add a new parsed pair info to. More... | |
static int | ED_Type2Constant (const char *strType) |
converts a string representation of a type (eg V_FLOAT) to the appropriate internal constant integer More... | |
static const char * | ED_Constant2Type (int constInt) |
converts an internal constant integer to a string representation of a type (eg V_FLOAT) More... | |
static int | ED_GetIntVectorFromString (const char *str, int v[], const int n) |
parses an int array from a string More... | |
int | ED_GetIntVector (const entityKeyDef_t *kd, int v[], const int n) |
parses a value from the definition More... | |
static int | ED_CheckNumber (const char *value, const int floatOrInt, const int insistPositive, int_float_tu *parsedNumber) |
checks that a string represents a single number More... | |
static int | ED_CheckRange (const entityKeyDef_t *keyDef, const int type, const int index, int_float_tu parsedNumber) |
check a value against the range for the key More... | |
static int | ED_CheckNumericType (const entityKeyDef_t *keyDef, const char *value, const int type) |
tests if a value string matches the type for this key. this includes each element of a numeric array. Also checks value against range def, if one exists. More... | |
int | ED_Check (const char *classname, const char *key, const char *value) |
tests if a value string matches the type for this key. Also checks the value against the range, if one was defined. More... | |
int | ED_CheckKey (const entityKeyDef_t *kd, const char *value) |
as ED_Check, but where the entity and key are known, so takes different arguments. More... | |
static int | ED_ParseType (entityKeyDef_t *kd, const char *parsedToken) |
takes a type string (eg "V_FLOAT 6") and configures entity def More... | |
static int | ED_Block2Constant (const char *blockName) |
converts a block name (eg "optional") to an constant (eg ED_OPTIONAL). More... | |
static const char * | ED_Constant2Block (int constInt) |
converts an internal constant integer to a string representation of a type (eg V_FLOAT) More... | |
static int | ED_AllocRange (entityKeyDef_t *kd, const char *rangeStr) |
static int | ED_PairParsed (entityKeyDef_t keyDefsBuf[], int *numKeyDefsSoFar_p, const char *newName, const char *newVal, const int mode) |
static int | ED_ParseEntities (const char **data_p) |
static int | ED_CheckDefaultTypes (void) |
checks if the default block entries meet the type and range definitions. More... | |
static int | ED_ProcessRanges (void) |
finish parsing ranges. Could not be done earlier as would not have necessarily known types and defaults. parses values in ranges into ints or floats and tests ranges against types and defaults against ranges. More... | |
int | ED_Parse (const char *data_p) |
const char * | ED_GetLastError (void) |
const entityKeyDef_t * | ED_GetKeyDef (const char *classname, const char *keyname, const int abstract) |
searches for the parsed key def More... | |
const entityKeyDef_t * | ED_GetKeyDefEntity (const entityDef_t *ed, const char *keyname, const int abstract) |
searches for the parsed key def, when the entity def is known More... | |
const entityDef_t * | ED_GetEntityDef (const char *classname) |
searches for the parsed entity def by classname More... | |
void | ED_Free (void) |
Variables | |
static char | lastErr [ED_MAX_ERR_LEN] |
static char | lastErrExtra [ED_MAX_ERR_LEN] |
int | numEntityDefs |
entityDef_t | entityDefs [ED_MAX_DEFS+1] |
Handles definition of entities, parsing them from entities.ufo.
Definition in file entitiesdef.cpp.
#define ED_MAX_ERR_LEN 512 |
Definition at line 40 of file entitiesdef.cpp.
#define ED_MAX_KEYS_PER_ENT 32 |
Definition at line 38 of file entitiesdef.cpp.
Referenced by ED_PairParsed(), and ED_ParseEntities().
#define ED_MAX_TOKEN_LEN 512 |
Definition at line 39 of file entitiesdef.cpp.
Referenced by ED_ParseEntities().
#define ED_PASS_ERROR | ( | function_call | ) |
if the function returns ED_ERROR, then the function that the macro is in also returns ED_ERROR. Note that the called function is expected to set lastErr, probably by using the ED_TEST_RETURN_ERROR macro
Definition at line 73 of file entitiesdef.cpp.
Referenced by ED_CheckNumericType(), ED_GetIntVector(), ED_PairParsed(), ED_Parse(), ED_ParseEntities(), ED_ParseType(), and ED_ProcessRanges().
#define ED_PASS_ERROR_EXTRAMSG | ( | function_call, | |
... | |||
) |
if the function returns ED_ERROR, then the function that the macro is in also returns ED_ERROR. Note that the called function is expected to set lastErr, probably by using the ED_TEST_RETURN_ERROR macro. this macro then appends extra detail to the message to give context
Definition at line 84 of file entitiesdef.cpp.
Referenced by ED_CheckDefaultTypes(), and ED_CheckNumericType().
#define ED_RETURN_ERROR | ( | ... | ) |
write an error message and exit the current function returning ED_ERROR
Definition at line 52 of file entitiesdef.cpp.
Referenced by ED_AllocRange(), ED_Block2Constant(), ED_CheckKey(), ED_CheckNumber(), ED_CheckRange(), ED_PairParsed(), ED_ParseEntities(), ED_ProcessRanges(), and ED_Type2Constant().
#define ED_TEST_RETURN_ERROR | ( | condition, | |
... | |||
) |
test a condition, write an error message and exit the current function with ED_ERROR
Definition at line 62 of file entitiesdef.cpp.
Referenced by ED_AllocEntityDef(), ED_CheckKey(), ED_CheckNumber(), ED_CheckNumericType(), ED_CheckRange(), ED_GetIntVectorFromString(), ED_PairParsed(), ED_Parse(), ED_ParseEntities(), ED_ParseType(), and ED_ProcessRanges().
|
static |
allocate space for key defs etc, pointers for which are stored in the entityDef_t
Definition at line 95 of file entitiesdef.cpp.
References entityDef_s::classname, entityKeyDef_s::desc, ED_OK, ED_TEST_RETURN_ERROR, entityDef_s::keyDefs, entityDef_s::numKeyDefs, and OBJZERO.
Referenced by ED_ParseEntities().
|
static |
Definition at line 486 of file entitiesdef.cpp.
References ED_OK, ED_RETURN_ERROR, entityKeyDef_s::numRanges, OBJZERO, entityKeyDef_s::ranges, and entityKeyRange_s::str.
Referenced by ED_PairParsed().
|
static |
converts a block name (eg "optional") to an constant (eg ED_OPTIONAL).
Definition at line 442 of file entitiesdef.cpp.
References ED_ABSTRACT, ED_DEFAULT, ED_MANDATORY, ED_MODE_TYPE, ED_OPTIONAL, ED_RANGE, ED_RETURN_ERROR, and Q_streq.
Referenced by ED_ParseEntities().
int ED_Check | ( | const char * | classname, |
const char * | key, | ||
const char * | value | ||
) |
tests if a value string matches the type for this key. Also checks the value against the range, if one was defined.
Definition at line 357 of file entitiesdef.cpp.
References ED_CheckKey(), ED_ERROR, and ED_GetKeyDef().
checks if the default block entries meet the type and range definitions.
Definition at line 649 of file entitiesdef.cpp.
References entityKeyDef_s::defaultVal, ED_CheckKey(), ED_OK, ED_PASS_ERROR_EXTRAMSG, entityDef_s::keyDefs, entityKeyDef_s::name, and entityDef_s::numKeyDefs.
Referenced by ED_Parse().
int ED_CheckKey | ( | const entityKeyDef_t * | kd, |
const char * | value | ||
) |
as ED_Check, but where the entity and key are known, so takes different arguments.
Definition at line 372 of file entitiesdef.cpp.
References ED_CheckNumericType(), ED_KEY_TYPE, ED_OK, ED_RETURN_ERROR, ED_TEST_RETURN_ERROR, ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, ED_TYPE_STRING, and entityKeyDef_s::flags.
Referenced by CheckEntities(), ED_Check(), and ED_CheckDefaultTypes().
|
static |
checks that a string represents a single number
value | The string to parse from |
floatOrInt | one of ED_TYPE_FLOAT or ED_TYPE_INT |
insistPositive | if 1, then tests for the number being greater than or equal to zero. |
parsedNumber | The result as a union |
Definition at line 226 of file entitiesdef.cpp.
References ED_Constant2Type(), ED_OK, ED_RETURN_ERROR, ED_TEST_RETURN_ERROR, ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, int_float_u::f, int_float_u::i, and int().
Referenced by ED_CheckNumericType(), ED_ParseType(), and ED_ProcessRanges().
|
static |
tests if a value string matches the type for this key. this includes each element of a numeric array. Also checks value against range def, if one exists.
keyDef | The descriptor of the key/value pair |
value | The string to parse from |
type | one of ED_TYPE_FLOAT, ED_TYPE_INT or ED_TYPE_BOOL |
Definition at line 321 of file entitiesdef.cpp.
References Com_Parse(), ED_CheckNumber(), ED_CheckRange(), ED_INSIST_POSITIVE, ED_OK, ED_PASS_ERROR, ED_PASS_ERROR_EXTRAMSG, ED_TEST_RETURN_ERROR, ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, entityKeyDef_s::flags, i, entityKeyDef_s::name, and entityKeyDef_s::vLen.
Referenced by ED_CheckKey().
|
static |
check a value against the range for the key
keyDef | The descriptor of the key/value pair |
type | either ED_TYPE_FLOAT, ED_TYPE_INT or ED_TYPE_BOOL |
index | the index of the number being checked in the value. eg angles "90 180", 90 is at 0, 180 is at 1. |
parsedNumber | The value to check |
Definition at line 269 of file entitiesdef.cpp.
References entityKeyRange_s::continuous, ED_OK, ED_RETURN_ERROR, ED_TEST_RETURN_ERROR, ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, int_float_u::f, entityKeyRange_s::fArr, int_float_u::i, entityKeyRange_s::iArr, entityKeyDef_s::name, entityKeyRange_s::numElements, entityKeyDef_s::numRanges, entityKeyDef_s::ranges, and entityKeyRange_s::str.
Referenced by ED_CheckNumericType().
|
static |
converts an internal constant integer to a string representation of a type (eg V_FLOAT)
Definition at line 465 of file entitiesdef.cpp.
References ED_ABSTRACT, ED_DEFAULT, ED_MANDATORY, ED_MODE_TYPE, ED_OPTIONAL, ED_RANGE, and lastErr.
Referenced by ED_PairParsed().
|
static |
converts an internal constant integer to a string representation of a type (eg V_FLOAT)
Definition at line 157 of file entitiesdef.cpp.
References ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, ED_TYPE_STRING, and lastErr.
Referenced by ED_CheckNumber().
|
static |
search for an existing keyDef to add a new parsed pair info to.
Definition at line 121 of file entitiesdef.cpp.
References ED_ABSTRACT, entityKeyDef_s::flags, i, entityKeyDef_s::name, and Q_streq.
Referenced by ED_PairParsed().
Definition at line 827 of file entitiesdef.cpp.
References entityKeyRange_s::fArr, i, entityKeyRange_s::iArr, entityKeyDef_s::name, numEntityDefs, entityDef_s::numKeyDefs, and entityKeyRange_s::str.
Referenced by Check_Free(), and TEST_F().
const entityDef_t* ED_GetEntityDef | ( | const char * | classname | ) |
searches for the parsed entity def by classname
Definition at line 815 of file entitiesdef.cpp.
References entityDef_s::classname, lastErr, entityDef_s::numKeyDefs, and Q_streq.
Referenced by CheckEntities(), ED_GetKeyDef(), and ED_ParseEntities().
int ED_GetIntVector | ( | const entityKeyDef_t * | kd, |
int | v[], | ||
const int | n | ||
) |
parses a value from the definition
kd | the key definition to parse from | |
[out] | v | the array of int to put the answer in it must have enough space for n elements. |
n | the number of elements expected in the vector |
Definition at line 208 of file entitiesdef.cpp.
References entityKeyDef_s::desc, ED_GetIntVectorFromString(), ED_OK, and ED_PASS_ERROR.
Referenced by Check_InfoStartAligned().
parses an int array from a string
str | the string to parse | |
[out] | v | the array of int to put the answer in it must have enough space for n elements. |
n | the number of elements expected in the vector |
Definition at line 183 of file entitiesdef.cpp.
References Com_Parse(), ED_OK, ED_TEST_RETURN_ERROR, and i.
Referenced by ED_GetIntVector().
const entityKeyDef_t* ED_GetKeyDef | ( | const char * | classname, |
const char * | keyname, | ||
const int | abstract | ||
) |
searches for the parsed key def
classname | The name, eg. "func_door" |
keyname | The key we are looking for |
abstract | send abstract to find an abstract key with this name |
Definition at line 775 of file entitiesdef.cpp.
References ED_GetEntityDef(), and ED_GetKeyDefEntity().
Referenced by ED_Check().
const entityKeyDef_t* ED_GetKeyDefEntity | ( | const entityDef_t * | ed, |
const char * | keyname, | ||
const int | abstract | ||
) |
searches for the parsed key def, when the entity def is known
ed | The list of keys for the entity |
keyname | The key we are looking for |
abstract | send a nonzero value if the abstract (radiant - not in any block) version of the key is required |
Definition at line 789 of file entitiesdef.cpp.
References entityDef_s::classname, ED_ABSTRACT, entityKeyDef_s::flags, entityDef_s::keyDefs, lastErr, entityKeyDef_s::name, and Q_streq.
Referenced by Check_InfoStartAligned(), CheckEntities(), and ED_GetKeyDef().
const char* ED_GetLastError | ( | void | ) |
Definition at line 763 of file entitiesdef.cpp.
References lastErr.
Referenced by Check_InfoStartAligned(), Check_InitEntityDefs(), and CheckEntities().
|
static |
Definition at line 515 of file entitiesdef.cpp.
References entityKeyDef_s::defaultVal, entityKeyDef_s::desc, ED_ABSTRACT, ED_AllocRange(), ED_Constant2Block(), ED_DEFAULT, ED_FindKeyDefInArray(), ED_MANDATORY, ED_MAX_KEYS_PER_ENT, ED_MODE_TYPE, ED_OK, ED_OPTIONAL, ED_ParseType(), ED_PASS_ERROR, ED_RANGE, ED_RETURN_ERROR, ED_TEST_RETURN_ERROR, entityKeyDef_s::flags, and entityKeyDef_s::name.
Referenced by ED_ParseEntities().
int ED_Parse | ( | const char * | data_p | ) |
parses entity definitions from entities.ufo
Definition at line 738 of file entitiesdef.cpp.
References ED_CheckDefaultTypes(), ED_OK, ED_ParseEntities(), ED_PASS_ERROR, ED_ProcessRanges(), ED_TEST_RETURN_ERROR, lastErr, numEntityDefs, and OBJZERO.
Referenced by Check_InitEntityDefs(), and TEST_F().
|
static |
Definition at line 565 of file entitiesdef.cpp.
References Com_Parse(), ED_ABSTRACT, ED_AllocEntityDef(), ED_Block2Constant(), ED_ERROR, ED_GetEntityDef(), ED_MANDATORY, ED_MAX_DEFS, ED_MAX_KEYS_PER_ENT, ED_MAX_TOKEN_LEN, ED_OK, ED_PairParsed(), ED_PASS_ERROR, ED_RETURN_ERROR, ED_TEST_RETURN_ERROR, numEntityDefs, OBJZERO, parsedToken, and Q_streq.
Referenced by ED_Parse().
|
static |
takes a type string (eg "V_FLOAT 6") and configures entity def
Definition at line 394 of file entitiesdef.cpp.
References Com_Parse(), ED_CheckNumber(), ED_ERROR, ED_INSIST_POSITIVE, ED_OK, ED_PASS_ERROR, ED_TEST_RETURN_ERROR, ED_Type2Constant(), ED_TYPE_INT, ED_TYPE_STRING, entityKeyDef_s::flags, entityKeyDef_s::name, Q_streq, type, and entityKeyDef_s::vLen.
Referenced by ED_PairParsed().
finish parsing ranges. Could not be done earlier as would not have necessarily known types and defaults. parses values in ranges into ints or floats and tests ranges against types and defaults against ranges.
Definition at line 668 of file entitiesdef.cpp.
References Com_Parse(), entityKeyRange_s::continuous, ED_CheckNumber(), ED_INSIST_POSITIVE, ED_KEY_TYPE, ED_OK, ED_PASS_ERROR, ED_RETURN_ERROR, ED_TEST_RETURN_ERROR, ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, ED_TYPE_STRING, entityKeyRange_s::fArr, i, entityKeyRange_s::iArr, int(), entityKeyDef_s::name, entityKeyRange_s::numElements, entityDef_s::numKeyDefs, Q_streq, and entityKeyRange_s::str.
Referenced by ED_Parse().
|
static |
converts a string representation of a type (eg V_FLOAT) to the appropriate internal constant integer
Definition at line 138 of file entitiesdef.cpp.
References ED_RETURN_ERROR, ED_TYPE_BOOL, ED_TYPE_FLOAT, ED_TYPE_INT, ED_TYPE_STRING, and Q_streq.
Referenced by ED_ParseType().
entityDef_t entityDefs[ED_MAX_DEFS+1] |
Definition at line 46 of file entitiesdef.cpp.
Referenced by Check_Stats(), and TEST_F().
|
static |
for storing last error message
Definition at line 42 of file entitiesdef.cpp.
Referenced by ED_Constant2Block(), ED_Constant2Type(), ED_GetEntityDef(), ED_GetKeyDefEntity(), ED_GetLastError(), and ED_Parse().
|
static |
temporary storage for extra information to be added to lastErr
Definition at line 43 of file entitiesdef.cpp.
int numEntityDefs |
Definition at line 45 of file entitiesdef.cpp.
Referenced by Check_InitEntityDefs(), Check_Stats(), ED_Free(), ED_Parse(), ED_ParseEntities(), and TEST_F().