src/cx/properties.h

Sun, 28 Dec 2025 17:31:20 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 28 Dec 2025 17:31:20 +0100
changeset 1675
36c0fb2b60b2
parent 1609
a767bf59cad3
permissions
-rw-r--r--

overhaul all attributes

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
1036
6d29532a76c3 add missing documentation for struct cx_properties_config_s
Mike Becker <universe@uap-core.de>
parents: 1031
diff changeset
44 /**
6d29532a76c3 add missing documentation for struct cx_properties_config_s
Mike Becker <universe@uap-core.de>
parents: 1031
diff changeset
45 * 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
46 */
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 struct cx_properties_config_s {
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 * 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
50 * This is '=' by default.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 char delimiter;
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 * The first comment character.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 * This is '#' by default.
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 char comment1;
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 * The second comment character.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 * 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
63 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 char comment2;
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 * The third comment character.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 * 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
69 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 char comment3;
1193
cfa44f3f5e3b last minute fixes for issue #548
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
71
1609
a767bf59cad3 fixes docstring comment for 'continuation' member
Mike Becker <universe@uap-core.de>
parents: 1603
diff changeset
72 /**
1193
cfa44f3f5e3b last minute fixes for issue #548
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
73 * 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
74 * This is '\' by default.
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 char continuation;
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 };
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 * Typedef for the properties config.
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 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
83
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 * Default properties configuration.
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 */
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
87 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
88
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 * 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
91 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 enum cx_properties_status {
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 * Everything is fine.
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 CX_PROPERTIES_NO_ERROR,
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 * 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
99 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 CX_PROPERTIES_NO_DATA,
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 ends unexpectedly.
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 * 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
105 * 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
106 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 CX_PROPERTIES_INCOMPLETE_DATA,
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 /**
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
109 * 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
110 *
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
111 * 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
112 * 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
113 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
114 * 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
115 */
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
116 CX_PROPERTIES_OK,
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
117 /**
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
118 * 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
119 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 CX_PROPERTIES_NULL_INPUT,
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
121 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
122 * 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
123 */
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
124 CX_PROPERTIES_INVALID_EMPTY_KEY,
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 data but no delimiter.
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_MISSING_DELIMITER,
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
129 /**
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
130 * 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
131 */
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
132 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
133 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
134 * 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
135 * 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
136 * 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
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 CX_PROPERTIES_FILE_ERROR,
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
139 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
140 * 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
141 * Only for cxPropertiesLoad().
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
142 */
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
143 CX_PROPERTIES_MAP_ERROR,
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 };
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 /**
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
147 * 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
148 */
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
149 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
150
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
151 /**
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 * 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
153 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 struct cx_properties_s {
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 * The configuration.
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 CxPropertiesConfig config;
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 /**
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
161 * The text input buffer.
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 */
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
163 CxBuffer input;
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
164
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
165 /**
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
166 * Internal buffer.
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
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 CxBuffer buffer;
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 };
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 * Typedef for the properties interface.
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 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
175
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
176 /**
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
177 * Initialize a properties interface.
923
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 * @param prop the properties interface
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 * @param config the properties configuration
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 * @see cxPropertiesInitDefault()
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
183 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
184 void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
185
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
186 /**
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
187 * Destroys the properties interface.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
188 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
189 * @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
190 * 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
191 * 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
192 * 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
193 * add a call to this function.
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
194 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
195 * @param prop the properties interface
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
196 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
197 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
198 void cxPropertiesDestroy(CxProperties *prop);
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 /**
1013
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
201 * Destroys and re-initializes the properties interface.
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
202 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
203 * 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
204 * encountering a syntax error.
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
205 *
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
206 * @param prop the properties interface
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
207 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
208 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
209 void cxPropertiesReset(CxProperties *prop);
1013
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
210
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 988
diff changeset
211 /**
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 * 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
213 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
214 * @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
215 * @see cxPropertiesInit()
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 */
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 #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
218 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
219
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 /**
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 932
diff changeset
221 * Fills the input buffer with data.
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 932
diff changeset
222 *
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
223 * 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
224 * cxPropertiesNext().
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 *
1058
d347f74ce7d1 downgrades the severity of the advice in cxPropertiesFilln() from attention to remark
Mike Becker <universe@uap-core.de>
parents: 1038
diff changeset
226 * @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
227 * 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
228 * 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
229 * 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
230 * function more than once before calling cxPropertiesNext(),
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
231 * 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
232 * 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
233 *
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 * @param prop the properties interface
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
235 * @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
236 * @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
237 * @retval zero success
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
238 * @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
239 * @see cxPropertiesFill()
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
241 CX_EXTERN CX_NONNULL CX_ACCESS_R(2, 3)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
242 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
243
1417
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
244 /**
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
245 * 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
246 *
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
247 * @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
248 * @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
249 * @retval zero success
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
250 * @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
251 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
252 CX_NONNULL CX_INLINE
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
253 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
254 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
255 }
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
256
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
257 /**
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
258 * Fills the input buffer with data.
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
259 *
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
260 * 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
261 * cxPropertiesNext().
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
262 *
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
263 * @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
264 * 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
265 * 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
266 * 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
267 * function more than once before calling cxPropertiesNext(),
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
268 * 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
269 * 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
270 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
271 * @param prop the properties interface
1038
8cab3d8e0af4 fix outdated documentation in properties.h
Mike Becker <universe@uap-core.de>
parents: 1036
diff changeset
272 * @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
273 * @retval zero success
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
274 * @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
275 * @see cxPropertiesFilln()
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 932
diff changeset
276 */
1417
b97faf8b7ab7 replace all remaining generics with cx_strcast() - resolves #700
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
277 #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
278
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
279 /**
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1417
diff changeset
280 * 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
281 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
282 * @param prop the properties interface
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
283 * @param buf a pointer to stack memory
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
284 * @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
285 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
286 CX_EXTERN CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
287 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
288
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 /**
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 * 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
291 *
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
292 * 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
293 * 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
294 *
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
295 * 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
296 * 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
297 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
298 * @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
299 * 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
300 * 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
301 * initialization with cxPropertiesInit().
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
302 *
1106
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
303 * @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
304 * 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
305 * use.
923
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 *
45da884269c8 add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 * @param prop the properties interface
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents: 923
diff changeset
308 * @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
309 * @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
310 * @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
311 * @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
312 * @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
313 * (fill more data and try again)
0480f8600fb7 refine docs for properties.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1069
diff changeset
314 * @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
315 * @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
316 * @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
317 * @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
318 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
319 CX_EXTERN CX_NONNULL CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
320 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
321
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
322 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
323 * 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
324 */
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
325 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
326
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
327 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
328 * 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
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 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
331
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
332 /**
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
333 * 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
334 *
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
335 * @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
336 * @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
337 * @param target the target map
1603
ffea41207599 change signatures of cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
338 * @param config the parser config
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 * @return status code
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
340 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
341 CX_EXTERN CX_NONNULL_ARG(3)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1609
diff changeset
342 CxPropertiesStatus cx_properties_load(const CxAllocator *allocator,
1603
ffea41207599 change signatures of cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
343 cxstring filename, CxMap *target, CxPropertiesConfig config);
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
344
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
345 /**
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 * 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
347 *
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
348 * 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
349 *
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
350 * 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
351 * 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
352 *
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
353 * @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
354 * 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
355 *
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
356 * @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
357 * @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
358 * @param target (@c CxMap*) the map where the properties shall be added
1603
ffea41207599 change signatures of cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
359 * @param config the parser config
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 * @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
361 * @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
362 * @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
363 * @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
364 * @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
365 * @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
366 * @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
367 * @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
368 * @see cxPropertiesLoadDefault()
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
369 */
1603
ffea41207599 change signatures of cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
370 #define cxPropertiesLoad(allocator, filename, target, config) \
ffea41207599 change signatures of cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
371 cx_properties_load(allocator, cx_strcast(filename), target, config)
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
372
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
373 /**
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
374 * 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
375 *
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
376 * 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
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 * 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
379 * 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
380 *
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
381 * @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
382 * 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
383 *
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
384 * @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
385 * @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
386 * @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
387 * @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
388 * @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
389 * @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
390 * @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
391 * @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
392 * @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
393 * @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
394 * @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
395 * @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
396 */
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
397 #define cxPropertiesLoadDefault(allocator, filename, target) \
1603
ffea41207599 change signatures of cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
398 cx_properties_load(allocator, cx_strcast(filename), target, cx_properties_config_default)
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
399
1069
6565e7ef5ee3 fix include guard for properties.h
Mike Becker <universe@uap-core.de>
parents: 1059
diff changeset
400 #endif // UCX_PROPERTIES_H

mercurial