#include "common/hercules.h" #include #include #include #include "map/npc.h" #include "map/script.h" #include "../3rdparty/pcre/include/pcre.h" #include #include "common/strlib.h" #include "common/HPMDataCheck.h" // should always be the last file included! (if you don't make it last, it'll intentionally break compile time) HPExport struct hplugin_info pinfo = { "regexp", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated) }; BUILDIN(regexp) { pcre *re; pcre_extra *pcreExtra; const char *error; int erroffset, r, offset = 0; int subStrVec[30]; const char* pattern = script_getstr(st,2); const char* subject = script_getstr(st,3); if (script_hasdata(st,4)) offset = script_getnum(st,4); re = pcre_compile(pattern, 0, &error, &erroffset, NULL); pcreExtra = pcre_study(re, 0, &error); r = pcre_exec(re, pcreExtra, subject, (int)strlen(subject), offset, 0, subStrVec, 30); pcre_free(re); if (pcreExtra != NULL) pcre_free(pcreExtra); if (r < 0) script_pushint(st,0); else script_pushint(st,(r > 0) ? r : 30 / 3); return true; } HPExport void plugin_init (void) { addScriptCommand( "regexp", "ss?", regexp ); }