NeoMutt  2024-04-16-36-g75b6fb
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 (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an Address to its initial value - Implements ConfigSetType::reset() -.
 
static int bool_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Bool to its initial value - Implements ConfigSetType::reset() -.
 
static int enum_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an Enumeration to its initial value - Implements ConfigSetType::reset() -.
 
static int long_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Long to its initial value - Implements ConfigSetType::reset() -.
 
static int mbtable_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an MbTable to its initial value - Implements ConfigSetType::reset() -.
 
static int myvar_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a MyVar to its initial value - Implements ConfigSetType::reset() -.
 
static int number_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Number to its initial value - Implements ConfigSetType::reset() -.
 
static int path_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Path to its initial value - Implements ConfigSetType::reset() -.
 
static int quad_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -.
 
static int regex_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Regex to its initial value - Implements ConfigSetType::reset() -.
 
static int slist_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Slist to its initial value - Implements ConfigSetType::reset() -.
 
static int sort_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Sort to its initial value - Implements ConfigSetType::reset() -.
 
static int string_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a String to its initial value - Implements ConfigSetType::reset() -.
 
static int expando_reset (const struct ConfigSet *cs, 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
csConfig items
varVariable to reset
cdefVariable definition
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_reset()

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

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

Definition at line 219 of file config_type.c.

221{
222 struct Address *a = NULL;
223 const char *initial = (const char *) cdef->initial;
224
225 if (initial)
226 a = address_new(initial);
227
228 int rc = CSR_SUCCESS;
229
230 if (cdef->validator)
231 {
232 rc = cdef->validator(cs, cdef, (intptr_t) a, err);
233
234 if (CSR_RESULT(rc) != CSR_SUCCESS)
235 {
236 address_destroy(cs, &a, cdef);
237 return rc | CSR_INV_VALIDATOR;
238 }
239 }
240
241 if (!a)
242 rc |= CSR_SUC_EMPTY;
243
244 address_destroy(cs, var, cdef);
245
246 *(struct Address **) var = a;
247 return rc;
248}
struct Address * address_new(const char *addr)
Create an Address from a string.
Definition: config_type.c:53
#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
static void address_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Address object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:63
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
+ Here is the call graph for this function:

◆ bool_reset()

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

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

Definition at line 168 of file bool.c.

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

◆ enum_reset()

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

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

Definition at line 172 of file enum.c.

174{
175 if (!cs || !var || !cdef)
176 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
177
178 if (cdef->initial == (*(unsigned char *) var))
180
181 if (startup_only(cdef, err))
183
184 if (cdef->validator)
185 {
186 int rc = cdef->validator(cs, cdef, cdef->initial, err);
187
188 if (CSR_RESULT(rc) != CSR_SUCCESS)
189 return rc | CSR_INV_VALIDATOR;
190 }
191
192 *(unsigned char *) var = cdef->initial;
193 return CSR_SUCCESS;
194}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
+ Here is the call graph for this function:

◆ long_reset()

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

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

Definition at line 230 of file long.c.

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

◆ mbtable_reset()

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

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

Definition at line 262 of file mbtable.c.

264{
265 struct MbTable *table = NULL;
266 const char *initial = (const char *) cdef->initial;
267
268 struct MbTable *curtable = *(struct MbTable **) var;
269 const char *curval = curtable ? curtable->orig_str : NULL;
270
271 int rc = CSR_SUCCESS;
272 if (!curtable)
273 rc |= CSR_SUC_EMPTY;
274
275 if (mutt_str_equal(initial, curval))
276 return rc | CSR_SUC_NO_CHANGE;
277
278 if (startup_only(cdef, err))
280
281 if (initial)
282 table = mbtable_parse(initial);
283
284 if (cdef->validator)
285 {
286 rc = cdef->validator(cs, cdef, (intptr_t) table, err);
287
288 if (CSR_RESULT(rc) != CSR_SUCCESS)
289 {
290 mbtable_destroy(cs, &table, cdef);
291 return rc | CSR_INV_VALIDATOR;
292 }
293 }
294
295 if (!table)
296 rc |= CSR_SUC_EMPTY;
297
298 mbtable_destroy(cs, var, cdef);
299
300 *(struct MbTable **) var = table;
301 return rc;
302}
static void mbtable_destroy(const struct ConfigSet *cs, 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:654
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 ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer err 
)
static

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

Definition at line 180 of file myvar.c.

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

◆ number_reset()

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

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

Definition at line 251 of file number.c.

253{
254 if (cdef->initial == (*(short *) var))
256
257 if (cdef->validator)
258 {
259 int rc = cdef->validator(cs, cdef, cdef->initial, err);
260
261 if (CSR_RESULT(rc) != CSR_SUCCESS)
262 return rc | CSR_INV_VALIDATOR;
263 }
264
265 if (startup_only(cdef, err))
267
268 *(short *) var = cdef->initial;
269 return CSR_SUCCESS;
270}
+ Here is the call graph for this function:

◆ path_reset()

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

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

Definition at line 220 of file path.c.

222{
223 int rc = CSR_SUCCESS;
224
225 const char *str = path_tidy((const char *) cdef->initial, cdef->type & D_PATH_DIR);
226 if (!str)
227 rc |= CSR_SUC_EMPTY;
228
229 if (mutt_str_equal(str, (*(char **) var)))
230 {
231 FREE(&str);
232 return rc | CSR_SUC_NO_CHANGE;
233 }
234
235 if (startup_only(cdef, err))
236 {
237 FREE(&str);
239 }
240
241 if (cdef->validator)
242 {
243 rc = cdef->validator(cs, cdef, cdef->initial, err);
244
245 if (CSR_RESULT(rc) != CSR_SUCCESS)
246 {
247 FREE(&str);
248 return rc | CSR_INV_VALIDATOR;
249 }
250 }
251
252 path_destroy(cs, var, cdef);
253
254 if (!str)
255 rc |= CSR_SUC_EMPTY;
256
257 *(const char **) var = str;
258 return rc;
259}
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
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define D_PATH_DIR
Path is a directory.
Definition: types.h:103
+ Here is the call graph for this function:

◆ quad_reset()

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

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

Definition at line 173 of file quad.c.

175{
176 if (cdef->initial == (*(char *) var))
178
179 if (startup_only(cdef, err))
181
182 if (cdef->validator)
183 {
184 int rc = cdef->validator(cs, cdef, cdef->initial, err);
185
186 if (CSR_RESULT(rc) != CSR_SUCCESS)
187 return rc | CSR_INV_VALIDATOR;
188 }
189
190 *(char *) var = cdef->initial;
191 return CSR_SUCCESS;
192}
+ Here is the call graph for this function:

◆ regex_reset()

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

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

Definition at line 286 of file regex.c.

288{
289 struct Regex *r = NULL;
290 const char *initial = (const char *) cdef->initial;
291
292 struct Regex *currx = *(struct Regex **) var;
293 const char *curval = currx ? currx->pattern : NULL;
294
295 int rc = CSR_SUCCESS;
296 if (!currx)
297 rc |= CSR_SUC_EMPTY;
298
299 if (mutt_str_equal(initial, curval))
300 return rc | CSR_SUC_NO_CHANGE;
301
302 if (startup_only(cdef, err))
304
305 if (initial)
306 {
307 r = regex_new(initial, cdef->type, err);
308 if (!r)
309 return CSR_ERR_CODE;
310 }
311
312 if (cdef->validator)
313 {
314 rc = cdef->validator(cs, cdef, (intptr_t) r, err);
315
316 if (CSR_RESULT(rc) != CSR_SUCCESS)
317 {
318 regex_destroy(cs, &r, cdef);
319 return rc | CSR_INV_VALIDATOR;
320 }
321 }
322
323 if (!r)
324 rc |= CSR_SUC_EMPTY;
325
326 regex_destroy(cs, var, cdef);
327
328 *(struct Regex **) var = r;
329 return rc;
330}
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:102
static void regex_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Regex object - Implements ConfigSetType::destroy() -.
Definition: regex.c:85
Cached regular expression.
Definition: regex3.h:85
char * pattern
printable version
Definition: regex3.h:86
+ Here is the call graph for this function:

◆ slist_reset()

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

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

Definition at line 298 of file slist.c.

300{
301 if (!cs || !var || !cdef)
302 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
303
304 struct Slist *list = NULL;
305 const char *initial = (const char *) cdef->initial;
306
307 if (initial)
308 list = slist_parse(initial, cdef->type);
309
310 if (slist_equal(list, *(struct Slist **) var))
311 {
312 slist_free(&list);
314 }
315
316 if (startup_only(cdef, err))
317 {
318 slist_free(&list);
320 }
321
322 int rc = CSR_SUCCESS;
323
324 if (cdef->validator)
325 {
326 rc = cdef->validator(cs, cdef, (intptr_t) list, err);
327
328 if (CSR_RESULT(rc) != CSR_SUCCESS)
329 {
330 slist_destroy(cs, &list, cdef);
331 return rc | CSR_INV_VALIDATOR;
332 }
333 }
334
335 if (!list)
336 rc |= CSR_SUC_EMPTY;
337
338 slist_destroy(cs, var, cdef);
339
340 *(struct Slist **) var = list;
341 return rc;
342}
static void slist_destroy(const struct ConfigSet *cs, 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:179
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:126
bool slist_equal(const struct Slist *a, const struct Slist *b)
Compare two string lists.
Definition: slist.c:89
String list.
Definition: slist.h:37
+ Here is the call graph for this function:

◆ sort_reset()

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

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

Definition at line 199 of file sort.c.

201{
202 if (cdef->initial == (*(short *) var))
204
205 if (startup_only(cdef, err))
207
208 if (cdef->validator)
209 {
210 int rc = cdef->validator(cs, cdef, cdef->initial, err);
211
212 if (CSR_RESULT(rc) != CSR_SUCCESS)
213 return rc | CSR_INV_VALIDATOR;
214 }
215
216 *(short *) var = cdef->initial;
217 return CSR_SUCCESS;
218}
+ Here is the call graph for this function:

◆ string_reset()

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

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

Definition at line 231 of file string.c.

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

◆ expando_reset()

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

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

Definition at line 285 of file config_type.c.

287{
288 if (!cs || !var || !cdef)
289 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
290
291 struct Expando *exp = NULL;
292 const char *initial = (const char *) cdef->initial;
293
294 if (initial)
295 {
296 const struct ExpandoDefinition *defs = (const struct ExpandoDefinition *)
297 cdef->data;
298 exp = expando_parse(initial, defs, err);
299 }
300
301 if (expando_equal(exp, *(struct Expando **) var))
302 {
303 expando_free(&exp);
305 }
306
307 if (startup_only(cdef, err))
308 {
309 expando_free(&exp);
311 }
312
313 int rc = CSR_SUCCESS;
314
315 if (cdef->validator)
316 {
317 rc = cdef->validator(cs, cdef, (intptr_t) exp, err);
318
319 if (CSR_RESULT(rc) != CSR_SUCCESS)
320 {
321 expando_destroy(cs, &exp, cdef);
322 return rc | CSR_INV_VALIDATOR;
323 }
324 }
325
326 if (!exp)
327 rc |= CSR_SUC_EMPTY;
328
329 expando_destroy(cs, var, cdef);
330
331 *(struct Expando **) var = exp;
332 return rc;
333}
struct Expando * expando_parse(const char *str, const struct ExpandoDefinition *defs, struct Buffer *err)
Parse an Expando string.
Definition: expando.c:74
void expando_free(struct Expando **ptr)
Free an Expando object.
Definition: expando.c:54
bool expando_equal(const struct Expando *a, const struct Expando *b)
Compare two expandos.
Definition: expando.c:129
static void expando_destroy(const struct ConfigSet *cs, 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:68
Definition of a format string.
Definition: definition.h:52
Parsed Expando trees.
Definition: expando.h:41
+ Here is the call graph for this function: