~ubuntu-branches/ubuntu/lucid/graphviz/lucid-updates

« back to all changes in this revision

Viewing changes to cmd/tools/gc.c

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-06-19 20:23:23 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080619202323-ls23h96ntj9ny94m
Tags: 2.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Drop libttf-dev (libttf-dev is in universe) (LP: #174749).
  - Replace gs-common with ghostscript.
  - Build-depend on python-dev instead of python2.4-dev or python2.5-dev.
  - Mention the correct python version for the python bindings in the
    package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: gc.c,v 1.3 2007/08/08 23:00:58 erg Exp $ $Revision: 1.3 $ */
 
1
/* $Id: gc.c,v 1.4 2008/01/09 20:50:35 erg Exp $ $Revision: 1.4 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
29
29
#endif
30
30
#include <string.h>
31
31
 
 
32
#ifdef USE_CGRAPH
 
33
#include <cgraph.h>
 
34
#include <cghdr.h>
 
35
typedef struct {
 
36
    Agrec_t h;
 
37
    int dfs_mark;
 
38
} Agnodeinfo_t;
 
39
 
 
40
#define ND_dfs_mark(n) (((Agnodeinfo_t*)(n->base.data))->dfs_mark)
 
41
#else
32
42
typedef struct {
33
43
    int cl_cnt;
34
44
} Agraphinfo_t;
39
49
 
40
50
#define GD_cl_cnt(g) (g)->u.cl_cnt
41
51
#define ND_dfs_mark(n) (n)->u.dfs_mark
 
52
#define agtail(e) ((e)->tail)
 
53
#define aghead(e) ((e)->head)
 
54
#define agnameof(g) ((g)->name)
42
55
 
43
56
#include <graph.h>
 
57
#endif
44
58
#include <ingraphs.h>
45
59
 
46
60
#ifdef HAVE_GETOPT_H
97
111
{
98
112
    unsigned int c;
99
113
 
 
114
#ifndef USE_CGRAPH
100
115
    aginit();
 
116
#endif
101
117
 
102
118
    while ((c = getopt(argc, argv, ":necCaDUrsv?")) != -1) {
103
119
        switch (c) {
160
176
 
161
177
    ND_dfs_mark(n) = 1;
162
178
    for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
163
 
        if (n == e->tail)
164
 
            nxt = e->head;
 
179
        if (n == agtail(e))
 
180
            nxt = aghead(e);
165
181
        else
166
 
            nxt = e->tail;
 
182
            nxt = agtail(e);
167
183
        if (ND_dfs_mark(nxt) == 0)
168
184
            cc_dfs(g, nxt);
169
185
    }
170
186
}
171
187
 
 
188
#ifdef USE_CGRAPH
 
189
static void cntCluster (Agraph_t * g, Agobj_t* sg, void* arg)
 
190
{
 
191
    char* sgname = agnameof ((Agraph_t*)sg);
 
192
 
 
193
    if (strncmp(sgname, "cluster", 7) == 0)
 
194
        *(int*)(arg) += 1;
 
195
}
 
196
#else
172
197
static void cl_count(Agraph_t * g)
173
198
{
174
199
    Agraph_t *mg;
188
213
    }
189
214
    GD_cl_cnt(g) = sum;
190
215
}
 
216
#endif
191
217
 
192
218
static int cc_decompose(Agraph_t * g)
193
219
{
235
261
        printf(" %s\n", gname);
236
262
}
237
263
 
238
 
static void emit(Agraph_t * g, int root)
 
264
static void emit(Agraph_t * g, int root, int cl_count)
239
265
{
240
266
    int n_edges = agnedges(g);
241
267
    int n_nodes = agnnodes(g);
247
273
        n_cc = cc_decompose(g);
248
274
 
249
275
    if (flags & CL)
 
276
#ifdef USE_CGRAPH
 
277
        n_cl = cl_count;
 
278
#else
250
279
        n_cl = GD_cl_cnt(g);
 
280
#endif
251
281
 
252
282
    if (root)
253
283
        file = fname;
254
 
    wcp(n_nodes, n_edges, n_cc, n_cl, g->name, file);
 
284
    wcp(n_nodes, n_edges, n_cc, n_cl, agnameof(g), file);
255
285
 
256
286
    if (root) {
257
287
        n_graphs++;
262
292
    }
263
293
}
264
294
 
 
295
#ifdef USE_CGRAPH
 
296
#define GTYPE(g) (agisdirected(g)?DIRECTED:UNDIRECTED)
 
297
 
 
298
static int eval(Agraph_t * g, int root)
 
299
{
 
300
    Agraph_t *subg;
 
301
    int cl_count;
 
302
 
 
303
    if (root && !(GTYPE(g) & gtype))
 
304
        return 1;
 
305
 
 
306
    if (root) {
 
307
        aginit(g, AGNODE, "nodeinfo", sizeof(Agnodeinfo_t), TRUE);
 
308
    }
 
309
 
 
310
    if ((flags & CL) && root) {
 
311
        cl_count = 0;
 
312
        agapply (g, (Agobj_t *)g, cntCluster, &cl_count, 0);
 
313
    }
 
314
 
 
315
    emit(g, root, cl_count);
 
316
 
 
317
    if (recurse) {
 
318
        n_indent++;
 
319
        for (subg = agfstsubg (g); subg; subg = agnxtsubg (subg))
 
320
            eval(subg, 0);
 
321
        n_indent--;
 
322
    }
 
323
    return 0;
 
324
}
 
325
#else
265
326
#define GTYPE(g) (AG_IS_DIRECTED(g)?DIRECTED:UNDIRECTED)
266
327
 
267
328
static int eval(Agraph_t * g, int root)
277
338
    if ((flags & CL) && root)
278
339
        cl_count(g);
279
340
 
280
 
    emit(g, root);
 
341
    emit(g, root, 0);
281
342
    if (recurse) {
282
343
        n_indent++;
283
344
        mg = g->meta_node->graph;
290
351
    }
291
352
    return 0;
292
353
}
 
354
#endif
 
355
 
 
356
#ifdef USE_CGRAPH
 
357
static Agraph_t *gread(FILE * fp)
 
358
{
 
359
    return agread(fp, (Agdisc_t *) 0);
 
360
}
 
361
#endif
293
362
 
294
363
int main(int argc, char *argv[])
295
364
{
298
367
    int rv = 0;
299
368
 
300
369
    init(argc, argv);
 
370
#ifdef USE_CGRAPH
 
371
    newIngraph(&ig, Files, gread);
 
372
#else
301
373
    newIngraph(&ig, Files, agread);
 
374
#endif
302
375
 
303
376
    while ((g = nextGraph(&ig)) != 0) {
304
377
        fname = fileName(&ig);
305
378
        if (verbose)
306
 
            fprintf(stderr, "Process graph %s in file %s\n", g->name,
 
379
            fprintf(stderr, "Process graph %s in file %s\n", agnameof(g),
307
380
                    fname);
308
381
        rv |= eval(g, 1);
309
382
        agclose(g);