/* OpenIDA - Outil d'analyse de fichiers binaires
* layout.c - mise en place de graphique
*
* 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 .
*/
#include "layout.h"
#include
#include
#include
#include "dot.h"
#include "node.h"
#include "../common/extstr.h"
/******************************************************************************
* *
* Paramètres : view = support à placer les différents éléments. *
* views = morceaux de code à afficher de façon organisée. *
* count = quantité de ces morceaux de code. *
* *
* Description : Dispose une série de morceaux d'affichage en graphique. *
* *
* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count)
{
GGraphNode **nodes; /* Intermédiaires en place */
size_t i; /* Boucle de parcours */
char *cmds; /* Description à envoyer à dot */
graph_layout *layout; /* Graphique construit */
GtkLinkRenderer **links; /* Liens graphiques construits */
size_t links_count; /* Quantité de ces liens */
/* Création de la glue */
nodes = (GGraphNode **)calloc(count, sizeof(GGraphNode *));
for (i = 0; i < count; i++)
nodes[i] = g_graph_node_new(views[i]);
/* Définition du graphique */
cmds = strdup("digraph G {\noverlap=false;\n splines=true;\n");
//cmds = strdup("digraph G {\n");
for (i = 0; i < count; i++)
cmds = g_graph_node_register_for_dot(nodes[i], cmds);
for (i = 0; (i + 1) < count; i++)
{
char buffer[128];
snprintf(buffer, 128, "_%p -> _%p;\n", views[i], views[i + 1]);
cmds = stradd(cmds, buffer);
}
cmds = stradd(cmds, "}");
printf("first step :: '%s'\n", cmds);
layout = create_graph_layout(cmds);
/* Affichage du graphique */
place_nodes_of_graph_layout(layout, GTK_FIXED(view), nodes, count);
links = create_links_from_graph_layout(layout, &links_count);
gtk_graph_view_attach_links(view, links, links_count);
delete_graph_layout(layout);
/* TODO : free nodes */
return true;
}