From 52c93a495506d44b7b82745c4f0c9d1ea270eb3e Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Thu, 27 Feb 2020 17:24:21 +0800 Subject: [PATCH] [utils]: Update iniparser Change-Id: Id29dc65a732aa62f4614f1d602545c04e7de054b Signed-off-by: Herman Chen --- utils/iniparser.c | 24 +++++++++++++++++++++++- utils/iniparser.h | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/utils/iniparser.c b/utils/iniparser.c index ae3327ee..750adebb 100644 --- a/utils/iniparser.c +++ b/utils/iniparser.c @@ -493,6 +493,28 @@ int iniparser_getint(const dictionary * d, const char * key, int notfound) return (int)iniparser_getlongint(d, key, notfound); } +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a double + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return double + + 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, + the notfound value is returned. + */ +/*--------------------------------------------------------------------------*/ +double iniparser_getdouble(const dictionary * d, const char * key, double notfound) +{ + const char * str ; + + str = iniparser_getstring(d, key, INI_INVALID_KEY); + if (str == INI_INVALID_KEY) return notfound ; + return atof(str); +} + /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to a boolean @@ -696,7 +718,7 @@ dictionary * iniparser_load(const char * ininame) char line [ASCIILINESZ + 1] ; char section [ASCIILINESZ + 1] ; char key [ASCIILINESZ + 1] ; - char tmp [(ASCIILINESZ * 2) + 1] ; + char tmp [(ASCIILINESZ * 2) + 2] ; char val [ASCIILINESZ + 1] ; int last = 0 ; diff --git a/utils/iniparser.h b/utils/iniparser.h index bd5ae03e..37ff7b71 100644 --- a/utils/iniparser.h +++ b/utils/iniparser.h @@ -230,6 +230,21 @@ int iniparser_getint(const dictionary * d, const char * key, int notfound); long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound); +/*-------------------------------------------------------------------------*/ +/** + @brief Get the string associated to a key, convert to a double + @param d Dictionary to search + @param key Key string to look for + @param notfound Value to return in case of error + @return double + + 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, + the notfound value is returned. + */ +/*--------------------------------------------------------------------------*/ +double iniparser_getdouble(const dictionary * d, const char * key, double notfound); + /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to a boolean