NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

Reset a config item to its initial value. More...

+ Collaboration diagram for reset():

Functions

static int address_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an Address to its initial value - Implements ConfigSetType::reset() -.
 
static int bool_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Bool to its initial value - Implements ConfigSetType::reset() -.
 
static int enum_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an Enumeration to its initial value - Implements ConfigSetType::reset() -.
 
static int long_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Long to its initial value - Implements ConfigSetType::reset() -.
 
static int mbtable_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an MbTable to its initial value - Implements ConfigSetType::reset() -.
 
static int myvar_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a MyVar to its initial value - Implements ConfigSetType::reset() -.
 
static int number_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Number to its initial value - Implements ConfigSetType::reset() -.
 
static int path_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Path to its initial value - Implements ConfigSetType::reset() -.
 
static int quad_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -.
 
static int regex_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Regex to its initial value - Implements ConfigSetType::reset() -.
 
static int slist_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Slist to its initial value - Implements ConfigSetType::reset() -.
 
static int sort_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Sort to its initial value - Implements ConfigSetType::reset() -.
 
static int string_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a String to its initial value - Implements ConfigSetType::reset() -.
 
static int expando_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an Expando to its initial value - Implements ConfigSetType::reset() -.
 

Detailed Description

Reset a config item to its initial value.

Parameters
varVariable to reset
cdefVariable definition
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_reset()

static int address_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset an Address to its initial value - Implements ConfigSetType::reset() -.

Definition at line 232 of file config_type.c.

233{
234 struct Address *a = NULL;
235 const char *initial = (const char *) cdef->initial;
236
237 if (initial)
238 a = address_new(initial);
239
240 int rc = CSR_SUCCESS;
241
242 if (cdef->validator)
243 {
244 rc = cdef->validator(cdef, (intptr_t) a, err);
245
246 if (CSR_RESULT(rc) != CSR_SUCCESS)
247 {
248 address_destroy(&a, cdef);
249 return rc | CSR_INV_VALIDATOR;
250 }
251 }
252
253 if (!a)
254 rc |= CSR_SUC_EMPTY;
255
256 address_destroy(var, cdef);
257
258 *(struct Address **) var = a;
259 return rc;
260}
struct Address * address_new(const char *addr)
Create an Address from a string.
Definition: config_type.c:52
#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
static void address_destroy(void *var, const struct ConfigDef *cdef)
Destroy an Address object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:62
An email address.
Definition: address.h:36
int(* validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:79
intptr_t initial
Initial value.
Definition: set.h:65
+ Here is the call graph for this function:

◆ bool_reset()

static int bool_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Bool to its initial value - Implements ConfigSetType::reset() -.

Definition at line 174 of file bool.c.

175{
176 if (cdef->initial == (*(bool *) var))
178
179 if (startup_only(cdef, err))
181
182 if (cdef->validator)
183 {
184 int rc = cdef->validator(cdef, cdef->initial, err);
185
186 if (CSR_RESULT(rc) != CSR_SUCCESS)
187 return rc | CSR_INV_VALIDATOR;
188 }
189
190 *(bool *) var = cdef->initial;
191 return CSR_SUCCESS;
192}
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_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:42
+ Here is the call graph for this function:

◆ enum_reset()

static int enum_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset an Enumeration to its initial value - Implements ConfigSetType::reset() -.

Definition at line 169 of file enum.c.

170{
171 if (cdef->initial == (*(unsigned char *) var))
173
174 if (startup_only(cdef, err))
176
177 if (cdef->validator)
178 {
179 int rc = cdef->validator(cdef, cdef->initial, err);
180
181 if (CSR_RESULT(rc) != CSR_SUCCESS)
182 return rc | CSR_INV_VALIDATOR;
183 }
184
185 *(unsigned char *) var = cdef->initial;
186 return CSR_SUCCESS;
187}
+ Here is the call graph for this function:

◆ long_reset()

static int long_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Long to its initial value - Implements ConfigSetType::reset() -.

Definition at line 235 of file long.c.

236{
237 if (cdef->initial == (*(long *) var))
239
240 if (startup_only(cdef, err))
242
243 if (cdef->validator)
244 {
245 int rc = cdef->validator(cdef, cdef->initial, err);
246
247 if (CSR_RESULT(rc) != CSR_SUCCESS)
248 return rc | CSR_INV_VALIDATOR;
249 }
250
251 *(long *) var = cdef->initial;
252 return CSR_SUCCESS;
253}
+ Here is the call graph for this function:

◆ mbtable_reset()

static int mbtable_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset an MbTable to its initial value - Implements ConfigSetType::reset() -.

Definition at line 272 of file mbtable.c.

273{
274 struct MbTable *table = NULL;
275 const char *initial = (const char *) cdef->initial;
276
277 struct MbTable *curtable = *(struct MbTable **) var;
278 const char *curval = curtable ? curtable->orig_str : NULL;
279
280 int rc = CSR_SUCCESS;
281 if (!curtable)
282 rc |= CSR_SUC_EMPTY;
283
284 if (mutt_str_equal(initial, curval))
285 return rc | CSR_SUC_NO_CHANGE;
286
287 if (startup_only(cdef, err))
289
290 if (initial)
291 table = mbtable_parse(initial);
292
293 if (cdef->validator)
294 {
295 rc = cdef->validator(cdef, (intptr_t) table, err);
296
297 if (CSR_RESULT(rc) != CSR_SUCCESS)
298 {
299 mbtable_destroy(&table, cdef);
300 return rc | CSR_INV_VALIDATOR;
301 }
302 }
303
304 if (!table)
305 rc |= CSR_SUC_EMPTY;
306
307 mbtable_destroy(var, cdef);
308
309 *(struct MbTable **) var = table;
310 return rc;
311}
static void mbtable_destroy(void *var, const struct ConfigDef *cdef)
Destroy an MbTable object - Implements ConfigSetType::destroy() -.
Definition: mbtable.c:110
struct MbTable * mbtable_parse(const char *s)
Parse a multibyte string into a table.
Definition: mbtable.c:66
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:661
Multibyte character table.
Definition: mbtable.h:36
char * orig_str
Original string used to generate this object.
Definition: mbtable.h:37
+ Here is the call graph for this function:

◆ myvar_reset()

static int myvar_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a MyVar to its initial value - Implements ConfigSetType::reset() -.

Definition at line 177 of file myvar.c.

178{
179 int rc = CSR_SUCCESS;
180
181 const char *str = mutt_str_dup((const char *) cdef->initial);
182 if (!str)
183 rc |= CSR_SUC_EMPTY;
184
185 if (mutt_str_equal(str, (*(char **) var)))
186 {
187 FREE(&str);
188 return rc | CSR_SUC_NO_CHANGE;
189 }
190
191 myvar_destroy(var, cdef);
192
193 if (!str)
194 rc |= CSR_SUC_EMPTY;
195
196 *(const char **) var = str;
197 return rc;
198}
static void myvar_destroy(void *var, const struct ConfigDef *cdef)
Destroy a MyVar - Implements ConfigSetType::destroy() -.
Definition: myvar.c:45
#define FREE(x)
Definition: memory.h:55
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:254
+ Here is the call graph for this function:

◆ number_reset()

static int number_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Number to its initial value - Implements ConfigSetType::reset() -.

Definition at line 280 of file number.c.

281{
282 if (cdef->initial == native_get(var))
284
285 if (cdef->validator)
286 {
287 int rc = cdef->validator(cdef, cdef->initial, err);
288
289 if (CSR_RESULT(rc) != CSR_SUCCESS)
290 return rc | CSR_INV_VALIDATOR;
291 }
292
293 if (startup_only(cdef, err))
295
296 native_set(var, cdef->initial);
297 return CSR_SUCCESS;
298}
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_reset()

static int path_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Path to its initial value - Implements ConfigSetType::reset() -.

Definition at line 230 of file path.c.

231{
232 int rc = CSR_SUCCESS;
233
234 const char *str = path_tidy((const char *) cdef->initial, cdef->type & D_PATH_DIR);
235 if (!str)
236 rc |= CSR_SUC_EMPTY;
237
238 if (mutt_str_equal(str, (*(char **) var)))
239 {
240 FREE(&str);
241 return rc | CSR_SUC_NO_CHANGE;
242 }
243
244 if (startup_only(cdef, err))
245 {
246 FREE(&str);
248 }
249
250 if (cdef->validator)
251 {
252 rc = cdef->validator(cdef, cdef->initial, err);
253
254 if (CSR_RESULT(rc) != CSR_SUCCESS)
255 {
256 FREE(&str);
257 return rc | CSR_INV_VALIDATOR;
258 }
259 }
260
261 path_destroy(var, cdef);
262
263 if (!str)
264 rc |= CSR_SUC_EMPTY;
265
266 *(const char **) var = str;
267 return rc;
268}
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
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:64
#define D_PATH_DIR
Path is a directory.
Definition: types.h:102
+ Here is the call graph for this function:

◆ quad_reset()

static int quad_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -.

Definition at line 180 of file quad.c.

181{
182 if (cdef->initial == (*(char *) var))
184
185 if (startup_only(cdef, err))
187
188 if (cdef->validator)
189 {
190 int rc = cdef->validator(cdef, cdef->initial, err);
191
192 if (CSR_RESULT(rc) != CSR_SUCCESS)
193 return rc | CSR_INV_VALIDATOR;
194 }
195
196 *(char *) var = cdef->initial;
197 return CSR_SUCCESS;
198}
+ Here is the call graph for this function:

◆ regex_reset()

static int regex_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Regex to its initial value - Implements ConfigSetType::reset() -.

Definition at line 297 of file regex.c.

298{
299 struct Regex *r = NULL;
300 const char *initial = (const char *) cdef->initial;
301
302 struct Regex *currx = *(struct Regex **) var;
303 const char *curval = currx ? currx->pattern : NULL;
304
305 int rc = CSR_SUCCESS;
306 if (!currx)
307 rc |= CSR_SUC_EMPTY;
308
309 if (mutt_str_equal(initial, curval))
310 return rc | CSR_SUC_NO_CHANGE;
311
312 if (startup_only(cdef, err))
314
315 if (initial)
316 {
317 r = regex_new(initial, cdef->type, err);
318 if (!r)
319 return CSR_ERR_CODE;
320 }
321
322 if (cdef->validator)
323 {
324 rc = cdef->validator(cdef, (intptr_t) r, err);
325
326 if (CSR_RESULT(rc) != CSR_SUCCESS)
327 {
328 regex_destroy(&r, cdef);
329 return rc | CSR_INV_VALIDATOR;
330 }
331 }
332
333 if (!r)
334 rc |= CSR_SUC_EMPTY;
335
336 regex_destroy(var, cdef);
337
338 *(struct Regex **) var = r;
339 return rc;
340}
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:102
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:34
static void regex_destroy(void *var, const struct ConfigDef *cdef)
Destroy a Regex object - Implements ConfigSetType::destroy() -.
Definition: regex.c:85
Cached regular expression.
Definition: regex3.h:86
char * pattern
printable version
Definition: regex3.h:87
+ Here is the call graph for this function:

◆ slist_reset()

static int slist_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Slist to its initial value - Implements ConfigSetType::reset() -.

Definition at line 289 of file slist.c.

290{
291 struct Slist *list = NULL;
292 const char *initial = (const char *) cdef->initial;
293
294 if (initial)
295 list = slist_parse(initial, cdef->type);
296
297 if (slist_equal(list, *(struct Slist **) var))
298 {
299 slist_free(&list);
301 }
302
303 if (startup_only(cdef, err))
304 {
305 slist_free(&list);
307 }
308
309 int rc = CSR_SUCCESS;
310
311 if (cdef->validator)
312 {
313 rc = cdef->validator(cdef, (intptr_t) list, err);
314
315 if (CSR_RESULT(rc) != CSR_SUCCESS)
316 {
317 slist_destroy(&list, cdef);
318 return rc | CSR_INV_VALIDATOR;
319 }
320 }
321
322 if (!list)
323 rc |= CSR_SUC_EMPTY;
324
325 slist_destroy(var, cdef);
326
327 *(struct Slist **) var = list;
328 return rc;
329}
static void slist_destroy(void *var, const struct ConfigDef *cdef)
Destroy an Slist object - Implements ConfigSetType::destroy() -.
Definition: slist.c:47
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition: slist.c:177
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
String list.
Definition: slist.h:37
+ Here is the call graph for this function:

◆ sort_reset()

static int sort_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a Sort to its initial value - Implements ConfigSetType::reset() -.

Definition at line 206 of file sort.c.

207{
208 if (cdef->initial == (*(short *) var))
210
211 if (startup_only(cdef, err))
213
214 if (cdef->validator)
215 {
216 int rc = cdef->validator(cdef, cdef->initial, err);
217
218 if (CSR_RESULT(rc) != CSR_SUCCESS)
219 return rc | CSR_INV_VALIDATOR;
220 }
221
222 *(short *) var = cdef->initial;
223 return CSR_SUCCESS;
224}
+ Here is the call graph for this function:

◆ string_reset()

static int string_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset a String to its initial value - Implements ConfigSetType::reset() -.

Definition at line 239 of file string.c.

240{
241 int rc = CSR_SUCCESS;
242
243 const char *str = mutt_str_dup((const char *) cdef->initial);
244 if (!str)
245 rc |= CSR_SUC_EMPTY;
246
247 if (mutt_str_equal(str, (*(char **) var)))
248 {
249 FREE(&str);
250 return rc | CSR_SUC_NO_CHANGE;
251 }
252
253 if (startup_only(cdef, err))
254 {
255 FREE(&str);
257 }
258
259 if (cdef->validator)
260 {
261 rc = cdef->validator(cdef, cdef->initial, err);
262
263 if (CSR_RESULT(rc) != CSR_SUCCESS)
264 {
265 FREE(&str);
266 return rc | CSR_INV_VALIDATOR;
267 }
268 }
269
270 string_destroy(var, cdef);
271
272 if (!str)
273 rc |= CSR_SUC_EMPTY;
274
275 *(const char **) var = str;
276 return rc;
277}
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:

◆ expando_reset()

static int expando_reset ( void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

Reset an Expando to its initial value - Implements ConfigSetType::reset() -.

Definition at line 291 of file config_type.c.

292{
293 struct Expando *exp = NULL;
294 const char *initial = (const char *) cdef->initial;
295
296 if (initial)
297 {
298 const struct ExpandoDefinition *defs = (const struct ExpandoDefinition *)
299 cdef->data;
300 exp = expando_parse(initial, defs, err);
301 }
302
303 if (expando_equal(exp, *(struct Expando **) var))
304 {
305 expando_free(&exp);
307 }
308
309 if (startup_only(cdef, err))
310 {
311 expando_free(&exp);
313 }
314
315 int rc = CSR_SUCCESS;
316
317 if (cdef->validator)
318 {
319 rc = cdef->validator(cdef, (intptr_t) exp, err);
320
321 if (CSR_RESULT(rc) != CSR_SUCCESS)
322 {
323 expando_destroy(&exp, cdef);
324 return rc | CSR_INV_VALIDATOR;
325 }
326 }
327
328 if (!exp)
329 rc |= CSR_SUC_EMPTY;
330
331 expando_destroy(var, cdef);
332
333 *(struct Expando **) var = exp;
334 return rc;
335}
struct Expando * expando_parse(const char *str, const struct ExpandoDefinition *defs, struct Buffer *err)
Parse an Expando string.
Definition: expando.c:81
void expando_free(struct Expando **ptr)
Free an Expando object.
Definition: expando.c:61
bool expando_equal(const struct Expando *a, const struct Expando *b)
Compare two expandos.
Definition: expando.c:137
static void expando_destroy(void *var, const struct ConfigDef *cdef)
Destroy an Expando object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:49
intptr_t data
Extra variable data.
Definition: set.h:66
Definition of a format string.
Definition: definition.h:44
Parsed Expando trees.
Definition: expando.h:41
+ Here is the call graph for this function: