diff options
Diffstat (limited to 'Ivy')
-rw-r--r-- | Ivy/IvyApplication.cxx | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/Ivy/IvyApplication.cxx b/Ivy/IvyApplication.cxx index f0d4f75..faafaf4 100644 --- a/Ivy/IvyApplication.cxx +++ b/Ivy/IvyApplication.cxx @@ -4,7 +4,8 @@ #include "stdafx.h"
#include "IvyApplication.h"
-#include "Regexp.h"
+
+
//#define IVY_DEBUG
@@ -55,7 +56,10 @@ IvyApplication::~IvyApplication() {
// bus->RemoveApplication( this );
for ( unsigned int i = 0; i < regexp_in.size(); i++)
+#ifdef USE_PCRE
+#else
delete regexp_in[i];
+#endif
regexp_in.clear();
if ( m_hSocket != INVALID_SOCKET )
Close();
@@ -95,12 +99,19 @@ void IvyApplication::OnReceive(char * line) int err;
unsigned int id;
int kind_of_msg = Bye;
+ char *arg;
+ int argc = 0;
+
+#ifdef USE_PCRE
+ pcre *exp;
+ const char *argv[max_subexp];
+ const char *errmsg;
+ int erroffset;
+#else
Regexp *exp;
-
-
- int argc = 0;
const char *argv[Regexp::NSUBEXP];
- char *arg;
+#endif
+
#ifdef IVY_DEBUG
TRACE("Receive %s\n",line);
@@ -149,6 +160,19 @@ void IvyApplication::OnReceive(char * line) #endif //IVY_DEBUG
return;
}
+#ifdef USE_PCRE
+ exp = pcre_compile( arg, PCRE_CASELESS, &errmsg, &erroffset, NULL );
+ if ( !exp )
+ {
+ string err( "Error can't compile regexp '" );
+ err += arg;
+ err += "' error ";
+ err += errmsg;
+ SendMsg( Error, Error, err.c_str() );
+ TRACE("IvyApplication %s\n",err.c_str());
+ return;
+ }
+#else
exp = new Regexp( arg );
if ( !exp->CompiledOK() )
{
@@ -160,6 +184,7 @@ void IvyApplication::OnReceive(char * line) TRACE("IvyApplication %s\n",err.c_str());
return;
}
+#endif
if ( regexp_in.size() < (id + 1) )
regexp_in.resize( id + 1 );
regexp_in[ id ] = exp;
@@ -175,7 +200,10 @@ void IvyApplication::OnReceive(char * line) if ( regexp_in[id] )
{
exp = regexp_in[ id ];
+#ifdef USE_PCRE
+#else
delete exp;
+#endif
regexp_in[ id ] = NULL;
}
break;
@@ -289,7 +317,11 @@ void IvyApplication::OnClose(int nErrorCode) bus->CallApplicationDisconnectedCallback( this );
for ( unsigned int i = 0; i < regexp_in.size(); i++)
+#ifdef USE_PCRE
+ pcre_free( regexp_in[i] );
+#else
delete regexp_in[i];
+#endif
regexp_in.clear();
Close();
// bus->RemoveApplication( this );
@@ -298,12 +330,33 @@ void IvyApplication::OnClose(int nErrorCode) int IvyApplication::SendMsg(const char *message)
{
int count = 0;
+#ifdef USE_PCRE
+ pcre *exp;
+ int ovector[max_subexp*3];
+#else
Regexp *exp;
+#endif
/* send to already connected */
for ( unsigned int i = 0; i < regexp_in.size(); i++ )
{
exp = regexp_in[i];
-
+#ifdef USE_PCRE
+ int match_count = pcre_exec( exp, NULL, message, strlen( message ), 0, 0, ovector, max_subexp );
+ if ( match_count > 1 )
+ {
+ string buffer;
+ const char *substring;
+ for ( int j = 1; j < match_count; j++ )
+ {
+ pcre_get_substring(message, ovector, match_count, j, &substring);
+ buffer += substring;
+ buffer += ARG_END;
+ pcre_free_substring( substring );
+ }
+ SendMsg( Msg, i, buffer.c_str() );
+ count++;
+ }
+#else
if ( exp && exp->Match( message ) )
{
string buffer;
@@ -315,6 +368,7 @@ int IvyApplication::SendMsg(const char *message) SendMsg( Msg, i, buffer.c_str() );
count++;
}
+#endif
}
return count;
}
|