1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14#include "cghdr.h"
15
16static void agflatten_elist(Dict_t * d, Dtlink_t ** lptr, int flag)
17{
18 dtrestore(d, *lptr);
19 dtmethod(d, flag? Dtlist : Dtoset);
20 *lptr = dtextract(d);
21}
22
23void agflatten_edges(Agraph_t * g, Agnode_t * n, int flag)
24{
25 Agsubnode_t *sn;
26 Dtlink_t **tmp;
27
28 sn = agsubrep(g,n);
29 tmp = &(sn->out_seq); /* avoiding - "dereferencing type-punned pointer will break strict-aliasing rules" */
30 agflatten_elist(g->e_seq, tmp, flag);
31 tmp = &(sn->in_seq);
32 agflatten_elist(g->e_seq, tmp, flag);
33}
34
35void agflatten(Agraph_t * g, int flag)
36{
37 Agnode_t *n;
38
39 if (flag) {
40 if (g->desc.flatlock == FALSE) {
41 dtmethod(g->n_seq,Dtlist);
42 for (n = agfstnode(g); n; n = agnxtnode(g,n))
43 agflatten_edges(g, n, flag);
44 g->desc.flatlock = TRUE;
45 }
46 } else {
47 if (g->desc.flatlock) {
48 dtmethod(g->n_seq,Dtoset);
49 for (n = agfstnode(g); n; n = agnxtnode(g,n))
50 agflatten_edges(g, n, flag);
51 g->desc.flatlock = FALSE;
52 }
53 }
54}
55
56void agnotflat(Agraph_t * g)
57{
58 if (g->desc.flatlock)
59 agerr(AGERR, "flat lock broken");
60}
61