32 #include "../../shared/parse.h"
33 #include "../../shared/shared.h"
44 if (property !=
nullptr)
49 switch (expression->
type) {
53 switch (variable->
type) {
67 const char* path = expression->
d.
terminal.d1.constString;
73 Com_Printf(
"UI_GetNodeFromExpression: Node '%s' wasn't found; nullptr returned\n", path);
76 if (propertyTmp !=
nullptr)
77 Com_Printf(
"UI_GetNodeFromExpression: No property expected, but path '%s' contain a property. Property ignored.\n", path);
87 const char* path = expression->
d.
terminal.d1.constString;
93 Com_Printf(
"UI_GetNodeFromExpression: Node '%s' wasn't found; nullptr returned\n", path);
96 if (property ==
nullptr) {
97 if (propertyTmp !=
nullptr)
98 Com_Printf(
"UI_GetNodeFromExpression: No property expected, but path '%s' contain a property. Property ignored.\n", path);
100 *
property = propertyTmp;
123 switch (expression->
type) {
129 const char* path = expression->
d.
terminal.d2.constString;
132 Com_Printf(
"UI_GetNodeFromExpression: Path '%s' from node '%s' found no node; nullptr returned\n", path,
UI_GetPath(relativeTo));
135 if (property ==
nullptr) {
136 if (propertyTmp !=
nullptr)
137 Com_Printf(
"UI_GetNodeFromExpression: No property expected, but path '%s' from node '%s' found no node; nullptr returned\n", path,
UI_GetPath(relativeTo));
139 *
property = propertyTmp;
162 switch (expression->
type) {
166 switch (variable->
type) {
169 Com_Printf(
"UI_GetFloatFromExpression: String variable not initialized. '0' returned");
178 if (cvar ==
nullptr) {
179 Com_Printf(
"UI_GetFloatFromExpression: Cvar variable not initialized. '0' returned");
185 Com_Printf(
"UI_GetFloatFromExpression: Unsupported variable type: %i. '0' returned", variable->
type);
192 const char*
string = expression->
d.
terminal.d1.constString;
203 const char* cvarName = expression->
d.
terminal.d1.constString;
206 cvar =
Cvar_Get(cvarName,
"", 0,
"Cvar from UI script expression");
216 Com_Printf(
"UI_GetFloatFromParam: Node wasn't found; '0'\n");
220 Com_Printf(
"UI_GetFloatFromParam: Property wasn't found; '0' returned\n");
227 const int paramId = expression->
d.
terminal.d1.integer;
228 const char*
string =
UI_GetParam(context, paramId);
229 if (
string[0] ==
'\0') {
230 Com_Printf(
"UI_GetFloatFromParam: Param '%i' is out of range, or empty; '0' returned\n", paramId);
245 switch (expression->
type) {
247 return value1 + value2;
249 return value1 - value2;
251 return value1 * value2;
254 Com_Printf(
"UI_GetFloatFromExpression: Div by 0. '0' returned");
257 return value1 / value2;
260 const int v1 = value1;
261 const int v2 = value2;
270 switch (expression->
type) {
279 Com_Error(
ERR_FATAL,
"UI_GetFloatFromExpression: (EA_OPERATOR_UNARY) Invalid expression type %i", expression->
type);
284 Com_Printf(
"UI_GetFloatFromExpression: Unsupported expression type: %i. '0' returned", expression->
type);
297 switch (expression->
type) {
301 switch (variable->
type) {
304 Com_Printf(
"UI_GetStringFromExpression: String variable not initialized. Empty string returned");
311 const int integer = number;
313 if (number == integer)
314 return va(
"%i", integer);
316 return va(
"%f", number);
321 if (cvar ==
nullptr) {
322 Com_Printf(
"UI_GetStringFromExpression: Cvar variable not initialized. Empty string returned");
328 Com_Printf(
"UI_GetStringFromExpression: Unsupported variable type: %i. Empty string returned", variable->
type);
335 const char*
string = expression->
d.
terminal.d1.constString;
342 const float number = expression->
d.
terminal.d1.number;
343 const int integer = number;
345 if (number == integer)
346 return va(
"%i", integer);
348 return va(
"%f", number);
354 const char* cvarName = expression->
d.
terminal.d1.constString;
357 cvar =
Cvar_Get(cvarName,
"", 0,
"Cvar from UI script expression");
368 Com_Printf(
"UI_GetStringFromExpression: Node wasn't found; Empty string returned\n");
372 Com_Printf(
"UI_GetStringFromExpression: Property wasn't found; Empty string returned\n");
376 if (
string ==
nullptr) {
391 switch (expression->
type) {
400 Com_Error(
ERR_FATAL,
"UI_GetFloatFromExpression: (EA_OPERATOR_UNARY) Invalid expression type %i", expression->
type);
414 const int integer = number;
416 if (number == integer)
417 return va(
"%i", integer);
419 return va(
"%f", number);
423 Com_Printf(
"UI_GetStringFromExpression: Unsupported expression type: %i", expression->
type);
433 if (expression ==
nullptr)
442 #define VALUE1 UI_GetBooleanFromExpression(expression->d.nonTerminal.left, context)
443 #define VALUE2 UI_GetBooleanFromExpression(expression->d.nonTerminal.right, context)
445 switch (expression->
type) {
455 Com_Error(
ERR_FATAL,
"UI_GetBooleanFromExpression: (BOOL2BOOL) Invalid expression type");
464 switch (expression->
type) {
466 return value1 == value2;
468 return value1 <= value2;
470 return value1 >= value2;
472 return value1 > value2;
474 return value1 < value2;
476 return value1 != value2;
478 Com_Error(
ERR_FATAL,
"UI_GetBooleanFromExpression: (FLOAT2BOOL) Invalid expression type");
483 switch (expression->
type) {
503 return node !=
nullptr;
512 Com_Error(
ERR_FATAL,
"UI_GetBooleanFromExpression: (EA_OPERATOR_UNARY) Invalid expression type %i", expression->
type);
520 switch (expression->
type) {
522 return Q_streq(value1, value2);
524 return !
Q_streq(value1, value2);
526 Com_Error(
ERR_FATAL,
"UI_GetBooleanFromExpression: (STRING2BOOL) Invalid expression type");
542 const char*
text, *base;
545 base =
va(
"( %s )", description);
549 Com_Printf(
"UI_AllocStaticStringCondition: Parse error on expression \"%s\"\n", base);
566 if (*text ==
nullptr) {
567 Com_Printf(
"UI_ParseTerminalExpression: Token expected\n");
586 }
else if (token[5] >=
'1' && token[5] <=
'9') {
588 if (sscanf(token + 5,
"%i", &i) == 1) {
600 if (
char const*
const cvarName =
Q_strstart(token,
"*cvar:")) {
611 if (
char const* path =
Q_strstart(token,
"*")) {
612 const char* propertyName;
617 char const*
const relativeToNode =
Q_strstart(path,
"node:");
619 path = relativeToNode;
625 if (!relativeToNode) {
626 Com_Printf(
"UI_ParseExpression: Old syntax, please prefix '%s' with \"*node:root.\" \n", token);
627 path =
va(
"root.%s", path);
632 propertyName = strchr(path,
'@');
633 if (propertyName ==
nullptr) {
646 if ((token[0] >=
'0' && token[0] <=
'9')
647 || (token[0] ==
'-' && token[1] >=
'0' && token[1] <=
'9')) {
649 float f = atof(token);
667 Com_Error(
ERR_FATAL,
"UI_ParseValueExpression: Token \"%s\" unknown. String must use quotes, cvar and nodes must use prefix.\n", token);
675 if (*text ==
nullptr)
685 if (*text ==
nullptr)
697 Com_Printf(
"UI_ParseExpression: Invalid 'expression' statement. Unknown '%s' operator\n", token);
705 if (*text ==
nullptr)
708 Com_Printf(
"UI_ParseExpression: Token ')' expected\n");
734 Com_Printf(
"UI_ParseExpression: Cvar or Node path expected, but type %d found\n", e->
type);
float UI_GetFloatFromNodeProperty(const uiNode_t *node, const value_t *property)
Return a float from a node property.
bool UI_IsInjectedString(const char *string)
Test if a string use an injection syntax.
uiAction_t * UI_AllocStaticAction(void)
Allocate an action.
struct uiAction_s::@14::@16 terminal
Stores a terminal action (a value, which must be a leaf in the tree)
void UI_ReadNodePath(const char *path, const uiNode_t *relativeNode, const uiNode_t *iterationNode, uiNode_t **resultNode, const value_t **resultProperty, value_t *luaMethod)
Read a path and return every we can use (node and property)
bool UI_GetBooleanFromExpression(uiAction_t *expression, const uiCallContext_t *context)
Check if an expression is true.
QGL_EXTERN GLint GLenum type
uiAction_t * UI_AllocStaticStringCondition(const char *description)
Allocate and initialize an expression according to a string.
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
uiValue_t * UI_GetVariable(const uiCallContext_t *context, int relativeVarId)
Return a variable from the context.
void Com_Printf(const char *const fmt,...)
uiAction_t * UI_ParseExpression(const char **text)
union uiAction_s::@14 d
Stores data about the action.
Internal data use by the UI package.
C interface to allow to access to cpp node code.
void Com_Error(int code, const char *fmt,...)
struct uiAction_s::@14::@15 nonTerminal
Stores a none terminal action (a command or an operator)
int UI_GetActionTokenType(const char *token, int group)
return an action type from a token, and a group
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
const char * UI_GetStringFromExpression(uiAction_t *expression, const uiCallContext_t *context)
#define Q_strncasecmp(s1, s2, n)
uiNode_t * UI_GetNodeFromExpression(uiAction_t *expression, const uiCallContext_t *context, const value_t **property)
Get a node and a property from an expression.
const char * UI_GetPath(const uiNode_t *node)
Return a path from a window to a node.
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
#define Q_strcasecmp(a, b)
Atomic structure used to define most of the UI.
Contain the context of the calling of a function.
int UI_GetParamNumber(const uiCallContext_t *context)
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
const char * UI_GetParam(const uiCallContext_t *context, int paramID)
const char * UI_GenInjectedString(const char *input, bool addNewLine, const uiCallContext_t *context)
Replace injection identifiers (e.g. ) by a value.
float UI_GetFloatFromExpression(uiAction_t *expression, const uiCallContext_t *context)
union uiValue_s::@17 value
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Com_TokenType_t Com_GetType(const char **data_p)
Get the current token type.
Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR) ...
void Com_UnParseLastToken(void)
Put back the last token into the parser The next call of Com_Parse will return the same token again...
const char * UI_Node_GetWidgetName(uiNode_t const *node)
const char * UI_GetStringFromNodeProperty(const uiNode_t *node, const value_t *property)
Return a string from a node property.
QGL_EXTERN int GLboolean GLfloat * v
char * UI_AllocStaticString(const char *string, int size)
Allocate a string into the UI static memory.
cvar_t * Cvar_FindVar(const char *varName)
Searches for a cvar given by parameter.
short type
Define the type of the element, it can be a command, an operator, or a value.
Atomic element to store UI scripts The parser use this atom to translate script action into many tree...
static uiAction_t * UI_ParseValueExpression(const char **text)
Read a value from the stream and init an action with it.