3
* (C) Copyright 1998-2004 Wojtek Kaniewski <wojtekka@toxygen.net>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include <sys/types.h>
23
#include "ydpconvert.h"
26
/* tablice konwersji */
27
u_char table_cp_iso[] = TABLE_CP_ISO;
28
u_char table_iso_plain[] = TABLE_ISO_PLAIN;
29
u_char *table_unicode[] = TABLE_UNICODE;
30
u_char *table_phonetic_iso[] = TABLE_PHONETIC_ISO;
32
u_char *char_table_conv(u_char *inp, u_char *table)
38
*inp = table[*inp - 128];
43
u_char *string_table_conv(u_char *inp, u_char **table)
45
static u_char buf[1024], letter[2] = " \0";
47
memset(buf, 0, sizeof(buf));
51
strncat(buf, table[*inp - 128], sizeof(buf) - strlen(buf) - 1);
54
strncat(buf, letter, sizeof(buf) - strlen(buf) - 1);
61
u_char *convert_cp1250(u_char *buf, int alloc)
63
return char_table_conv(alloc ? (u_char*) xstrdup(buf) : buf, table_cp_iso);
66
u_char *convert_plain(u_char *inp, int charset, int alloc)
70
return char_table_conv(alloc ? (u_char*) xstrdup(inp) : inp, table_iso_plain);
75
return string_table_conv(inp, table_unicode);
81
u_char *convert_phonetic(u_char *inp, int charset, int alloc)
85
return char_table_conv(string_table_conv(inp, table_phonetic_iso), table_iso_plain);
87
return string_table_conv(inp, table_phonetic_iso);
90
return string_table_conv(inp, table_unicode);