NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
native_set()

Set a config item by string. More...

+ Collaboration diagram for native_set():

Functions

static int address_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an Address config item by Address object - Implements ConfigSetType::native_set() -.
 
static int bool_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Bool config item by bool - Implements ConfigSetType::native_set() -.
 
static int enum_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an Enumeration config item by int - Implements ConfigSetType::native_set() -.
 
static int long_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Long config item by long - Implements ConfigSetType::native_set() -.
 
static int mbtable_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an MbTable config item by MbTable object - Implements ConfigSetType::native_set() -.
 
static int myvar_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a MyVar config item by string - Implements ConfigSetType::native_set() -.
 
static int number_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Number config item by int - Implements ConfigSetType::native_set() -.
 
static int path_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Path config item by string - Implements ConfigSetType::native_set() -.
 
static int quad_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Quad-option config item by int - Implements ConfigSetType::native_set() -.
 
static int regex_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Regex config item by Regex object - Implements ConfigSetType::native_set() -.
 
static int slist_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Slist config item by Slist - Implements ConfigSetType::native_set() -.
 
static int sort_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Sort config item by int - Implements ConfigSetType::native_set() -.
 
static int string_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a String config item by string - Implements ConfigSetType::native_set() -.
 

Detailed Description

Set a config item by string.

Parameters
csConfig items
varVariable to set
cdefVariable definition
valueNative pointer/value to set
errBuffer for error messages (may be NULL)
Return values
numResult, e.g. CSR_SUCCESS
Precondition
cs is not NULL
var is not NULL
cdef is not NULL

Function Documentation

◆ address_native_set()

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

Set an Address config item by Address object - Implements ConfigSetType::native_set() -.

Definition at line 178 of file config_type.c.

181{
182 int rc;
183
184 if (cdef->validator)
185 {
186 rc = cdef->validator(cs, cdef, value, err);
187
188 if (CSR_RESULT(rc) != CSR_SUCCESS)
189 return rc | CSR_INV_VALIDATOR;
190 }
191
192 mutt_addr_free(var);
193
194 struct Address *addr = address_dup((struct Address *) value);
195
196 rc = CSR_SUCCESS;
197 if (!addr)
198 rc |= CSR_SUC_EMPTY;
199
200 *(struct Address **) var = addr;
201 return rc;
202}
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:462
static struct Address * address_dup(struct Address *addr)
Create a copy of an Address object.
Definition: config_type.c:164
#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
+ Here is the call graph for this function:

◆ bool_native_set()

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

Set a Bool config item by bool - Implements ConfigSetType::native_set() -.

Definition at line 129 of file bool.c.

131{
132 if ((value < 0) || (value > 1))
133 {
134 buf_printf(err, _("Invalid boolean value: %ld"), (long) value);
136 }
137
138 if (value == (*(bool *) var))
140
141 if (startup_only(cdef, err))
143
144 if (cdef->validator)
145 {
146 int rc = cdef->validator(cs, cdef, value, err);
147
148 if (CSR_RESULT(rc) != CSR_SUCCESS)
149 return rc | CSR_INV_VALIDATOR;
150 }
151
152 *(bool *) var = value;
153 return CSR_SUCCESS;
154}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
static bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
Validator function for D_ON_STARTUP.
Definition: set.h:296
#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 _(a)
Definition: message.h:28
+ Here is the call graph for this function:

◆ enum_native_set()

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

Set an Enumeration config item by int - Implements ConfigSetType::native_set() -.

Definition at line 122 of file enum.c.

124{
125 if (!cs || !var || !cdef)
126 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
127
128 struct EnumDef *ed = (struct EnumDef *) cdef->data;
129 if (!ed || !ed->lookup)
130 return CSR_ERR_CODE;
131
132 const char *name = mutt_map_get_name(value, ed->lookup);
133 if (!name)
134 {
135 buf_printf(err, _("Invalid enum value: %ld"), (long) value);
137 }
138
139 if (value == (*(unsigned char *) var))
141
142 if (startup_only(cdef, err))
144
145 if (cdef->validator)
146 {
147 int rc = cdef->validator(cs, cdef, value, err);
148
149 if (CSR_RESULT(rc) != CSR_SUCCESS)
150 return rc | CSR_INV_VALIDATOR;
151 }
152
153 *(unsigned char *) var = value;
154 return CSR_SUCCESS;
155}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
intptr_t data
Extra variable data.
Definition: set.h:68
An enumeration.
Definition: enum.h:30
const char * name
Config variable.
Definition: enum.h:31
struct Mapping * lookup
Lookup table.
Definition: enum.h:33
+ Here is the call graph for this function:

◆ long_native_set()

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

Set a Long config item by long - Implements ConfigSetType::native_set() -.

Definition at line 113 of file long.c.

115{
116 if ((value < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
117 {
118 buf_printf(err, _("Option %s may not be negative"), cdef->name);
120 }
121
122 if (value == (*(long *) var))
124
125 if (startup_only(cdef, err))
127
128 if (cdef->validator)
129 {
130 int rc = cdef->validator(cs, cdef, value, err);
131
132 if (CSR_RESULT(rc) != CSR_SUCCESS)
133 return rc | CSR_INV_VALIDATOR;
134 }
135
136 *(long *) var = value;
137 return CSR_SUCCESS;
138}
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:101
+ Here is the call graph for this function:

◆ mbtable_native_set()

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

Set an MbTable config item by MbTable object - Implements ConfigSetType::native_set() -.

Definition at line 216 of file mbtable.c.

219{
220 int rc;
221
222 if (mbtable_equal(*(struct MbTable **) var, (struct MbTable *) value))
224
225 if (startup_only(cdef, err))
227
228 if (cdef->validator)
229 {
230 rc = cdef->validator(cs, cdef, value, err);
231
232 if (CSR_RESULT(rc) != CSR_SUCCESS)
233 return rc | CSR_INV_VALIDATOR;
234 }
235
236 mbtable_free(var);
237
238 struct MbTable *table = mbtable_dup((struct MbTable *) value);
239
240 rc = CSR_SUCCESS;
241 if (!table)
242 rc |= CSR_SUC_EMPTY;
243
244 *(struct MbTable **) var = table;
245 return rc;
246}
bool mbtable_equal(const struct MbTable *a, const struct MbTable *b)
Compare two MbTables.
Definition: mbtable.c:51
static struct MbTable * mbtable_dup(struct MbTable *table)
Create a copy of an MbTable object.
Definition: mbtable.c:203
void mbtable_free(struct MbTable **ptr)
Free an MbTable object.
Definition: mbtable.c:308
Multibyte character table.
Definition: mbtable.h:36
+ Here is the call graph for this function:

◆ myvar_native_set()

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

Set a MyVar config item by string - Implements ConfigSetType::native_set() -.

Definition at line 114 of file myvar.c.

116{
117 const char *str = (const char *) value;
118
119 /* Store empty myvars as NULL */
120 if (str && (str[0] == '\0'))
121 value = 0;
122
123 if (mutt_str_equal((const char *) value, (*(char **) var)))
125
126 int rc;
127
128 myvar_destroy(cs, var, cdef);
129
130 str = mutt_str_dup(str);
131 rc = CSR_SUCCESS;
132 if (!str)
133 rc |= CSR_SUC_EMPTY;
134
135 *(const char **) var = str;
136 return rc;
137}
static void myvar_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a MyVar - Implements ConfigSetType::destroy() -.
Definition: myvar.c:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
+ Here is the call graph for this function:

◆ number_native_set()

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

Set a Number config item by int - Implements ConfigSetType::native_set() -.

Definition at line 143 of file number.c.

146{
147 if ((value < SHRT_MIN) || (value > SHRT_MAX))
148 {
149 buf_printf(err, _("Invalid number: %ld"), (long) value);
151 }
152
153 if ((value < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
154 {
155 buf_printf(err, _("Option %s may not be negative"), cdef->name);
157 }
158
159 if (value == native_get(var))
161
162 if (cdef->validator)
163 {
164 int rc = cdef->validator(cs, cdef, value, err);
165
166 if (CSR_RESULT(rc) != CSR_SUCCESS)
167 return rc | CSR_INV_VALIDATOR;
168 }
169
170 if (startup_only(cdef, err))
172
173 native_set(var, value);
174 return CSR_SUCCESS;
175}
static void native_set(void *var, intptr_t val)
Set an int into a Number config item.
Definition: number.c:58
static intptr_t native_get(void *var)
Get an int from a Number config item.
Definition: number.c:50
+ Here is the call graph for this function:

◆ path_native_set()

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

Set a Path config item by string - Implements ConfigSetType::native_set() -.

Definition at line 164 of file path.c.

166{
167 const char *str = (const char *) value;
168
169 /* Store empty paths as NULL */
170 if (str && (str[0] == '\0'))
171 value = 0;
172
173 if ((value == 0) && (cdef->type & D_NOT_EMPTY))
174 {
175 buf_printf(err, _("Option %s may not be empty"), cdef->name);
177 }
178
179 if (mutt_str_equal((const char *) value, (*(char **) var)))
181
182 int rc;
183
184 if (startup_only(cdef, err))
186
187 if (cdef->validator)
188 {
189 rc = cdef->validator(cs, cdef, value, err);
190
191 if (CSR_RESULT(rc) != CSR_SUCCESS)
192 return rc | CSR_INV_VALIDATOR;
193 }
194
195 path_destroy(cs, var, cdef);
196
197 str = path_tidy(str, cdef->type & D_PATH_DIR);
198 rc = CSR_SUCCESS;
199 if (!str)
200 rc |= CSR_SUC_EMPTY;
201
202 *(const char **) var = str;
203 return rc;
204}
static char * path_tidy(const char *path, bool is_dir)
Tidy a path for storage.
Definition: path.c:58
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:78
#define D_PATH_DIR
Path is a directory.
Definition: types.h:103
#define D_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:80
+ Here is the call graph for this function:

◆ quad_native_set()

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

Set a Quad-option config item by int - Implements ConfigSetType::native_set() -.

Definition at line 134 of file quad.c.

136{
137 if ((value < 0) || (value >= (mutt_array_size(QuadValues) - 1)))
138 {
139 buf_printf(err, _("Invalid quad value: %ld"), (long) value);
141 }
142
143 if (value == (*(char *) var))
145
146 if (startup_only(cdef, err))
148
149 if (cdef->validator)
150 {
151 int rc = cdef->validator(cs, cdef, value, err);
152
153 if (CSR_RESULT(rc) != CSR_SUCCESS)
154 return rc | CSR_INV_VALIDATOR;
155 }
156
157 *(char *) var = value;
158 return CSR_SUCCESS;
159}
#define mutt_array_size(x)
Definition: memory.h:38
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:53
+ Here is the call graph for this function:

◆ regex_native_set()

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

Set a Regex config item by Regex object - Implements ConfigSetType::native_set() -.

Definition at line 228 of file regex.c.

230{
231 int rc;
232
233 if (regex_equal(*(struct Regex **) var, (struct Regex *) value))
235
236 if (startup_only(cdef, err))
238
239 if (cdef->validator)
240 {
241 rc = cdef->validator(cs, cdef, value, err);
242
243 if (CSR_RESULT(rc) != CSR_SUCCESS)
244 return rc | CSR_INV_VALIDATOR;
245 }
246
247 rc = CSR_SUCCESS;
248 struct Regex *orig = (struct Regex *) value;
249 struct Regex *r = NULL;
250
251 if (orig && orig->pattern)
252 {
253 const uint32_t flags = orig->pat_not ? D_REGEX_ALLOW_NOT : 0;
254 r = regex_new(orig->pattern, flags, err);
255 if (!r)
256 rc = CSR_ERR_INVALID;
257 }
258 else
259 {
260 rc |= CSR_SUC_EMPTY;
261 }
262
263 if (CSR_RESULT(rc) == CSR_SUCCESS)
264 {
265 regex_free(var);
266 *(struct Regex **) var = r;
267 }
268
269 return rc;
270}
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:102
bool regex_equal(const struct Regex *a, const struct Regex *b)
Compare two regexes.
Definition: regex.c:52
void regex_free(struct Regex **ptr)
Free a Regex object.
Definition: regex.c:68
Cached regular expression.
Definition: regex3.h:86
char * pattern
printable version
Definition: regex3.h:87
bool pat_not
do not match
Definition: regex3.h:89
#define D_REGEX_ALLOW_NOT
Regex can begin with '!'.
Definition: types.h:107
+ Here is the call graph for this function:

◆ slist_native_set()

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

Set a Slist config item by Slist - Implements ConfigSetType::native_set() -.

Definition at line 154 of file slist.c.

156{
157 if (!cs || !var || !cdef)
158 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
159
160 int rc;
161
162 if (slist_equal((struct Slist *) value, *(struct Slist **) var))
164
165 if (startup_only(cdef, err))
167
168 if (cdef->validator)
169 {
170 rc = cdef->validator(cs, cdef, value, err);
171
172 if (CSR_RESULT(rc) != CSR_SUCCESS)
173 return rc | CSR_INV_VALIDATOR;
174 }
175
176 slist_free(var);
177
178 struct Slist *list = slist_dup((struct Slist *) value);
179
180 rc = CSR_SUCCESS;
181 if (!list)
182 rc |= CSR_SUC_EMPTY;
183
184 *(struct Slist **) var = list;
185 return rc;
186}
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:122
bool slist_equal(const struct Slist *a, const struct Slist *b)
Compare two string lists.
Definition: slist.c:89
struct Slist * slist_dup(const struct Slist *list)
Create a copy of an Slist object.
Definition: slist.c:106
String list.
Definition: slist.h:37
+ Here is the call graph for this function:

◆ sort_native_set()

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

Set a Sort config item by int - Implements ConfigSetType::native_set() -.

Definition at line 156 of file sort.c.

158{
159 const char *str = NULL;
160
161 str = mutt_map_get_name((value & SORT_MASK), (struct Mapping *) cdef->data);
162
163 if (!str)
164 {
165 buf_printf(err, _("Invalid sort type: %ld"), (long) value);
167 }
168
169 if (value == (*(short *) var))
171
172 if (startup_only(cdef, err))
174
175 if (cdef->validator)
176 {
177 int rc = cdef->validator(cs, cdef, value, err);
178
179 if (CSR_RESULT(rc) != CSR_SUCCESS)
180 return rc | CSR_INV_VALIDATOR;
181 }
182
183 *(short *) var = value;
184 return CSR_SUCCESS;
185}
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
Mapping between user-readable string and a constant.
Definition: mapping.h:33
+ Here is the call graph for this function:

◆ string_native_set()

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

Set a String config item by string - Implements ConfigSetType::native_set() -.

Definition at line 133 of file string.c.

136{
137 const char *str = (const char *) value;
138
139 /* Store empty strings as NULL */
140 if (str && (str[0] == '\0'))
141 value = 0;
142
143 if ((value == 0) && (cdef->type & D_NOT_EMPTY))
144 {
145 buf_printf(err, _("Option %s may not be empty"), cdef->name);
147 }
148
149 if (mutt_str_equal((const char *) value, (*(char **) var)))
151
152 int rc;
153
154 if (startup_only(cdef, err))
156
157 if (cdef->validator)
158 {
159 rc = cdef->validator(cs, cdef, value, err);
160
161 if (CSR_RESULT(rc) != CSR_SUCCESS)
162 return rc | CSR_INV_VALIDATOR;
163 }
164
165 string_destroy(cs, var, cdef);
166
167 str = mutt_str_dup(str);
168 rc = CSR_SUCCESS;
169 if (!str)
170 rc |= CSR_SUC_EMPTY;
171
172 *(const char **) var = str;
173 return rc;
174}
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:47
+ Here is the call graph for this function: