NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN
string_set()

Set a config item by string. More...

+ Collaboration diagram for string_set():

Functions

static int address_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an Address by string - Implements ConfigSetType::string_set() -. More...
 
static int bool_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Bool by string - Implements ConfigSetType::string_set() -. More...
 
static int enum_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an Enumeration by string - Implements ConfigSetType::string_set() -. More...
 
static int long_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Long by string - Implements ConfigSetType::string_set() -. More...
 
static int mbtable_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an MbTable by string - Implements ConfigSetType::string_set() -. More...
 
static int number_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Number by string - Implements ConfigSetType::string_set() -. More...
 
static int path_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Path by string - Implements ConfigSetType::string_set() -. More...
 
static int quad_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Quad-option by string - Implements ConfigSetType::string_set() -. More...
 
static int regex_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Regex by string - Implements ConfigSetType::string_set() -. More...
 
static int slist_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Slist by string - Implements ConfigSetType::string_set() -. More...
 
static int sort_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Sort by string - Implements ConfigSetType::string_set() -. More...
 
static int string_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a String by string - Implements ConfigSetType::string_set() -. More...
 

Detailed Description

Set a config item by string.

Parameters
csConfig items
varVariable to set (may be NULL)
cdefVariable definition
valueValue to set (may be NULL)
errBuffer for error messages (may be NULL)
Return values
numResult, e.g. CSR_SUCCESS

If var is NULL, then the config item's initial value will be set.

Contract

Function Documentation

◆ address_string_set()

static int address_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set an Address by string - Implements ConfigSetType::string_set() -.

Definition at line 61 of file address.c.

63 {
64  struct Address *addr = NULL;
65 
66  /* An empty address "" will be stored as NULL */
67  if (var && value && (value[0] != '\0'))
68  {
69  // TODO - config can only store one
70  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
71  mutt_addrlist_parse(&al, value);
72  addr = mutt_addr_copy(TAILQ_FIRST(&al));
74  }
75 
76  int rc = CSR_SUCCESS;
77 
78  if (var)
79  {
80  if (cdef->validator)
81  {
82  rc = cdef->validator(cs, cdef, (intptr_t) addr, err);
83 
84  if (CSR_RESULT(rc) != CSR_SUCCESS)
85  {
86  address_destroy(cs, &addr, cdef);
87  return rc | CSR_INV_VALIDATOR;
88  }
89  }
90 
91  /* ordinary variable setting */
92  address_destroy(cs, var, cdef);
93 
94  *(struct Address **) var = addr;
95 
96  if (!addr)
97  rc |= CSR_SUC_EMPTY;
98  }
99  else
100  {
101  /* set the default/initial value */
102  if (cdef->type & DT_INITIAL_SET)
103  FREE(&cdef->initial);
104 
105  cdef->type |= DT_INITIAL_SET;
106  cdef->initial = (intptr_t) mutt_str_dup(value);
107  }
108 
109  return rc;
110 }
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:716
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1470
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:458
static void address_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Address object - Implements ConfigSetType::destroy() -.
Definition: address.c:49
#define FREE(x)
Definition: memory.h:40
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:181
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
#define CSR_INV_VALIDATOR
Value was rejected by the validator.
Definition: set.h:48
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUC_EMPTY
Value is empty/unset.
Definition: set.h:42
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
An email address.
Definition: address.h:36
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:82
intptr_t initial
Initial value.
Definition: set.h:67
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define DT_INITIAL_SET
Config item must have its initial value freed.
Definition: types.h:79
+ Here is the call graph for this function:

◆ bool_string_set()

static int bool_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Bool by string - Implements ConfigSetType::string_set() -.

Definition at line 57 of file bool.c.

59 {
60  if (!value)
61  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
62 
63  int num = -1;
64  for (size_t i = 0; BoolValues[i]; i++)
65  {
66  if (mutt_istr_equal(BoolValues[i], value))
67  {
68  num = i % 2;
69  break;
70  }
71  }
72 
73  if (num < 0)
74  {
75  mutt_buffer_printf(err, _("Invalid boolean value: %s"), value);
77  }
78 
79  if (var)
80  {
81  if (num == (*(bool *) var))
83 
84  if (cdef->validator)
85  {
86  int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
87 
88  if (CSR_RESULT(rc) != CSR_SUCCESS)
89  return rc | CSR_INV_VALIDATOR;
90  }
91 
92  *(bool *) var = num;
93  }
94  else
95  {
96  cdef->initial = num;
97  }
98 
99  return CSR_SUCCESS;
100 }
const char * BoolValues[]
Valid strings for creating a Bool.
Definition: bool.c:50
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:727
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:47
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
+ Here is the call graph for this function:

◆ enum_string_set()

static int enum_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set an Enumeration by string - Implements ConfigSetType::string_set() -.

Definition at line 45 of file enum.c.

47 {
48  if (!cs || !cdef || !value)
49  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
50 
51  struct EnumDef *ed = (struct EnumDef *) cdef->data;
52  if (!ed || !ed->lookup)
53  return CSR_ERR_CODE;
54 
55  int num = mutt_map_get_value(value, ed->lookup);
56  if (num < 0)
57  {
58  mutt_buffer_printf(err, _("Invalid enum value: %s"), value);
59  return (CSR_ERR_INVALID | CSR_INV_TYPE);
60  }
61 
62  if (var)
63  {
64  if (num == (*(unsigned char *) var))
65  return (CSR_SUCCESS | CSR_SUC_NO_CHANGE);
66 
67  if (cdef->validator)
68  {
69  int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
70 
71  if (CSR_RESULT(rc) != CSR_SUCCESS)
72  return (rc | CSR_INV_VALIDATOR);
73  }
74 
75  *(unsigned char *) var = num;
76  }
77  else
78  {
79  cdef->initial = num;
80  }
81 
82  return CSR_SUCCESS;
83 }
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
intptr_t data
Extra variable data.
Definition: set.h:68
An enumeration.
Definition: enum.h:30
struct Mapping * lookup
Lookup table.
Definition: enum.h:33
+ Here is the call graph for this function:

◆ long_string_set()

static int long_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Long by string - Implements ConfigSetType::string_set() -.

Definition at line 43 of file long.c.

45 {
46  if (!value || (value[0] == '\0'))
47  {
48  mutt_buffer_printf(err, _("Option %s may not be empty"), cdef->name);
50  }
51 
52  long num = 0;
53  if (!mutt_str_atol_full(value, &num))
54  {
55  mutt_buffer_printf(err, _("Invalid long: %s"), value);
57  }
58 
59  if ((num < 0) && (cdef->type & DT_NOT_NEGATIVE))
60  {
61  mutt_buffer_printf(err, _("Option %s may not be negative"), cdef->name);
63  }
64 
65  if (var)
66  {
67  if (num == (*(long *) var))
69 
70  if (cdef->validator)
71  {
72  int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
73 
74  if (CSR_RESULT(rc) != CSR_SUCCESS)
75  return rc | CSR_INV_VALIDATOR;
76  }
77 
78  *(long *) var = num;
79  }
80  else
81  {
82  cdef->initial = num;
83  }
84 
85  return CSR_SUCCESS;
86 }
const char * name
User-visible name.
Definition: set.h:65
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:47
+ Here is the call graph for this function:

◆ mbtable_string_set()

static int mbtable_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set an MbTable by string - Implements ConfigSetType::string_set() -.

Definition at line 107 of file mbtable.c.

109 {
110  /* Store empty mbtables as NULL */
111  if (value && (value[0] == '\0'))
112  value = NULL;
113 
114  struct MbTable *table = NULL;
115 
116  int rc = CSR_SUCCESS;
117 
118  if (var)
119  {
120  struct MbTable *curval = *(struct MbTable **) var;
121  if (curval && mutt_str_equal(value, curval->orig_str))
123 
124  table = mbtable_parse(value);
125 
126  if (cdef->validator)
127  {
128  rc = cdef->validator(cs, cdef, (intptr_t) table, err);
129 
130  if (CSR_RESULT(rc) != CSR_SUCCESS)
131  {
132  mbtable_free(&table);
133  return rc | CSR_INV_VALIDATOR;
134  }
135  }
136 
137  mbtable_destroy(cs, var, cdef);
138 
139  *(struct MbTable **) var = table;
140 
141  if (!table)
142  rc |= CSR_SUC_EMPTY;
143  }
144  else
145  {
146  if (cdef->type & DT_INITIAL_SET)
147  FREE(&cdef->initial);
148 
149  cdef->type |= DT_INITIAL_SET;
150  cdef->initial = (intptr_t) mutt_str_dup(value);
151  }
152 
153  return rc;
154 }
static void mbtable_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an MbTable object - Implements ConfigSetType::destroy() -.
Definition: mbtable.c:95
void mbtable_free(struct MbTable **table)
Free an MbTable object.
Definition: mbtable.c:281
struct MbTable * mbtable_parse(const char *s)
Parse a multibyte string into a table.
Definition: mbtable.c:49
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:715
Multibyte character table.
Definition: mbtable.h:34
char * orig_str
Original string used to generate this object.
Definition: mbtable.h:35
+ Here is the call graph for this function:

◆ number_string_set()

static int number_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Number by string - Implements ConfigSetType::string_set() -.

Definition at line 44 of file number.c.

46 {
47  if (!value || (value[0] == '\0'))
48  {
49  mutt_buffer_printf(err, _("Option %s may not be empty"), cdef->name);
51  }
52 
53  int num = 0;
54  if (!mutt_str_atoi_full(value, &num))
55  {
56  mutt_buffer_printf(err, _("Invalid number: %s"), value);
58  }
59 
60  if ((num < SHRT_MIN) || (num > SHRT_MAX))
61  {
62  mutt_buffer_printf(err, _("Number is too big: %s"), value);
64  }
65 
66  if ((num < 0) && (cdef->type & DT_NOT_NEGATIVE))
67  {
68  mutt_buffer_printf(err, _("Option %s may not be negative"), cdef->name);
70  }
71 
72  if (var)
73  {
74  if (num == (*(short *) var))
76 
77  if (cdef->validator)
78  {
79  int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
80 
81  if (CSR_RESULT(rc) != CSR_SUCCESS)
82  return rc | CSR_INV_VALIDATOR;
83  }
84 
85  *(short *) var = num;
86  }
87  else
88  {
89  cdef->initial = num;
90  }
91 
92  return CSR_SUCCESS;
93 }
+ Here is the call graph for this function:

◆ path_string_set()

static int path_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Path by string - Implements ConfigSetType::string_set() -.

Definition at line 85 of file path.c.

87 {
88  /* Store empty paths as NULL */
89  if (value && (value[0] == '\0'))
90  value = NULL;
91 
92  if (!value && (cdef->type & DT_NOT_EMPTY))
93  {
94  mutt_buffer_printf(err, _("Option %s may not be empty"), cdef->name);
96  }
97 
98  int rc = CSR_SUCCESS;
99 
100  if (var)
101  {
102  if (mutt_str_equal(value, (*(char **) var)))
104 
105  if (cdef->validator)
106  {
107  rc = cdef->validator(cs, cdef, (intptr_t) value, err);
108 
109  if (CSR_RESULT(rc) != CSR_SUCCESS)
110  return rc | CSR_INV_VALIDATOR;
111  }
112 
113  path_destroy(cs, var, cdef);
114 
115  const char *str = path_tidy(value, cdef->type & DT_PATH_DIR);
116  if (!str)
117  rc |= CSR_SUC_EMPTY;
118 
119  *(const char **) var = str;
120  }
121  else
122  {
123  if (cdef->type & DT_INITIAL_SET)
124  FREE(&cdef->initial);
125 
126  cdef->type |= DT_INITIAL_SET;
127  cdef->initial = (intptr_t) mutt_str_dup(value);
128  }
129 
130  return rc;
131 }
static char * path_tidy(const char *path, bool is_dir)
Tidy a path for storage.
Definition: path.c:56
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:73
#define DT_PATH_DIR
Path is a directory.
Definition: types.h:53
#define DT_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:46
+ Here is the call graph for this function:

◆ quad_string_set()

static int quad_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Quad-option by string - Implements ConfigSetType::string_set() -.

Definition at line 56 of file quad.c.

58 {
59  if (!value)
60  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
61 
62  int num = -1;
63  for (size_t i = 0; QuadValues[i]; i++)
64  {
65  if (mutt_istr_equal(QuadValues[i], value))
66  {
67  num = i;
68  break;
69  }
70  }
71 
72  if (num < 0)
73  {
74  mutt_buffer_printf(err, _("Invalid quad value: %s"), value);
76  }
77 
78  if (var)
79  {
80  if (num == (*(char *) var))
82 
83  if (cdef->validator)
84  {
85  int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
86 
87  if (CSR_RESULT(rc) != CSR_SUCCESS)
88  return rc | CSR_INV_VALIDATOR;
89  }
90 
91  *(char *) var = num;
92  }
93  else
94  {
95  cdef->initial = num;
96  }
97 
98  return CSR_SUCCESS;
99 }
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:49
+ Here is the call graph for this function:

◆ regex_string_set()

static int regex_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Regex by string - Implements ConfigSetType::string_set() -.

Definition at line 120 of file regex.c.

122 {
123  /* Store empty regexes as NULL */
124  if (value && (value[0] == '\0'))
125  value = NULL;
126 
127  struct Regex *r = NULL;
128 
129  int rc = CSR_SUCCESS;
130 
131  if (var)
132  {
133  struct Regex *curval = *(struct Regex **) var;
134  if (curval && mutt_str_equal(value, curval->pattern))
136 
137  if (value)
138  {
139  r = regex_new(value, cdef->type, err);
140  if (!r)
141  return CSR_ERR_INVALID;
142  }
143 
144  if (cdef->validator)
145  {
146  rc = cdef->validator(cs, cdef, (intptr_t) r, err);
147 
148  if (CSR_RESULT(rc) != CSR_SUCCESS)
149  {
150  regex_free(&r);
151  return rc | CSR_INV_VALIDATOR;
152  }
153  }
154 
155  regex_destroy(cs, var, cdef);
156 
157  *(struct Regex **) var = r;
158 
159  if (!r)
160  rc |= CSR_SUC_EMPTY;
161  }
162  else
163  {
164  if (cdef->type & DT_INITIAL_SET)
165  FREE(&cdef->initial);
166 
167  cdef->type |= DT_INITIAL_SET;
168  cdef->initial = (intptr_t) mutt_str_dup(value);
169  }
170 
171  return rc;
172 }
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:80
void regex_free(struct Regex **r)
Free a Regex object.
Definition: regex.c:48
static void regex_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Regex object - Implements ConfigSetType::destroy() -.
Definition: regex.c:63
Cached regular expression.
Definition: regex3.h:90
char * pattern
printable version
Definition: regex3.h:91
+ Here is the call graph for this function:

◆ slist_string_set()

static int slist_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Slist by string - Implements ConfigSetType::string_set() -.

Definition at line 61 of file slist.c.

63 {
64  if (!cs || !cdef)
65  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
66 
67  /* Store empty string list as NULL */
68  if (value && (value[0] == '\0'))
69  value = NULL;
70 
71  struct Slist *list = NULL;
72 
73  int rc = CSR_SUCCESS;
74 
75  if (var)
76  {
77  list = slist_parse(value, cdef->type);
78 
79  if (cdef->validator)
80  {
81  rc = cdef->validator(cs, cdef, (intptr_t) list, err);
82 
83  if (CSR_RESULT(rc) != CSR_SUCCESS)
84  {
85  slist_free(&list);
86  return (rc | CSR_INV_VALIDATOR);
87  }
88  }
89 
90  slist_destroy(cs, var, cdef);
91 
92  *(struct Slist **) var = list;
93 
94  if (!list)
95  rc |= CSR_SUC_EMPTY;
96  }
97  else
98  {
99  if (cdef->type & DT_INITIAL_SET)
100  FREE(&cdef->initial);
101 
102  cdef->type |= DT_INITIAL_SET;
103  cdef->initial = (intptr_t) mutt_str_dup(value);
104  }
105 
106  return rc;
107 }
static void slist_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Slist object - Implements ConfigSetType::destroy() -.
Definition: slist.c:46
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition: slist.c:200
void slist_free(struct Slist **list)
Free an Slist object.
Definition: slist.c:162
String list.
Definition: slist.h:47
+ Here is the call graph for this function:

◆ sort_string_set()

static int sort_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a Sort by string - Implements ConfigSetType::string_set() -.

Definition at line 47 of file sort.c.

49 {
50  intptr_t id = -1;
51  uint16_t flags = 0;
52 
53  if (!value || (value[0] == '\0'))
54  {
55  mutt_buffer_printf(err, _("Option %s may not be empty"), cdef->name);
57  }
58 
59  size_t plen = 0;
60 
61  if (cdef->type & DT_SORT_REVERSE)
62  {
64  if (plen != 0)
65  {
66  flags |= SORT_REVERSE;
67  value += plen;
68  }
69  }
70 
71  if (cdef->type & DT_SORT_LAST)
72  {
74  if (plen != 0)
75  {
76  flags |= SORT_LAST;
77  value += plen;
78  }
79  }
80 
81  id = mutt_map_get_value(value, (struct Mapping *) cdef->data);
82 
83  if (id < 0)
84  {
85  mutt_buffer_printf(err, _("Invalid sort name: %s"), value);
87  }
88 
89  id |= flags;
90 
91  if (var)
92  {
93  if (id == (*(short *) var))
95 
96  if (cdef->validator)
97  {
98  int rc = cdef->validator(cs, cdef, (intptr_t) id, err);
99 
100  if (CSR_RESULT(rc) != CSR_SUCCESS)
101  return rc | CSR_INV_VALIDATOR;
102  }
103 
104  *(short *) var = id;
105  }
106  else
107  {
108  cdef->initial = id;
109  }
110 
111  return CSR_SUCCESS;
112 }
#define PREFIX_REVERSE
Definition: sort.c:41
#define PREFIX_LAST
Definition: sort.c:42
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:158
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
#define DT_SORT_REVERSE
Sort flag for -reverse prefix.
Definition: sort2.h:36
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:80
#define DT_SORT_LAST
Sort flag for -last prefix.
Definition: sort2.h:35
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:79
Mapping between user-readable string and a constant.
Definition: mapping.h:32
+ Here is the call graph for this function:

◆ string_string_set()

static int string_string_set ( const struct ConfigSet cs,
void *  var,
struct ConfigDef cdef,
const char *  value,
struct Buffer err 
)
static

Set a String by string - Implements ConfigSetType::string_set() -.

Definition at line 57 of file string.c.

59 {
60  /* Store empty strings as NULL */
61  if (value && (value[0] == '\0'))
62  value = NULL;
63 
64  if (!value && (cdef->type & DT_NOT_EMPTY))
65  {
66  mutt_buffer_printf(err, _("Option %s may not be empty"), cdef->name);
68  }
69 
70  int rc = CSR_SUCCESS;
71 
72  if (var)
73  {
74  if (mutt_str_equal(value, (*(char **) var)))
76 
77  if (cdef->validator)
78  {
79  rc = cdef->validator(cs, cdef, (intptr_t) value, err);
80 
81  if (CSR_RESULT(rc) != CSR_SUCCESS)
82  return rc | CSR_INV_VALIDATOR;
83  }
84 
85  string_destroy(cs, var, cdef);
86 
87  const char *str = mutt_str_dup(value);
88  if (!str)
89  rc |= CSR_SUC_EMPTY;
90 
91  *(const char **) var = str;
92  }
93  else
94  {
95  if (cdef->type & DT_INITIAL_SET)
96  FREE(&cdef->initial);
97 
98  cdef->type |= DT_INITIAL_SET;
99  cdef->initial = (intptr_t) mutt_str_dup(value);
100  }
101 
102  return rc;
103 }
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:45
+ Here is the call graph for this function: