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