NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
helpers.c File Reference

Helper functions to get/set config values. More...

#include "config.h"
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "helpers.h"
#include "quad.h"
#include "set.h"
#include "subset.h"
#include "types.h"
+ Include dependency graph for helpers.c:

Go to the source code of this file.

Functions

bool cs_subset_bool (const struct ConfigSubset *sub, const char *name)
 Get a boolean config item by name.
 
unsigned char cs_subset_enum (const struct ConfigSubset *sub, const char *name)
 Get a enumeration config item by name.
 
long cs_subset_long (const struct ConfigSubset *sub, const char *name)
 Get a long config item by name.
 
struct MbTablecs_subset_mbtable (const struct ConfigSubset *sub, const char *name)
 Get a Multibyte table config item by name.
 
short cs_subset_number (const struct ConfigSubset *sub, const char *name)
 Get a number config item by name.
 
const char * cs_subset_path (const struct ConfigSubset *sub, const char *name)
 Get a path config item by name.
 
enum QuadOption cs_subset_quad (const struct ConfigSubset *sub, const char *name)
 Get a quad-value config item by name.
 
const struct Regexcs_subset_regex (const struct ConfigSubset *sub, const char *name)
 Get a regex config item by name.
 
const struct Slistcs_subset_slist (const struct ConfigSubset *sub, const char *name)
 Get a string-list config item by name.
 
short cs_subset_sort (const struct ConfigSubset *sub, const char *name)
 Get a sort config item by name.
 
const char * cs_subset_string (const struct ConfigSubset *sub, const char *name)
 Get a string config item by name.
 
bool config_he_set_initial (struct ConfigSet *cs, struct HashElem *he, const char *value)
 Set the initial value of a Config Option.
 
bool config_str_set_initial (struct ConfigSet *cs, const char *name, const char *value)
 Set the initial value of a Config Option.
 

Detailed Description

Helper functions to get/set config values.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file helpers.c.

Function Documentation

◆ cs_subset_bool()

bool cs_subset_bool ( const struct ConfigSubset sub,
const char *  name 
)

Get a boolean config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
boolBoolean value

Definition at line 47 of file helpers.c.

48{
49 ASSERT(sub && name);
50
51 struct HashElem *he = cs_subset_create_inheritance(sub, name);
52 ASSERT(he);
53
54#ifndef NDEBUG
55 struct HashElem *he_base = cs_get_base(he);
56 ASSERT(CONFIG_TYPE(he_base->type) == DT_BOOL);
57#endif
58
59 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
60 ASSERT(value != INT_MIN);
61
62 return (bool) value;
63}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
#define ASSERT(COND)
Definition: signal2.h:60
The item stored in a Hash Table.
Definition: hash.h:44
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
intptr_t cs_subset_he_native_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: subset.c:260
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:210
#define CONFIG_TYPE(t)
Definition: types.h:49
@ DT_BOOL
boolean option
Definition: types.h:32
+ Here is the call graph for this function:

◆ cs_subset_enum()

unsigned char cs_subset_enum ( const struct ConfigSubset sub,
const char *  name 
)

Get a enumeration config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
numEnumeration

Definition at line 71 of file helpers.c.

72{
73 ASSERT(sub && name);
74
75 struct HashElem *he = cs_subset_create_inheritance(sub, name);
76 ASSERT(he);
77
78#ifndef NDEBUG
79 struct HashElem *he_base = cs_get_base(he);
80 ASSERT(CONFIG_TYPE(he_base->type) == DT_ENUM);
81#endif
82
83 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
84 ASSERT(value != INT_MIN);
85
86 return (unsigned char) value;
87}
@ DT_ENUM
an enumeration
Definition: types.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_long()

long cs_subset_long ( const struct ConfigSubset sub,
const char *  name 
)

Get a long config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
numLong value

Definition at line 95 of file helpers.c.

96{
97 ASSERT(sub && name);
98
99 struct HashElem *he = cs_subset_create_inheritance(sub, name);
100 ASSERT(he);
101
102#ifndef NDEBUG
103 struct HashElem *he_base = cs_get_base(he);
104 ASSERT(CONFIG_TYPE(he_base->type) == DT_LONG);
105#endif
106
107 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
108 ASSERT(value != INT_MIN);
109
110 return (long) value;
111}
@ DT_LONG
a number (long)
Definition: types.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_mbtable()

struct MbTable * cs_subset_mbtable ( const struct ConfigSubset sub,
const char *  name 
)

Get a Multibyte table config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrMultibyte table

Definition at line 119 of file helpers.c.

120{
121 ASSERT(sub && name);
122
123 struct HashElem *he = cs_subset_create_inheritance(sub, name);
124 ASSERT(he);
125
126#ifndef NDEBUG
127 struct HashElem *he_base = cs_get_base(he);
128 ASSERT(CONFIG_TYPE(he_base->type) == DT_MBTABLE);
129#endif
130
131 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
132 ASSERT(value != INT_MIN);
133
134 return (struct MbTable *) value;
135}
Multibyte character table.
Definition: mbtable.h:36
@ DT_MBTABLE
multibyte char table
Definition: types.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_number()

short cs_subset_number ( const struct ConfigSubset sub,
const char *  name 
)

Get a number config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
numNumber

Definition at line 143 of file helpers.c.

144{
145 ASSERT(sub && name);
146
147 struct HashElem *he = cs_subset_create_inheritance(sub, name);
148 ASSERT(he);
149
150#ifndef NDEBUG
151 struct HashElem *he_base = cs_get_base(he);
152 ASSERT(CONFIG_TYPE(he_base->type) == DT_NUMBER);
153#endif
154
155 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
156 ASSERT(value != INT_MIN);
157
158 return (short) value;
159}
@ DT_NUMBER
a number
Definition: types.h:38
+ Here is the call graph for this function:

◆ cs_subset_path()

const char * cs_subset_path ( const struct ConfigSubset sub,
const char *  name 
)

Get a path config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrPath
NULLEmpty path

Definition at line 168 of file helpers.c.

169{
170 ASSERT(sub && name);
171
172 struct HashElem *he = cs_subset_create_inheritance(sub, name);
173 ASSERT(he);
174
175#ifndef NDEBUG
176 struct HashElem *he_base = cs_get_base(he);
177 ASSERT(CONFIG_TYPE(he_base->type) == DT_PATH);
178#endif
179
180 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
181 ASSERT(value != INT_MIN);
182
183 return (const char *) value;
184}
@ DT_PATH
a path to a file/directory
Definition: types.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_quad()

enum QuadOption cs_subset_quad ( const struct ConfigSubset sub,
const char *  name 
)

Get a quad-value config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
numQuad-value

Definition at line 192 of file helpers.c.

193{
194 ASSERT(sub && name);
195
196 struct HashElem *he = cs_subset_create_inheritance(sub, name);
197 ASSERT(he);
198
199#ifndef NDEBUG
200 struct HashElem *he_base = cs_get_base(he);
201 ASSERT(CONFIG_TYPE(he_base->type) == DT_QUAD);
202#endif
203
204 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
205 ASSERT(value != INT_MIN);
206
207 return (enum QuadOption) value;
208}
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_regex()

const struct Regex * cs_subset_regex ( const struct ConfigSubset sub,
const char *  name 
)

Get a regex config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrRegex
NULLEmpty regex

Definition at line 217 of file helpers.c.

218{
219 ASSERT(sub && name);
220
221 struct HashElem *he = cs_subset_create_inheritance(sub, name);
222 ASSERT(he);
223
224#ifndef NDEBUG
225 struct HashElem *he_base = cs_get_base(he);
226 ASSERT(CONFIG_TYPE(he_base->type) == DT_REGEX);
227#endif
228
229 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
230 ASSERT(value != INT_MIN);
231
232 return (const struct Regex *) value;
233}
Cached regular expression.
Definition: regex3.h:86
@ DT_REGEX
regular expressions
Definition: types.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_slist()

const struct Slist * cs_subset_slist ( const struct ConfigSubset sub,
const char *  name 
)

Get a string-list config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrString list
NULLEmpty string list

Definition at line 242 of file helpers.c.

243{
244 ASSERT(sub && name);
245
246 struct HashElem *he = cs_subset_create_inheritance(sub, name);
247 ASSERT(he);
248
249#ifndef NDEBUG
250 struct HashElem *he_base = cs_get_base(he);
251 ASSERT(CONFIG_TYPE(he_base->type) == DT_SLIST);
252#endif
253
254 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
255 ASSERT(value != INT_MIN);
256
257 return (const struct Slist *) value;
258}
String list.
Definition: slist.h:37
@ DT_SLIST
a list of strings
Definition: types.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_sort()

short cs_subset_sort ( const struct ConfigSubset sub,
const char *  name 
)

Get a sort config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
numSort

Definition at line 266 of file helpers.c.

267{
268 ASSERT(sub && name);
269
270 struct HashElem *he = cs_subset_create_inheritance(sub, name);
271 ASSERT(he);
272
273#ifndef NDEBUG
274 struct HashElem *he_base = cs_get_base(he);
275 ASSERT(CONFIG_TYPE(he_base->type) == DT_SORT);
276#endif
277
278 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
279 ASSERT(value != INT_MIN);
280
281 return (short) value;
282}
@ DT_SORT
sorting methods
Definition: types.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_string()

const char * cs_subset_string ( const struct ConfigSubset sub,
const char *  name 
)

Get a string config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrString
NULLEmpty string

Definition at line 291 of file helpers.c.

292{
293 ASSERT(sub && name);
294
295 struct HashElem *he = cs_subset_create_inheritance(sub, name);
296 ASSERT(he);
297
298#ifndef NDEBUG
299 struct HashElem *he_base = cs_get_base(he);
300 ASSERT(CONFIG_TYPE(he_base->type) == DT_STRING);
301#endif
302
303 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
304 ASSERT(value != INT_MIN);
305
306 return (const char *) value;
307}
@ DT_STRING
a string
Definition: types.h:44
+ Here is the call graph for this function:

◆ config_he_set_initial()

bool config_he_set_initial ( struct ConfigSet cs,
struct HashElem he,
const char *  value 
)

Set the initial value of a Config Option.

Definition at line 312 of file helpers.c.

313{
314 if (!cs || !he)
315 return false;
316
317 struct Buffer *err = buf_pool_get();
318
319 int rc = cs_he_initial_set(cs, he, value, err);
320 if (!buf_is_empty(err))
321 mutt_error("%s", buf_string(err)); // LCOV_EXCL_LINE
322
323 buf_pool_release(&err);
324 cs_he_reset(cs, he, NULL);
325
326 return (CSR_RESULT(rc) == CSR_SUCCESS);
327}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:399
int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:513
#define CSR_RESULT(x)
Definition: set.h:50
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:33
#define mutt_error(...)
Definition: logging2.h:93
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_str_set_initial()

bool config_str_set_initial ( struct ConfigSet cs,
const char *  name,
const char *  value 
)

Set the initial value of a Config Option.

Definition at line 332 of file helpers.c.

333{
334 if (!cs || !name)
335 return false;
336
337 struct HashElem *he = cs_get_elem(cs, name);
338 if (!he)
339 {
340 mutt_error(_("Unknown option %s"), name);
341 return false;
342 }
343
344 return config_he_set_initial(cs, he, value);
345}
bool config_he_set_initial(struct ConfigSet *cs, struct HashElem *he, const char *value)
Set the initial value of a Config Option.
Definition: helpers.c:312
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:175
#define _(a)
Definition: message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function: