NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
helpers.c File Reference

Helper functions to get config values. More...

#include "config.h"
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "helpers.h"
#include "quad.h"
#include "set.h"
#include "subset.h"
#include "types.h"
+ Include dependency graph for helpers.c:

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...
 
unsigned char cs_subset_enum (const struct ConfigSubset *sub, const char *name)
 Get a enumeration config item by name. More...
 
long cs_subset_long (const struct ConfigSubset *sub, const char *name)
 Get a long config item by name. More...
 
struct MbTablecs_subset_mbtable (const struct ConfigSubset *sub, const char *name)
 Get a Multibyte table 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.c.

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

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 }
An email address.
Definition: address.h:35
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
const char * name
User-visible name.
Definition: set.h:65
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
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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 value

Definition at line 73 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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:

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

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
#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
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_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 121 of file helpers.c.

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 }
#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:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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_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 145 of file helpers.c.

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 }
#define DT_MBTABLE
multibyte char table
Definition: types.h:34
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
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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_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 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_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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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:

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

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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:250
#define DT_PATH
a path to a file/directory
Definition: types.h:36
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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_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 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_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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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
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
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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 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_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 }
#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:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
Cached regular expression.
Definition: regex3.h:89
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 268 of file helpers.c.

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 }
#define DT_SLIST
a list of strings
Definition: types.h:39
String list.
Definition: slist.h:46
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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 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_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 }
#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:200
#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:250
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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 317 of file helpers.c.

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 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
#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:250
#define DT_STRING
a string
Definition: types.h:41
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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: