~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to lib/cgraph/graph.c

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: graph.c,v 1.1 2007/10/25 20:27:57 north Exp $ $Revision: 1.1 $ */
 
1
/* $Id: graph.c,v 1.8 2009/07/11 15:38:51 erg Exp $ $Revision: 1.8 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
82
82
        AGSEQ(g) = agnextseq(par, AGRAPH);
83
83
        dtinsert(par->g_dict, g);
84
84
    }                           /* else AGSEQ=0 */
85
 
    if (g->desc.has_attrs)
 
85
    if (!par || par->desc.has_attrs)
86
86
        agraphattr_init(g);
87
87
    agmethod_init(g, g);
88
88
    return g;
191
191
    return g->desc.strict;
192
192
}
193
193
 
 
194
int agissimple(Agraph_t * g)
 
195
{
 
196
    return (g->desc.strict && g->desc.no_loop);
 
197
}
 
198
 
 
199
static int cnt(Dict_t * d, Dtlink_t ** set)
 
200
{
 
201
        int rv;
 
202
    dtrestore(d, *set);
 
203
    rv = dtsize(d);
 
204
    *set = dtextract(d);
 
205
        return rv;
 
206
}
 
207
 
 
208
int agcountuniqedges(Agraph_t * g, Agnode_t * n, int want_in, int want_out)
 
209
{
 
210
    Agedge_t *e;
 
211
    Agsubnode_t *sn;
 
212
    int rv = 0;
 
213
 
 
214
    sn = agsubrep(g, n);
 
215
    if (want_out) rv = cnt(g->e_seq,&(sn->out_seq));
 
216
    if (want_in) {
 
217
                if (!want_out) rv += cnt(g->e_seq,&(sn->in_seq));       /* cheap */
 
218
                else {  /* less cheap */
 
219
                        for (e = agfstin(g, n); e; e = agnxtin(g, e))
 
220
                                if (e->node != n) rv++;  /* don't double count loops */
 
221
                }
 
222
    }
 
223
    return rv;
 
224
}
 
225
 
194
226
int agdegree(Agraph_t * g, Agnode_t * n, int want_in, int want_out)
195
227
{
196
 
    Agedge_t *e;
 
228
    Agsubnode_t *sn;
197
229
    int rv = 0;
198
230
 
199
 
    if (want_in)
200
 
        for (e = agfstin(g, n); e; e = agnxtin(g, e))
201
 
            rv++;
202
 
    if (want_out)
203
 
        for (e = agfstout(g, n); e; e = agnxtout(g, e))
204
 
            rv++;
205
 
    return rv;
 
231
    sn = agsubrep(g, n);
 
232
    if (want_out) rv += cnt(g->e_seq,&(sn->out_seq));
 
233
    if (want_in) rv += cnt(g->e_seq,&(sn->in_seq));
 
234
        return rv;
206
235
}
207
236
 
208
237
int agraphidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc)
234
263
};
235
264
 
236
265
 
237
 
/* directed, strict, maingraph */
238
 
Agdesc_t Agdirected = { 1, 0, 1 };
239
 
Agdesc_t Agstrictdirected = { 1, 1, 1 };
240
 
Agdesc_t Agundirected = { 0, 0, 1 };
241
 
Agdesc_t Agstrictundirected = { 0, 1, 1 };
 
266
/* directed, strict, no_loops, maingraph */
 
267
Agdesc_t Agdirected = { 1, 0, 0, 1 };
 
268
Agdesc_t Agstrictdirected = { 1, 1, 0, 1 };
 
269
Agdesc_t Agundirected = { 0, 0, 0, 1 };
 
270
Agdesc_t Agstrictundirected = { 0, 1, 0, 1 };
242
271
 
243
272
Agdisc_t AgDefaultDisc = { &AgMemDisc, &AgIdDisc, &AgIoDisc };