NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
string_set()

Set a config item by string. More...

+ Collaboration diagram for string_set():

Functions

static int address_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an Address by string - Implements ConfigSetType::string_set() -.
 
static int bool_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Bool by string - Implements ConfigSetType::string_set() -.
 
static int enum_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an Enumeration by string - Implements ConfigSetType::string_set() -.
 
static int long_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Long by string - Implements ConfigSetType::string_set() -.
 
static int mbtable_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an MbTable by string - Implements ConfigSetType::string_set() -.
 
static int myvar_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a MyVar by string - Implements ConfigSetType::string_set() -.
 
static int number_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Number by string - Implements ConfigSetType::string_set() -.
 
static int path_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Path by string - Implements ConfigSetType::string_set() -.
 
static int quad_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Quad-option by string - Implements ConfigSetType::string_set() -.
 
static int regex_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Regex by string - Implements ConfigSetType::string_set() -.
 
static int slist_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Slist by string - Implements ConfigSetType::string_set() -.
 
static int sort_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Sort by string - Implements ConfigSetType::string_set() -.
 
static int string_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a String by string - Implements ConfigSetType::string_set() -.
 
static int expando_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an Expando by string - Implements ConfigSetType::string_set() -.
 

Detailed Description

Set a config item by string.

Parameters
csConfig items
varVariable to set (may be NULL)
cdefVariable definition
valueValue to set (may be NULL)
errBuffer for error messages (may be NULL)
Return values
numResult, e.g. CSR_SUCCESS

If var is NULL, then the config item's initial value will be set.

Precondition
cs is not NULL
cdef is not NULL

Function Documentation

◆ address_string_set()

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

Set an Address by string - Implements ConfigSetType::string_set() -.

Definition at line 74 of file config_type.c.

76{
77 /* Store empty address as NULL */
78 if (value && (value[0] == '\0'))
79 value = NULL;
80
81 struct Address *addr = NULL;
82
83 int rc = CSR_SUCCESS;
84
85 if (!value && (cdef->type & D_NOT_EMPTY))
86 {
87 buf_printf(err, _("Option %s may not be empty"), cdef->name);
89 }
90
91 if (var && value)
92 {
93 // TODO - config can only store one
94 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
95 mutt_addrlist_parse(&al, value);
96 addr = mutt_addr_copy(TAILQ_FIRST(&al));
98 }
99
100 if (var)
101 {
102 if (cdef->validator)
103 {
104 rc = cdef->validator(cs, cdef, (intptr_t) addr, err);
105
106 if (CSR_RESULT(rc) != CSR_SUCCESS)
107 {
108 address_destroy(cs, &addr, cdef);
109 return rc | CSR_INV_VALIDATOR;
110 }
111 }
112
113 /* ordinary variable setting */
114 address_destroy(cs, var, cdef);
115
116 *(struct Address **) var = addr;
117
118 if (!addr)
119 rc |= CSR_SUC_EMPTY;
120 }
121 else
122 {
123 /* set the default/initial value */
124 if (cdef->type & D_INTERNAL_INITIAL_SET)
125 FREE(&cdef->initial);
126
128 cdef->initial = (intptr_t) mutt_str_dup(value);
129 }
130
131 return rc;
132}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:745
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:480
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_INV_VALIDATOR
Value was rejected by the validator.
Definition: set.h:48
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUC_EMPTY
Value is empty/unset.
Definition: set.h:42
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
static void address_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Address object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:62
#define FREE(x)
Definition: memory.h:55
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
#define TAILQ_FIRST(head)
Definition: queue.h:741
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:655
An email address.
Definition: address.h:36
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
intptr_t initial
Initial value.
Definition: set.h:67
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
#define D_INTERNAL_INITIAL_SET
Config item must have its initial value freed.
Definition: types.h:90
#define D_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:80
+ Here is the call graph for this function:

◆ bool_string_set()

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

Set a Bool by string - Implements ConfigSetType::string_set() -.

Definition at line 58 of file bool.c.

60{
61 if (!value)
62 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
63
64 int num = -1;
65 for (size_t i = 0; BoolValues[i]; i++)
66 {
67 if (mutt_istr_equal(BoolValues[i], value))
68 {
69 num = i % 2;
70 break;
71 }
72 }
73
74 if (num < 0)
75 {
76 buf_printf(err, _("Invalid boolean value: %s"), value);
78 }
79
80 if (var)
81 {
82 if (num == (*(bool *) var))
84
85 if (startup_only(cdef, err))
87
88 if (cdef->validator)
89 {
90 int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
91
92 if (CSR_RESULT(rc) != CSR_SUCCESS)
93 return rc | CSR_INV_VALIDATOR;
94 }
95
96 *(bool *) var = num;
97 }
98 else
99 {
100 cdef->initial = num;
101 }
102
103 return CSR_SUCCESS;
104}
const char * BoolValues[]
Valid strings for creating a Bool.
Definition: bool.c:51
static bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
Validator function for D_ON_STARTUP.
Definition: set.h:296
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:47
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
+ Here is the call graph for this function:

◆ enum_string_set()

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

Set an Enumeration by string - Implements ConfigSetType::string_set() -.

Definition at line 45 of file enum.c.

47{
48 if (!cs || !cdef || !value)
49 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
50
51 struct EnumDef *ed = (struct EnumDef *) cdef->data;
52 if (!ed || !ed->lookup)
53 return CSR_ERR_CODE;
54
55 int num = mutt_map_get_value(value, ed->lookup);
56 if (num < 0)
57 {
58 buf_printf(err, _("Invalid enum value: %s"), value);
60 }
61
62 if (var)
63 {
64 if (num == (*(unsigned char *) var))
66
67 if (startup_only(cdef, err))
69
70 if (cdef->validator)
71 {
72 int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
73
74 if (CSR_RESULT(rc) != CSR_SUCCESS)
75 return rc | CSR_INV_VALIDATOR;
76 }
77
78 *(unsigned char *) var = num;
79 }
80 else
81 {
82 cdef->initial = num;
83 }
84
85 return CSR_SUCCESS;
86}
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
intptr_t data
Extra variable data.
Definition: set.h:68
An enumeration.
Definition: enum.h:30
struct Mapping * lookup
Lookup table.
Definition: enum.h:33
+ Here is the call graph for this function:

◆ long_string_set()

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

Set a Long by string - Implements ConfigSetType::string_set() -.

Definition at line 45 of file long.c.

47{
48 if (!value || (value[0] == '\0'))
49 {
50 buf_printf(err, _("Option %s may not be empty"), cdef->name);
52 }
53
54 long num = 0;
55 if (!mutt_str_atol_full(value, &num))
56 {
57 buf_printf(err, _("Invalid long: %s"), value);
59 }
60
61 if ((num < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
62 {
63 buf_printf(err, _("Option %s may not be negative"), cdef->name);
65 }
66
67 if (var)
68 {
69 if (num == (*(long *) var))
71
72 if (startup_only(cdef, err))
74
75 if (cdef->validator)
76 {
77 int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
78
79 if (CSR_RESULT(rc) != CSR_SUCCESS)
80 return rc | CSR_INV_VALIDATOR;
81 }
82
83 *(long *) var = num;
84 }
85 else
86 {
87 cdef->initial = num;
88 }
89
90 return CSR_SUCCESS;
91}
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:101
+ Here is the call graph for this function:

◆ mbtable_string_set()

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

Set an MbTable by string - Implements ConfigSetType::string_set() -.

Definition at line 122 of file mbtable.c.

124{
125 /* Store empty mbtables as NULL */
126 if (value && (value[0] == '\0'))
127 value = NULL;
128
129 struct MbTable *table = NULL;
130
131 int rc = CSR_SUCCESS;
132
133 if (var)
134 {
135 struct MbTable *curval = *(struct MbTable **) var;
136 if (curval && mutt_str_equal(value, curval->orig_str))
138
139 if (startup_only(cdef, err))
141
142 table = mbtable_parse(value);
143
144 if (cdef->validator)
145 {
146 rc = cdef->validator(cs, cdef, (intptr_t) table, err);
147
148 if (CSR_RESULT(rc) != CSR_SUCCESS)
149 {
150 mbtable_free(&table);
151 return rc | CSR_INV_VALIDATOR;
152 }
153 }
154
155 mbtable_destroy(cs, var, cdef);
156
157 *(struct MbTable **) var = table;
158
159 if (!table)
160 rc |= CSR_SUC_EMPTY;
161 }
162 else
163 {
164 if (cdef->type & D_INTERNAL_INITIAL_SET)
165 FREE(&cdef->initial);
166
168 cdef->initial = (intptr_t) mutt_str_dup(value);
169 }
170
171 return rc;
172}
static void mbtable_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an MbTable object - Implements ConfigSetType::destroy() -.
Definition: mbtable.c:110
struct MbTable * mbtable_parse(const char *s)
Parse a multibyte string into a table.
Definition: mbtable.c:66
void mbtable_free(struct MbTable **ptr)
Free an MbTable object.
Definition: mbtable.c:308
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
Multibyte character table.
Definition: mbtable.h:36
char * orig_str
Original string used to generate this object.
Definition: mbtable.h:37
+ Here is the call graph for this function:

◆ myvar_string_set()

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

Set a MyVar by string - Implements ConfigSetType::string_set() -.

Definition at line 57 of file myvar.c.

59{
60 /* Store empty myvars as NULL */
61 if (value && (value[0] == '\0'))
62 value = NULL;
63
64 int rc = CSR_SUCCESS;
65
66 if (var)
67 {
68 if (mutt_str_equal(value, (*(char **) var)))
70
71 myvar_destroy(cs, var, cdef);
72
73 const char *str = mutt_str_dup(value);
74 if (!str)
75 rc |= CSR_SUC_EMPTY;
76
77 *(const char **) var = str;
78 }
79 else
80 {
81 if (cdef->type & D_INTERNAL_INITIAL_SET)
82 FREE(&cdef->initial);
83
85 cdef->initial = (intptr_t) mutt_str_dup(value);
86 }
87
88 return rc;
89}
static void myvar_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a MyVar - Implements ConfigSetType::destroy() -.
Definition: myvar.c:45
+ Here is the call graph for this function:

◆ number_string_set()

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

Set a Number by string - Implements ConfigSetType::string_set() -.

Definition at line 75 of file number.c.

77{
78 int num = 0;
79 if (value && *value && !mutt_str_atoi_full(value, &num))
80 {
81 buf_printf(err, _("Invalid number: %s"), value);
83 }
84
85 if ((num < SHRT_MIN) || (num > SHRT_MAX))
86 {
87 buf_printf(err, _("Number is too big: %s"), value);
89 }
90
91 if ((num < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
92 {
93 buf_printf(err, _("Option %s may not be negative"), cdef->name);
95 }
96
97 if (var)
98 {
99 if (num == native_get(var))
101
102 if (cdef->validator)
103 {
104 int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
105
106 if (CSR_RESULT(rc) != CSR_SUCCESS)
107 return rc | CSR_INV_VALIDATOR;
108 }
109
110 if (startup_only(cdef, err))
112
113 native_set(var, num);
114 }
115 else
116 {
117 cdef->initial = num;
118 }
119
120 return CSR_SUCCESS;
121}
static void native_set(void *var, intptr_t val)
Set an int into a Number config item.
Definition: number.c:58
static intptr_t native_get(void *var)
Get an int from a Number config item.
Definition: number.c:50
+ Here is the call graph for this function:

◆ path_string_set()

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

Set a Path by string - Implements ConfigSetType::string_set() -.

Definition at line 90 of file path.c.

92{
93 /* Store empty paths as NULL */
94 if (value && (value[0] == '\0'))
95 value = NULL;
96
97 if (!value && (cdef->type & D_NOT_EMPTY))
98 {
99 buf_printf(err, _("Option %s may not be empty"), cdef->name);
101 }
102
103 int rc = CSR_SUCCESS;
104
105 if (var)
106 {
107 if (mutt_str_equal(value, (*(char **) var)))
109
110 if (startup_only(cdef, err))
112
113 if (cdef->validator)
114 {
115 rc = cdef->validator(cs, cdef, (intptr_t) value, err);
116
117 if (CSR_RESULT(rc) != CSR_SUCCESS)
118 return rc | CSR_INV_VALIDATOR;
119 }
120
121 path_destroy(cs, var, cdef);
122
123 const char *str = path_tidy(value, cdef->type & D_PATH_DIR);
124 if (!str)
125 rc |= CSR_SUC_EMPTY;
126
127 *(const char **) var = str;
128 }
129 else
130 {
131 if (cdef->type & D_INTERNAL_INITIAL_SET)
132 FREE(&cdef->initial);
133
135 cdef->initial = (intptr_t) mutt_str_dup(value);
136 }
137
138 return rc;
139}
static char * path_tidy(const char *path, bool is_dir)
Tidy a path for storage.
Definition: path.c:58
static void path_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Path - Implements ConfigSetType::destroy() -.
Definition: path.c:78
#define D_PATH_DIR
Path is a directory.
Definition: types.h:103
+ Here is the call graph for this function:

◆ quad_string_set()

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

Set a Quad-option by string - Implements ConfigSetType::string_set() -.

Definition at line 60 of file quad.c.

62{
63 if (!value)
64 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
65
66 int num = -1;
67 for (size_t i = 0; QuadValues[i]; i++)
68 {
69 if (mutt_istr_equal(QuadValues[i], value))
70 {
71 num = i;
72 break;
73 }
74 }
75
76 if (num < 0)
77 {
78 buf_printf(err, _("Invalid quad value: %s"), value);
80 }
81
82 if (var)
83 {
84 if (num == (*(char *) var))
86
87 if (startup_only(cdef, err))
89
90 if (cdef->validator)
91 {
92 int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
93
94 if (CSR_RESULT(rc) != CSR_SUCCESS)
95 return rc | CSR_INV_VALIDATOR;
96 }
97
98 *(char *) var = num;
99 }
100 else
101 {
102 cdef->initial = num;
103 }
104
105 return CSR_SUCCESS;
106}
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:53
+ Here is the call graph for this function:

◆ regex_string_set()

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

Set a Regex by string - Implements ConfigSetType::string_set() -.

Definition at line 142 of file regex.c.

144{
145 /* Store empty regexes as NULL */
146 if (value && (value[0] == '\0'))
147 value = NULL;
148
149 struct Regex *r = NULL;
150
151 int rc = CSR_SUCCESS;
152
153 if (var)
154 {
155 struct Regex *curval = *(struct Regex **) var;
156 if (curval && mutt_str_equal(value, curval->pattern))
158
159 if (startup_only(cdef, err))
161
162 if (value)
163 {
164 r = regex_new(value, cdef->type, err);
165 if (!r)
166 return CSR_ERR_INVALID;
167 }
168
169 if (cdef->validator)
170 {
171 rc = cdef->validator(cs, cdef, (intptr_t) r, err);
172
173 if (CSR_RESULT(rc) != CSR_SUCCESS)
174 {
175 regex_free(&r);
176 return rc | CSR_INV_VALIDATOR;
177 }
178 }
179
180 regex_destroy(cs, var, cdef);
181
182 *(struct Regex **) var = r;
183
184 if (!r)
185 rc |= CSR_SUC_EMPTY;
186 }
187 else
188 {
189 if (cdef->type & D_INTERNAL_INITIAL_SET)
190 FREE(&cdef->initial);
191
193 cdef->initial = (intptr_t) mutt_str_dup(value);
194 }
195
196 return rc;
197}
struct Regex * regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:102
void regex_free(struct Regex **ptr)
Free a Regex object.
Definition: regex.c:68
static void regex_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a Regex object - Implements ConfigSetType::destroy() -.
Definition: regex.c:85
Cached regular expression.
Definition: regex3.h:86
char * pattern
printable version
Definition: regex3.h:87
+ Here is the call graph for this function:

◆ slist_string_set()

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

Set a Slist by string - Implements ConfigSetType::string_set() -.

Definition at line 62 of file slist.c.

64{
65 if (!cs || !cdef)
66 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
67
68 /* Store empty string list as NULL */
69 if (value && (value[0] == '\0'))
70 value = NULL;
71
72 struct Slist *list = NULL;
73
74 int rc = CSR_SUCCESS;
75
76 if (var)
77 {
78 list = slist_parse(value, cdef->type);
79
80 if (slist_equal(list, *(struct Slist **) var))
81 {
82 slist_free(&list);
84 }
85
86 if (startup_only(cdef, err))
87 {
88 slist_free(&list);
90 }
91
92 if (cdef->validator)
93 {
94 rc = cdef->validator(cs, cdef, (intptr_t) list, err);
95
96 if (CSR_RESULT(rc) != CSR_SUCCESS)
97 {
98 slist_free(&list);
99 return rc | CSR_INV_VALIDATOR;
100 }
101 }
102
103 slist_destroy(cs, var, cdef);
104
105 *(struct Slist **) var = list;
106
107 if (!list)
108 rc |= CSR_SUC_EMPTY;
109 }
110 else
111 {
112 if (cdef->type & D_INTERNAL_INITIAL_SET)
113 FREE(&cdef->initial);
114
116 cdef->initial = (intptr_t) mutt_str_dup(value);
117 }
118
119 return rc;
120}
static void slist_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Slist object - Implements ConfigSetType::destroy() -.
Definition: slist.c:47
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition: slist.c:175
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:122
bool slist_equal(const struct Slist *a, const struct Slist *b)
Compare two string lists.
Definition: slist.c:89
String list.
Definition: slist.h:37
+ Here is the call graph for this function:

◆ sort_string_set()

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

Set a Sort by string - Implements ConfigSetType::string_set() -.

Definition at line 49 of file sort.c.

51{
52 intptr_t id = -1;
53 uint16_t flags = 0;
54
55 if (!value || (value[0] == '\0'))
56 {
57 buf_printf(err, _("Option %s may not be empty"), cdef->name);
59 }
60
61 size_t plen = 0;
62
63 if (cdef->type & D_SORT_REVERSE)
64 {
66 if (plen != 0)
67 {
68 flags |= SORT_REVERSE;
69 value += plen;
70 }
71 }
72
73 if (cdef->type & D_SORT_LAST)
74 {
75 plen = mutt_str_startswith(value, PREFIX_LAST);
76 if (plen != 0)
77 {
78 flags |= SORT_LAST;
79 value += plen;
80 }
81 }
82
83 id = mutt_map_get_value(value, (struct Mapping *) cdef->data);
84
85 if (id < 0)
86 {
87 buf_printf(err, _("Invalid sort name: %s"), value);
89 }
90
91 id |= flags;
92
93 if (var)
94 {
95 if (id == (*(short *) var))
97
98 if (startup_only(cdef, err))
100
101 if (cdef->validator)
102 {
103 int rc = cdef->validator(cs, cdef, (intptr_t) id, err);
104
105 if (CSR_RESULT(rc) != CSR_SUCCESS)
106 return rc | CSR_INV_VALIDATOR;
107 }
108
109 *(short *) var = id;
110 }
111 else
112 {
113 cdef->initial = id;
114 }
115
116 return CSR_SUCCESS;
117}
#define PREFIX_REVERSE
Definition: sort.c:43
#define PREFIX_LAST
Definition: sort.c:44
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort.h:40
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort.h:39
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
Mapping between user-readable string and a constant.
Definition: mapping.h:33
#define D_SORT_LAST
Sort flag for -last prefix.
Definition: types.h:119
#define D_SORT_REVERSE
Sort flag for -reverse prefix.
Definition: types.h:120
+ Here is the call graph for this function:

◆ string_string_set()

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

Set a String by string - Implements ConfigSetType::string_set() -.

Definition at line 59 of file string.c.

61{
62 /* Store empty strings as NULL */
63 if (value && (value[0] == '\0'))
64 value = NULL;
65
66 if (!value && (cdef->type & D_NOT_EMPTY))
67 {
68 buf_printf(err, _("Option %s may not be empty"), cdef->name);
70 }
71
72 int rc = CSR_SUCCESS;
73
74 if (var)
75 {
76 if (mutt_str_equal(value, (*(char **) var)))
78
79 if (startup_only(cdef, err))
81
82 if (cdef->validator)
83 {
84 rc = cdef->validator(cs, cdef, (intptr_t) value, err);
85
86 if (CSR_RESULT(rc) != CSR_SUCCESS)
87 return rc | CSR_INV_VALIDATOR;
88 }
89
90 string_destroy(cs, var, cdef);
91
92 const char *str = mutt_str_dup(value);
93 if (!str)
94 rc |= CSR_SUC_EMPTY;
95
96 *(const char **) var = str;
97 }
98 else
99 {
100 if (cdef->type & D_INTERNAL_INITIAL_SET)
101 FREE(&cdef->initial);
102
104 cdef->initial = (intptr_t) mutt_str_dup(value);
105 }
106
107 return rc;
108}
static void string_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a String - Implements ConfigSetType::destroy() -.
Definition: string.c:47
+ Here is the call graph for this function:

◆ expando_string_set()

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

Set an Expando by string - Implements ConfigSetType::string_set() -.

Definition at line 60 of file config_type.c.

62{
63 /* Store empty string list as NULL */
64 if (value && (value[0] == '\0'))
65 value = NULL;
66
67 if (!value && (cdef->type & D_NOT_EMPTY))
68 {
69 buf_printf(err, _("Option %s may not be empty"), cdef->name);
71 }
72
73 int rc = CSR_SUCCESS;
74
75 if (var)
76 {
77 const struct ExpandoDefinition *defs = (const struct ExpandoDefinition *)
78 cdef->data;
79 struct Expando *exp = expando_parse(value, defs, err);
80 if (!exp && !buf_is_empty(err))
81 {
82 char opt[128] = { 0 };
83 // L10N: e.g. "Option index_format:" plus an error message
84 snprintf(opt, sizeof(opt), _("Option %s: "), cdef->name);
85 buf_insert(err, 0, opt);
86 return CSR_ERR_INVALID;
87 }
88
89 if (expando_equal(exp, *(struct Expando **) var))
90 {
91 expando_free(&exp);
93 }
94
95 if (startup_only(cdef, err))
96 {
97 expando_free(&exp);
99 }
100
101 if (cdef->validator)
102 {
103 rc = cdef->validator(cs, cdef, (intptr_t) exp, err);
104
105 if (CSR_RESULT(rc) != CSR_SUCCESS)
106 {
107 expando_free(&exp);
108 return rc | CSR_INV_VALIDATOR;
109 }
110 }
111
112 expando_destroy(cs, var, cdef);
113
114 *(struct Expando **) var = exp;
115
116 if (!exp)
117 rc |= CSR_SUC_EMPTY;
118 }
119 else
120 {
121 if (cdef->type & D_INTERNAL_INITIAL_SET)
122 FREE(&cdef->initial);
123
125 cdef->initial = (intptr_t) mutt_str_dup(value);
126 }
127
128 return rc;
129}
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
Definition of a format string.
Definition: definition.h:44
Parsed Expando trees.
Definition: expando.h:41
+ Here is the call graph for this function: