From c06735031379e0dae58c19f3ab922258248d9c26 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Mon, 17 May 2010 13:21:56 -0400 Subject: Adding support for explicit 32/64 types (attempt 2). This is a reworked patch to add support for explicit 32 and 64 bit values in the config files. --- ini/ini.d/real.conf | 4 ++ ini/ini_config.h | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ini/ini_config_ut.c | 145 ++++++++++++++++++++++++++++++++++++++++++ ini/ini_get_value.c | 74 +++++++++++++++++++-- ini/ini_parse.c | 2 +- 5 files changed, 400 insertions(+), 5 deletions(-) diff --git a/ini/ini.d/real.conf b/ini/ini.d/real.conf index e3348e3..c426ec5 100644 --- a/ini/ini.d/real.conf +++ b/ini/ini.d/real.conf @@ -50,3 +50,7 @@ long_array = 1 2; 4' ;8p .16/ 32? double_array = 1.1 2.222222; .4' . ;8p .16/ -32? empty_value = space_value = " " +int32_t = -1000000000 +uint32_t = 3000000000 +int64_t = -1000000000123 +uint64_t = 3000000000123 diff --git a/ini/ini_config.h b/ini/ini_config.h index 3b58a11..28e1af8 100644 --- a/ini/ini_config.h +++ b/ini/ini_config.h @@ -1171,6 +1171,186 @@ unsigned long get_ulong_config_value(struct collection_item *item, unsigned long def, int *error); +/** + * @brief Convert item value to integer number. + * + * This is a conversion function. + * It converts the value read from the INI file + * and stored in the configuration item + * into an int32_t number. Any of the conversion + * functions can be used to try to convert the value + * stored as a string inside the item. + * The results can be different depending upon + * how the caller tries to interpret the value. + * If "strict" parameter is non zero the function will fail + * if there are more characters after the last digit. + * The value range is from INT_MIN to INT_MAX. + * + * @param[in] item Item to interpret. + * It must be retrieved using + * \ref get_config_item(). + * @param[in] strict Fail the function if + * the symbol after last digit + * is not valid. + * @param[in] def Default value to use if + * conversion failed. + * @param[out] error Variable will get the value + * of the error code if + * error happened. + * Can be NULL. In this case + * function does not set + * the code. + * Codes: + * - 0 - Success. + * - EINVAL - Argument is invalid. + * - EIO - Conversion failed due + * invalid characters. + * - ERANGE - Value is out of range. + * + * @return Converted value. + * In case of failure the function returns default value and + * sets error code into the provided variable. + */ +int32_t get_int32_config_value(struct collection_item *item, + int strict, + int32_t def, + int *error); + +/** + * @brief Convert item value to integer number. + * + * This is a conversion function. + * It converts the value read from the INI file + * and stored in the configuration item + * into an uint32_t number. Any of the conversion + * functions can be used to try to convert the value + * stored as a string inside the item. + * The results can be different depending upon + * how the caller tries to interpret the value. + * If "strict" parameter is non zero the function will fail + * if there are more characters after the last digit. + * The value range is from 0 to ULONG_MAX. + * + * @param[in] item Item to interpret. + * It must be retrieved using + * \ref get_config_item(). + * @param[in] strict Fail the function if + * the symbol after last digit + * is not valid. + * @param[in] def Default value to use if + * conversion failed. + * @param[out] error Variable will get the value + * of the error code if + * error happened. + * Can be NULL. In this case + * function does not set + * the code. + * Codes: + * - 0 - Success. + * - EINVAL - Argument is invalid. + * - EIO - Conversion failed due + * invalid characters. + * - ERANGE - Value is out of range. + * + * @return Converted value. + * In case of failure the function returns default value and + * sets error code into the provided variable. + */ +uint32_t get_uint32_config_value(struct collection_item *item, + int strict, + uint32_t def, + int *error); + +/** + * @brief Convert item value to integer number. + * + * This is a conversion function. + * It converts the value read from the INI file + * and stored in the configuration item + * into an int64_t number. Any of the conversion + * functions can be used to try to convert the value + * stored as a string inside the item. + * The results can be different depending upon + * how the caller tries to interpret the value. + * If "strict" parameter is non zero the function will fail + * if there are more characters after the last digit. + * The value range is from LLONG_MIN to LLONG_MAX. + * + * @param[in] item Item to interpret. + * It must be retrieved using + * \ref get_config_item(). + * @param[in] strict Fail the function if + * the symbol after last digit + * is not valid. + * @param[in] def Default value to use if + * conversion failed. + * @param[out] error Variable will get the value + * of the error code if + * error happened. + * Can be NULL. In this case + * function does not set + * the code. + * Codes: + * - 0 - Success. + * - EINVAL - Argument is invalid. + * - EIO - Conversion failed due + * invalid characters. + * - ERANGE - Value is out of range. + * + * @return Converted value. + * In case of failure the function returns default value and + * sets error code into the provided variable. + */ +int64_t get_int64_config_value(struct collection_item *item, + int strict, + int64_t def, + int *error); + +/** + * @brief Convert item value to integer number. + * + * This is a conversion function. + * It converts the value read from the INI file + * and stored in the configuration item + * into an uint64_t number. Any of the conversion + * functions can be used to try to convert the value + * stored as a string inside the item. + * The results can be different depending upon + * how the caller tries to interpret the value. + * If "strict" parameter is non zero the function will fail + * if there are more characters after the last digit. + * The value range is from 0 to ULLONG_MAX. + * + * @param[in] item Item to interpret. + * It must be retrieved using + * \ref get_config_item(). + * @param[in] strict Fail the function if + * the symbol after last digit + * is not valid. + * @param[in] def Default value to use if + * conversion failed. + * @param[out] error Variable will get the value + * of the error code if + * error happened. + * Can be NULL. In this case + * function does not set + * the code. + * Codes: + * - 0 - Success. + * - EINVAL - Argument is invalid. + * - EIO - Conversion failed due + * invalid characters. + * - ERANGE - Value is out of range. + * + * @return Converted value. + * In case of failure the function returns default value and + * sets error code into the provided variable. + */ +uint64_t get_uint64_config_value(struct collection_item *item, + int strict, + uint64_t def, + int *error); + /** * @brief Convert item value to floating point number. * diff --git a/ini/ini_config_ut.c b/ini/ini_config_ut.c index c9b13fd..b88b769 100644 --- a/ini/ini_config_ut.c +++ b/ini/ini_config_ut.c @@ -480,6 +480,11 @@ int get_test(void) long *array; double *darray; char **prop_array; + int32_t val_int32; + uint32_t val_uint32; + int64_t val_int64; + uint64_t val_uint64; + COLOUT(printf("\n\n===== GET TEST START ======\n")); COLOUT(printf("Reading collection\n")); @@ -1060,6 +1065,146 @@ int get_test(void) COLOUT(for (i=0;i= MAX_KEY) { - TRACE_ERROR_STRING("Section name is too long", buf); + TRACE_ERROR_STRING("Key name is too long", buf); *ext_error = ERR_LONGKEY; return RET_INVALID; } -- cgit