NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
charset.h File Reference

Validator for the "charset" config variables. More...

#include <stdint.h>
+ Include dependency graph for charset.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DT_CHARSET_SINGLE   0x0800
 Flag for charset_validator to allow only one charset. More...
 
#define DT_CHARSET_STRICT   0x1000
 Flag for charset_validator to use strict char check. More...
 

Functions

int charset_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variable - Implements ConfigDef::validator() More...
 

Detailed Description

Validator for the "charset" config variables.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file charset.h.

Macro Definition Documentation

◆ DT_CHARSET_SINGLE

#define DT_CHARSET_SINGLE   0x0800

Flag for charset_validator to allow only one charset.

Definition at line 28 of file charset.h.

◆ DT_CHARSET_STRICT

#define DT_CHARSET_STRICT   0x1000

Flag for charset_validator to use strict char check.

Definition at line 29 of file charset.h.

Function Documentation

◆ charset_validator()

int charset_validator ( const struct ConfigSet cs,
const struct ConfigDef cdef,
intptr_t  value,
struct Buffer err 
)

Validate the "charset" config variable - Implements ConfigDef::validator()

Definition at line 39 of file charset.c.

41 {
42  if (value == 0)
43  return CSR_SUCCESS;
44 
45  const char *str = (const char *) value;
46 
47  if ((cdef->type & DT_CHARSET_SINGLE) && strchr(str, ':'))
48  {
50  err, _("'charset' must contain exactly one character set name"));
51  return CSR_ERR_INVALID;
52  }
53 
54  int rc = CSR_SUCCESS;
55  bool strict = (cdef->type & DT_CHARSET_STRICT);
56  char *q = NULL;
57  char *s = mutt_str_dup(str);
58 
59  for (char *p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q))
60  {
61  if (*p == '\0')
62  continue;
63  if (!mutt_ch_check_charset(p, strict))
64  {
65  rc = CSR_ERR_INVALID;
66  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, p);
67  break;
68  }
69  }
70 
71  FREE(&s);
72  return rc;
73 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define DT_CHARSET_SINGLE
Flag for charset_validator to allow only one charset.
Definition: charset.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
#define DT_CHARSET_STRICT
Flag for charset_validator to use strict char check.
Definition: charset.h:29
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:818
const char * name
User-visible name.
Definition: set.h:63
char * p
Definition: charset.h:47
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
#define FREE(x)
Definition: memory.h:40
+ Here is the call graph for this function: