NeoMutt  2023-11-03-85-g512e01
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() -.
 

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 150 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 & DT_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(cs, 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:173
static bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
Validator function for DT_ON_STARTUP.
Definition: set.h:301
#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 DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:51
+ 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 149 of file myvar.c.

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

167{
168 int num = 0;
169 if (!mutt_str_atoi_full(value, &num))
170 {
171 buf_printf(err, _("Invalid number: %s"), NONULL(value));
173 }
174
175 int result = *((short *) var) + num;
176 if ((result < SHRT_MIN) || (result > SHRT_MAX))
177 {
178 buf_printf(err, _("Number is too big: %s"), value);
180 }
181
182 if ((result < 0) && (cdef->type & DT_NOT_NEGATIVE))
183 {
184 buf_printf(err, _("Option %s may not be negative"), cdef->name);
186 }
187
188 if (cdef->validator)
189 {
190 int rc = cdef->validator(cs, cdef, (intptr_t) result, err);
191
192 if (CSR_RESULT(rc) != CSR_SUCCESS)
193 return rc | CSR_INV_VALIDATOR;
194 }
195
196 if (startup_only(cdef, err))
198
199 *(short *) var = result;
200 return CSR_SUCCESS;
201}
+ 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 204 of file slist.c.

207{
208 if (!cs || !cdef)
209 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
210
211 int rc = CSR_SUCCESS;
212
213 /* Store empty strings as NULL */
214 if (value && (value[0] == '\0'))
215 value = NULL;
216
217 if (!value)
218 return rc | CSR_SUC_NO_CHANGE;
219
220 if (startup_only(cdef, err))
222
223 struct Slist *orig = *(struct Slist **) var;
224 if (slist_is_member(orig, value))
225 return rc | CSR_SUC_NO_CHANGE;
226
227 struct Slist *copy = slist_dup(orig);
228 if (!copy)
229 copy = slist_new(cdef->type & SLIST_SEP_MASK);
230
231 slist_add_string(copy, value);
232
233 if (cdef->validator)
234 {
235 rc = cdef->validator(cs, cdef, (intptr_t) copy, err);
236 if (CSR_RESULT(rc) != CSR_SUCCESS)
237 {
238 slist_free(&copy);
239 return rc | CSR_INV_VALIDATOR;
240 }
241 }
242
243 slist_free(&orig);
244 *(struct Slist **) var = copy;
245
246 return rc;
247}
#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:162
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:192
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
#define SLIST_SEP_MASK
Definition: slist.h:37
String list.
Definition: slist.h:47
+ 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 188 of file string.c.

191{
192 /* Skip if the value is missing or empty string*/
193 if (!value || (value[0] == '\0'))
195
196 if (value && startup_only(cdef, err))
198
199 int rc = CSR_SUCCESS;
200
201 char *str = NULL;
202 const char **var_str = (const char **) var;
203
204 if (*var_str)
205 mutt_str_asprintf(&str, "%s%s", *var_str, value);
206 else
207 str = mutt_str_dup(value);
208
209 if (cdef->validator)
210 {
211 rc = cdef->validator(cs, cdef, (intptr_t) str, err);
212
213 if (CSR_RESULT(rc) != CSR_SUCCESS)
214 {
215 FREE(&str);
216 return rc | CSR_INV_VALIDATOR;
217 }
218 }
219
220 string_destroy(cs, var, cdef);
221 *var_str = str;
222
223 return rc;
224}
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:45
+ Here is the call graph for this function: