NeoMutt  2025-01-09-117-gace867
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 (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 (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 (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 (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 (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 (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
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_plus_equals()

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

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

◆ myvar_string_plus_equals()

static int myvar_string_plus_equals ( 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 151 of file myvar.c.

153{
154 /* Skip if the value is missing or empty string*/
155 if (!value || (value[0] == '\0'))
157
158 int rc = CSR_SUCCESS;
159
160 char *str = NULL;
161 const char **var_str = (const char **) var;
162
163 if (*var_str)
164 mutt_str_asprintf(&str, "%s%s", *var_str, value);
165 else
166 str = mutt_str_dup(value);
167
168 myvar_destroy(var, cdef);
169 *var_str = str;
170
171 return rc;
172}
static void myvar_destroy(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:254
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:804
+ Here is the call graph for this function:

◆ number_string_plus_equals()

static int number_string_plus_equals ( 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 190 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(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(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(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get an int from a Number config item - Implements ConfigSetType::native_get() -.
Definition: number.c:182
static void native_set(void *var, intptr_t val)
Set an int into a Number config item.
Definition: number.c:61
+ Here is the call graph for this function:

◆ slist_string_plus_equals()

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

190{
191 int rc = CSR_SUCCESS;
192
193 /* Store empty strings as NULL */
194 if (value && (value[0] == '\0'))
195 value = NULL;
196
197 if (!value)
198 return rc | CSR_SUC_NO_CHANGE;
199
200 if (startup_only(cdef, err))
202
203 struct Slist *orig = *(struct Slist **) var;
204 if (slist_is_member(orig, value))
205 return rc | CSR_SUC_NO_CHANGE;
206
207 struct Slist *copy = slist_dup(orig);
208 if (!copy)
209 copy = slist_new(cdef->type & D_SLIST_SEP_MASK);
210
211 slist_add_string(copy, value);
212
213 if (cdef->validator)
214 {
215 rc = cdef->validator(cdef, (intptr_t) copy, err);
216 if (CSR_RESULT(rc) != CSR_SUCCESS)
217 {
218 slist_free(&copy);
219 return rc | CSR_INV_VALIDATOR;
220 }
221 }
222
223 slist_free(&orig);
224 *(struct Slist **) var = copy;
225
226 return rc;
227}
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:124
struct Slist * slist_add_string(struct Slist *list, const char *str)
Add a string to a list.
Definition: slist.c:68
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
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:112
+ Here is the call graph for this function:

◆ string_string_plus_equals()

static int string_string_plus_equals ( 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 188 of file string.c.

190{
191 /* Skip if the value is missing or empty string*/
192 if (!value || (value[0] == '\0'))
194
195 if (value && startup_only(cdef, err))
197
198 int rc = CSR_SUCCESS;
199
200 char *str = NULL;
201 const char **var_str = (const char **) var;
202
203 if (*var_str)
204 mutt_str_asprintf(&str, "%s%s", *var_str, value);
205 else
206 str = mutt_str_dup(value);
207
208 if (cdef->validator)
209 {
210 rc = cdef->validator(cdef, (intptr_t) str, err);
211
212 if (CSR_RESULT(rc) != CSR_SUCCESS)
213 {
214 FREE(&str);
215 return rc | CSR_INV_VALIDATOR;
216 }
217 }
218
219 string_destroy(var, cdef);
220 *var_str = str;
221
222 return rc;
223}
static void string_destroy(void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:48
#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 ( 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 219 of file config_type.c.

221{
222 /* Skip if the value is missing or empty string*/
223 if (!value || (value[0] == '\0'))
225
226 if (value && startup_only(cdef, err))
228
229 int rc = CSR_SUCCESS;
230
231 char *str = NULL;
232 struct Expando *exp_old = *(struct Expando **) var;
233
234 if (exp_old && exp_old->string)
235 mutt_str_asprintf(&str, "%s%s", exp_old->string, value);
236 else
237 str = mutt_str_dup(value);
238
239 const struct ExpandoDefinition *defs = (const struct ExpandoDefinition *) cdef->data;
240 struct Expando *exp_new = expando_parse(str, defs, err);
241 FREE(&str);
242
243 if (!exp_new && !buf_is_empty(err))
244 {
245 char opt[128] = { 0 };
246 // L10N: e.g. "Option index_format:" plus an error message
247 snprintf(opt, sizeof(opt), _("Option %s: "), cdef->name);
248 buf_insert(err, 0, opt);
249 return CSR_ERR_INVALID;
250 }
251
252 if (expando_equal(exp_new, exp_old))
253 {
254 expando_free(&exp_new); // LCOV_EXCL_LINE
255 return CSR_SUCCESS | CSR_SUC_NO_CHANGE; // LCOV_EXCL_LINE
256 }
257
258 if (cdef->validator)
259 {
260 rc = cdef->validator(cdef, (intptr_t) exp_new, err);
261
262 if (CSR_RESULT(rc) != CSR_SUCCESS)
263 {
264 expando_free(&exp_new);
265 return rc | CSR_INV_VALIDATOR;
266 }
267 }
268
269 expando_destroy(var, cdef);
270 *(struct Expando **) var = exp_new;
271
272 return rc;
273}
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(void *var, const struct ConfigDef *cdef)
Destroy an Expando object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:49
intptr_t data
Extra variable data.
Definition: set.h:66
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: