- Agedge_t * edge = NULL;
- for (edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge)) {
+ unsigned cursor;
+ Agedge_t * edge;
+ xbt_dynar_reset(edges);
+ for (edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge))
+ xbt_dynar_push_as(edges, Agedge_t *, edge);
+#ifdef HAVE_CGRAPH_H
+ /* Hack: circumvent a bug in libcgraph, where the edges are not always given
+ * back in creation order. We sort them again, according to their sequence
+ * id. The problem appears to be solved (i.e.: I did not test it) in
+ * graphviz' mercurial repository by the following changeset:
+ * changeset: 8431:d5f1fb7e8103
+ * user: Emden Gansner <erg@research.att.com>
+ * date: Tue Oct 11 12:38:58 2011 -0400
+ * summary: Make sure edges are stored in node creation order
+ * It should be fixed in graphviz 2.30 and above.
+ */
+ xbt_dynar_sort(edges, edge_compare);
+#endif
+ xbt_dynar_foreach(edges, cursor, edge) {