From: Andrea Zagli <azagli@libero.it> Date: Mon, 25 Apr 2016 15:33:46 +0000 (+0200) Subject: Merge branch 'libpeas' into namespace X-Git-Tag: v0.10.0~1 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=89795082de66f4325af0ddca5cc6d6038cc3d9e5;p=zakconfi%2Flibzakconfi Merge branch 'libpeas' into namespace --- 89795082de66f4325af0ddca5cc6d6038cc3d9e5 diff --cc plugins/file/plgfile.c index b31dec3,f8e886a..c4edfc7 --- a/plugins/file/plgfile.c +++ b/plugins/file/plgfile.c @@@ -36,18 -36,20 +36,20 @@@ #include "plgfile.h" -static void confi_pluggable_iface_init (ConfiPluggableInterface *iface); +static void zak_confi_pluggable_iface_init (ZakConfiPluggableInterface *iface); - static gboolean zak_confi_file_plugin_path_get_group_and_key (ZakConfiPluggable *pluggable, const gchar *path, gchar **group, gchar **key); -gboolean confi_file_plugin_initialize (ConfiPluggable *pluggable, const gchar *cnc_string); ++gboolean zak_confi_file_plugin_initialize (ZakConfiPluggable *pluggable, const gchar *cnc_string); + -static gboolean confi_file_plugin_path_get_group_and_key (const gchar *path, gchar **group, gchar **key); -static gchar *confi_file_plugin_path_get_value_from_file (ConfiPluggable *pluggable, const gchar *path); -static gchar *confi_file_plugin_path_get_value (ConfiPluggable *pluggable, const gchar *path); -static gboolean confi_file_plugin_path_set_value (ConfiPluggable *pluggable, const gchar *path, const gchar *value); -static void confi_file_plugin_get_children (ConfiPluggable *pluggable, GNode *parentNode); ++static gboolean zak_confi_file_plugin_path_get_group_and_key (const gchar *path, gchar **group, gchar **key); +static gchar *zak_confi_file_plugin_path_get_value_from_file (ZakConfiPluggable *pluggable, const gchar *path); +static gchar *zak_confi_file_plugin_path_get_value (ZakConfiPluggable *pluggable, const gchar *path); +static gboolean zak_confi_file_plugin_path_set_value (ZakConfiPluggable *pluggable, const gchar *path, const gchar *value); +static void zak_confi_file_plugin_get_children (ZakConfiPluggable *pluggable, GNode *parentNode); -#define CONFI_FILE_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CONFI_TYPE_FILE_PLUGIN, ConfiFilePluginPrivate)) +#define ZAK_CONFI_FILE_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CONFI_TYPE_FILE_PLUGIN, ZakConfiFilePluginPrivate)) -typedef struct _ConfiFilePluginPrivate ConfiFilePluginPrivate; -struct _ConfiFilePluginPrivate +typedef struct _ZakConfiFilePluginPrivate ZakConfiFilePluginPrivate; +struct _ZakConfiFilePluginPrivate { gchar *cnc_string; @@@ -196,47 -198,24 +198,24 @@@ zak_confi_file_plugin_initialize (ZakCo } static gboolean - zak_confi_file_plugin_path_get_group_and_key (ZakConfiPluggable *pluggable, const gchar *path, gchar **group, gchar **key) -confi_file_plugin_path_get_group_and_key (const gchar *path, gchar **group, gchar **key) ++zak_confi_file_plugin_path_get_group_and_key (const gchar *path, gchar **group, gchar **key) { - gchar *path_; - gchar **tokens; - - guint l; - guint i; - guint c; + gchar *last; if (path == NULL) return FALSE; + if (path[strlen (path) - 1] == '/') return FALSE; - path_ = g_strdup_printf ("%s/", path); - tokens = g_strsplit (path_, "/", -1); - if (tokens == NULL) return FALSE; - - l = g_strv_length (tokens); - c = 1; - for (i = 0; i < l; i++) + last = g_strrstr (path, "/"); + if (last == NULL) { - if (g_strcmp0 (tokens[i], "") != 0) - { - if (c == 1) - { - *group = g_strdup (tokens[i]); - g_strstrip (*group); - c = 2; - } - else if (c == 2) - { - *key = g_strdup (tokens[i]); - g_strstrip (*key); - c = 3; - } - if (c > 2) - { - break; - } - } + return FALSE; } - g_strfreev (tokens); - g_free (path_); + + *group = g_strndup (path + (path[0] == '/' ? 1 : 0), strlen (path + (path[0] == '/' ? 1 : 0)) - strlen (last)); + g_strstrip (*group); + + *key = g_strdup (last + 1); + g_strstrip (*key); return TRUE; } @@@ -257,7 -236,7 +236,7 @@@ static gcha group = NULL; key = NULL; - if (!zak_confi_file_plugin_path_get_group_and_key (pluggable, path, &group, &key)) - if (!confi_file_plugin_path_get_group_and_key (path, &group, &key)) ++ if (!zak_confi_file_plugin_path_get_group_and_key (path, &group, &key)) { return NULL; } @@@ -288,9 -267,9 +267,6 @@@ zak_confi_file_plugin_get_children (Zak guint g; guint k; -- gchar *group; -- gchar *key; -- GError *error; GNode *gNode; @@@ -393,9 -373,15 +370,15 @@@ zak_confi_file_plugin_path_set_value (Z g_return_val_if_fail (value != NULL, FALSE); - path_ = confi_path_normalize (pluggable, path); ++ path_ = zak_confi_path_normalize (pluggable, path); + if (path_ == NULL) + { + return FALSE; + } + group = NULL; key = NULL; - if (!zak_confi_file_plugin_path_get_group_and_key (pluggable, path, &group, &key)) - if (!confi_file_plugin_path_get_group_and_key (path_, &group, &key)) ++ if (!zak_confi_file_plugin_path_get_group_and_key (path, &group, &key)) { return FALSE; } @@@ -452,11 -438,11 +435,11 @@@ static ZakConfiKe { group = NULL; key_ = NULL; - if (zak_confi_file_plugin_path_get_group_and_key (pluggable, path, &group, &key_)) - if (confi_file_plugin_path_get_group_and_key (path, &group, &key_)) ++ if (zak_confi_file_plugin_path_get_group_and_key (path, &group, &key_)) { - ck = g_new0 (ConfiKey, 1); + ck = g_new0 (ZakConfiKey, 1); ck->key = g_strdup (key); - ck->value = confi_file_plugin_path_get_value (pluggable, path); + ck->value = zak_confi_file_plugin_path_get_value (pluggable, path); ck->description = g_key_file_get_comment (priv->kfile, group, key, NULL);; ck->path = g_strdup (path); @@@ -505,11 -491,11 +488,11 @@@ static ZakConfiKe group = NULL; key = NULL; - if (zak_confi_file_plugin_path_get_group_and_key (pluggable, path_, &group, &key)) - if (confi_file_plugin_path_get_group_and_key (path_, &group, &key)) ++ if (zak_confi_file_plugin_path_get_group_and_key (path_, &group, &key)) { - ck = g_new0 (ConfiKey, 1); + ck = g_new0 (ZakConfiKey, 1); ck->key = g_strdup (key); - ck->value = confi_file_plugin_path_get_value (pluggable, path_); + ck->value = zak_confi_file_plugin_path_get_value (pluggable, path_); ck->description = g_key_file_get_comment (priv->kfile, group, key, NULL); ck->path = g_strdup (group); @@@ -539,7 -525,7 +522,7 @@@ zak_confi_file_plugin_remove_path (ZakC group = NULL; key = NULL; - if (zak_confi_file_plugin_path_get_group_and_key (pluggable, path, &group, &key)) - if (confi_file_plugin_path_get_group_and_key (path, &group, &key)) ++ if (zak_confi_file_plugin_path_get_group_and_key (path, &group, &key)) { error = NULL; ret = g_key_file_remove_key (priv->kfile, group, key, &error); diff --cc tests/test.c index 7dcbb43,f5ade1f..50c21c1 --- a/tests/test.c +++ b/tests/test.c @@@ -85,58 -81,31 +85,31 @@@ main (int argc, char **argv g_node_traverse (tree, G_PRE_ORDER, G_TRAVERSE_ALL, -1, traverse_func, NULL); g_printf ("\n"); - if (g_strcmp0 (peas_plugin_info_get_module_name (ppinfo), "file") == 0) - { - gchar *val = zak_confi_path_get_value (confi, "FOLDER1/key1"); - g_printf ("Value from key \"FOLDER1/key1\"\n%s\n\n", val); - zak_confi_path_set_value (confi, "FOLDER1/key1", "new value programmatically setted"); - g_printf ("Value from key \"FOLDER1/key1\"\n%s\n\n", zak_confi_path_get_value (confi, "FOLDER1/key1")); - zak_confi_path_set_value (confi, "FOLDER1/key1", val); - - zak_confi_add_key (confi, "FOLDER2", "key999", NULL); - zak_confi_path_set_value (confi, "FOLDER2/key999", "value for key999, programmatically setted"); - - ZakConfiKey *ck; - ck = zak_confi_path_get_confi_key (confi, "FOLDER1/key2"); - g_printf ("ZakConfiKey for FOLDER1/key2\n"); - g_printf ("Path: %s\n", ck->path); - g_printf ("Key: %s\n", ck->key); - g_printf ("Description: %s\n", ck->description); - g_printf ("Value: %s\n", ck->value); - g_printf ("\n"); - - g_printf ("Setting root \"FOLDER2\"\n"); - zak_confi_set_root (confi, "FOLDER2"); - g_printf ("Value from key \"key2\" %s\n", zak_confi_path_get_value (confi, "key2")); - g_printf ("Value from key \"FOLDER2/key2\" (expected null) %s\n", zak_confi_path_get_value (confi, "FOLDER2/key2")); - } - else - { - gchar *val = zak_confi_path_get_value (confi, "folder/key1/key1_2"); - g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", val); - zak_confi_path_set_value (confi, "folder/key1/key1_2", "new value programmatically setted"); - g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", zak_confi_path_get_value (confi, "folder/key1/key1_2")); - zak_confi_path_set_value (confi, "folder/key1/key1_2", val); - - zak_confi_add_key (confi, "folder/key2", "key2-2", NULL); - zak_confi_path_set_value (confi, "folder/key2/key2-2", "value for key2-2, programmatically setted"); - - ZakConfiKey *ck; - ck = zak_confi_path_get_confi_key (confi, "folder/key2/key2-2"); - g_printf ("ZakConfiKey for folder/key2/key2-2\n"); - g_printf ("Path: %s\n", ck->path); - g_printf ("Key: %s\n", ck->key); - g_printf ("Description: %s\n", ck->description); - g_printf ("Value: %s\n", ck->value); - g_printf ("\n"); - - g_printf ("Setting root \"folder/key2\"\n"); - zak_confi_set_root (confi, "folder/key2"); - g_printf ("Value from key \"key2-1\" %s\n", zak_confi_path_get_value (confi, "key2-1")); - g_printf ("Value from key \"folder/key1/key1_2\" (expected null) %s\n", zak_confi_path_get_value (confi, "folder/key1/key1_2")); - } - gchar *val = confi_path_get_value (confi, "folder/key1/key1_2"); ++ gchar *val = zak_confi_path_get_value (confi, "folder/key1/key1_2"); + g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", val); - confi_path_set_value (confi, "folder/key1/key1_2", "new value programmatically setted"); - g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", confi_path_get_value (confi, "folder/key1/key1_2")); - confi_path_set_value (confi, "folder/key1/key1_2", val); - g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", confi_path_get_value (confi, "folder/key1/key1_2")); ++ zak_confi_path_set_value (confi, "folder/key1/key1_2", "new value programmatically setted"); ++ g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", zak_confi_path_get_value (confi, "folder/key1/key1_2")); ++ zak_confi_path_set_value (confi, "folder/key1/key1_2", val); ++ g_printf ("Value from key \"folder/key1/key1_2\"\n%s\n\n", zak_confi_path_get_value (confi, "folder/key1/key1_2")); + - confi_add_key (confi, "folder/key2", "key2-2", NULL); - confi_path_set_value (confi, "folder/key2/key2-2", "value for key2-2, programmatically setted"); ++ zak_confi_add_key (confi, "folder/key2", "key2-2", NULL); ++ zak_confi_path_set_value (confi, "folder/key2/key2-2", "value for key2-2, programmatically setted"); + - ConfiKey *ck; - ck = confi_path_get_confi_key (confi, "folder/key2/key2-2"); ++ ZakConfiKey *ck; ++ ck = zak_confi_path_get_confi_key (confi, "folder/key2/key2-2"); + g_printf ("ConfiKey for folder/key2/key2-2\n"); + g_printf ("Path: %s\n", ck->path); + g_printf ("Key: %s\n", ck->key); + g_printf ("Description: %s\n", ck->description); + g_printf ("Value: %s\n", ck->value); + g_printf ("\n"); + + g_printf ("Setting root \"folder/key2\"\n"); - confi_set_root (confi, "folder/key2"); - g_printf ("Value from key \"key2-1\" %s\n", confi_path_get_value (confi, "key2-1")); - g_printf ("Value from key \"folder/key1/key1_2\" (expected null) %s\n", confi_path_get_value (confi, "folder/key1/key1_2")); ++ zak_confi_set_root (confi, "folder/key2"); ++ g_printf ("Value from key \"key2-1\" %s\n", zak_confi_path_get_value (confi, "key2-1")); ++ g_printf ("Value from key \"folder/key1/key1_2\" (expected null) %s\n", zak_confi_path_get_value (confi, "folder/key1/key1_2")); - confi_destroy (confi); + zak_confi_destroy (confi); return 0; }