]> granicus.if.org Git - graphviz/commitdiff
Add option to ccomps to allow range of output graphs
authorerg <devnull@localhost>
Mon, 14 Jun 2010 16:56:04 +0000 (16:56 +0000)
committererg <devnull@localhost>
Mon, 14 Jun 2010 16:56:04 +0000 (16:56 +0000)
cmd/tools/ccomps.1
cmd/tools/ccomps.c

index c85283c28e10b8284b964f90dca97d33ccbf4672..1b95fa89070f299fae8331cf3a7256326bb53160 100644 (file)
@@ -7,7 +7,7 @@ ccomps \- connected components filter for graphs
 .B \-sxvnzC?
 ]
 [
-.BI -X [#]v
+.BI -X [#]s[-f]
 ]
 [
 .BI -o outfile
@@ -34,7 +34,7 @@ Counts of nodes, edges and connected components are printed.
 .TP
 .B \-z
 Sort components by size, with the largest first. This is only
-effective if either \fB-x\fP or \fB-X#v\fP is present.
+effective if either \fB-x\fP or \fB-X#\fP is present.
 Thus, \fB-zX#0\fP will cause the largest component to be printed.
 .TP
 .B \-C
@@ -57,8 +57,17 @@ edges.
 Prints only the component containing the node \fInode_name\fP,
 if any.
 .TP
-.BI \-X# " index"
-Prints only component number \fIindex\fP, if any, starting at 0.
+.BI \-X# " start"
+.TP
+.BI \-X# " start-"
+.TP
+.BI \-X# " start-last"
+Prints only components in the given range. In the first form, only
+the component whose index is \fIstart\fP, if any, is printed.
+In the second form, each component whose index is at least \fIstart\fP
+is printed. In the last form, only those components whose indices are
+in the range \fB[\fP\fIIstart\fP\fB,\fP\fIlast\fP\fB]\fP are printed.
+Thus, the flag \fB-x\fP is equivalent to \fB-X#0-\fP.
 .TP
 .BI \-o " outfile"
 If specified, each graph will be written to a different file
index 596d8478abd0c530e0d36d41239d25ba4693a3c4..9df3677ec3110351354c5e7e2930151005d9ae8a 100644 (file)
@@ -83,11 +83,13 @@ char *path = 0;
 int sufcnt = 0;
 int sorted = 0;
 int sortIndex = 0;
+int sortFinal;
 int x_index = -1;
+int x_final = -1;  /* require 0 <= x_index <= x_final or x_final= -1 */ 
 char *x_node;
 
 static char *useString =
-    "Usage: ccomps [-svnCx?] [-X[#]v] [-o<out template>] <files>\n\
+    "Usage: ccomps [-svnCx?] [-X[#]s[-f]] [-o<out template>] <files>\n\
   -s - silent\n\
   -x - external\n\
   -X - extract component\n\
@@ -133,6 +135,7 @@ static int isCluster(Agraph_t * g)
 static void init(int argc, char *argv[])
 {
     int c;
+    char* endp;
 
     Cmd = argv[0];
     opterr = 0;
@@ -158,8 +161,26 @@ static void init(int argc, char *argv[])
            if (*optarg == '#') {
                char *p = optarg + 1;
                if (isdigit(*p)) {
-                   x_index = atoi(p);
+                   x_index = (int)strtol (p, &endp, 10);
                    printMode = EXTRACT;
+                   if (*endp == '-') {
+                       p = endp + 1;
+                       if (isdigit(*p)) {
+                           x_final = atoi (p);
+                           if (x_final < x_index) {
+                               printMode = INTERNAL;
+                               fprintf(stderr,
+                                   "ccomps: final index %d < start index %d in -X%s flag - ignored\n",
+                                   x_final, x_index, optarg);
+                           }
+                       }
+                       else if (*p) {
+                           printMode = INTERNAL;
+                           fprintf(stderr,
+                               "ccomps: number expected in -X%s flag - ignored\n",
+                               optarg);
+                       }
+                   }
                } else
                    fprintf(stderr,
                            "ccomps: number expected in -X%s flag - ignored\n",
@@ -191,6 +212,7 @@ static void init(int argc, char *argv[])
        if ((printMode == EXTRACT) && (x_index >= 0)) {
            printMode = INTERNAL;
            sortIndex = x_index;
+           sortFinal = x_final;
        }
        else if (printMode == EXTERNAL) {
            sortIndex = -1;
@@ -540,7 +562,7 @@ printSorted (Agraph_t* root, int c_cnt)
 {
     Agraph_t** ccs = N_NEW(c_cnt, Agraph_t*);
     Agraph_t* subg;
-    int i = 0;
+    int i = 0, endi;
 
     for (subg = agfstsubg(root); subg; subg = agnxtsubg(subg)) {
        if (GD_cc_subg(subg))
@@ -556,10 +578,16 @@ printSorted (Agraph_t* root, int c_cnt)
                sortIndex, agnameof(root));
            return;
        }
-       subg = ccs[sortIndex];
-       if (doAll)
-           subGInduce(root, subg);
-       gwrite(subg);
+       if (sortFinal >= sortIndex)
+           endi = sortFinal;
+       else
+           endi = c_cnt-1;
+        for (i = sortIndex; i <= endi ; i++) {
+           subg = ccs[i];
+           if (doAll)
+               subGInduce(root, subg);
+           gwrite(subg);
+       }
     }
     else for (i = 0; i < c_cnt; i++) {
        subg = ccs[i];
@@ -582,6 +610,7 @@ static int processClusters(Agraph_t * g)
     Agnode_t *n;
     Agraph_t *dout;
     Agnode_t *dn;
+    int extracted = 0;
 
     dg = deriveGraph(g);
 
@@ -628,11 +657,13 @@ static int processClusters(Agraph_t * g)
                subGInduce(g, out);
            gwrite(out);
        } else if (printMode == EXTRACT) {
-           if (x_index == c_cnt) {
+           if (x_index <= c_cnt) {
+               extracted = 1;
                if (doAll)
                    subGInduce(g, out);
                gwrite(out);
-               return 0;
+               if (c_cnt == x_final)
+                   return 0;
            }
        }
        if (printMode != INTERNAL)
@@ -643,7 +674,7 @@ static int processClusters(Agraph_t * g)
                    c_cnt, n_cnt, e_cnt);
        c_cnt++;
     }
-    if (printMode == EXTRACT) {
+    if ((printMode == EXTRACT) && !extracted)  {
        fprintf(stderr,
                "ccomps: component %d not found in graph %s - ignored\n",
                x_index, agnameof(g));
@@ -684,6 +715,7 @@ static int process(Agraph_t * g)
     char *name;
     Agraph_t *out;
     Agnode_t *n;
+    int extracted = 0;
 
     aginit(g, AGNODE, "nodeinfo", sizeof(Agnodeinfo_t), TRUE);
     bindGraphinfo (g);
@@ -731,11 +763,13 @@ static int process(Agraph_t * g)
                subGInduce(g, out);
            gwrite(out);
        } else if (printMode == EXTRACT) {
-           if (x_index == c_cnt) {
+           if (x_index <= c_cnt) {
+               extracted = 1;
                if (doAll)
                    subGInduce(g, out);
                gwrite(out);
-               return 0;
+               if (c_cnt == x_final)
+                   return 0;
            }
        }
        if (printMode != INTERNAL)
@@ -745,7 +779,7 @@ static int process(Agraph_t * g)
                    c_cnt, n_cnt, e_cnt);
        c_cnt++;
     }
-    if (printMode == EXTRACT) {
+    if ((printMode == EXTRACT) && !extracted) {
        fprintf(stderr,
                "ccomps: component %d not found in graph %s - ignored\n",
                x_index, agnameof(g));