aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-04-12 02:06:49 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2010-04-12 02:06:49 +0200
commit24b8bbb2616d685006a279e46a4bd2e8e7cf6694 (patch)
treec585d428a08bdd8c7f22b1fdef8e65d758f60d6e /lib
parente21c0f8b276cc3ca177bcf6217eba9c634d410f7 (diff)
Start handling CTCPs, in a saner way than before.
Diffstat (limited to 'lib')
-rw-r--r--lib/misc.c45
-rw-r--r--lib/misc.h2
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/misc.c b/lib/misc.c
index fe2ff17c..2901704a 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -613,3 +613,48 @@ int md5_verify_password( char *password, char *hash )
return ret;
}
+
+char **split_command_parts( char *command )
+{
+ static char *cmd[IRC_MAX_ARGS+1];
+ char *s, q = 0;
+ int k;
+
+ memset( cmd, 0, sizeof( cmd ) );
+ cmd[0] = command;
+ k = 1;
+ for( s = command; *s && k < IRC_MAX_ARGS; s ++ )
+ if( *s == ' ' && !q )
+ {
+ *s = 0;
+ while( *++s == ' ' );
+ if( *s == '"' || *s == '\'' )
+ {
+ q = *s;
+ s ++;
+ }
+ if( *s )
+ {
+ cmd[k++] = s;
+ s --;
+ }
+ else
+ {
+ break;
+ }
+ }
+ else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
+ {
+ char *cpy;
+
+ for( cpy = s; *cpy; cpy ++ )
+ cpy[0] = cpy[1];
+ }
+ else if( *s == q )
+ {
+ q = *s = 0;
+ }
+ cmd[k] = NULL;
+
+ return cmd;
+}
diff --git a/lib/misc.h b/lib/misc.h
index ce36caf5..e0e08bf1 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -67,4 +67,6 @@ G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl );
G_MODULE_EXPORT int md5_verify_password( char *password, char *hash );
+G_MODULE_EXPORT char **split_command_parts( char *command );
+
#endif