Moved setting related function from util.c to setting.c.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 31 Dec 2012 13:18:07 +0000 (14:18 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 31 Dec 2012 13:18:07 +0000 (14:18 +0100)
Now there is no dependency from the setting.c to the util function.

src/setting.c
src/util.c
src/util.h

index 2f6e139..48f5649 100644 (file)
@@ -20,6 +20,7 @@
 #include "setting.h"
 #include "util.h"
 
+static Arg* setting_char_to_arg(const gchar* str, const Type type);
 static void setting_print_value(const Setting* s, void* value);
 static gboolean setting_webkit(const Setting* s, const gboolean get);
 #ifdef FEATURE_COOKIE
@@ -159,7 +160,7 @@ gboolean setting_run(gchar* name, const gchar* param)
 
     /* if string param is given convert it to the required data type and set
      * it to the arg of the setting */
-    a = util_char_to_arg(param, s->type);
+    a = setting_char_to_arg(param, s->type);
     if (a == NULL) {
         vp_echo(VP_MSG_ERROR, TRUE, "No valid value");
         return FALSE;
@@ -178,6 +179,40 @@ gboolean setting_run(gchar* name, const gchar* param)
     return result;
 }
 
+/**
+ * Converts string representing also given data type into and Arg.
+ */
+static Arg* setting_char_to_arg(const gchar* str, const Type type)
+{
+    if (!str) {
+        return NULL;
+    }
+
+    Arg* arg = g_new0(Arg, 1);
+    switch (type) {
+        case TYPE_BOOLEAN:
+            arg->i = g_ascii_strncasecmp(str, "true", 4) == 0
+                || g_ascii_strncasecmp(str, "on", 2) == 0 ? 1 : 0;
+            break;
+
+        case TYPE_INTEGER:
+            arg->i = g_ascii_strtoull(str, (gchar**)NULL, 10);
+            break;
+
+        case TYPE_FLOAT:
+            arg->i = (1000000 * g_ascii_strtod(str, (gchar**)NULL));
+            break;
+
+        case TYPE_CHAR:
+        case TYPE_COLOR:
+        case TYPE_FONT:
+            arg->s = g_strdup(str);
+            break;
+    }
+
+    return arg;
+}
+
 /**
  * Print the setting value to the input box.
  */
index 5e873dc..b53fb99 100644 (file)
@@ -49,43 +49,3 @@ void util_create_file_if_not_exists(const char* filename) {
         fclose(f);
     }
 }
-
-Arg* util_char_to_arg(const gchar* str, Type type)
-{
-    Arg* arg = util_new_arg();
-
-    if (!str) {
-        return NULL;
-    }
-    switch (type) {
-        case TYPE_BOOLEAN:
-            arg->i = g_ascii_strncasecmp(str, "true", 4) == 0
-                || g_ascii_strncasecmp(str, "on", 2) == 0 ? 1 : 0;
-            break;
-
-        case TYPE_INTEGER:
-            arg->i = g_ascii_strtoull(str, (gchar**)NULL, 10);
-            break;
-
-        case TYPE_FLOAT:
-            arg->i = (1000000 * g_ascii_strtod(str, (gchar**)NULL));
-            break;
-
-        case TYPE_CHAR:
-        case TYPE_COLOR:
-        case TYPE_FONT:
-            arg->s = g_strdup(str);
-            break;
-    }
-
-    return arg;
-}
-
-Arg* util_new_arg(void)
-{
-    Arg* arg = g_new0(Arg, 1);
-    arg->i = 0;
-    arg->s = NULL;
-
-    return arg;
-}
index 2433d9e..1f88f61 100644 (file)
@@ -26,7 +26,5 @@ gchar* util_get_config_dir(void);
 gchar* util_get_cache_dir(void);
 void util_create_dir_if_not_exists(const gchar* dirpath);
 void util_create_file_if_not_exists(const gchar* filename);
-Arg* util_char_to_arg(const gchar* str, Type type);
-Arg* util_new_arg(void);
 
 #endif /* end of include guard: UTIL_H */