diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-09-03 12:37:20 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-09-03 12:37:20 +0000 |
commit | d80c8e9e575239553719b4991b40e2dca6e6478e (patch) | |
tree | 6ab848f808bd4301452089eda9784801b706b0b6 /src/common | |
parent | f74b280a1fe2566d1182d1e2180d12a514b3d6c9 (diff) | |
download | weechat-d80c8e9e575239553719b4991b40e2dca6e6478e.zip |
Fixed bug with strings comparison (str[n]casecmp) and some locales (like turkish), now using ASCII comparison
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/command.c | 102 | ||||
-rw-r--r-- | src/common/completion.c | 116 | ||||
-rw-r--r-- | src/common/weechat.c | 76 | ||||
-rw-r--r-- | src/common/weechat.h | 2 | ||||
-rw-r--r-- | src/common/weeconfig.c | 52 | ||||
-rw-r--r-- | src/common/weelist.c | 4 |
6 files changed, 213 insertions, 139 deletions
diff --git a/src/common/command.c b/src/common/command.c index 0835cf192..073ed2a82 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -191,7 +191,7 @@ alias_search (char *alias_name) for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (strcasecmp (alias_name, ptr_alias->alias_name) == 0) + if (ascii_strcasecmp (alias_name, ptr_alias->alias_name) == 0) return ptr_alias; } return NULL; @@ -208,7 +208,7 @@ alias_find_pos (char *alias_name) for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (strcasecmp (alias_name, ptr_alias->alias_name) < 0) + if (ascii_strcasecmp (alias_name, ptr_alias->alias_name) < 0) return ptr_alias; } return NULL; @@ -484,7 +484,7 @@ exec_weechat_command (t_irc_server *server, char *string) for (i = 0; weechat_commands[i].command_name; i++) { - if (strcasecmp (weechat_commands[i].command_name, command + 1) == 0) + if (ascii_strcasecmp (weechat_commands[i].command_name, command + 1) == 0) { if ((argc < weechat_commands[i].min_arg) || (argc > weechat_commands[i].max_arg)) @@ -544,7 +544,7 @@ exec_weechat_command (t_irc_server *server, char *string) } for (i = 0; irc_commands[i].command_name; i++) { - if ((strcasecmp (irc_commands[i].command_name, command + 1) == 0) && + if ((ascii_strcasecmp (irc_commands[i].command_name, command + 1) == 0) && ((irc_commands[i].cmd_function_args) || (irc_commands[i].cmd_function_1arg))) { @@ -615,7 +615,7 @@ exec_weechat_command (t_irc_server *server, char *string) for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (strcasecmp (ptr_alias->alias_name, command + 1) == 0) + if (ascii_strcasecmp (ptr_alias->alias_name, command + 1) == 0) { if (ptr_args) { @@ -890,7 +890,7 @@ weechat_cmd_buffer (int argc, char **argv) char *error; int target_buffer; - if ((argc == 0) || ((argc == 1) && (strcasecmp (argv[0], "list") == 0))) + if ((argc == 0) || ((argc == 1) && (ascii_strcasecmp (argv[0], "list") == 0))) { /* list opened buffers */ @@ -908,7 +908,7 @@ weechat_cmd_buffer (int argc, char **argv) } else { - if (strcasecmp (argv[0], "move") == 0) + if (ascii_strcasecmp (argv[0], "move") == 0) { /* move buffer to another number in the list */ @@ -943,7 +943,7 @@ weechat_cmd_buffer (int argc, char **argv) return -1; } } - else if (strcasecmp (argv[0], "close") == 0) + else if (ascii_strcasecmp (argv[0], "close") == 0) { /* close buffer (server or channel/private) */ @@ -995,7 +995,7 @@ weechat_cmd_buffer (int argc, char **argv) } gui_draw_buffer_status (gui_current_window->buffer, 1); } - else if (strcasecmp (argv[0], "notify") == 0) + else if (ascii_strcasecmp (argv[0], "notify") == 0) { /* set notify level for buffer */ @@ -1114,7 +1114,7 @@ weechat_cmd_clear (int argc, char **argv) { if (argc == 1) { - if (strcasecmp (argv[0], "-all") == 0) + if (ascii_strcasecmp (argv[0], "-all") == 0) gui_buffer_clear_all (); else { @@ -1198,7 +1198,7 @@ weechat_cmd_debug (int argc, char **argv) return -1; } - if (strcasecmp (argv[0], "dump") == 0) + if (ascii_strcasecmp (argv[0], "dump") == 0) { wee_dump (0); } @@ -1294,7 +1294,7 @@ weechat_cmd_help (int argc, char **argv) { for (i = 0; weechat_commands[i].command_name; i++) { - if (strcasecmp (weechat_commands[i].command_name, argv[0]) == 0) + if (ascii_strcasecmp (weechat_commands[i].command_name, argv[0]) == 0) { gui_printf (NULL, "\n"); gui_printf (NULL, "[w]"); @@ -1319,7 +1319,7 @@ weechat_cmd_help (int argc, char **argv) } for (i = 0; irc_commands[i].command_name; i++) { - if ((strcasecmp (irc_commands[i].command_name, argv[0]) == 0) + if ((ascii_strcasecmp (irc_commands[i].command_name, argv[0]) == 0) && (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)) { gui_printf (NULL, "\n"); @@ -1402,7 +1402,7 @@ weechat_cmd_key (char *arguments) weechat_cmd_key_display (ptr_key, 0); } } - else if (strncasecmp (arguments, "unbind ", 7) == 0) + else if (ascii_strncasecmp (arguments, "unbind ", 7) == 0) { arguments += 7; while (arguments[0] == ' ') @@ -1418,7 +1418,7 @@ weechat_cmd_key (char *arguments) return -1; } } - else if (strcasecmp (arguments, "functions") == 0) + else if (ascii_strcasecmp (arguments, "functions") == 0) { gui_printf (NULL, "\n"); gui_printf (NULL, _("Internal key functions:\n")); @@ -1431,12 +1431,12 @@ weechat_cmd_key (char *arguments) i++; } } - else if (strncasecmp (arguments, "reset", 5) == 0) + else if (ascii_strncasecmp (arguments, "reset", 5) == 0) { arguments += 5; while (arguments[0] == ' ') arguments++; - if (strcasecmp (arguments, "-yes") == 0) + if (ascii_strcasecmp (arguments, "-yes") == 0) { gui_key_free_all (); gui_key_init (); @@ -1570,18 +1570,18 @@ weechat_cmd_perl (int argc, char **argv) break; case 1: - if (strcasecmp (argv[0], "autoload") == 0) + if (ascii_strcasecmp (argv[0], "autoload") == 0) plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload"); - else if (strcasecmp (argv[0], "reload") == 0) + else if (ascii_strcasecmp (argv[0], "reload") == 0) { plugin_unload (PLUGIN_TYPE_PERL, NULL); plugin_auto_load (PLUGIN_TYPE_PERL, "perl/autoload"); } - else if (strcasecmp (argv[0], "unload") == 0) + else if (ascii_strcasecmp (argv[0], "unload") == 0) plugin_unload (PLUGIN_TYPE_PERL, NULL); break; case 2: - if (strcasecmp (argv[0], "load") == 0) + if (ascii_strcasecmp (argv[0], "load") == 0) { /* load Perl script */ if (strstr(argv[1], DIR_SEPARATOR)) @@ -1713,18 +1713,18 @@ weechat_cmd_python (int argc, char **argv) break; case 1: - if (strcasecmp (argv[0], "autoload") == 0) + if (ascii_strcasecmp (argv[0], "autoload") == 0) plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload"); - else if (strcasecmp (argv[0], "reload") == 0) + else if (ascii_strcasecmp (argv[0], "reload") == 0) { plugin_unload (PLUGIN_TYPE_PYTHON, NULL); plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload"); } - else if (strcasecmp (argv[0], "unload") == 0) + else if (ascii_strcasecmp (argv[0], "unload") == 0) plugin_unload (PLUGIN_TYPE_PYTHON, NULL); break; case 2: - if (strcasecmp (argv[0], "load") == 0) + if (ascii_strcasecmp (argv[0], "load") == 0) { /* load Python script */ if (strstr(argv[1], DIR_SEPARATOR)) @@ -1856,18 +1856,18 @@ weechat_cmd_ruby (int argc, char **argv) break; case 1: - if (strcasecmp (argv[0], "autoload") == 0) + if (ascii_strcasecmp (argv[0], "autoload") == 0) plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload"); - else if (strcasecmp (argv[0], "reload") == 0) + else if (ascii_strcasecmp (argv[0], "reload") == 0) { plugin_unload (PLUGIN_TYPE_RUBY, NULL); plugin_auto_load (PLUGIN_TYPE_RUBY, "ruby/autoload"); } - else if (strcasecmp (argv[0], "unload") == 0) + else if (ascii_strcasecmp (argv[0], "unload") == 0) plugin_unload (PLUGIN_TYPE_RUBY, NULL); break; case 2: - if (strcasecmp (argv[0], "load") == 0) + if (ascii_strcasecmp (argv[0], "load") == 0) { /* load Ruby script */ if (strstr(argv[1], DIR_SEPARATOR)) @@ -1967,7 +1967,7 @@ weechat_cmd_server (int argc, char **argv) } else { - if (strcasecmp (argv[0], "del") == 0) + if (ascii_strcasecmp (argv[0], "del") == 0) { if (argc < 2) { @@ -2067,15 +2067,15 @@ weechat_cmd_server (int argc, char **argv) { if (argv[i][0] == '-') { - if (strcasecmp (argv[i], "-auto") == 0) + if (ascii_strcasecmp (argv[i], "-auto") == 0) server.autoconnect = 1; - if (strcasecmp (argv[i], "-noauto") == 0) + if (ascii_strcasecmp (argv[i], "-noauto") == 0) server.autoconnect = 0; - if (strcasecmp (argv[i], "-ipv6") == 0) + if (ascii_strcasecmp (argv[i], "-ipv6") == 0) server.ipv6 = 1; - if (strcasecmp (argv[i], "-ssl") == 0) + if (ascii_strcasecmp (argv[i], "-ssl") == 0) server.ssl = 1; - if (strcasecmp (argv[i], "-pwd") == 0) + if (ascii_strcasecmp (argv[i], "-pwd") == 0) { if (i == (argc - 1)) { @@ -2088,7 +2088,7 @@ weechat_cmd_server (int argc, char **argv) } server.password = strdup (argv[++i]); } - if (strcasecmp (argv[i], "-nicks") == 0) + if (ascii_strcasecmp (argv[i], "-nicks") == 0) { if (i >= (argc - 3)) { @@ -2103,7 +2103,7 @@ weechat_cmd_server (int argc, char **argv) server.nick2 = strdup (argv[++i]); server.nick3 = strdup (argv[++i]); } - if (strcasecmp (argv[i], "-username") == 0) + if (ascii_strcasecmp (argv[i], "-username") == 0) { if (i == (argc - 1)) { @@ -2116,7 +2116,7 @@ weechat_cmd_server (int argc, char **argv) } server.username = strdup (argv[++i]); } - if (strcasecmp (argv[i], "-realname") == 0) + if (ascii_strcasecmp (argv[i], "-realname") == 0) { if (i == (argc - 1)) { @@ -2129,7 +2129,7 @@ weechat_cmd_server (int argc, char **argv) } server.realname = strdup (argv[++i]); } - if (strcasecmp (argv[i], "-command") == 0) + if (ascii_strcasecmp (argv[i], "-command") == 0) { if (i == (argc - 1)) { @@ -2142,7 +2142,7 @@ weechat_cmd_server (int argc, char **argv) } server.command = strdup (argv[++i]); } - if (strcasecmp (argv[i], "-autojoin") == 0) + if (ascii_strcasecmp (argv[i], "-autojoin") == 0) { if (i == (argc - 1)) { @@ -2529,7 +2529,7 @@ weechat_cmd_window (int argc, char **argv) t_gui_window *ptr_win; int i; - if ((argc == 0) || ((argc == 1) && (strcasecmp (argv[0], "list") == 0))) + if ((argc == 0) || ((argc == 1) && (ascii_strcasecmp (argv[0], "list") == 0))) { /* list opened windows */ @@ -2558,29 +2558,29 @@ weechat_cmd_window (int argc, char **argv) } else { - if (strcasecmp (argv[0], "splith") == 0) + if (ascii_strcasecmp (argv[0], "splith") == 0) { /* split window horizontally */ gui_window_split_horiz (gui_current_window); } - else if (strcasecmp (argv[0], "splitv") == 0) + else if (ascii_strcasecmp (argv[0], "splitv") == 0) { /* split window vertically */ gui_window_split_vertic (gui_current_window); } - else if (strcasecmp (argv[0], "merge") == 0) + else if (ascii_strcasecmp (argv[0], "merge") == 0) { if (argc >= 2) { - if (strcasecmp (argv[1], "down") == 0) + if (ascii_strcasecmp (argv[1], "down") == 0) gui_window_merge_down (gui_current_window); - else if (strcasecmp (argv[1], "up") == 0) + else if (ascii_strcasecmp (argv[1], "up") == 0) gui_window_merge_up (gui_current_window); - else if (strcasecmp (argv[1], "left") == 0) + else if (ascii_strcasecmp (argv[1], "left") == 0) gui_window_merge_left (gui_current_window); - else if (strcasecmp (argv[1], "right") == 0) + else if (ascii_strcasecmp (argv[1], "right") == 0) gui_window_merge_right (gui_current_window); - else if (strcasecmp (argv[1], "all") == 0) + else if (ascii_strcasecmp (argv[1], "all") == 0) gui_window_merge_all (gui_current_window); else { @@ -2594,9 +2594,9 @@ weechat_cmd_window (int argc, char **argv) else gui_window_merge_auto (gui_current_window); } - else if (strcasecmp (argv[0], "-1") == 0) + else if (ascii_strcasecmp (argv[0], "-1") == 0) gui_switch_to_previous_window (); - else if (strcasecmp (argv[0], "+1") == 0) + else if (ascii_strcasecmp (argv[0], "+1") == 0) gui_switch_to_next_window (); else { diff --git a/src/common/completion.c b/src/common/completion.c index decfad2c8..41be8e894 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -111,13 +111,13 @@ completion_build_list (t_completion *completion, void *channel) /* WeeChat internal commands */ /* no completion for some commands */ - if ((strcasecmp (completion->base_command, "server") == 0) - || (strcasecmp (completion->base_command, "save") == 0)) + if ((ascii_strcasecmp (completion->base_command, "server") == 0) + || (ascii_strcasecmp (completion->base_command, "save") == 0)) { completion_stop (completion); return; } - if ((strcasecmp (completion->base_command, "alias") == 0) + if ((ascii_strcasecmp (completion->base_command, "alias") == 0) && (completion->base_command_arg == 1)) { for (ptr_list = index_commands; ptr_list; ptr_list = ptr_list->next_weelist) @@ -128,7 +128,7 @@ completion_build_list (t_completion *completion, void *channel) } return; } - if ((strcasecmp (completion->base_command, "buffer") == 0) + if ((ascii_strcasecmp (completion->base_command, "buffer") == 0) && (completion->base_command_arg == 1)) { weelist_add (&completion->completion_list, @@ -145,7 +145,7 @@ completion_build_list (t_completion *completion, void *channel) "notify"); return; } - if ((strcasecmp (completion->base_command, "clear") == 0) + if ((ascii_strcasecmp (completion->base_command, "clear") == 0) && (completion->base_command_arg == 1)) { weelist_add (&completion->completion_list, @@ -153,8 +153,8 @@ completion_build_list (t_completion *completion, void *channel) "-all"); return; } - if ((strcasecmp (completion->base_command, "connect") == 0) - || (strcasecmp (completion->base_command, "disconnect") == 0)) + if ((ascii_strcasecmp (completion->base_command, "connect") == 0) + || (ascii_strcasecmp (completion->base_command, "disconnect") == 0)) { if (completion->base_command_arg == 1) { @@ -173,7 +173,7 @@ completion_build_list (t_completion *completion, void *channel) return; } } - if (strcasecmp (completion->base_command, "debug") == 0) + if (ascii_strcasecmp (completion->base_command, "debug") == 0) { if (completion->base_command_arg == 1) weelist_add (&completion->completion_list, @@ -183,7 +183,7 @@ completion_build_list (t_completion *completion, void *channel) completion_stop (completion); return; } - if ((strcasecmp (completion->base_command, "help") == 0) + if ((ascii_strcasecmp (completion->base_command, "help") == 0) && (completion->base_command_arg == 1)) { for (i = 0; weechat_commands[i].command_name; i++) @@ -201,7 +201,7 @@ completion_build_list (t_completion *completion, void *channel) } return; } - if (strcasecmp (completion->base_command, "key") == 0) + if (ascii_strcasecmp (completion->base_command, "key") == 0) { if (completion->base_command_arg == 1) { @@ -229,8 +229,8 @@ completion_build_list (t_completion *completion, void *channel) return; } } - if (((strcasecmp (completion->base_command, "perl") == 0) - || (strcasecmp (completion->base_command, "python") == 0)) + if (((ascii_strcasecmp (completion->base_command, "perl") == 0) + || (ascii_strcasecmp (completion->base_command, "python") == 0)) && (completion->base_command_arg == 1)) { weelist_add (&completion->completion_list, @@ -247,7 +247,7 @@ completion_build_list (t_completion *completion, void *channel) "unload"); return; } - if (strcasecmp (completion->base_command, "set") == 0) + if (ascii_strcasecmp (completion->base_command, "set") == 0) { if (completion->base_command_arg == 1) { @@ -340,7 +340,7 @@ completion_build_list (t_completion *completion, void *channel) completion_stop (completion); return; } - if ((strcasecmp (completion->base_command, "unalias") == 0) + if ((ascii_strcasecmp (completion->base_command, "unalias") == 0) && (completion->base_command_arg == 1)) { for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) @@ -351,7 +351,7 @@ completion_build_list (t_completion *completion, void *channel) } return; } - if (strcasecmp (completion->base_command, "window") == 0) + if (ascii_strcasecmp (completion->base_command, "window") == 0) { if (completion->base_command_arg == 1) { @@ -397,33 +397,33 @@ completion_build_list (t_completion *completion, void *channel) /* IRC commands */ /* no completion for some commands */ - if ((strcasecmp (completion->base_command, "admin") == 0) - || (strcasecmp (completion->base_command, "die") == 0) - || (strcasecmp (completion->base_command, "info") == 0) - || (strcasecmp (completion->base_command, "join") == 0) - || (strcasecmp (completion->base_command, "links") == 0) - || (strcasecmp (completion->base_command, "list") == 0) - || (strcasecmp (completion->base_command, "lusers") == 0) - || (strcasecmp (completion->base_command, "motd") == 0) - || (strcasecmp (completion->base_command, "oper") == 0) - || (strcasecmp (completion->base_command, "rehash") == 0) - || (strcasecmp (completion->base_command, "restart") == 0) - || (strcasecmp (completion->base_command, "service") == 0) - || (strcasecmp (completion->base_command, "servlist") == 0) - || (strcasecmp (completion->base_command, "squery") == 0) - || (strcasecmp (completion->base_command, "squit") == 0) - || (strcasecmp (completion->base_command, "stats") == 0) - || (strcasecmp (completion->base_command, "summon") == 0) - || (strcasecmp (completion->base_command, "time") == 0) - || (strcasecmp (completion->base_command, "trace") == 0) - || (strcasecmp (completion->base_command, "users") == 0) - || (strcasecmp (completion->base_command, "wallops") == 0) - || (strcasecmp (completion->base_command, "who") == 0)) + if ((ascii_strcasecmp (completion->base_command, "admin") == 0) + || (ascii_strcasecmp (completion->base_command, "die") == 0) + || (ascii_strcasecmp (completion->base_command, "info") == 0) + || (ascii_strcasecmp (completion->base_command, "join") == 0) + || (ascii_strcasecmp (completion->base_command, "links") == 0) + || (ascii_strcasecmp (completion->base_command, "list") == 0) + || (ascii_strcasecmp (completion->base_command, "lusers") == 0) + || (ascii_strcasecmp (completion->base_command, "motd") == 0) + || (ascii_strcasecmp (completion->base_command, "oper") == 0) + || (ascii_strcasecmp (completion->base_command, "rehash") == 0) + || (ascii_strcasecmp (completion->base_command, "restart") == 0) + || (ascii_strcasecmp (completion->base_command, "service") == 0) + || (ascii_strcasecmp (completion->base_command, "servlist") == 0) + || (ascii_strcasecmp (completion->base_command, "squery") == 0) + || (ascii_strcasecmp (completion->base_command, "squit") == 0) + || (ascii_strcasecmp (completion->base_command, "stats") == 0) + || (ascii_strcasecmp (completion->base_command, "summon") == 0) + || (ascii_strcasecmp (completion->base_command, "time") == 0) + || (ascii_strcasecmp (completion->base_command, "trace") == 0) + || (ascii_strcasecmp (completion->base_command, "users") == 0) + || (ascii_strcasecmp (completion->base_command, "wallops") == 0) + || (ascii_strcasecmp (completion->base_command, "who") == 0)) { completion_stop (completion); return; } - if ((strcasecmp (completion->base_command, "away") == 0) + if ((ascii_strcasecmp (completion->base_command, "away") == 0) && (completion->base_command_arg == 1)) { if (cfg_irc_default_msg_away && cfg_irc_default_msg_away[0]) @@ -432,7 +432,7 @@ completion_build_list (t_completion *completion, void *channel) cfg_irc_default_msg_away); return; } - if ((strcasecmp (completion->base_command, "ctcp") == 0) + if ((ascii_strcasecmp (completion->base_command, "ctcp") == 0) && (completion->base_command_arg == 2)) { weelist_add (&completion->completion_list, @@ -446,7 +446,7 @@ completion_build_list (t_completion *completion, void *channel) "version"); return; } - if ((strcasecmp (completion->base_command, "dcc") == 0) + if ((ascii_strcasecmp (completion->base_command, "dcc") == 0) && (completion->base_command_arg == 1)) { weelist_add (&completion->completion_list, @@ -460,7 +460,7 @@ completion_build_list (t_completion *completion, void *channel) "close"); return; } - if (strcasecmp (completion->base_command, "invite") == 0) + if (ascii_strcasecmp (completion->base_command, "invite") == 0) { /* arg1: nickname */ if (completion->base_command_arg == 1) @@ -486,30 +486,30 @@ completion_build_list (t_completion *completion, void *channel) } return; } - if (strcasecmp (completion->base_command, "kick") == 0) + if (ascii_strcasecmp (completion->base_command, "kick") == 0) { if (completion->base_command_arg != 1) completion_stop (completion); return; } - if (strcasecmp (completion->base_command, "kill") == 0) + if (ascii_strcasecmp (completion->base_command, "kill") == 0) { if (completion->base_command_arg != 1) completion_stop (completion); return; } - if (strcasecmp (completion->base_command, "me") == 0) + if (ascii_strcasecmp (completion->base_command, "me") == 0) { completion->context = COMPLETION_NICK; return; } - if (strcasecmp (completion->base_command, "notice") == 0) + if (ascii_strcasecmp (completion->base_command, "notice") == 0) { if (completion->base_command_arg != 1) completion_stop (completion); return; } - if ((strcasecmp (completion->base_command, "part") == 0) + if ((ascii_strcasecmp (completion->base_command, "part") == 0) && (completion->base_command_arg == 1)) { if (cfg_irc_default_msg_part && cfg_irc_default_msg_part[0]) @@ -518,13 +518,13 @@ completion_build_list (t_completion *completion, void *channel) cfg_irc_default_msg_part); return; } - if (strcasecmp (completion->base_command, "query") == 0) + if (ascii_strcasecmp (completion->base_command, "query") == 0) { if (completion->base_command_arg != 1) completion_stop (completion); return; } - if ((strcasecmp (completion->base_command, "quit") == 0) + if ((ascii_strcasecmp (completion->base_command, "quit") == 0) && (completion->base_command_arg == 1)) { if (cfg_irc_default_msg_quit && cfg_irc_default_msg_quit[0]) @@ -533,7 +533,7 @@ completion_build_list (t_completion *completion, void *channel) cfg_irc_default_msg_quit); return; } - if (strcasecmp (completion->base_command, "topic") == 0) + if (ascii_strcasecmp (completion->base_command, "topic") == 0) { if (completion->base_command_arg == 1) { @@ -717,7 +717,7 @@ completion_command (t_completion *completion) other_completion = 0; for (ptr_weelist = index_commands; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) { - if (strncasecmp (ptr_weelist->data, completion->base_word + 1, length) == 0) + if (ascii_strncasecmp (ptr_weelist->data, completion->base_word + 1, length) == 0) { if ((!completion->word_found) || word_found_seen) { @@ -725,7 +725,7 @@ completion_command (t_completion *completion) for (ptr_weelist2 = ptr_weelist->next_weelist; ptr_weelist2; ptr_weelist2 = ptr_weelist2->next_weelist) { - if (strncasecmp (ptr_weelist2->data, + if (ascii_strncasecmp (ptr_weelist2->data, completion->base_word + 1, length) == 0) other_completion++; } @@ -739,7 +739,7 @@ completion_command (t_completion *completion) other_completion++; } if (completion->word_found && - (strcasecmp (ptr_weelist->data, completion->word_found) == 0)) + (ascii_strcasecmp (ptr_weelist->data, completion->word_found) == 0)) word_found_seen = 1; } if (completion->word_found) @@ -765,7 +765,7 @@ completion_command_arg (t_completion *completion, t_irc_channel *channel) for (ptr_weelist = completion->completion_list; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) { - if (strncasecmp (ptr_weelist->data, completion->base_word, length) == 0) + if (ascii_strncasecmp (ptr_weelist->data, completion->base_word, length) == 0) { if ((!completion->word_found) || word_found_seen) { @@ -773,7 +773,7 @@ completion_command_arg (t_completion *completion, t_irc_channel *channel) for (ptr_weelist2 = ptr_weelist->next_weelist; ptr_weelist2; ptr_weelist2 = ptr_weelist2->next_weelist) { - if (strncasecmp (ptr_weelist2->data, + if (ascii_strncasecmp (ptr_weelist2->data, completion->base_word, length) == 0) other_completion++; } @@ -787,7 +787,7 @@ completion_command_arg (t_completion *completion, t_irc_channel *channel) other_completion++; } if (completion->word_found && - (strcasecmp (ptr_weelist->data, completion->word_found) == 0)) + (ascii_strcasecmp (ptr_weelist->data, completion->word_found) == 0)) word_found_seen = 1; } if (completion->word_found) @@ -821,7 +821,7 @@ completion_nick (t_completion *completion, t_irc_channel *channel) other_completion = 0; for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick) { - if (strncasecmp (ptr_nick->nick, completion->base_word, length) == 0) + if (ascii_strncasecmp (ptr_nick->nick, completion->base_word, length) == 0) { if ((!completion->word_found) || word_found_seen) { @@ -829,7 +829,7 @@ completion_nick (t_completion *completion, t_irc_channel *channel) for (ptr_nick2 = ptr_nick->next_nick; ptr_nick2; ptr_nick2 = ptr_nick2->next_nick) { - if (strncasecmp (ptr_nick2->nick, + if (ascii_strncasecmp (ptr_nick2->nick, completion->base_word, length) == 0) other_completion++; } @@ -843,7 +843,7 @@ completion_nick (t_completion *completion, t_irc_channel *channel) other_completion++; } if (completion->word_found && - (strcasecmp (ptr_nick->nick, completion->word_found) == 0)) + (ascii_strcasecmp (ptr_nick->nick, completion->word_found) == 0)) word_found_seen = 1; } if (completion->word_found) diff --git a/src/common/weechat.c b/src/common/weechat.c index b8692da57..f0ed84597 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -84,6 +84,78 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ /* + * ascii_strcasecmp: locale and case independent string comparison + */ + +int +ascii_strcasecmp (char *string1, char *string2) +{ + int c1, c2; + + if (!string1 || !string2) + return (string1) ? 1 : ((string2) ? -1 : 0); + + while (string1[0] && string2[0]) + { + c1 = (int)((unsigned char) string1[0]); + c2 = (int)((unsigned char) string2[0]); + + if ((c1 >= 'A') && (c1 <= 'Z')) + c1 += ('a' - 'A'); + + if ((c2 >= 'A') && (c2 <= 'Z')) + c2 += ('a' - 'A'); + + if ((c1 - c2) != 0) + return c1 - c2; + + string1++; + string2++; + } + + return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); +} + +/* + * ascii_strncasecmp: locale and case independent string comparison + * with max length + */ + +int +ascii_strncasecmp (char *string1, char *string2, int max) +{ + int c1, c2, count; + + if (!string1 || !string2) + return (string1) ? 1 : ((string2) ? -1 : 0); + + count = 0; + while ((count < max) && string1[0] && string2[0]) + { + c1 = (int)((unsigned char) string1[0]); + c2 = (int)((unsigned char) string2[0]); + + if ((c1 >= 'A') && (c1 <= 'Z')) + c1 += ('a' - 'A'); + + if ((c2 >= 'A') && (c2 <= 'Z')) + c2 += ('a' - 'A'); + + if ((c1 - c2) != 0) + return c1 - c2; + + string1++; + string2++; + count++; + } + + if (count >= max) + return 0; + else + return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); +} + +/* * wee_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log) */ @@ -131,7 +203,7 @@ weechat_convert_encoding (char *from_code, char *to_code, char *string) size_t inbytesleft, outbytesleft; if (from_code && from_code[0] && to_code && to_code[0] - && (strcasecmp(from_code, to_code) != 0)) + && (ascii_strcasecmp(from_code, to_code) != 0)) { cd = iconv_open (to_code, from_code); if (cd == (iconv_t)(-1)) @@ -418,7 +490,7 @@ wee_parse_args (int argc, char *argv[]) wee_display_commands (1, 0); wee_shutdown (EXIT_SUCCESS, 0); } - else if ((strncasecmp (argv[i], "irc", 3) == 0)) + else if ((ascii_strncasecmp (argv[i], "irc", 3) == 0)) { if (server_init_with_url (argv[i], &server_tmp) < 0) { diff --git a/src/common/weechat.h b/src/common/weechat.h index 9304671a8..80771d700 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -118,6 +118,8 @@ extern char *local_charset; extern gnutls_certificate_credentials gnutls_xcred; #endif +extern int ascii_strcasecmp (char *, char *); +extern int ascii_strncasecmp (char *, char *, int); extern void wee_log_printf (char *, ...); extern void wee_dump (int); extern char *weechat_convert_encoding (char *, char *, char *); diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index 31bd94833..2b181d1ae 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -775,7 +775,7 @@ get_pos_array_values (char **array, char *string) i = 0; while (array[i]) { - if (strcasecmp (array[i], string) == 0) + if (ascii_strcasecmp (array[i], string) == 0) return i; i++; } @@ -926,9 +926,9 @@ config_option_set_value (t_config_option *option, char *value) switch (option->option_type) { case OPTION_TYPE_BOOLEAN: - if (strcasecmp (value, "on") == 0) + if (ascii_strcasecmp (value, "on") == 0) *(option->ptr_int) = BOOL_TRUE; - else if (strcasecmp (value, "off") == 0) + else if (ascii_strcasecmp (value, "off") == 0) *(option->ptr_int) = BOOL_FALSE; else return -1; @@ -965,43 +965,43 @@ config_option_set_value (t_config_option *option, char *value) void * config_get_server_option_ptr (t_irc_server *server, char *option_name) { - if (strcasecmp (option_name, "server_name") == 0) + if (ascii_strcasecmp (option_name, "server_name") == 0) return (void *)(&server->name); - if (strcasecmp (option_name, "server_autoconnect") == 0) + if (ascii_strcasecmp (option_name, "server_autoconnect") == 0) return (void *)(&server->autoconnect); - if (strcasecmp (option_name, "server_autoreconnect") == 0) + if (ascii_strcasecmp (option_name, "server_autoreconnect") == 0) return (void *)(&server->autoreconnect); - if (strcasecmp (option_name, "server_autoreconnect_delay") == 0) + if (ascii_strcasecmp (option_name, "server_autoreconnect_delay") == 0) return (void *)(&server->autoreconnect_delay); - if (strcasecmp (option_name, "server_address") == 0) + if (ascii_strcasecmp (option_name, "server_address") == 0) return (void *)(&server->address); - if (strcasecmp (option_name, "server_port") == 0) + if (ascii_strcasecmp (option_name, "server_port") == 0) return (void *)(&server->port); - if (strcasecmp (option_name, "server_ipv6") == 0) + if (ascii_strcasecmp (option_name, "server_ipv6") == 0) return (void *)(&server->ipv6); - if (strcasecmp (option_name, "server_ssl") == 0) + if (ascii_strcasecmp (option_name, "server_ssl") == 0) return (void *)(&server->ssl); - if (strcasecmp (option_name, "server_password") == 0) + if (ascii_strcasecmp (option_name, "server_password") == 0) return (void *)(&server->password); - if (strcasecmp (option_name, "server_nick1") == 0) + if (ascii_strcasecmp (option_name, "server_nick1") == 0) return (void *)(&server->nick1); - if (strcasecmp (option_name, "server_nick2") == 0) + if (ascii_strcasecmp (option_name, "server_nick2") == 0) return (void *)(&server->nick2); - if (strcasecmp (option_name, "server_nick3") == 0) + if (ascii_strcasecmp (option_name, "server_nick3") == 0) return (void *)(&server->nick3); - if (strcasecmp (option_name, "server_username") == 0) + if (ascii_strcasecmp (option_name, "server_username") == 0) return (void *)(&server->username); - if (strcasecmp (option_name, "server_realname") == 0) + if (ascii_strcasecmp (option_name, "server_realname") == 0) return (void *)(&server->realname); - if (strcasecmp (option_name, "server_command") == 0) + if (ascii_strcasecmp (option_name, "server_command") == 0) return (void *)(&server->command); - if (strcasecmp (option_name, "server_command_delay") == 0) + if (ascii_strcasecmp (option_name, "server_command_delay") == 0) return (void *)(&server->command_delay); - if (strcasecmp (option_name, "server_autojoin") == 0) + if (ascii_strcasecmp (option_name, "server_autojoin") == 0) return (void *)(&server->autojoin); - if (strcasecmp (option_name, "server_autorejoin") == 0) + if (ascii_strcasecmp (option_name, "server_autorejoin") == 0) return (void *)(&server->autorejoin); - if (strcasecmp (option_name, "server_notify_levels") == 0) + if (ascii_strcasecmp (option_name, "server_notify_levels") == 0) return (void *)(&server->notify_levels); /* option not found */ return NULL; @@ -1031,7 +1031,7 @@ config_set_server_value (t_irc_server *server, char *option_name, for (i = 0; weechat_options[CONFIG_SECTION_SERVER][i].option_name; i++) { /* if option found, return pointer */ - if (strcasecmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, option_name) == 0) + if (ascii_strcasecmp (weechat_options[CONFIG_SECTION_SERVER][i].option_name, option_name) == 0) { ptr_option = &weechat_options[CONFIG_SECTION_SERVER][i]; break; @@ -1043,9 +1043,9 @@ config_set_server_value (t_irc_server *server, char *option_name, switch (ptr_option->option_type) { case OPTION_TYPE_BOOLEAN: - if (strcasecmp (value, "on") == 0) + if (ascii_strcasecmp (value, "on") == 0) *((int *)(ptr_data)) = BOOL_TRUE; - else if (strcasecmp (value, "off") == 0) + else if (ascii_strcasecmp (value, "off") == 0) *((int *)(ptr_data)) = BOOL_FALSE; else return -2; @@ -1095,7 +1095,7 @@ config_option_search (char *option_name) for (j = 0; weechat_options[i][j].option_name; j++) { /* if option found, return pointer */ - if (strcasecmp (weechat_options[i][j].option_name, option_name) == 0) + if (ascii_strcasecmp (weechat_options[i][j].option_name, option_name) == 0) return &weechat_options[i][j]; } } diff --git a/src/common/weelist.c b/src/common/weelist.c index e4bf30ef9..2a34937e2 100644 --- a/src/common/weelist.c +++ b/src/common/weelist.c @@ -42,7 +42,7 @@ weelist_search (t_weelist *weelist, char *data) for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) { - if (strcasecmp (data, ptr_weelist->data) == 0) + if (ascii_strcasecmp (data, ptr_weelist->data) == 0) return ptr_weelist; } /* word not found in list */ @@ -60,7 +60,7 @@ weelist_find_pos (t_weelist *weelist, char *data) for (ptr_weelist = weelist; ptr_weelist; ptr_weelist = ptr_weelist->next_weelist) { - if (strcasecmp (data, ptr_weelist->data) < 0) + if (ascii_strcasecmp (data, ptr_weelist->data) < 0) return ptr_weelist; } /* position not found, best position is at the end */ |