Debian Codegraph @

lib/circogen/block.c

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11 #include "config.h"
12
13 #include <assert.h>
14 #include <circogen/circular.h>
15 #include <circogen/block.h>
16 #include <util/alloc.h>
17 #include <util/list.h>
18
19 void initBlocklist(blocklist_t * bl)
20 {
21 bl->first = NULL;
22 bl->last = NULL;
23 }
24
25 block_t *mkBlock(Agraph_t * g)
26 {
27 block_t *sn = gv_alloc(sizeof(block_t));
28 initBlocklist(&sn->children);
29 sn->sub_graph = g;
30 return sn;
31 }
32
33 void freeBlock(block_t * sp)
34 {
35 if (!sp)
36 return;
37 LIST_FREE(&sp->circle_list);
38 free(sp);
39 }
40
41 int blockSize(block_t * sp)
42 {
43 return agnnodes (sp->sub_graph);
44 }
45
46 /// add block at end
47 void appendBlock(blocklist_t * bl, block_t * bp)
48 {
49 bp->next = NULL;
50 if (bl->last) {
51 bl->last->next = bp;
52 bl->last = bp;
53 } else {
54 bl->first = bp;
55 bl->last = bp;
56 }
57 }
58
59 /// add block at beginning
60 void insertBlock(blocklist_t * bl, block_t * bp)
61 {
62 if (bl->first) {
63 bp->next = bl->first;
64 bl->first = bp;
65 } else {
66 bl->first = bp;
67 bl->last = bp;
68 }
69 }
70
71 #ifdef DEBUG
72 void printBlocklist(blocklist_t * snl)
73 {
74 block_t *bp;
75 for (bp = snl->first; bp; bp = bp->next) {
76 Agnode_t *n;
77 char *p;
78 Agraph_t *g = bp->sub_graph;
79 fprintf(stderr, "block=%s\n", agnameof(g));
80 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
81 Agedge_t *e;
82 if (PARENT(n))
83 p = agnameof(PARENT(n));
84 else
85 p = "<nil>";
86 fprintf(stderr, " %s (%d %s)\n", agnameof(n), VAL(n), p);
87 for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
88 fprintf(stderr, " %s--", agnameof(agtail(e)));
89 fprintf(stderr, "%s\n", agnameof(aghead(e)));
90 }
91 }
92 }
93 }
94 #endif