From a2d459ae8470c511de6c7d7e0ce95ee5753aa85c Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Fri, 27 Jan 2023 08:49:03 +0500 Subject: [PATCH] engine: common: add printf-like version of Cvar_Get function. --- engine/common/cvar.c | 17 +++++++++++++++++ engine/common/cvar.h | 1 + 2 files changed, 18 insertions(+) diff --git a/engine/common/cvar.c b/engine/common/cvar.c index 397a5808..a38cc2f4 100644 --- a/engine/common/cvar.c +++ b/engine/common/cvar.c @@ -469,6 +469,23 @@ convar_t *Cvar_Get( const char *name, const char *value, int flags, const char * return var; } +/* +============ +Cvar_Getf +============ +*/ +convar_t *Cvar_Getf( const char *var_name, int flags, const char *description, const char *format, ... ) +{ + char value[MAX_VA_STRING]; + va_list args; + + va_start( args, format ); + Q_vsnprintf( value, sizeof( value ), format, args ); + va_end( args ); + + return Cvar_Get( var_name, value, flags, description ); +} + /* ============ Cvar_RegisterVariable diff --git a/engine/common/cvar.h b/engine/common/cvar.h index b234e919..3d167f4f 100644 --- a/engine/common/cvar.h +++ b/engine/common/cvar.h @@ -63,6 +63,7 @@ cvar_t *Cvar_GetList( void ); convar_t *Cvar_FindVarExt( const char *var_name, int ignore_group ); void Cvar_RegisterVariable( convar_t *var ); convar_t *Cvar_Get( const char *var_name, const char *value, int flags, const char *description ); +convar_t *Cvar_Getf( const char *var_name, int flags, const char *description, const char *format, ... ) _format( 4 ); void Cvar_LookupVars( int checkbit, void *buffer, void *ptr, setpair_t callback ); void Cvar_FullSet( const char *var_name, const char *value, int flags ); void Cvar_DirectSet( convar_t *var, const char *value );