0.8.10claws78
[claws.git] / src / codeconv.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto
4  *
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.
9  *
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.
14  *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __CODECONV_H__
21 #define __CODECONV_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28
29 typedef struct _CodeConverter   CodeConverter;
30
31 typedef enum
32 {
33         C_AUTO,
34         C_US_ASCII,
35         C_UTF_8,
36         C_ISO_8859_1,
37         C_ISO_8859_2,
38         C_ISO_8859_4,
39         C_ISO_8859_5,
40         C_ISO_8859_7,
41         C_ISO_8859_8,
42         C_ISO_8859_9,
43         C_ISO_8859_11,
44         C_ISO_8859_13,
45         C_ISO_8859_15,
46         C_BALTIC,
47         C_CP1251,
48         C_WINDOWS_1251,
49         C_KOI8_R,
50         C_KOI8_U,
51         C_ISO_2022_JP,
52         C_ISO_2022_JP_2,
53         C_EUC_JP,
54         C_SHIFT_JIS,
55         C_ISO_2022_KR,
56         C_EUC_KR,
57         C_ISO_2022_CN,
58         C_EUC_CN,
59         C_GB2312,
60         C_EUC_TW,
61         C_BIG5,
62         C_TIS_620,
63         C_WINDOWS_874
64 } CharSet;
65
66 typedef void (*CodeConvFunc) (gchar *outbuf, gint outlen, const gchar *inbuf);
67
68 struct _CodeConverter
69 {
70         CodeConvFunc code_conv_func;
71         gchar *charset_str;
72         CharSet charset;
73 };
74
75 #define CS_AUTO                 "AUTO"
76 #define CS_US_ASCII             "US-ASCII"
77 #define CS_ANSI_X3_4_1968       "ANSI_X3.4-1968"
78 #define CS_UTF_8                "UTF-8"
79 #define CS_ISO_8859_1           "ISO-8859-1"
80 #define CS_ISO_8859_2           "ISO-8859-2"
81 #define CS_ISO_8859_4           "ISO-8859-4"
82 #define CS_ISO_8859_5           "ISO-8859-5"
83 #define CS_ISO_8859_7           "ISO-8859-7"
84 #define CS_ISO_8859_8           "ISO-8859-8"
85 #define CS_ISO_8859_9           "ISO-8859-9"
86 #define CS_ISO_8859_11          "ISO-8859-11"
87 #define CS_ISO_8859_13          "ISO-8859-13"
88 #define CS_ISO_8859_15          "ISO-8859-15"
89 #define CS_BALTIC               "BALTIC"
90 #define CS_CP1251               "CP1251"
91 #define CS_WINDOWS_1251         "Windows-1251"
92 #define CS_KOI8_R               "KOI8-R"
93 #define CS_KOI8_U               "KOI8-U"
94 #define CS_ISO_2022_JP          "ISO-2022-JP"
95 #define CS_ISO_2022_JP_2        "ISO-2022-JP-2"
96 #define CS_EUC_JP               "EUC-JP"
97 #define CS_EUCJP                "EUCJP"
98 #define CS_SHIFT_JIS            "Shift_JIS"
99 #define CS_SHIFT__JIS           "SHIFT-JIS"
100 #define CS_SJIS                 "SJIS"
101 #define CS_X_SJIS               "X-SJIS"
102 #define CS_ISO_2022_KR          "ISO-2022-KR"
103 #define CS_EUC_KR               "EUC-KR"
104 #define CS_ISO_2022_CN          "ISO-2022-CN"
105 #define CS_EUC_CN               "EUC-CN"
106 #define CS_GB2312               "GB2312"
107 #define CS_EUC_TW               "EUC-TW"
108 #define CS_BIG5                 "Big5"
109 #define CS_TIS_620              "TIS-620"
110 #define CS_WINDOWS_874          "Windows-874"
111
112 void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
113 void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf);
114 void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
115 void conv_anytoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
116 void conv_anytojis(gchar *outbuf, gint outlen, const gchar *inbuf);
117 void conv_unreadable_eucjp(gchar *str);
118 void conv_unreadable_8bit(gchar *str);
119 void conv_unreadable_latin(gchar *str);
120 void conv_mb_alnum(gchar *str);
121
122 CharSet conv_guess_ja_encoding(const gchar *str);
123
124 void conv_jistodisp  (gchar *outbuf, gint outlen, const gchar *inbuf);
125 void conv_sjistodisp (gchar *outbuf, gint outlen, const gchar *inbuf);
126 void conv_euctodisp  (gchar *outbuf, gint outlen, const gchar *inbuf);
127 void conv_ustodisp   (gchar *outbuf, gint outlen, const gchar *inbuf);
128 void conv_latintodisp(gchar *outbuf, gint outlen, const gchar *inbuf);
129 void conv_noconv     (gchar *outbuf, gint outlen, const gchar *inbuf);
130
131 void conv_localetodisp(gchar *outbuf, gint outlen, const gchar *inbuf);
132
133 CodeConverter *conv_code_converter_new  (const gchar    *charset);
134 void conv_code_converter_destroy        (CodeConverter  *conv);
135 gint conv_convert                       (CodeConverter  *conv,
136                                          gchar          *outbuf,
137                                          gint            outlen,
138                                          const gchar    *inbuf);
139
140 gchar *conv_codeset_strdup              (const gchar    *inbuf,
141                                          const gchar    *src_code,
142                                          const gchar    *dest_code);
143
144 CodeConvFunc conv_get_code_conv_func    (const gchar    *src_charset_str,
145                                          const gchar    *dest_charset_str);
146
147 #if HAVE_ICONV
148 gchar *conv_iconv_strdup                (const gchar    *inbuf,
149                                          const gchar    *src_code,
150                                          const gchar    *dest_code);
151 #endif
152
153 const gchar *conv_get_charset_str               (CharSet         charset);
154 CharSet conv_get_charset_from_str               (const gchar    *charset);
155 CharSet conv_get_current_charset                (void);
156 const gchar *conv_get_current_charset_str       (void);
157 CharSet conv_get_outgoing_charset               (void);
158 const gchar *conv_get_outgoing_charset_str      (void);
159
160 const gchar *conv_get_current_locale            (void);
161
162 void conv_unmime_header_overwrite       (gchar          *str);
163 void conv_unmime_header                 (gchar          *outbuf,
164                                          gint            outlen,
165                                          const gchar    *str,
166                                          const gchar    *charset);
167 void conv_encode_header                 (gchar          *dest,
168                                          gint            len,
169                                          const gchar    *src,
170                                          gint            header_len);
171
172
173 #endif /* __CODECONV_H__ */