diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-info.c | 10 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 38 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 66 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 5 | ||||
-rw-r--r-- | src/plugins/plugin-api-info.c | 100 |
5 files changed, 131 insertions, 88 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index e3318d416..ebd0265cd 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -1259,15 +1259,17 @@ irc_info_init () &irc_info_info_irc_nick_from_host_cb, NULL, NULL); weechat_hook_info ( "irc_nick_color", - N_("get nick color code (nick is first converted to lower case, " - "following the value of CASEMAPPING on the server, " + N_("get nick color code, ignoring case (this calls the info " + "\"nick_color_ignore_case\" with appropriate range, according " + "to the value of CASEMAPPING on the server, " "defaulting to \"rfc1459\" if the server is not given)"), N_("server,nickname (server is optional)"), &irc_info_info_irc_nick_color_cb, NULL, NULL); weechat_hook_info ( "irc_nick_color_name", - N_("get nick color name (nick is first converted to lower case, " - "following the value of CASEMAPPING on the server, " + N_("get nick color name, ignoring case (this calls the info " + "\"nick_color_name_ignore_case\" with appropriate range, according " + "to the value of CASEMAPPING on the server, " "defaulting to \"rfc1459\" if the server is not given)"), N_("server,nickname (server is optional)"), &irc_info_info_irc_nick_color_name_cb, NULL, NULL); diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index f593c9312..286907999 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -141,15 +141,20 @@ irc_nick_is_nick (struct t_irc_server *server, const char *string) char * irc_nick_find_color (struct t_irc_server *server, const char *nickname) { - char *nickname_lower, *result; + char str_args[4096]; + int casemapping, range; - nickname_lower = irc_server_string_tolower (server, nickname); - if (!nickname_lower) - return NULL; + casemapping = (server) ? server->casemapping : -1; + if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) + casemapping = IRC_SERVER_CASEMAPPING_RFC1459; + range = irc_server_casemapping_range[casemapping]; - result = weechat_info_get ("nick_color", nickname_lower); - free (nickname_lower); - return result; + snprintf (str_args, sizeof (str_args), + "%s;%d", + (nickname) ? nickname : "", + range); + + return weechat_info_get ("nick_color_ignore_case", str_args); } /* @@ -161,15 +166,20 @@ irc_nick_find_color (struct t_irc_server *server, const char *nickname) char * irc_nick_find_color_name (struct t_irc_server *server, const char *nickname) { - char *nickname_lower, *result; + char str_args[4096]; + int casemapping, range; - nickname_lower = irc_server_string_tolower (server, nickname); - if (!nickname_lower) - return NULL; + casemapping = (server) ? server->casemapping : -1; + if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) + casemapping = IRC_SERVER_CASEMAPPING_RFC1459; + range = irc_server_casemapping_range[casemapping]; - result = weechat_info_get ("nick_color_name", nickname_lower); - free (nickname_lower); - return result; + snprintf (str_args, sizeof (str_args), + "%s;%d", + (nickname) ? nickname: "", + range); + + return weechat_info_get ("nick_color_name_ignore_case", str_args); } /* diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 1c4106796..2cd37d1ff 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -334,72 +334,6 @@ irc_server_strncasecmp (struct t_irc_server *server, } /* - * Converts string to lower case, following server casemapping. - * - * Note: result must be freed after use. - */ - -char * -irc_server_string_tolower (struct t_irc_server *server, const char *string) -{ - char *result, *ptr_result; - int casemapping, range; - - if (!string) - return NULL; - - casemapping = (server) ? server->casemapping : -1; - if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) - casemapping = IRC_SERVER_CASEMAPPING_RFC1459; - - range = irc_server_casemapping_range[casemapping]; - - result = strdup (string); - ptr_result = result; - while (ptr_result && ptr_result[0]) - { - if ((ptr_result[0] >= 'A') && (ptr_result[0] < 'A' + range)) - ptr_result[0] += ('a' - 'A'); - ptr_result = (char *)weechat_utf8_next_char (ptr_result); - } - - return result; -} - -/* - * Converts string to upper case, following server casemapping. - * - * Note: result must be freed after use. - */ - -char * -irc_server_string_toupper (struct t_irc_server *server, const char *string) -{ - char *result, *ptr_result; - int casemapping, range; - - if (!string) - return NULL; - - casemapping = (server) ? server->casemapping : -1; - if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) - casemapping = IRC_SERVER_CASEMAPPING_RFC1459; - - range = irc_server_casemapping_range[casemapping]; - - result = strdup (string); - ptr_result = result; - while (ptr_result && ptr_result[0]) - { - if ((ptr_result[0] >= 'a') && (ptr_result[0] < 'a' + range)) - ptr_result[0] -= ('a' - 'A'); - ptr_result = (char *)weechat_utf8_next_char (ptr_result); - } - - return result; -} - -/* * Evaluates a string using the server as context: * ${irc_server.xxx} and ${server} are replaced by a server option and the * server name. diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 4ae647ed2..054516a8f 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -328,6 +328,7 @@ enum t_irc_fingerprint_digest_algo IRC_FINGERPRINT_NUM_ALGOS, }; +extern int irc_server_casemapping_range[]; extern char *irc_server_prefix_modes_default; extern char *irc_server_prefix_chars_default; extern char *irc_server_chanmodes_default; @@ -348,10 +349,6 @@ extern int irc_server_strcasecmp (struct t_irc_server *server, extern int irc_server_strncasecmp (struct t_irc_server *server, const char *string1, const char *string2, int max); -extern char *irc_server_string_tolower (struct t_irc_server *server, - const char *string); -extern char *irc_server_string_toupper (struct t_irc_server *server, - const char *string); extern char *irc_server_eval_expression (struct t_irc_server *server, const char *string); extern void irc_server_sasl_get_creds (struct t_irc_server *server, diff --git a/src/plugins/plugin-api-info.c b/src/plugins/plugin-api-info.c index 86443bf22..4d9f07b42 100644 --- a/src/plugins/plugin-api-info.c +++ b/src/plugins/plugin-api-info.c @@ -815,6 +815,7 @@ plugin_api_info_nick_color_cb (const void *pointer, void *data, result = gui_nick_find_color ( (num_items >= 1) ? items[0] : NULL, + -1, (num_items >= 2) ? items[1] : NULL); if (items) @@ -844,6 +845,7 @@ plugin_api_info_nick_color_name_cb (const void *pointer, void *data, result = gui_nick_find_color_name ( (num_items >= 1) ? items[0] : NULL, + -1, (num_items >= 2) ? items[1] : NULL); if (items) @@ -853,6 +855,84 @@ plugin_api_info_nick_color_name_cb (const void *pointer, void *data, } /* + * Returns nick color code for a nickname (case ignored using a range of chars). + */ + +char * +plugin_api_info_nick_color_ignore_case_cb (const void *pointer, void *data, + const char *info_name, + const char *arguments) +{ + char **items, *result, *error; + int num_items, case_range; + long number; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) info_name; + + items = string_split (arguments, ";", NULL, 0, 3, &num_items); + + case_range = -1; + if (num_items >= 2) + { + number = strtol (items[1], &error, 10); + if (error && !error[0]) + case_range = (int)number; + } + + result = gui_nick_find_color ( + (num_items >= 1) ? items[0] : NULL, + case_range, + (num_items >= 3) ? items[2] : NULL); + + if (items) + string_free_split (items); + + return result; +} + +/* + * Returns nick color name for a nickname (case ignored using a range of chars). + */ + +char * +plugin_api_info_nick_color_name_ignore_case_cb (const void *pointer, void *data, + const char *info_name, + const char *arguments) +{ + char **items, *result, *error; + int num_items, case_range; + long number; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) info_name; + + items = string_split (arguments, ";", NULL, 0, 3, &num_items); + + case_range = -1; + if (num_items >= 2) + { + number = strtol (items[1], &error, 10); + if (error && !error[0]) + case_range = (int)number; + } + + result = gui_nick_find_color_name ( + (num_items >= 1) ? items[0] : NULL, + case_range, + (num_items >= 3) ? items[2] : NULL); + + if (items) + string_free_split (items); + + return result; +} + +/* * Returns uptime according to the start date and arguments. */ @@ -2083,6 +2163,26 @@ plugin_api_info_init () "options with nick colors and forced nick colors are " "ignored)"), &plugin_api_info_nick_color_name_cb, NULL, NULL); + hook_info (NULL, "nick_color_ignore_case", + N_("get nick color code, ignoring case"), + N_("nickname;range;colors (range is a number of chars (see " + "function strcasecmp_range, 0 = convert to lower case without " + "using a range), colors is an optional comma-separated list " + "of colors to use; background is allowed for a color with " + "format text:background; if colors is present, WeeChat " + "options with nick colors and forced nick colors are " + "ignored)"), + &plugin_api_info_nick_color_ignore_case_cb, NULL, NULL); + hook_info (NULL, "nick_color_name_ignore_case", + N_("get nick color name, ignoring case"), + N_("nickname;range;colors (range is a number of chars (see " + "function strcasecmp_range, 0 = convert to lower case without " + "using a range), colors is an optional comma-separated list " + "of colors to use; background is allowed for a color with " + "format text:background; if colors is present, WeeChat " + "options with nick colors and forced nick colors are " + "ignored)"), + &plugin_api_info_nick_color_name_ignore_case_cb, NULL, NULL); hook_info (NULL, "uptime", N_("WeeChat uptime (format: \"days:hh:mm:ss\")"), N_("\"days\" (number of days) or \"seconds\" (number of " |