ucx
UAP Common Extensions
properties.h
Go to the documentation of this file.
1 /*
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3  *
4  * Copyright 2017 Mike Becker, 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  */
37 #ifndef UCX_PROPERTIES_H
38 #define UCX_PROPERTIES_H
39 
40 #include "ucx.h"
41 #include "map.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
53 typedef struct {
58  char *buffer;
59 
64  size_t buflen;
65 
70  size_t pos;
71 
76  char *tmp;
77 
82  size_t tmplen;
83 
88  size_t tmpcap;
89 
95  int error;
96 
101  char delimiter;
102 
107  char comment1;
108 
113  char comment2;
114 
119  char comment3;
120 } UcxProperties;
121 
122 
128 
134 
150 void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len);
151 
170 int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value);
171 
186 int ucx_properties2map(UcxProperties *prop, UcxMap *map);
187 
201 int ucx_properties_load(UcxMap *map, FILE *file);
202 
214 int ucx_properties_store(UcxMap *map, FILE *file);
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif /* UCX_PROPERTIES_H */
221 
The UCX string structure.
Definition: string.h:90
UcxProperties * ucx_properties_new()
Constructs a new UcxProperties object.
Definition: properties.c:35
char comment3
The third comment character.
Definition: properties.h:119
Main UCX Header providing most common definitions.
size_t pos
Current buffer position (don't set manually).
Definition: properties.h:70
char comment2
The second comment character.
Definition: properties.h:113
int ucx_properties_load(UcxMap *map, FILE *file)
Loads a properties file to a UcxMap.
Definition: properties.c:222
UcxProperties object for parsing properties data.
Definition: properties.h:53
size_t buflen
Length of the input buffer (don't set manually).
Definition: properties.h:64
char * buffer
Input buffer (don't set manually).
Definition: properties.h:58
int error
Parser error code.
Definition: properties.h:95
size_t tmplen
Internal temporary buffer length (don't set manually).
Definition: properties.h:82
char comment1
The first comment character.
Definition: properties.h:107
int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value)
Retrieves the next key/value-pair.
Definition: properties.c:80
int ucx_properties2map(UcxProperties *prop, UcxMap *map)
Retrieves all available key/value-pairs and puts them into a UcxMap.
Definition: properties.c:200
char delimiter
The delimiter that shall be used.
Definition: properties.h:101
char * tmp
Internal temporary buffer (don't set manually).
Definition: properties.h:76
Structure for the UCX map.
Definition: map.h:81
size_t tmpcap
Internal temporary buffer capacity (don't set manually).
Definition: properties.h:88
Hash map implementation.
void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len)
Sets the input buffer for the properties parser.
Definition: properties.c:64
int ucx_properties_store(UcxMap *map, FILE *file)
Stores a UcxMap to a file.
Definition: properties.c:242
void ucx_properties_free(UcxProperties *prop)
Destroys a UcxProperties object.
Definition: properties.c:57