Move some string functions from core to logic (bug 4406 part 4, r=fyren).

This commit is contained in:
David Anderson 2010-05-14 19:28:10 -07:00
parent b5b002aa4b
commit 1cdacf69be
12 changed files with 128 additions and 44 deletions

View File

@ -49,6 +49,7 @@
#include "ExtensionSys.h"
#include <sourcemod_version.h>
#include "ConsoleDetours.h"
#include "logic_bridge.h"
PlayerManager g_Players;
bool g_OnMapStarted = false;
@ -1300,7 +1301,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
continue;
}
if (stristr(pTarget->GetName(), info->pattern) != NULL)
if (logicore.stristr(pTarget->GetName(), info->pattern) != NULL)
{
if (found_client)
{

View File

@ -35,6 +35,7 @@ files = [
'MemoryUtils.cpp',
'smn_admin.cpp',
'smn_banning.cpp',
'stringutil.cpp',
'sm_crc32.cpp'
]
if AMBuild.target['platform'] == 'windows':

View File

@ -31,6 +31,7 @@ OBJECTS = \
MemoryUtils.cpp \
smn_admin.cpp \
smn_banning.cpp \
stringutil.cpp \
smn_players.cpp
##############################################

View File

@ -38,6 +38,7 @@
#include "Profiler.h"
#include "sm_crc32.h"
#include "MemoryUtils.h"
#include "stringutil.h"
sm_core_t smcore;
IHandleSys *handlesys;
@ -63,7 +64,8 @@ static sm_logic_t logic =
g_pThreader,
sm_profiler,
&g_MemUtils,
UTIL_CRC32
UTIL_CRC32,
stristr
};
static void logic_init(const sm_core_t* core, sm_logic_t* _logic)

View File

@ -42,7 +42,7 @@ using namespace SourceMod;
* 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 - 8)
#define SM_LOGIC_MAGIC (0x0F47C0DE - 9)
#if defined SM_LOGIC
class IVEngineServer
@ -118,6 +118,7 @@ struct sm_logic_t
IProfiler *profiler;
IMemoryUtils *memutils;
unsigned int (*CRC32)(const void *, size_t);
const char *(*stristr)(const char *, const char *);
};
typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);

67
core/logic/stringutil.cpp Normal file
View File

@ -0,0 +1,67 @@
/**
* vim: set ts=4 sw=4 tw=99 et :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2009 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>.
*
* Version: $Id$
*/
#include <string.h>
#include <ctype.h>
#include "stringutil.h"
const char *stristr(const char *str, const char *substr)
{
if (!*substr)
{
return ((char *)str);
}
char *needle = (char *)substr;
char *prevloc = (char *)str;
char *haystack = (char *)str;
while (*haystack)
{
if (tolower(*haystack) == tolower(*needle))
{
haystack++;
if (!*++needle)
{
return prevloc;
}
}
else
{
haystack = ++prevloc;
needle = (char *)substr;
}
}
return NULL;
}

38
core/logic/stringutil.h Normal file
View File

@ -0,0 +1,38 @@
/**
* vim: set ts=4 sw=4 tw=99 et :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2009 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>.
*
* Version: $Id$
*/
#ifndef _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_
#define _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_
const char *stristr(const char *str, const char *substr);
#endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */

View File

@ -57,6 +57,7 @@ IThreader *g_pThreader;
ITextParsers *textparsers;
SM_FN_CRC32 UTIL_CRC32;
IMemoryUtils *memutils;
sm_logic_t logicore;
class VEngineServer_Logic : public IVEngineServer_Logic
{
@ -140,14 +141,12 @@ static sm_core_t core_bridge =
void InitLogicBridge()
{
sm_logic_t logic;
serverGlobals.universalTime = g_pUniversalTime;
serverGlobals.frametime = &gpGlobals->frametime;
serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick;
core_bridge.core_ident = g_pCoreIdent;
logic_init_fn(&core_bridge, &logic);
logic_init_fn(&core_bridge, &logicore);
/* Add SMGlobalClass instances */
SMGlobalClass* glob = SMGlobalClass::head;
@ -156,12 +155,12 @@ void InitLogicBridge()
glob = glob->m_pGlobalClassNext;
}
assert(glob->m_pGlobalClassNext == NULL);
glob->m_pGlobalClassNext = logic.head;
glob->m_pGlobalClassNext = logicore.head;
g_pThreader = logic.threader;
g_pSourcePawn2->SetProfiler(logic.profiler);
UTIL_CRC32 = logic.CRC32;
memutils = logic.memutils;
g_pThreader = logicore.threader;
g_pSourcePawn2->SetProfiler(logicore.profiler);
UTIL_CRC32 = logicore.CRC32;
memutils = logicore.memutils;
}
bool StartLogicBridge(char *error, size_t maxlength)

View File

@ -31,13 +31,18 @@
#ifndef _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
#define _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
#include "logic/intercom.h"
void InitLogicBridge();
bool StartLogicBridge(char *error, size_t maxlength);
void ShutdownLogicBridge();
struct sm_logic_t;
typedef unsigned int (*SM_FN_CRC32)(const void *, size_t);
extern SM_FN_CRC32 UTIL_CRC32;
extern sm_logic_t logicore;
#endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */

View File

@ -1274,37 +1274,6 @@ done:
return (maxlen - llen - 1);
}
const char *stristr(const char *str, const char *substr)
{
if (!*substr)
{
return ((char *)str);
}
char *needle = (char *)substr;
char *prevloc = (char *)str;
char *haystack = (char *)str;
while (*haystack)
{
if (tolower(*haystack) == tolower(*needle))
{
haystack++;
if (!*++needle)
{
return prevloc;
}
}
else
{
haystack = ++prevloc;
needle = (char *)substr;
}
}
return NULL;
}
unsigned int strncopy(char *dest, const char *src, size_t count)
{
if (!count)

View File

@ -43,7 +43,6 @@ using namespace SourceMod;
#define IS_STR_FILLED(var) (var[0] != '\0')
size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param);
const char *stristr(const char *str, const char *substr);
unsigned int strncopy(char *dest, const char *src, size_t count);
bool gnprintf(char *buffer,
size_t maxlen,

View File

@ -35,6 +35,7 @@
#include "sm_stringutil.h"
#include <ITextParsers.h>
#include <ctype.h>
#include "logic_bridge.h"
inline const char *_strstr(const char *str, const char *substr)
{
@ -68,7 +69,7 @@ static cell_t sm_contain(IPluginContext *pCtx, const cell_t *params)
pCtx->LocalToString(params[1], &str);
pCtx->LocalToString(params[2], &substr);
func = (params[3]) ? _strstr : stristr;
func = (params[3]) ? _strstr : logicore.stristr;
const char *pos = func(str, substr);
if (pos)
{