]> granicus.if.org Git - graphviz/commitdiff
Add two new gvpr scripts: one to add edges to a graph, and the other
authorEmden R. Gansner <erg@emdenrg.net>
Mon, 11 Jan 2016 19:58:09 +0000 (14:58 -0500)
committerEmden R. Gansner <erg@emdenrg.net>
Mon, 11 Jan 2016 19:58:09 +0000 (14:58 -0500)
to report on multiedges and loops.

cmd/gvpr/lib/Makefile.am
cmd/gvpr/lib/addedges [new file with mode: 0644]
cmd/gvpr/lib/chkedges [new file with mode: 0644]

index ceaf2127e042e079db468d31f8f58120c74dc4e8..a6281928bd168ff3385766145ec663dccb1a4c66 100644 (file)
@@ -3,8 +3,8 @@
 
 gvprdir = $(pkgdatadir)/gvpr
 
-gvpr_DATA = addranks addrings anon attr bb bbox bipart binduce chkclusters \
-       cliptree col collapse color cycle dechain deghist \
+gvpr_DATA = addedges addranks addrings anon attr bb bbox bipart binduce chkclusters \
+       chkedges cliptree col collapse color cycle dechain deghist \
        deledges delmulti delnodes depath dijkstra \
        flatten get-layers-list histogram group indent knbhd \
        maxdeg path rotate scale scalexy span topon \
diff --git a/cmd/gvpr/lib/addedges b/cmd/gvpr/lib/addedges
new file mode 100644 (file)
index 0000000..1831c28
--- /dev/null
@@ -0,0 +1,20 @@
+/* Add edges from input graph to argument graph
+ * Does not add nodes.
+ */
+BEGIN{
+  graph_t g = readG(ARGV[0]);
+  node_t h, t;
+  edge_t e;
+}
+E {
+  if ((h = isNode(g,head.name)) && (t = isNode(g,tail.name))) {
+    if (!isEdge(t,h,"")) {
+      e = copy(g,$);
+    }
+  }
+}
+END {
+  write(g);
+}
+
+
diff --git a/cmd/gvpr/lib/chkedges b/cmd/gvpr/lib/chkedges
new file mode 100644 (file)
index 0000000..89ea02f
--- /dev/null
@@ -0,0 +1,40 @@
+/* Looks for multiedges and loops, and output
+ * those found along with counts. If the -d flag
+ * is given, edge direction is taken into account.
+ */
+BEGIN{
+  char* ename; 
+  char* n; 
+  int doDir, cnt[]; 
+  int loopcnt[];
+  int nloops, nmulti;
+  if ((ARGC > 0) && (ARGV[0] == "-d"))
+    doDir = 1;
+  else
+    doDir = 0;
+}
+BEG_G{unset(cnt); unset(loopcnt); nloops = nmulti = 0;}
+E{
+  if (doDir || (tail.name <= head.name)) ename=tail.name+"_"+head.name;
+  else ename = head.name+"_"+tail.name;
+  if (tail == head) {
+    loopcnt[ename] += 1;
+    if (loopcnt[ename] == 1) nloops += 1;
+  }
+  else {
+    cnt[ename] += 1;
+    if (cnt[ename] == 2) nmulti += 1;
+  }
+}
+END_G{
+  printf ("graph %s: %d loops %d multiedges\n", $.name, nloops, nmulti);
+  for (cnt[n]) {
+    if (cnt[n] > 1)
+      printf ("%s : %d\n", n, cnt[n]);
+  }
+  for (loopcnt[n]) {
+    if (loopcnt[n] > 0)
+      printf ("%s : %d\n", n, loopcnt[n]);
+  }
+}
+