From 1cdacf69be66de41d2cd07d1a55760379ea95152 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 14 May 2010 19:28:10 -0700 Subject: [PATCH] Move some string functions from core to logic (bug 4406 part 4, r=fyren). --- core/PlayerManager.cpp | 3 +- core/logic/AMBuilder | 1 + core/logic/Makefile | 1 + core/logic/common_logic.cpp | 4 ++- core/logic/intercom.h | 3 +- core/logic/stringutil.cpp | 67 +++++++++++++++++++++++++++++++++++++ core/logic/stringutil.h | 38 +++++++++++++++++++++ core/logic_bridge.cpp | 15 ++++----- core/logic_bridge.h | 5 +++ core/sm_stringutil.cpp | 31 ----------------- core/sm_stringutil.h | 1 - core/smn_string.cpp | 3 +- 12 files changed, 128 insertions(+), 44 deletions(-) create mode 100644 core/logic/stringutil.cpp create mode 100644 core/logic/stringutil.h diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 44b934e4..159a39ff 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -49,6 +49,7 @@ #include "ExtensionSys.h" #include #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) { diff --git a/core/logic/AMBuilder b/core/logic/AMBuilder index c3081a43..8be3ca3a 100644 --- a/core/logic/AMBuilder +++ b/core/logic/AMBuilder @@ -35,6 +35,7 @@ files = [ 'MemoryUtils.cpp', 'smn_admin.cpp', 'smn_banning.cpp', + 'stringutil.cpp', 'sm_crc32.cpp' ] if AMBuild.target['platform'] == 'windows': diff --git a/core/logic/Makefile b/core/logic/Makefile index 045c677b..a98ac39b 100644 --- a/core/logic/Makefile +++ b/core/logic/Makefile @@ -31,6 +31,7 @@ OBJECTS = \ MemoryUtils.cpp \ smn_admin.cpp \ smn_banning.cpp \ + stringutil.cpp \ smn_players.cpp ############################################## diff --git a/core/logic/common_logic.cpp b/core/logic/common_logic.cpp index c8c26d0b..1c881dcd 100644 --- a/core/logic/common_logic.cpp +++ b/core/logic/common_logic.cpp @@ -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) diff --git a/core/logic/intercom.h b/core/logic/intercom.h index efeafc81..b28c58d4 100644 --- a/core/logic/intercom.h +++ b/core/logic/intercom.h @@ -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); diff --git a/core/logic/stringutil.cpp b/core/logic/stringutil.cpp new file mode 100644 index 00000000..d03a39e3 --- /dev/null +++ b/core/logic/stringutil.cpp @@ -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 . + * + * 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 . + * + * Version: $Id$ + */ + +#include +#include +#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; +} + + diff --git a/core/logic/stringutil.h b/core/logic/stringutil.h new file mode 100644 index 00000000..7b19e95e --- /dev/null +++ b/core/logic/stringutil.h @@ -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 . + * + * 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 . + * + * 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_ */ + diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 4b454ff7..216118fd 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -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) diff --git a/core/logic_bridge.h b/core/logic_bridge.h index b3b059b1..a16f35d3 100644 --- a/core/logic_bridge.h +++ b/core/logic_bridge.h @@ -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_ */ diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index 137ff2a3..02018d5d 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -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) diff --git a/core/sm_stringutil.h b/core/sm_stringutil.h index 3b5ed50b..4f67fba4 100644 --- a/core/sm_stringutil.h +++ b/core/sm_stringutil.h @@ -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, diff --git a/core/smn_string.cpp b/core/smn_string.cpp index 8cdfa8ad..f01b58a3 100644 --- a/core/smn_string.cpp +++ b/core/smn_string.cpp @@ -35,6 +35,7 @@ #include "sm_stringutil.h" #include #include +#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) {