diff options
Diffstat (limited to 'plugins/yaml/collection.c')
-rw-r--r-- | plugins/yaml/collection.c | 83 |
1 files changed, 52 insertions, 31 deletions
diff --git a/plugins/yaml/collection.c b/plugins/yaml/collection.c index 1615fa8..376e894 100644 --- a/plugins/yaml/collection.c +++ b/plugins/yaml/collection.c @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * collection.h - collection de noeuds Yaml + * collection.h - collection de noeuds Yaml de type "sequence" ou "mapping" * * Copyright (C) 2019 Cyrille Bagard * @@ -27,11 +27,14 @@ #include <malloc.h> +#include "node-int.h" + + /* Collection de noeuds au format Yaml (instance) */ struct _GYamlCollection { - GObject parent; /* A laisser en premier */ + GYamlNode parent; /* A laisser en premier */ bool is_seq; /* Nature de la collection */ @@ -43,7 +46,7 @@ struct _GYamlCollection /* Collection de noeuds au format Yaml (classe) */ struct _GYamlCollectionClass { - GObjectClass parent; /* A laisser en premier */ + GYamlNodeClass parent; /* A laisser en premier */ }; @@ -60,10 +63,13 @@ static void g_yaml_collection_dispose(GYamlCollection *); /* Procède à la libération totale de la mémoire. */ static void g_yaml_collection_finalize(GYamlCollection *); +/* Recherche les noeuds correspondant à un chemin. */ +static void g_yaml_collection_find_by_path(const GYamlCollection *, const char *, bool, GYamlNode ***, size_t *); + /* Indique le type défini pour une collection de noeuds Yaml. */ -G_DEFINE_TYPE(GYamlCollection, g_yaml_collection, G_TYPE_OBJECT); +G_DEFINE_TYPE(GYamlCollection, g_yaml_collection, G_TYPE_YAML_NODE); /****************************************************************************** @@ -81,12 +87,17 @@ G_DEFINE_TYPE(GYamlCollection, g_yaml_collection, G_TYPE_OBJECT); static void g_yaml_collection_class_init(GYamlCollectionClass *klass) { GObjectClass *object; /* Autre version de la classe */ + GYamlNodeClass *node; /* Version parente de classe */ object = G_OBJECT_CLASS(klass); object->dispose = (GObjectFinalizeFunc/* ! */)g_yaml_collection_dispose; object->finalize = (GObjectFinalizeFunc)g_yaml_collection_finalize; + node = G_YAML_NODE_CLASS(klass); + + node->find = (find_yaml_node_fc)g_yaml_collection_find_by_path; + } @@ -264,10 +275,11 @@ GYamlNode **g_yaml_collection_get_nodes(const GYamlCollection *collec, size_t *c /****************************************************************************** * * -* Paramètres : collec = noeud d'arborescence Yaml à consulter. * -* path = chemin d'accès à parcourir. * -* nodes = liste de noeuds avec correspondance établie. [OUT] * -* count = quantité de ces noeuds. [OUT] * +* Paramètres : node = noeud d'arborescence Yaml à consulter. * +* path = chemin d'accès à parcourir. * +* prepare = indication sur une préparation d'un prochain appel.* +* nodes = liste de noeuds avec correspondance établie. [OUT] * +* count = quantité de ces noeuds. [OUT] * * * * Description : Recherche les noeuds correspondant à un chemin. * * * @@ -277,36 +289,45 @@ GYamlNode **g_yaml_collection_get_nodes(const GYamlCollection *collec, size_t *c * * ******************************************************************************/ -void _g_yaml_collection_find_by_path(const GYamlCollection *collec, const char *path, GYamlNode ***nodes, size_t *count) +static void g_yaml_collection_find_by_path(const GYamlCollection *collec, const char *path, bool prepare, GYamlNode ***nodes, size_t *count) { size_t i; /* Boucle de parcours */ - for (i = 0; i < collec->count; i++) - _g_yaml_node_find_by_path(collec->nodes[i], path, nodes, count); + if (path[0] != '/') + goto wrong_path; -} + if (path[1] == '\0') + { + if (prepare) + { + *nodes = realloc(*nodes, ++(*count) * sizeof(GYamlNode **)); + g_object_ref(G_OBJECT(collec)); + (*nodes)[*count - 1] = G_YAML_NODE(collec); -/****************************************************************************** -* * -* Paramètres : collec = noeud d'arborescence Yaml à consulter. * -* path = chemin d'accès à parcourir. * -* nodes = liste de noeuds avec correspondance établie. [OUT] * -* count = quantité de ces noeuds. [OUT] * -* * -* Description : Recherche les noeuds correspondant à un chemin. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ + } + else + { + *nodes = realloc(*nodes, (*count + collec->count) * sizeof(GYamlNode **)); -void g_yaml_collection_find_by_path(const GYamlCollection *collec, const char *path, GYamlNode ***nodes, size_t *count) -{ - *nodes = NULL; - *count = 0; + for (i = 0; i < collec->count; i++) + { + g_object_ref(G_OBJECT(collec->nodes[i])); + (*nodes)[*count + i] = collec->nodes[i]; + } + + *count += collec->count; + + } + + } + + else + for (i = 0; i < collec->count; i++) + _g_yaml_node_find_by_path(collec->nodes[i], path, prepare, nodes, count); + + wrong_path: - _g_yaml_collection_find_by_path(collec, path, nodes, count); + ; } |