2
This software may only be used by you under license from AT&T Corp.
3
("AT&T"). A copy of AT&T's Source Code Agreement is available at
4
AT&T's Internet website having the URL:
5
<http://www.research.att.com/sw/tools/graphviz/license/source.html>
6
If you received this software without first entering into a license
7
with AT&T, you have an infringing copy of this software and cannot use
8
it without violating AT&T's intellectual property rights.
12
* Written by Stephen North
13
* Updated by Emden Gansner
16
typedef char Agraphinfo_t;
17
typedef struct Agnodeinfo_t { char mark; } Agnodeinfo_t;
18
typedef char Agedgeinfo_t;
35
int printMode = INTERNAL;
41
static char* useString =
42
"Usage: ccomps [-svx?] [-o <out template>] <files>\n\
46
-o - output file template\n\
48
If no files are specified, stdin is used\n";
63
sfx = strrchr (name, '.');
67
path = (char*)malloc (size+1);
68
strncpy (path, name, size);
77
init (int argc, char* argv[])
82
while ((c = getopt(argc, argv, ":o:xsv?")) != -1) {
99
if (optopt == '?') usage(0);
100
else fprintf(stderr,"ccomps: option -%c unrecognized - ignored\n", c);
107
if (argc) Files = argv;
111
dfs(Agraph_t* g, Agnode_t* n, Agraph_t* out, int cnt)
119
for (e = agfstedge(g,n); e ; e = agnxtedge(g,e,n)) {
120
if ((other = e->tail) == n) other = e->head;
121
if (other->u.mark == 0) cnt = dfs(g,other,out,cnt);
127
nodeInduce (Agraph_t* g)
133
for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
134
for (e = agfstout(g->root,n); e; e = agnxtout(g->root,e)) {
135
if (agcontains(g,e->head)) {
148
static char* buf = 0;
150
if (sufcnt == 0) name = outfile;
153
buf = (char*)malloc(strlen(outfile)+20); /* enough to handle '_number' */
154
if (suffix) sprintf (buf, "%s_%d.%s", path, sufcnt, suffix);
155
else sprintf (buf, "%s_%d", path, sufcnt);
168
if (!outfile) agwrite (g, stdout);
171
outf = fopen (name, "w");
173
fprintf (stderr, "Could not open %s for writing\n", name);
182
process (Agraph_t* g)
184
long n_cnt,c_cnt,e_cnt;
190
for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
191
if (n->u.mark) continue;
192
sprintf(name,"%s_component_%d",g->name,c_cnt);
193
out = agsubg(g,name);
194
n_cnt = dfs(g,n,out,0);
195
e_cnt = nodeInduce(out);
196
if (printMode == EXTERNAL) gwrite(out);
197
if (printMode != INTERNAL)
200
fprintf(stderr,"(%4d) %7ld nodes %7ld edges\n",
201
c_cnt, n_cnt, e_cnt);
205
if (printMode == INTERNAL) gwrite(g);
208
fprintf(stderr," %7ld nodes %7ld edges %7ld components %s\n",
209
agnnodes(g),agnedges(g),c_cnt,g->name);
213
main (int argc, char* argv[])
219
newIngraph (&ig, Files, agread);
221
while ((g = nextGraph(&ig)) != 0) {