NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
helpers.h File Reference

Helper functions to get config values. More...

#include <stdbool.h>
#include "quad.h"
+ Include dependency graph for helpers.h:
+ This graph shows which files directly or indirectly include this file:

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.
 
const struct Expandocs_subset_expando (const struct ConfigSubset *sub, const char *name)
 Get an Expando config item by name.
 

Detailed Description

Helper functions to get 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.h.

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 48 of file helpers.c.

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}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
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
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
#define DTYPE(t)
Definition: types.h:50
@ 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 72 of file helpers.c.

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}
@ 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 96 of file helpers.c.

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}
@ DT_LONG
a number (long)
Definition: types.h:36
+ 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 120 of file helpers.c.

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}
Multibyte character table.
Definition: mbtable.h:36
@ DT_MBTABLE
multibyte char table
Definition: types.h:37
+ 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 144 of file helpers.c.

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}
@ DT_NUMBER
a number
Definition: types.h:39
+ 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 169 of file helpers.c.

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}
@ DT_PATH
a path to a file/directory
Definition: types.h:40
+ 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 193 of file helpers.c.

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}
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:41
+ 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 218 of file helpers.c.

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}
Cached regular expression.
Definition: regex3.h:85
@ DT_REGEX
regular expressions
Definition: types.h:42
+ 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 243 of file helpers.c.

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}
String list.
Definition: slist.h:37
@ DT_SLIST
a list of strings
Definition: types.h:43
+ 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 267 of file helpers.c.

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}
@ DT_SORT
sorting methods
Definition: types.h:44
+ 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 292 of file helpers.c.

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}
@ DT_STRING
a string
Definition: types.h:45
+ Here is the call graph for this function:

◆ cs_subset_expando()

const struct Expando * cs_subset_expando ( const struct ConfigSubset sub,
const char *  name 
)

Get an Expando config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrExpando
NULLEmpty Expando

Definition at line 358 of file config_type.c.

359{
360 assert(sub && name);
361
362 struct HashElem *he = cs_subset_create_inheritance(sub, name);
363 assert(he);
364
365#ifndef NDEBUG
366 struct HashElem *he_base = cs_get_base(he);
367 assert(DTYPE(he_base->type) == DT_EXPANDO);
368#endif
369
370 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
371 assert(value != INT_MIN);
372
373 return (const struct Expando *) value;
374}
Parsed Expando trees.
Definition: expando.h:41
@ DT_EXPANDO
an expando
Definition: types.h:34
+ Here is the call graph for this function: