NeoMutt  2024-02-01-23-g345d7b
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() -.
 

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 75 of file config_type.c.

77{
78 struct Address *addr = NULL;
79
80 /* An empty address "" will be stored as NULL */
81 if (var && value && (value[0] != '\0'))
82 {
83 // TODO - config can only store one
84 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
85 mutt_addrlist_parse(&al, value);
86 addr = mutt_addr_copy(TAILQ_FIRST(&al));
88 }
89
90 int rc = CSR_SUCCESS;
91
92 if (var)
93 {
94 if (cdef->validator)
95 {
96 rc = cdef->validator(cs, cdef, (intptr_t) addr, err);
97
98 if (CSR_RESULT(rc) != CSR_SUCCESS)
99 {
100 address_destroy(cs, &addr, cdef);
101 return rc | CSR_INV_VALIDATOR;
102 }
103 }
104
105 /* ordinary variable setting */
106 address_destroy(cs, var, cdef);
107
108 *(struct Address **) var = addr;
109
110 if (!addr)
111 rc |= CSR_SUC_EMPTY;
112 }
113 else
114 {
115 /* set the default/initial value */
116 if (cdef->type & D_INTERNAL_INITIAL_SET)
117 FREE(&cdef->initial);
118
120 cdef->initial = (intptr_t) mutt_str_dup(value);
121 }
122
123 return rc;
124}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1464
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
#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:63
#define FREE(x)
Definition: memory.h:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
An email address.
Definition: address.h:36
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:87
+ 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
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:178
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_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:721
+ 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}
const char * name
User-visible name.
Definition: set.h:65
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:98
+ 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:709
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 47 of file number.c.

49{
50 if (!value || (value[0] == '\0'))
51 {
52 buf_printf(err, _("Option %s may not be empty"), cdef->name);
54 }
55
56 int num = 0;
57 if (!mutt_str_atoi_full(value, &num))
58 {
59 buf_printf(err, _("Invalid number: %s"), value);
61 }
62
63 if ((num < SHRT_MIN) || (num > SHRT_MAX))
64 {
65 buf_printf(err, _("Number is too big: %s"), value);
67 }
68
69 if ((num < 0) && (cdef->type & D_INTEGER_NOT_NEGATIVE))
70 {
71 buf_printf(err, _("Option %s may not be negative"), cdef->name);
73 }
74
75 if (var)
76 {
77 if (num == (*(short *) var))
79
80 if (cdef->validator)
81 {
82 int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
83
84 if (CSR_RESULT(rc) != CSR_SUCCESS)
85 return rc | CSR_INV_VALIDATOR;
86 }
87
88 if (startup_only(cdef, err))
90
91 *(short *) var = num;
92 }
93 else
94 {
95 cdef->initial = num;
96 }
97
98 return CSR_SUCCESS;
99}
+ 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:100
#define D_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:78
+ 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:85
char * pattern
printable version
Definition: regex3.h:86
+ 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:179
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:126
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
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:72
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
Mapping between user-readable string and a constant.
Definition: mapping.h:33
#define D_SORT_LAST
Sort flag for -last prefix.
Definition: types.h:116
#define D_SORT_REVERSE
Sort flag for -reverse prefix.
Definition: types.h:117
+ 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: