docs/Writerside/topics/properties.h.md

Fri, 28 Feb 2025 19:07:47 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 28 Feb 2025 19:07:47 +0100
changeset 1231
a9f9c59e0b63
parent 1230
3ec9cce0de01
permissions
-rw-r--r--

write basic parsing documentation

relates to #451

1143
0559812df10c assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents: 1142
diff changeset
1 # Properties
1142
9437530176bc add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
2
1230
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
3 The UCX properties parser can be used to parse line based key/value strings.
1229
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
4
1190
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
5 <warning>
1229
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
6 New Feature - documentation work in progress!
1190
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
7 </warning>
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
8
1230
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
9 ## Supported Syntax
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
10
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
11 Key/value pairs must be line based and separated by a single character delimter.
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
12 The parser supports up to three different characters which introduce comments.
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
13 All characters starting with a comment character up to the end of the line are ignored.
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
14 Blank lines are also ignored.
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
15
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
16 An example properties file looks like this:
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
17
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
18 ```properties
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
19 # Comment line at start of file
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
20 key1 = value1
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
21 key2 = value2
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
22 # next is a blank line and will be ignored
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
23
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
24 keys_are_trimmed = and_so_are_values # also a comment
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
25 ```
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
26
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
27 > Delimiter and comment characters are configured with the `CxPropertiesConfig` structure.
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
28 > There is also a field reserved for `continuation` which will be used as a line continuation character
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
29 > in a future version of UCX.
3ec9cce0de01 add information about supported properties syntax
Mike Becker <universe@uap-core.de>
parents: 1229
diff changeset
30 > In UCX 3.1 this is not implemented.
1229
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
31
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
32 ## Basic Parsing
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
33
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
34 ```C
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
35 #include <cx/properties.h>
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
36
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
37 typedef struct cx_properties_config_s {
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
38 char delimiter;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
39 char comment1;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
40 char comment2;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
41 char comment3;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
42 // reserved for future use - not implemented in UCX 3.1
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
43 char continuation;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
44 } CxPropertiesConfig;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
45
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
46 void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
47
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
48 void cxPropertiesInitDefault(CxProperties *prop);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
49
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
50 void cxPropertiesDestroy(CxProperties *prop);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
51
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
52 void cxPropertiesReset(CxProperties *prop);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
53
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
54 int cxPropertiesFilln(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
55 const char *buf, size_t len);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
56
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
57 // where S is one of cxstring, cxmutstr, char*, const char*
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
58 int cxPropertiesFill(CxProperties *prop, S string);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
59
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
60 CxPropertiesStatus cxPropertiesNext(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
61 cxstring *key, cxstring *value);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
62
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
63 void cxPropertiesUseStack(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
64 char *buf, size_t capacity);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
65 ```
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
66
1231
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
67 The first step is to initialize a `CxProperties` structure with a call to `cxPropertiesInit()` using the desired config.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
68 The shorthand `cxPropertiesInitDefault()` creates a default configuration with the equals sign `'='` as delimiter
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
69 and the hash-symbol `'#'` as comment symbol (the other two comment symbols remain unused in the default config).
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
70
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
71 > In a future UCX version, the default `continuation` character will be a backslash `'\'`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
72 > In UCX 3.1 this feature is not implemented, yet.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
73
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
74 The actual parsing is an interleaving invocation of the `cxPropertiesFill()` (or `cxPropertiesFilln()`) and `cxPropertiesNext()` functions.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
75 The `cxPropertiesFill()` function is a convenience function, that accepts UCX strings and normal zero-terminated C strings and behaves otherwise like `cxPropertiesFilln()`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
76
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
77 Filling the input buffer is cost-free if there is no data already in the input buffer.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
78 In that case, the input buffer only stores the pointer to the original data without creating a copy.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
79 Calling `cxPropertiesNext()` will return with `CX_PROPERTIES_NO_ERROR` (= zero) for each key/value-pair that is successfully parsed,
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
80 and stores the pointers and lengths for both the key and the value into the structures pointed to by the `key` and `value` arguments.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
81
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
82 > This is all still free of any copies and allocations.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
83 > That means, the pointers in `key` and `value` after `cxPropertiesNext()` returns will point into the input buffer.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
84 > If you intend to store the key and/or the value somewhere else, it is strongly recommended to create a copy with `cx_strdup()`,
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
85 > because you will otherwise soon end up with a dangling pointer.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
86 > {style="note"}
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
87
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
88 If `cxPropertiesNext()` returns `CX_PROPERTIES_INCOMPLETE_DATA` it means that the input buffer is exhausted,
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
89 but the last line did not contain a full key/value pair.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
90 In that case, you can call `cxPropertiesFill()` again to add more data and continue with `cxPropertiesNext()`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
91
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
92 Note, that adding more data to a non-empty input buffer will lead to an allocation,
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
93 unless you specified some stack memory with `cxPropertiesUseStack()`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
94 The stack capacity must be large enough to contain the longest line in your data.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
95 If the internal buffer is not large enough to contain a single line, it is extended.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
96 If that is not possible for some reason, `cxPropertiesNext()` fails and returns `CX_PROPERTIES_BUFFER_ALLOC_FAILED`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
97
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
98 If you want to reuse a `CxProperties` structure with the same config, you can call `cxPropertiesReset()`, even if the last operation was a failure.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
99 Otherwise, you should always call `cxPropertiesDestroy()` when you are done with the parser.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
100
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
101 > It is strongly recommended to always call `cxPropertiesDestroy` when you are done with the parser,
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
102 > even if you did not expect any allocations because you used `cxPropertiesUseStack()`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
103
1229
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
104 ### List of Status Codes
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
105
1231
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
106 Below is a full list of error codes for `cxPropertiesNext()`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
107
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
108 | Status Code | Meaning |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
109 |-----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
110 | CX_PROPERTIES_NO_ERROR | A key/value pair was found and returned. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
111 | CX_PROPERTIES_NO_DATA | The input buffer does not contain more data. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
112 | CX_PROPERTIES_INCOMPLETE_DATA | The input ends unexpectedly. This can happen when the last line does not terminate with a line break, or when the input ends with a parsed key but no value. Use `cxPropertiesFill()` to add more data before retrying. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
113 | CX_PROPERTIES_NULL_INPUT | The input buffer was never initialized. Probably you forgot to call `cxPropertiesFill()` at least once. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
114 | CX_PROPERTIES_INVALID_EMPTY_KEY | Only white-spaces were found on the left hand-side of the delimiter. Keys must not be empty. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
115 | CX_PROPERTIES_INVALID_MISSING_DELIMITER | A line contains data, but no delimiter. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
116 | CX_PROPERTIES_BUFFER_ALLOC_FAILED | More internal buffer was needed, but could not be allocated. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
117
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
118
1229
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
119 ## Sources and Sinks
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
120
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
121 ```C
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
122 #include <cx/properties.h>
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
123
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
124 CxPropertiesSource
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
125 cxPropertiesStringSource(cxstring str);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
126
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
127 CxPropertiesSource
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
128 cxPropertiesCstrSource(const char *str);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
129
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
130 CxPropertiesSource
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
131 cxPropertiesCstrnSource(const char *str, size_t len);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
132
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
133 CxPropertiesSource
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
134 cxPropertiesFileSource(FILE *file, size_t chunk_size);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
135
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
136 CxPropertiesSink
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
137 cxPropertiesMapSink(CxMap *map);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
138
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
139 CxPropertiesStatus
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
140 cxPropertiesLoad(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
141 CxPropertiesSink sink, CxPropertiesSource source);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
142 ```
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
143
1231
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
144 <warning>
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
145 TODO: write documentation
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
146 </warning>
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
147
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
148 ### Additional Status Codes
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
149
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
150 For sources and sinks there are three additional special status codes,
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
151 which only appear as return values for `cxPropertiesLoad()`.
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
152
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
153 | Status Code | Meaning |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
154 |-----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
155 | CX_PROPERTIES_READ_INIT_FAILED | Initializing the properties source failed and the `cx_properties_read_init_func` returned non-zero. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
156 | CX_PROPERTIES_READ_FAILED | Reading from a properties source failed and the `cx_properties_read_func` returned non-zero. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
157 | CX_PROPERTIES_SINK_FAILED | Sinking a key/value-pair failed and the `cx_properties_sink_func` returned non-zero. |
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
158
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
159
1229
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
160 ### Creating own Sources and Sinks
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
161
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
162 ```C
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
163 #include <cx/properties.h>
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
164
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
165 typedef int(*cx_properties_read_init_func)(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
166 CxPropertiesSource *src);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
167
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
168 typedef int(*cx_properties_read_func)(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
169 CxPropertiesSource *src, cxstring *target);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
170
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
171 typedef void(*cx_properties_read_clean_func)(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
172 CxPropertiesSource *src);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
173
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
174 typedef int(*cx_properties_sink_func)(CxProperties *prop,
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
175 CxPropertiesSink *sink, cxstring key, cxstring value);
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
176
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
177 typedef struct cx_properties_source_s {
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
178 void *src;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
179 void *data_ptr;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
180 size_t data_size;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
181 cx_properties_read_func read_func;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
182 cx_properties_read_init_func read_init_func;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
183 cx_properties_read_clean_func read_clean_func;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
184 } CxPropertiesSource;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
185
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
186 typedef struct cx_properties_sink_s {
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
187 void *sink;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
188 void *data;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
189 cx_properties_sink_func sink_func;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
190 } CxPropertiesSink;
9899043d7e39 basic structure for properties docu
Mike Becker <universe@uap-core.de>
parents: 1190
diff changeset
191 ```
1190
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
192
1231
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
193 <warning>
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
194 TODO: write documentation
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
195 </warning>
a9f9c59e0b63 write basic parsing documentation
Mike Becker <universe@uap-core.de>
parents: 1230
diff changeset
196
1190
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
197 <seealso>
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
198 <category ref="apidoc">
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
199 <a href="https://ucx.sourceforge.io/api/properties_8h.html">properties.h</a>
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
200 </category>
a7b913d5d589 bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents: 1143
diff changeset
201 </seealso>

mercurial