dd44047d768b03909faa675338aba29e7d92548b
[apps/madmutt.git] / charset.h
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2006 Pierre Habouzit
18  */
19 /*
20  * Copyright notice from original mutt:
21  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
22  *
23  * This file is part of mutt-ng, see http://www.muttng.org/.
24  * It's licensed under the GNU General Public License,
25  * please see the file GPL in the top level source directory.
26  */
27
28 #ifndef _CHARSET_H
29 #define _CHARSET_H
30
31 #ifdef HAVE_CONFIG_H
32 #  include "config.h"
33 #endif
34
35 /****************************************************************************/
36 /* charset functions                                                        */
37 /****************************************************************************/
38
39 extern char *Charset;
40 extern int Charset_is_utf8;
41 extern wchar_t CharsetReplacement;
42
43 void charset_initialize(void);
44 void charset_canonicalize(char *, ssize_t, const char *);
45 int charset_is_utf8(const char *s);
46 int charset_is_us_ascii(const char *s);
47
48
49 /****************************************************************************/
50 /* iconv-line functions                                                     */
51 /****************************************************************************/
52
53 #ifdef HAVE_ICONV_H
54 #  include <iconv.h>
55
56 static inline ssize_t
57 my_iconv(iconv_t ict, const char **in, ssize_t *il, char **out, ssize_t *ol) {
58     return iconv(ict, (char **)in, (size_t*)il, out, (size_t*)ol);
59 }
60
61 #else
62 #  define iconv_t              void*
63 #  define iconv_open(a, b)     ((iconv_t)(-1))
64 #  define my_iconv(a,b,c,d,e)  0
65 #  define iconv_close(a)       0
66 #endif
67
68 #define M_ICONV_HOOK_FROM 1
69 #define M_ICONV_HOOK_TO   2
70
71 int mutt_convert_string (char **, const char *, const char *, int);
72 const char *mutt_get_first_charset (const char *);
73 int mutt_convert_nonmime_string (char **);
74
75 iconv_t mutt_iconv_open (const char *, const char *, int);
76 ssize_t mutt_iconv (iconv_t, const char **, ssize_t *, char **, ssize_t *,
77                     const char **, const char *);
78
79
80 /****************************************************************************/
81 /* fgetconv functions                                                       */
82 /****************************************************************************/
83
84 typedef void *FGETCONV;
85
86 FGETCONV *fgetconv_open (FILE *, const char *, const char *, int);
87 int fgetconv (FGETCONV *);
88 char *fgetconvs (char *, ssize_t, FGETCONV *);
89 void fgetconv_close (FGETCONV **);
90
91 #endif /* _CHARSET_H */