ucx/cx/properties.h

Sat, 13 Dec 2025 15:58:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 13 Dec 2025 15:58:58 +0100
changeset 115
e57ca2747782
parent 113
dde28a806552
permissions
-rw-r--r--

fix build with newest toolkit version

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

mercurial