VM_tokenize_console, // #514 float(string str) tokenize_console = #514; (DP_QC_TOKENIZE_CONSOLE)
VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_QC_TOKENIZE_CONSOLE)
VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE)
-NULL, // #517
-NULL, // #518
+VM_buf_cvarlist, // #517 void(float buf, string prefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST)
+VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION)
NULL, // #519
VM_keynumtostring, // #520 string keynumtostring(float keynum)
VM_findkeysforcommand, // #521 string findkeysforcommand(string command)
#include "quakedef.h"
+char *cvar_dummy_description = "custom cvar";
+
cvar_t *cvar_vars = NULL;
cvar_t *cvar_hashtable[65536];
char *cvar_null_string = "";
return var->defstring;
}
+/*
+============
+Cvar_VariableDescription
+============
+*/
+const char *Cvar_VariableDescription (const char *var_name)
+{
+ cvar_t *var;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ return cvar_null_string;
+ return var->description;
+}
+
/*
============
Adds a newly allocated variable to the variable list or sets its value.
============
*/
-cvar_t *Cvar_Get (const char *name, const char *value, int flags)
+cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription)
{
int hashindex;
cvar_t *current, *next, *cvar;
{
cvar->flags |= flags;
Cvar_SetQuick_Internal (cvar, value);
+ if(newdescription && (cvar->flags & CVAR_ALLOCATED))
+ {
+ if(cvar->description != cvar_dummy_description)
+ Z_Free(cvar->description);
+
+ if(*newdescription)
+ {
+ alloclen = strlen(newdescription) + 1;
+ cvar->description = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->description, newdescription, alloclen);
+ }
+ else
+ cvar->description = cvar_dummy_description;
+ }
return cvar;
}
memcpy(cvar->defstring, value, alloclen);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
- cvar->description = "custom cvar"; // actually checked by VM_cvar_type
+
+ if(newdescription && *newdescription)
+ {
+ alloclen = strlen(newdescription) + 1;
+ cvar->description = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->description, newdescription, alloclen);
+ }
+ else
+ cvar->description = cvar_dummy_description; // actually checked by VM_cvar_type
// link the variable in
// alphanumerical order
// make sure it's the right number of parameters
if (Cmd_Argc() < 3)
{
- Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value>\n");
+ Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value> [<description>]\n");
return;
}
Con_DPrint("Set: ");
// all looks ok, create/modify the cvar
- Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0);
+ Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0, Cmd_Argc() >= 3 ? Cmd_Argv(3) : NULL);
}
void Cvar_SetA_f (void)
// make sure it's the right number of parameters
if (Cmd_Argc() < 3)
{
- Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value>\n");
+ Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value> [<description>]\n");
return;
}
Con_DPrint("SetA: ");
// all looks ok, create/modify the cvar
- Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE);
+ Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE, Cmd_Argc() >= 3 ? Cmd_Argv(3) : NULL);
}
const char *Cvar_VariableDefString (const char *var_name);
// returns an empty string if not defined
+const char *Cvar_VariableDescription (const char *var_name);
+// returns an empty string if not defined
+
const char *Cvar_CompleteVariable (const char *partial);
// attempts to match a partial variable name for command line completion
// returns NULL if nothing fits
// commands to create new cvars (or set existing ones)
// seta creates an archived cvar (saved to config)
-cvar_t *Cvar_Get (const char *name, const char *value, int flags);
+cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription);
// allocates a cvar by name and returns its address,
// or merely sets its value if it already exists.
+char *cvar_dummy_description; // ALWAYS the same pointer
+cvar_t *cvar_vars; // used to list all cvars
+
#endif
"DP_QC_CMD "
"DP_QC_CRC16 "
"DP_QC_CVAR_TYPE "
+"DP_QC_CVAR_DESCRIPTION "
"DP_QC_RENDER_SCENE "
"DP_QC_STRFTIME "
"DP_QC_STRINGBUFFERS "
+"DP_QC_STRINGBUFFERS_CVARLIST "
"DP_QC_STRINGCOLORFUNCTIONS "
"DP_QC_STRING_CASE_FUNCTIONS "
"DP_QC_STRREPLACE "
VM_tokenize_console, // #514 float(string str) tokenize_console = #514; (DP_QC_TOKENIZE_CONSOLE)
VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_QC_TOKENIZE_CONSOLE)
VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE)
-NULL, // #517
-NULL, // #518
+VM_buf_cvarlist, // #517 void(float buf, string prefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST)
+VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION)
NULL, // #519
NULL, // #520
NULL, // #521
ret |= 4; // CVAR_TYPE_PRIVATE
if(!(cvar->flags & CVAR_ALLOCATED))
ret |= 8; // CVAR_TYPE_ENGINE
- if(strcmp(cvar->description, "custom cvar")) // has to match Cvar_Get's placeholder string
+ if(cvar->description != cvar_dummy_description)
ret |= 16; // CVAR_TYPE_HASDESCRIPTION
PRVM_G_FLOAT(OFS_RETURN) = ret;
VM_CheckEmptyString(string);
PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Cvar_VariableDefString(string));
}
+
+/*
+========================
+VM_cvar_defstring
+
+const string VM_cvar_description (string, ...)
+========================
+*/
+void VM_cvar_description (void)
+{
+ char string[VM_STRINGTEMP_LENGTH];
+ VM_SAFEPARMCOUNTRANGE(1,8,VM_cvar_description);
+ VM_VarString(0, string, sizeof(string));
+ VM_CheckEmptyString(string);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Cvar_VariableDescription(string));
+}
/*
=================
VM_cvar_set
return;
}
- Cvar_Get(name, value, flags);
+ Cvar_Get(name, value, flags, NULL);
PRVM_G_FLOAT(OFS_RETURN) = 1; // success
}
BufStr_Shrink(stringbuffer);
}
+
+
+
+
+
+
+void VM_buf_cvarlist(void)
+{
+ cvar_t *cvar;
+ const char *partial;
+ size_t len;
+ size_t alloclen;
+ int n;
+ prvm_stringbuffer_t *stringbuffer;
+ VM_SAFEPARMCOUNT(2, VM_bufstr_free);
+
+ stringbuffer = (prvm_stringbuffer_t *)Mem_ExpandableArray_RecordAtIndex(&prog->stringbuffersarray, (int)PRVM_G_FLOAT(OFS_PARM0));
+ if(!stringbuffer)
+ {
+ VM_Warning("VM_bufstr_free: invalid buffer %i used in %s\n", (int)PRVM_G_FLOAT(OFS_PARM0), PRVM_NAME);
+ return;
+ }
+
+ partial = PRVM_G_STRING(OFS_PARM1);
+ if(!partial)
+ len = 0;
+ else
+ len = strlen(partial);
+
+ for (n = 0;n < stringbuffer->num_strings;n++)
+ if (stringbuffer->strings[n])
+ Mem_Free(stringbuffer->strings[n]);
+ if (stringbuffer->strings)
+ Mem_Free(stringbuffer->strings);
+ stringbuffer->strings = NULL;
+
+ n = 0;
+ for(cvar = cvar_vars; cvar; cvar = cvar->next)
+ {
+ if(partial && strncasecmp(partial, cvar->name, len))
+ continue;
+ ++n;
+ }
+
+ stringbuffer->max_strings = stringbuffer->num_strings = n;
+ if (stringbuffer->max_strings)
+ stringbuffer->strings = (char **)Mem_Alloc(prog->progs_mempool, sizeof(stringbuffer->strings[0]) * stringbuffer->max_strings);
+
+ n = 0;
+ for(cvar = cvar_vars; cvar; cvar = cvar->next)
+ {
+ if(partial && strncasecmp(partial, cvar->name, len))
+ continue;
+
+ alloclen = strlen(cvar->name) + 1;
+ stringbuffer->strings[n] = (char *)Mem_Alloc(prog->progs_mempool, alloclen);
+ memcpy(stringbuffer->strings[n], cvar->name, alloclen);
+
+ ++n;
+ }
+}
+
+
+
+
//=============
/*
void VM_tokenize_console (void);
void VM_argv_start_index (void);
void VM_argv_end_index (void);
+
+void VM_buf_cvarlist(void);
+void VM_cvar_description(void);
"DP_QC_COPYENTITY "
"DP_QC_CRC16 "
"DP_QC_CVAR_DEFSTRING "
+"DP_QC_CVAR_DESCRIPTION "
"DP_QC_CVAR_STRING "
"DP_QC_CVAR_TYPE "
"DP_QC_EDICT_NUM "
"DP_QC_SINCOSSQRTPOW "
"DP_QC_STRFTIME "
"DP_QC_STRINGBUFFERS "
+"DP_QC_STRINGBUFFERS_CVARLIST "
"DP_QC_STRINGCOLORFUNCTIONS "
"DP_QC_STRING_CASE_FUNCTIONS "
"DP_QC_STRREPLACE "
VM_tokenize_console, // #514 float(string str) tokenize_console = #514; (DP_QC_TOKENIZE_CONSOLE)
VM_argv_start_index, // #515 float(float idx) argv_start_index = #515; (DP_QC_TOKENIZE_CONSOLE)
VM_argv_end_index, // #516 float(float idx) argv_end_index = #516; (DP_QC_TOKENIZE_CONSOLE)
-NULL, // #517
-NULL, // #518
+VM_buf_cvarlist, // #517 void(float buf, string prefix) buf_cvarlist = #517; (DP_QC_STRINGBUFFERS_CVARLIST)
+VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION)
NULL, // #519
};