![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Configuration parser definitions. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "rnr/rnrconfig.h"#include "rnr/log.h"#include "rnr/new.h"#include "rnr/hash.h"#include "rnr/config.h"Go to the source code of this file.
Classes | |
| struct | config_section_t |
| struct | config_t |
| struct | config_iter_t |
Macros | |
| #define | HASH_MIN_SECTIONS (hashcount_t)8 |
| min. num. of database sections More... | |
| #define | HASH_MAX_SECTIONS HASHCOUNT_T_MAX |
| max. num. of database sections | |
| #define | HASH_MIN_ENTRIES (hashcount_t)8 |
| min. num. of section entries | |
| #define | HASH_MAX_ENTRIES HASHCOUNT_T_MAX |
| max. num. of section entries | |
| #define | HASH_INPUT_BUF_SIZE 1024 |
| Maximum input line size. | |
Functions | |
| static int | ConfigSectionAddPair (ConfigSection_T *pSect, const char *sKey, const char *sVal) |
| Add or update a key-value pair in the given section. More... | |
| static void | ConfigSectionHashDeleteCb (void *pKey, void *pData) |
| Delete section entry hash callback. More... | |
| static void | ConfigMainHashDeleteCb (void *pKey, void *pData) |
| Delete section hash callback. More... | |
| Config_T * | ConfigDbNew (const char *sMainName) |
| Create and initialize a new empty configuration database. More... | |
| void | ConfigDbDelete (Config_T *pConfig) |
| Delete the configuration database. More... | |
| Config_T * | ConfigDbRead (const char *sFileName) |
| Create a new configuration database from a configuration file. More... | |
| Config_T * | ConfigDbReadFp (FILE *fp, const char *sFileName) |
| Create a new configuration database from a opened configuration file. More... | |
| const char * | ConfigDbGetName (Config_T *pConfig) |
| Get the current name assigned to the configuration database. More... | |
| void | ConfigDbSetName (Config_T *pConfig, const char *sMainName) |
| Assign a new name for the configuration database. More... | |
| void | ConfigDbPrint (Config_T *pConfig, FILE *fp) |
| Print configuration database to the output file stream. More... | |
| ConfigSection_T * | ConfigSectionNew (Config_T *pConfig, const char *sSectionName) |
| Add a new empty section to the configuration database. More... | |
| int | ConfigSectionDelete (Config_T *pConfig, ConfigSection_T *pSect) |
| Delete a section from the configuration database. More... | |
| ConfigSection_T * | ConfigSectionGet (Config_T *pConfig, const char *sSectionName) |
| Get a section from the configuration database. More... | |
| void | ConfigSectionPrint (ConfigSection_T *pSect, FILE *fp) |
| Print one section to the output file stream. More... | |
| const char * | ConfigGetStr (Config_T *pConfig, const char *sSectionName, const char *sKey) |
| Get a string value from the configuration database. More... | |
| int | ConfigGetLong (Config_T *pConfig, const char *sSectionName, const char *sKey, long *pVal) |
| Get and convert a long value from the configuration database. More... | |
| int | ConfigGetDouble (Config_T *pConfig, const char *sSectionName, const char *sKey, double *pVal) |
| Get and convert a double value from the configuration database. More... | |
| int | ConfigSetStr (Config_T *pConfig, const char *sSectionName, const char *sKey, const char *sVal) |
| Set or update a string value in the configuration database. More... | |
| int | ConfigSetLong (Config_T *pConfig, const char *sSectionName, const char *sKey, long lVal) |
| Set or update a long value in the configuration database. More... | |
| int | ConfigSetULong (Config_T *pConfig, const char *sSectionName, const char *sKey, unsigned long ulVal) |
| Set or update an unsigned long value in the configuration database. More... | |
| int | ConfigSetDouble (Config_T *pConfig, const char *sSectionName, const char *sKey, double fVal) |
| Set or update a double value in the configuration database. More... | |
| int | ConfigDelete (Config_T *pConfig, const char *sSectionName, const char *sKey) |
| Delete entry from the configuration database. More... | |
| ConfigIter_T * | ConfigDbIterNew (Config_T *pConfig) |
| Create a new configuration database iterator. More... | |
| ConfigIter_T * | ConfigSectionIterNew (Config_T *pConfig, const char *sSectionName) |
| Create a new configuration section iterator. More... | |
| void | ConfigIterDelete (ConfigIter_T *pIter) |
| Delete a configuration iterator. More... | |
| const char * | ConfigIterNext (ConfigIter_T *pIter) |
| Get the next value in iteration. More... | |
Variables | |
| static int | ConfigMainCounter = 0 |
Configuration parser definitions.
This file has been modified from the original source (see below).
Definition in file config.c.
| #define HASH_MIN_SECTIONS (hashcount_t)8 |
min. num. of database sections
Configuration limits.
Definition at line 101 of file config.c.
Referenced by ConfigDbNew().
| void ConfigDbDelete | ( | Config_T * | pConfig | ) |
Delete the configuration database.
All sections, section key=value entries, plus the database itself are deleted.
| pConfig | Configuration database. |
Definition at line 295 of file config.c.
References _TSTR, hash_table_destroy(), LOGDIAG4CALL, config_t::m_hashMain, config_t::m_sMainName, and NULL.
Referenced by CmdDbDelete(), and ConfigDbReadFp().
| const char* ConfigDbGetName | ( | Config_T * | pConfig | ) |
Get the current name assigned to the configuration database.
| pConfig | Configuration database. |
Definition at line 486 of file config.c.
References CHKPTR, config_t::m_sMainName, and NULL.
Referenced by CmdDelete(), CmdFind(), CmdGetd(), CmdGeti(), CmdGets(), CmdSectDelete(), CmdSectNew(), CmdSetd(), CmdSeti(), and CmdSets().
| ConfigIter_T* ConfigDbIterNew | ( | Config_T * | pConfig | ) |
Create a new configuration database iterator.
The iterator will iterator over section names.
| pConfig | Configuration database. |
Definition at line 943 of file config.c.
References hash_scan_begin(), config_t::m_hashMain, config_iter_t::m_scanHash, and NEW.
Referenced by CmdFind(), and ConfigSetInt().
| Config_T* ConfigDbNew | ( | const char * | sMainName | ) |
Create and initialize a new empty configuration database.
| sMainName | Name of configuration database. If Null, then a name will be auto-generated. |
Definition at line 243 of file config.c.
References _TPTR, _TSTR, ConfigMainCounter, ConfigMainHashDeleteCb(), HASH_MAX_SECTIONS, HASH_MIN_SECTIONS, hash_table_create(), LOGDIAG3, LOGDIAG4CALL, LOGERROR, config_t::m_hashMain, config_t::m_sMainName, NEW, new_strdup(), and NULL.
Referenced by CmdDbNew(), and ConfigDbReadFp().
| void ConfigDbPrint | ( | Config_T * | pConfig, |
| FILE * | fp | ||
| ) |
Print configuration database to the output file stream.
The output format is valid for input.
| pConfig | Configuration database. |
| fp | Output file pointer. |
Definition at line 514 of file config.c.
References ConfigSectionPrint(), hash_scan_begin(), hash_scan_next(), hnode_get, config_t::m_hashMain, config_t::m_sMainName, and NULL.
Referenced by CmdDbPrint(), and test_config().
| Config_T* ConfigDbRead | ( | const char * | sFileName | ) |
Create a new configuration database from a configuration file.
The file syntax must conform to the simplified 'INI' format supported by librnr config.
The file is closed upon exiting this function.
| sFileName | File path name of configuration file. |
Definition at line 326 of file config.c.
References _TPTR, _TSTR, CHKPTR, ConfigDbReadFp(), LOGDIAG4, LOGDIAG4CALL, LOGSYSERROR, and NULL.
Referenced by CmdDbRead(), and test_config().
| Config_T* ConfigDbReadFp | ( | FILE * | fp, |
| const char * | sFileName | ||
| ) |
Create a new configuration database from a opened configuration file.
The file syntax must conform to the simplified 'INI' format supported by librnr config.
The file is remains open upon exiting this function.
| fp | Input file pointer. |
| sFileName | Input file name. NULL is okay. |
Definition at line 364 of file config.c.
References _TPTR, _TSTR, CHKPTR, ConfigDbDelete(), ConfigDbNew(), ConfigSectionAddPair(), ConfigSectionNew(), HASH_INPUT_BUF_SIZE, LOGDIAG4, LOGDIAG4CALL, LOGERROR, config_t::m_sMainName, config_section_t::m_sSectionName, NULL, and RC_ERROR.
Referenced by ConfigDbRead().
| void ConfigDbSetName | ( | Config_T * | pConfig, |
| const char * | sMainName | ||
| ) |
Assign a new name for the configuration database.
| pConfig | Configuration database. |
| sMainName | New database name. |
Definition at line 498 of file config.c.
References CHKPTR, config_t::m_sMainName, and new_strdup().
| int ConfigDelete | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey | ||
| ) |
Delete entry from the configuration database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
Definition at line 906 of file config.c.
References ConfigSectionGet(), hash_delete(), LOGDIAG4, config_section_t::m_hashSection, config_t::m_sMainName, NULL, OK, and RC_ERROR.
Referenced by CmdDelete(), and ConfigSetInt().
| int ConfigGetDouble | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey, | ||
| double * | pVal | ||
| ) |
Get and convert a double value from the configuration database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
| pVal | Converted value. |
Definition at line 759 of file config.c.
References ConfigGetStr(), LOGERROR, config_t::m_sMainName, NULL, OK, and RC_ERROR.
Referenced by CmdGetd().
| int ConfigGetLong | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey, | ||
| long * | pVal | ||
| ) |
Get and convert a long value from the configuration database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
| pVal | Converted value. |
Definition at line 714 of file config.c.
References ConfigGetStr(), LOGERROR, config_t::m_sMainName, NULL, OK, and RC_ERROR.
Referenced by ConfigGetInt(), and ConfigGetULong().
| const char* ConfigGetStr | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey | ||
| ) |
Get a string value from the configuration database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
Definition at line 682 of file config.c.
References ConfigSectionGet(), hash_lookup(), hnode_get, config_section_t::m_hashSection, and NULL.
Referenced by CmdFind(), CmdGets(), ConfigGetDouble(), ConfigGetLong(), and ConfigGetStrDft().
| void ConfigIterDelete | ( | ConfigIter_T * | pIter | ) |
Delete a configuration iterator.
| pIter | Configuration iterator. |
Definition at line 985 of file config.c.
Referenced by CmdFind(), and ConfigSetInt().
| const char* ConfigIterNext | ( | ConfigIter_T * | pIter | ) |
Get the next value in iteration.
After an iterator is created, the first call will return the first vale. Subsequent calls return the next values.
If iterator was created to iterate over the section names, then the values returned are section names. If the iterator was created to iterate over section keys, then the values returned are keys.
| pIter | Configuration iterator. |
Definition at line 1004 of file config.c.
References hash_scan_next(), hnode_getkey, config_iter_t::m_scanHash, and NULL.
Referenced by CmdFind(), and ConfigSetInt().
|
static |
Delete section hash callback.
When a section or configuration datatbase is deleted, the hash will make a callback to this function to delete the hash key and data (section).
| pKey | Section key to main hash. |
| pData | Key data to delete (ConfigSection_T *). |
Definition at line 212 of file config.c.
References hash_table_destroy(), config_section_t::m_hashSection, and config_section_t::m_sSectionName.
Referenced by ConfigDbNew().
|
static |
Add or update a key-value pair in the given section.
| pSect | Configuration section to update. |
| sKey | Section key to add or update. |
| sVal | Key value to add |
Definition at line 151 of file config.c.
References hash_insert(), hash_lookup(), hnode_get, hnode_put, config_section_t::m_hashSection, new_strdup(), NULL, OK, and RC_ERROR.
Referenced by ConfigDbReadFp(), and ConfigSetStr().
| int ConfigSectionDelete | ( | Config_T * | pConfig, |
| ConfigSection_T * | pSect | ||
| ) |
Delete a section from the configuration database.
| pConfig | Configuration database. |
| pSect | Configuration section to delete. |
Definition at line 600 of file config.c.
References _TPTR, hash_delete(), hash_lookup(), LOGDIAG4CALL, LOGERROR, config_t::m_hashMain, config_t::m_sMainName, config_section_t::m_sSectionName, NULL, OK, and RC_ERROR.
Referenced by CmdSectDelete().
| ConfigSection_T* ConfigSectionGet | ( | Config_T * | pConfig, |
| const char * | sSectionName | ||
| ) |
Get a section from the configuration database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
Definition at line 635 of file config.c.
References hash_lookup(), hnode_get, config_t::m_hashMain, and NULL.
Referenced by CmdSectDelete(), ConfigDelete(), ConfigGetStr(), ConfigSectionIterNew(), and ConfigSetStr().
|
static |
Delete section entry hash callback.
When a key-value entry or section is deleted, the hash will make a callback to this function to delete the hash key and data.
| pKey | Section key to delete. |
| pData | Key value to delete. |
Definition at line 197 of file config.c.
Referenced by ConfigSectionNew().
| ConfigIter_T* ConfigSectionIterNew | ( | Config_T * | pConfig, |
| const char * | sSectionName | ||
| ) |
Create a new configuration section iterator.
The iterator will iterator over section keys.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
Definition at line 963 of file config.c.
References ConfigSectionGet(), hash_scan_begin(), config_section_t::m_hashSection, config_iter_t::m_scanHash, NEW, and NULL.
Referenced by CmdFind(), and ConfigSetInt().
| ConfigSection_T* ConfigSectionNew | ( | Config_T * | pConfig, |
| const char * | sSectionName | ||
| ) |
Add a new empty section to the configuration database.
The section cannot already exist.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
Definition at line 547 of file config.c.
References _TPTR, _TSTR, CHKPTR, ConfigSectionHashDeleteCb(), hash_insert(), hash_lookup(), HASH_MAX_ENTRIES, HASH_MIN_ENTRIES, hash_table_create(), LOGDIAG4CALL, LOGERROR, config_t::m_hashMain, config_section_t::m_hashSection, config_t::m_sMainName, config_section_t::m_sSectionName, NEW, new_strdup(), and NULL.
Referenced by CmdSectNew(), and ConfigDbReadFp().
| void ConfigSectionPrint | ( | ConfigSection_T * | pSect, |
| FILE * | fp | ||
| ) |
Print one section to the output file stream.
The output format is valid for input.
| pSect | Configuration section. |
| fp | Output file pointer. |
Definition at line 654 of file config.c.
References hash_scan_begin(), hash_scan_next(), hnode_get, hnode_getkey, config_section_t::m_hashSection, config_section_t::m_sSectionName, and NULL.
Referenced by ConfigDbPrint().
| int ConfigSetDouble | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey, | ||
| double | fVal | ||
| ) |
Set or update a double value in the configuration database.
The double value is converted to a string prior to adding to the database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
| fVal | Section key double value. |
Definition at line 883 of file config.c.
References ConfigSetStr().
Referenced by CmdSetd(), and ConfigGetStrDft().
| int ConfigSetLong | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey, | ||
| long | lVal | ||
| ) |
Set or update a long value in the configuration database.
The long value is converted to a string prior to adding to the database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
| lVal | Section key long value. |
Definition at line 841 of file config.c.
References ConfigSetStr().
Referenced by ConfigGetStrDft(), and ConfigSetInt().
| int ConfigSetStr | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey, | ||
| const char * | sVal | ||
| ) |
Set or update a string value in the configuration database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
| sVal | Section key value. |
Definition at line 809 of file config.c.
References _TPTR, _TSTR, ConfigSectionAddPair(), ConfigSectionGet(), LOGDIAG4, LOGDIAG4CALL, config_t::m_sMainName, NULL, and RC_ERROR.
Referenced by CmdSets(), ConfigGetStrDft(), ConfigSetDouble(), ConfigSetLong(), and ConfigSetULong().
| int ConfigSetULong | ( | Config_T * | pConfig, |
| const char * | sSectionName, | ||
| const char * | sKey, | ||
| unsigned long | ulVal | ||
| ) |
Set or update an unsigned long value in the configuration database.
The long value is converted to a string prior to adding to the database.
| pConfig | Configuration database. |
| sSectionName | Configuration section name. |
| sKey | Section key. |
| ulVal | Section key unsigned long value. |
Definition at line 862 of file config.c.
References ConfigSetStr().
Referenced by ConfigGetStrDft().
|
static |
Internal counter to make configuration names unique.
Definition at line 140 of file config.c.
Referenced by ConfigDbNew().