NeoMutt  2022-04-29-178-g3b62e6
Teaching an old dog new tricks
DOXYGEN
string_plus_equals()

Add to a config item by string. More...

+ Collaboration diagram for string_plus_equals():

Functions

static int long_string_plus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Add to a Long by string - Implements ConfigSetType::string_plus_equals() -. More...
 
static int number_string_plus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Add to a Number by string - Implements ConfigSetType::string_plus_equals() -. More...
 
static int slist_string_plus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Add to a Slist by string - Implements ConfigSetType::string_plus_equals() -. More...
 
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_plus_equals() -. More...
 
static int string_string_plus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Concat String to a string - Implements ConfigSetType::string_plus_equals() -. More...
 

Detailed Description

Add to a config item by 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

Contract

Function Documentation

◆ long_string_plus_equals()

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

Add to a Long by string - Implements ConfigSetType::string_plus_equals() -.

Definition at line 144 of file long.c.

147{
148 long num = 0;
149 if (!mutt_str_atol_full(value, &num))
150 {
151 mutt_buffer_printf(err, _("Invalid long: %s"), NONULL(value));
153 }
154
155 long result = *((long *) var) + num;
156 if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
157 {
158 mutt_buffer_printf(err, _("Option %s may not be negative"), cdef->name);
160 }
161
162 if (result == (*(long *) var))
164
165 if (cdef->validator)
166 {
167 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
168
169 if (CSR_RESULT(rc) != CSR_SUCCESS)
170 return rc | CSR_INV_VALIDATOR;
171 }
172
173 *(long *) var = result;
174 return CSR_SUCCESS;
175}
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:158
#define _(a)
Definition: message.h:28
#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 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 DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:47
+ Here is the call graph for this function:

◆ number_string_plus_equals()

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

Add to a Number by string - Implements ConfigSetType::string_plus_equals() -.

Definition at line 158 of file number.c.

161{
162 int num = 0;
163 if (!mutt_str_atoi_full(value, &num))
164 {
165 mutt_buffer_printf(err, _("Invalid number: %s"), NONULL(value));
167 }
168
169 int result = *((short *) var) + num;
170 if ((result < SHRT_MIN) || (result > SHRT_MAX))
171 {
172 mutt_buffer_printf(err, _("Number is too big: %s"), value);
174 }
175
176 if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
177 {
178 mutt_buffer_printf(err, _("Option %s may not be negative"), cdef->name);
180 }
181
182 if (cdef->validator)
183 {
184 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
185
186 if (CSR_RESULT(rc) != CSR_SUCCESS)
187 return rc | CSR_INV_VALIDATOR;
188 }
189
190 *(short *) var = result;
191 return CSR_SUCCESS;
192}
+ Here is the call graph for this function:

◆ slist_string_plus_equals()

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

Add to a Slist by string - Implements ConfigSetType::string_plus_equals() -.

Definition at line 186 of file slist.c.

189{
190 if (!cs || !cdef)
191 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
192
193 int rc = CSR_SUCCESS;
194
195 /* Store empty strings as NULL */
196 if (value && (value[0] == '\0'))
197 return rc |= CSR_SUC_NO_CHANGE;
198
199 struct Slist *orig = *(struct Slist **) var;
200 if (slist_is_member(orig, value))
201 return rc |= CSR_SUC_NO_CHANGE;
202
203 struct Slist *copy = slist_dup(orig);
204 if (!copy)
205 copy = slist_new(cdef->type & SLIST_SEP_MASK);
206
207 slist_add_string(copy, value);
208
209 if (cdef->validator)
210 {
211 rc = cdef->validator(cs, cdef, (intptr_t) copy, err);
212 if (CSR_RESULT(rc) != CSR_SUCCESS)
213 {
214 slist_free(&copy);
215 return (rc | CSR_INV_VALIDATOR);
216 }
217 }
218
219 slist_free(&orig);
220 *(struct Slist **) var = copy;
221
222 return rc;
223}
struct Slist * slist_add_string(struct Slist *list, const char *str)
Add a string to a list.
Definition: slist.c:80
bool slist_is_member(const struct Slist *list, const char *str)
Is a string a member of a list?
Definition: slist.c:177
struct Slist * slist_dup(const struct Slist *list)
Create a copy of an Slist object.
Definition: slist.c:120
struct Slist * slist_new(uint32_t flags)
Create a new string list.
Definition: slist.c:43
void slist_free(struct Slist **list)
Free an Slist object.
Definition: slist.c:162
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define SLIST_SEP_MASK
Definition: slist.h:37
String list.
Definition: slist.h:47
+ 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_plus_equals() -.

Definition at line 228 of file slist.c.

231{
232 if (!cs || !cdef)
233 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
234
235 int rc = CSR_SUCCESS;
236
237 /* Store empty strings as NULL */
238 if (value && (value[0] == '\0'))
239 return rc |= CSR_SUC_NO_CHANGE;
240
241 struct Slist *orig = *(struct Slist **) var;
242 if (!slist_is_member(orig, value))
243 return rc |= CSR_SUC_NO_CHANGE;
244
245 struct Slist *copy = slist_dup(orig);
246 slist_remove_string(copy, value);
247
248 if (cdef->validator)
249 {
250 rc = cdef->validator(cs, cdef, (intptr_t) copy, err);
251 if (CSR_RESULT(rc) != CSR_SUCCESS)
252 {
253 slist_free(&copy);
254 return (rc | CSR_INV_VALIDATOR);
255 }
256 }
257
258 slist_free(&orig);
259 *(struct Slist **) var = copy;
260
261 return rc;
262}
struct Slist * slist_remove_string(struct Slist *list, const char *str)
Remove a string from a list.
Definition: slist.c:258
+ Here is the call graph for this function:

◆ string_string_plus_equals()

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

Concat String to a string - Implements ConfigSetType::string_plus_equals() -.

Definition at line 182 of file string.c.

185{
186 /* Skip if the value is missing or empty string*/
187 if (!value || (value && (value[0] == '\0')))
189
190 int rc = CSR_SUCCESS;
191
192 char *str = NULL;
193 const char **var_str = (const char **) var;
194
195 if (*var_str)
196 mutt_str_asprintf(&str, "%s%s", *var_str, value);
197 else
198 str = mutt_str_dup(value);
199
200 if (cdef->validator)
201 {
202 rc = cdef->validator(cs, cdef, (intptr_t) str, err);
203
204 if (CSR_RESULT(rc) != CSR_SUCCESS)
205 {
206 FREE(&str);
207 return rc | CSR_INV_VALIDATOR;
208 }
209 }
210
211 string_destroy(cs, var, cdef);
212 *var_str = str;
213
214 return rc;
215}
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:45
#define FREE(x)
Definition: memory.h:43
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1008
+ Here is the call graph for this function: