NeoMutt  2024-12-12-14-g7b49f7
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 47 of file helpers.c.

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}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
#define ASSERT(COND)
Definition: signal2.h:58
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 71 of file helpers.c.

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

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

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

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

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

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

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}
Cached regular expression.
Definition: regex3.h:86
@ 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 242 of file helpers.c.

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

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

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}
@ 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 357 of file config_type.c.

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