NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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() -.
 
static int myvar_string_plus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Add to a MyVar by string - Implements ConfigSetType::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)
 Add to a Number by string - Implements ConfigSetType::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)
 Add to a Slist by string - Implements ConfigSetType::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)
 Add to a String by string - Implements ConfigSetType::string_plus_equals() -.
 
static int expando_string_plus_equals (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Add to an Expando by string - Implements ConfigSetType::string_plus_equals() -.
 

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
Precondition
cs is not NULL
var is not NULL
cdef is not NULL

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

155{
156 long num = 0;
157 if (!mutt_str_atol_full(value, &num))
158 {
159 buf_printf(err, _("Invalid long: %s"), NONULL(value));
161 }
162
163 long result = *((long *) var) + num;
164 if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
165 {
166 buf_printf(err, _("Option %s may not be negative"), cdef->name);
168 }
169
170 if (result == (*(long *) var))
172
173 if (startup_only(cdef, err))
175
176 if (cdef->validator)
177 {
178 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
179
180 if (CSR_RESULT(rc) != CSR_SUCCESS)
181 return rc | CSR_INV_VALIDATOR;
182 }
183
184 *(long *) var = result;
185 return CSR_SUCCESS;
186}
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:

◆ myvar_string_plus_equals()

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

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

Definition at line 153 of file myvar.c.

156{
157 /* Skip if the value is missing or empty string*/
158 if (!value || (value[0] == '\0'))
160
161 int rc = CSR_SUCCESS;
162
163 char *str = NULL;
164 const char **var_str = (const char **) var;
165
166 if (*var_str)
167 mutt_str_asprintf(&str, "%s%s", *var_str, value);
168 else
169 str = mutt_str_dup(value);
170
171 myvar_destroy(cs, var, cdef);
172 *var_str = str;
173
174 return rc;
175}
static void myvar_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a MyVar - Implements ConfigSetType::destroy() -.
Definition: myvar.c:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:803
+ 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 189 of file number.c.

192{
193 int num = 0;
194 if (!mutt_str_atoi_full(value, &num))
195 {
196 buf_printf(err, _("Invalid number: %s"), NONULL(value));
198 }
199
200 int result = number_native_get(NULL, var, NULL, NULL) + num;
201 if ((result < SHRT_MIN) || (result > SHRT_MAX))
202 {
203 buf_printf(err, _("Number is too big: %s"), value);
205 }
206
207 if ((result < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
208 {
209 buf_printf(err, _("Option %s may not be negative"), cdef->name);
211 }
212
213 if (cdef->validator)
214 {
215 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
216
217 if (CSR_RESULT(rc) != CSR_SUCCESS)
218 return rc | CSR_INV_VALIDATOR;
219 }
220
221 if (startup_only(cdef, err))
223
224 native_set(var, result);
225 return CSR_SUCCESS;
226}
static intptr_t number_native_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get an int from a Number config item - Implements ConfigSetType::native_get() -.
Definition: number.c:180
static void native_set(void *var, intptr_t val)
Set an int into a Number config item.
Definition: number.c:58
+ 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 205 of file slist.c.

208{
209 if (!cs || !cdef)
210 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
211
212 int rc = CSR_SUCCESS;
213
214 /* Store empty strings as NULL */
215 if (value && (value[0] == '\0'))
216 value = NULL;
217
218 if (!value)
219 return rc | CSR_SUC_NO_CHANGE;
220
221 if (startup_only(cdef, err))
223
224 struct Slist *orig = *(struct Slist **) var;
225 if (slist_is_member(orig, value))
226 return rc | CSR_SUC_NO_CHANGE;
227
228 struct Slist *copy = slist_dup(orig);
229 if (!copy)
230 copy = slist_new(cdef->type & D_SLIST_SEP_MASK);
231
232 slist_add_string(copy, value);
233
234 if (cdef->validator)
235 {
236 rc = cdef->validator(cs, cdef, (intptr_t) copy, err);
237 if (CSR_RESULT(rc) != CSR_SUCCESS)
238 {
239 slist_free(&copy);
240 return rc | CSR_INV_VALIDATOR;
241 }
242 }
243
244 slist_free(&orig);
245 *(struct Slist **) var = copy;
246
247 return rc;
248}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:122
struct Slist * slist_add_string(struct Slist *list, const char *str)
Add a string to a list.
Definition: slist.c:66
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
struct Slist * slist_new(uint32_t flags)
Create a new string list.
Definition: slist.c:51
String list.
Definition: slist.h:37
#define D_SLIST_SEP_MASK
Definition: types.h:113
+ 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

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

Definition at line 190 of file string.c.

193{
194 /* Skip if the value is missing or empty string*/
195 if (!value || (value[0] == '\0'))
197
198 if (value && startup_only(cdef, err))
200
201 int rc = CSR_SUCCESS;
202
203 char *str = NULL;
204 const char **var_str = (const char **) var;
205
206 if (*var_str)
207 mutt_str_asprintf(&str, "%s%s", *var_str, value);
208 else
209 str = mutt_str_dup(value);
210
211 if (cdef->validator)
212 {
213 rc = cdef->validator(cs, cdef, (intptr_t) str, err);
214
215 if (CSR_RESULT(rc) != CSR_SUCCESS)
216 {
217 FREE(&str);
218 return rc | CSR_INV_VALIDATOR;
219 }
220 }
221
222 string_destroy(cs, var, cdef);
223 *var_str = str;
224
225 return rc;
226}
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:47
#define FREE(x)
Definition: memory.h:55
+ Here is the call graph for this function:

◆ expando_string_plus_equals()

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

Add to an Expando by string - Implements ConfigSetType::string_plus_equals() -.

Definition at line 224 of file config_type.c.

227{
228 /* Skip if the value is missing or empty string*/
229 if (!value || (value[0] == '\0'))
231
232 if (value && startup_only(cdef, err))
234
235 int rc = CSR_SUCCESS;
236
237 char *str = NULL;
238 struct Expando *exp_old = *(struct Expando **) var;
239
240 if (exp_old && exp_old->string)
241 mutt_str_asprintf(&str, "%s%s", exp_old->string, value);
242 else
243 str = mutt_str_dup(value);
244
245 const struct ExpandoDefinition *defs = (const struct ExpandoDefinition *) cdef->data;
246 struct Expando *exp_new = expando_parse(str, defs, err);
247 FREE(&str);
248
249 if (!exp_new && !buf_is_empty(err))
250 {
251 char opt[128] = { 0 };
252 // L10N: e.g. "Option index_format:" plus an error message
253 snprintf(opt, sizeof(opt), _("Option %s: "), cdef->name);
254 buf_insert(err, 0, opt);
255 return CSR_ERR_INVALID;
256 }
257
258 if (expando_equal(exp_new, exp_old))
259 {
260 expando_free(&exp_new); // LCOV_EXCL_LINE
261 return CSR_SUCCESS | CSR_SUC_NO_CHANGE; // LCOV_EXCL_LINE
262 }
263
264 if (cdef->validator)
265 {
266 rc = cdef->validator(cs, cdef, (intptr_t) exp_new, err);
267
268 if (CSR_RESULT(rc) != CSR_SUCCESS)
269 {
270 expando_free(&exp_new);
271 return rc | CSR_INV_VALIDATOR;
272 }
273 }
274
275 expando_destroy(cs, var, cdef);
276 *(struct Expando **) var = exp_new;
277
278 return rc;
279}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
size_t buf_insert(struct Buffer *buf, size_t offset, const char *s)
Add a string in the middle of a buffer.
Definition: buffer.c:256
struct Expando * expando_parse(const char *str, const struct ExpandoDefinition *defs, struct Buffer *err)
Parse an Expando string.
Definition: expando.c:81
void expando_free(struct Expando **ptr)
Free an Expando object.
Definition: expando.c:61
bool expando_equal(const struct Expando *a, const struct Expando *b)
Compare two expandos.
Definition: expando.c:137
static void expando_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Expando object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:48
intptr_t data
Extra variable data.
Definition: set.h:68
Definition of a format string.
Definition: definition.h:44
Parsed Expando trees.
Definition: expando.h:41
const char * string
Pointer to the parsed string.
Definition: expando.h:42
+ Here is the call graph for this function: