Move some string functions from core to logic (bug 4406 part 4, r=fyren).
authorDavid Anderson <dvander@alliedmods.net>
Fri May 14 19:28:10 2010 -0700 (2010-05-14)
changeset 3002409a6de13f09
parent 3001 e6a16c3f47b2
child 3003 489c2b05a1b2
Move some string functions from core to logic (bug 4406 part 4, r=fyren).
core/PlayerManager.cpp
core/logic/AMBuilder
core/logic/Makefile
core/logic/common_logic.cpp
core/logic/intercom.h
core/logic/stringutil.cpp
core/logic/stringutil.h
core/logic_bridge.cpp
core/logic_bridge.h
core/sm_stringutil.cpp
core/sm_stringutil.h
core/smn_string.cpp
     1.1 --- a/core/PlayerManager.cpp	Fri May 14 18:22:03 2010 -0700
     1.2 +++ b/core/PlayerManager.cpp	Fri May 14 19:28:10 2010 -0700
     1.3 @@ -49,6 +49,7 @@
     1.4  #include "ExtensionSys.h"
     1.5  #include <sourcemod_version.h>
     1.6  #include "ConsoleDetours.h"
     1.7 +#include "logic_bridge.h"
     1.8  
     1.9  PlayerManager g_Players;
    1.10  bool g_OnMapStarted = false;
    1.11 @@ -1300,7 +1301,7 @@
    1.12  			continue;
    1.13  		}
    1.14  
    1.15 -		if (stristr(pTarget->GetName(), info->pattern) != NULL)
    1.16 +		if (logicore.stristr(pTarget->GetName(), info->pattern) != NULL)
    1.17  		{
    1.18  			if (found_client)
    1.19  			{
     2.1 --- a/core/logic/AMBuilder	Fri May 14 18:22:03 2010 -0700
     2.2 +++ b/core/logic/AMBuilder	Fri May 14 19:28:10 2010 -0700
     2.3 @@ -35,6 +35,7 @@
     2.4  	'MemoryUtils.cpp',
     2.5  	'smn_admin.cpp',
     2.6  	'smn_banning.cpp',
     2.7 +	'stringutil.cpp',
     2.8  	'sm_crc32.cpp'
     2.9  	]
    2.10  if AMBuild.target['platform'] == 'windows':
     3.1 --- a/core/logic/Makefile	Fri May 14 18:22:03 2010 -0700
     3.2 +++ b/core/logic/Makefile	Fri May 14 19:28:10 2010 -0700
     3.3 @@ -31,6 +31,7 @@
     3.4  	MemoryUtils.cpp		\
     3.5  	smn_admin.cpp		\
     3.6  	smn_banning.cpp		\
     3.7 +	stringutil.cpp		\
     3.8  	smn_players.cpp
     3.9  
    3.10  ##############################################
     4.1 --- a/core/logic/common_logic.cpp	Fri May 14 18:22:03 2010 -0700
     4.2 +++ b/core/logic/common_logic.cpp	Fri May 14 19:28:10 2010 -0700
     4.3 @@ -38,6 +38,7 @@
     4.4  #include "Profiler.h"
     4.5  #include "sm_crc32.h"
     4.6  #include "MemoryUtils.h"
     4.7 +#include "stringutil.h"
     4.8  
     4.9  sm_core_t smcore;
    4.10  IHandleSys *handlesys;
    4.11 @@ -63,7 +64,8 @@
    4.12  	g_pThreader,
    4.13  	sm_profiler,
    4.14  	&g_MemUtils,
    4.15 -	UTIL_CRC32
    4.16 +	UTIL_CRC32,
    4.17 +	stristr
    4.18  };
    4.19  
    4.20  static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
     5.1 --- a/core/logic/intercom.h	Fri May 14 18:22:03 2010 -0700
     5.2 +++ b/core/logic/intercom.h	Fri May 14 19:28:10 2010 -0700
     5.3 @@ -42,7 +42,7 @@
     5.4   * Add 1 to the RHS of this expression to bump the intercom file
     5.5   * This is to prevent mismatching core/logic binaries
     5.6   */
     5.7 -#define SM_LOGIC_MAGIC		(0x0F47C0DE - 8)
     5.8 +#define SM_LOGIC_MAGIC		(0x0F47C0DE - 9)
     5.9  
    5.10  #if defined SM_LOGIC
    5.11  class IVEngineServer
    5.12 @@ -118,6 +118,7 @@
    5.13  	IProfiler		*profiler;
    5.14  	IMemoryUtils    *memutils;
    5.15  	unsigned int    (*CRC32)(const void *, size_t);
    5.16 +	const char      *(*stristr)(const char *, const char *);
    5.17  };
    5.18  
    5.19  typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/core/logic/stringutil.cpp	Fri May 14 19:28:10 2010 -0700
     6.3 @@ -0,0 +1,67 @@
     6.4 +/**
     6.5 + * vim: set ts=4 sw=4 tw=99 et :
     6.6 + * =============================================================================
     6.7 + * SourceMod
     6.8 + * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
     6.9 + * =============================================================================
    6.10 + *
    6.11 + * This program is free software; you can redistribute it and/or modify it under
    6.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    6.13 + * Free Software Foundation.
    6.14 + * 
    6.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    6.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    6.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    6.18 + * details.
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License along with
    6.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    6.22 + *
    6.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    6.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    6.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    6.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    6.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    6.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    6.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    6.30 + * or <http://www.sourcemod.net/license.php>.
    6.31 + *
    6.32 + * Version: $Id$
    6.33 + */
    6.34 +
    6.35 +#include <string.h>
    6.36 +#include <ctype.h>
    6.37 +#include "stringutil.h"
    6.38 +
    6.39 +const char *stristr(const char *str, const char *substr)
    6.40 +{
    6.41 +	if (!*substr)
    6.42 +	{
    6.43 +		return ((char *)str);
    6.44 +	}
    6.45 +
    6.46 +	char *needle = (char *)substr;
    6.47 +	char *prevloc = (char *)str;
    6.48 +	char *haystack = (char *)str;
    6.49 +
    6.50 +	while (*haystack)
    6.51 +	{
    6.52 +		if (tolower(*haystack) == tolower(*needle))
    6.53 +		{
    6.54 +			haystack++;
    6.55 +			if (!*++needle)
    6.56 +			{
    6.57 +				return prevloc;
    6.58 +			}
    6.59 +		}
    6.60 +		else
    6.61 +		{
    6.62 +			haystack = ++prevloc;
    6.63 +			needle = (char *)substr;
    6.64 +		}
    6.65 +	}
    6.66 +
    6.67 +	return NULL;
    6.68 +}
    6.69 +
    6.70 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/core/logic/stringutil.h	Fri May 14 19:28:10 2010 -0700
     7.3 @@ -0,0 +1,38 @@
     7.4 +/**
     7.5 + * vim: set ts=4 sw=4 tw=99 et :
     7.6 + * =============================================================================
     7.7 + * SourceMod
     7.8 + * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
     7.9 + * =============================================================================
    7.10 + *
    7.11 + * This program is free software; you can redistribute it and/or modify it under
    7.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    7.13 + * Free Software Foundation.
    7.14 + * 
    7.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    7.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    7.18 + * details.
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License along with
    7.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    7.22 + *
    7.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    7.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    7.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    7.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    7.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    7.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    7.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    7.30 + * or <http://www.sourcemod.net/license.php>.
    7.31 + *
    7.32 + * Version: $Id$
    7.33 + */
    7.34 +
    7.35 +#ifndef _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_
    7.36 +#define _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_
    7.37 +
    7.38 +const char *stristr(const char *str, const char *substr);
    7.39 +
    7.40 +#endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */
    7.41 +
     8.1 --- a/core/logic_bridge.cpp	Fri May 14 18:22:03 2010 -0700
     8.2 +++ b/core/logic_bridge.cpp	Fri May 14 19:28:10 2010 -0700
     8.3 @@ -57,6 +57,7 @@
     8.4  ITextParsers *textparsers;
     8.5  SM_FN_CRC32 UTIL_CRC32;
     8.6  IMemoryUtils *memutils;
     8.7 +sm_logic_t logicore;
     8.8  
     8.9  class VEngineServer_Logic : public IVEngineServer_Logic
    8.10  {
    8.11 @@ -140,14 +141,12 @@
    8.12  
    8.13  void InitLogicBridge()
    8.14  {
    8.15 -	sm_logic_t logic;
    8.16 -
    8.17  	serverGlobals.universalTime = g_pUniversalTime;
    8.18  	serverGlobals.frametime = &gpGlobals->frametime;
    8.19  	serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick;
    8.20  
    8.21  	core_bridge.core_ident = g_pCoreIdent;
    8.22 -	logic_init_fn(&core_bridge, &logic);
    8.23 +	logic_init_fn(&core_bridge, &logicore);
    8.24  
    8.25  	/* Add SMGlobalClass instances */
    8.26  	SMGlobalClass* glob = SMGlobalClass::head;
    8.27 @@ -156,12 +155,12 @@
    8.28  		glob = glob->m_pGlobalClassNext;
    8.29  	}
    8.30  	assert(glob->m_pGlobalClassNext == NULL);
    8.31 -	glob->m_pGlobalClassNext = logic.head;
    8.32 +	glob->m_pGlobalClassNext = logicore.head;
    8.33  
    8.34 -	g_pThreader = logic.threader;
    8.35 -	g_pSourcePawn2->SetProfiler(logic.profiler);
    8.36 -	UTIL_CRC32 = logic.CRC32;
    8.37 -	memutils = logic.memutils;
    8.38 +	g_pThreader = logicore.threader;
    8.39 +	g_pSourcePawn2->SetProfiler(logicore.profiler);
    8.40 +	UTIL_CRC32 = logicore.CRC32;
    8.41 +	memutils = logicore.memutils;
    8.42  }
    8.43  
    8.44  bool StartLogicBridge(char *error, size_t maxlength)
     9.1 --- a/core/logic_bridge.h	Fri May 14 18:22:03 2010 -0700
     9.2 +++ b/core/logic_bridge.h	Fri May 14 19:28:10 2010 -0700
     9.3 @@ -31,13 +31,18 @@
     9.4  #ifndef _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
     9.5  #define _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
     9.6  
     9.7 +#include "logic/intercom.h"
     9.8 +
     9.9  void InitLogicBridge();
    9.10  bool StartLogicBridge(char *error, size_t maxlength);
    9.11  void ShutdownLogicBridge();
    9.12  
    9.13 +struct sm_logic_t;
    9.14 +
    9.15  typedef unsigned int (*SM_FN_CRC32)(const void *, size_t);
    9.16  
    9.17  extern SM_FN_CRC32 UTIL_CRC32;
    9.18 +extern sm_logic_t logicore;
    9.19  
    9.20  #endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */
    9.21  
    10.1 --- a/core/sm_stringutil.cpp	Fri May 14 18:22:03 2010 -0700
    10.2 +++ b/core/sm_stringutil.cpp	Fri May 14 19:28:10 2010 -0700
    10.3 @@ -1274,37 +1274,6 @@
    10.4  	return (maxlen - llen - 1);
    10.5  }
    10.6  
    10.7 -const char *stristr(const char *str, const char *substr)
    10.8 -{
    10.9 -	if (!*substr)
   10.10 -	{
   10.11 -		return ((char *)str);
   10.12 -	}
   10.13 -
   10.14 -	char *needle = (char *)substr;
   10.15 -	char *prevloc = (char *)str;
   10.16 -	char *haystack = (char *)str;
   10.17 -
   10.18 -	while (*haystack)
   10.19 -	{
   10.20 -		if (tolower(*haystack) == tolower(*needle))
   10.21 -		{
   10.22 -			haystack++;
   10.23 -			if (!*++needle)
   10.24 -			{
   10.25 -				return prevloc;
   10.26 -			}
   10.27 -		}
   10.28 -		else
   10.29 -		{
   10.30 -			haystack = ++prevloc;
   10.31 -			needle = (char *)substr;
   10.32 -		}
   10.33 -	}
   10.34 -
   10.35 -	return NULL;
   10.36 -}
   10.37 -
   10.38  unsigned int strncopy(char *dest, const char *src, size_t count)
   10.39  {
   10.40  	if (!count)
    11.1 --- a/core/sm_stringutil.h	Fri May 14 18:22:03 2010 -0700
    11.2 +++ b/core/sm_stringutil.h	Fri May 14 19:28:10 2010 -0700
    11.3 @@ -43,7 +43,6 @@
    11.4  #define IS_STR_FILLED(var) (var[0] != '\0')
    11.5  
    11.6  size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param);
    11.7 -const char *stristr(const char *str, const char *substr);
    11.8  unsigned int strncopy(char *dest, const char *src, size_t count);
    11.9  bool gnprintf(char *buffer,
   11.10  			  size_t maxlen,
    12.1 --- a/core/smn_string.cpp	Fri May 14 18:22:03 2010 -0700
    12.2 +++ b/core/smn_string.cpp	Fri May 14 19:28:10 2010 -0700
    12.3 @@ -35,6 +35,7 @@
    12.4  #include "sm_stringutil.h"
    12.5  #include <ITextParsers.h>
    12.6  #include <ctype.h>
    12.7 +#include "logic_bridge.h"
    12.8  
    12.9  inline const char *_strstr(const char *str, const char *substr)
   12.10  {
   12.11 @@ -68,7 +69,7 @@
   12.12  	pCtx->LocalToString(params[1], &str);
   12.13  	pCtx->LocalToString(params[2], &substr);
   12.14  
   12.15 -	func = (params[3]) ? _strstr : stristr;
   12.16 +	func = (params[3]) ? _strstr : logicore.stristr;
   12.17  	const char *pos = func(str, substr);
   12.18  	if (pos)
   12.19  	{