NeoMutt  2024-12-12-14-g7b49f7
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 <limits.h>
31#include <stdbool.h>
32#include <stdint.h>
33#include <stdlib.h>
34#include "mutt/lib.h"
35#include "helpers.h"
36#include "quad.h"
37#include "set.h"
38#include "subset.h"
39#include "types.h"
40
47bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
64
71unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
88
95long cs_subset_long(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
112
119struct MbTable *cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
136
143short cs_subset_number(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
160
168const char *cs_subset_path(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
185
192enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
209
217const struct Regex *cs_subset_regex(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
234
242const struct Slist *cs_subset_slist(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
259
266short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
283
291const char *cs_subset_string(const struct ConfigSubset *sub, const char *name)
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(DTYPE(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}
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:217
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:242
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:192
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:71
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition: helpers.c:95
struct MbTable * cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
Get a Multibyte table config item by name.
Definition: helpers.c:119
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
Shared code.
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
#define ASSERT(COND)
Definition: signal2.h:58
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:86
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:50
@ DT_NUMBER
a number
Definition: types.h:39
@ DT_SLIST
a list of strings
Definition: types.h:43
@ DT_BOOL
boolean option
Definition: types.h:32
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:41
@ DT_STRING
a string
Definition: types.h:45
@ DT_SORT
sorting methods
Definition: types.h:44
@ DT_MBTABLE
multibyte char table
Definition: types.h:37
@ DT_LONG
a number (long)
Definition: types.h:36
@ DT_ENUM
an enumeration
Definition: types.h:33
@ DT_REGEX
regular expressions
Definition: types.h:42
@ DT_PATH
a path to a file/directory
Definition: types.h:40