summaryrefslogtreecommitdiff
path: root/Ivy/IvyApplication.cxx
diff options
context:
space:
mode:
authorfcolin2007-02-01 13:00:21 +0000
committerfcolin2007-02-01 13:00:21 +0000
commit2132f900f65f521c61e60a3541716104d83ee384 (patch)
tree483ff874b9c2c453a3f7aa71f5a1b8694df3bb0a /Ivy/IvyApplication.cxx
parent896c064fa646fb30d446aaf66567f81d7590f9e9 (diff)
downloadivy-cplusplus-2132f900f65f521c61e60a3541716104d83ee384.zip
ivy-cplusplus-2132f900f65f521c61e60a3541716104d83ee384.tar.gz
ivy-cplusplus-2132f900f65f521c61e60a3541716104d83ee384.tar.bz2
ivy-cplusplus-2132f900f65f521c61e60a3541716104d83ee384.tar.xz
Utilisateur : Fcolin Date : 17/11/05 Heure : 15:08 Archivé dans $/Bus/Ivy Commentaire: nice Bug in nextArg not reentrant routine due to static variable (vss 27)
Diffstat (limited to 'Ivy/IvyApplication.cxx')
-rw-r--r--Ivy/IvyApplication.cxx36
1 files changed, 17 insertions, 19 deletions
diff --git a/Ivy/IvyApplication.cxx b/Ivy/IvyApplication.cxx
index 5a50b96..32b89a2 100644
--- a/Ivy/IvyApplication.cxx
+++ b/Ivy/IvyApplication.cxx
@@ -9,36 +9,32 @@
//#define IVY_DEBUG
-#define ARG_START "\002"
-#define ARG_END "\003"
+#define ARG_START 2
+#define ARG_END 3
-static char * firstArg( char *s, const char *separator )
+static char * firstArg( char *s, const char separator )
{
char *ptr = s;
- while ( *ptr && *ptr != *separator )
+ while ( *ptr && *ptr != separator )
ptr++;
- if ( *ptr == *separator )
+ if ( *ptr == separator )
return ptr++ ;
else return NULL;
}
/*
function like strok but do not eat consecutive separator
*/
-static char * nextArg( char *s, const char *separator )
+static char * nextArg( char **s, const char separator )
{
- static char *start = NULL;
- static char *end = NULL;
- if ( s )
- {
- end = s;
- }
- start = end;
+ char *start = *s;
+ char *end = *s;
- while ( *end && *end != *separator )
+ while ( *end && *end != separator )
end++;
- if ( *end == *separator ) *end++ = '\0';
+ if ( *end == separator ) *end++ = '\0';
if ( end == start ) return NULL;
+ *s = end;
return start;
}
/////////////////////////////////////////////////////////////////////////////
@@ -102,6 +98,7 @@ void IvyApplication::OnReceive(char * line)
int kind_of_msg = Bye;
char *arg;
int argc = 0;
+ char *arg_ptr;
#ifdef USE_PCRE
pcre *exp;
@@ -243,11 +240,12 @@ void IvyApplication::OnReceive(char * line)
TRACE("Message id=%d msg='%s'\n", id, arg);
#endif //IVY_DEBUG
- arg = nextArg( arg, ARG_END);
+ arg_ptr = arg;
+ arg = nextArg( &arg_ptr, ARG_END);
while ( arg )
{
argv[argc++] = arg;
- arg = nextArg( NULL, ARG_END );
+ arg = nextArg( &arg_ptr, ARG_END );
}
bus->CallMessageCallback( this, id, argc, argv );
break;
@@ -283,8 +281,8 @@ void IvyApplication::SendMsg(MsgType msg, int id, const char * arg)
{
char buffer[1024];
if ( arg )
- _snprintf_s( buffer, sizeof( buffer ),sizeof( buffer )-1, "%d %d" ARG_START "%s\n", msg, id, arg );
- else sprintf_s( buffer,sizeof( buffer ), "%d %d" ARG_START "\n", msg, id );
+ _snprintf_s( buffer, sizeof( buffer ),sizeof( buffer )-1, "%d %d%c%s\n", msg, id, ARG_START, arg );
+ else sprintf_s( buffer,sizeof( buffer ), "%d %d%c\n", msg, id, ARG_START);
#ifdef IVY_DEBUG
TRACE("SendMsg %s\n",buffer);