NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
charset.h
Go to the documentation of this file.
1 
23 #ifndef MUTT_LIB_CHARSET_H
24 #define MUTT_LIB_CHARSET_H
25 
26 #include <iconv.h>
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <wchar.h>
31 
32 struct Buffer;
33 
34 extern char *C_AssumedCharset;
35 extern char *C_Charset;
36 extern bool CharsetIsUtf8;
37 extern wchar_t ReplacementChar;
38 
42 struct FgetConv
43 {
44  FILE *fp;
45  iconv_t cd;
46  char bufi[512];
47  char bufo[512];
48  char *p;
49  char *ob;
50  char *ib;
51  size_t ibl;
52  const char **inrepls;
53 };
54 
59 {
60  FILE *fp;
61  iconv_t cd;
62 };
63 
68 {
71 };
72 
73 #define MUTT_ICONV_NO_FLAGS 0
74 #define MUTT_ICONV_HOOK_FROM 1
75 
76 void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
77 const char * mutt_ch_charset_lookup(const char *chs);
78 int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to);
79 bool mutt_ch_check_charset(const char *cs, bool strict);
80 char * mutt_ch_choose(const char *fromcode, const char *charsets, const char *u, size_t ulen, char **d, size_t *dlen);
81 bool mutt_ch_chscmp(const char *cs1, const char *cs2);
82 int mutt_ch_convert_nonmime_string(char **ps);
83 int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags);
84 int mutt_ch_fgetconv(struct FgetConv *fc);
85 void mutt_ch_fgetconv_close(struct FgetConv **fc);
86 struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags);
87 char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
88 char * mutt_ch_get_default_charset(void);
89 char * mutt_ch_get_langinfo_charset(void);
90 size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl, int *iconverrno);
91 const char * mutt_ch_iconv_lookup(const char *chs);
92 iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags);
93 bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
94 void mutt_ch_lookup_remove(void);
95 void mutt_ch_set_charset(const char *charset);
96 
97 #define mutt_ch_is_utf8(str) mutt_ch_chscmp(str, "utf-8")
98 #define mutt_ch_is_us_ascii(str) mutt_ch_chscmp(str, "us-ascii")
99 
100 #endif /* MUTT_LIB_CHARSET_H */
mutt_ch_check_charset
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:818
FgetConvNot
A dummy converter.
Definition: charset.h:58
FgetConv::cd
iconv_t cd
Definition: charset.h:45
mutt_ch_get_langinfo_charset
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition: charset.c:462
CharsetIsUtf8
bool CharsetIsUtf8
Is the user's current character set utf-8?
Definition: charset.c:63
mutt_ch_get_default_charset
char * mutt_ch_get_default_charset(void)
Get the default character set.
Definition: charset.c:440
Buffer
String manipulation buffer.
Definition: buffer.h:33
mutt_ch_iconv_open
iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags)
Set up iconv for conversions.
Definition: charset.c:565
mutt_ch_convert_nonmime_string
int mutt_ch_convert_nonmime_string(char **ps)
Try to convert a string using a list of character sets.
Definition: charset.c:309
C_AssumedCharset
char * C_AssumedCharset
Config: If a message is missing a character set, assume this character set.
Definition: charset.c:52
mutt_ch_check
int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to)
Check whether a string can be converted between encodings.
Definition: charset.c:717
mutt_ch_lookup_remove
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:517
mutt_ch_iconv_lookup
const char * mutt_ch_iconv_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:702
mutt_ch_fgetconv
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
Definition: charset.c:908
ReplacementChar
wchar_t ReplacementChar
When a Unicode character can't be displayed, use this instead.
Definition: charset.c:58
FgetConv::p
char * p
Definition: charset.h:48
mutt_ch_lookup_add
bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err)
Add a new character set lookup.
Definition: charset.c:485
mutt_ch_choose
char * mutt_ch_choose(const char *fromcode, const char *charsets, const char *u, size_t ulen, char **d, size_t *dlen)
Figure the best charset to encode a string.
Definition: charset.c:1036
MUTT_LOOKUP_ICONV
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition: charset.h:70
FgetConv::inrepls
const char ** inrepls
Definition: charset.h:52
chs
static char * chs
Definition: gnupgparse.c:73
mutt_ch_chscmp
bool mutt_ch_chscmp(const char *cs1, const char *cs2)
Are the names of two character sets equivalent?
Definition: charset.c:418
MUTT_LOOKUP_CHARSET
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition: charset.h:69
mutt_ch_fgetconv_open
struct FgetConv * mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags)
Prepare a file for charset conversion.
Definition: charset.c:858
C_Charset
char * C_Charset
Config: Default character set for displaying text on screen.
Definition: charset.c:53
FgetConv::fp
FILE * fp
Definition: charset.h:44
FgetConv::bufi
char bufi[512]
Definition: charset.h:46
FgetConv::bufo
char bufo[512]
Definition: charset.h:47
mutt_ch_set_charset
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:1003
FgetConv::ib
char * ib
Definition: charset.h:50
LookupType
LookupType
Types of character set lookups.
Definition: charset.h:67
FgetConv::ibl
size_t ibl
Definition: charset.h:51
mutt_ch_canonical_charset
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:352
FgetConv
Cursor for converting a file's encoding.
Definition: charset.h:42
mutt_ch_convert_string
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:754
FgetConvNot::fp
FILE * fp
Definition: charset.h:60
mutt_ch_fgetconvs
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
Definition: charset.c:970
mutt_ch_iconv
size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl, int *iconverrno)
Change the encoding of a string.
Definition: charset.c:618
mutt_ch_fgetconv_close
void mutt_ch_fgetconv_close(struct FgetConv **fc)
Close an fgetconv handle.
Definition: charset.c:888
mutt_ch_charset_lookup
const char * mutt_ch_charset_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:538
FgetConvNot::cd
iconv_t cd
Definition: charset.h:61
FgetConv::ob
char * ob
Definition: charset.h:49