ucx/cx/properties.h

Mon, 06 Jan 2025 21:18:36 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 06 Jan 2025 21:18:36 +0100
changeset 852
83fdf679df99
permissions
-rw-r--r--

update ucx

852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
83fdf679df99 update ucx
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 * @file properties.h
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 * @brief Interface for parsing data from properties files.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * @author Mike Becker
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 * @author Olaf Wintermann
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 * @copyright 2-Clause BSD License
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #ifndef UCX_PROPERTIES_H
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #define UCX_PROPERTIES_H
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "common.h"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "string.h"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "map.h"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include "buffer.h"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #include <stdio.h>
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include <string.h>
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #ifdef __cplusplus
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 extern "C" {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 #endif
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 * Configures the expected characters for the properties parser.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 struct cx_properties_config_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 * The key/value delimiter that shall be used.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 * This is '=' by default.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 char delimiter;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 * The character, when appearing at the end of a line, continues that line.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 * This is '\' by default.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 // char continuation; // TODO: line continuation in properties
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 * The first comment character.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 * This is '#' by default.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 char comment1;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 * The second comment character.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 * This is not set by default.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 char comment2;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 * The third comment character.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 * This is not set by default.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 char comment3;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 * Typedef for the properties config.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 typedef struct cx_properties_config_s CxPropertiesConfig;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 * Default properties configuration.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 extern const CxPropertiesConfig cx_properties_config_default;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 * Status codes for the properties interface.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 enum cx_properties_status {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 * Everything is fine.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 CX_PROPERTIES_NO_ERROR,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 * The input buffer does not contain more data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 CX_PROPERTIES_NO_DATA,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 * The input ends unexpectedly.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 * This either happens when the last line does not terminate with a line
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 * break, or when the input ends with a parsed key but no value.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 CX_PROPERTIES_INCOMPLETE_DATA,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 * Not used as a status and never returned by any function.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 * You can use this enumerator to check for all "good" status results
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 * by checking if the status is less than @c CX_PROPERTIES_OK.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 * A "good" status means, that you can refill data and continue parsing.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 CX_PROPERTIES_OK,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 * Input buffer is @c NULL.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 CX_PROPERTIES_NULL_INPUT,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 * The line contains a delimiter, but no key.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 CX_PROPERTIES_INVALID_EMPTY_KEY,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 * The line contains data, but no delimiter.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 CX_PROPERTIES_INVALID_MISSING_DELIMITER,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 * More internal buffer was needed, but could not be allocated.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 CX_PROPERTIES_BUFFER_ALLOC_FAILED,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 * Initializing the properties source failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 * @see cx_properties_read_init_func
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 CX_PROPERTIES_READ_INIT_FAILED,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 * Reading from a properties source failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 * @see cx_properties_read_func
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 CX_PROPERTIES_READ_FAILED,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 * Sinking a k/v-pair failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 * @see cx_properties_sink_func
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 CX_PROPERTIES_SINK_FAILED,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 * Typedef for the properties status enum.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 typedef enum cx_properties_status CxPropertiesStatus;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 * Interface for working with properties data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 struct cx_properties_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 * The configuration.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 CxPropertiesConfig config;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 * The text input buffer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 CxBuffer input;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 * Internal buffer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 CxBuffer buffer;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 * Typedef for the properties interface.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 typedef struct cx_properties_s CxProperties;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 * Typedef for a properties sink.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 typedef struct cx_properties_sink_s CxPropertiesSink;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 * A function that consumes a k/v-pair in a sink.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 * The sink could be e.g. a map and the sink function would be calling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 * a map function to store the k/v-pair.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 * @param prop the properties interface that wants to sink a k/v-pair
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 * @param sink the sink
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 * @param key the key
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 * @param value the value
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 * @retval non-zero sinking the k/v-pair failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 typedef int(*cx_properties_sink_func)(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 CxPropertiesSink *sink,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 cxstring key,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 cxstring value
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 * Defines a sink for k/v-pairs.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 struct cx_properties_sink_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 * The sink object.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 void *sink;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 * Optional custom data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 void *data;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 * A function for consuming k/v-pairs into the sink.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 cx_properties_sink_func sink_func;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 * Typedef for a properties source.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 typedef struct cx_properties_source_s CxPropertiesSource;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 * A function that reads data from a source.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 * When the source is depleted, implementations SHALL provide an empty
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 * string in the @p target and return zero.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 * A non-zero return value is only permitted in case of an error.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 * The meaning of the optional parameters is implementation-dependent.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 * @param prop the properties interface that wants to read from the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 * @param src the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 * @param target a string buffer where the read data shall be stored
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 * @retval non-zero reading the data failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 typedef int(*cx_properties_read_func)(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 CxPropertiesSource *src,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 cxstring *target
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 * A function that may initialize additional memory for the source.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 * @param prop the properties interface that wants to read from the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 * @param src the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 * @retval zero initialization was successful
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 * @retval non-zero otherwise
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 typedef int(*cx_properties_read_init_func)(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 CxPropertiesSource *src
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 * A function that cleans memory initialized by the read_init_func.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 * @param prop the properties interface that wants to read from the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 * @param src the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 typedef void(*cx_properties_read_clean_func)(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 CxPropertiesSource *src
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 * Defines a properties source.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 struct cx_properties_source_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 * The source object.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 * For example a file stream or a string.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 void *src;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 * Optional additional data pointer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 void *data_ptr;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 * Optional size information.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 size_t data_size;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 * A function that reads data from the source.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 cx_properties_read_func read_func;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 * Optional function that may prepare the source for reading data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 cx_properties_read_init_func read_init_func;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 * Optional function that cleans additional memory allocated by the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 * read_init_func.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 cx_properties_read_clean_func read_clean_func;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 * Initialize a properties interface.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 * @param config the properties configuration
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 * @see cxPropertiesInitDefault()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 * Destroys the properties interface.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 * @note Even when you are certain that you did not use the interface in a
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 * way that caused a memory allocation, you should call this function anyway.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 * Future versions of the library might add features that need additional memory
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 * and you really don't want to search the entire code where you might need
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 * add call to this function.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 void cxPropertiesDestroy(CxProperties *prop);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 * Destroys and re-initializes the properties interface.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 * You might want to use this, to reset the parser after
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 * encountering a syntax error.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 static inline void cxPropertiesReset(CxProperties *prop) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 CxPropertiesConfig config = prop->config;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 cxPropertiesDestroy(prop);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 cxPropertiesInit(prop, config);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 * Initialize a properties parser with the default configuration.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 * @param prop (@c CxProperties*) the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365 * @see cxPropertiesInit()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367 #define cxPropertiesInitDefault(prop) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 cxPropertiesInit(prop, cx_properties_config_default)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371 * Fills the input buffer with data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 * After calling this function, you can parse the data by calling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 * cxPropertiesNext().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 * @remark The properties interface tries to avoid allocations.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
377 * When you use this function and cxPropertiesNext() interleaving,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 * no allocations are performed. However, you must not free the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379 * pointer to the data in that case. When you invoke the fill
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 * function more than once before calling cxPropertiesNext(),
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
381 * the additional data is appended - inevitably leading to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
382 * an allocation of a new buffer and copying the previous contents.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 * @param buf a pointer to the data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 * @param len the length of the data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 * @retval non-zero a memory allocation was necessary but failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 * @see cxPropertiesFill()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392 cx_attr_access_r(2, 3)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
393 int cxPropertiesFilln(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
394 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
395 const char *buf,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
396 size_t len
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
397 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
398
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
399 #ifdef __cplusplus
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
400 } // extern "C"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 static inline int cxPropertiesFill(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 cxstring str
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 ) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 return cxPropertiesFilln(prop, str.ptr, str.length);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 static inline int cxPropertiesFill(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
412 cxmutstr str
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 ) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 return cxPropertiesFilln(prop, str.ptr, str.length);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418 cx_attr_cstr_arg(2)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 static inline int cxPropertiesFill(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 const char *str
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
422 ) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423 return cxPropertiesFilln(prop, str, strlen(str));
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
425
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 extern "C" {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427 #else // __cplusplus
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
429 * Fills the input buffer with data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
431 * After calling this function, you can parse the data by calling
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
432 * cxPropertiesNext().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434 * @attention The properties interface tries to avoid allocations.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
435 * When you use this function and cxPropertiesNext() interleaving,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
436 * no allocations are performed. However, you must not free the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 * pointer to the data in that case. When you invoke the fill
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
438 * function more than once before calling cxPropertiesNext(),
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 * the additional data is appended - inevitably leading to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 * an allocation of a new buffer and copying the previous contents.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
442 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
443 * @param str the text to fill in
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 * @retval non-zero a memory allocation was necessary but failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 * @see cxPropertiesFilln()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 #define cxPropertiesFill(prop, str) _Generic((str), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 cxstring: cx_properties_fill_cxstr, \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
450 cxmutstr: cx_properties_fill_mutstr, \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
451 char*: cx_properties_fill_str, \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 const char*: cx_properties_fill_str) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
453 (prop, str)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
456 * @copydoc cxPropertiesFill()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
457 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459 static inline int cx_properties_fill_cxstr(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 cxstring str
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
462 ) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463 return cxPropertiesFilln(prop, str.ptr, str.length);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
467 * @copydoc cxPropertiesFill()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
469 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
470 static inline int cx_properties_fill_mutstr(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
471 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
472 cxmutstr str
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
473 ) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
474 return cxPropertiesFilln(prop, str.ptr, str.length);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 * @copydoc cxPropertiesFill()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 cx_attr_cstr_arg(2)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 static inline int cx_properties_fill_str(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 const char *str
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 ) {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 return cxPropertiesFilln(prop, str, strlen(str));
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 }
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 #endif
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 * Specifies stack memory that shall be used as internal buffer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 * @param buf a pointer to stack memory
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 * @param capacity the capacity of the stack memory
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 void cxPropertiesUseStack(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
499 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 char *buf,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 size_t capacity
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
503
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
505 * Retrieves the next key/value-pair.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
506 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
507 * This function returns zero as long as there are key/value-pairs found.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
508 * If no more key/value-pairs are found, #CX_PROPERTIES_NO_DATA is returned.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510 * When an incomplete line is encountered, #CX_PROPERTIES_INCOMPLETE_DATA is
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
511 * returned, and you can add more data with #cxPropertiesFill().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 * @remark The incomplete line will be stored in an internal buffer, which is
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 * allocated on the heap, by default. If you want to avoid allocations,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 * you can specify sufficient space with cxPropertiesUseStack() after
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 * initialization with cxPropertiesInit().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518 * @attention The returned strings will point into a buffer that might not be
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 * available later. It is strongly recommended to copy the strings for further
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
520 * use.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
522 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
523 * @param key a pointer to the cxstring that shall contain the property name
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
524 * @param value a pointer to the cxstring that shall contain the property value
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
525 * @retval CX_PROPERTIES_NO_ERROR (zero) a key/value pair was found
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
526 * @retval CX_PROPERTIES_NO_DATA there is no (more) data in the input buffer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
527 * @retval CX_PROPERTIES_INCOMPLETE_DATA the data in the input buffer is incomplete
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
528 * (fill more data and try again)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
529 * @retval CX_PROPERTIES_NULL_INPUT the input buffer was never filled
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
530 * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
531 * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
532 * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
534 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
535 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
536 CxPropertiesStatus cxPropertiesNext(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
537 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538 cxstring *key,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
539 cxstring *value
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
540 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
541
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
543 * Creates a properties sink for an UCX map.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
544 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
545 * The values stored in the map will be pointers to strings allocated
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546 * by #cx_strdup_a().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
547 * The default stdlib allocator will be used, unless you specify a custom
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
548 * allocator in the optional @c data of the sink.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
549 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
550 * @param map the map that shall consume the k/v-pairs.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
551 * @return the sink
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
552 * @see cxPropertiesLoad()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
554 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 CxPropertiesSink cxPropertiesMapSink(CxMap *map);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
557
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
558 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
559 * Creates a properties source based on an UCX string.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
560 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
561 * @param str the string
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
562 * @return the properties source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
563 * @see cxPropertiesLoad()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
564 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
565 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
566 CxPropertiesSource cxPropertiesStringSource(cxstring str);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
567
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
568 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
569 * Creates a properties source based on C string with the specified length.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
571 * @param str the string
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
572 * @param len the length
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
573 * @return the properties source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
574 * @see cxPropertiesLoad()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
575 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
576 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
577 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
578 cx_attr_access_r(1, 2)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
579 CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
580
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
581 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
582 * Creates a properties source based on a C string.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
583 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
584 * The length will be determined with strlen(), so the string MUST be
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
585 * zero-terminated.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
586 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
587 * @param str the string
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
588 * @return the properties source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
589 * @see cxPropertiesLoad()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
590 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
591 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
592 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
593 cx_attr_cstr_arg(1)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
594 CxPropertiesSource cxPropertiesCstrSource(const char *str);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
595
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
596 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
597 * Creates a properties source based on an FILE.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
598 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
599 * @param file the file
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
600 * @param chunk_size how many bytes may be read in one operation
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
601 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
602 * @return the properties source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
603 * @see cxPropertiesLoad()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
604 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
605 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
606 cx_attr_nodiscard
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
607 cx_attr_access_r(1)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
608 CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
609
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
610
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
611 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
612 * Loads properties data from a source and transfers it to a sink.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
613 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
614 * This function tries to read as much data from the source as possible.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
615 * When the source was completely consumed and at least on k/v-pair was found,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
616 * the return value will be #CX_PROPERTIES_NO_ERROR.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
617 * When the source was consumed but no k/v-pairs were found, the return value
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
618 * will be #CX_PROPERTIES_NO_DATA.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
619 * The other result codes apply, according to their description.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
620 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
621 * @param prop the properties interface
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
622 * @param sink the sink
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
623 * @param source the source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
624 * @retval CX_PROPERTIES_NO_ERROR (zero) a key/value pair was found
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
625 * @retval CX_PROPERTIES_READ_INIT_FAILED initializing the source failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
626 * @retval CX_PROPERTIES_READ_FAILED reading from the source failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
627 * @retval CX_PROPERTIES_SINK_FAILED sinking the properties into the sink failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
628 * @retval CX_PROPERTIES_NO_DATA the source did not provide any key/value pairs
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
629 * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
630 * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
631 * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
632 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
633 cx_attr_nonnull
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
634 CxPropertiesStatus cxPropertiesLoad(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
635 CxProperties *prop,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
636 CxPropertiesSink sink,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
637 CxPropertiesSource source
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
638 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
639
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
640 #ifdef __cplusplus
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
641 } // extern "C"
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
642 #endif
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
643
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
644 #endif // UCX_PROPERTIES_H

mercurial