Sun, 13 Oct 2024 15:19:12 +0200
fix missing parameter doc
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | * \file properties.h |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | * \brief Interface for parsing data from properties files. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * \author Mike Becker |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | * \author Olaf Wintermann |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | * \copyright 2-Clause BSD License |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | #ifndef UCX_PROPERTIES |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | #define UCX_PROPERTIES |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | #include "common.h" |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | #include "string.h" |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
41 | #include "array_list.h" |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | struct cx_properties_config_s { |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | * The key/value delimiter that shall be used. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | * This is '=' by default. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | char delimiter; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | * The character, when appearing at the end of a line, continues that line. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | * This is '\' by default. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | */ |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
54 | // char continuation; // TODO: line continuation in properties |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | * The first comment character. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | * This is '#' by default. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | char comment1; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | * The second comment character. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | * This is not set by default. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | char comment2; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | * The third comment character. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | * This is not set by default. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | char comment3; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | }; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | * Typedef for the properties config. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | typedef struct cx_properties_config_s CxPropertiesConfig; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | * Default properties configuration. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | extern const CxPropertiesConfig cx_properties_config_default; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | * Status codes for the properties interface. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | enum cx_properties_status { |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | * Everything is fine. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | CX_PROPERTIES_NO_ERROR, |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | * The input buffer does not contain more data. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | CX_PROPERTIES_NO_DATA, |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | * The input ends unexpectedly. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | * This either happens when the last line does not terminate with a line |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | * break, or when the input ends with a parsed key but no value. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | CX_PROPERTIES_INCOMPLETE_DATA, |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | * Input buffer is \c NULL. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | CX_PROPERTIES_NULL_INPUT, |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
108 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
109 | * The line contains a delimiter, but no key. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
110 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
111 | CX_PROPERTIES_INVALID_EMPTY_KEY, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
112 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
113 | * The line contains data, but no delimiter. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
114 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
115 | CX_PROPERTIES_INVALID_MISSING_DELIMITER, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
116 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
117 | * More internal buffer was needed, but could not be allocated. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
118 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
119 | CX_PROPERTIES_BUFFER_ALLOC_FAILED, |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | }; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | * Interface for working with properties data. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | struct cx_properties_s { |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | * The configuration. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | CxPropertiesConfig config; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | * The text buffer. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | const char *text; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | /** |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
137 | * Size of the text buffer. |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | */ |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
139 | size_t text_size; |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | * Position in the text buffer. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | size_t text_pos; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
145 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
146 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
147 | * Temporary internal buffer. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
148 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
149 | char *buf; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
150 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
151 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
152 | * Size of the internal buffer. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
153 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
154 | size_t buf_size; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
155 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
156 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
157 | * Capacity of the internal buffer. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
158 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
159 | size_t buf_capacity; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
160 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
161 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
162 | * Internal flags. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
163 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
164 | int flags; |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | }; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | * Typedef for the properties interface. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | typedef struct cx_properties_s CxProperties; |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | /** |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
174 | * Initialize a properties interface. |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
176 | * @param prop the properties interface |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | * @param config the properties configuration |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | * @see cxPropertiesInitDefault() |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | */ |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
180 | __attribute__((__nonnull__)) |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
181 | void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
182 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
183 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
184 | * Destroys the properties interface. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
185 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
186 | * \note Even when you are certain that you did not use the interface in a |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
187 | * way that caused a memory allocation, you should call this function anyway. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
188 | * Future versions of the library might add features that need additional memory |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
189 | * and you really don't want to search the entire code where you might need |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
190 | * add call to this function. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
191 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
192 | * @param prop the properties interface |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
193 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
194 | __attribute__((__nonnull__)) |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
195 | void cxPropertiesDestroy(CxProperties *prop); |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | * Initialize a properties parser with the default configuration. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | * @param prop the properties interface |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | * @see cxPropertiesInit() |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | #define cxPropertiesInitDefault(prop) \ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | cxPropertiesInit(prop, cx_properties_config_default) |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | * Sets an input buffer. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | * After calling this function, you can parse the data by calling |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | * cxPropertiesNext() until the status is #CX_PROPERTIES_NO_DATA. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | * @param prop the properties interface |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | * @param buf a pointer to data |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | * @param len the length of the data |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | __attribute__((__nonnull__)) |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
217 | void cxPropertiesInput( |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | CxProperties *prop, |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
219 | const char *buf, |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | size_t len |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
221 | ); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
222 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
223 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
224 | * Sets a new input buffer after copying the current unprocessed data |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
225 | * to a temporary buffer. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
226 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
227 | * This temporary buffer is allocated on the heap, unless you specified |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
228 | * a buffer on the stack with #cxPropertiesUseStack(). |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
229 | * In that case, the stack buffer is used, until the capacity is not sufficient |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
230 | * anymore. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
231 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
232 | * When this function is called without any unprocessed data that needs to be |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
233 | * copied, it behaves exactly as #cxPropertiesInput(). |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
234 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
235 | * @param prop the properties interface |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
236 | * @param buf a pointer to data |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
237 | * @param len the length of the data |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
238 | * @return non-zero when a memory allocation was necessary but failed |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
239 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
240 | __attribute__((__nonnull__)) |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
241 | int cxPropertiesFill( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
242 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
243 | const char *buf, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
244 | size_t len |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
245 | ); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
246 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
247 | /** |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
248 | * Specifies stack memory that shall be used by #cxPropertiesFill(). |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
249 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
250 | * @param prop the properties interface |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
251 | * @param buf a pointer to stack memory |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
252 | * @param capacity the capacity of the stack memory |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
253 | */ |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
254 | void cxPropertiesUseStack( |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
255 | CxProperties *prop, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
256 | char *buf, |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
257 | size_t capacity |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
258 | ); |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | /** |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | * Retrieves the next key/value-pair. |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | * |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
263 | * This function returns zero as long as there are key/value-pairs found. |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
264 | * If no more key/value-pairs are found, #CX_PROPERTIES_NO_DATA is returned. |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
265 | * |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
266 | * When an incomplete line is encountered, #CX_PROPERTIES_INCOMPLETE_DATA is |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
267 | * returned and the position of the input buffer will be the start of the |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
268 | * affected line. You can then add more data with #cxPropertiesFill(). |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
269 | * |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
270 | * \attention The returned strings will point into a buffer that might not be |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
271 | * available later. It is strongly recommended to copy the strings for further |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
272 | * use. |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | * |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | * @param prop the properties interface |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
275 | * @param key a pointer to the cxstring that shall contain the property name |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | * @param value a pointer to the cxstring that shall contain the property value |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
277 | * @return the status code as defined above |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
278 | * @see cxPropertiesFill() |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | */ |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
280 | enum cx_properties_status cxPropertiesNext( |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
281 | CxProperties *prop, |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
923
diff
changeset
|
282 | cxstring *key, |
923
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | cxstring *value |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | ); |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | |
45da884269c8
add ucx2.1 style interface for a properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
286 | #endif // UCX_PROPERTIES |