diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-01-02 02:10:10 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-01-02 02:10:10 +0000 |
commit | b2c5317e17f27170a0a831b74c819c671c29ec44 (patch) | |
tree | 823ba13b1e2d8f733be720d67bb235a2a8cdbc5b /src/common | |
parent | 9adb547b36bc6d0ab40ac558021697a16e29d8fb (diff) | |
download | weechat-b2c5317e17f27170a0a831b74c819c671c29ec44.zip |
Added new options look_charset_decode/look_charset_encode and /unset command.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/command.c | 43 | ||||
-rw-r--r-- | src/common/command.h | 1 | ||||
-rw-r--r-- | src/common/weechat.c | 49 | ||||
-rw-r--r-- | src/common/weechat.h | 2 | ||||
-rw-r--r-- | src/common/weeconfig.c | 10 | ||||
-rw-r--r-- | src/common/weeconfig.h | 2 |
6 files changed, 107 insertions, 0 deletions
diff --git a/src/common/command.c b/src/common/command.c index a20b5ea03..61765b570 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -97,6 +97,9 @@ t_weechat_command weechat_commands[] = { "unalias", N_("remove an alias"), N_("alias_name"), N_("alias_name: name of alias to remove"), 1, 1, NULL, weechat_cmd_unalias }, + { "unset", N_("reset config parameters"), + N_("option"), N_("option: name of an option"), + 1, 1, NULL, weechat_cmd_unset }, { "window", N_("manage windows"), N_("[action]"), N_("action: action to do:\n" @@ -1836,6 +1839,46 @@ weechat_cmd_unalias (char *arguments) } /* + * weechat_cmd_unset: reset options + */ + +int +weechat_cmd_unset (char *arguments) +{ + t_config_option *ptr_option; + + ptr_option = config_option_search (arguments); + if (ptr_option) + { + if (ptr_option->handler_change == NULL) + { + gui_printf (NULL, + _("%s option \"%s\" can not be changed while WeeChat is running\n"), + WEECHAT_ERROR, arguments); + } + else + { + if (config_option_set_value (ptr_option, "") == 0) + { + (void) (ptr_option->handler_change()); + gui_printf (NULL, "[%s]\n", config_get_section (ptr_option)); + gui_printf (NULL, " %s =\n", arguments); + } + else + gui_printf (NULL, _("%s option \"%s\" can not be reset (use " + "/set command to change this option)\n"), + WEECHAT_ERROR, arguments); + } + } + else + { + gui_printf (NULL, _("%s config option \"%s\" not found\n"), + WEECHAT_ERROR, arguments); + } + return 0; +} + +/* * weechat_cmd_window: manage windows */ diff --git a/src/common/command.h b/src/common/command.h index a8ecd8e3b..586cb7737 100644 --- a/src/common/command.h +++ b/src/common/command.h @@ -77,6 +77,7 @@ extern int weechat_cmd_save (int, char **); extern int weechat_cmd_server (int, char **); extern int weechat_cmd_set (char *); extern int weechat_cmd_unalias (char *); +extern int weechat_cmd_unset (char *); extern int weechat_cmd_window (int, char **); #endif /* command.h */ diff --git a/src/common/weechat.c b/src/common/weechat.c index 0e9724243..4c4ba7f6c 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -49,6 +49,8 @@ #include <sys/stat.h> #include <time.h> #include <signal.h> +#include <iconv.h> +#include <langinfo.h> #include "weechat.h" #include "weeconfig.h" @@ -62,6 +64,8 @@ int quit_weechat; /* = 1 if quit request from user... why ? :'( */ char *weechat_home; /* WeeChat home dir. (example: /home/toto/.weechat) */ FILE *weechat_log_file; /* WeeChat log file (~/.weechat/weechat.log) */ +char *local_charset = NULL; /* local charset, for example: ISO-8859-1 */ + int server_cmd_line; /* at least one server on WeeChat command line */ @@ -77,6 +81,49 @@ my_sigint () } /* + * weechat_convert_encoding: convert string to another encoding + */ + +char * +weechat_convert_encoding (char *from_code, char *to_code, char *string) +{ + iconv_t cd; + char *inbuf, *ptr_inbuf, *outbuf, *ptr_outbuf; + int inbytesleft, outbytesleft; + + if (from_code && from_code[0] && to_code && to_code[0] + && (strcasecmp(from_code, to_code) != 0)) + { + cd = iconv_open (to_code, from_code); + if (cd == (iconv_t)(-1)) + outbuf = strdup (string); + else + { + inbuf = strdup (string); + ptr_inbuf = inbuf; + inbytesleft = strlen (inbuf); + outbytesleft = inbytesleft * 4; + outbuf = (char *) malloc (outbytesleft + 2); + ptr_outbuf = outbuf; + iconv (cd, &ptr_inbuf, &inbytesleft, &ptr_outbuf, &outbytesleft); + if (inbytesleft != 0) + { + free (outbuf); + outbuf = strdup (string); + } + else + ptr_outbuf[0] = '\0'; + free (inbuf); + iconv_close (cd); + } + } + else + outbuf = strdup (string); + + return outbuf; +} + +/* * wee_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log) */ @@ -469,6 +516,8 @@ main (int argc, char *argv[]) textdomain (PACKAGE); #endif + local_charset = strdup (nl_langinfo (CODESET)); + signal (SIGINT, my_sigint); /* ignore SIGINT signal */ gui_pre_init (&argc, &argv); /* pre-initiliaze interface */ wee_init_vars (); /* initialize some variables */ diff --git a/src/common/weechat.h b/src/common/weechat.h index c2fdaab42..df8691433 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -102,7 +102,9 @@ extern int quit_weechat; extern char *weechat_home; +extern char *local_charset; +extern char *weechat_convert_encoding (char *, char *, char *); extern void wee_log_printf (char *, ...); extern void wee_shutdown (); diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index 05f8a6731..ea88d11b7 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -60,6 +60,8 @@ int cfg_look_set_title; int cfg_look_startup_logo; int cfg_look_startup_version; char *cfg_look_weechat_slogan; +char *cfg_look_charset_decode; +char *cfg_look_charset_encode; int cfg_look_color_nicks; int cfg_look_color_actions; int cfg_look_remove_colors_from_msgs; @@ -95,6 +97,14 @@ t_config_option weechat_options_look[] = N_("WeeChat slogan (if empty, slogan is not used)"), OPTION_TYPE_STRING, 0, 0, 0, "the geekest IRC client!", NULL, NULL, &cfg_look_weechat_slogan, config_change_noop }, + { "look_charset_decode", N_("charset for decoding messages from server"), + N_("charset for decoding messages from server, examples: UTF-8, ISO-8859-1 (if empty, messages are not converted)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &cfg_look_charset_decode, config_change_buffer_content }, + { "look_charset_encode", N_("charset for encoding messages sent to server"), + N_("charset for encoding messages sent to server, examples: UFT-8, ISO-8859-1 (if empty, local charset is used)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &cfg_look_charset_encode, config_change_buffer_content }, { "look_color_nicks", N_("display nick names with different colors"), N_("display nick names with different colors"), OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h index 15b822d9b..e9b3d26b3 100644 --- a/src/common/weeconfig.h +++ b/src/common/weeconfig.h @@ -77,6 +77,8 @@ extern int cfg_look_set_title; extern int cfg_look_startup_logo; extern int cfg_look_startup_version; extern char *cfg_look_weechat_slogan; +extern char *cfg_look_charset_decode; +extern char *cfg_look_charset_encode; extern int cfg_look_color_nicks; extern int cfg_look_color_actions; extern int cfg_look_remove_colors_from_msgs; |