diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b60f31..7036aa8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ find_package(Iconv REQUIRED) find_package(JNI REQUIRED) find_package(LibXml2 REQUIRED) find_package(Oracle REQUIRED) +find_package(PCRE REQUIRED) find_package(Perl REQUIRED) find_package(STLPort REQUIRED) find_package(ZLib REQUIRED) diff --git a/cmake/FindPCRE.cmake b/cmake/FindPCRE.cmake new file mode 100644 index 00000000..eb3c2da7 --- /dev/null +++ b/cmake/FindPCRE.cmake @@ -0,0 +1,29 @@ + +find_path(PCRE_ROOT + NAMES include/pcre.h +) + +find_path(PCRE_INCLUDE_DIR pcre.h + HINTS + $ENV{PCRE_ROOT} + PATH_SUFFIXES include + PATHS + ${PCRE_ROOT} + ${PCRE_INCLUDEDIR} +) + +find_library(PCRE_LIBRARY + NAMES pcre libpcre + PATH_SUFFIXES lib + HINTS + $ENV{PCRE_ROOT} + ${PCRE_ROOT} + ${PCRE_LIBRARYDIR} +) + +# handle the QUIETLY and REQUIRED arguments and set OPENAL_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR) + +mark_as_advanced(PCRE_ROOT PCRE_INCLUDE_DIR PCRE_LIBRARY) diff --git a/engine/shared/library/CMakeLists.txt b/engine/shared/library/CMakeLists.txt index e327667e..94a5d742 100644 --- a/engine/shared/library/CMakeLists.txt +++ b/engine/shared/library/CMakeLists.txt @@ -20,6 +20,7 @@ add_subdirectory(sharedNetworkMessages) add_subdirectory(sharedObject) add_subdirectory(sharedPathfinding) add_subdirectory(sharedRandom) +add_subdirectory(sharedRegex) add_subdirectory(sharedSkillSystem) add_subdirectory(sharedSynchronization) add_subdirectory(sharedTerrain) diff --git a/engine/shared/library/sharedRegex/CMakeLists.txt b/engine/shared/library/sharedRegex/CMakeLists.txt new file mode 100644 index 00000000..ab238dd7 --- /dev/null +++ b/engine/shared/library/sharedRegex/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +project(sharedRegex) + +if(WIN32) + add_definitions(/D_CRT_SECURE_NO_WARNINGS) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public) + +add_subdirectory(src) diff --git a/engine/shared/library/sharedRegex/include/public/sharedRegex/ConfigSharedRegex.h b/engine/shared/library/sharedRegex/include/public/sharedRegex/ConfigSharedRegex.h new file mode 100644 index 00000000..1e7a7483 --- /dev/null +++ b/engine/shared/library/sharedRegex/include/public/sharedRegex/ConfigSharedRegex.h @@ -0,0 +1 @@ +#include "../../src/shared/ConfigSharedRegex.h" diff --git a/engine/shared/library/sharedRegex/include/public/sharedRegex/FirstSharedRegex.h b/engine/shared/library/sharedRegex/include/public/sharedRegex/FirstSharedRegex.h new file mode 100644 index 00000000..97579fa8 --- /dev/null +++ b/engine/shared/library/sharedRegex/include/public/sharedRegex/FirstSharedRegex.h @@ -0,0 +1 @@ +#include "../../src/shared/FirstSharedRegex.h" diff --git a/engine/shared/library/sharedRegex/include/public/sharedRegex/RegexServices.h b/engine/shared/library/sharedRegex/include/public/sharedRegex/RegexServices.h new file mode 100644 index 00000000..f4c5d0f5 --- /dev/null +++ b/engine/shared/library/sharedRegex/include/public/sharedRegex/RegexServices.h @@ -0,0 +1,7 @@ +#if defined(PLATFORM_WIN32) +#include "../../src/win32/RegexServices.h" +#elif defined(PLATFORM_LINUX) +#include "../../src/linux/RegexServices.h" +#else +#error unsupported platform +#endif diff --git a/engine/shared/library/sharedRegex/include/public/sharedRegex/SetupSharedRegex.h b/engine/shared/library/sharedRegex/include/public/sharedRegex/SetupSharedRegex.h new file mode 100644 index 00000000..cb5b06a1 --- /dev/null +++ b/engine/shared/library/sharedRegex/include/public/sharedRegex/SetupSharedRegex.h @@ -0,0 +1 @@ +#include "../../src/shared/SetupSharedRegex.h" diff --git a/engine/shared/library/sharedRegex/src/CMakeLists.txt b/engine/shared/library/sharedRegex/src/CMakeLists.txt new file mode 100644 index 00000000..e7f924d1 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/CMakeLists.txt @@ -0,0 +1,39 @@ + +set(SHARED_SOURCES + shared/ConfigSharedRegex.cpp + shared/ConfigSharedRegex.h + shared/FirstSharedRegex.h + shared/SetupSharedRegex.cpp + shared/SetupSharedRegex.h +) + +if(WIN32) + set(PLATFORM_SOURCES + win32/FirstSharedRegex.cpp + win32/RegexServices.cpp + win32/RegexServices.h + ) + + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32) +else() + set(PLATFORM_SOURCES + linux/RegexServices.cpp + linux/RegexServices.h + ) + + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/linux) +endif() + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/shared + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public + ${PCRE_INCLUDE_DIR} +) + +add_library(sharedRegex STATIC + ${SHARED_SOURCES} + ${PLATFORM_SOURCES} +) diff --git a/engine/shared/library/sharedRegex/src/linux/RegexServices.cpp b/engine/shared/library/sharedRegex/src/linux/RegexServices.cpp new file mode 100644 index 00000000..ea5464e7 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/linux/RegexServices.cpp @@ -0,0 +1,26 @@ +// ====================================================================== +// +// RegexServices.cpp +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "sharedRegex/FirstSharedRegex.h" +#include "sharedRegex/RegexServices.h" + +// ====================================================================== + +void *RegexServices::allocateMemory(size_t byteCount) +{ + return new char[byteCount]; +} + +// ---------------------------------------------------------------------- + +void RegexServices::freeMemory(void *pointer) +{ + delete [] reinterpret_cast(pointer); +} + +// ====================================================================== diff --git a/engine/shared/library/sharedRegex/src/linux/RegexServices.h b/engine/shared/library/sharedRegex/src/linux/RegexServices.h new file mode 100644 index 00000000..762c80de --- /dev/null +++ b/engine/shared/library/sharedRegex/src/linux/RegexServices.h @@ -0,0 +1,25 @@ +// ====================================================================== +// +// RegexServices.h +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_RegexServices_H +#define INCLUDED_RegexServices_H + +// ====================================================================== + +class RegexServices +{ +public: + + static void *allocateMemory(size_t byteCount); + static void freeMemory(void *pointer); + +}; + +// ====================================================================== + +#endif diff --git a/engine/shared/library/sharedRegex/src/shared/ConfigSharedRegex.cpp b/engine/shared/library/sharedRegex/src/shared/ConfigSharedRegex.cpp new file mode 100644 index 00000000..7dc578d6 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/shared/ConfigSharedRegex.cpp @@ -0,0 +1,42 @@ +// ====================================================================== +// +// ConfigSharedRegex.cpp +// copyright 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "sharedRegex/FirstSharedRegex.h" +#include "sharedRegex/ConfigSharedRegex.h" + +#include "sharedFoundation/ConfigFile.h" + +// ====================================================================== + +#define KEY_BOOL(a,b) (ms_ ## a = ConfigFile::getKeyBool("SharedRegex", #a, (b))) + +// ====================================================================== + +namespace ConfigSharedRegexNamespace +{ + bool ms_sample; +} + +using namespace ConfigSharedRegexNamespace; + +// ====================================================================== + +void ConfigSharedRegex::install() +{ + KEY_BOOL(sample, false); +} + +// ---------------------------------------------------------------------- + +bool ConfigSharedRegex::getSample() +{ + return ms_sample; +} + +// ====================================================================== + + diff --git a/engine/shared/library/sharedRegex/src/shared/ConfigSharedRegex.h b/engine/shared/library/sharedRegex/src/shared/ConfigSharedRegex.h new file mode 100644 index 00000000..8b3ba345 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/shared/ConfigSharedRegex.h @@ -0,0 +1,24 @@ +// ====================================================================== +// +// ConfigSharedRegex.h +// Copyright 2004, Sony Online Entertainment Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_ConfigSharedRegex_H +#define INCLUDED_ConfigSharedRegex_H + +// ====================================================================== + +class ConfigSharedRegex +{ +public: + + static void install(); + static bool getSample(); +}; + +// ====================================================================== + +#endif diff --git a/engine/shared/library/sharedRegex/src/shared/FirstSharedRegex.h b/engine/shared/library/sharedRegex/src/shared/FirstSharedRegex.h new file mode 100644 index 00000000..d46a7d5c --- /dev/null +++ b/engine/shared/library/sharedRegex/src/shared/FirstSharedRegex.h @@ -0,0 +1,18 @@ +// ====================================================================== +// +// FirstSharedRegex.h +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_FirstSharedRegex_H +#define INCLUDED_FirstSharedRegex_H + +// ====================================================================== + +#include "sharedFoundation/FirstSharedFoundation.h" + +// ====================================================================== + +#endif diff --git a/engine/shared/library/sharedRegex/src/shared/SetupSharedRegex.cpp b/engine/shared/library/sharedRegex/src/shared/SetupSharedRegex.cpp new file mode 100644 index 00000000..d0273670 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/shared/SetupSharedRegex.cpp @@ -0,0 +1,70 @@ +// ====================================================================== +// +// SetupSharedRegex.cpp +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "sharedRegex/FirstSharedRegex.h" +#include "sharedRegex/SetupSharedRegex.h" + +#include "sharedDebug/InstallTimer.h" +#include "sharedFoundation/ExitChain.h" +#include "sharedRegex/ConfigSharedRegex.h" +#include "sharedRegex/RegexServices.h" +#include "pcre.h" + +// ====================================================================== + +namespace SetupSharedRegexNamespace +{ + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + void remove(); + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + bool s_installed; + + void *(*s_oldMalloc)(size_t); + void (*s_oldFree)(void*); +} + +using namespace SetupSharedRegexNamespace; + +// ====================================================================== + +void SetupSharedRegexNamespace::remove() +{ + DEBUG_FATAL(!s_installed, ("SetupSharedRegex not installed.")); + s_installed = false; + + //-- Restore malloc and free functions. + pcre_malloc = s_oldMalloc; + pcre_free = s_oldFree; +} + +// ====================================================================== + +void SetupSharedRegex::install() +{ + InstallTimer const installTimer("SetupSharedRegex::install"); + + DEBUG_FATAL(s_installed, ("SetupSharedRegex already installed.")); + + ConfigSharedRegex::install(); + + //-- Save old malloc and free functions. + s_oldMalloc = pcre_malloc; + s_oldFree = pcre_free; + + //-- Hook up PCRE malloc and free to our memory manager. + pcre_malloc = &RegexServices::allocateMemory; + pcre_free = &RegexServices::freeMemory; + + s_installed = true; + ExitChain::add(remove, "SetupSharedRegex"); +} + +// ====================================================================== diff --git a/engine/shared/library/sharedRegex/src/shared/SetupSharedRegex.h b/engine/shared/library/sharedRegex/src/shared/SetupSharedRegex.h new file mode 100644 index 00000000..0d244918 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/shared/SetupSharedRegex.h @@ -0,0 +1,24 @@ +// ====================================================================== +// +// SetupSharedRegex.h +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_SetupSharedRegex_H +#define INCLUDED_SetupSharedRegex_H + +// ====================================================================== + +class SetupSharedRegex +{ +public: + + static void install(); + +}; + +// ====================================================================== + +#endif diff --git a/engine/shared/library/sharedRegex/src/win32/FirstSharedRegex.cpp b/engine/shared/library/sharedRegex/src/win32/FirstSharedRegex.cpp new file mode 100644 index 00000000..d219edf0 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/win32/FirstSharedRegex.cpp @@ -0,0 +1,9 @@ +// ====================================================================== +// +// FirstSharedRegex.cpp +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "sharedRegex/FirstSharedRegex.h" diff --git a/engine/shared/library/sharedRegex/src/win32/RegexServices.cpp b/engine/shared/library/sharedRegex/src/win32/RegexServices.cpp new file mode 100644 index 00000000..c12a1c67 --- /dev/null +++ b/engine/shared/library/sharedRegex/src/win32/RegexServices.cpp @@ -0,0 +1,57 @@ +// ====================================================================== +// +// RegexServices.cpp +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#include "sharedRegex/FirstSharedRegex.h" +#include "sharedRegex/RegexServices.h" + +// ====================================================================== + +static void * __cdecl localAllocate(size_t size, uint32 owner, bool array, bool leakTest) +{ + return MemoryManager::allocate(size, owner, array, leakTest); +} + +static __declspec(naked) void * regexAllocate(size_t) +{ + _asm + { + // setup local call stack + push ebp + mov ebp, esp + + // MemoryManager::alloc(size, [return address], false, true) + push 1 + push 0 + mov eax, dword ptr [ebp+4] + push eax + mov eax, dword ptr [ebp+8] + push eax + call localAllocate + add esp, 12 + + mov esp, ebp + pop ebp + ret + } +} + +// ---------------------------------------------------------------------- + +void *RegexServices::allocateMemory(size_t byteCount) +{ + return regexAllocate(byteCount); +} + +// ---------------------------------------------------------------------- + +void RegexServices::freeMemory(void *pointer) +{ + MemoryManager::free(pointer, false); +} + +// ====================================================================== diff --git a/engine/shared/library/sharedRegex/src/win32/RegexServices.h b/engine/shared/library/sharedRegex/src/win32/RegexServices.h new file mode 100644 index 00000000..762c80de --- /dev/null +++ b/engine/shared/library/sharedRegex/src/win32/RegexServices.h @@ -0,0 +1,25 @@ +// ====================================================================== +// +// RegexServices.h +// Copyright 2003 Sony Online Entertainment, Inc. +// All Rights Reserved. +// +// ====================================================================== + +#ifndef INCLUDED_RegexServices_H +#define INCLUDED_RegexServices_H + +// ====================================================================== + +class RegexServices +{ +public: + + static void *allocateMemory(size_t byteCount); + static void freeMemory(void *pointer); + +}; + +// ====================================================================== + +#endif