NeoMutt  2025-12-11-177-g48e272
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
charset.h
Go to the documentation of this file.
1
23
24#ifndef MUTT_MUTT_CHARSET_H
25#define MUTT_MUTT_CHARSET_H
26
27#include <iconv.h>
28#include <stdbool.h>
29#include <stddef.h>
30#include <stdint.h>
31#include <stdio.h>
32#include "queue.h"
33#include "regex3.h"
34
35struct Buffer;
36struct Slist;
37
38extern bool CharsetIsUtf8;
39extern wchar_t ReplacementChar;
40
45{
46 FILE *fp;
47 iconv_t cd;
48 char bufi[512];
49 char bufo[512];
50 char *p;
51 char *ob;
52 char *ib;
53 size_t ibl;
54 const char **inrepls;
55};
56
65
66#define MUTT_ICONV_NO_FLAGS 0
67#define MUTT_ICONV_HOOK_FROM 1
68
74struct Lookup
75{
77 struct Regex regex;
80};
81TAILQ_HEAD(LookupList, Lookup);
82
83extern struct LookupList Lookups;
84
85void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
86const char * mutt_ch_charset_lookup(const char *chs);
87int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to);
88bool mutt_ch_check_charset(const char *cs, bool strict);
89char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen);
90bool mutt_ch_chscmp(const char *cs1, const char *cs2);
91int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps);
92int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags);
93int mutt_ch_fgetconv(struct FgetConv *fc);
94void mutt_ch_fgetconv_close(struct FgetConv **ptr);
95struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags);
96char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
97const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset);
99size_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);
100const char * mutt_ch_iconv_lookup(const char *chs);
101iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags);
102bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
103void mutt_ch_lookup_remove(void);
104void mutt_ch_set_charset(const char *charset);
105void mutt_ch_cache_cleanup(void);
106
107#define mutt_ch_is_utf8(str) mutt_ch_chscmp(str, "utf-8")
108#define mutt_ch_is_us_ascii(str) mutt_ch_chscmp(str, "us-ascii")
109
111#define ICONV_T_INVALID ((iconv_t) -1)
112
114#define ICONV_ILLEGAL_SEQ ((size_t) -1)
116#define ICONV_BUF_TOO_SMALL ((size_t) -2)
117
123static inline bool iconv_t_valid(const iconv_t cd)
124{
125 return cd != ICONV_T_INVALID;
126}
127
128#endif /* MUTT_MUTT_CHARSET_H */
struct LookupList Lookups
Lookup table of preferred character set names.
Definition charset.c:69
bool CharsetIsUtf8
Is the user's current character set utf-8?
Definition charset.c:66
wchar_t ReplacementChar
When a Unicode character can't be displayed, use this instead.
Definition charset.c:61
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition charset.c:880
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:683
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition charset.c:527
char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen)
Figure the best charset to encode a string.
Definition charset.c:1094
int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps)
Try to convert a string using a list of character sets.
Definition charset.c:317
#define ICONV_T_INVALID
Error value for iconv functions.
Definition charset.h:111
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition charset.c:472
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:495
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition charset.c:360
void mutt_ch_cache_cleanup(void)
Clean up the cached iconv handles and charset strings.
Definition charset.c:1161
const char * mutt_ch_iconv_lookup(const char *chs)
Look for a replacement character set.
Definition charset.c:767
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition charset.c:817
LookupType
Types of character set lookups.
Definition charset.h:61
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition charset.h:63
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition charset.h:62
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition charset.c:1061
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:782
const char * mutt_ch_charset_lookup(const char *chs)
Look for a replacement character set.
Definition charset.c:548
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
Definition charset.c:966
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:919
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
Definition charset.c:1028
bool mutt_ch_chscmp(const char *cs1, const char *cs2)
Are the names of two character sets equivalent?
Definition charset.c:428
void mutt_ch_fgetconv_close(struct FgetConv **ptr)
Close an fgetconv handle.
Definition charset.c:948
iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags)
Set up iconv for conversions.
Definition charset.c:580
const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset)
Get the default character set.
Definition charset.c:451
static bool iconv_t_valid(const iconv_t cd)
Is the conversion descriptor valid?
Definition charset.h:123
#define TAILQ_HEAD(name, type)
Definition queue.h:680
Manage regular expressions.
String manipulation buffer.
Definition buffer.h:36
Cursor for converting a file's encoding.
Definition charset.h:45
char bufi[512]
Input buffer.
Definition charset.h:48
iconv_t cd
iconv conversion descriptor
Definition charset.h:47
char bufo[512]
Output buffer.
Definition charset.h:49
size_t ibl
Input buffer length.
Definition charset.h:53
FILE * fp
File to read from.
Definition charset.h:46
char * p
Current position in output buffer.
Definition charset.h:50
const char ** inrepls
Replacement characters.
Definition charset.h:54
char * ib
Current position in input buffer.
Definition charset.h:52
char * ob
End of output buffer.
Definition charset.h:51
Regex to String lookup table.
Definition charset.h:75
char * replacement
Alternative charset to use.
Definition charset.h:78
enum LookupType type
Lookup type.
Definition charset.h:76
struct Regex regex
Regular expression.
Definition charset.h:77
TAILQ_ENTRY(Lookup) entries
Linked list.
Cached regular expression.
Definition regex3.h:86
String list.
Definition slist.h:37