added format/formatargs api
authorDavid Anderson <dvander@alliedmods.net>
Sat Oct 06 16:47:58 2007 +0000 (2007-10-06)
changeset 376f2d55f90f697
parent 375 17ca1d5645ac
child 377 185f66cb03cd
added format/formatargs api
sourcemm/ISmmAPI.h
sourcemm/ISmmPlugin.h
sourcemm/metamod.cpp
sourcemm/metamod.h
     1.1 --- a/sourcemm/ISmmAPI.h	Sat Oct 06 15:47:59 2007 +0000
     1.2 +++ b/sourcemm/ISmmAPI.h	Sat Oct 06 16:47:58 2007 +0000
     1.3 @@ -33,6 +33,7 @@
     1.4   * @file ISmmAPI.h
     1.5   */
     1.6  
     1.7 +#include <stdarg.h>
     1.8  #include <interface.h>
     1.9  #include <eiface.h>
    1.10  #include <sourcehook.h>
    1.11 @@ -334,6 +335,38 @@
    1.12  	 * 						EnableVSPListener().
    1.13  	 */
    1.14  	virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
    1.15 +
    1.16 +	/**
    1.17 +	 * @brief Formats a string.  This is a platform safe wrapper around 
    1.18 +	 * snprintf/_snprintf.
    1.19 +	 *
    1.20 +	 * @param buffer		Buffer to write to.
    1.21 +	 * @param maxlength		Maximum length of the buffer.
    1.22 +	 * @param format		Format specifiers.
    1.23 +	 * @param ...			Format arguments.
    1.24 +	 * @return				Number of bytes actually written, not including the 
    1.25 +	 *						null terminator.
    1.26 +	 */
    1.27 +	virtual size_t Format(char *buffer, 
    1.28 +		size_t maxlength,
    1.29 +		const char *format,
    1.30 +		...) =0;
    1.31 +
    1.32 +	/**
    1.33 +	 * @brief Formats a string.  This is a platform safe wrapper around 
    1.34 +	 * vsnprintf/_vsnprintf.
    1.35 +	 *
    1.36 +	 * @param buffer		Buffer to write to.
    1.37 +	 * @param maxlength		Maximum length of the buffer.
    1.38 +	 * @param format		Format specifiers.
    1.39 +	 * @param ap			Format argument list.
    1.40 +	 * @return				Number of bytes actually written, not including the 
    1.41 +	 *						null terminator.
    1.42 +	 */
    1.43 +	virtual size_t FormatArgs(char *buffer,
    1.44 +		size_t maxlength,
    1.45 +		const char *format,
    1.46 +		va_list ap) =0;
    1.47  };
    1.48  
    1.49  
     2.1 --- a/sourcemm/ISmmPlugin.h	Sat Oct 06 15:47:59 2007 +0000
     2.2 +++ b/sourcemm/ISmmPlugin.h	Sat Oct 06 16:47:58 2007 +0000
     2.3 @@ -425,7 +425,7 @@
     2.4  	{ \
     2.5  		if (error && maxlen) \
     2.6  		{ \
     2.7 -			snprintf(error, maxlen, "Could not find interface: %s", v_name); \
     2.8 +			ismm->Format(error, maxlen, "Could not find interface: %s", v_name); \
     2.9  		} \
    2.10  		return false; \
    2.11  	}
    2.12 @@ -444,7 +444,7 @@
    2.13  	{ \
    2.14  		if (error && maxlen) \
    2.15  		{ \
    2.16 -			snprintf(error, maxlen, "Could not find interface: %s", v_name); \
    2.17 +			ismm->Format(error, maxlen, "Could not find interface: %s", v_name); \
    2.18  		} \
    2.19  		return false; \
    2.20  	}
     3.1 --- a/sourcemm/metamod.cpp	Sat Oct 06 15:47:59 2007 +0000
     3.2 +++ b/sourcemm/metamod.cpp	Sat Oct 06 16:47:58 2007 +0000
     3.3 @@ -1242,3 +1242,19 @@
     3.4  	return vsp_callbacks;
     3.5  }
     3.6  
     3.7 +size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
     3.8 +{
     3.9 +	va_list ap;
    3.10 +	size_t result;
    3.11 +
    3.12 +	va_start(ap, format);
    3.13 +	result = FormatArgs(buffer, maxlength, format, ap);
    3.14 +	va_end(ap);
    3.15 +
    3.16 +	return result;
    3.17 +}
    3.18 +
    3.19 +size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
    3.20 +{
    3.21 +	return UTIL_FormatArgs(buffer, maxlength, format, ap);
    3.22 +}
     4.1 --- a/sourcemm/metamod.h	Sat Oct 06 15:47:59 2007 +0000
     4.2 +++ b/sourcemm/metamod.h	Sat Oct 06 16:47:58 2007 +0000
     4.3 @@ -89,6 +89,8 @@
     4.4  	int GetVSPVersion();
     4.5  	int GetSourceEngineBuild();
     4.6  	IServerPluginCallbacks *GetVSPInfo(int *pVersion);
     4.7 +	size_t Format(char *buffer, size_t maxlength, const char *format, ...);
     4.8 +	size_t FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap);
     4.9  public:
    4.10  	const char *GetGameBinaryPath();
    4.11  	const char *GetPluginsFile();