libsystem: config-parser: add percent config parse api
authorWaLyong Cho <walyong.cho@samsung.com>
Thu, 24 Nov 2016 02:40:32 +0000 (11:40 +0900)
committerWaLyong Cho <walyong.cho@samsung.com>
Thu, 24 Nov 2016 04:13:48 +0000 (13:13 +0900)
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>
src/libsystem/config-parser.c
src/libsystem/config-parser.h

index 3319056..e6ade0e 100644 (file)
@@ -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;
+}
index f2e9d3f..1909fe8 100644 (file)
@@ -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