src/cx/properties.h

Wed, 10 Dec 2025 13:12:27 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 10 Dec 2025 13:12:27 +0100
changeset 1562
f2b63cad2142
parent 1560
f060ecd65575
permissions
-rw-r--r--

add support for line continuation in the properties parser - resolves #457

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

mercurial