From 0efdf8c11e50d6aed89ed72760a72e68b701bf9d Mon Sep 17 00:00:00 2001 From: bustico Date: Wed, 20 Sep 2006 09:28:59 +0000 Subject: Ajout de la fonctionnalité pour capter des intervalles numériques de la forme A=((?I10#20)) l'api ne change pas. --- src/ivy.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/ivy.c') diff --git a/src/ivy.c b/src/ivy.c index e7866a5..f9d5f23 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -30,6 +30,7 @@ #include +#include "intervalRegexp.h" #include "ivychannel.h" #include "ivysocket.h" #include "list.h" @@ -136,6 +137,7 @@ static MsgRcvPtr msg_recv = 0; static IvyClientPtr clients = 0; static const char *ready_message = 0; +static void substituteInterval (IvyBuffer *src); /* * function like strok but do not eat consecutive separator @@ -753,6 +755,8 @@ IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) make_message( &buffer, fmt_regex, ap ); va_end (ap ); + substituteInterval (&buffer); + /* add Msg to the query list */ IVY_LIST_ADD_START( msg_recv, msg ) msg->id = recv_id++; @@ -907,3 +911,44 @@ char **IvyGetApplicationMessages( IvyClientPtr app ) } return messagelist; } + +static void substituteInterval (IvyBuffer *src) +{ + // pas de traitement couteux s'il n'y a rien à interpoler + if (strstr (src->data, "(?I") == NULL) { + return; + } else { + IvyBuffer dst = {NULL, 0, 0}; + dst.size = 8192; + dst.data = malloc (dst.size); + + char *curPos = src->data; + char *itvPos; + while ((itvPos = strstr (curPos, "(?I")) != NULL) { + // copie depuis la position courante jusqu'à l'intervalle + int lenCp, min,max; + char withDecimal; + lenCp = itvPos-curPos; + memcpy (&(dst.data[dst.offset]), curPos, lenCp); + curPos=itvPos; + dst.offset += lenCp; + + // extraction des paramètres de l'intervalle + sscanf (itvPos, "(?I%d#%d%c", &min, &max, &withDecimal); + + // printf ("DBG> substituteInterval min=%d max=%d withDecimal=%d\n", + // min, max, (withDecimal != 'i')); + + // generation et copie de l'intervalle + regexpGen (&(dst.data[dst.offset]), dst.size-dst.offset, min, max, (withDecimal != 'i')); + dst.offset = strlen (dst.data); + + // consommation des caractères décrivant intervalle dans la chaine source + curPos = strstr (curPos, ")"); + curPos++; + } + strncat (dst.data, curPos, dst.size-dst.offset); + free (src->data); + src->data = dst.data; + } +} -- cgit v1.1