NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
string_minus_equals()

Remove from a config item as a string. More...

+ Collaboration diagram for string_minus_equals():

Functions

static int long_string_minus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Subtract from a Long by string - Implements ConfigSetType::string_minus_equals() -.
 
static int number_string_minus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Subtract from a Number by string - Implements ConfigSetType::string_minus_equals() -.
 
static int slist_string_minus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Remove from a Slist by string - Implements ConfigSetType::string_minus_equals() -.
 

Detailed Description

Remove from a config item as a string.

Parameters
csConfig items
varVariable to set
cdefVariable definition
valueValue to set
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

◆ long_string_minus_equals()

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

Subtract from a Long by string - Implements ConfigSetType::string_minus_equals() -.

Definition at line 191 of file long.c.

194{
195 long num = 0;
196 if (!mutt_str_atol_full(value, &num))
197 {
198 buf_printf(err, _("Invalid long: %s"), NONULL(value));
200 }
201
202 long result = *((long *) var) - num;
203 if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
204 {
205 buf_printf(err, _("Option %s may not be negative"), cdef->name);
207 }
208
209 if (result == (*(long *) var))
211
212 if (startup_only(cdef, err))
214
215 if (cdef->validator)
216 {
217 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
218
219 if (CSR_RESULT(rc) != CSR_SUCCESS)
220 return rc | CSR_INV_VALIDATOR;
221 }
222
223 *(long *) var = result;
224 return CSR_SUCCESS;
225}
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:296
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:47
#define CSR_INV_VALIDATOR
Value was rejected by the validator.
Definition: set.h:48
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define _(a)
Definition: message.h:28
#define NONULL(x)
Definition: string2.h:37
const char * name
User-visible name.
Definition: set.h:65
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:82
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:101
+ Here is the call graph for this function:

◆ number_string_minus_equals()

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

Subtract from a Number by string - Implements ConfigSetType::string_minus_equals() -.

Definition at line 231 of file number.c.

234{
235 int num = 0;
236 if (!mutt_str_atoi(value, &num))
237 {
238 buf_printf(err, _("Invalid number: %s"), NONULL(value));
240 }
241
242 int result = native_get(var) - num;
243 if ((result < SHRT_MIN) || (result > SHRT_MAX))
244 {
245 buf_printf(err, _("Number is too big: %s"), value);
247 }
248
249 if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
250 {
251 buf_printf(err, _("Option %s may not be negative"), cdef->name);
253 }
254
255 if (cdef->validator)
256 {
257 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
258
259 if (CSR_RESULT(rc) != CSR_SUCCESS)
260 return rc | CSR_INV_VALIDATOR;
261 }
262
263 if (startup_only(cdef, err))
265
266 native_set(var, result);
267 return CSR_SUCCESS;
268}
const char * mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: atoi.c:188
static void native_set(void *var, intptr_t val)
Set an int into a Number config item.
Definition: number.c:58
static intptr_t native_get(void *var)
Get an int from a Number config item.
Definition: number.c:50
+ Here is the call graph for this function:

◆ slist_string_minus_equals()

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

Remove from a Slist by string - Implements ConfigSetType::string_minus_equals() -.

Definition at line 253 of file slist.c.

256{
257 if (!cs || !cdef)
258 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
259
260 int rc = CSR_SUCCESS;
261
262 /* Store empty strings as NULL */
263 if (value && (value[0] == '\0'))
264 value = NULL;
265
266 if (!value)
267 return rc | CSR_SUC_NO_CHANGE;
268
269 if (startup_only(cdef, err))
271
272 struct Slist *orig = *(struct Slist **) var;
273 if (!slist_is_member(orig, value))
274 return rc | CSR_SUC_NO_CHANGE;
275
276 struct Slist *copy = slist_dup(orig);
277 slist_remove_string(copy, value);
278
279 if (cdef->validator)
280 {
281 rc = cdef->validator(cs, cdef, (intptr_t) copy, err);
282 if (CSR_RESULT(rc) != CSR_SUCCESS)
283 {
284 slist_free(&copy);
285 return rc | CSR_INV_VALIDATOR;
286 }
287 }
288
289 slist_free(&orig);
290 *(struct Slist **) var = copy;
291
292 return rc;
293}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
struct Slist * slist_remove_string(struct Slist *list, const char *str)
Remove a string from a list.
Definition: slist.c:233
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:122
bool slist_is_member(const struct Slist *list, const char *str)
Is a string a member of a list?
Definition: slist.c:152
struct Slist * slist_dup(const struct Slist *list)
Create a copy of an Slist object.
Definition: slist.c:106
String list.
Definition: slist.h:37
+ Here is the call graph for this function: