From 0d5698d41b2fb135cb9fa79ff57ecd047db01a75 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Fri, 17 Nov 2017 17:19:07 +1100 Subject: [PATCH] Add inv_strpbrk() function and convert equivalent sindex() calls inv_strpbrk() is the inverse of the standard function strpbrk(). Calls to sindex() where both strings are not NULL and the second string begins with ^ are equivalent to calls to inv_strpbrk() (but without the ^). Convert those calls. --- include/ircaux.h | 1 + source/commands.c | 6 +++--- source/ircaux.c | 36 ++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/include/ircaux.h b/include/ircaux.h index 1b30bdc..a8330f3 100644 --- a/include/ircaux.h +++ b/include/ircaux.h @@ -28,6 +28,7 @@ char * BX_last_arg (char **); char * BX_expand_twiddle (char *); char * BX_upper (char *); char * BX_lower (char *); +char *inv_strpbrk(const char *s, const char *reject); char * BX_sindex (const char *, const char *); char * BX_rsindex (const char *, const char *, const char *, int); char * BX_path_search (char *, char *); diff --git a/source/commands.c b/source/commands.c index 4931bc3..69ee9a6 100644 --- a/source/commands.c +++ b/source/commands.c @@ -3526,7 +3526,7 @@ BUILT_IN_COMMAND(untopic) ChannelList *chan; int server; - args = sindex(args, "^ "); + args = inv_strpbrk(args, " "); if (is_channel(args)) channel = next_arg(args, &args); @@ -3543,12 +3543,12 @@ BUILT_IN_COMMAND(e_topic) ChannelList *chan; int server; - args = sindex(args, "^ "); + args = inv_strpbrk(args, " "); if (is_channel(args)) { channel = next_arg(args, &args); - args = sindex(args, "^ "); + args = inv_strpbrk(args, " "); } if (!(chan = prepare_command(&server, channel, args ? PC_TOPIC : NO_OP))) diff --git a/source/ircaux.c b/source/ircaux.c index 5203f3a..63d8954 100644 --- a/source/ircaux.c +++ b/source/ircaux.c @@ -467,7 +467,7 @@ char *BX_next_arg(char *str, char **new_ptr) if (!str) return NULL; - if ((ptr = sindex(str, "^ ")) != NULL) + if ((ptr = inv_strpbrk(str, " ")) != NULL) { if ((str = strchr(ptr, ' ')) != NULL) *str++ = 0; @@ -614,7 +614,7 @@ char *safe_new_next_arg (char *str, char **new_ptr) if (!str || !*str) return empty_string; - if ((ptr = sindex(str, "^ \t")) != NULL) + if ((ptr = inv_strpbrk(str, " \t")) != NULL) { if (*ptr == '"') { @@ -666,7 +666,7 @@ char *BX_new_new_next_arg (char *str, char **new_ptr, char *type) if (!str || !*str) return NULL; - if ((ptr = sindex(str, "^ \t")) != NULL) + if ((ptr = inv_strpbrk(str, " \t")) != NULL) { if ((*ptr == '"') || (*ptr == '\'')) { @@ -1066,6 +1066,23 @@ char *BX_check_nickname (char *nick) return *nick ? nick : NULL; } +/* inv_strcpbrk() + * + * Returns a pointer to the first character in a string which is NOT found + * in 'reject'. + * + * This is the inverse of the standard function strpbrk(). + */ +char *inv_strpbrk(const char *s, const char *reject) +{ + s += strspn(s, reject); + + if (!*s) + return NULL; + + return (char *)s; +} + /* sindex() * * Returns a pointer to the first matching character in a string, or NULL if @@ -1081,18 +1098,9 @@ char *BX_sindex(const char *string, const char *group) return NULL; if (*group == '^') - { - string += strspn(string, group + 1); - } + return inv_strpbrk(string, group + 1); else - { - string += strcspn(string, group); - } - - if (*string) - return (char *)string; - else - return NULL; + return strpbrk(string, group); } /* rsindex()