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

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

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "mutt/lib.h"
#include "charset.h"
#include "lib.h"
+ Include dependency graph for charset.c:

Go to the source code of this file.


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.

  • 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

Definition in file charset.c.

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;
45  const char *str = (const char *) value;
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  }
54  int rc = CSR_SUCCESS;
55  bool strict = (cdef->type & DT_CHARSET_STRICT);
56  char *q = NULL;
57  char *s = mutt_str_dup(str);
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  {
66  mutt_buffer_printf(err, _("Invalid value for option %s: %s"), cdef->name, p);
67  break;
68  }
69  }
71  FREE(&s);
72  return rc;
73 }
Action completed successfully.
Definition: set.h:35
Value hasn&#39;t been set.
Definition: set.h:38
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
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
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: