dictionary.h   dictionary.h 
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@file dictionary.h @file dictionary.h
@author N. Devillard @author N. Devillard
@date Aug 2000 @date Sep 2007
@version $Revision: 1.11 $ @version $Revision: 1.12 $
@brief Implements a dictionary for string variables. @brief Implements a dictionary for string variables.
This module implements a simple dictionary object, i.e. a list This module implements a simple dictionary object, i.e. a list
of string/string associations. This object is useful to store e.g. of string/string associations. This object is useful to store e.g.
informations retrieved from a configuration file (ini files). informations retrieved from a configuration file (ini files).
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
/* /*
$Id: dictionary.h,v 1.11 2002-06-17 09:30:46 ndevilla Exp $ $Id: dictionary.h,v 1.12 2007-11-23 21:37:00 ndevilla Exp $
$Author: ndevilla $ $Author: ndevilla $
$Date: 2002-06-17 09:30:46 $ $Date: 2007-11-23 21:37:00 $
$Revision: 1.11 $ $Revision: 1.12 $
*/ */
#ifndef _DICTIONARY_H_ #ifndef _DICTIONARY_H_
#define _DICTIONARY_H_ #define _DICTIONARY_H_
/*------------------------------------------------------------------------- -- /*------------------------------------------------------------------------- --
Includes Includes
-------------------------------------------------------------------------- -*/ -------------------------------------------------------------------------- -*/
#include <stdio.h> #include <stdio.h>
skipping to change at line 117 skipping to change at line 117
This function locates a key in a dictionary and returns a pointer to its This function locates a key in a dictionary and returns a pointer to its
value, or the passed 'def' pointer if no such key can be found in value, or the passed 'def' pointer if no such key can be found in
dictionary. The returned character pointer points to data internal to the dictionary. The returned character pointer points to data internal to the
dictionary object, you should not try to free it or modify it. dictionary object, you should not try to free it or modify it.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
char * dictionary_get(dictionary * d, char * key, char * def); char * dictionary_get(dictionary * d, char * key, char * def);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Get a value from a dictionary, as a char.
@param d dictionary object to search.
@param key Key to look for in the dictionary.
@param def Default value for the key if not found.
@return char
This function locates a key in a dictionary using dictionary_get,
and returns the first char of the found string.
*/
/*-------------------------------------------------------------------------
-*/
char dictionary_getchar(dictionary * d, char * key, char def) ;
/*-------------------------------------------------------------------------
*/
/**
@brief Get a value from a dictionary, as an int.
@param d dictionary object to search.
@param key Key to look for in the dictionary.
@param def Default value for the key if not found.
@return int
This function locates a key in a dictionary using dictionary_get,
and applies atoi on it to return an int. If the value cannot be found
in the dictionary, the default is returned.
*/
/*-------------------------------------------------------------------------
-*/
int dictionary_getint(dictionary * d, char * key, int def);
/*-------------------------------------------------------------------------
*/
/**
@brief Get a value from a dictionary, as a double.
@param d dictionary object to search.
@param key Key to look for in the dictionary.
@param def Default value for the key if not found.
@return double
This function locates a key in a dictionary using dictionary_get,
and applies atof on it to return a double. If the value cannot be found
in the dictionary, the default is returned.
*/
/*-------------------------------------------------------------------------
-*/
double dictionary_getdouble(dictionary * d, char * key, double def);
/*-------------------------------------------------------------------------
*/
/**
@brief Set a value in a dictionary. @brief Set a value in a dictionary.
@param d dictionary object to modify. @param d dictionary object to modify.
@param key Key to modify or add. @param key Key to modify or add.
@param val Value to add. @param val Value to add.
@return void @return int 0 if Ok, anything else otherwise
If the given key is found in the dictionary, the associated value is If the given key is found in the dictionary, the associated value is
replaced by the provided one. If the key cannot be found in the replaced by the provided one. If the key cannot be found in the
dictionary, it is added to it. dictionary, it is added to it.
It is Ok to provide a NULL value for val, but NULL values for the diction ary It is Ok to provide a NULL value for val, but NULL values for the diction ary
or the key are considered as errors: the function will return immediately or the key are considered as errors: the function will return immediately
in such a case. in such a case.
Notice that if you dictionary_set a variable to NULL, a call to Notice that if you dictionary_set a variable to NULL, a call to
dictionary_get will return a NULL value: the variable will be found, and dictionary_get will return a NULL value: the variable will be found, and
its value (NULL) is returned. In other words, setting the variable its value (NULL) is returned. In other words, setting the variable
content to NULL is equivalent to deleting the variable from the content to NULL is equivalent to deleting the variable from the
dictionary. It is not possible (in this implementation) to have a key in dictionary. It is not possible (in this implementation) to have a key in
the dictionary without value. the dictionary without value.
This function returns non-zero in case of failure.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
void dictionary_set(dictionary * vd, char * key, char * val); int dictionary_set(dictionary * vd, char * key, char * val);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Delete a key in a dictionary @brief Delete a key in a dictionary
@param d dictionary object to modify. @param d dictionary object to modify.
@param key Key to remove. @param key Key to remove.
@return void @return void
This function deletes a key in a dictionary. Nothing is done if the This function deletes a key in a dictionary. Nothing is done if the
key cannot be found. key cannot be found.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
void dictionary_unset(dictionary * d, char * key); void dictionary_unset(dictionary * d, char * key);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Set a key in a dictionary, providing an int.
@param d Dictionary to update.
@param key Key to modify or add
@param val Integer value to store (will be stored as a string).
@return void
This helper function calls dictionary_set() with the provided integer
converted to a string using %d.
*/
/*-------------------------------------------------------------------------
-*/
void dictionary_setint(dictionary * d, char * key, int val);
/*-------------------------------------------------------------------------
*/
/**
@brief Set a key in a dictionary, providing a double.
@param d Dictionary to update.
@param key Key to modify or add
@param val Double value to store (will be stored as a string).
@return void
This helper function calls dictionary_set() with the provided double
converted to a string using %g.
*/
/*-------------------------------------------------------------------------
-*/
void dictionary_setdouble(dictionary * d, char * key, double val);
/*-------------------------------------------------------------------------
*/
/**
@brief Dump a dictionary to an opened file pointer. @brief Dump a dictionary to an opened file pointer.
@param d Dictionary to dump @param d Dictionary to dump
@param f Opened file pointer. @param f Opened file pointer.
@return void @return void
Dumps a dictionary onto an opened file pointer. Key pairs are printed out Dumps a dictionary onto an opened file pointer. Key pairs are printed out
as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr a s as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr a s
output file pointers. output file pointers.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
 End of changes. 8 change blocks. 
89 lines changed or deleted 9 lines changed or added


 iniparser.h   iniparser.h 
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@file iniparser.h @file iniparser.h
@author N. Devillard @author N. Devillard
@date Mar 2000 @date Sep 2007
@version $Revision: 1.23 $ @version 3.0
@brief Parser for ini files. @brief Parser for ini files.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
/* /*
$Id: iniparser.h,v 1.23 2006-09-27 11:03:35 ndevilla Exp $ $Id: iniparser.h,v 1.26 2011-03-02 20:15:13 ndevilla Exp $
$Author: ndevilla $ $Revision: 1.26 $
$Date: 2006-09-27 11:03:35 $
$Revision: 1.23 $
*/ */
#ifndef _INIPARSER_H_ #ifndef _INIPARSER_H_
#define _INIPARSER_H_ #define _INIPARSER_H_
/*------------------------------------------------------------------------- -- /*------------------------------------------------------------------------- --
Includes Includes
-------------------------------------------------------------------------- -*/ -------------------------------------------------------------------------- -*/
#include <stdio.h> #include <stdio.h>
skipping to change at line 108 skipping to change at line 106
This function prints out the contents of a dictionary, one element by This function prints out the contents of a dictionary, one element by
line, onto the provided file pointer. It is OK to specify @c stderr line, onto the provided file pointer. It is OK to specify @c stderr
or @c stdout as output files. This function is meant for debugging or @c stdout as output files. This function is meant for debugging
purposes mostly. purposes mostly.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
void iniparser_dump(dictionary * d, FILE * f); void iniparser_dump(dictionary * d, FILE * f);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Get the string associated to a key, return NULL if not found
@param d Dictionary to search
@param key Key string to look for
@return pointer to statically allocated character string, or NULL.
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
NULL is returned.
The returned char pointer is pointing to a string allocated in
the dictionary, do not free or modify it.
This function is only provided for backwards compatibility with
previous versions of iniparser. It is recommended to use
iniparser_getstring() instead.
*/
/*-------------------------------------------------------------------------
-*/
char * iniparser_getstr(dictionary * d, const char * key);
/*-------------------------------------------------------------------------
*/
/**
@brief Get the string associated to a key @brief Get the string associated to a key
@param d Dictionary to search @param d Dictionary to search
@param key Key string to look for @param key Key string to look for
@param def Default value to return if key not found. @param def Default value to return if key not found.
@return pointer to statically allocated character string @return pointer to statically allocated character string
This function queries a dictionary for a key. A key as read from an This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found, ini file is given as "section:key". If the key cannot be found,
the pointer passed as 'def' is returned. the pointer passed as 'def' is returned.
The returned char pointer is pointing to a string allocated in The returned char pointer is pointing to a string allocated in
the dictionary, do not free or modify it. the dictionary, do not free or modify it.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
char * iniparser_getstring(dictionary * d, const char * key, char * def); char * iniparser_getstring(dictionary * d, char * key, char * def);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Get the string associated to a key, convert to an int @brief Get the string associated to a key, convert to an int
@param d Dictionary to search @param d Dictionary to search
@param key Key string to look for @param key Key string to look for
@param notfound Value to return in case of error @param notfound Value to return in case of error
@return integer @return integer
This function queries a dictionary for a key. A key as read from an This function queries a dictionary for a key. A key as read from an
skipping to change at line 170 skipping to change at line 148
- "042" -> 34 (octal -> decimal) - "042" -> 34 (octal -> decimal)
- "0x42" -> 66 (hexa -> decimal) - "0x42" -> 66 (hexa -> decimal)
Warning: the conversion may overflow in various ways. Conversion is Warning: the conversion may overflow in various ways. Conversion is
totally outsourced to strtol(), see the associated man page for overflow totally outsourced to strtol(), see the associated man page for overflow
handling. handling.
Credits: Thanks to A. Becker for suggesting strtol() Credits: Thanks to A. Becker for suggesting strtol()
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
int iniparser_getint(dictionary * d, const char * key, int notfound); int iniparser_getint(dictionary * d, char * key, int notfound);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Get the string associated to a key, convert to a double @brief Get the string associated to a key, convert to a double
@param d Dictionary to search @param d Dictionary to search
@param key Key string to look for @param key Key string to look for
@param notfound Value to return in case of error @param notfound Value to return in case of error
@return double @return double
This function queries a dictionary for a key. A key as read from an This function queries a dictionary for a key. A key as read from an
skipping to change at line 219 skipping to change at line 197
- A string starting with 'n' - A string starting with 'n'
- A string starting with 'N' - A string starting with 'N'
- A string starting with 'f' - A string starting with 'f'
- A string starting with 'F' - A string starting with 'F'
- A string starting with '0' - A string starting with '0'
The notfound value returned if no boolean is identified, does not The notfound value returned if no boolean is identified, does not
necessarily have to be 0 or 1. necessarily have to be 0 or 1.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
int iniparser_getboolean(dictionary * d, const char * key, int notfound); int iniparser_getboolean(dictionary * d, char * key, int notfound);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Set an entry in a dictionary. @brief Set an entry in a dictionary.
@param ini Dictionary to modify. @param ini Dictionary to modify.
@param entry Entry to modify (entry name) @param entry Entry to modify (entry name)
@param val New value to associate to the entry. @param val New value to associate to the entry.
@return int 0 if Ok, -1 otherwise. @return int 0 if Ok, -1 otherwise.
If the given entry can be found in the dictionary, it is modified to If the given entry can be found in the dictionary, it is modified to
contain the provided value. If it cannot be found, -1 is returned. contain the provided value. If it cannot be found, -1 is returned.
It is Ok to set val to NULL. It is Ok to set val to NULL.
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
int iniparser_set(dictionary * ini, char * entry, char * val);
int iniparser_setstr(dictionary * ini, char * entry, char * val);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Delete an entry in a dictionary @brief Delete an entry in a dictionary
@param ini Dictionary to modify @param ini Dictionary to modify
@param entry Entry to delete (entry name) @param entry Entry to delete (entry name)
@return void @return void
If the given entry can be found, it is deleted from the dictionary. If the given entry can be found, it is deleted from the dictionary.
*/ */
skipping to change at line 277 skipping to change at line 254
@return Pointer to newly allocated dictionary @return Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing This is the parser for ini files. This function is called, providing
the name of the file to be read. It returns a dictionary object that the name of the file to be read. It returns a dictionary object that
should not be accessed directly, but through accessor functions should not be accessed directly, but through accessor functions
instead. instead.
The returned dictionary must be freed using iniparser_freedict(). The returned dictionary must be freed using iniparser_freedict().
*/ */
/*------------------------------------------------------------------------- -*/ /*------------------------------------------------------------------------- -*/
dictionary * iniparser_load(const char * ininame); dictionary * iniparser_load(char * ininame);
/*------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- */
/** /**
@brief Free all memory associated to an ini dictionary @brief Free all memory associated to an ini dictionary
@param d Dictionary to free @param d Dictionary to free
@return void @return void
Free all memory associated to an ini dictionary. Free all memory associated to an ini dictionary.
It is mandatory to call this function before the dictionary object It is mandatory to call this function before the dictionary object
gets out of the current context. gets out of the current context.
 End of changes. 8 change blocks. 
34 lines changed or deleted 9 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/