~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to agraph/subg.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
9
*/
 
10
#pragma prototyped
 
11
 
 
12
#include <aghdr.h>
 
13
 
 
14
#ifdef DMALLOC
 
15
#include "dmalloc.h"
 
16
#endif
 
17
 
 
18
static Agraph_t *agfindsubg_by_id(Agraph_t *g, unsigned long id)
 
19
{
 
20
        Agraph_t                template;
 
21
 
 
22
        agdtdisc(g,g->g_dict,&Ag_obj_id_disc);
 
23
        AGID(&template) = id;
 
24
        return (Agraph_t*)dtsearch(g->g_dict,&template);
 
25
}
 
26
 
 
27
static Agraph_t *localsubg(Agraph_t *g, unsigned long id)
 
28
{
 
29
        Agraph_t        *subg;
 
30
 
 
31
        subg = agfindsubg_by_id(g,id);
 
32
        if (subg) return subg;
 
33
 
 
34
        subg = agalloc(g,sizeof(Agraph_t));
 
35
        subg->clos = g->clos;
 
36
        subg->desc = g->desc;
 
37
        subg->desc.maingraph = FALSE;
 
38
        subg->desc.flatlock = FALSE;
 
39
        subg->parent = g;
 
40
        subg->root = g->root;
 
41
        AGID(subg) = id;
 
42
        return agopen1(subg);
 
43
}
 
44
 
 
45
Agraph_t *agidsubg(Agraph_t *g, unsigned long id, int cflag)
 
46
{
 
47
        Agraph_t        *subg;
 
48
        subg = agfindsubg_by_id(g,id);
 
49
        if ((subg == NILgraph) && cflag && agallocid(g,AGRAPH,id))
 
50
                subg = localsubg(g, id);
 
51
        return subg;
 
52
}
 
53
 
 
54
Agraph_t *agsubg(Agraph_t *g, char *name, int cflag)
 
55
{
 
56
        unsigned long           id;
 
57
        Agraph_t        *subg;
 
58
 
 
59
        if (name && agmapnametoid(g, AGRAPH, name, &id, FALSE)) {
 
60
                /* might already exist */
 
61
                if ((subg = agfindsubg_by_id(g,id))) return subg;
 
62
        }
 
63
 
 
64
        if (cflag && agmapnametoid(g, AGRAPH, name, &id, TRUE)) /* reserve id */
 
65
                return localsubg(g, id);
 
66
 
 
67
        return NILgraph;
 
68
}
 
69
 
 
70
Agraph_t *agfstsubg(Agraph_t *g)
 
71
{
 
72
        return (Agraph_t*) dtfirst(g->g_dict);
 
73
}
 
74
 
 
75
Agraph_t *agnxtsubg(Agraph_t *subg)
 
76
{
 
77
        Agraph_t        *g;
 
78
 
 
79
        g = agparent(subg);
 
80
        return (Agraph_t*) dtnext(g->g_dict,subg);
 
81
}
 
82
 
 
83
Agraph_t *agparent(Agraph_t *g)
 
84
{
 
85
        return g->parent;
 
86
}
 
87
 
 
88
Agraph_t *agroot(Agraph_t *g)
 
89
{
 
90
        return g->root;
 
91
}
 
92
 
 
93
/* this function is only responsible for deleting the entry
 
94
 * in the parent's subg dict.  the rest is done in agclose().
 
95
 */
 
96
long agdelsubg(Agraph_t* g, Agraph_t *subg)
 
97
{
 
98
        return (long)dtdelete(g->g_dict,subg);
 
99
}