summaryrefslogtreecommitdiff
path: root/src/graph/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graph/node.c')
-rw-r--r--src/graph/node.c225
1 files changed, 225 insertions, 0 deletions
diff --git a/src/graph/node.c b/src/graph/node.c
new file mode 100644
index 0000000..b220c4f
--- /dev/null
+++ b/src/graph/node.c
@@ -0,0 +1,225 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * node.c - éléments de graphiques chez dot
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "node.h"
+
+
+#include <stdio.h>
+
+
+#include "../common/extstr.h"
+
+
+
+/* -------------------------- GESTION DES NOEUDS A L'UNITE -------------------------- */
+
+
+/* Intermédiaire entre le noeud dot et la bribe de code (instance) */
+struct _GGraphNode
+{
+ GObject parent; /* A laisser en premier */
+
+ GtkBinView *view; /* Morceau de code représenté */
+ char *name; /* Adresse sous forme humaine */
+
+};
+
+
+/* Intermédiaire entre le noeud dot et la bribe de code (classe) */
+struct _GGraphNodeClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des intermédiaires avec les noeuds dot. */
+static void g_graph_node_class_init(GGraphNodeClass *);
+
+/* Initialise la classe des intermédiaires avec les noeuds dot. */
+static void g_graph_node_init(GGraphNode *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GESTION DES NOEUDS A L'UNITE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type définit par la GLib pour le noeud. */
+G_DEFINE_TYPE(GGraphNode, g_graph_node, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des intermédiaires avec les noeuds dot. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_node_class_init(GGraphNodeClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance à initialiser. *
+* *
+* Description : Initialise la classe des intermédiaires avec les noeuds dot. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_graph_node_init(GGraphNode *node)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : view = morceau d'affichage à représenter. *
+* *
+* Description : Constitue un intermédiaire entre un noeud dot et du code. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *g_graph_node_new(GtkBinView *view)
+{
+ GGraphNode *result; /* Structure à retourner */
+ size_t len; /* Taille du nom */
+
+ result = g_object_new(G_TYPE_GRAPH_NODE, NULL);
+
+ result->view = view;
+
+ len = 3 + sizeof(GtkBinView *) * 2 + 1;
+
+ result->name = (char *)calloc(len, sizeof(char));
+ snprintf(result->name, len, "_%p", result->view);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = intermédiaire à consulter. *
+* cmds = description pour dot à compléter. *
+* *
+* Description : Déclare l'intermédiaire en tant que noeud pour dot. *
+* *
+* Retour : Description dûment complétée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds)
+{
+ GtkRequisition requisition; /* Taille à l'écran requise */
+
+ cmds = stradd(cmds, node->name);
+
+
+ gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
+
+
+ cmds = stradd(cmds, " [shape=box];\n");
+
+ return cmds;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = intermédiaire à consulter. *
+* fixed = support de destination. *
+* x = abscisse du point d'intégration. *
+* y = ordonnée du point d'intégration. *
+* *
+* Description : Place le morceau de code de l'intermédiaire à l'écran. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_graph_node_place(const GGraphNode *node, GtkFixed *fixed, gint x, gint y)
+{
+ gtk_fixed_put(fixed, GTK_WIDGET(node->view), x, y);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATION D'ENSEMBLES DE NOEUDS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : nodes = liste de noeuds à parcourir. *
+* count = taille de la liste. *
+* target = nom du noeud recherché. *
+* *
+* Description : Recherche un noeud donné dans une série de noeuds. *
+* *
+* Retour : Noeud trouvé ou NULL si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGraphNode *find_graph_node_by_name(const GGraphNode **nodes, size_t count, const char *target)
+{
+ GGraphNode *result; /* Trouvaille à remonter */
+ size_t i; /* Boucle de parcours */
+
+ result = NULL;
+
+ for (i = 0; i < count && result == NULL; i++)
+ if (strcmp(nodes[i]->name, target) == 0)
+ result = nodes[i];
+
+ return result;
+
+}