Graphviz  2.41.20171026.1811
block.c
Go to the documentation of this file.
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 
15 #include <assert.h>
16 
17 #include "circular.h"
18 #include "block.h"
19 
21 {
22  bl->first = NULL;
23  bl->last = NULL;
24 }
25 
26 /*
27 void
28 cleanBlocklist(blocklist_t* sp)
29 {
30  block_t* bp;
31  block_t* temp;
32 
33  if (!sp) return;
34  for(bp = sp->first; bp; bp = temp) {
35  temp = bp->next;
36  freeBlock(bp);
37  }
38 }
39 */
40 
42 {
43  block_t *sn;
44 
45  sn = NEW(block_t);
46  initBlocklist(&sn->children);
47  sn->sub_graph = g;
48  return sn;
49 }
50 
51 void freeBlock(block_t * sp)
52 {
53  if (!sp)
54  return;
56  free(sp);
57 }
58 
59 int blockSize(block_t * sp)
60 {
61  return agnnodes (sp->sub_graph);
62 }
63 
64 /* appendBlock:
65  * add block at end
66  */
68 {
69  bp->next = NULL;
70  if (bl->last) {
71  bl->last->next = bp;
72  bl->last = bp;
73  } else {
74  bl->first = bp;
75  bl->last = bp;
76  }
77 }
78 
79 /* insertBlock:
80  * add block at beginning
81  */
83 {
84  if (bl->first) {
85  bp->next = bl->first;
86  bl->first = bp;
87  } else {
88  bl->first = bp;
89  bl->last = bp;
90  }
91 }
92 
93 #ifdef DEBUG
94 void printBlocklist(blocklist_t * snl)
95 {
96  block_t *bp;
97  for (bp = snl->first; bp; bp = bp->next) {
98  Agnode_t *n;
99  char *p;
100  Agraph_t *g = bp->sub_graph;
101  fprintf(stderr, "block=%s\n", agnameof(g));
102  for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
103  Agedge_t *e;
104  if (PARENT(n))
105  p = agnameof(PARENT(n));
106  else
107  p = "<nil>";
108  fprintf(stderr, " %s (%d %s)\n", agnameof(n), VAL(n), p);
109  for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
110  fprintf(stderr, " %s--", agnameof(agtail(e)));
111  fprintf(stderr, "%s\n", agnameof(aghead(e)));
112  }
113  }
114  }
115 }
116 #endif
void appendBlock(blocklist_t *bl, block_t *bp)
Definition: block.c:67
void initBlocklist(blocklist_t *bl)
Definition: block.c:20
CGRAPH_API Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Definition: edge.c:86
#define PARENT(n)
Definition: circular.h:89
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
Definition: edge.c:525
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition: node.c:45
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
Definition: edge.c:533
Agraph_t * sub_graph
Definition: block.h:33
void insertBlock(blocklist_t *bl, block_t *bp)
Definition: block.c:82
CGRAPH_API char * agnameof(void *)
Definition: id.c:143
int blockSize(block_t *sp)
Definition: block.c:59
block_t * first
Definition: block.h:26
void freeNodelist(nodelist_t *list)
Definition: nodelist.c:32
block_t * last
Definition: block.h:27
block_t * mkBlock(Agraph_t *g)
Definition: block.c:41
nodelist_t * circle_list
Definition: block.h:36
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
Definition: node.c:38
Definition: block.h:30
#define NULL
Definition: logic.h:39
CGRAPH_API Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition: edge.c:95
block_t * next
Definition: block.h:32
#define VAL(n)
Definition: circular.h:92
CGRAPH_API int agnnodes(Agraph_t *g)
Definition: graph.c:162
void freeBlock(block_t *sp)
Definition: block.c:51
blocklist_t children
Definition: block.h:37
#define NEW(t)
Definition: memory.h:35