ucx/properties.h

changeset 130
633f15ce2ee4
parent 120
8170f658f017
child 133
0a70e0d36949
equal deleted inserted replaced
129:61edec666928 130:633f15ce2ee4
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 /**
29 * @file properties.h
30 *
31 * Load / store utilities for properties files.
32 *
33 * @author Mike Becker
34 * @author Olaf Wintermann
35 */
28 36
29 #ifndef UCX_PROPERTIES_H 37 #ifndef UCX_PROPERTIES_H
30 #define UCX_PROPERTIES_H 38 #define UCX_PROPERTIES_H
31 39
32 #include "ucx.h" 40 #include "ucx.h"
49 char comment2; 57 char comment2;
50 char comment3; 58 char comment3;
51 } UcxProperties; 59 } UcxProperties;
52 60
53 61
62 /**
63 * Constructs a new UcxProperties object.
64 * @return A pointer to the new UcxProperties object.
65 */
54 UcxProperties *ucx_properties_new(); 66 UcxProperties *ucx_properties_new();
55 void ucx_properties_free(UcxProperties *parser); 67 /**
56 void ucx_properties_fill(UcxProperties *parser, char *buf, size_t len); 68 * Destroys an UcxProperties object.
57 int ucx_properties_next(UcxProperties *parser, sstr_t *name, sstr_t *value); 69 * @param prop The UcxProperties object to destroy.
58 int ucx_properties2map(UcxProperties *parser, UcxMap *map); 70 */
71 void ucx_properties_free(UcxProperties *prop);
72 /**
73 * Refills the input buffer.
74 * @param prop The UcxProperties object.
75 * @param buf A pointer to the new buffer.
76 * @param len The payload length of the buffer.
77 */
78 void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len);
79 int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value);
80 int ucx_properties2map(UcxProperties *prop, UcxMap *map);
59 81
82 /**
83 * Loads a properties file to an UcxMap.
84 *
85 * This is a convenience function that reads chunks of 1 KB from an input
86 * stream until the end of the stream is reached.
87 *
88 * An UcxProperties object is implicitly created and destroyed.
89 *
90 * @param map The map object to write the key/value-pairs to.
91 * @param file The <code>FILE*</code> stream to read from.
92 * @return 0 on success, or a non-zero value on error
93 *
94 * @see ucx_properties_fill()
95 * @see ucx_properties2map()
96 */
60 int ucx_properties_load(UcxMap *map, FILE *file); 97 int ucx_properties_load(UcxMap *map, FILE *file);
98 /**
99 * Stores an UcxMap to a file.
100 *
101 * The key/value-pairs are written by using the following format:
102 *
103 * <code>[key] = [value]\\n</code>
104 *
105 * @param map The map to store.
106 * @param file The <code>FILE*</code> stream to write to.
107 * @return 0 on success, or a non-zero value on error
108 */
61 int ucx_properties_store(UcxMap *map, FILE *file); 109 int ucx_properties_store(UcxMap *map, FILE *file);
62 110
63 #ifdef __cplusplus 111 #ifdef __cplusplus
64 } 112 }
65 #endif 113 #endif

mercurial