NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
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 
49 const struct Address *cs_subset_address(const struct ConfigSubset *sub, const char *name)
50 {
51  assert(sub && name);
52 
53  struct HashElem *he = cs_subset_create_inheritance(sub, name);
54  assert(he);
55 
56 #ifndef NDEBUG
57  struct HashElem *he_base = cs_get_base(he);
58  assert(DTYPE(he_base->type) == DT_ADDRESS);
59 #endif
60 
61  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
62  assert(value != INT_MIN);
63 
64  return (const struct Address *) value;
65 }
66 
73 bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
74 {
75  assert(sub && name);
76 
77  struct HashElem *he = cs_subset_create_inheritance(sub, name);
78  assert(he);
79 
80 #ifndef NDEBUG
81  struct HashElem *he_base = cs_get_base(he);
82  assert(DTYPE(he_base->type) == DT_BOOL);
83 #endif
84 
85  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
86  assert(value != INT_MIN);
87 
88  return (bool) value;
89 }
90 
97 unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
98 {
99  assert(sub && name);
100 
101  struct HashElem *he = cs_subset_create_inheritance(sub, name);
102  assert(he);
103 
104 #ifndef NDEBUG
105  struct HashElem *he_base = cs_get_base(he);
106  assert(DTYPE(he_base->type) == DT_ENUM);
107 #endif
108 
109  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
110  assert(value != INT_MIN);
111 
112  return (unsigned char) value;
113 }
114 
121 long cs_subset_long(const struct ConfigSubset *sub, const char *name)
122 {
123  assert(sub && name);
124 
125  struct HashElem *he = cs_subset_create_inheritance(sub, name);
126  assert(he);
127 
128 #ifndef NDEBUG
129  struct HashElem *he_base = cs_get_base(he);
130  assert(DTYPE(he_base->type) == DT_LONG);
131 #endif
132 
133  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
134  assert(value != INT_MIN);
135 
136  return (long) value;
137 }
138 
145 struct MbTable *cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
146 {
147  assert(sub && name);
148 
149  struct HashElem *he = cs_subset_create_inheritance(sub, name);
150  assert(he);
151 
152 #ifndef NDEBUG
153  struct HashElem *he_base = cs_get_base(he);
154  assert(DTYPE(he_base->type) == DT_MBTABLE);
155 #endif
156 
157  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
158  assert(value != INT_MIN);
159 
160  return (struct MbTable *) value;
161 }
162 
169 short cs_subset_number(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_NUMBER);
179 #endif
180 
181  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
182  assert(value != INT_MIN);
183 
184  return (short) value;
185 }
186 
194 const char *cs_subset_path(const struct ConfigSubset *sub, const char *name)
195 {
196  assert(sub && name);
197 
198  struct HashElem *he = cs_subset_create_inheritance(sub, name);
199  assert(he);
200 
201 #ifndef NDEBUG
202  struct HashElem *he_base = cs_get_base(he);
203  assert(DTYPE(he_base->type) == DT_PATH);
204 #endif
205 
206  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
207  assert(value != INT_MIN);
208 
209  return (const char *) value;
210 }
211 
218 enum QuadOption cs_subset_quad(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_QUAD);
228 #endif
229 
230  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
231  assert(value != INT_MIN);
232 
233  return (enum QuadOption) value;
234 }
235 
243 const struct Regex *cs_subset_regex(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_REGEX);
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 Regex *) value;
259 }
260 
268 const struct Slist *cs_subset_slist(const struct ConfigSubset *sub, const char *name)
269 {
270  assert(sub && name);
271 
272  struct HashElem *he = cs_subset_create_inheritance(sub, name);
273  assert(he);
274 
275 #ifndef NDEBUG
276  struct HashElem *he_base = cs_get_base(he);
277  assert(DTYPE(he_base->type) == DT_SLIST);
278 #endif
279 
280  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
281  assert(value != INT_MIN);
282 
283  return (const struct Slist *) value;
284 }
285 
292 short cs_subset_sort(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_SORT);
302 #endif
303 
304  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
305  assert(value != INT_MIN);
306 
307  return (short) value;
308 }
309 
317 const char *cs_subset_string(const struct ConfigSubset *sub, const char *name)
318 {
319  assert(sub && name);
320 
321  struct HashElem *he = cs_subset_create_inheritance(sub, name);
322  assert(he);
323 
324 #ifndef NDEBUG
325  struct HashElem *he_base = cs_get_base(he);
326  assert(DTYPE(he_base->type) == DT_STRING);
327 #endif
328 
329  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
330  assert(value != INT_MIN);
331 
332  return (const char *) value;
333 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Constants for all the config types.
#define DT_LONG
a number (long)
Definition: types.h:33
A collection of config items.
#define DT_REGEX
regular expressions
Definition: types.h:38
#define DT_SORT
sorting methods
Definition: types.h:40
An email address.
Definition: address.h:35
#define DT_SLIST
a list of strings
Definition: types.h:39
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:49
#define DT_MBTABLE
multibyte char table
Definition: types.h:34
String list.
Definition: slist.h:46
multibyte character table
Definition: mbtable.h:33
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
QuadOption
Possible values for a quad-option.
Definition: quad.h:35
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:243
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:250
#define DT_ADDRESS
e-mail address
Definition: types.h:29
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
#define DT_STRING
a string
Definition: types.h:41
A set of inherited config items.
Definition: subset.h:46
#define DT_PATH
a path to a file/directory
Definition: types.h:36
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
Type representing a quad-option.
Subset of Config Items.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
struct MbTable * cs_subset_mbtable(const struct ConfigSubset *sub, const char *name)
Get a Multibyte table config item by name.
Definition: helpers.c:145
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:268
Cached regular expression.
Definition: regex3.h:89
#define DT_ENUM
an enumeration
Definition: types.h:31
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition: helpers.c:97
The item stored in a Hash Table.
Definition: hash.h:43
Helper functions to get config values.
Convenience wrapper for the library headers.
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition: helpers.c:121
#define DT_NUMBER
a number
Definition: types.h:35
#define DT_BOOL
boolean option
Definition: types.h:30