summaryrefslogtreecommitdiff
path: root/src/ivy.c
diff options
context:
space:
mode:
authorjestin2004-06-25 18:27:39 +0000
committerjestin2004-06-25 18:27:39 +0000
commita1eb3a36064e13c725c6d8f6301b43a431783afd (patch)
tree1fea5158059206014f374ba5a5a439d623a43e65 /src/ivy.c
parentcfc602e2408bf90cce7be62f3f1e940cd5af7172 (diff)
downloadivy-c-a1eb3a36064e13c725c6d8f6301b43a431783afd.zip
ivy-c-a1eb3a36064e13c725c6d8f6301b43a431783afd.tar.gz
ivy-c-a1eb3a36064e13c725c6d8f6301b43a431783afd.tar.bz2
ivy-c-a1eb3a36064e13c725c6d8f6301b43a431783afd.tar.xz
le Makefile peut être utilisé sur Solaris, OSX et Linux. Par dégaut, c'est
pour linux. ivy.c corrige un unbindmsg ivyprobe: -n pour le nom de l'agent, -v pour la version de la lib ivytcl: plein de problèmes réglés, d'autres introduits, notamment pour la gestion de la boucle d'évéenents sous windows ... Test.tcl déplacé dans les exemples
Diffstat (limited to 'src/ivy.c')
-rw-r--r--src/ivy.c84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/ivy.c b/src/ivy.c
index 870e6fc..1a019c8 100644
--- a/src/ivy.c
+++ b/src/ivy.c
@@ -23,7 +23,12 @@
#include <stdarg.h>
#include <ctype.h>
+#ifndef USE_PCRE_REGEX
#include <regex.h>
+#else
+#define OVECSIZE 60 /* must be multiple of 3, for regexp return */
+#include <pcre.h>
+#endif
#include <fcntl.h>
@@ -76,7 +81,12 @@ struct _msg_snd { /* requete de reception d'un client */
MsgSndPtr next;
int id;
char *str_regexp; /* la regexp sous forme inhumaine */
+#ifndef USE_PCRE_REGEX
regex_t regexp; /* la regexp sous forme machine */
+#else
+ pcre *regexp;
+ pcre_extra *inspect;
+#endif
};
struct _clnt_lst {
@@ -168,6 +178,40 @@ static void IvyCleanup()
SocketClose( broadcast );
}
+#ifdef USE_PCRE_REGEX
+static int
+MsgCall (const char *message, MsgSndPtr msg, Client client)
+{
+ int ovector[OVECSIZE];
+ int index;
+ int rc=pcre_exec(
+ msg->regexp,
+ msg->inspect,
+ message,
+ strlen(message),
+ 0, /* debut */
+ 0, /* no other regexp option */
+ ovector,
+ OVECSIZE);
+ if (rc<1) return 0; /* no match */
+#ifdef DEBUG
+ printf( "Sending message id=%d '%s'\n",msg->id,message);
+#endif
+ SocketSend( client, "%d %d" ARG_START ,Msg, msg->id);
+#ifdef DEBUG
+ printf( "Send matching args count %ld\n",msg->regexp.re_nsub);
+#endif
+ index=1;
+ while ( index<rc ) {
+ SocketSend( client, "%.*s" ARG_END , ovector[2*index+1]- ovector[2*index],
+ message + ovector[2*index]);
+ ++index;
+ }
+ SocketSend (client, "\n");
+ return 1;
+}
+
+#else /* we don't USE_PCRE_REGEX */
static int
MsgCall (const char *message, MsgSndPtr msg, Client client)
{
@@ -219,6 +263,7 @@ MsgCall (const char *message, MsgSndPtr msg, Client client)
SocketSend (client, "\n");
return 1;
}
+#endif /* USE_PCRE_REGEX */
static int
ClientCall (IvyClientPtr clnt, const char *message)
@@ -284,7 +329,13 @@ static void Receive( Client client, void *data, char *line )
char *argv[MAX_MATCHING_ARGS];
char *arg;
int kind_of_msg = Bye;
+#ifndef USE_PCRE_REGEX
regex_t regexp;
+#else
+ pcre *regexp;
+ const char *errbuf;
+ int erroffset;
+#endif
err = sscanf( line ,"%d %d", &kind_of_msg, &id );
arg = strstr( line , ARG_START );
@@ -323,6 +374,7 @@ static void Receive( Client client, void *data, char *line )
#endif //DEBUG
return;
}
+#ifndef USE_PCRE_REGEX
reg = regcomp(&regexp, arg, REG_ICASE|REG_EXTENDED);
if ( reg == 0 )
{
@@ -341,9 +393,31 @@ static void Receive( Client client, void *data, char *line )
printf("Error compiling '%s', %s\n", arg, errbuf);
MsgSendTo( client, Error, reg, errbuf );
}
+#else
+ regexp = pcre_compile(arg, 0,&errbuf,&erroffset,NULL);
+ if ( regexp != NULL )
+ {
+ IVY_LIST_ADD( clnt->msg_send, snd )
+ if ( snd )
+ {
+ snd->id = id;
+ snd->str_regexp = strdup( arg );
+ snd->regexp = regexp;
+ snd->inspect = pcre_study(regexp,0,&errbuf);
+ if (errbuf!=NULL)
+ {
+ printf("Error studying %s, message: %s\n",arg,errbuf);
+ }
+ }
+ }
+ else
+ {
+ printf("Error compiling '%s', %s\n", arg, errbuf);
+ MsgSendTo( client, Error, erroffset, errbuf );
+ }
+#endif
break;
case DelRegexp:
-
#ifdef DEBUG
printf("Regexp Delete id=%d\n", id);
#endif //DEBUG
@@ -351,12 +425,17 @@ static void Receive( Client client, void *data, char *line )
IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id ));
if ( snd )
{
+#ifndef USE_PCRE_REGEX
+ free( snd->str_regexp );
+#else
free( snd->str_regexp );
+ if (snd->inspect!=NULL) pcre_free(snd->inspect);
+ pcre_free(snd->regexp);
+#endif
IVY_LIST_REMOVE( clnt->msg_send, snd );
}
break;
case StartRegexp:
-
#ifdef DEBUG
printf("Regexp Start id=%d Application='%s'\n", id, arg);
#endif //DEBUG
@@ -701,6 +780,7 @@ IvyUnbindMsg (MsgRcvPtr msg)
IVY_LIST_EACH (clients, clnt ) {
MsgSendTo( clnt->client, DelRegexp,msg->id, "");
}
+ IVY_LIST_REMOVE( msg_recv, msg );
}
/* demande de reception d'un message */