diff options
author | Karl Ramm <kcr@1ts.org> | 2009-04-18 18:30:45 +0000 |
---|---|---|
committer | Karl Ramm <kcr@1ts.org> | 2009-04-18 18:30:45 +0000 |
commit | 8efc3c3886115ee61fc6f43a7ecb6cb1a63b7bd6 (patch) | |
tree | 328b4fd063ddcd17bb15556e74ac2c1578d97cab /zwgc | |
parent | fc19902115b3403f21ec5b27aee04b90191fc565 (diff) |
Zephyrgrams to the tty port now undergo character set conversion.
This completes ticket #5.
zwgc/notice.c
record the charset of the current notice as the notice_charset variable
zwgc/standard_ports.
set the tty_charset variable. We do this here instead of tty_filter.c
because tty_filter_init gets called twice, and has consumed the command
line arguments the first time.
zwgc/tty_filter.c
New function, zwgc_transliterate, which wraps ZTransliterate with a
bit of local color. It's called from convert_desc_to_tty_str_info.
New global static info_default_string holds a reused pointer to ""
so we don't try to free it from free_info.
Diffstat (limited to 'zwgc')
-rw-r--r-- | zwgc/notice.c | 2 | ||||
-rw-r--r-- | zwgc/standard_ports.c | 9 | ||||
-rw-r--r-- | zwgc/tty_filter.c | 30 |
3 files changed, 37 insertions, 4 deletions
diff --git a/zwgc/notice.c b/zwgc/notice.c index 3ca2dc7..47a58ac 100644 --- a/zwgc/notice.c +++ b/zwgc/notice.c @@ -272,7 +272,7 @@ decode_notice(ZNotice_t *notice, var_set_variable("instance", notice->z_class_inst); var_set_variable("opcode", notice->z_opcode); var_set_variable("default", notice->z_default_format); - var_set_variable("charset", (char *)ZCharsetToString(notice->z_charset)); /*XXX const*/ + var_set_variable("notice_charset", (char *)ZCharsetToString(notice->z_charset)); /*XXX const*/ var_set_variable("recipient", (notice->z_recipient[0] ? notice->z_recipient : "*")); var_set_variable("fullsender", notice->z_sender); diff --git a/zwgc/standard_ports.c b/zwgc/standard_ports.c index fa535da..bfbd81a 100644 --- a/zwgc/standard_ports.c +++ b/zwgc/standard_ports.c @@ -198,10 +198,12 @@ void init_standard_ports(int *pargc, string default_port = ""; char **new, **current; int fallback; + char *charset = NULL; /* * Process argument list handling "-disable <port>" and * "-default <output port>" arguments, as well as "-ttymode" + * and -charset, because tty_filter_init gets run twice */ for (new=current=argv+1; *current; current++) { if (string_Eq((string) *current, "-disable")) { @@ -219,6 +221,11 @@ void init_standard_ports(int *pargc, p = get_standard_port_info((string) *current); if (p) p->port_setup_status = DEFAULT_OK; + } else if (string_Eq((string) *current, "-charset")) { + current++; *pargc -= 2; + if (!*current) + usage(); + charset = *current; } else if (string_Eq((string) *current, "-ttymode")) { default_port = (string) "tty"; (*pargc)--; @@ -234,6 +241,8 @@ void init_standard_ports(int *pargc, } *new = *current; + var_set_variable_then_free_value("tty_charset", (string)ZGetCharsetString(charset)); + fallback = boolean_value_of(ZGetVariable("fallback")); /* * Initialize all non-disabled ports. If a port reports an error, diff --git a/zwgc/tty_filter.c b/zwgc/tty_filter.c index 81f2365..6921b5f 100644 --- a/zwgc/tty_filter.c +++ b/zwgc/tty_filter.c @@ -32,8 +32,11 @@ static const char rcsid_tty_filter_c[] = "$Id$"; #endif #endif +#include <zephyr/zephyr.h> + #include "new_memory.h" #include "new_string.h" +#include "variables.h" #include "string_dictionary_aux.h" #include "formatter.h" #include "zwgc.h" @@ -235,6 +238,8 @@ typedef struct _tty_str_info { unsigned int ignore: 1; } tty_str_info; +const char *info_default_string = ""; + static void free_info(tty_str_info *info) { @@ -242,6 +247,8 @@ free_info(tty_str_info *info) while (info) { next_info = info->next; + if (info->str != info_default_string) + free(info->str); free(info); info = next_info; } @@ -286,6 +293,24 @@ do_mode_change(tty_str_info *current_mode_p, return 0; } +static void +zwgc_transliterate(char *in, int inlen, char **out, int *outlen){ + int retval = 0; + string notice_charset = var_get_variable("notice_charset"); + string tty_charset = var_get_variable("tty_charset"); + + if (string_Eq(notice_charset, "UNKNOWN") || + string_Eq(notice_charset, tty_charset) || + (retval = ZTransliterate(in, inlen, + notice_charset, tty_charset, + out, outlen)) != 0) { + *out = string_CreateFromData(in, inlen); + *outlen = inlen; + } + if (retval != 0) + var_set_variable("error", strerror(retval)); +} + static tty_str_info * convert_desc_to_tty_str_info(desctype *desc) { @@ -301,7 +326,7 @@ convert_desc_to_tty_str_info(desctype *desc) tty_str_info current_mode; current_mode.next = NULL; - current_mode.str = ""; + current_mode.str = info_default_string; /* "" */ current_mode.len = 0; current_mode.alignment = 'l'; current_mode.bold_p = 0; @@ -356,8 +381,7 @@ convert_desc_to_tty_str_info(desctype *desc) } if (desc->code == DT_STR) { /* just combine string info with current mode: */ - temp->str = desc->str; - temp->len = desc->len; + zwgc_transliterate(desc->str, desc->len, &temp->str, &temp->len); } else if (desc->code == DT_NL) { /* make the new block a ' ' alignment block with an empty string */ temp->alignment = ' '; |