src/cx/properties.h

Tue, 09 Dec 2025 18:55:14 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 09 Dec 2025 18:55:14 +0100
changeset 1560
f060ecd65575
parent 1557
03fbf1c99e73
permissions
-rw-r--r--

add note that cxPropertiesLoad() does not roll back the changes to the map on error

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 /**
cfa44f3f5e3b last minute fixes for issue #548
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
81 * Reserved for future use.
cfa44f3f5e3b last minute fixes for issue #548
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
82 */
cfa44f3f5e3b last minute fixes for issue #548
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
83 char continuation;
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 };
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 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 * Typedef for the properties config.
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 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
90
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 * Default properties configuration.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 */
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
94 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
95
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 * 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
98 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 enum cx_properties_status {
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 * Everything is fine.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 CX_PROPERTIES_NO_ERROR,
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 * 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
106 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 CX_PROPERTIES_NO_DATA,
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 * The input ends unexpectedly.
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 * 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
112 * 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
113 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 CX_PROPERTIES_INCOMPLETE_DATA,
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 /**
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
116 * 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
117 *
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
118 * 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
119 * 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
120 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
121 * 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
122 */
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
123 CX_PROPERTIES_OK,
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
124 /**
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
125 * 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
126 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 CX_PROPERTIES_NULL_INPUT,
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
128 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
129 * 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
130 */
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
131 CX_PROPERTIES_INVALID_EMPTY_KEY,
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
132 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
133 * 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
134 */
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
135 CX_PROPERTIES_INVALID_MISSING_DELIMITER,
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
136 /**
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
137 * 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
138 */
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
139 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
140 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
141 * 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
142 * 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
143 * 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
144 */
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
145 CX_PROPERTIES_FILE_ERROR,
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 * 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
148 * Only for cxPropertiesLoad().
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
149 */
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
150 CX_PROPERTIES_MAP_ERROR,
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 };
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 /**
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
154 * 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
155 */
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
156 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
157
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
158 /**
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 * 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
160 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 struct cx_properties_s {
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 * The configuration.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 CxPropertiesConfig config;
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 /**
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
168 * The text input buffer.
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
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 CxBuffer input;
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
171
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
172 /**
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
173 * Internal buffer.
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
174 */
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
175 CxBuffer buffer;
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 };
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 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 * Typedef for the properties interface.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 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
182
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
183 /**
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
184 * Initialize a properties interface.
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 *
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 * @param prop the properties interface
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 * @param config the properties configuration
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 * @see cxPropertiesInitDefault()
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 980
diff changeset
190 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
191 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
192
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
193 /**
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
194 * Destroys the properties interface.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
195 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
196 * @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
197 * 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
198 * 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
199 * 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
200 * add a call to this function.
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
201 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
202 * @param prop the properties interface
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
203 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 980
diff changeset
204 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
205 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
206
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 /**
1013
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
208 * Destroys and re-initializes the properties interface.
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
209 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
210 * 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
211 * encountering a syntax error.
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
212 *
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
213 * @param prop the properties interface
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 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
216 CX_EXPORT void cxPropertiesReset(CxProperties *prop);
1013
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
217
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
218 /**
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 * 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
220 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
221 * @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
222 * @see cxPropertiesInit()
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 #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
225 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
226
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 /**
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 932
diff changeset
228 * Fills the input buffer with data.
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 932
diff changeset
229 *
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
230 * 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
231 * cxPropertiesNext().
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 *
1058
d347f74ce7d1 downgrades the severity of the advice in cxPropertiesFilln() from attention to remark
Mike Becker <universe@uap-core.de>
parents: 1038
diff changeset
233 * @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
234 * 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
235 * 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
236 * 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
237 * function more than once before calling cxPropertiesNext(),
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
238 * 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
239 * 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
240 *
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 * @param prop the properties interface
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
242 * @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
243 * @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
244 * @retval zero success
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
245 * @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
246 * @see cxPropertiesFill()
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 */
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
248 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
249 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
250
1417
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
251 /**
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
252 * 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
253 *
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
254 * @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
255 * @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
256 * @retval zero success
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
257 * @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
258 */
988
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
259 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
260 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
261 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
262 }
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
263
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
264 /**
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
265 * Fills the input buffer with data.
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
266 *
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
267 * 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
268 * cxPropertiesNext().
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
269 *
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
270 * @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
271 * 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
272 * 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
273 * 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
274 * function more than once before calling cxPropertiesNext(),
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
275 * 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
276 * 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
277 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
278 * @param prop the properties interface
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
279 * @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
280 * @retval zero success
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
281 * @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
282 * @see cxPropertiesFilln()
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 932
diff changeset
283 */
1417
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
284 #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
285
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
286 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
287 * 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
288 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
289 * @param prop the properties interface
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
290 * @param buf a pointer to stack memory
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
291 * @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
292 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 980
diff changeset
293 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
294 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
295
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 * 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
298 *
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
299 * 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
300 * 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
301 *
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
302 * 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
303 * 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
304 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
305 * @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
306 * 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
307 * 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
308 * initialization with cxPropertiesInit().
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
309 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
310 * @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
311 * 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
312 * use.
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 *
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 * @param prop the properties interface
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
315 * @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
316 * @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
317 * @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
318 * @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
319 * @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
320 * (fill more data and try again)
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
321 * @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
322 * @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
323 * @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
324 * @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
325 */
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
326 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
327 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
328
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
329 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
330 * 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
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 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
333
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
334 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
335 * 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
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 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
338
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
339 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
340 * 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
341 *
1555
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 config the parser config
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
343 * @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
344 * @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
345 * @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
346 * @return status code
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
347 */
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
348 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
349 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
350 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
351
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
352 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
353 * 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
354 *
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
355 * 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
356 *
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
357 * 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
358 * 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
359 *
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
360 * @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
361 * 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
362 *
1555
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 config the parser config
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
364 * @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
365 * @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
366 * @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
367 * @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
368 * @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
369 * @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
370 * @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
371 * @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
372 * @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
373 * @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
374 * @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
375 * @see cxPropertiesLoadDefault()
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
376 */
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
377 #define cxPropertiesLoad(config, allocator, filename, target) \
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
378 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
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 /**
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
381 * 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
382 *
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
383 * 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
384 *
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
385 * 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
386 * 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
387 *
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
388 * @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
389 * 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
390 *
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
391 * @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
392 * @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
393 * @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
394 * @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
395 * @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
396 * @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
397 * @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
398 * @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
399 * @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
400 * @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
401 * @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
402 * @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
403 */
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
404 #define cxPropertiesLoadDefault(allocator, filename, target) \
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
405 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
406
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
407
932
484dab606292 add extern "C" to properties.h
Mike Becker <universe@uap-core.de>
parents: 928
diff changeset
408 #ifdef __cplusplus
484dab606292 add extern "C" to properties.h
Mike Becker <universe@uap-core.de>
parents: 928
diff changeset
409 } // extern "C"
484dab606292 add extern "C" to properties.h
Mike Becker <universe@uap-core.de>
parents: 928
diff changeset
410 #endif
484dab606292 add extern "C" to properties.h
Mike Becker <universe@uap-core.de>
parents: 928
diff changeset
411
1069
6565e7ef5ee3 fix include guard for properties.h
Mike Becker <universe@uap-core.de>
parents: 1059
diff changeset
412 #endif // UCX_PROPERTIES_H

mercurial