diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-04-12 23:07:06 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-04-12 23:07:06 +0200 |
commit | 34723d2accede91aa8e5ad98f3434104995e15bb (patch) | |
tree | 89e470cffbeb4f5673e8ba2d008f1e963030c62a /src | |
parent | 001ea53f9de524bee480cdd3996b1c9e10b2d568 (diff) | |
download | weechat-34723d2accede91aa8e5ad98f3434104995e15bb.zip |
api: allow wildcard "*" inside the mask in function string_match
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 16 | ||||
-rw-r--r-- | src/core/wee-config.c | 14 | ||||
-rw-r--r-- | src/core/wee-string.c | 133 | ||||
-rw-r--r-- | src/plugins/alias/alias-info.c | 2 | ||||
-rw-r--r-- | src/plugins/alias/alias.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 24 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 5 | ||||
-rw-r--r-- | src/plugins/irc/irc-info.c | 4 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 18 | ||||
-rw-r--r-- | src/plugins/plugin-script.c | 2 | ||||
-rw-r--r-- | src/plugins/script/script-info.c | 3 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-command.c | 2 |
12 files changed, 117 insertions, 109 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index a0ad2bd28..0a173c814 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -5593,8 +5593,7 @@ command_set_display_option_lists (char **argv, int arg_start, int arg_end, { gui_chat_printf (NULL, _("%sOption \"%s\" not found (tip: you can use " - "\"*\" at beginning and/or end of option to " - "see a sublist)"), + "wildcard \"*\" in option to see a sublist)"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], argv[i]); } @@ -7070,12 +7069,12 @@ command_init () "freenode.#weechat\")\n" " - \"*\" means all buffers\n" " - a name starting with '!' is excluded\n" - " - name can start or end with '*' to match many buffers\n" + " - wildcard \"*\" is allowed\n" " tags: comma separated list of tags, for example \"irc_join," "irc_part,irc_quit\"\n" " - logical \"and\": use \"+\" between tags (for example: " "\"nick_toto+irc_action\")\n" - " - tags can start or end with '*'\n" + " - wildcard \"*\" is allowed\n" " regex: POSIX extended regular expression to search in line\n" " - use '\\t' to separate prefix from message, special chars " "like '|' must be escaped: '\\|'\n" @@ -7271,7 +7270,7 @@ command_init () " bar(xxx): bar \"xxx\"\n" " item(*): any bar item\n" " item(xxx): bar item \"xxx\"\n" - "The key can start or end with '*' to match many mouse events.\n" + "Wildcard \"*\" is allowed in key to match many mouse events.\n" "A special value for command with format \"hsignal:name\" can be " "used for context mouse, this will send the hsignal \"name\" with " "the focus hashtable as argument.\n" @@ -7591,8 +7590,7 @@ command_init () NULL, "set", N_("set config options"), N_("[<option> [<value>]] || diff [<option> [<option>...]]"), - N_("option: name of an option (can start or end with '*' to list many " - "options)\n" + N_("option: name of an option (wildcard \"*\" is allowed)\n" " value: new value for option\n" " diff: display only changed options\n" "\n" @@ -7621,8 +7619,8 @@ command_init () NULL, "unset", N_("unset/reset config options"), N_("<option>"), - N_("option: name of an option (may begin or end with \"*\" to " - "mass-reset options, use carefully!)\n" + N_("option: name of an option (wildcard \"*\" is allowed to mass-reset " + "options, use carefully!)\n" "\n" "According to option, it's reset (for standard options) or removed " "(for optional settings, like server values).\n" diff --git a/src/core/wee-config.c b/src/core/wee-config.c index a9afde63f..e6a4abd24 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -2289,11 +2289,11 @@ config_weechat_init_options () weechat_config_file, ptr_section, "highlight_tags", "string", N_("comma separated list of tags to highlight; case insensitive " - "comparison; each tag can start or end with \"*\" to match more " - "than one tag; many tags can be separated by \"+\" to make a " - "logical \"and\" between tags; examples: \"nick_flashcode\" for " - "messages from nick \"FlashCode\", \"irc_notice+nick_toto*\" for " - "notices from a nick starting with \"toto\""), + "comparison; wildcard \"*\" is allowed in each tag; many tags can " + "be separated by \"+\" to make a logical \"and\" between tags; " + "examples: \"nick_flashcode\" for messages from nick \"FlashCode\", " + "\"irc_notice+nick_toto*\" for notices from a nick starting with " + "\"toto\""), NULL, 0, 0, "", NULL, 0, NULL, NULL, &config_change_highlight_tags, NULL, NULL, NULL); config_look_hotlist_add_conditions = config_file_new_option ( weechat_config_file, ptr_section, @@ -3324,8 +3324,8 @@ config_weechat_init_options () N_("comma separated list of plugins to load automatically " "at startup, \"*\" means all plugins found, a name beginning with " "\"!\" is a negative value to prevent a plugin from being loaded, " - "names can start or end with \"*\" to match several plugins " - "(examples: \"*\" or \"*,!lua,!tcl\")"), + "wildcard \"*\" is allowed in names (examples: \"*\" or " + "\"*,!lua,!tcl\")"), NULL, 0, 0, "*", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); config_plugin_debug = config_file_new_option ( weechat_config_file, ptr_section, diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 7dfcd3219..21a1fca4d 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -363,7 +363,8 @@ string_strcasestr (const char *string, const char *search) /* * Checks if a string matches a mask. * - * Mask can begin or end with "*", no other "*" are allowed inside mask. + * The mask can contain wildcards ("*"), each wildcard matches 0 or more chars + * in the string. * * Returns: * 1: string matches mask @@ -373,78 +374,92 @@ string_strcasestr (const char *string, const char *search) int string_match (const char *string, const char *mask, int case_sensitive) { - char last, *mask2; - int len_string, len_mask, rc; + const char *ptr_string, *ptr_mask, *pos_word, *pos_end; + char *word; + int wildcard, length_word; - if (!mask || !mask[0]) + if (!string || !mask || !mask[0]) return 0; - /* if mask is "*", then any string matches */ - if (strcmp (mask, "*") == 0) - return 1; + ptr_string = string; + ptr_mask = mask; - len_string = strlen (string); - len_mask = strlen (mask); + while (ptr_mask[0]) + { + wildcard = 0; - last = mask[len_mask - 1]; + /* if we are on a wildcard, set the wildcard flag and skip it */ + if (ptr_mask[0] == '*') + { + wildcard = 1; + ptr_mask++; + while (ptr_mask[0] == '*') + { + ptr_mask++; + } + if (!ptr_mask[0]) + return 1; + } - /* mask begins with "*" */ - if ((mask[0] == '*') && (last != '*')) - { - /* not enough chars in string to match */ - if (len_string < len_mask - 1) + /* no match if some mask without string */ + if (!string[0]) return 0; - /* check if end of string matches */ - if ((case_sensitive && (strcmp (string + len_string - (len_mask - 1), - mask + 1) == 0)) - || (!case_sensitive && (string_strcasecmp (string + len_string - (len_mask - 1), - mask + 1) == 0))) - return 1; - /* no match */ - return 0; - } - /* mask ends with "*" */ - if ((mask[0] != '*') && (last == '*')) - { - /* not enough chars in string to match */ - if (len_string < len_mask - 1) - return 0; - /* check if beginning of string matches */ - if ((case_sensitive && (strncmp (string, mask, len_mask - 1) == 0)) - || (!case_sensitive && (string_strncasecmp (string, - mask, - len_mask - 1) == 0))) - return 1; - /* no match */ - return 0; - } + /* search the next wildcard (after the word) */ + pos_end = strchr (ptr_mask, '*'); - /* mask begins and ends with "*" */ - if ((mask[0] == '*') && (last == '*')) - { - /* not enough chars in string to match */ - if (len_string < len_mask - 2) - return 0; - /* keep only relevant chars in mask for searching string */ - mask2 = string_strndup (mask + 1, len_mask - 2); - if (!mask2) + /* extract the word before the wildcard (or the end of mask) */ + if (pos_end) + { + length_word = pos_end - ptr_mask; + } + else + { + length_word = strlen (ptr_mask); + pos_end = ptr_mask + length_word; + } + word = string_strndup (ptr_mask, length_word); + if (!word) return 0; - /* search string */ - rc = ((case_sensitive && strstr (string, mask2)) - || (!case_sensitive && string_strcasestr (string, mask2))) ? - 1 : 0; - /* free and return */ - free (mask2); - return rc; + + /* check if the word is matching */ + if (wildcard) + { + /* search the word anywhere in the string (from current position) */ + pos_word = (case_sensitive) ? + strstr (ptr_string, word) : string_strcasestr (ptr_string, word); + if (!pos_word) + { + free (word); + return 0; + } + ptr_string = pos_word + length_word; + } + else + { + /* check if word is at beginning of string */ + if ((case_sensitive + && (strncmp (ptr_string, word, length_word) != 0)) + || (!case_sensitive + && (string_strncasecmp (ptr_string, word, + utf8_strlen (word)) != 0))) + { + free (word); + return 0; + } + ptr_string += length_word; + } + + free (word); + + ptr_mask = pos_end; } - /* no "*" at all, compare strings */ - if ((case_sensitive && (strcmp (string, mask) == 0)) - || (!case_sensitive && (string_strcasecmp (string, mask) == 0))) + /* match if no more string/mask */ + if (!ptr_string[0] && !ptr_mask[0]) return 1; - /* no match */ + /* no match in other cases */ return 0; } diff --git a/src/plugins/alias/alias-info.c b/src/plugins/alias/alias-info.c index 22191e6e7..f4204bb98 100644 --- a/src/plugins/alias/alias-info.c +++ b/src/plugins/alias/alias-info.c @@ -94,6 +94,6 @@ alias_info_init () { weechat_hook_infolist ("alias", N_("list of aliases"), N_("alias pointer (optional)"), - N_("alias name (can start or end with \"*\" as wildcard) (optional)"), + N_("alias name (wildcard \"*\" is allowed) (optional)"), &alias_info_get_infolist_cb, NULL); } diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index e1a1150bf..fad87ab7b 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -991,8 +991,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) "is done with target command)\n" " note: you can use %%command to use completion of an " "existing command\n" - " alias: name of alias (can start or end with \"*\" for alias " - "listing)\n" + " alias: name of alias (wildcard \"*\" is allowed)\n" " command: command name with arguments (many commands can be " "separated by semicolons)\n" "\n" diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 3e619c697..b56371486 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -166,8 +166,7 @@ irc_command_mode_nicks (struct t_irc_server *server, if (set[0] == '-' && (mode[0] == 'o' || mode[0] == 'h') && argv[i][0] - && ((argv[i][0] == '*') - || (argv[i][strlen (argv[i]) - 1] == '*')) + && strchr (argv[i], '*') && (strcmp (server->nick, ptr_nick->name) == 0)) { continue; @@ -5730,8 +5729,7 @@ irc_command_init () N_("[-current] [-exclude=<channel>[,<channel>...]] <command> " "[<arguments>]"), N_(" -current: execute command for channels of current server only\n" - " -exclude: exclude some channels ('*' is allowed at beginning or " - "end of channel name, to exclude many channels)\n" + " -exclude: exclude some channels (wildcard \"*\" is allowed)\n" " command: command to execute\n" "arguments: arguments for command (special variables $nick, $channel " "and $server are replaced by their value)\n" @@ -5752,8 +5750,7 @@ irc_command_init () "[<arguments>]"), N_(" -current: execute command for private buffers of current server " "only\n" - " -exclude: exclude some nicks ('*' is allowed at beginning or " - "end of nick name, to exclude many nicks)\n" + " -exclude: exclude some nicks (wildcard \"*\" is allowed)\n" " command: command to execute\n" "arguments: arguments for command (special variables $nick, $channel " "and $server are replaced by their value)\n" @@ -5774,8 +5771,7 @@ irc_command_init () N_("execute a command on all connected servers"), N_("[-exclude=<server>[,<server>...]] " "<command> [<arguments>]"), - N_(" -exclude: exclude some servers ('*' is allowed at beginning or end " - "of server name, to exclude many servers)\n" + N_(" -exclude: exclude some servers (wildcard \"*\" is allowed)\n" " command: command to execute\n" "arguments: arguments for command (special variables $nick, $channel " "and $server are replaced by their value)\n" @@ -5871,7 +5867,7 @@ irc_command_init () "dehalfop", N_("remove channel half-operator status from nick(s)"), N_("<nick> [<nick>...]"), - N_("nick: nick or mask (can start or end with \"*\" as wildcard)\n" + N_("nick: nick or mask (wildcard \"*\" is allowed)\n" " *: remove channel half-operator status from everybody on channel " "except yourself"), "%(nicks)", &irc_command_dehalfop, NULL); @@ -5879,7 +5875,7 @@ irc_command_init () "deop", N_("remove channel operator status from nick(s)"), N_("<nick> [<nick>...] || * -yes"), - N_("nick: nick or mask (can start or end with \"*\" as wildcard)\n" + N_("nick: nick or mask (wildcard \"*\" is allowed)\n" " *: remove channel operator status from everybody on channel " "except yourself"), "%(nicks)|%*", &irc_command_deop, NULL); @@ -5887,7 +5883,7 @@ irc_command_init () "devoice", N_("remove voice from nick(s)"), N_("<nick> [<nick>...] || * -yes"), - N_("nick: nick or mask (can start or end with \"*\" as wildcard)\n" + N_("nick: nick or mask (wildcard \"*\" is allowed)\n" " *: remove voice from everybody on channel"), "%(nicks)|%*", &irc_command_devoice, NULL); weechat_hook_command ( @@ -5911,7 +5907,7 @@ irc_command_init () "halfop", N_("give channel half-operator status to nick(s)"), N_("<nick> [<nick>...] || * -yes"), - N_("nick: nick or mask (can start or end with \"*\" as wildcard)\n" + N_("nick: nick or mask (wildcard \"*\" is allowed)\n" " *: give channel half-operator status to everybody on channel"), "%(nicks)", &irc_command_halfop, NULL); weechat_hook_command ( @@ -6166,7 +6162,7 @@ irc_command_init () "op", N_("give channel operator status to nick(s)"), N_("<nick> [<nick>...] || * -yes"), - N_("nick: nick or mask (can start or end with \"*\" as wildcard)\n" + N_("nick: nick or mask (wildcard \"*\" is allowed)\n" " *: give channel operator status to everybody on channel"), "%(nicks)|%*", &irc_command_op, NULL); weechat_hook_command ( @@ -6433,7 +6429,7 @@ irc_command_init () "voice", N_("give voice to nick(s)"), N_("<nick> [<nick>...]"), - N_("nick: nick or mask (can start or end with \"*\" as wildcard)\n" + N_("nick: nick or mask (wildcard \"*\" is allowed)\n" " *: give voice to everybody on channel"), "%(nicks)|%*", &irc_command_voice, NULL); weechat_hook_command ( diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index d034e2541..970eb738d 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -2406,9 +2406,8 @@ irc_config_init () N_("restrict highlights to these tags on irc buffers (to have " "highlight on user messages but not server messages); tags " "must be separated by a comma and \"+\" can be used to make a " - "logical \"and\" between tags; tags can start or end with \"*\" " - "to match more than one tag; an empty value allows highlight on any " - "tag"), + "logical \"and\" between tags; wildcard \"*\" is allowed in tags; " + "an empty value allows highlight on any tag"), NULL, 0, 0, "irc_privmsg,irc_notice", NULL, 0, NULL, NULL, &irc_config_change_look_highlight_tags_restrict, NULL, NULL, NULL); irc_config_look_item_away_message = weechat_config_new_option ( diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 066415a1d..36a519d10 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -640,7 +640,7 @@ irc_info_init () weechat_hook_infolist ("irc_server", N_("list of IRC servers"), N_("server pointer (optional)"), - N_("server name (can start or end with \"*\" as wildcard) (optional)"), + N_("server name (wildcard \"*\" is allowed) (optional)"), &irc_info_get_infolist_cb, NULL); weechat_hook_infolist ("irc_channel", N_("list of channels for an IRC server"), @@ -660,7 +660,7 @@ irc_info_init () weechat_hook_infolist ("irc_notify", N_("list of notify"), N_("notify pointer (optional)"), - N_("server name (can start or end with \"*\" as wildcard) (optional)"), + N_("server name (wildcard \"*\" is allowed) (optional)"), &irc_info_get_infolist_cb, NULL); /* hdata hooks */ diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 450e18238..c3ea57569 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -1214,11 +1214,11 @@ plugin_api_init () /* WeeChat core infolist hooks */ hook_infolist (NULL, "bar", N_("list of bars"), N_("bar pointer (optional)"), - N_("bar name (can start or end with \"*\" as wildcard) (optional)"), + N_("bar name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "bar_item", N_("list of bar items"), N_("bar item pointer (optional)"), - N_("bar item name (can start or end with \"*\" as wildcard) (optional)"), + N_("bar item name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "bar_window", N_("list of bar windows"), N_("bar window pointer (optional)"), @@ -1226,7 +1226,7 @@ plugin_api_init () &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "buffer", N_("list of buffers"), N_("buffer pointer (optional)"), - N_("buffer name (can start or end with \"*\" as wildcard) (optional)"), + N_("buffer name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "buffer_lines", N_("lines of a buffer"), N_("buffer pointer"), @@ -1234,7 +1234,7 @@ plugin_api_init () &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "filter", N_("list of filters"), NULL, - N_("filter name (can start or end with \"*\" as wildcard) (optional)"), + N_("filter name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "history", N_("history of commands"), N_("buffer pointer (if not set, return global history) (optional)"), @@ -1243,8 +1243,8 @@ plugin_api_init () hook_infolist (NULL, "hook", N_("list of hooks"), N_("hook pointer (optional)"), N_("type,arguments (type is command/timer/.., arguments to " - "get only some hooks (can start or end with \"*\" as " - "wildcard), both are optional)"), + "get only some hooks (wildcard \"*\" is allowed), " + "both are optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "hotlist", N_("list of buffers in hotlist"), NULL, @@ -1266,15 +1266,15 @@ plugin_api_init () &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "option", N_("list of options"), NULL, - N_("option name (can start or end with \"*\" as wildcard) (optional)"), + N_("option name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "plugin", N_("list of plugins"), N_("plugin pointer (optional)"), - N_("plugin name (can start or end with \"*\" as wildcard) (optional)"), + N_("plugin name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "proxy", N_("list of proxies"), N_("proxy pointer (optional)"), - N_("proxy name (can start or end with \"*\" as wildcard) (optional)"), + N_("proxy name (wildcard \"*\" is allowed) (optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "url_options", N_("options for URL"), NULL, diff --git a/src/plugins/plugin-script.c b/src/plugins/plugin-script.c index fe80aecac..bffe58e75 100644 --- a/src/plugins/plugin-script.c +++ b/src/plugins/plugin-script.c @@ -193,7 +193,7 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin, init->callback_hdata, weechat_plugin); weechat_hook_infolist (string, N_("list of scripts"), N_("script pointer (optional)"), - N_("script name (can start or end with \"*\" as wildcard) (optional)"), + N_("script name (wildcard \"*\" is allowed) (optional)"), init->callback_infolist, NULL); snprintf (string, length, "%s_callback", weechat_plugin->name); weechat_hook_hdata (string, N_("callback of a script"), diff --git a/src/plugins/script/script-info.c b/src/plugins/script/script-info.c index aec302b26..6c706ad05 100644 --- a/src/plugins/script/script-info.c +++ b/src/plugins/script/script-info.c @@ -99,7 +99,8 @@ script_info_init () weechat_hook_infolist ("script_script", N_("list of scripts"), N_("script pointer (optional)"), - N_("script name with extension (can start or end with \"*\" as wildcard) (optional)"), + N_("script name with extension " + "(wildcard \"*\" is allowed) (optional)"), &script_info_get_infolist_cb, NULL); /* hdata hooks */ diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index fb42c14ab..56954bdc8 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -1004,7 +1004,7 @@ trigger_command_init () " monitor: open the trigger monitor buffer, with optional filter:\n" " filter: filter hooks/triggers to display (a hook must start " "with \"@\", for example \"@signal\"), many filters can be separated " - "by commas; each trigger name can start or end with \"*\"\n" + "by commas; wildcard \"*\" is allowed in each trigger name\n" "\n" "When a trigger callback is called, following actions are performed, " "in this order:\n" |