| 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 | |
| 20 | void initBlocklist(blocklist_t * bl) |
| 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 | |
| 41 | block_t *mkBlock(Agraph_t * g) |
| 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; |
| 55 | freeNodelist(sp->circle_list); |
| 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 | */ |
| 67 | void appendBlock(blocklist_t * bl, block_t * bp) |
| 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 | */ |
| 82 | void insertBlock(blocklist_t * bl, block_t * bp) |
| 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 |
| 117 | |