From 8c238d3def13ef509272f2f9889d57aa00fe4eaa Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 9 Jul 2019 20:14:57 +0900 Subject: [PATCH] Parse developer flag names when cvar is set So much easier to remember "vulkan" instead of which power of two it is. --- libs/util/cvar.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/libs/util/cvar.c b/libs/util/cvar.c index 64ef200ab..3b30b00f9 100644 --- a/libs/util/cvar.c +++ b/libs/util/cvar.c @@ -37,6 +37,7 @@ # include #endif +#include #include #include @@ -327,6 +328,82 @@ Cvar_WriteVariables (QFile *f) Qprintf (f, "seta %s \"%s\"\n", var->name, var->string); } +// XXX make sure in sync with SYS_* in sys.h +static const char *developer_flags[] = { + "dev", + "warn", + "vid", + "fs_nf", + "fs_f", + "fs", + "net", + "rua_obj", + "rua_msg", + "snd", + "glt", + "glsl", + "skin", + "model", + "vulkan", + 0 +}; + +static int +parse_developer_flag (const char *flag) +{ + const char **devflag; + char *end; + int val; + + val = strtol (flag, &end, 0); + if (!*end) { + return val; + } + for (devflag = developer_flags; *devflag; devflag++) { + if (!strcmp (*devflag, flag)) { + return 1 << (devflag - developer_flags); + } + } + return 0; +} + +static void +developer_f (cvar_t *var) +{ + char *buf = alloca (strlen (var->string) + 1); + const char *s; + char *b; + char c; + int parse = 0; + + for (s = var->string; *s; s++) { + if (isalpha (*s) || *s == '|') { + parse = 1; + break; + } + } + if (!parse) { + return; + } + var->int_val = 0; + for (s = var->string, b = buf; (c = *s++); ) { + if (isspace (c)) { + continue; + } + if (c == '|') { + *b = 0; + var->int_val |= parse_developer_flag (buf); + b = buf; + continue; + } + *b++ = c; + } + if (b != buf) { + *b = 0; + var->int_val |= parse_developer_flag (buf); + } +} + static void set_cvar (const char *cmd, int orflags) { @@ -587,7 +664,7 @@ Cvar_Init_Hash (void) VISIBLE void Cvar_Init (void) { - developer = Cvar_Get ("developer", "0", CVAR_NONE, NULL, + developer = Cvar_Get ("developer", "0", CVAR_NONE, developer_f, "set to enable extra debugging information"); Cmd_AddCommand ("set", Cvar_Set_f, "Set the selected variable, useful on "