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

     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2013 Olaf Wintermann. All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions are met:
     8  *
     9  *   1. Redistributions of source code must retain the above copyright
    10  *      notice, this list of conditions and the following disclaimer.
    11  *
    12  *   2. Redistributions in binary form must reproduce the above copyright
    13  *      notice, this list of conditions and the following disclaimer in the
    14  *      documentation and/or other materials provided with the distribution.
    15  *
    16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    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
    26  * POSSIBILITY OF SUCH DAMAGE.
    27  */
    28 /**
    29  * @file properties.h
    30  * 
    31  * Load / store utilities for properties files.
    32  * 
    33  * @author Mike Becker
    34  * @author Olaf Wintermann
    35  */
    37 #ifndef UCX_PROPERTIES_H
    38 #define	UCX_PROPERTIES_H
    40 #include "ucx.h"
    41 #include "map.h"
    43 #ifdef	__cplusplus
    44 extern "C" {
    45 #endif
    47 typedef struct {
    48     char   *buffer;
    49     size_t buflen;
    50     size_t pos;
    51     char   *tmp;
    52     size_t tmplen;
    53     size_t tmpcap;
    54     int    error;
    55     char   delimiter;
    56     char   comment1;
    57     char   comment2;
    58     char   comment3;
    59 } UcxProperties;
    62 /**
    63  * Constructs a new UcxProperties object.
    64  * @return A pointer to the new UcxProperties object.
    65  */
    66 UcxProperties *ucx_properties_new();
    67 /**
    68  * Destroys an UcxProperties object.
    69  * @param prop The UcxProperties object to destroy.
    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);
    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  */
    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  */
   109 int ucx_properties_store(UcxMap *map, FILE *file);
   111 #ifdef	__cplusplus
   112 }
   113 #endif
   115 #endif	/* UCX_PROPERTIES_H */

mercurial