Move gnprintf/atcprintf from core to logic.

This commit is contained in:
David Anderson
2015-08-30 19:32:46 -07:00
parent 9d2bee261c
commit e78fe93e92
15 changed files with 1373 additions and 1265 deletions
+1
View File
@@ -75,6 +75,7 @@ binary.sources += [
'Logger.cpp',
'smn_core.cpp',
'smn_menus.cpp',
'sprintf.cpp',
]
if builder.target_platform == 'windows':
binary.sources += ['thread/WinThreads.cpp']
+3 -2
View File
@@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
@@ -32,6 +32,7 @@
#include "common_logic.h"
#include "PhraseCollection.h"
#include "Translator.h"
#include "sprintf.h"
#include <am-string.h>
CPhraseCollection::CPhraseCollection()
@@ -114,7 +115,7 @@ bool CPhraseCollection::FormatString(char *buffer,
unsigned int arg;
arg = 0;
if (!smcore.gnprintf(buffer, maxlength, format, this, params, numparams, arg, pOutLength, pFailPhrase))
if (!gnprintf(buffer, maxlength, format, this, params, numparams, arg, pOutLength, pFailPhrase))
{
return false;
}
+2 -1
View File
@@ -40,6 +40,7 @@
#include <ILibrarySys.h>
#include "PhraseCollection.h"
#include "stringutil.h"
#include "sprintf.h"
#include <am-string.h>
Translator g_Translator;
@@ -1059,7 +1060,7 @@ bool Translator::FormatString(char *buffer,
unsigned int arg;
arg = 0;
if (!smcore.gnprintf(buffer, maxlength, format, pPhrases, params, numparams, arg, pOutLength, pFailPhrase))
if (!gnprintf(buffer, maxlength, format, pPhrases, params, numparams, arg, pOutLength, pFailPhrase))
{
return false;
}
+2
View File
@@ -51,6 +51,7 @@
#include "AdminCache.h"
#include "ProfileTools.h"
#include "Logger.h"
#include "sprintf.h"
sm_core_t smcore;
IHandleSys *handlesys = &g_HandleSys;
@@ -124,6 +125,7 @@ static sm_logic_t logic =
g_pThreader,
&g_Translator,
stristr,
atcprintf,
CoreTranslate,
AddCorePhraseFile,
UTIL_ReplaceAll,
+5 -4
View File
@@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries
*/
#define SM_LOGIC_MAGIC (0x0F47C0DE - 33)
#define SM_LOGIC_MAGIC (0x0F47C0DE - 34)
#if defined SM_LOGIC
class IVEngineServer
@@ -297,9 +297,6 @@ struct sm_core_t
void (*ConPrint)(const char *message);
const char * (*GetCvarString)(ConVar*);
bool (*GetCvarBool)(ConVar*);
bool (*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **,
unsigned int, unsigned int &, size_t *, const char **);
size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);
bool (*GetGameName)(char *buffer, size_t maxlength);
const char * (*GetGameDescription)();
const char * (*GetSourceEngineName)();
@@ -319,6 +316,9 @@ struct sm_core_t
int (*GetImmunityMode)();
void (*UpdateAdminCmdFlags)(const char *cmd, OverrideType type, FlagBits bits, bool remove);
bool (*LookForCommandAdminFlags)(const char *cmd, FlagBits *pFlags);
bool (*DescribePlayer)(int index, const char **namep, const char **authp, int *useridp);
int (*MaxClients)();
int (*GetGlobalTarget)();
const char *gamesuffix;
/* Data */
ServerGlobals *serverGlobals;
@@ -334,6 +334,7 @@ struct sm_logic_t
IThreader *threader;
ITranslator *translator;
const char *(*stristr)(const char *, const char *);
size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);
bool (*CoreTranslate)(char *, size_t, const char *, unsigned int, size_t *, ...);
void (*AddCorePhraseFile)(const char *filename);
unsigned int (*ReplaceAll)(char*, size_t, const char *, const char *, bool);
+3 -2
View File
@@ -35,6 +35,7 @@
#include <IPlayerHelpers.h>
#include <ISourceMod.h>
#include <ITranslator.h>
#include "sprintf.h"
static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
{
@@ -90,7 +91,7 @@ static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
int arg = 2;
pCtx->LocalToString(params[1], &fmt);
size_t res = smcore.atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
buffer[res++] = '\n';
buffer[res] = '\0';
@@ -129,7 +130,7 @@ static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
int arg = 3;
pCtx->LocalToString(params[2], &fmt);
size_t res = smcore.atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
buffer[res++] = '\n';
buffer[res] = '\0';
+2 -1
View File
@@ -35,6 +35,7 @@
#include "common_logic.h"
#include "ShareSys.h"
#include "PluginSys.h"
#include "sprintf.h"
using namespace SourceHook;
@@ -412,7 +413,7 @@ static cell_t FormatNativeString(IPluginContext *pContext, const cell_t *params)
size_t written;
{
DetectExceptions eh(pContext);
written = smcore.atcprintf(output_buffer, maxlen, format_buffer, s_curcaller, s_curparams, &var_param);
written = atcprintf(output_buffer, maxlen, format_buffer, s_curcaller, s_curparams, &var_param);
if (eh.HasException())
return 0;
}
+3 -2
View File
@@ -40,6 +40,7 @@
#include <ITranslator.h>
#include "common_logic.h"
#include "Logger.h"
#include "sprintf.h"
#include <am-utility.h>
#include "handle_helpers.h"
@@ -774,7 +775,7 @@ static cell_t sm_WriteFileLine(IPluginContext *pContext, const cell_t *params)
char buffer[2048];
{
DetectExceptions eh(pContext);
smcore.atcprintf(buffer, sizeof(buffer), fmt, pContext, params, &arg);
atcprintf(buffer, sizeof(buffer), fmt, pContext, params, &arg);
if (eh.HasException())
return 0;
}
@@ -809,7 +810,7 @@ static cell_t sm_BuildPath(IPluginContext *pContext, const cell_t *params)
{
DetectExceptions eh(pContext);
smcore.atcprintf(path, sizeof(path), fmt, pContext, params, &arg);
atcprintf(path, sizeof(path), fmt, pContext, params, &arg);
if (eh.HasException())
return 0;
}
+4 -3
View File
@@ -35,6 +35,7 @@
#include <ITextParsers.h>
#include <ctype.h>
#include "stringutil.h"
#include "sprintf.h"
#include <am-string.h>
inline const char *_strstr(const char *str, const char *substr)
@@ -188,7 +189,7 @@ static cell_t sm_formatex(IPluginContext *pCtx, const cell_t *params)
pCtx->LocalToString(params[1], &buf);
pCtx->LocalToString(params[3], &fmt);
res = smcore.atcprintf(buf, static_cast<size_t>(params[2]), fmt, pCtx, params, &arg);
res = atcprintf(buf, static_cast<size_t>(params[2]), fmt, pCtx, params, &arg);
return static_cast<cell_t>(res);
}
@@ -257,7 +258,7 @@ static cell_t sm_format(IPluginContext *pCtx, const cell_t *params)
}
buf = (copy) ? __copy_buf : destbuf;
res = smcore.atcprintf(buf, maxlen, fmt, pCtx, params, &arg);
res = atcprintf(buf, maxlen, fmt, pCtx, params, &arg);
if (copy)
{
@@ -307,7 +308,7 @@ static cell_t sm_vformat(IPluginContext *pContext, const cell_t *params)
pContext->LocalToString(params[3], &format);
size_t total = smcore.atcprintf(destination, maxlen, format, pContext, local_params, &vargPos);
size_t total = atcprintf(destination, maxlen, format, pContext, local_params, &vargPos);
/* Perform copy-on-write if we need to */
if (copy)
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
// vim: set ts=4 sw=4 tw=99 noet :
// =============================================================================
// SourceMod
// Copyright (C) 2004-2015 AlliedModders LLC. All rights reserved.
// =============================================================================
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License, version 3.0, as published by the
// Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, AlliedModders LLC gives you permission to link the
// code of this program (as well as its derivative works) to "Half-Life 2," the
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
// by the Valve Corporation. You must obey the GNU General Public License in
// all respects for all other code used. Additionally, AlliedModders LLC grants
// this exception to all derivative works. AlliedModders LLC defines further
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
// or <http://www.sourcemod.net/license.php>.
#ifndef _include_sourcemod_core_logic_sprintf_h_
#define _include_sourcemod_core_logic_sprintf_h_
#include <sp_vm_api.h>
// "AMX Templated Cell Printf", originally. SourceMod doesn't have cell-strings
// so this is a normal sprintf(), except that its variadic arguments are
// derived from scripted arguments.
size_t atcprintf(char *buffer,
size_t maxlen,
const char *format,
SourcePawn::IPluginContext *pCtx,
const cell_t *params,
int *param);
// "Generic Printf", originally. This is similar to atcprintf, except arguments
// are provided as an array of opaque pointers, rather than scripted arguments
// or C++ va_lists. This is essentially what Core uses to translate and format
// phrases internally.
bool gnprintf(char *buffer,
size_t maxlen,
const char *format,
IPhraseCollection *pPhrases,
void **params,
unsigned int numparams,
unsigned int &curparam,
size_t *pOutLength,
const char **pFailPhrase);
#endif // _include_sourcemod_core_logic_sprintf_h_