iniparser.h File Reference
Detailed Description
Devillard
- Date:
- Mar 2000
- Version:
- Revision
- 1.23
Definition in file iniparser.h.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dictionary.h"
Go to the source code of this file.
Functions | |
void | iniparser_dump (dictionary *d, FILE *f) |
void | iniparser_dump_ini (dictionary *d, FILE *f) |
int | iniparser_find_entry (dictionary *ini, char *entry) |
void | iniparser_freedict (dictionary *d) |
int | iniparser_getboolean (dictionary *d, const char *key, int notfound) |
double | iniparser_getdouble (dictionary *d, char *key, double notfound) |
int | iniparser_getint (dictionary *d, const char *key, int notfound) |
int | iniparser_getnsec (dictionary *d) |
char * | iniparser_getsecname (dictionary *d, int n) |
char * | iniparser_getstr (dictionary *d, const char *key) |
char * | iniparser_getstring (dictionary *d, const char *key, char *def) |
dictionary * | iniparser_load (const char *ininame) |
int | iniparser_setstr (dictionary *ini, char *entry, char *val) |
void | iniparser_unset (dictionary *ini, char *entry) |
Function Documentation
void iniparser_dump | ( | dictionary * | d, | |
FILE * | f | |||
) |
Dump a dictionary to an opened file pointer.
- Parameters:
-
d Dictionary to dump. f Opened file pointer to dump to.
- Returns:
- void
stderr
or stdout
as output files. This function is meant for debugging purposes mostly.
void iniparser_dump_ini | ( | dictionary * | d, | |
FILE * | f | |||
) |
Save a dictionary to a loadable ini file.
- Parameters:
-
d Dictionary to dump f Opened file pointer to dump to
- Returns:
- void
stderr
or stdout
as output files.
int iniparser_find_entry | ( | dictionary * | ini, | |
char * | entry | |||
) |
Finds out if a given entry exists in a dictionary.
- Parameters:
-
ini Dictionary to search entry Name of the entry to look for
- Returns:
- integer 1 if entry exists, 0 otherwise
void iniparser_freedict | ( | dictionary * | d | ) |
Free all memory associated to an ini dictionary.
- Parameters:
-
d Dictionary to free
- Returns:
- void
int iniparser_getboolean | ( | dictionary * | d, | |
const char * | key, | |||
int | notfound | |||
) |
Get the string associated to a key, convert to a boolean.
- Parameters:
-
d Dictionary to search key Key string to look for notfound Value to return in case of error
- Returns:
- integer
A true boolean is found if one of the following is matched:
- A string starting with 'y'
- A string starting with 'Y'
- A string starting with 't'
- A string starting with 'T'
- A string starting with '1'
A false boolean is found if one of the following is matched:
- A string starting with 'n'
- A string starting with 'N'
- A string starting with 'f'
- A string starting with 'F'
- A string starting with '0'
The notfound value returned if no boolean is identified, does not necessarily have to be 0 or 1.
double iniparser_getdouble | ( | dictionary * | d, | |
char * | key, | |||
double | notfound | |||
) |
Get the string associated to a key, convert to a double.
- Parameters:
-
d Dictionary to search key Key string to look for notfound Value to return in case of error
- Returns:
- double
int iniparser_getint | ( | dictionary * | d, | |
const char * | key, | |||
int | notfound | |||
) |
Get the string associated to a key, convert to an int.
- Parameters:
-
d Dictionary to search key Key string to look for notfound Value to return in case of error
- Returns:
- integer
Supported values for integers include the usual C notation so decimal, octal (starting with 0) and hexadecimal (starting with 0x) are supported. Examples:
- "42" -> 42
- "042" -> 34 (octal -> decimal)
- "0x42" -> 66 (hexa -> decimal)
Warning: the conversion may overflow in various ways. Conversion is totally outsourced to strtol(), see the associated man page for overflow handling.
Credits: Thanks to A. Becker for suggesting strtol()
int iniparser_getnsec | ( | dictionary * | d | ) |
Get number of sections in a dictionary.
- Parameters:
-
d Dictionary to examine
- Returns:
- int Number of sections found in dictionary
This clearly fails in the case a section name contains a colon, but this should simply be avoided.
This function returns -1 in case of error.
char* iniparser_getsecname | ( | dictionary * | d, | |
int | n | |||
) |
Get name for section n in a dictionary.
- Parameters:
-
d Dictionary to examine n Section number (from 0 to nsec-1).
- Returns:
- Pointer to char string
This function returns NULL in case of error.
char* iniparser_getstr | ( | dictionary * | d, | |
const char * | key | |||
) |
Get the string associated to a key, return NULL if not found.
- Parameters:
-
d Dictionary to search key Key string to look for
- Returns:
- pointer to statically allocated character string, or NULL.
This function is only provided for backwards compatibility with previous versions of iniparser. It is recommended to use iniparser_getstring() instead.
char* iniparser_getstring | ( | dictionary * | d, | |
const char * | key, | |||
char * | def | |||
) |
Get the string associated to a key.
- Parameters:
-
d Dictionary to search key Key string to look for def Default value to return if key not found.
- Returns:
- pointer to statically allocated character string
dictionary* iniparser_load | ( | const char * | ininame | ) |
Parse an ini file and return an allocated dictionary object.
- Parameters:
-
ininame Name of the ini file to read.
- Returns:
- Pointer to newly allocated dictionary
The returned dictionary must be freed using iniparser_freedict().
int iniparser_setstr | ( | dictionary * | ini, | |
char * | entry, | |||
char * | val | |||
) |
Set an entry in a dictionary.
- Parameters:
-
ini Dictionary to modify. entry Entry to modify (entry name) val New value to associate to the entry.
- Returns:
- int 0 if Ok, -1 otherwise.
void iniparser_unset | ( | dictionary * | ini, | |
char * | entry | |||
) |
Delete an entry in a dictionary.
- Parameters:
-
ini Dictionary to modify entry Entry to delete (entry name)
- Returns:
- void