NeoMutt  2023-11-03-107-g582dc1
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() -.
 

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 209 of file config_type.c.

211{
212 struct Address *a = NULL;
213 const char *initial = (const char *) cdef->initial;
214
215 if (initial)
216 a = address_new(initial);
217
218 int rc = CSR_SUCCESS;
219
220 if (cdef->validator)
221 {
222 rc = cdef->validator(cs, cdef, (intptr_t) a, err);
223
224 if (CSR_RESULT(rc) != CSR_SUCCESS)
225 {
226 address_destroy(cs, &a, cdef);
227 return rc | CSR_INV_VALIDATOR;
228 }
229 }
230
231 if (!a)
232 rc |= CSR_SUC_EMPTY;
233
234 address_destroy(cs, var, cdef);
235
236 *(struct Address **) var = a;
237 return rc;
238}
#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
struct Address * address_new(const char *addr)
Create an Address from a string.
Definition: config_type.c:52
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:62
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 167 of file bool.c.

169{
170 if (cdef->initial == (*(bool *) var))
172
173 if (startup_only(cdef, err))
175
176 if (cdef->validator)
177 {
178 int rc = cdef->validator(cs, cdef, cdef->initial, err);
179
180 if (CSR_RESULT(rc) != CSR_SUCCESS)
181 return rc | CSR_INV_VALIDATOR;
182 }
183
184 *(bool *) var = cdef->initial;
185 return CSR_SUCCESS;
186}
static bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
Validator function for DT_ON_STARTUP.
Definition: set.h:301
#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 228 of file long.c.

230{
231 if (cdef->initial == (*(long *) var))
233
234 if (startup_only(cdef, err))
236
237 if (cdef->validator)
238 {
239 int rc = cdef->validator(cs, cdef, cdef->initial, err);
240
241 if (CSR_RESULT(rc) != CSR_SUCCESS)
242 return rc | CSR_INV_VALIDATOR;
243 }
244
245 *(long *) var = cdef->initial;
246 return CSR_SUCCESS;
247}
+ 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 261 of file mbtable.c.

263{
264 struct MbTable *table = NULL;
265 const char *initial = (const char *) cdef->initial;
266
267 struct MbTable *curtable = *(struct MbTable **) var;
268 const char *curval = curtable ? curtable->orig_str : NULL;
269
270 int rc = CSR_SUCCESS;
271 if (!curtable)
272 rc |= CSR_SUC_EMPTY;
273
274 if (mutt_str_equal(initial, curval))
275 return rc | CSR_SUC_NO_CHANGE;
276
277 if (startup_only(cdef, err))
279
280 if (initial)
281 table = mbtable_parse(initial);
282
283 if (cdef->validator)
284 {
285 rc = cdef->validator(cs, cdef, (intptr_t) table, err);
286
287 if (CSR_RESULT(rc) != CSR_SUCCESS)
288 {
289 mbtable_destroy(cs, &table, cdef);
290 return rc | CSR_INV_VALIDATOR;
291 }
292 }
293
294 if (!table)
295 rc |= CSR_SUC_EMPTY;
296
297 mbtable_destroy(cs, var, cdef);
298
299 *(struct MbTable **) var = table;
300 return rc;
301}
static void mbtable_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an MbTable object - Implements ConfigSetType::destroy() -.
Definition: mbtable.c:109
struct MbTable * mbtable_parse(const char *s)
Parse a multibyte string into a table.
Definition: mbtable.c:65
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:763
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 176 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(cs, 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(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a MyVar - Implements ConfigSetType::destroy() -.
Definition: myvar.c:41
#define FREE(x)
Definition: memory.h:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
+ 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 248 of file number.c.

250{
251 if (cdef->initial == (*(short *) var))
253
254 if (cdef->validator)
255 {
256 int rc = cdef->validator(cs, cdef, cdef->initial, err);
257
258 if (CSR_RESULT(rc) != CSR_SUCCESS)
259 return rc | CSR_INV_VALIDATOR;
260 }
261
262 if (startup_only(cdef, err))
264
265 *(short *) var = cdef->initial;
266 return CSR_SUCCESS;
267}
+ 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 217 of file path.c.

219{
220 int rc = CSR_SUCCESS;
221
222 const char *str = path_tidy((const char *) cdef->initial, cdef->type & DT_PATH_DIR);
223 if (!str)
224 rc |= CSR_SUC_EMPTY;
225
226 if (mutt_str_equal(str, (*(char **) var)))
227 {
228 FREE(&str);
229 return rc | CSR_SUC_NO_CHANGE;
230 }
231
232 if (startup_only(cdef, err))
233 {
234 FREE(&str);
236 }
237
238 if (cdef->validator)
239 {
240 rc = cdef->validator(cs, cdef, cdef->initial, err);
241
242 if (CSR_RESULT(rc) != CSR_SUCCESS)
243 {
244 FREE(&str);
245 return rc | CSR_INV_VALIDATOR;
246 }
247 }
248
249 path_destroy(cs, var, cdef);
250
251 if (!str)
252 rc |= CSR_SUC_EMPTY;
253
254 *(const char **) var = str;
255 return rc;
256}
static char * path_tidy(const char *path, bool is_dir)
Tidy a path for storage.
Definition: path.c:55
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:75
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define DT_PATH_DIR
Path is a directory.
Definition: types.h:57
+ 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 169 of file quad.c.

171{
172 if (cdef->initial == (*(char *) var))
174
175 if (startup_only(cdef, err))
177
178 if (cdef->validator)
179 {
180 int rc = cdef->validator(cs, cdef, cdef->initial, err);
181
182 if (CSR_RESULT(rc) != CSR_SUCCESS)
183 return rc | CSR_INV_VALIDATOR;
184 }
185
186 *(char *) var = cdef->initial;
187 return CSR_SUCCESS;
188}
+ 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 284 of file regex.c.

286{
287 struct Regex *r = NULL;
288 const char *initial = (const char *) cdef->initial;
289
290 struct Regex *currx = *(struct Regex **) var;
291 const char *curval = currx ? currx->pattern : NULL;
292
293 int rc = CSR_SUCCESS;
294 if (!currx)
295 rc |= CSR_SUC_EMPTY;
296
297 if (mutt_str_equal(initial, curval))
298 return rc | CSR_SUC_NO_CHANGE;
299
300 if (startup_only(cdef, err))
302
303 if (initial)
304 {
305 r = regex_new(initial, cdef->type, err);
306 if (!r)
307 return CSR_ERR_CODE;
308 }
309
310 if (cdef->validator)
311 {
312 rc = cdef->validator(cs, cdef, (intptr_t) r, err);
313
314 if (CSR_RESULT(rc) != CSR_SUCCESS)
315 {
316 regex_destroy(cs, &r, cdef);
317 return rc | CSR_INV_VALIDATOR;
318 }
319 }
320
321 if (!r)
322 rc |= CSR_SUC_EMPTY;
323
324 regex_destroy(cs, var, cdef);
325
326 *(struct Regex **) var = r;
327 return rc;
328}
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:100
static void regex_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Regex object - Implements ConfigSetType::destroy() -.
Definition: regex.c:83
Cached regular expression.
Definition: regex3.h:89
char * pattern
printable version
Definition: regex3.h:90
+ 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 297 of file slist.c.

299{
300 if (!cs || !var || !cdef)
301 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
302
303 struct Slist *list = NULL;
304 const char *initial = (const char *) cdef->initial;
305
306 if (initial)
307 list = slist_parse(initial, cdef->type);
308
309 if (slist_equal(list, *(struct Slist **) var))
310 {
311 slist_free(&list);
313 }
314
315 if (startup_only(cdef, err))
316 {
317 slist_free(&list);
319 }
320
321 int rc = CSR_SUCCESS;
322
323 if (cdef->validator)
324 {
325 rc = cdef->validator(cs, cdef, (intptr_t) list, err);
326
327 if (CSR_RESULT(rc) != CSR_SUCCESS)
328 {
329 slist_destroy(cs, &list, cdef);
330 return rc | CSR_INV_VALIDATOR;
331 }
332 }
333
334 if (!list)
335 rc |= CSR_SUC_EMPTY;
336
337 slist_destroy(cs, var, cdef);
338
339 *(struct Slist **) var = list;
340 return rc;
341}
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:215
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:162
bool slist_equal(const struct Slist *a, const struct Slist *b)
Compare two string lists.
Definition: slist.c:103
String list.
Definition: slist.h:47
+ 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 198 of file sort.c.

200{
201 if (cdef->initial == (*(short *) var))
203
204 if (startup_only(cdef, err))
206
207 if (cdef->validator)
208 {
209 int rc = cdef->validator(cs, cdef, cdef->initial, err);
210
211 if (CSR_RESULT(rc) != CSR_SUCCESS)
212 return rc | CSR_INV_VALIDATOR;
213 }
214
215 *(short *) var = cdef->initial;
216 return CSR_SUCCESS;
217}
+ 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 229 of file string.c.

231{
232 int rc = CSR_SUCCESS;
233
234 const char *str = mutt_str_dup((const char *) cdef->initial);
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(cs, 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 string_destroy(cs, var, cdef);
262
263 if (!str)
264 rc |= CSR_SUC_EMPTY;
265
266 *(const char **) var = str;
267 return rc;
268}
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: