-
Notifications
You must be signed in to change notification settings - Fork 0
/
core-rc.h
233 lines (183 loc) · 6.79 KB
/
core-rc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
///
/// @file core-rc.h @brief core runtime configuration functions
///
/// Copyright (c) 2009, 2011, 2021 by Lutz Sammer. All Rights Reserved.
///
/// Contributor(s):
///
/// License: AGPLv3
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License.
///
/// 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 Affero General Public License for more details.
///
/// $Id$
//////////////////////////////////////////////////////////////////////////////
/// @addtogroup CoreRc
/// @{
//////////////////////////////////////////////////////////////////////////////
// Declares
//////////////////////////////////////////////////////////////////////////////
/**
** Configuration main dictionary typedef.
*/
typedef union _config_ Config;
/**
** Configuration main dictionary structure.
*/
union _config_
{
void *Pointer; ///< pointer to array
};
/**
** Config object.
*/
typedef union _config_object_
{
void *Pointer; ///< pointer to data
} ConfigObject;
/**
** Config constant import.
**
** A table of index/value pairs to import into configuration.
**
** @todo passing string isn't the best
*/
typedef struct _config_import_
{
const char *Index; ///< index of import constant
const char *Value; ///< value of import constant
} ConfigImport;
/**
** Config string intern object.
*/
typedef struct _config_intern_object_
{
const char *String; ///< string to intern
ConfigObject *Object; ///< object of the interned string
} ConfigInternObject;
//////////////////////////////////////////////////////////////////////////////
// Inlines
//////////////////////////////////////////////////////////////////////////////
/**
** Get dictionary array of configuration.
**
** This function is currently a cast only.
**
** @param config configuration loaded
**
** @returns config object containing the config dictionary.
*/
static inline const ConfigObject *ConfigDict(const Config * config)
{
return (const ConfigObject *)config;
}
/**
** Create a new fixed integer object.
**
** @param integer 31/63 bit used signed integer
**
** @returns config object containing the integer value.
*/
static inline ConfigObject *ConfigNewInteger(ssize_t integer)
{
return (ConfigObject *) ((integer << 1) + 1);
}
/**
** Create a new fixed unsigned object.
*/
#define ConfigNewUnsigned ConfigNewInteger
//////////////////////////////////////////////////////////////////////////////
// Prototypes
//////////////////////////////////////////////////////////////////////////////
/// Create a new floating-point number object.
extern ConfigObject *ConfigNewDouble(double);
/// Create a new array object.
extern ConfigObject *ConfigNewArray(const Array *);
/// Create a new string object.
extern ConfigObject *ConfigNewString(const char *);
/// Create a new config object.
extern Config *ConfigNewConfig(const Array * array);
/// Check integer value.
extern int ConfigCheckInteger(const ConfigObject *, ssize_t *);
/// Check unsigned value.
extern int ConfigCheckUnsigned(const ConfigObject *, size_t *);
/// Check boolean value.
extern int ConfigCheckBoolean(const ConfigObject *);
/// Check double value.
extern int ConfigCheckDouble(const ConfigObject *, double *);
/// Check string value.
extern int ConfigCheckString(const ConfigObject *, const char **);
/// Check array value.
extern int ConfigCheckArray(const ConfigObject *, const ConfigObject **);
#ifdef USE_CORE_RC_GET_STRINGS
/// Get object value from config.
extern int ConfigStringsGetObject(const ConfigObject *, const ConfigObject **,
...);
/// Get integer value from config.
extern int ConfigStringsGetInteger(const ConfigObject *, ssize_t *, ...);
/// Get unsigned value from config.
extern int ConfigStringsGetUnsigned(const ConfigObject *, size_t *, ...);
/// Get boolean value from config.
extern int ConfigStringsGetBoolean(const ConfigObject *, ...);
/// Get double value from config.
extern int ConfigStringsGetDouble(const ConfigObject *, double *, ...);
/// Get string value from config.
extern int ConfigStringsGetString(const ConfigObject *, const char **, ...);
/// Get array value from config.
extern int ConfigStringsGetArray(const ConfigObject *, const ConfigObject **,
...);
#endif // USE_CORE_RC_GET_STRINGS
/// Get object value from config.
extern int ConfigGetObject(const ConfigObject *, const ConfigObject **, ...);
/// Get integer value from config.
extern int ConfigGetInteger(const ConfigObject *, ssize_t *, ...);
/// Get unsigned value from config.
extern int ConfigGetUnsigned(const ConfigObject *, size_t *, ...);
/// Get boolean value from config.
extern int ConfigGetBoolean(const ConfigObject *, ...);
/// Get double value from config.
extern int ConfigGetDouble(const ConfigObject *, double *, ...);
/// Get string value from config.
extern int ConfigGetString(const ConfigObject *, const char **, ...);
/// Get array value from config.
extern int ConfigGetArray(const ConfigObject *, const ConfigObject **, ...);
/// Get first value from config array.
extern const ConfigObject *ConfigArrayFirst(const ConfigObject *,
const ConfigObject **);
/// Get next value from config array.
extern const ConfigObject *ConfigArrayNext(const ConfigObject *,
const ConfigObject **);
/// Get first value with integer key from config array.
extern const ConfigObject *ConfigArrayFirstFixedKey(const ConfigObject *,
const ConfigObject **);
/// Get next value with integer key from config array.
extern const ConfigObject *ConfigArrayNextFixedKey(const ConfigObject *,
const ConfigObject **);
/// Print config object.
extern void ConfigPrint(const ConfigObject *, int, FILE *);
/// Define a configuration variable.
extern void ConfigDefine(Config *, const ConfigObject *, const ConfigObject *);
/// Read configuration from file stream.
extern Config *ConfigRead(int, const ConfigImport *, FILE *)
__attribute__((deprecated));
/// Read configuration from file name.
extern Config *ConfigReadFile(int, const ConfigImport *, const char *)
__attribute__((deprecated));
/// Read configuration from file stream.
extern Config *ConfigRead2(Config *, FILE *);
/// Read configuration from file name.
extern Config *ConfigReadFile2(Config *, const char *);
/// Write configuration to file stream.
extern int ConfigWrite(const Config *, FILE *);
/// Write configuration to file name.
extern int ConfigWriteFile(const Config *, const char *);
/// Release memory used by config.
extern void ConfigFreeMem(Config *);
/// @}