From 2ed2ddf74fc542b4df2e5a8470e303e9c8d1746d Mon Sep 17 00:00:00 2001 From: north Date: Thu, 25 Oct 2007 20:27:57 +0000 Subject: [PATCH] Initial version of Cgraph created. --- lib/cgraph/flatten.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/cgraph/flatten.c diff --git a/lib/cgraph/flatten.c b/lib/cgraph/flatten.c new file mode 100644 index 000000000..6e09077f5 --- /dev/null +++ b/lib/cgraph/flatten.c @@ -0,0 +1,44 @@ +#include "cghdr.h" + +static void agflatten_elist(Dict_t * d, Dtlink_t ** lptr) +{ + dtrestore(d, *lptr); + (void) dtflatten(d); + *lptr = dtextract(d); +} + +void agflatten_edges(Agraph_t * g, Agnode_t * n) +{ + Agsubnode_t *sn; + Dtlink_t **tmp; + + sn = agsubrep(g,n); + tmp = &(sn->out_seq); /* avoiding - "dereferencing type-punned pointer will break strict-aliasing rules" */ + agflatten_elist(g->e_seq, tmp); + tmp = &(sn->in_seq); + agflatten_elist(g->e_seq, tmp); +} + +void agflatten(Agraph_t * g, int flag) +{ + Agnode_t *n; + + if (flag) { + if (g->desc.flatlock == FALSE) { + dtflatten(g->n_seq); + g->desc.flatlock = TRUE; + for (n = agfstnode(g); n; n = agnxtnode(g,n)) + agflatten_edges(g, n); + } + } else { + if (g->desc.flatlock) { + g->desc.flatlock = FALSE; + } + } +} + +void agnotflat(Agraph_t * g) +{ + if (g->desc.flatlock) + agerr(AGERR, "flat lock broken"); +} -- 2.40.0