universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: ucx: /home/mike/workspace/c/ucx/src/ucx/properties.h File Reference universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
ucx universe@390:
universe@390:
UAP Common Extensions
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390:
universe@390: universe@390:
universe@390: universe@390: universe@390:
universe@390:
universe@390:
universe@390: Data Structures | universe@390: Functions
universe@390:
universe@390:
properties.h File Reference
universe@390:
universe@390:
universe@390: universe@390:

Load / store utilities for properties files. universe@390: More...

universe@390:
#include "ucx.h"
universe@390: #include "map.h"
universe@390:
universe@390:

Go to the source code of this file.

universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Data Structures

struct  UcxProperties
 UcxProperties object for parsing properties data. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Functions

UcxPropertiesucx_properties_new ()
 Constructs a new UcxProperties object. More...
 
void ucx_properties_free (UcxProperties *prop)
 Destroys a UcxProperties object. More...
 
void ucx_properties_fill (UcxProperties *prop, char *buf, size_t len)
 Sets the input buffer for the properties parser. More...
 
int ucx_properties_next (UcxProperties *prop, sstr_t *name, sstr_t *value)
 Retrieves the next key/value-pair. More...
 
int ucx_properties2map (UcxProperties *prop, UcxMap *map)
 Retrieves all available key/value-pairs and puts them into a UcxMap. More...
 
int ucx_properties_load (UcxMap *map, FILE *file)
 Loads a properties file to a UcxMap. More...
 
int ucx_properties_store (UcxMap *map, FILE *file)
 Stores a UcxMap to a file. More...
 
universe@390:

Detailed Description

universe@390:

Load / store utilities for properties files.

universe@390:
Author
Mike Becker
universe@390:
universe@390: Olaf Wintermann
universe@390:

Function Documentation

universe@390: universe@390:

◆ ucx_properties2map()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int ucx_properties2map (UcxPropertiesprop,
UcxMapmap 
)
universe@390:
universe@390: universe@390:

Retrieves all available key/value-pairs and puts them into a UcxMap.

universe@390:

This is done by successive calls to ucx_properties_next() until no more key/value-pairs can be retrieved.

universe@390:

The memory for the map values is allocated by the map's own allocator.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
propthe UcxProperties object
mapthe target map
universe@390:
universe@390:
universe@390:
Returns
The UcxProperties.error code (i.e. 0 on success).
universe@390:
See also
ucx_properties_fill()
universe@390:
universe@390: UcxMap.allocator
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_properties_fill()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_properties_fill (UcxPropertiesprop,
char * buf,
size_t len 
)
universe@390:
universe@390: universe@390:

Sets the input buffer for the properties parser.

universe@390:

After calling this function, you may parse the data by calling ucx_properties_next() until it returns 0. The function ucx_properties2map() is a convenience function that reads as much data as possible by using this function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
propthe UcxProperties object
bufa pointer to the new buffer
lenthe payload length of the buffer
universe@390:
universe@390:
universe@390:
See also
ucx_properties_next()
universe@390:
universe@390: ucx_properties2map()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_properties_free()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_properties_free (UcxPropertiesprop)
universe@390:
universe@390: universe@390:

Destroys a UcxProperties object.

universe@390:
Parameters
universe@390: universe@390: universe@390:
propthe UcxProperties object to destroy
universe@390:
universe@390:
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_properties_load()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int ucx_properties_load (UcxMapmap,
FILE * file 
)
universe@390:
universe@390: universe@390:

Loads a properties file to a UcxMap.

universe@390:

This is a convenience function that reads data from an input stream until the end of the stream is reached.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
mapthe map object to write the key/value-pairs to
filethe FILE* stream to read from
universe@390:
universe@390:
universe@390:
Returns
0 on success, or a non-zero value on error
universe@390:
See also
ucx_properties_fill()
universe@390:
universe@390: ucx_properties2map()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_properties_new()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxProperties* ucx_properties_new ()
universe@390:
universe@390: universe@390:

Constructs a new UcxProperties object.

universe@390:
Returns
a pointer to the new UcxProperties object
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_properties_next()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int ucx_properties_next (UcxPropertiesprop,
sstr_tname,
sstr_tvalue 
)
universe@390:
universe@390: universe@390:

Retrieves the next key/value-pair.

universe@390:

This function returns a nonzero value as long as there are key/value-pairs found. If no more key/value-pairs are found, you may refill the input buffer with ucx_properties_fill().

universe@390:

Attention: the sstr_t.ptr pointers of the output parameters point to memory within the input buffer of the parser and will get invalid some time. If you want long term copies of the key/value-pairs, use sstrdup() after calling this function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
propthe UcxProperties object
namea pointer to the sstr_t that shall contain the property name
valuea pointer to the sstr_t that shall contain the property value
universe@390:
universe@390:
universe@390:
Returns
Nonzero, if a key/value-pair was successfully retrieved
universe@390:
See also
ucx_properties_fill()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_properties_store()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int ucx_properties_store (UcxMapmap,
FILE * file 
)
universe@390:
universe@390: universe@390:

Stores a UcxMap to a file.

universe@390:

The key/value-pairs are written by using the following format:

universe@390:

[key] = [value]\n

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
mapthe map to store
filethe FILE* stream to write to
universe@390:
universe@390:
universe@390:
Returns
0 on success, or a non-zero value on error
universe@390: universe@390:
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: