/** * @sa Com_MacroExpandString * @todo we should review this code, '*' doesn't work very well for all the needed things */ const char *UI_GetReferenceString (const uiNode_t* const node, const char *ref) { if (!ref) return nullptr; /* its a cvar */ if (ref[0] != '*') return CL_Translate(ref); /* get the reference and the name */ const char *token = Com_MacroExpandString(ref); if (token) return CL_Translate(token); /* skip the star */ token = ref + 1; if (token[0] == '\0') return nullptr; if (char const* const binding = Q_strstart(token, "binding:")) { return Key_GetBinding(binding, cls.state != ca_active ? KEYSPACE_UI : KEYSPACE_GAME); } Sys_Error("UI_GetReferenceString: unknown reference %s", token); }
/** * @brief Parses the given string into command line tokens. * @note @c cmd_argv and @c cmd_argv are filled and set here * @note *cvars will be expanded unless they are in a quoted token * @sa Com_MacroExpandString * @param[in] text The text to parse and tokenize * @param[in] macroExpand expand cvar string with their values */ void Cmd_TokenizeString (const char *text, qboolean macroExpand) { const char *com_token, *expanded; Cmd_BufClear(); /* macro expand the text */ if (macroExpand) { expanded = Com_MacroExpandString(text); if (expanded) text = expanded; } while (1) { /* skip whitespace up to a newline */ while (*text && *text <= ' ' && *text != '\n') { text++; } if (*text == '\n') { /* a newline seperates commands in the buffer */ text++; break; } if (!*text) return; /* set cmd_args to everything after the first arg */ if (cmd_argc == 1) { Q_strncpyz(cmd_args, text, sizeof(cmd_args)); Com_Chop(cmd_args); } com_token = Com_Parse(&text); if (!text) return; if (cmd_argc < MAX_STRING_TOKENS) { /* check first char of string if it is a variable */ if (com_token[0] == '*') { com_token++; com_token = Cvar_GetString(com_token); } assert(!cmd_argv[cmd_argc]); cmd_argv[cmd_argc] = Mem_PoolStrDup(com_token, com_cmdSysPool, 0); cmd_argc++; } } }
/** * @sa Com_MacroExpandString * @todo we should review this code, '*' doesn't work very well for all the needed things */ const char* UI_GetReferenceString (const uiNode_t* const node, const char* ref) { if (!ref) return nullptr; /* its a cvar */ if (ref[0] != '*') return CL_Translate(ref); /* get the reference and the name */ const char* token = Com_MacroExpandString(ref); if (token) return CL_Translate(token); /* skip the star */ token = ref + 1; if (token[0] == '\0') return nullptr; Sys_Error("UI_GetReferenceString: unknown reference %s", token); }
/** * @sa Com_MacroExpandString * @todo we should review this code, '*' doesn't work very well for all the needed things */ const char *UI_GetReferenceString (const uiNode_t* const node, const char *ref) { if (!ref) return NULL; /* its a cvar */ if (ref[0] == '*') { const char *token; /* get the reference and the name */ token = Com_MacroExpandString(ref); if (token) { if (token[0] == '_') { token++; return _(token); } return token; } /* skip the star */ token = ref + 1; if (token[0] == '\0') return NULL; if (char const* const binding = Q_strstart(token, "binding:")) { return Key_GetBinding(binding, cls.state != ca_active ? KEYSPACE_UI : KEYSPACE_GAME); } Sys_Error("UI_GetReferenceString: unknown reference %s", token); /* translatable string */ } else if (ref[0] == '_') { ref++; return _(ref); } /* just a string */ return ref; }