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/tty_filter.c | |
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/tty_filter.c')
-rw-r--r-- | zwgc/tty_filter.c | 30 |
1 files changed, 27 insertions, 3 deletions
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 = ' '; |