ucx/properties.h

changeset 152
62921b370c60
parent 124
80609f9675f1
equal deleted inserted replaced
151:11f3bb408051 152:62921b370c60
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2015 Olaf Wintermann. All rights reserved. 4 * Copyright 2016 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
125 * @return a pointer to the new UcxProperties object 125 * @return a pointer to the new UcxProperties object
126 */ 126 */
127 UcxProperties *ucx_properties_new(); 127 UcxProperties *ucx_properties_new();
128 128
129 /** 129 /**
130 * Destroys an UcxProperties object. 130 * Destroys a UcxProperties object.
131 * @param prop the UcxProperties object to destroy 131 * @param prop the UcxProperties object to destroy
132 */ 132 */
133 void ucx_properties_free(UcxProperties *prop); 133 void ucx_properties_free(UcxProperties *prop);
134 134
135 /** 135 /**
136 * Sets the input buffer for the properties parser. 136 * Sets the input buffer for the properties parser.
137 * 137 *
138 * After calling this function, you may parse the data by calling 138 * After calling this function, you may parse the data by calling
139 * ucx_properties_next() until it returns 0. The function ucx_properties2map() 139 * ucx_properties_next() until it returns 0. The function ucx_properties2map()
140 * is a convenience function that performs these successive calls of 140 * is a convenience function that reads as much data as possible by using this
141 * ucx_properties_next() within a while loop and puts the properties to a map. 141 * function.
142 * 142 *
143 * 143 *
144 * @param prop the UcxProperties object 144 * @param prop the UcxProperties object
145 * @param buf a pointer to the new buffer 145 * @param buf a pointer to the new buffer
146 * @param len the payload length of the buffer 146 * @param len the payload length of the buffer
168 * @see ucx_properties_fill() 168 * @see ucx_properties_fill()
169 */ 169 */
170 int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value); 170 int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value);
171 171
172 /** 172 /**
173 * Retrieves all available key/value-pairs and puts them into an UcxMap. 173 * Retrieves all available key/value-pairs and puts them into a UcxMap.
174 * 174 *
175 * This is done by successive calls to ucx_properties_next() until no more 175 * This is done by successive calls to ucx_properties_next() until no more
176 * key/value-pairs can be retrieved. 176 * key/value-pairs can be retrieved.
177 * 177 *
178 * @param prop the UcxProperties object 178 * @param prop the UcxProperties object
181 * @see ucx_properties_fill() 181 * @see ucx_properties_fill()
182 */ 182 */
183 int ucx_properties2map(UcxProperties *prop, UcxMap *map); 183 int ucx_properties2map(UcxProperties *prop, UcxMap *map);
184 184
185 /** 185 /**
186 * Loads a properties file to an UcxMap. 186 * Loads a properties file to a UcxMap.
187 * 187 *
188 * This is a convenience function that reads chunks of 1 KB from an input 188 * This is a convenience function that reads data from an input
189 * stream until the end of the stream is reached. 189 * stream until the end of the stream is reached.
190 *
191 * An UcxProperties object is implicitly created and destroyed.
192 * 190 *
193 * @param map the map object to write the key/value-pairs to 191 * @param map the map object to write the key/value-pairs to
194 * @param file the <code>FILE*</code> stream to read from 192 * @param file the <code>FILE*</code> stream to read from
195 * @return 0 on success, or a non-zero value on error 193 * @return 0 on success, or a non-zero value on error
196 * 194 *
198 * @see ucx_properties2map() 196 * @see ucx_properties2map()
199 */ 197 */
200 int ucx_properties_load(UcxMap *map, FILE *file); 198 int ucx_properties_load(UcxMap *map, FILE *file);
201 199
202 /** 200 /**
203 * Stores an UcxMap to a file. 201 * Stores a UcxMap to a file.
204 * 202 *
205 * The key/value-pairs are written by using the following format: 203 * The key/value-pairs are written by using the following format:
206 * 204 *
207 * <code>[key] = [value]\\n</code> 205 * <code>[key] = [value]\\n</code>
208 * 206 *

mercurial