From 3299999f3d945f220b3205f6c2786a69db6e35c5 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Fri, 27 Jan 2023 06:43:28 +0500 Subject: [PATCH] engine: common: add printf-like version of Info_SetValueForKey function. --- engine/common/common.h | 1 + engine/common/infostring.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/engine/common/common.h b/engine/common/common.h index 3d747d3c..2ff09685 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -818,6 +818,7 @@ const char *Info_ValueForKey( const char *s, const char *key ); void Info_RemovePrefixedKeys( char *start, char prefix ); qboolean Info_RemoveKey( char *s, const char *key ); qboolean Info_SetValueForKey( char *s, const char *key, const char *value, int maxsize ); +qboolean Info_SetValueForKeyf( char *s, const char *key, int maxsize, const char *format, ... ) _format( 4 ); qboolean Info_SetValueForStarKey( char *s, const char *key, const char *value, int maxsize ); qboolean Info_IsValid( const char *s ); void Info_WriteVars( file_t *f ); diff --git a/engine/common/infostring.c b/engine/common/infostring.c index 220cc9e8..c7a4ed75 100644 --- a/engine/common/infostring.c +++ b/engine/common/infostring.c @@ -496,3 +496,16 @@ qboolean Info_SetValueForKey( char *s, const char *key, const char *value, int m return Info_SetValueForStarKey( s, key, value, maxsize ); } + +qboolean Info_SetValueForKeyf( char *s, const char *key, int maxsize, 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 Info_SetValueForKey( s, key, value, maxsize ); +} +