NeoMutt  2025-01-09-117-gace867
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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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
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
var is not NULL
cdef is not NULL

Function Documentation

◆ address_native_set()

static int address_native_set ( 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 177 of file config_type.c.

179{
180 int rc;
181
182 if (cdef->validator)
183 {
184 rc = cdef->validator(cdef, value, err);
185
186 if (CSR_RESULT(rc) != CSR_SUCCESS)
187 return rc | CSR_INV_VALIDATOR;
188 }
189
190 mutt_addr_free(var);
191
192 struct Address *addr = address_dup((struct Address *) value);
193
194 rc = CSR_SUCCESS;
195 if (!addr)
196 rc |= CSR_SUC_EMPTY;
197
198 *(struct Address **) var = addr;
199 return rc;
200}
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:163
#define CSR_INV_VALIDATOR
Value was rejected by the validator.
Definition: set.h:46
#define CSR_RESULT(x)
Definition: set.h:50
#define CSR_SUC_EMPTY
Value is empty/unset.
Definition: set.h:40
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:33
An email address.
Definition: address.h:36
int(* validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:79
+ Here is the call graph for this function:

◆ bool_native_set()

static int bool_native_set ( 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 128 of file bool.c.

130{
131 if ((value < 0) || (value > 1))
132 {
133 buf_printf(err, _("Invalid boolean value: %ld"), (long) value);
135 }
136
137 if (value == (*(bool *) var))
139
140 if (startup_only(cdef, err))
142
143 if (cdef->validator)
144 {
145 int rc = cdef->validator(cdef, value, err);
146
147 if (CSR_RESULT(rc) != CSR_SUCCESS)
148 return rc | CSR_INV_VALIDATOR;
149 }
150
151 *(bool *) var = value;
152 return CSR_SUCCESS;
153}
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:293
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:36
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:45
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:42
#define _(a)
Definition: message.h:28
+ Here is the call graph for this function:

◆ enum_native_set()

static int enum_native_set ( 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 118 of file enum.c.

120{
121 struct EnumDef *ed = (struct EnumDef *) cdef->data;
122 if (!ed || !ed->lookup)
123 return CSR_ERR_CODE;
124
125 const char *name = mutt_map_get_name(value, ed->lookup);
126 if (!name)
127 {
128 buf_printf(err, _("Invalid enum value: %ld"), (long) value);
130 }
131
132 if (value == (*(unsigned char *) var))
134
135 if (startup_only(cdef, err))
137
138 if (cdef->validator)
139 {
140 int rc = cdef->validator(cdef, value, err);
141
142 if (CSR_RESULT(rc) != CSR_SUCCESS)
143 return rc | CSR_INV_VALIDATOR;
144 }
145
146 *(unsigned char *) var = value;
147 return CSR_SUCCESS;
148}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:34
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:66
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 ( 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(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:63
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:64
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:100
+ Here is the call graph for this function:

◆ mbtable_native_set()

static int mbtable_native_set ( 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 215 of file mbtable.c.

217{
218 int rc;
219
220 if (mbtable_equal(*(struct MbTable **) var, (struct MbTable *) value))
222
223 if (startup_only(cdef, err))
225
226 if (cdef->validator)
227 {
228 rc = cdef->validator(cdef, value, err);
229
230 if (CSR_RESULT(rc) != CSR_SUCCESS)
231 return rc | CSR_INV_VALIDATOR;
232 }
233
234 mbtable_free(var);
235
236 struct MbTable *table = mbtable_dup((struct MbTable *) value);
237
238 rc = CSR_SUCCESS;
239 if (!table)
240 rc |= CSR_SUC_EMPTY;
241
242 *(struct MbTable **) var = table;
243 return rc;
244}
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:202
void mbtable_free(struct MbTable **ptr)
Free an MbTable object.
Definition: mbtable.c:317
Multibyte character table.
Definition: mbtable.h:36
+ Here is the call graph for this function:

◆ myvar_native_set()

static int myvar_native_set ( 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 113 of file myvar.c.

115{
116 const char *str = (const char *) value;
117
118 /* Store empty myvars as NULL */
119 if (str && (str[0] == '\0'))
120 value = 0;
121
122 if (mutt_str_equal((const char *) value, (*(char **) var)))
124
125 int rc;
126
127 myvar_destroy(var, cdef);
128
129 str = mutt_str_dup(str);
130 rc = CSR_SUCCESS;
131 if (!str)
132 rc |= CSR_SUC_EMPTY;
133
134 *(const char **) var = str;
135 return rc;
136}
static void myvar_destroy(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:254
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
+ Here is the call graph for this function:

◆ number_native_set()

static int number_native_set ( 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 146 of file number.c.

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

◆ path_native_set()

static int path_native_set ( 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 162 of file path.c.

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

◆ quad_native_set()

static int quad_native_set ( 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(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:54
+ Here is the call graph for this function:

◆ regex_native_set()

static int regex_native_set ( 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 227 of file regex.c.

229{
230 int rc;
231
232 if (regex_equal(*(struct Regex **) var, (struct Regex *) value))
234
235 if (startup_only(cdef, err))
237
238 if (cdef->validator)
239 {
240 rc = cdef->validator(cdef, value, err);
241
242 if (CSR_RESULT(rc) != CSR_SUCCESS)
243 return rc | CSR_INV_VALIDATOR;
244 }
245
246 rc = CSR_SUCCESS;
247 struct Regex *orig = (struct Regex *) value;
248 struct Regex *r = NULL;
249
250 if (orig && orig->pattern)
251 {
252 const uint32_t flags = orig->pat_not ? D_REGEX_ALLOW_NOT : 0;
253 r = regex_new(orig->pattern, flags, err);
254 if (!r)
255 rc = CSR_ERR_INVALID;
256 }
257 else
258 {
259 rc |= CSR_SUC_EMPTY;
260 }
261
262 if (CSR_RESULT(rc) == CSR_SUCCESS)
263 {
264 regex_free(var);
265 *(struct Regex **) var = r;
266 }
267
268 return rc;
269}
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:106
+ Here is the call graph for this function:

◆ slist_native_set()

static int slist_native_set ( 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 144 of file slist.c.

146{
147 int rc;
148
149 if (slist_equal((struct Slist *) value, *(struct Slist **) var))
151
152 if (startup_only(cdef, err))
154
155 if (cdef->validator)
156 {
157 rc = cdef->validator(cdef, value, err);
158
159 if (CSR_RESULT(rc) != CSR_SUCCESS)
160 return rc | CSR_INV_VALIDATOR;
161 }
162
163 slist_free(var);
164
165 struct Slist *list = slist_dup((struct Slist *) value);
166
167 rc = CSR_SUCCESS;
168 if (!list)
169 rc |= CSR_SUC_EMPTY;
170
171 *(struct Slist **) var = list;
172 return rc;
173}
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:124
bool slist_equal(const struct Slist *a, const struct Slist *b)
Compare two string lists.
Definition: slist.c:91
struct Slist * slist_dup(const struct Slist *list)
Create a copy of an Slist object.
Definition: slist.c:108
String list.
Definition: slist.h:37
+ Here is the call graph for this function:

◆ sort_native_set()

static int sort_native_set ( 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(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: sort.h:38
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 ( 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.

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