NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
helpers.h File Reference

Helper functions to get config values. More...

#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

const struct Addresscs_subset_address (const struct ConfigSubset *sub, const char *name)
 Get an Address config item by name. More...
 
bool cs_subset_bool (const struct ConfigSubset *sub, const char *name)
 Get a boolean config item by name. More...
 
long cs_subset_long (const struct ConfigSubset *sub, const char *name)
 Get a long config item by name. More...
 
short cs_subset_number (const struct ConfigSubset *sub, const char *name)
 Get a number config item by name. More...
 
const char * cs_subset_path (const struct ConfigSubset *sub, const char *name)
 Get a path config item by name. More...
 
enum QuadOption cs_subset_quad (const struct ConfigSubset *sub, const char *name)
 Get a quad-value config item by name. More...
 
const struct Regexcs_subset_regex (const struct ConfigSubset *sub, const char *name)
 Get a regex config item by name. More...
 
const struct Slistcs_subset_slist (const struct ConfigSubset *sub, const char *name)
 Get a string-list config item by name. More...
 
short cs_subset_sort (const struct ConfigSubset *sub, const char *name)
 Get a sort config item by name. More...
 
const char * cs_subset_string (const struct ConfigSubset *sub, const char *name)
 Get a string config item by name. More...
 

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_address()

const struct Address* cs_subset_address ( const struct ConfigSubset sub,
const char *  name 
)

Get an Address config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrAddress
NULLEmpty address

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  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 }
An email address.
Definition: address.h:34
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
#define DT_ADDRESS
e-mail address
Definition: types.h:29
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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

Definition at line 69 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define DT_BOOL
boolean option
Definition: types.h:30
+ 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 90 of file helpers.c.

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 }
#define DT_LONG
a number (long)
Definition: types.h:33
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call 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 111 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define DT_NUMBER
a number
Definition: types.h:35
+ Here is the call graph for this function:
+ Here is the caller 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 133 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
#define DT_PATH
a path to a file/directory
Definition: types.h:36
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 154 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#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:36
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
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 176 of file helpers.c.

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 }
#define DT_REGEX
regular expressions
Definition: types.h:38
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
Cached regular expression.
Definition: regex3.h:88
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 198 of file helpers.c.

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 }
#define DT_SLIST
a list of strings
Definition: types.h:39
String list.
Definition: slist.h:45
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.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 219 of file helpers.c.

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 }
#define DT_SORT
sorting methods
Definition: types.h:40
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 241 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
#define DTYPE(x)
Mask for the Data Type.
Definition: types.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:237
#define DT_STRING
a string
Definition: types.h:41
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function: