101 #define HASH_MIN_SECTIONS (hashcount_t)8 102 #define HASH_MAX_SECTIONS HASHCOUNT_T_MAX
103 #define HASH_MIN_ENTRIES (hashcount_t)8
104 #define HASH_MAX_ENTRIES HASHCOUNT_T_MAX
109 #define HASH_INPUT_BUF_SIZE 1024 263 LOGERROR(
"failed to create new configuration main hash table");
269 if( sMainName ==
NULL )
272 buf[
sizeof(buf)-1] = 0;
299 if( pConfig ==
NULL )
335 if( (fp = fopen(sFileName,
"r")) ==
NULL )
389 while( fgets(bufGet, (
int)
sizeof(bufGet), fp) !=
NULL )
394 for(i=0; isspace((
int)bufGet[i]); ++i);
397 if( (bufGet[i] == 0) || (bufGet[i] ==
'#') || (bufGet[0] ==
'\n') )
405 if( bufGet[i] ==
'[' )
407 if( (t = strrchr(bufGet+i,
']' )) ==
NULL )
409 LOGERROR(
"Config %s: Line %d: malformed section statement: %d",
418 LOGERROR(
"Config %s: [%s]: Line %d: failed adding section",
429 if( pCurSect ==
NULL )
431 LOGERROR(
"Config %s: Line %d: not in a section",
439 bufKey[0] = bufSep[0] = bufVal[0] = 0;
440 if( sscanf(bufGet+i,
"%[^:= \t]%[:= \t]%[^\n#]", bufKey, bufSep, bufVal)
443 LOGERROR(
"Config %s: [%s]: Line %d: malformed input",
449 i = (int)strlen(bufVal) - 1;
450 while( (i >= 0) && isspace((
int)bufVal[i]) )
456 LOGERROR(
"Config %s: [%s]: Line %d: malformed input",
467 LOGERROR(
"Config %s: [%s]: Line %d: failed to add key=value enttry",
520 fprintf(fp,
"# Configuration %s\n", pConfig->
m_sMainName);
559 LOGERROR(
"%s: [%s]: section multiply defined",
577 LOGERROR(
"%s: [%s]: failed to create new section hash table",
612 LOGERROR(
"%s: [%s]: section not define",
663 fprintf(fp,
"%s=%s\n",
715 const char *sKey,
long *pVal)
725 else if( (sVal ==
NULL) || (*sVal == 0) )
727 LOGERROR(
"Config %s: [%s]: value is null",
733 lVal = strtol(sVal, &sEnd, 0);
737 LOGERROR(
"Config %s: [%s]: %s=%s: not an integer",
760 const char *sKey,
double *pVal)
770 else if( (sVal ==
NULL) || (*sVal == 0) )
772 LOGERROR(
"Config %s: [%s]: value is null",
778 fVal = strtod(sVal, &sEnd);
782 LOGERROR(
"Config %s: [%s]: %s=%s: not a float",
810 const char *sKey,
const char *sVal)
819 LOGDIAG4(
"%s: [%s]: section not defined",
842 const char *sKey,
long lVal)
846 sprintf(buf,
"%ld", lVal);
863 const char *sKey,
unsigned long ulVal)
867 sprintf(buf,
"%lu", ulVal);
884 const char *sKey,
double fVal)
888 sprintf(buf,
"%.16f", fVal);
913 LOGDIAG4(
"%s: [%s]: section not defined",
919 LOGDIAG4(
"%s: [%s]: %s could not delete",
char * m_sMainName
configuration name
void ConfigIterDelete(ConfigIter_T *pIter)
Delete a configuration iterator.
char * m_sSectionName
section name
static int ConfigMainCounter
#define hnode_getkey(N)
Get hash node hash key.
static int ConfigSectionAddPair(ConfigSection_T *pSect, const char *sKey, const char *sVal)
Add or update a key-value pair in the given section.
int ConfigDelete(Config_T *pConfig, const char *sSectionName, const char *sKey)
Delete entry from the configuration database.
hnode_t * hash_scan_next(hscan_t *scan)
Retrieve the next node from the hash table.
char * new_strdup(const char *s)
Duplicate a string.
int ConfigSetStr(Config_T *pConfig, const char *sSectionName, const char *sKey, const char *sVal)
Set or update a string value in the configuration database.
#define CHKPTR(p,...)
Checks validity of pointer.
#define LOGDIAG3(fmt,...)
Standard Diagnostic Level 3 logging.
Configuration parser declarations.
General purpose hash data and function declarations.
#define HASH_MAX_ENTRIES
max. num. of section entries
Memory allocation and deallocation declarations.
hnode_t * hash_lookup(hash_t *hash, const void *key)
Find a node in the hash table and return a pointer to it.
const char * ConfigGetStr(Config_T *pConfig, const char *sSectionName, const char *sKey)
Get a string value from the configuration database.
void ConfigDbPrint(Config_T *pConfig, FILE *fp)
Print configuration database to the output file stream.
Config_T * ConfigDbReadFp(FILE *fp, const char *sFileName)
Create a new configuration database from a opened configuration file.
ConfigIter_T * ConfigDbIterNew(Config_T *pConfig)
Create a new configuration database iterator.
#define LOGSYSERROR(fmt,...)
Standard System Error logging.
#define RC_ERROR
common function error return code
bool_t hash_delete(hash_t *hash, void *key)
Unlink and delete a hash node with the given key from the hash table.
#define HASH_MAX_SECTIONS
max. num. of database sections
Config_T * ConfigDbNew(const char *sMainName)
Create and initialize a new empty configuration database.
#define LOGERROR(fmt,...)
Standard Error logging.
#define HASH_MIN_SECTIONS
min. num. of database sections
#define LOGDIAG4(fmt,...)
Standard Diagnostic Level 4 logging.
int ConfigSectionDelete(Config_T *pConfig, ConfigSection_T *pSect)
Delete a section from the configuration database.
ConfigSection_T * ConfigSectionNew(Config_T *pConfig, const char *sSectionName)
Add a new empty section to the configuration database.
static void ConfigMainHashDeleteCb(void *pKey, void *pData)
Delete section hash callback.
const char * ConfigIterNext(ConfigIter_T *pIter)
Get the next value in iteration.
#define NEW(T)
Allocate new type.
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.
#define HASH_INPUT_BUF_SIZE
Maximum input line size.
void hash_scan_begin(hscan_t *scan, hash_t *hash)
Reset the hash scanner (iterator).
ConfigSection_T * ConfigSectionGet(Config_T *pConfig, const char *sSectionName)
Get a section from the configuration database.
RoadNarrows Robotics common configuration file.
hash_t * m_hashMain
main hash table of sections
#define _TSTR(var)
string variable
#define hnode_get(N)
Get hash node user data.
hash_t * hash_table_create(bool_t isdynamic, hashcount_t minsize, hashcount_t maxsize, hash_comp_t compfun, hash_fun_t hashfun, hnode_data_free_t freedatafun)
Create a dynamic hash table.
int ConfigGetLong(Config_T *pConfig, const char *sSectionName, const char *sKey, long *pVal)
Get and convert a long value from the configuration database.
void ConfigDbSetName(Config_T *pConfig, const char *sMainName)
Assign a new name for the configuration database.
#define _TPTR(var)
pointer
#define LOGDIAG4CALL(...)
Standard Diagnostic Level 4 function call tracing.
void ConfigDbDelete(Config_T *pConfig)
Delete the configuration database.
Hash table control structure.
int ConfigSetDouble(Config_T *pConfig, const char *sSectionName, const char *sKey, double fVal)
Set or update a double value in the configuration database.
void ConfigSectionPrint(ConfigSection_T *pSect, FILE *fp)
Print one section to the output file stream.
int ConfigSetLong(Config_T *pConfig, const char *sSectionName, const char *sKey, long lVal)
Set or update a long value in the configuration database.
Hash chain node structure.
hash_t * m_hashSection
section's key=value entries hash table
bool_t hash_insert(hash_t *hash, void *key, void *data)
Insert user data with the given key into the hash table.
ConfigIter_T * ConfigSectionIterNew(Config_T *pConfig, const char *sSectionName)
Create a new configuration section iterator.
int ConfigGetDouble(Config_T *pConfig, const char *sSectionName, const char *sKey, double *pVal)
Get and convert a double value from the configuration database.
hscan_t m_scanHash
hash table scanner (iterator)
#define HASH_MIN_ENTRIES
min. num. of section entries
#define hnode_put(N, V)
Pet hash node user data.
const char * ConfigDbGetName(Config_T *pConfig)
Get the current name assigned to the configuration database.
void hash_table_destroy(hash_t *hash)
Delete the hash table, all of its entries, and all of the user data.
static void ConfigSectionHashDeleteCb(void *pKey, void *pData)
Delete section entry hash callback.
Config_T * ConfigDbRead(const char *sFileName)
Create a new configuration database from a configuration file.