summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaLyong Cho <walyong.cho@samsung.com>2016-11-24 02:40:32 (GMT)
committerWaLyong Cho <walyong.cho@samsung.com>2016-11-24 04:13:48 (GMT)
commitbc5459ccb05559557d0142512938e9415402fdb1 (patch)
tree1176c89d15b1698faa37b8866cd6aede26834be9
parentb00833dcc135d7b826114070b998923853c9928e (diff)
downloadlibsystem-bc5459ccb05559557d0142512938e9415402fdb1.zip
libsystem-bc5459ccb05559557d0142512938e9415402fdb1.tar.gz
libsystem-bc5459ccb05559557d0142512938e9415402fdb1.tar.bz2
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 <walyong.cho@samsung.com>
-rw-r--r--src/libsystem/config-parser.c28
-rw-r--r--src/libsystem/config-parser.h16
2 files changed, 44 insertions, 0 deletions
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