NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN

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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 
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() -. More...
 

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

Contract

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 201 of file address.c.

203 {
204  struct Address *a = NULL;
205  const char *initial = (const char *) cdef->initial;
206 
207  if (initial)
208  a = address_new(initial);
209 
210  int rc = CSR_SUCCESS;
211 
212  if (cdef->validator)
213  {
214  rc = cdef->validator(cs, cdef, (intptr_t) a, err);
215 
216  if (CSR_RESULT(rc) != CSR_SUCCESS)
217  {
218  address_destroy(cs, &a, cdef);
219  return rc | CSR_INV_VALIDATOR;
220  }
221  }
222 
223  if (!a)
224  rc |= CSR_SUC_EMPTY;
225 
226  address_destroy(cs, var, cdef);
227 
228  *(struct Address **) var = a;
229  return rc;
230 }
struct Address * address_new(const char *addr)
Create an Address from a string.
Definition: address.c:237
static void address_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Address object - Implements ConfigSetType::destroy() -.
Definition: address.c:49
#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
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 161 of file bool.c.

163 {
164  if (cdef->initial == (*(bool *) var))
166 
167  if (cdef->validator)
168  {
169  int rc = cdef->validator(cs, cdef, cdef->initial, err);
170 
171  if (CSR_RESULT(rc) != CSR_SUCCESS)
172  return rc | CSR_INV_VALIDATOR;
173  }
174 
175  *(bool *) var = cdef->initial;
176  return CSR_SUCCESS;
177 }
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44

◆ 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 166 of file enum.c.

168 {
169  if (!cs || !var || !cdef)
170  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
171 
172  if (cdef->initial == (*(unsigned char *) var))
173  return (CSR_SUCCESS | CSR_SUC_NO_CHANGE);
174 
175  if (cdef->validator)
176  {
177  int rc = cdef->validator(cs, cdef, cdef->initial, err);
178 
179  if (CSR_RESULT(rc) != CSR_SUCCESS)
180  return (rc | CSR_INV_VALIDATOR);
181  }
182 
183  *(unsigned char *) var = cdef->initial;
184  return CSR_SUCCESS;
185 }
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36

◆ 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 216 of file long.c.

218 {
219  if (cdef->initial == (*(long *) var))
221 
222  if (cdef->validator)
223  {
224  int rc = cdef->validator(cs, cdef, cdef->initial, err);
225 
226  if (CSR_RESULT(rc) != CSR_SUCCESS)
227  return (rc | CSR_INV_VALIDATOR);
228  }
229 
230  *(long *) var = cdef->initial;
231  return CSR_SUCCESS;
232 }

◆ 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 238 of file mbtable.c.

240 {
241  struct MbTable *table = NULL;
242  const char *initial = (const char *) cdef->initial;
243 
244  struct MbTable *curtable = *(struct MbTable **) var;
245  const char *curval = curtable ? curtable->orig_str : NULL;
246 
247  int rc = CSR_SUCCESS;
248  if (!curtable)
249  rc |= CSR_SUC_EMPTY;
250 
251  if (mutt_str_equal(initial, curval))
252  return rc | CSR_SUC_NO_CHANGE;
253 
254  if (initial)
255  table = mbtable_parse(initial);
256 
257  if (cdef->validator)
258  {
259  rc = cdef->validator(cs, cdef, (intptr_t) table, err);
260 
261  if (CSR_RESULT(rc) != CSR_SUCCESS)
262  {
263  mbtable_destroy(cs, &table, cdef);
264  return rc | CSR_INV_VALIDATOR;
265  }
266  }
267 
268  if (!table)
269  rc |= CSR_SUC_EMPTY;
270 
271  mbtable_destroy(cs, var, cdef);
272 
273  *(struct MbTable **) var = table;
274  return rc;
275 }
static void mbtable_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an MbTable object - Implements ConfigSetType::destroy() -.
Definition: mbtable.c:95
struct MbTable * mbtable_parse(const char *s)
Parse a multibyte string into a table.
Definition: mbtable.c:49
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:715
Multibyte character table.
Definition: mbtable.h:34
char * orig_str
Original string used to generate this object.
Definition: mbtable.h:35
+ 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 236 of file number.c.

238 {
239  if (cdef->initial == (*(short *) var))
241 
242  if (cdef->validator)
243  {
244  int rc = cdef->validator(cs, cdef, cdef->initial, err);
245 
246  if (CSR_RESULT(rc) != CSR_SUCCESS)
247  return rc | CSR_INV_VALIDATOR;
248  }
249 
250  *(short *) var = cdef->initial;
251  return CSR_SUCCESS;
252 }

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

211 {
212  int rc = CSR_SUCCESS;
213 
214  const char *str = path_tidy((const char *) cdef->initial, cdef->type & DT_PATH_DIR);
215  if (!str)
216  rc |= CSR_SUC_EMPTY;
217 
218  if (mutt_str_equal(str, (*(char **) var)))
219  {
220  FREE(&str);
221  return rc | CSR_SUC_NO_CHANGE;
222  }
223 
224  if (cdef->validator)
225  {
226  rc = cdef->validator(cs, cdef, cdef->initial, err);
227 
228  if (CSR_RESULT(rc) != CSR_SUCCESS)
229  {
230  FREE(&str);
231  return rc | CSR_INV_VALIDATOR;
232  }
233  }
234 
235  path_destroy(cs, var, cdef);
236 
237  if (!str)
238  rc |= CSR_SUC_EMPTY;
239 
240  *(const char **) var = str;
241  return rc;
242 }
static char * path_tidy(const char *path, bool is_dir)
Tidy a path for storage.
Definition: path.c:56
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:73
#define FREE(x)
Definition: memory.h:40
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define DT_PATH_DIR
Path is a directory.
Definition: types.h:53

◆ 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 163 of file quad.c.

165 {
166  if (cdef->initial == (*(char *) var))
168 
169  if (cdef->validator)
170  {
171  int rc = cdef->validator(cs, cdef, cdef->initial, err);
172 
173  if (CSR_RESULT(rc) != CSR_SUCCESS)
174  return rc | CSR_INV_VALIDATOR;
175  }
176 
177  *(char *) var = cdef->initial;
178  return CSR_SUCCESS;
179 }

◆ 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 255 of file regex.c.

257 {
258  struct Regex *r = NULL;
259  const char *initial = (const char *) cdef->initial;
260 
261  struct Regex *currx = *(struct Regex **) var;
262  const char *curval = currx ? currx->pattern : NULL;
263 
264  int rc = CSR_SUCCESS;
265  if (!currx)
266  rc |= CSR_SUC_EMPTY;
267 
268  if (mutt_str_equal(initial, curval))
269  return rc | CSR_SUC_NO_CHANGE;
270 
271  if (initial)
272  {
273  r = regex_new(initial, cdef->type, err);
274  if (!r)
275  return CSR_ERR_CODE;
276  }
277 
278  if (cdef->validator)
279  {
280  rc = cdef->validator(cs, cdef, (intptr_t) r, err);
281 
282  if (CSR_RESULT(rc) != CSR_SUCCESS)
283  {
284  regex_destroy(cs, &r, cdef);
285  return rc | CSR_INV_VALIDATOR;
286  }
287  }
288 
289  if (!r)
290  rc |= CSR_SUC_EMPTY;
291 
292  regex_destroy(cs, var, cdef);
293 
294  *(struct Regex **) var = r;
295  return rc;
296 }
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:80
static void regex_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Regex object - Implements ConfigSetType::destroy() -.
Definition: regex.c:63
Cached regular expression.
Definition: regex3.h:90
char * pattern
printable version
Definition: regex3.h:91

◆ 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 267 of file slist.c.

269 {
270  if (!cs || !var || !cdef)
271  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
272 
273  struct Slist *list = NULL;
274  const char *initial = (const char *) cdef->initial;
275 
276  if (initial)
277  list = slist_parse(initial, cdef->type);
278 
279  int rc = CSR_SUCCESS;
280 
281  if (cdef->validator)
282  {
283  rc = cdef->validator(cs, cdef, (intptr_t) list, err);
284 
285  if (CSR_RESULT(rc) != CSR_SUCCESS)
286  {
287  slist_destroy(cs, &list, cdef);
288  return (rc | CSR_INV_VALIDATOR);
289  }
290  }
291 
292  if (!list)
293  rc |= CSR_SUC_EMPTY;
294 
295  slist_destroy(cs, var, cdef);
296 
297  *(struct Slist **) var = list;
298  return rc;
299 }
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:200
String list.
Definition: slist.h:47

◆ 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 192 of file sort.c.

194 {
195  if (cdef->initial == (*(short *) var))
197 
198  if (cdef->validator)
199  {
200  int rc = cdef->validator(cs, cdef, cdef->initial, err);
201 
202  if (CSR_RESULT(rc) != CSR_SUCCESS)
203  return rc | CSR_INV_VALIDATOR;
204  }
205 
206  *(short *) var = cdef->initial;
207  return CSR_SUCCESS;
208 }

◆ 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 220 of file string.c.

222 {
223  int rc = CSR_SUCCESS;
224 
225  const char *str = mutt_str_dup((const char *) cdef->initial);
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 (cdef->validator)
236  {
237  rc = cdef->validator(cs, cdef, cdef->initial, err);
238 
239  if (CSR_RESULT(rc) != CSR_SUCCESS)
240  {
241  FREE(&str);
242  return rc | CSR_INV_VALIDATOR;
243  }
244  }
245 
246  string_destroy(cs, var, cdef);
247 
248  if (!str)
249  rc |= CSR_SUC_EMPTY;
250 
251  *(const char **) var = str;
252  return rc;
253 }
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:181