Jump to content
  • 0
AnnieRuru

port *preg_match from rathena

Question

http://upaste.me/868111089e57a3d30

 

there is something funny about this plugin

 

1.

if I uncomment the //#ifdef PCRE_SUPPORT

even though I have PCRE compiled, but it always go under the #else statement ... dunno why

 

2.

and the only way to make this work porperly is also

uncomment the #ifdef PCRE_SUPPORT inside npc.h !!

https://github.com/HerculesWS/Hercules/blob/master/src/map/npc.h#L285

 

maybe its my compiler problem ? microsoft visual basic 2010

Share this post


Link to post
Share on other sites

13 answers to this question

Recommended Posts

  • 0

after 1 year ++....

https://github.com/HerculesWS/Hercules/issues/909#issuecomment-163911353

finally able to solve this

#include "common/hercules.h"#include <stdio.h>#include <string.h>#include <stdlib.h>#include "map/script.h"#include "../3rdparty/pcre/include/pcre.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 );}
I also edited the wiki to reflect the change

http://herc.ws/wiki/Building_HPM_Plugin_for_MSVC#PCRE_SUPPORT

Share this post


Link to post
Share on other sites
  • 0

http://upaste.me/868111089e57a3d30

 

there is something funny about this plugin

 

1.

if I uncomment the //#ifdef PCRE_SUPPORT

even though I have PCRE compiled, but it always go under the #else statement ... dunno why

 

2.

and the only way to make this work probably is also

uncomment the #ifdef PCRE_SUPPORT inside npc.h !!

https://github.com/HerculesWS/Hercules/blob/master/src/map/npc.h#L285

 

maybe its my compiler problem ? microsoft visual basic 2010

 

Yeah, seems to be windows compiler problem.. :P This is what I'm experiencing with installing the server side manners plugin by odin.. :P

 

When I tried to compile the same plugin with linux, it compiled properly but the plugin doesn't load ( but it seems to be the plugin source itself)...

Share this post


Link to post
Share on other sites
  • 0

I cant compile it

 

In GCC

        CC      regexp.cregexp.c: In function ‘buildin_regexp’:regexp.c:47: error: ‘libpcre’ undeclared (first use in this function)regexp.c:47: error: (Each undeclared identifier is reported only onceregexp.c:47: error: for each function it appears in.)regexp.c: In function ‘plugin_init’:regexp.c:71: error: ‘libpcre’ undeclared (first use in this function)make[1]: *** [../../plugins/regexp.so] Error 1make[1]: Leaving directory `/root/rosfus/trunk/src/plugins'make: *** [plugins] Error 2

 

In MSVC 2010

1>------ 已启动全部重新生成: 项目: regexp, 配置: Release Win32 ------1>生成启动时间为 2014/3/12 7:19:52。1>InitializeBuildStatus:1>  正在创建“regexpregexp.unsuccessfulbuild”,因为已指定“AlwaysCreate”。1>ClCompile:1>  regexp.c1>..srcpluginsregexp.c(47): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(47): error C2223: “->compile”的左侧必须指向结构/联合1>..srcpluginsregexp.c(48): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(48): error C2223: “->study”的左侧必须指向结构/联合1>..srcpluginsregexp.c(50): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(50): error C2223: “->exec”的左侧必须指向结构/联合1>..srcpluginsregexp.c(52): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(52): error C2223: “->free”的左侧必须指向结构/联合1>..srcpluginsregexp.c(54): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(54): error C2223: “->free”的左侧必须指向结构/联合1>..srcpluginsregexp.c(71): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(71): warning C4047: “=”:“int”与“void *”的间接级别不同1>1>生成失败。1>1>已用时间 00:00:03.55========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========

Share this post


Link to post
Share on other sites
  • 0

[member=安赫尔]

 

Hmm, did you run ./configure in linux, if  yes, did you see if pcre being said yes during the configuration..

 

Then, when it comes to plugins, i think you need to add this in the makefile when compiling pcre plugins,

 

 

../../plugins/pluginname@DLLEXT@: pluginname.c $(ALL_H)
@echo " CC $<"
@$(CC) -lpcre @DEFS@ @CFLAGS@ @CPPFLAGS@ @LDFLAGS@ @SOFLAGS@ -o $@ $<

Share this post


Link to post
Share on other sites
  • 0

so its not my compiler problem, many member else experiencing this issue

seems to me like the pcre are not compatible with plugins

 

@samuel

I'm using windows with microsoft visual express so

I also try fix odin server side manner

http://upaste.me/a7a2110923a939b03

and my compiler throw this error

2>whisp.obj : error LNK2019: unresolved external symbol __imp__pcre_exec referenced in function _filter_chat2>whisp.obj : error LNK2019: unresolved external symbol __imp__pcre_study referenced in function _read_manner2>whisp.obj : error LNK2019: unresolved external symbol __imp__pcre_compile referenced in function _read_manner2>whisp.obj : error LNK2001: unresolved external symbol __imp__pcre_free2>..pluginswhisp.dll : fatal error LNK1120: 4 unresolved externals
that is the reason I'm actually using libpcre->compile, libpcre->study and so on because it has already defined in npc_chat.c

https://github.com/HerculesWS/Hercules/blob/master/src/map/npc_chat.c#L436

 

that's why ...

 

@安赫尔

yes, like I said in my 2nd point

to make this plugin works,

comment the line inside npc.h

line 285, change #ifdef PCRE_SUPPORT into //#ifdef PCRE_SUPPORT

line 348, change #endif into //#endif

then this plugin will work

but doing like this will defeat the purpose of making a plugin, because plugin means you don't have to touch the source ?

 

the patch is actually working though

http://upaste.me/c4861109339c41185

but not the plugin ...

 

maybe I should do a pull request ...

Share this post


Link to post
Share on other sites
  • 0

Well, this error LNK2019: unresolved external symbol also happens with some source I'm converting into plugin..

 

It's like that it was already defined in the included source, but plugins can't get it or something.. :D

 

I remember that I tried to define the unresolved external symbol within the plugin code itself and the warning disappeared.. :P

Share this post


Link to post
Share on other sites
  • 0

I remember that I tried to define the unresolved external symbol within the plugin code itself and the warning disappeared.. :P

//===== Hercules Plugin ======================================//= *regexp Script Command//===== By: ==================================================//= AnnieRuru//===== Current Version: =====================================//= 1.0//===== Compatible With: ===================================== //= Hercules 2014-03-12//===== Description: =========================================//= check the string match with regular expression//===== Topic ================================================//= none//===== Additional Comments: =================================  //= rip off from rathena *preg_match//============================================================#include <stdio.h>#include <string.h>#include <stdlib.h>#include "../map/npc.h"#include "../map/script.h"#include "../common/HPMi.h"#include "../../3rdparty/pcre/include/pcre.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) {#ifdef PCRE_SUPPORT	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 = libpcre->compile(pattern, 0, &error, &erroffset, NULL);	pcreExtra = libpcre->study(re, 0, &error);	r = libpcre->exec(re, pcreExtra, subject, (int)strlen(subject), offset, 0, subStrVec, 30);	libpcre->free(re);	if (pcreExtra != NULL)		libpcre->free(pcreExtra);	if (r < 0)		script_pushint(st,0);	else		script_pushint(st,(r > 0) ? r : 30 / 3);	return true;#else	ShowError( "buildin_regexp: Cannot run because PCRE library are disabled.n" );	script_pushint(st,0);	return false;#endif}HPExport void plugin_init (void) {#ifdef PCRE_SUPPORT	script = GET_SYMBOL("script");	libpcre = GET_SYMBOL("libpcre");	addScriptCommand( "regexp", "ss?", regexp );#else	ShowError( "buildin_regexp: Cannot run because PCRE library are disabled.n" );#endif}
yeah ... yeah ... the error disappeared

but you also get the ShowError warning saying that it is disabled

Share this post


Link to post
Share on other sites
  • 0

Well seems to be a limitation for the plugin system as of now.. :)

 

Although I hope there would be great updates with it, :D

Share this post


Link to post
Share on other sites
  • 0

after 1 year ++....https://github.com/HerculesWS/Hercules/issues/909#issuecomment-163911353finally able to solve this

#include "common/hercules.h"#include <stdio.h>#include <string.h>#include <stdlib.h>#include "map/script.h"#include "../3rdparty/pcre/include/pcre.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 );}
I also edited the wiki to reflect the changehttp://herc.ws/wiki/Building_HPM_Plugin_for_MSVC#PCRE_SUPPORT
For Linux: http://upaste.me/2220e2

^ this change is required.

Share this post


Link to post
Share on other sites
  • 0

@@Dastgir

do that in the wiki ...

 

its useless to tell in the topic because not everyone will read this,

but everyone in the wiki will see what you posted

Share this post


Link to post
Share on other sites
  • 0

@@Dastgir

do that in the wiki ...

 

its useless to tell in the topic because not everyone will read this,

but everyone in the wiki will see what you posted

As hemagx said, This is temporary solution, till HpmHook is fixed.

Share this post


Link to post
Share on other sites
  • 0

oh thanks for the yellbox ... I was just about to edit the title though

 

ok time to try out the command

prontera,159,183,5	script	pcre_match	1_F_MARIA,{	input .@t$;	if ( "([a-z])$" ~= .@t$ )		npctalk "It's a "+ $@regexmatch$[0];	close;L_1:	npctalk "It's a "+ $@p2$;	end;OnInit:	defpattern 1, "^[^:]+: (|d{2})?([a-z]).$", "L_1";	activatepset 1;	end;}prontera,155,183,5	script	regexp	1_F_MARIA,{	input .@t$;	if ( regexp("([a-z])$", .@t$ ) )		npctalk "It's a ... ";	close;}
Haru's regular expression ...

this is bug ... why that only accept a,z,- ... three characters only

 

regexp in this plugin is accurate, can accept anything between abcde...z

but cannot export the result set

the symbol for the end line, has to be $

 

defpattern ... works great as many members already using it

but the symbol for the end line, has to be .$

 

omg, so many patterns !

Edited by AnnieRuru

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.