ucx/properties.h

Mon, 05 Aug 2013 14:38:37 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 05 Aug 2013 14:38:37 +0200
changeset 130
633f15ce2ee4
parent 120
8170f658f017
child 133
0a70e0d36949
permissions
-rw-r--r--

started documentation of UcxProperties + some fixes

olaf@108 1 /*
olaf@108 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
olaf@108 3 *
olaf@108 4 * Copyright 2013 Olaf Wintermann. All rights reserved.
olaf@108 5 *
olaf@108 6 * Redistribution and use in source and binary forms, with or without
olaf@108 7 * modification, are permitted provided that the following conditions are met:
olaf@108 8 *
olaf@108 9 * 1. Redistributions of source code must retain the above copyright
olaf@108 10 * notice, this list of conditions and the following disclaimer.
olaf@108 11 *
olaf@108 12 * 2. Redistributions in binary form must reproduce the above copyright
olaf@108 13 * notice, this list of conditions and the following disclaimer in the
olaf@108 14 * documentation and/or other materials provided with the distribution.
olaf@108 15 *
olaf@108 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
olaf@108 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
olaf@108 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
olaf@108 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
olaf@108 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
olaf@108 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
olaf@108 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
olaf@108 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
olaf@108 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
olaf@108 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
olaf@108 26 * POSSIBILITY OF SUCH DAMAGE.
olaf@108 27 */
universe@130 28 /**
universe@130 29 * @file properties.h
universe@130 30 *
universe@130 31 * Load / store utilities for properties files.
universe@130 32 *
universe@130 33 * @author Mike Becker
universe@130 34 * @author Olaf Wintermann
universe@130 35 */
olaf@108 36
olaf@120 37 #ifndef UCX_PROPERTIES_H
olaf@120 38 #define UCX_PROPERTIES_H
olaf@108 39
olaf@108 40 #include "ucx.h"
olaf@108 41 #include "map.h"
olaf@108 42
olaf@108 43 #ifdef __cplusplus
olaf@108 44 extern "C" {
olaf@108 45 #endif
olaf@108 46
olaf@108 47 typedef struct {
olaf@108 48 char *buffer;
olaf@108 49 size_t buflen;
olaf@108 50 size_t pos;
olaf@108 51 char *tmp;
olaf@108 52 size_t tmplen;
olaf@108 53 size_t tmpcap;
olaf@109 54 int error;
olaf@108 55 char delimiter;
olaf@108 56 char comment1;
olaf@108 57 char comment2;
olaf@108 58 char comment3;
olaf@110 59 } UcxProperties;
olaf@108 60
olaf@108 61
universe@130 62 /**
universe@130 63 * Constructs a new UcxProperties object.
universe@130 64 * @return A pointer to the new UcxProperties object.
universe@130 65 */
olaf@110 66 UcxProperties *ucx_properties_new();
universe@130 67 /**
universe@130 68 * Destroys an UcxProperties object.
universe@130 69 * @param prop The UcxProperties object to destroy.
universe@130 70 */
universe@130 71 void ucx_properties_free(UcxProperties *prop);
universe@130 72 /**
universe@130 73 * Refills the input buffer.
universe@130 74 * @param prop The UcxProperties object.
universe@130 75 * @param buf A pointer to the new buffer.
universe@130 76 * @param len The payload length of the buffer.
universe@130 77 */
universe@130 78 void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len);
universe@130 79 int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value);
universe@130 80 int ucx_properties2map(UcxProperties *prop, UcxMap *map);
olaf@109 81
universe@130 82 /**
universe@130 83 * Loads a properties file to an UcxMap.
universe@130 84 *
universe@130 85 * This is a convenience function that reads chunks of 1 KB from an input
universe@130 86 * stream until the end of the stream is reached.
universe@130 87 *
universe@130 88 * An UcxProperties object is implicitly created and destroyed.
universe@130 89 *
universe@130 90 * @param map The map object to write the key/value-pairs to.
universe@130 91 * @param file The <code>FILE*</code> stream to read from.
universe@130 92 * @return 0 on success, or a non-zero value on error
universe@130 93 *
universe@130 94 * @see ucx_properties_fill()
universe@130 95 * @see ucx_properties2map()
universe@130 96 */
olaf@109 97 int ucx_properties_load(UcxMap *map, FILE *file);
universe@130 98 /**
universe@130 99 * Stores an UcxMap to a file.
universe@130 100 *
universe@130 101 * The key/value-pairs are written by using the following format:
universe@130 102 *
universe@130 103 * <code>[key] = [value]\\n</code>
universe@130 104 *
universe@130 105 * @param map The map to store.
universe@130 106 * @param file The <code>FILE*</code> stream to write to.
universe@130 107 * @return 0 on success, or a non-zero value on error
universe@130 108 */
olaf@109 109 int ucx_properties_store(UcxMap *map, FILE *file);
olaf@108 110
olaf@108 111 #ifdef __cplusplus
olaf@108 112 }
olaf@108 113 #endif
olaf@108 114
olaf@120 115 #endif /* UCX_PROPERTIES_H */
olaf@108 116

mercurial