NeoMutt  2021-02-05-89-gabe350
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 "subset.h"
39 #include "types.h"
40 
48 const struct Address *cs_subset_address(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  assert(DTYPE(he->type) == DT_ADDRESS);
56 
57  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
58  assert(value != INT_MIN);
59 
60  return (const struct Address *) value;
61 }
62 
69 bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
70 {
71  assert(sub && name);
72 
73  struct HashElem *he = cs_subset_create_inheritance(sub, name);
74  assert(he);
75 
76  assert(DTYPE(he->type) == DT_BOOL);
77 
78  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
79  assert(value != INT_MIN);
80 
81  return (bool) value;
82 }
83 
90 long cs_subset_long(const struct ConfigSubset *sub, const char *name)
91 {
92  assert(sub && name);
93 
94  struct HashElem *he = cs_subset_create_inheritance(sub, name);
95  assert(he);
96 
97  assert(DTYPE(he->type) == DT_LONG);
98 
99  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
100  assert(value != INT_MIN);
101 
102  return (long) value;
103 }
104 
111 short cs_subset_number(const struct ConfigSubset *sub, const char *name)
112 {
113  assert(sub && name);
114 
115  struct HashElem *he = cs_subset_create_inheritance(sub, name);
116  assert(he);
117 
118  assert(DTYPE(he->type) == DT_NUMBER);
119 
120  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
121  assert(value != INT_MIN);
122 
123  return (short) value;
124 }
125 
133 const char *cs_subset_path(const struct ConfigSubset *sub, const char *name)
134 {
135  assert(sub && name);
136 
137  struct HashElem *he = cs_subset_create_inheritance(sub, name);
138  assert(he);
139 
140  assert(DTYPE(he->type) == DT_PATH);
141 
142  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
143  assert(value != INT_MIN);
144 
145  return (const char *) value;
146 }
147 
154 enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
155 {
156  assert(sub && name);
157 
158  struct HashElem *he = cs_subset_create_inheritance(sub, name);
159  assert(he);
160 
161  assert(DTYPE(he->type) == DT_QUAD);
162 
163  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
164  assert(value != INT_MIN);
165 
166  return (enum QuadOption) value;
167 }
168 
176 const struct Regex *cs_subset_regex(const struct ConfigSubset *sub, const char *name)
177 {
178  assert(sub && name);
179 
180  struct HashElem *he = cs_subset_create_inheritance(sub, name);
181  assert(he);
182 
183  assert(DTYPE(he->type) == DT_REGEX);
184 
185  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
186  assert(value != INT_MIN);
187 
188  return (const struct Regex *) value;
189 }
190 
198 const struct Slist *cs_subset_slist(const struct ConfigSubset *sub, const char *name)
199 {
200  assert(sub && name);
201 
202  struct HashElem *he = cs_subset_create_inheritance(sub, name);
203  assert(he);
204 
205  assert(DTYPE(he->type) == DT_SLIST);
206 
207  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
208  assert(value != INT_MIN);
209 
210  return (const struct Slist *) value;
211 }
212 
219 short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
220 {
221  assert(sub && name);
222 
223  struct HashElem *he = cs_subset_create_inheritance(sub, name);
224  assert(he);
225 
226  assert(DTYPE(he->type) == DT_SORT);
227 
228  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
229  assert(value != INT_MIN);
230 
231  return (short) value;
232 }
233 
241 const char *cs_subset_string(const struct ConfigSubset *sub, const char *name)
242 {
243  assert(sub && name);
244 
245  struct HashElem *he = cs_subset_create_inheritance(sub, name);
246  assert(he);
247 
248  assert(DTYPE(he->type) == DT_STRING);
249 
250  intptr_t value = cs_subset_he_native_get(sub, he, NULL);
251  assert(value != INT_MIN);
252 
253  return (const char *) value;
254 }
DT_QUAD
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
DT_STRING
#define DT_STRING
a string
Definition: types.h:41
QuadOption
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
cs_subset_long
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition: helpers.c:90
types.h
DT_REGEX
#define DT_REGEX
regular expressions
Definition: types.h:38
DTYPE
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
cs_subset_bool
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:69
Regex
Cached regular expression.
Definition: regex3.h:89
cs_subset_address
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:48
cs_subset_create_inheritance
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
cs_subset_number
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:111
lib.h
DT_NUMBER
#define DT_NUMBER
a number
Definition: types.h:35
cs_subset_path
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:133
cs_subset_regex
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:176
DT_SORT
#define DT_SORT
sorting methods
Definition: types.h:40
DT_LONG
#define DT_LONG
a number (long)
Definition: types.h:33
DT_PATH
#define DT_PATH
a path to a file/directory
Definition: types.h:36
subset.h
helpers.h
HashElem::type
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
cs_subset_quad
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:154
DT_BOOL
#define DT_BOOL
boolean option
Definition: types.h:30
cs_subset_sort
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:219
cs_subset_string
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:241
HashElem
The item stored in a Hash Table.
Definition: hash.h:43
cs_subset_slist
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:198
DT_ADDRESS
#define DT_ADDRESS
e-mail address
Definition: types.h:29
ConfigSubset
A set of inherited config items.
Definition: subset.h:46
DT_SLIST
#define DT_SLIST
a list of strings
Definition: types.h:39
Address
An email address.
Definition: address.h:34
cs_subset_he_native_get
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:237
quad.h
Slist
String list.
Definition: slist.h:46