NeoMutt  2025-01-09-104-g5de5ef
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 (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 (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 (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
varVariable to set
cdefVariable definition
valueValue to set
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

◆ long_string_minus_equals()

static int long_string_minus_equals ( 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 189 of file long.c.

191{
192 long num = 0;
193 if (!mutt_str_atol_full(value, &num))
194 {
195 buf_printf(err, _("Invalid long: %s"), NONULL(value));
197 }
198
199 long result = *((long *) var) - num;
200 if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
201 {
202 buf_printf(err, _("Option %s may not be negative"), cdef->name);
204 }
205
206 if (result == (*(long *) var))
208
209 if (startup_only(cdef, err))
211
212 if (cdef->validator)
213 {
214 int rc = cdef->validator(cdef, (intptr_t) result, err);
215
216 if (CSR_RESULT(rc) != CSR_SUCCESS)
217 return rc | CSR_INV_VALIDATOR;
218 }
219
220 *(long *) var = result;
221 return CSR_SUCCESS;
222}
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:293
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:36
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:45
#define CSR_INV_VALIDATOR
Value was rejected by the validator.
Definition: set.h:46
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:42
#define CSR_RESULT(x)
Definition: set.h:50
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:33
#define _(a)
Definition: message.h:28
#define NONULL(x)
Definition: string2.h:37
const char * name
User-visible name.
Definition: set.h:63
int(* validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:79
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:64
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:100
+ Here is the call graph for this function:

◆ number_string_minus_equals()

static int number_string_minus_equals ( 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.

233{
234 int num = 0;
235 if (!mutt_str_atoi(value, &num))
236 {
237 buf_printf(err, _("Invalid number: %s"), NONULL(value));
239 }
240
241 int result = native_get(var) - num;
242 if ((result < SHRT_MIN) || (result > SHRT_MAX))
243 {
244 buf_printf(err, _("Number is too big: %s"), value);
246 }
247
248 if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
249 {
250 buf_printf(err, _("Option %s may not be negative"), cdef->name);
252 }
253
254 if (cdef->validator)
255 {
256 int rc = cdef->validator(cdef, (intptr_t) result, 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 native_set(var, result);
266 return CSR_SUCCESS;
267}
const char * mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: atoi.c:192
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:

◆ slist_string_minus_equals()

static int slist_string_minus_equals ( 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 232 of file slist.c.

234{
235 int rc = CSR_SUCCESS;
236
237 /* Store empty strings as NULL */
238 if (value && (value[0] == '\0'))
239 value = NULL;
240
241 if (!value)
242 return rc | CSR_SUC_NO_CHANGE;
243
244 if (startup_only(cdef, err))
246
247 struct Slist *orig = *(struct Slist **) var;
248 if (!slist_is_member(orig, value))
249 return rc | CSR_SUC_NO_CHANGE;
250
251 struct Slist *copy = slist_dup(orig);
252 slist_remove_string(copy, value);
253
254 if (cdef->validator)
255 {
256 rc = cdef->validator(cdef, (intptr_t) copy, err);
257 if (CSR_RESULT(rc) != CSR_SUCCESS)
258 {
259 slist_free(&copy);
260 return rc | CSR_INV_VALIDATOR;
261 }
262 }
263
264 slist_free(&orig);
265 *(struct Slist **) var = copy;
266
267 return rc;
268}
struct Slist * slist_remove_string(struct Slist *list, const char *str)
Remove a string from a list.
Definition: slist.c:235
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:124
bool slist_is_member(const struct Slist *list, const char *str)
Is a string a member of a list?
Definition: slist.c:154
struct Slist * slist_dup(const struct Slist *list)
Create a copy of an Slist object.
Definition: slist.c:108
String list.
Definition: slist.h:37
+ Here is the call graph for this function: