NeoMutt  2024-02-01-25-ga71e95
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
helpers.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <assert.h>
31#include <limits.h>
32#include <stdbool.h>
33#include <stdint.h>
34#include <stdlib.h>
35#include "mutt/lib.h"
36#include "helpers.h"
37#include "quad.h"
38#include "set.h"
39#include "subset.h"
40#include "types.h"
41
48bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
49{
50 assert(sub && name);
51
52 struct HashElem *he = cs_subset_create_inheritance(sub, name);
53 assert(he);
54
55#ifndef NDEBUG
56 struct HashElem *he_base = cs_get_base(he);
57 assert(DTYPE(he_base->type) == DT_BOOL);
58#endif
59
60 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
61 assert(value != INT_MIN);
62
63 return (bool) value;
64}
65
72unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
73{
74 assert(sub && name);
75
76 struct HashElem *he = cs_subset_create_inheritance(sub, name);
77 assert(he);
78
79#ifndef NDEBUG
80 struct HashElem *he_base = cs_get_base(he);
81 assert(DTYPE(he_base->type) == DT_ENUM);
82#endif
83
84 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
85 assert(value != INT_MIN);
86
87 return (unsigned char) value;
88}
89
96long cs_subset_long(const struct ConfigSubset *sub, const char *name)
97{
98 assert(sub && name);
99
100 struct HashElem *he = cs_subset_create_inheritance(sub, name);
101 assert(he);
102
103#ifndef NDEBUG
104 struct HashElem *he_base = cs_get_base(he);
105 assert(DTYPE(he_base->type) == DT_LONG);
106#endif
107
108 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
109 assert(value != INT_MIN);
110
111 return (long) value;
112}
113
120struct MbTable *cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
121{
122 assert(sub && name);
123
124 struct HashElem *he = cs_subset_create_inheritance(sub, name);
125 assert(he);
126
127#ifndef NDEBUG
128 struct HashElem *he_base = cs_get_base(he);
129 assert(DTYPE(he_base->type) == DT_MBTABLE);
130#endif
131
132 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
133 assert(value != INT_MIN);
134
135 return (struct MbTable *) value;
136}
137
144short cs_subset_number(const struct ConfigSubset *sub, const char *name)
145{
146 assert(sub && name);
147
148 struct HashElem *he = cs_subset_create_inheritance(sub, name);
149 assert(he);
150
151#ifndef NDEBUG
152 struct HashElem *he_base = cs_get_base(he);
153 assert(DTYPE(he_base->type) == DT_NUMBER);
154#endif
155
156 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
157 assert(value != INT_MIN);
158
159 return (short) value;
160}
161
169const char *cs_subset_path(const struct ConfigSubset *sub, const char *name)
170{
171 assert(sub && name);
172
173 struct HashElem *he = cs_subset_create_inheritance(sub, name);
174 assert(he);
175
176#ifndef NDEBUG
177 struct HashElem *he_base = cs_get_base(he);
178 assert(DTYPE(he_base->type) == DT_PATH);
179#endif
180
181 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
182 assert(value != INT_MIN);
183
184 return (const char *) value;
185}
186
193enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
194{
195 assert(sub && name);
196
197 struct HashElem *he = cs_subset_create_inheritance(sub, name);
198 assert(he);
199
200#ifndef NDEBUG
201 struct HashElem *he_base = cs_get_base(he);
202 assert(DTYPE(he_base->type) == DT_QUAD);
203#endif
204
205 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
206 assert(value != INT_MIN);
207
208 return (enum QuadOption) value;
209}
210
218const struct Regex *cs_subset_regex(const struct ConfigSubset *sub, const char *name)
219{
220 assert(sub && name);
221
222 struct HashElem *he = cs_subset_create_inheritance(sub, name);
223 assert(he);
224
225#ifndef NDEBUG
226 struct HashElem *he_base = cs_get_base(he);
227 assert(DTYPE(he_base->type) == DT_REGEX);
228#endif
229
230 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
231 assert(value != INT_MIN);
232
233 return (const struct Regex *) value;
234}
235
243const struct Slist *cs_subset_slist(const struct ConfigSubset *sub, const char *name)
244{
245 assert(sub && name);
246
247 struct HashElem *he = cs_subset_create_inheritance(sub, name);
248 assert(he);
249
250#ifndef NDEBUG
251 struct HashElem *he_base = cs_get_base(he);
252 assert(DTYPE(he_base->type) == DT_SLIST);
253#endif
254
255 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
256 assert(value != INT_MIN);
257
258 return (const struct Slist *) value;
259}
260
267short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
268{
269 assert(sub && name);
270
271 struct HashElem *he = cs_subset_create_inheritance(sub, name);
272 assert(he);
273
274#ifndef NDEBUG
275 struct HashElem *he_base = cs_get_base(he);
276 assert(DTYPE(he_base->type) == DT_SORT);
277#endif
278
279 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
280 assert(value != INT_MIN);
281
282 return (short) value;
283}
284
292const char *cs_subset_string(const struct ConfigSubset *sub, const char *name)
293{
294 assert(sub && name);
295
296 struct HashElem *he = cs_subset_create_inheritance(sub, name);
297 assert(he);
298
299#ifndef NDEBUG
300 struct HashElem *he_base = cs_get_base(he);
301 assert(DTYPE(he_base->type) == DT_STRING);
302#endif
303
304 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
305 assert(value != INT_MIN);
306
307 return (const char *) value;
308}
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:218
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:243
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:193
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:72
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:169
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition: helpers.c:96
struct MbTable * cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
Get a Multibyte table config item by name.
Definition: helpers.c:120
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
Helper functions to get config values.
Convenience wrapper for the library headers.
Parse the 'set' command.
Type representing a quad-option.
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
A set of inherited config items.
Definition: subset.h:47
The item stored in a Hash Table.
Definition: hash.h:43
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:44
Multibyte character table.
Definition: mbtable.h:36
Cached regular expression.
Definition: regex3.h:85
String list.
Definition: slist.h:37
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:258
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:208
Subset of Config Items.
Constants for all the config types.
#define DTYPE(t)
Definition: types.h:49
@ DT_NUMBER
a number
Definition: types.h:38
@ DT_SLIST
a list of strings
Definition: types.h:42
@ DT_BOOL
boolean option
Definition: types.h:32
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:40
@ DT_STRING
a string
Definition: types.h:44
@ DT_SORT
sorting methods
Definition: types.h:43
@ DT_MBTABLE
multibyte char table
Definition: types.h:36
@ DT_LONG
a number (long)
Definition: types.h:35
@ DT_ENUM
an enumeration
Definition: types.h:33
@ DT_REGEX
regular expressions
Definition: types.h:41
@ DT_PATH
a path to a file/directory
Definition: types.h:39