4 Copyright (C) 1999-2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "line-split.h"
27 unsigned char translation_in[256], translation_out[256];
29 void translation_reset(void)
33 for (n = 0; n < 256; n++)
34 translation_in[n] = (unsigned char) n;
35 for (n = 0; n < 256; n++)
36 translation_out[n] = (unsigned char) n;
39 void translate_output(char *text)
41 while (*text != '\0') {
42 *text = (char) translation_out[(int) (unsigned char) *text];
48 (isdigit(a) ? ((a)-'0') : (toupper(a)-'A'+10))
50 void translation_parse_line(const char *str, int *pos)
55 for (ptr = str; *ptr != '\0'; ptr++) {
56 if (ptr[0] != '0' || ptr[1] != 'x')
60 value = (gethex(ptr[0]) << 4) + gethex(ptr[1]);
62 translation_in[*pos] = (unsigned char) value;
64 translation_out[*pos-256] = (unsigned char) value;
68 if (*ptr != ',') break;
72 int translation_read(const char *file)
74 char tmpbuf[1024], *str, *path;
76 int f, pos, ret, recvlen;
78 g_return_val_if_fail(file != NULL, FALSE);
80 path = convert_home(file);
81 f = open(file, O_RDONLY);
84 if (f == -1) return FALSE;
86 pos = 0; buffer = NULL;
88 recvlen = read(f, tmpbuf, sizeof(tmpbuf));
90 ret = line_split(tmpbuf, recvlen, &str, &buffer);
93 translation_parse_line(str, &pos);
95 line_split_free(buffer);
103 static void read_settings(void)
105 translation_read(settings_get_str("translation"));
108 void translation_init(void)
112 settings_add_str("misc", "translation", "");
113 signal_add("setup changed", (SIGNAL_FUNC) read_settings);
118 void translation_deinit(void)
121 signal_remove("setup changed", (SIGNAL_FUNC) read_settings);