NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
charset.c
Go to the documentation of this file.
1
24
30
31
#include "config.h"
32
#include <stdbool.h>
33
#include <stdint.h>
34
#include <string.h>
35
#include "
mutt/lib.h
"
36
#include "
charset.h
"
37
#include "
set.h
"
38
#include "
types.h
"
39
45
int
charset_validator
(
const
struct
ConfigDef
*cdef, intptr_t value,
struct
Buffer
*err)
46
{
47
if
(value == 0)
48
return
CSR_SUCCESS
;
49
50
const
char
*str = (
const
char
*) value;
51
52
if
((cdef->
type
&
D_CHARSET_SINGLE
) && strchr(str,
':'
))
53
{
54
buf_printf
(err,
_
(
"'charset' must contain exactly one character set name"
));
55
return
CSR_ERR_INVALID
;
56
}
57
58
int
rc =
CSR_SUCCESS
;
59
bool
strict = (cdef->
type
&
D_CHARSET_STRICT
);
60
char
*q = NULL;
61
char
*s =
mutt_str_dup
(str);
62
63
for
(
char
*p = strtok_r(s,
":"
, &q); p; p = strtok_r(NULL,
":"
, &q))
64
{
65
if
(*p ==
'\0'
)
66
continue
;
// LCOV_EXCL_LINE
67
if
(!
mutt_ch_check_charset
(p, strict))
68
{
69
rc =
CSR_ERR_INVALID
;
70
buf_printf
(err,
_
(
"Invalid value for option %s: %s"
), cdef->
name
, p);
71
break
;
72
}
73
}
74
75
FREE
(&s);
76
return
rc;
77
}
78
84
int
charset_slist_validator
(
const
struct
ConfigDef
*cdef, intptr_t value,
struct
Buffer
*err)
85
{
86
if
(value == 0)
87
return
CSR_SUCCESS
;
88
89
const
struct
Slist
*list = (
const
struct
Slist
*) value;
90
91
int
rc =
CSR_SUCCESS
;
92
bool
strict = (cdef->
type
&
D_CHARSET_STRICT
);
93
94
const
struct
ListNode
*np = NULL;
95
STAILQ_FOREACH
(np, &list->
head
, entries)
96
{
97
char
const
*charset = np->
data
;
98
if
(!
mutt_ch_check_charset
(charset, strict))
99
{
100
rc =
CSR_ERR_INVALID
;
101
buf_printf
(err,
_
(
"Invalid value for option %s: %s"
), cdef->
name
, charset);
102
break
;
103
}
104
}
105
106
return
rc;
107
}
buf_printf
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition
buffer.c:168
charset.h
Validator for the "charset" config variables.
set.h
A collection of config items.
CSR_ERR_INVALID
#define CSR_ERR_INVALID
Value hasn't been set.
Definition
set.h:36
CSR_SUCCESS
#define CSR_SUCCESS
Action completed successfully.
Definition
set.h:33
charset_validator
int charset_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "charset" config variables - Implements ConfigDef::validator() -.
Definition
charset.c:45
charset_slist_validator
int charset_slist_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the multiple "charset" config variables - Implements ConfigDef::validator() -.
Definition
charset.c:84
FREE
#define FREE(x)
Free memory and set the pointer to NULL.
Definition
memory.h:68
mutt_ch_check_charset
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition
charset.c:882
lib.h
Convenience wrapper for the library headers.
_
#define _(a)
Definition
message.h:28
mutt_str_dup
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition
string.c:257
STAILQ_FOREACH
#define STAILQ_FOREACH(var, head, field)
Definition
queue.h:390
Buffer
String manipulation buffer.
Definition
buffer.h:36
ConfigDef
Definition
set.h:65
ConfigDef::name
const char * name
User-visible name.
Definition
set.h:66
ConfigDef::type
uint32_t type
Variable type, e.g. DT_STRING.
Definition
set.h:67
ListNode
A List node for strings.
Definition
list.h:37
ListNode::data
char * data
String.
Definition
list.h:38
Slist
String list.
Definition
slist.h:37
Slist::head
struct ListHead head
List containing values.
Definition
slist.h:38
types.h
Constants for all the config types.
D_CHARSET_SINGLE
#define D_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition
types.h:84
D_CHARSET_STRICT
#define D_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition
types.h:85