From fb6aa032cf84f543234534cd2c24102eb730bbc4 Mon Sep 17 00:00:00 2001 From: fcolin Date: Tue, 26 Jul 2005 08:47:24 +0000 Subject: compile sur Windows les fichiers getopt sont necessaires uniquement sur Windows( WIN32 ) compilateur VStudio --- src/Makefile.win32 | 10 +++---- src/getopt.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/getopt.h | 16 ++++++++++++ src/ivy.c | 34 ++++++++++++------------ src/ivybind.c | 32 +++++++++++------------ src/ivyprobe.c | 44 ++++++++++++++++--------------- 6 files changed, 153 insertions(+), 59 deletions(-) create mode 100755 src/getopt.c create mode 100755 src/getopt.h diff --git a/src/Makefile.win32 b/src/Makefile.win32 index 3599350..ab0fcfb 100755 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -46,7 +46,7 @@ REGEXP= -DUSE_PCRE_REGEX -DPCRE_OPT=$(PCRE_OPT) CHANNEL = -DTCL_CHANNEL_INTEGRATION -OBJ = ivyloop.obj timer.obj ivysocket.obj ivy.obj +OBJ = ivyloop.obj timer.obj ivysocket.obj ivy.obj ivybind.obj ivyargument.obj # WINDOWS add ivyloop.obj if TCL_CHANNEL_INTEGRATION is not set TARGETS = ivyprobe ivyperf @@ -63,21 +63,21 @@ shared-libs: $(TARGETLIBS) commands: $(TARGETS) -ivy.obj: ivy.c - $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivy.c +ivybind.obj: ivybind.c + $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivybind.c ivyprobe: ivyprobe.obj libivy.lib $(CC) $(CFLAGS) -o $@ ivyprobe.obj libivy.lib wsock32.lib $(PCRELIB) ivyprobe.obj : ivyprobe.c - $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) -c ivyprobe.c -o $@ + $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivyprobe.c ivyperf: ivyperf.obj libivy.lib $(CC) $(CFLAGS) -o $@ ivyperf.obj libivy.lib wsock32.lib $(PCRELIB) ivyperf.obj : ivyperf.c - $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) -c ivyperf.c -o $@ + $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivyperf.c libivy.lib: $(OBJ) diff --git a/src/getopt.c b/src/getopt.c new file mode 100755 index 0000000..36a9bc1 --- /dev/null +++ b/src/getopt.c @@ -0,0 +1,76 @@ +#include +#include +#include + +int optind = 1; +char *optarg = (char *)NULL; + +int getopt (int argc, char **argv, char *optstring) +{ + int cur_option; /* Current option */ + char *cp; /* Character pointer */ + static int GetOptionPosition = 1; + + if (GetOptionPosition == 1) + { + +/* Check for out of range, correct start character and not single */ + + if ((optind >= argc) || (*argv[optind] != '-') || !argv[optind][1]) + return EOF; + + if (!strcmp (argv[optind], "--")) + return EOF; + } + +/* Get the current character from the current argument vector */ + + cur_option = argv[optind][GetOptionPosition]; + +/* Validate it */ + + if ((cur_option == ':') || + ((cp = strchr (optstring, cur_option)) == (char *)NULL)) + { + +/* Move to the next offset */ + + if (!argv[optind][++GetOptionPosition]) + { + optind++; + GetOptionPosition = 1; + } + + return '?'; + } + +/* Parameters following ? */ + + optarg = (char *)NULL; + + if (*(++cp) == ':') + { + if (argv[optind][GetOptionPosition + 1]) + optarg = &argv[optind++][GetOptionPosition + 1]; + + else if (++optind >= argc) + { + optarg = (char *)NULL; + GetOptionPosition = 1; + return '?'; + } + + else + optarg = argv[optind++]; + + GetOptionPosition = 1; + } + + else if (!argv[optind][++GetOptionPosition]) + { + GetOptionPosition = 1; + optind++; + } + + return cur_option; +} diff --git a/src/getopt.h b/src/getopt.h new file mode 100755 index 0000000..d52543f --- /dev/null +++ b/src/getopt.h @@ -0,0 +1,16 @@ +#ifndef __GETOPT_H_ +#define __GETOPT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +extern int optind ; +extern char *optarg ; +extern int getopt (int argc, char **argv, char *optstring) ; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/ivy.c b/src/ivy.c index b7a60a5..673b76f 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -242,14 +242,14 @@ static void SortClients() } static void MsgSendTo( Client client, MsgType msgtype, int id, int len_arg, const void *arg ) { - ushort header[3]; + unsigned short header[3]; #ifdef DEBUG printf( "Sending message type=%d id=%d '%.*s'\n",msgtype,id,len_arg,arg); #endif - header[0] = htons( (ushort)msgtype ); - header[1] = htons( (ushort)id ); - header[2] = htons( (ushort)len_arg ); + header[0] = htons( (unsigned short)msgtype ); + header[1] = htons( (unsigned short)id ); + header[2] = htons( (unsigned short)len_arg ); SocketSendBuf( client, (char *)header, sizeof(header) ); if ( len_arg ) { @@ -375,7 +375,7 @@ static char* Receive( Client client, void *data, char *message, unsigned int len { IvyClientPtr clnt; int id; - ushort len_args; + unsigned short len_args; MsgSndPtr snd; MsgRcvPtr rcv; int argc = 0; @@ -388,9 +388,9 @@ static char* Receive( Client client, void *data, char *message, unsigned int len ptr_end = message; if ( len < 6 ) return NULL; /* incomplete message */ - kind_of_msg = ntohs( *((ushort *) ptr_end)++ ); - id = ntohs( *((ushort *) ptr_end)++ ); - len_args = ntohs( *((ushort *) ptr_end)++ ); + kind_of_msg = ntohs( *((unsigned short *) ptr_end)++ ); + id = ntohs( *((unsigned short *) ptr_end)++ ); + len_args = ntohs( *((unsigned short *) ptr_end)++ ); if ( len_args ) { @@ -643,15 +643,15 @@ static void IvySendHello(unsigned long mask) int len; lenAppId = strlen( applicationUniqueId ); lenAppName = strlen( ApplicationName ); - len = 4*sizeof(ushort) + lenAppId + lenAppName; + len = 4*sizeof(unsigned short) + lenAppId + lenAppName; packet = malloc( len ); ptr = packet; - *((ushort *) ptr)++ = htons( VERSION ); - *((ushort *) ptr)++ = htons( ApplicationPort ); - *((ushort *) ptr)++ = htons( lenAppId ); + *((unsigned short *) ptr)++ = htons( VERSION ); + *((unsigned short *) ptr)++ = htons( ApplicationPort ); + *((unsigned short *) ptr)++ = htons( lenAppId ); strncpy( ptr, applicationUniqueId , lenAppId); ptr += lenAppId; - *((ushort *) ptr)++ = htons( lenAppName ); + *((unsigned short *) ptr)++ = htons( lenAppName ); strncpy( ptr, ApplicationName , lenAppName); SocketSendBroadcastRaw (broadcast, mask, SupervisionPort, packet,len ); @@ -677,15 +677,15 @@ static char* BroadcastReceive( Client client, void *data, char *message, unsigne if ( len < 6 ) return NULL; /* incomplete message */ - version = ntohs( *((ushort *) ptr_end)++ ); - serviceport = ntohs( *((ushort *) ptr_end)++ ); - len_appid = ntohs( *((ushort *) ptr_end)++ ); + version = ntohs( *((unsigned short *) ptr_end)++ ); + serviceport = ntohs( *((unsigned short *) ptr_end)++ ); + len_appid = ntohs( *((unsigned short *) ptr_end)++ ); if ( len < (6 +len_appid) ) return NULL; /* incomplete message */ strncpy( appid , ptr_end, len_appid ); appid[ len_appid ] = '\0'; ptr_end += len_appid; - len_appname = ntohs( *((ushort *) ptr_end)++ ); + len_appname = ntohs( *((unsigned short *) ptr_end)++ ); if ( len < (6 +len_appid + len_appname) ) return NULL; /* incomplete message */ strncpy( appname , ptr_end, len_appname ); diff --git a/src/ivybind.c b/src/ivybind.c index e859457..9cd1f58 100644 --- a/src/ivybind.c +++ b/src/ivybind.c @@ -22,33 +22,33 @@ #include #include -#ifndef USE_PCRE_REGEX -#include -#else +#ifdef USE_PCRE_REGEX #define OVECSIZE 60 /* must be multiple of 3, for regexp return */ #include +#else +#include #endif #include "list.h" #include "ivybind.h" -#ifndef USE_PCRE_REGEX - static int erroroffset; - static char errbuf[4096]; -#else +#ifdef USE_PCRE_REGEX static const char *errbuf; static int erroffset; +#else + static int erroroffset; + static char errbuf[4096]; #endif struct _binding { struct _binding *next; -#ifndef USE_PCRE_REGEX - regex_t regexp; /* la regexp sous forme machine */ - regmatch_t match[MAX_MSG_FIELDS+1]; /* resultat du match */ -#else +#ifdef USE_PCRE_REGEX pcre *regexp; pcre_extra *inspect; int ovector[OVECSIZE]; +#else + regex_t regexp; /* la regexp sous forme machine */ + regmatch_t match[MAX_MSG_FIELDS+1]; /* resultat du match */ #endif }; @@ -92,19 +92,19 @@ IvyBinding IvyBindingCompile( const char * expression ) } void IvyBindingGetCompileError( int *offset, const char **errmessage ) { -#ifndef USE_PCRE_REGEX - *offset = erroroffset; +#ifdef USE_PCRE_REGEX + *offset = erroffset; *errmessage = errbuf; #else - *offset = erroffset; + *offset = erroroffset; *errmessage = errbuf; #endif } void IvyBindingFree( IvyBinding bind ) { #ifdef USE_PCRE_REGEX - if (bind->inspect!=NULL) pcre_free(bind->inspect); - pcre_free(bind->regexp); + if (bind->inspect!=NULL) pcre_free(bind->inspect); + pcre_free(bind->regexp); #else #endif free ( bind ); diff --git a/src/ivyprobe.c b/src/ivyprobe.c index 1da9ebc..8143706 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -37,22 +37,21 @@ #ifdef __MINGW32__ #include #include -#endif -#else +#endif // __MINGW32__ +#else // WIN32 #include #include #ifdef __INTERIX extern char *optarg; extern int optind; -#endif -#ifndef USE_PCRE_REGEX -#include -#else +#endif // __INTERIX +#endif // WIN32 + +#ifdef USE_PCRE_REGEX #define OVECSIZE 60 /* must be multiple of 3, for regexp return */ #include -#endif - - +#else +#include #endif #include "ivychannel.h" @@ -70,10 +69,10 @@ int app_count = 0; int wait_count = 0; int fbindcallback = 0; -void DirectCallback(IvyClientPtr app, void *user_data, int id, char *msg ) +void DirectCallback(IvyClientPtr app, void *user_data, int id, int len, void *msg ) { printf("%s sent a direct message, id=%d, message=%s\n", - IvyGetApplicationName(app),id,msg); + IvyGetApplicationName(app),id,(char*)msg); } void BindCallback(IvyClientPtr app, void *user_data, IvyBindEvent event, char *regexp ) @@ -109,6 +108,7 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) char *line; char *cmd; char *arg; + char *choparg; int id; IvyClientPtr app; int err; @@ -145,7 +145,15 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) } else if (strcmp(cmd, "bind") == 0) { arg = strtok (NULL, "'"); if (arg) { -#ifndef USE_PCRE_REGEX +#ifdef USE_PCRE_REGEX + pcre *regexp; + const char *errbuf; + int erroffset; + Chop(arg); + regexp = pcre_compile(arg, 0,&errbuf,&erroffset,NULL); + if (regexp==NULL) { + printf("Error compiling '%s', %s, not bound\n", arg, errbuf); +#else regex_t reg; int err; Chop(arg); @@ -153,14 +161,7 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) char errbuf[4096]; regerror (err, ®, errbuf, 4096); printf("Error compiling '%s', %s, not bound\n", arg, errbuf); -#else - pcre *regexp; - const char *errbuf; - int erroffset; - Chop(arg); - regexp = pcre_compile(arg, 0,&errbuf,&erroffset,NULL); - if (regexp==NULL) { - printf("Error compiling '%s', %s, not bound\n", arg, errbuf); + #endif } else { IvyBindMsg (Callback, NULL, Chop(arg)); @@ -178,12 +179,13 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) } else if (strcmp(cmd, "direct") == 0) { arg = strtok (NULL, " \n"); if (arg) { + choparg = Chop(arg); app = IvyGetApplication (arg); if (app) { arg = strtok (NULL, " "); id = atoi (arg) ; arg = strtok (NULL, "'"); - IvySendDirectMsg (app, id, Chop(arg)); + IvySendDirectMsg (app, id, strlen(choparg), choparg); } else printf ("No Application %s!!!\n",arg); } -- cgit v1.1