Regex: Use AMTL.

This commit is contained in:
Arkshine 2014-07-06 12:13:01 +02:00
parent 08475bb0cc
commit ee4f6b8a89
3 changed files with 49 additions and 47 deletions

View File

@ -10,8 +10,10 @@ elif builder.target_platform == 'mac':
elif builder.target_platform == 'windows':
binary.compiler.postlink += [binary.Dep('lib_win\\pcre.lib')]
binary.compiler.defines += ['PCRE_STATIC']
binary.compiler.defines += [
'PCRE_STATIC',
'HAVE_STDINT_H',
]
binary.sources = [
'sdk/amxxmodule.cpp',
'module.cpp',

View File

@ -33,23 +33,23 @@
#include <string.h>
#include "pcre.h"
#include "amxxmodule.h"
#include "CVector.h"
#include <am-vector.h>
#include "CRegEx.h"
CVector<RegEx *> PEL;
ke::Vector<RegEx *> PEL;
int GetPEL()
{
for (int i=0; i<(int)PEL.size(); i++)
for (int i=0; i<(int)PEL.length(); i++)
{
if (PEL[i]->isFree())
return i;
}
RegEx *x = new RegEx();
PEL.push_back(x);
PEL.append(x);
return (int)PEL.size() - 1;
return (int)PEL.length() - 1;
}
// native Regex:regex_compile(const pattern[], &ret, error[], maxLen, const flags[]="");
@ -150,7 +150,7 @@ static cell AMX_NATIVE_CALL regex_match_c(AMX *amx, cell *params)
int id = params[2]-1;
const char *str = MF_GetAmxString(amx, params[1], 0, &len);
if (id >= (int)PEL.size() || id < 0 || PEL[id]->isFree())
if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
return 0;
@ -187,7 +187,7 @@ static cell AMX_NATIVE_CALL regex_match_ex(AMX *amx, cell *params)
{
int id = params[1] - 1;
if (id >= (int)PEL.size() || id < 0 || PEL[id]->isFree())
if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
return 0;
@ -226,7 +226,7 @@ static cell AMX_NATIVE_CALL regex_match_ex(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL regex_substr(AMX *amx, cell *params)
{
int id = params[1]-1;
if (id >= (int)PEL.size() || id < 0 || PEL[id]->isFree())
if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
return 0;
@ -252,7 +252,7 @@ static cell AMX_NATIVE_CALL regex_free(AMX *amx, cell *params)
int id = *c;
*c = 0;
id -= 1;
if (id >= (int)PEL.size() || id < 0 || PEL[id]->isFree())
if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
return 0;
@ -282,7 +282,7 @@ void OnAmxxAttach()
void OnAmxxDetach()
{
for (int i = 0; i<(int)PEL.size(); i++)
for (int i = 0; i<(int)PEL.length(); i++)
{
if (PEL[i])
{

View File

@ -52,8 +52,8 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\;..\sdk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;REGEX_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\;..\..\..\public\amtl;..\sdk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;REGEX_EXPORTS;HAVE_STDINT_H;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@ -75,8 +75,8 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\;..\sdk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;REGEX_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\;..\..\..\public\amtl;..\sdk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;REGEX_EXPORTS;HAVE_STDINT_H;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>