.B \-sxvnzC?
]
[
-.BI -X [#]v
+.BI -X [#]s[-f]
]
[
.BI -o outfile
.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
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
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\
static void init(int argc, char *argv[])
{
int c;
+ char* endp;
Cmd = argv[0];
opterr = 0;
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",
if ((printMode == EXTRACT) && (x_index >= 0)) {
printMode = INTERNAL;
sortIndex = x_index;
+ sortFinal = x_final;
}
else if (printMode == EXTERNAL) {
sortIndex = -1;
{
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))
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];
Agnode_t *n;
Agraph_t *dout;
Agnode_t *dn;
+ int extracted = 0;
dg = deriveGraph(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)
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));
char *name;
Agraph_t *out;
Agnode_t *n;
+ int extracted = 0;
aginit(g, AGNODE, "nodeinfo", sizeof(Agnodeinfo_t), TRUE);
bindGraphinfo (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)
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));