src/ucx/properties.h

Sat, 21 Jan 2017 17:05:23 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 21 Jan 2017 17:05:23 +0100
changeset 153
85320d8b5d5c
parent 135
471e28cca288
permissions
-rw-r--r--

fixes solaris build

91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
4 * Copyright 2016 Olaf Wintermann. All rights reserved.
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
fac51f87def0 ucx update
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
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 * @file properties.h
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * Load / store utilities for properties files.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 * @author Mike Becker
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 * @author Olaf Wintermann
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #ifndef UCX_PROPERTIES_H
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #define UCX_PROPERTIES_H
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "ucx.h"
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "map.h"
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #ifdef __cplusplus
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 extern "C" {
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #endif
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 * UcxProperties object for parsing properties data.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 * Most of the fields are for internal use only. You may configure the
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 * properties parser, e.g. by changing the used delimiter or specifying
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 * up to three different characters that shall introduce comments.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 typedef struct {
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 * Input buffer (don't set manually).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 * Automatically set by calls to ucx_properties_fill().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 char *buffer;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 * Length of the input buffer (don't set manually).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 * Automatically set by calls to ucx_properties_fill().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 size_t buflen;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 * Current buffer position (don't set manually).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 * Used by ucx_properties_next().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 size_t pos;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 * Internal temporary buffer (don't set manually).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 * Used by ucx_properties_next().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 char *tmp;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 * Internal temporary buffer length (don't set manually).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 * Used by ucx_properties_next().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 size_t tmplen;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 * Internal temporary buffer capacity (don't set manually).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 * Used by ucx_properties_next().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 size_t tmpcap;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 * Parser error code.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 * This is always 0 on success and a nonzero value on syntax errors.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 * The value is set by ucx_properties_next().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 int error;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 * The delimiter that shall be used.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 * This is '=' by default.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 char delimiter;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 * The first comment character.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 * This is '#' by default.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 char comment1;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 * The second comment character.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 * This is not set by default.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 char comment2;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 * The third comment character.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 * This is not set by default.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 char comment3;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 } UcxProperties;
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 * Constructs a new UcxProperties object.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 * @return a pointer to the new UcxProperties object
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 UcxProperties *ucx_properties_new();
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 /**
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
130 * Destroys a UcxProperties object.
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 * @param prop the UcxProperties object to destroy
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 void ucx_properties_free(UcxProperties *prop);
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 * Sets the input buffer for the properties parser.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 * After calling this function, you may parse the data by calling
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 * ucx_properties_next() until it returns 0. The function ucx_properties2map()
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
140 * is a convenience function that reads as much data as possible by using this
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
141 * function.
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 * @param prop the UcxProperties object
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 * @param buf a pointer to the new buffer
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 * @param len the payload length of the buffer
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 * @see ucx_properties_next()
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 * @see ucx_properties2map()
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len);
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 /**
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 * Retrieves the next key/value-pair.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 * This function returns a nonzero value as long as there are key/value-pairs
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 * found. If no more key/value-pairs are found, you may refill the input buffer
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 * with ucx_properties_fill().
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 * <b>Attention:</b> the sstr_t.ptr pointers of the output parameters point to
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 * memory within the input buffer of the parser and will get invalid some time.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 * If you want long term copies of the key/value-pairs, use sstrdup() after
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 * calling this function.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 * @param prop the UcxProperties object
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 * @param name a pointer to the sstr_t that shall contain the property name
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 * @param value a pointer to the sstr_t that shall contain the property value
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 * @return Nonzero, if a key/value-pair was successfully retrieved
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 * @see ucx_properties_fill()
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value);
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 /**
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
173 * Retrieves all available key/value-pairs and puts them into a UcxMap.
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 * This is done by successive calls to ucx_properties_next() until no more
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 * key/value-pairs can be retrieved.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 * @param prop the UcxProperties object
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 * @param map the target map
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 * @return The UcxProperties.error code (i.e. 0 on success).
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 * @see ucx_properties_fill()
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 int ucx_properties2map(UcxProperties *prop, UcxMap *map);
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 /**
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
186 * Loads a properties file to a UcxMap.
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 *
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
188 * This is a convenience function that reads data from an input
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 * stream until the end of the stream is reached.
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 * @param map the map object to write the key/value-pairs to
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 * @param file the <code>FILE*</code> stream to read from
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 * @return 0 on success, or a non-zero value on error
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 * @see ucx_properties_fill()
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 * @see ucx_properties2map()
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 int ucx_properties_load(UcxMap *map, FILE *file);
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 /**
135
471e28cca288 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 99
diff changeset
201 * Stores a UcxMap to a file.
91
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 * The key/value-pairs are written by using the following format:
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 * <code>[key] = [value]\\n</code>
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 *
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 * @param map the map to store
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 * @param file the <code>FILE*</code> stream to write to
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 * @return 0 on success, or a non-zero value on error
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 int ucx_properties_store(UcxMap *map, FILE *file);
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 #ifdef __cplusplus
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 }
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 #endif
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 #endif /* UCX_PROPERTIES_H */
fac51f87def0 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218

mercurial