block.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include <assert.h>
  11. #include <circogen/circular.h>
  12. #include <circogen/block.h>
  13. #include <util/alloc.h>
  14. void initBlocklist(blocklist_t * bl)
  15. {
  16. bl->first = NULL;
  17. bl->last = NULL;
  18. }
  19. block_t *mkBlock(Agraph_t * g)
  20. {
  21. block_t *sn = gv_alloc(sizeof(block_t));
  22. initBlocklist(&sn->children);
  23. sn->sub_graph = g;
  24. return sn;
  25. }
  26. void freeBlock(block_t * sp)
  27. {
  28. if (!sp)
  29. return;
  30. nodelist_free(&sp->circle_list);
  31. free(sp);
  32. }
  33. int blockSize(block_t * sp)
  34. {
  35. return agnnodes (sp->sub_graph);
  36. }
  37. /// add block at end
  38. void appendBlock(blocklist_t * bl, block_t * bp)
  39. {
  40. bp->next = NULL;
  41. if (bl->last) {
  42. bl->last->next = bp;
  43. bl->last = bp;
  44. } else {
  45. bl->first = bp;
  46. bl->last = bp;
  47. }
  48. }
  49. /// add block at beginning
  50. void insertBlock(blocklist_t * bl, block_t * bp)
  51. {
  52. if (bl->first) {
  53. bp->next = bl->first;
  54. bl->first = bp;
  55. } else {
  56. bl->first = bp;
  57. bl->last = bp;
  58. }
  59. }
  60. #ifdef DEBUG
  61. void printBlocklist(blocklist_t * snl)
  62. {
  63. block_t *bp;
  64. for (bp = snl->first; bp; bp = bp->next) {
  65. Agnode_t *n;
  66. char *p;
  67. Agraph_t *g = bp->sub_graph;
  68. fprintf(stderr, "block=%s\n", agnameof(g));
  69. for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
  70. Agedge_t *e;
  71. if (PARENT(n))
  72. p = agnameof(PARENT(n));
  73. else
  74. p = "<nil>";
  75. fprintf(stderr, " %s (%d %s)\n", agnameof(n), VAL(n), p);
  76. for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
  77. fprintf(stderr, " %s--", agnameof(agtail(e)));
  78. fprintf(stderr, "%s\n", agnameof(aghead(e)));
  79. }
  80. }
  81. }
  82. }
  83. #endif