Graphviz  2.31.20130524.0447
lib/circogen/block.c
Go to the documentation of this file.
00001 /* $Id$ $Revision$ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 
00015 #include <assert.h>
00016 
00017 #include "circular.h"
00018 #include "block.h"
00019 
00020 void initBlocklist(blocklist_t * bl)
00021 {
00022     bl->first = NULL;
00023     bl->last = NULL;
00024 }
00025 
00026 /*
00027 void
00028 cleanBlocklist(blocklist_t* sp)
00029 {
00030         block_t*  bp;
00031         block_t*  temp;
00032 
00033     if (!sp) return;
00034         for(bp = sp->first; bp; bp = temp) {
00035                 temp = bp->next;
00036                 freeBlock(bp);
00037         }
00038 }
00039 */
00040 
00041 block_t *mkBlock(Agraph_t * g)
00042 {
00043     block_t *sn;
00044 
00045     sn = NEW(block_t);
00046     initBlocklist(&sn->children);
00047     sn->sub_graph = g;
00048     return sn;
00049 }
00050 
00051 void freeBlock(block_t * sp)
00052 {
00053     if (!sp)
00054         return;
00055     freeNodelist(sp->circle_list);
00056     free(sp);
00057 }
00058 
00059 int blockSize(block_t * sp)
00060 {
00061     return agnnodes (sp->sub_graph);
00062 }
00063 
00064 /* appendBlock:
00065  * add block at end
00066  */
00067 void appendBlock(blocklist_t * bl, block_t * bp)
00068 {
00069     bp->next = NULL;
00070     if (bl->last) {
00071         bl->last->next = bp;
00072         bl->last = bp;
00073     } else {
00074         bl->first = bp;
00075         bl->last = bp;
00076     }
00077 }
00078 
00079 /* insertBlock:
00080  * add block at beginning
00081  */
00082 void insertBlock(blocklist_t * bl, block_t * bp)
00083 {
00084     if (bl->first) {
00085         bp->next = bl->first;
00086         bl->first = bp;
00087     } else {
00088         bl->first = bp;
00089         bl->last = bp;
00090     }
00091 }
00092 
00093 #ifdef DEBUG
00094 void printBlocklist(blocklist_t * snl)
00095 {
00096     block_t *bp;
00097     for (bp = snl->first; bp; bp = bp->next) {
00098         Agnode_t *n;
00099         char *p;
00100         Agraph_t *g = bp->sub_graph;
00101         fprintf(stderr, "block=%s\n", agnameof(g));
00102         for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
00103             Agedge_t *e;
00104             if (PARENT(n))
00105                 p = agnameof(PARENT(n));
00106             else
00107                 p = "<nil>";
00108             fprintf(stderr, "  %s (%d %s)\n", agnameof(n), VAL(n), p);
00109             for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
00110                 fprintf(stderr, "    %s--", agnameof(agtail(e)));
00111                 fprintf(stderr, "%s\n", agnameof(aghead(e)));
00112             }
00113         }
00114     }
00115 }
00116 #endif