From 380f560fa4537ee7dfabb63997b93ee791e5f414 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 5 Oct 2004 08:32:23 +0000 Subject: [PATCH] Finalized (not tested!) --- dlls/regex/module.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/dlls/regex/module.cpp b/dlls/regex/module.cpp index 32d1e14c..73fe604f 100755 --- a/dlls/regex/module.cpp +++ b/dlls/regex/module.cpp @@ -36,7 +36,7 @@ static cell AMX_NATIVE_CALL regex_match(AMX *amx, cell *params) const char *err = x->mError; *eOff = x->mErrorOffset; MF_SetAmxString(amx, params[4], err?err:"unknown", params[5]); - return 0; + return -1; } int e = x->Match(str); @@ -46,7 +46,11 @@ static cell AMX_NATIVE_CALL regex_match(AMX *amx, cell *params) cell *res = MF_GetAmxAddr(amx, params[3]); *res = x->mErrorOffset; x->Clear(); - return -1; + return -2; + } else if (e == 0) { + *res = 0; + x->Clear(); + return 0; } else { cell *res = MF_GetAmxAddr(amx, params[3]); *res = x->mSubStrings; @@ -78,9 +82,27 @@ static cell AMX_NATIVE_CALL regex_substr(AMX *amx, cell *params) return 1; } +static cell AMX_NATIVE_CALL regex_free(AMX *amx, cell *params) +{ + cell *c = MF_GetAmxAddr(amx, params[1]); + int id = *c; + *c = 0; + if (id >= (int)PEL.size() || id < 0 || PEL[id]->isFree()) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id); + return 0; + } + + RegEx *x = PEL[id]; + x->Clear(); + + return 1; +} + AMX_NATIVE_INFO regex_Natives[] = { {"regex_match", regex_match}, {"regex_substr", regex_substr}, + {"regex_free", regex_free}, {NULL, NULL}, };