diff options
-rw-r--r-- | Ivy/IvyApplication.cxx | 36 |
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);
|