simplifications.
[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 const char *charset_getfirst(const char *);
49
50
51 /****************************************************************************/
52 /* iconv-line functions                                                     */
53 /****************************************************************************/
54
55 #define MUTT_ICONV_ERROR  ((iconv_t)(-1))
56
57 #ifdef HAVE_ICONV_H
58 #  include <iconv.h>
59
60 static inline ssize_t
61 my_iconv(iconv_t ict, const char **in, ssize_t *il, char **out, ssize_t *ol) {
62     return iconv(ict, (char **)in, (size_t*)il, out, (size_t*)ol);
63 }
64
65 #else
66 #  define iconv_t              void*
67 #  define iconv_open(a, b)     MUTT_ICONV_ERROR
68 #  define my_iconv(a,b,c,d,e)  0
69 #  define iconv_close(a)       0
70 #endif
71
72 #define M_ICONV_HOOK_FROM 1
73 #define M_ICONV_HOOK_TO   2
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 int mutt_convert_string(char **, const char *, const char *, int);
80 int mutt_convert_nonmime_string (char **);
81
82
83 /****************************************************************************/
84 /* fgetconv functions                                                       */
85 /****************************************************************************/
86
87 typedef struct fgetconv_t fgetconv_t;
88
89 fgetconv_t *fgetconv_open(FILE *, const char *, const char *, int);
90 void fgetconv_close(fgetconv_t **);
91
92 int fgetconv(fgetconv_t *);
93 char *fgetconvs(char *, ssize_t, fgetconv_t *);
94
95 #endif /* _CHARSET_H */