From bc5459ccb05559557d0142512938e9415402fdb1 Mon Sep 17 00:00:00 2001 From: WaLyong Cho Date: Thu, 24 Nov 2016 11:40:32 +0900 Subject: [PATCH] libsystem: config-parser: add percent config parse api To parse percent formatted key/value config, add new config_parse_percent(). The right value has to end with '%' character. Change-Id: I7a3edcfe8c272aab9e817ce1f2b8513ba2f92c9e Signed-off-by: WaLyong Cho --- src/libsystem/config-parser.c | 28 ++++++++++++++++++++++++++++ src/libsystem/config-parser.h | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/libsystem/config-parser.c b/src/libsystem/config-parser.c index 3319056..e6ade0e 100644 --- a/src/libsystem/config-parser.c +++ b/src/libsystem/config-parser.c @@ -345,3 +345,31 @@ int config_parse_bytes( return 0; } + +int config_parse_percent( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data) { + + size_t *percent = data, p = 0; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (!isempty(rvalue)) { + r = parse_percent(rvalue, &p); + if (r < 0) + return r; + } + + *percent = p; + + return 0; +} diff --git a/src/libsystem/config-parser.h b/src/libsystem/config-parser.h index f2e9d3f..1909fe8 100644 --- a/src/libsystem/config-parser.h +++ b/src/libsystem/config-parser.h @@ -171,6 +171,22 @@ int config_parse_string(const char *filename, unsigned line, const char *section */ int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data); +/** + * @brief A common percent(%) type rvalue parser. The right value has + * to be end with '%'. + * + * @param filename a parsing config file name + * @param line a parsing config file line + * @param section a parsing config file section + * @param lvalue a parsing config file left value + * @param ltype a parsing config file left value type. (not used.) + * @param rvalue a parsing config file rvalue + * @param data user data + * + * @return 0 on success, -errno on failure. + */ +int config_parse_percent(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data); + #ifdef __cplusplus } #endif -- 2.7.4