Wed, 31 Dec 2025 16:40:12 +0100
update ucx to version 4.0
| 440 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | /** | |
| 29 | * @file properties.h | |
| 30 | * @brief Interface for parsing data from properties files. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
| 34 | */ | |
| 35 | ||
| 36 | #ifndef UCX_PROPERTIES_H | |
| 37 | #define UCX_PROPERTIES_H | |
| 38 | ||
| 39 | #include "common.h" | |
| 40 | #include "string.h" | |
| 41 | #include "map.h" | |
| 42 | #include "buffer.h" | |
| 43 | ||
| 44 | /** | |
| 45 | * Configures the expected characters for the properties parser. | |
| 46 | */ | |
| 47 | struct cx_properties_config_s { | |
| 48 | /** | |
| 49 | * The key/value delimiter that shall be used. | |
| 50 | * This is '=' by default. | |
| 51 | */ | |
| 52 | char delimiter; | |
| 53 | ||
| 54 | /** | |
| 55 | * The first comment character. | |
| 56 | * This is '#' by default. | |
| 57 | */ | |
| 58 | char comment1; | |
| 59 | ||
| 60 | /** | |
| 61 | * The second comment character. | |
| 62 | * This is not set by default. | |
| 63 | */ | |
| 64 | char comment2; | |
| 65 | ||
| 66 | /** | |
| 67 | * The third comment character. | |
| 68 | * This is not set by default. | |
| 69 | */ | |
| 70 | char comment3; | |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
71 | |
| 1016 | 72 | /** |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
73 | * The character, when appearing at the end of a line, continues that line. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
74 | * This is '\' by default. |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
75 | */ |
|
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
76 | char continuation; |
| 440 | 77 | }; |
| 78 | ||
| 79 | /** | |
| 80 | * Typedef for the properties config. | |
| 81 | */ | |
| 82 | typedef struct cx_properties_config_s CxPropertiesConfig; | |
| 83 | ||
| 84 | /** | |
| 85 | * Default properties configuration. | |
| 86 | */ | |
| 870 | 87 | CX_EXPORT extern const CxPropertiesConfig cx_properties_config_default; |
| 440 | 88 | |
| 89 | /** | |
| 90 | * Status codes for the properties interface. | |
| 91 | */ | |
| 92 | enum cx_properties_status { | |
| 93 | /** | |
| 94 | * Everything is fine. | |
| 95 | */ | |
| 96 | CX_PROPERTIES_NO_ERROR, | |
| 97 | /** | |
| 98 | * The input buffer does not contain more data. | |
| 99 | */ | |
| 100 | CX_PROPERTIES_NO_DATA, | |
| 101 | /** | |
| 102 | * The input ends unexpectedly. | |
| 103 | * | |
| 104 | * This either happens when the last line does not terminate with a line | |
| 105 | * break, or when the input ends with a parsed key but no value. | |
| 106 | */ | |
| 107 | CX_PROPERTIES_INCOMPLETE_DATA, | |
| 108 | /** | |
| 109 | * Not used as a status and never returned by any function. | |
| 110 | * | |
| 111 | * You can use this enumerator to check for all "good" status results | |
| 112 | * by checking if the status is less than @c CX_PROPERTIES_OK. | |
| 113 | * | |
| 845 | 114 | * A "good" status means that you can refill data and continue parsing. |
| 440 | 115 | */ |
| 116 | CX_PROPERTIES_OK, | |
| 117 | /** | |
| 118 | * Input buffer is @c NULL. | |
| 119 | */ | |
| 120 | CX_PROPERTIES_NULL_INPUT, | |
| 121 | /** | |
| 845 | 122 | * The line contains a delimiter but no key. |
| 440 | 123 | */ |
| 124 | CX_PROPERTIES_INVALID_EMPTY_KEY, | |
| 125 | /** | |
| 845 | 126 | * The line contains data but no delimiter. |
| 440 | 127 | */ |
| 128 | CX_PROPERTIES_INVALID_MISSING_DELIMITER, | |
| 129 | /** | |
| 130 | * More internal buffer was needed, but could not be allocated. | |
| 131 | */ | |
| 132 | CX_PROPERTIES_BUFFER_ALLOC_FAILED, | |
| 133 | /** | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
134 | * A file operation failed. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
135 | * Only for cxPropertiesLoad(). |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
136 | * It is system-specific if errno is set. |
| 440 | 137 | */ |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
138 | CX_PROPERTIES_FILE_ERROR, |
| 440 | 139 | /** |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
140 | * A map operation failed. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
141 | * Only for cxPropertiesLoad(). |
| 440 | 142 | */ |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
143 | CX_PROPERTIES_MAP_ERROR, |
| 440 | 144 | }; |
| 145 | ||
| 146 | /** | |
| 147 | * Typedef for the properties status enum. | |
| 148 | */ | |
| 149 | typedef enum cx_properties_status CxPropertiesStatus; | |
| 150 | ||
| 151 | /** | |
| 152 | * Interface for working with properties data. | |
| 153 | */ | |
| 154 | struct cx_properties_s { | |
| 155 | /** | |
| 156 | * The configuration. | |
| 157 | */ | |
| 158 | CxPropertiesConfig config; | |
| 159 | ||
| 160 | /** | |
| 161 | * The text input buffer. | |
| 162 | */ | |
| 163 | CxBuffer input; | |
| 164 | ||
| 165 | /** | |
| 166 | * Internal buffer. | |
| 167 | */ | |
| 168 | CxBuffer buffer; | |
| 169 | }; | |
| 170 | ||
| 171 | /** | |
| 172 | * Typedef for the properties interface. | |
| 173 | */ | |
| 174 | typedef struct cx_properties_s CxProperties; | |
| 175 | ||
| 176 | /** | |
| 177 | * Initialize a properties interface. | |
| 178 | * | |
| 179 | * @param prop the properties interface | |
| 180 | * @param config the properties configuration | |
| 181 | * @see cxPropertiesInitDefault() | |
| 182 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
183 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
184 | void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config); |
| 440 | 185 | |
| 186 | /** | |
| 187 | * Destroys the properties interface. | |
| 188 | * | |
| 189 | * @note Even when you are certain that you did not use the interface in a | |
| 190 | * way that caused a memory allocation, you should call this function anyway. | |
| 845 | 191 | * Future versions of the library might add features that need additional memory, |
| 192 | * and you really don't want to search the entire code where you might need to | |
| 193 | * add a call to this function. | |
| 440 | 194 | * |
| 195 | * @param prop the properties interface | |
| 196 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
197 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
198 | void cxPropertiesDestroy(CxProperties *prop); |
| 440 | 199 | |
| 200 | /** | |
| 201 | * Destroys and re-initializes the properties interface. | |
| 202 | * | |
| 845 | 203 | * You might want to use this to reset the parser after |
| 440 | 204 | * encountering a syntax error. |
| 205 | * | |
| 206 | * @param prop the properties interface | |
| 207 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
208 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
209 | void cxPropertiesReset(CxProperties *prop); |
| 440 | 210 | |
| 211 | /** | |
| 212 | * Initialize a properties parser with the default configuration. | |
| 213 | * | |
| 214 | * @param prop (@c CxProperties*) the properties interface | |
| 215 | * @see cxPropertiesInit() | |
| 216 | */ | |
| 217 | #define cxPropertiesInitDefault(prop) \ | |
| 870 | 218 | cxPropertiesInit(prop, cx_properties_config_default) |
| 440 | 219 | |
| 220 | /** | |
| 221 | * Fills the input buffer with data. | |
| 222 | * | |
| 223 | * After calling this function, you can parse the data by calling | |
| 224 | * cxPropertiesNext(). | |
| 225 | * | |
| 226 | * @remark The properties interface tries to avoid allocations. | |
| 227 | * When you use this function and cxPropertiesNext() interleaving, | |
| 228 | * no allocations are performed. However, you must not free the | |
| 229 | * pointer to the data in that case. When you invoke the fill | |
| 230 | * function more than once before calling cxPropertiesNext(), | |
| 231 | * the additional data is appended - inevitably leading to | |
| 232 | * an allocation of a new buffer and copying the previous contents. | |
| 233 | * | |
| 234 | * @param prop the properties interface | |
| 235 | * @param buf a pointer to the data | |
| 236 | * @param len the length of the data | |
| 237 | * @retval zero success | |
| 238 | * @retval non-zero a memory allocation was necessary but failed | |
| 239 | * @see cxPropertiesFill() | |
| 240 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
241 | CX_EXTERN CX_NONNULL CX_ACCESS_R(2, 3) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
242 | int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len); |
| 440 | 243 | |
| 845 | 244 | /** |
| 245 | * Internal function, do not use. | |
| 246 | * | |
| 247 | * @param prop the properties interface | |
| 248 | * @param str the text to fill in | |
| 249 | * @retval zero success | |
| 250 | * @retval non-zero a memory allocation was necessary but failed | |
| 251 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
252 | CX_NONNULL CX_INLINE |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
253 | int cx_properties_fill(CxProperties *prop, cxstring str) { |
| 440 | 254 | return cxPropertiesFilln(prop, str.ptr, str.length); |
| 255 | } | |
| 256 | ||
| 257 | /** | |
| 258 | * Fills the input buffer with data. | |
| 259 | * | |
| 260 | * After calling this function, you can parse the data by calling | |
| 261 | * cxPropertiesNext(). | |
| 262 | * | |
| 263 | * @attention The properties interface tries to avoid allocations. | |
| 264 | * When you use this function and cxPropertiesNext() interleaving, | |
| 265 | * no allocations are performed. However, you must not free the | |
| 266 | * pointer to the data in that case. When you invoke the fill | |
| 267 | * function more than once before calling cxPropertiesNext(), | |
| 268 | * the additional data is appended - inevitably leading to | |
| 269 | * an allocation of a new buffer and copying the previous contents. | |
| 270 | * | |
| 271 | * @param prop the properties interface | |
| 272 | * @param str the text to fill in | |
| 273 | * @retval zero success | |
| 274 | * @retval non-zero a memory allocation was necessary but failed | |
| 275 | * @see cxPropertiesFilln() | |
| 276 | */ | |
| 845 | 277 | #define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str)) |
| 440 | 278 | |
| 279 | /** | |
| 845 | 280 | * Specifies stack memory that shall be used as an internal buffer. |
| 440 | 281 | * |
| 282 | * @param prop the properties interface | |
| 283 | * @param buf a pointer to stack memory | |
| 284 | * @param capacity the capacity of the stack memory | |
| 285 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
286 | CX_EXTERN CX_NONNULL |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
287 | void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity); |
| 440 | 288 | |
| 289 | /** | |
| 290 | * Retrieves the next key/value-pair. | |
| 291 | * | |
| 292 | * This function returns zero as long as there are key/value-pairs found. | |
| 293 | * If no more key/value-pairs are found, #CX_PROPERTIES_NO_DATA is returned. | |
| 294 | * | |
| 295 | * When an incomplete line is encountered, #CX_PROPERTIES_INCOMPLETE_DATA is | |
| 296 | * returned, and you can add more data with #cxPropertiesFill(). | |
| 297 | * | |
| 298 | * @remark The incomplete line will be stored in an internal buffer, which is | |
| 299 | * allocated on the heap, by default. If you want to avoid allocations, | |
| 300 | * you can specify sufficient space with cxPropertiesUseStack() after | |
| 301 | * initialization with cxPropertiesInit(). | |
| 302 | * | |
| 303 | * @attention The returned strings will point into a buffer that might not be | |
| 304 | * available later. It is strongly recommended to copy the strings for further | |
| 305 | * use. | |
| 306 | * | |
| 307 | * @param prop the properties interface | |
| 308 | * @param key a pointer to the cxstring that shall contain the property name | |
| 309 | * @param value a pointer to the cxstring that shall contain the property value | |
| 310 | * @retval CX_PROPERTIES_NO_ERROR (zero) a key/value pair was found | |
| 311 | * @retval CX_PROPERTIES_NO_DATA there is no (more) data in the input buffer | |
| 312 | * @retval CX_PROPERTIES_INCOMPLETE_DATA the data in the input buffer is incomplete | |
| 313 | * (fill more data and try again) | |
| 314 | * @retval CX_PROPERTIES_NULL_INPUT the input buffer was never filled | |
| 315 | * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key | |
| 316 | * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter | |
| 317 | * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed | |
| 318 | */ | |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
319 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
320 | CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value); |
| 440 | 321 | |
| 322 | /** | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
323 | * The size of the stack memory that `cxPropertiesLoad()` will reserve with `cxPropertiesUseStack()`. |
| 440 | 324 | */ |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
325 | CX_EXPORT extern const unsigned cx_properties_load_buf_size; |
| 440 | 326 | |
| 327 | /** | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
328 | * The size of the stack memory that `cxPropertiesLoad()` will use to read contents from the file. |
| 440 | 329 | */ |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
330 | CX_EXPORT extern const unsigned cx_properties_load_fill_size; |
| 440 | 331 | |
| 332 | /** | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
333 | * Internal function - use cxPropertiesLoad() instead. |
| 440 | 334 | * |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
335 | * @param allocator the allocator for the values |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
336 | * @param filename the file name |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
337 | * @param target the target map |
| 1016 | 338 | * @param config the parser config |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
339 | * @return status code |
| 440 | 340 | */ |
|
1040
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
341 | CX_EXTERN CX_NONNULL_ARG(3) |
|
473d8cb58a6c
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
342 | CxPropertiesStatus cx_properties_load(const CxAllocator *allocator, |
| 1016 | 343 | cxstring filename, CxMap *target, CxPropertiesConfig config); |
| 440 | 344 | |
| 345 | /** | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
346 | * Loads properties from a file and inserts them into a map. |
| 440 | 347 | * |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
348 | * Entries are added to the map, possibly overwriting existing entries. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
349 | * |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
350 | * The map must either store pointers of type @c char*, or elements of type cxmutstr. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
351 | * Any other configuration is not supported. |
| 440 | 352 | * |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
353 | * @note When the parser finds an error, all successfully parsed keys before the error |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
354 | * are added to the map nonetheless. |
|
471
063a9f29098c
ucx update + fix doc attach/detach + fix ui_set with unbound values
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
355 | * |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
356 | * @param allocator the allocator for the values that will be stored in the map |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
357 | * @param filename (any string) the absolute or relative path to the file |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
358 | * @param target (@c CxMap*) the map where the properties shall be added |
| 1016 | 359 | * @param config the parser config |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
360 | * @retval CX_PROPERTIES_NO_ERROR (zero) at least one key/value pair was found |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
361 | * @retval CX_PROPERTIES_NO_DATA the file is syntactically OK, but does not contain properties |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
362 | * @retval CX_PROPERTIES_INCOMPLETE_DATA unexpected end of file |
| 440 | 363 | * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key |
| 364 | * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter | |
| 365 | * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
366 | * @retval CX_PROPERTIES_FILE_ERROR a file operation failed; depending on the system @c errno might be set |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
367 | * @retval CX_PROPERTIES_MAP_ERROR storing a key/value pair in the map failed |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
368 | * @see cxPropertiesLoadDefault() |
| 440 | 369 | */ |
| 1016 | 370 | #define cxPropertiesLoad(allocator, filename, target, config) \ |
| 371 | cx_properties_load(allocator, cx_strcast(filename), target, config) | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
372 | |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
373 | /** |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
374 | * Loads properties from a file and inserts them into a map with a default config. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
375 | * |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
376 | * Entries are added to the map, possibly overwriting existing entries. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
377 | * |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
378 | * The map must either store pointers of type @c char*, or elements of type cxmutstr. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
379 | * Any other configuration is not supported. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
380 | * |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
381 | * @note When the parser finds an error, all successfully parsed keys before the error |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
382 | * are added to the map nonetheless. |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
383 | * |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
384 | * @param allocator the allocator for the values that will be stored in the map |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
385 | * @param filename (any string) the absolute or relative path to the file |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
386 | * @param target (@c CxMap*) the map where the properties shall be added |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
387 | * @retval CX_PROPERTIES_NO_ERROR (zero) at least one key/value pair was found |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
388 | * @retval CX_PROPERTIES_NO_DATA the file is syntactically OK, but does not contain properties |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
389 | * @retval CX_PROPERTIES_INCOMPLETE_DATA unexpected end of file |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
390 | * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
391 | * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
392 | * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
393 | * @retval CX_PROPERTIES_FILE_ERROR a file operation failed; depending on the system @c errno might be set |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
394 | * @retval CX_PROPERTIES_MAP_ERROR storing a key/value pair in the map failed |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
395 | * @see cxPropertiesLoad() |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
396 | */ |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
397 | #define cxPropertiesLoadDefault(allocator, filename, target) \ |
| 1016 | 398 | cx_properties_load(allocator, cx_strcast(filename), target, cx_properties_config_default) |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
399 | |
| 440 | 400 | #endif // UCX_PROPERTIES_H |