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

« back to all changes in this revision

Viewing changes to agraph/obj.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
int agobjidcmpf(Dict_t *dict, void *arg0, void *arg1, Dtdisc_t *disc)
 
19
{
 
20
        Agobj_t *obj0, *obj1;
 
21
 
 
22
        NOTUSED(dict);
 
23
        obj0 = arg0; obj1 = arg1;
 
24
        NOTUSED(disc);
 
25
        return AGID(obj0) - AGID(obj1);
 
26
}
 
27
 
 
28
int agobjseqcmpf(Dict_t *dict, void *arg0, void *arg1, Dtdisc_t *disc)
 
29
{
 
30
        Agobj_t *obj0, *obj1;
 
31
 
 
32
        NOTUSED(dict);
 
33
        obj0 = arg0; obj1 = arg1;
 
34
        NOTUSED(disc);
 
35
        return AGSEQ(obj0) - AGSEQ(obj1);
 
36
}
 
37
 
 
38
int agdelete(Agraph_t *g, void *obj)
 
39
{
 
40
        Agraph_t        *h;
 
41
 
 
42
        h = agraphof(obj);
 
43
        if ((g != h) && ((AGTYPE((Agobj_t*)obj) != AGRAPH) || (g != agparent(h))))
 
44
                agerror(AGERROR_WRONGGRAPH,"agdelete");
 
45
 
 
46
        switch (AGTYPE((Agobj_t*)obj)) {
 
47
                case AGNODE: return agdelnode(obj);
 
48
                case AGINEDGE: case AGOUTEDGE: return agdeledge(obj);
 
49
                case AGRAPH:  return agclose(obj);
 
50
                default:  abort();
 
51
        }
 
52
        return SUCCESS; /* not reached */
 
53
}
 
54
 
 
55
#ifdef NOTDEF
 
56
int agrename(void *obj, char *newname)
 
57
{
 
58
        Agraph_t        *g;
 
59
        unsigned long           old_id, new_id;
 
60
 
 
61
        g = agraphof(obj);
 
62
        g->disc->id.convert(g, g->disc->id_state, AGTAG(obj), newname);
 
63
        if (g->disc->id.alloc(g, g->disc->id_state, AGTAG(obj), new_id)) {
 
64
        }
 
65
        switch (AGTYPE((Agobj_t *)obj)) {
 
66
        case AGRAPH: agstrfree(g,g->name); g->name = agstrdup(g,newname); break;
 
67
        case AGNODE: agrename_node((Agnode_t*)obj,newname); break;
 
68
        case AGINEDGE: case AGEDGEOUT: agerror(AGERROR_UNIMPL,"edge renaming");
 
69
        }
 
70
        return SUCCESS;
 
71
}
 
72
#endif
 
73
 
 
74
/* perform initialization/update/finalization method invocation.
 
75
 * skip over nil pointers to next method below.
 
76
 */
 
77
 
 
78
void agmethod_init(Agraph_t *g, void *obj)
 
79
{
 
80
        if (g->clos->callbacks_enabled)
 
81
                aginitcb(obj,g->clos->cb);
 
82
        else agrecord_callback(obj, CB_INITIALIZE, NILsym);
 
83
}
 
84
 
 
85
void aginitcb(void *obj, Agcbstack_t *cbstack)
 
86
{
 
87
        agobjfn_t               fn;
 
88
 
 
89
        if (cbstack == NIL(Agcbstack_t*)) return;
 
90
        aginitcb(obj,cbstack->prev);
 
91
        fn = NIL(agobjfn_t);
 
92
        switch (AGTYPE(obj)) {
 
93
        case AGRAPH:
 
94
                fn =  cbstack->f->graph.ins;
 
95
                break;
 
96
        case AGNODE:
 
97
                fn = cbstack->f->node.ins;
 
98
                break;
 
99
        case AGEDGE:
 
100
                fn = cbstack->f->edge.ins;
 
101
                break;
 
102
        }
 
103
        if (fn) fn(obj,cbstack->state);
 
104
}
 
105
 
 
106
void agmethod_upd(Agraph_t *g, void *obj, Agsym_t *sym)
 
107
{
 
108
        if (g->clos->callbacks_enabled)
 
109
                agupdcb(obj,sym,g->clos->cb);
 
110
        else agrecord_callback(obj, CB_UPDATE, sym);
 
111
}
 
112
 
 
113
void agupdcb(void *obj, Agsym_t *sym, Agcbstack_t *cbstack)
 
114
{
 
115
        agobjupdfn_t            fn;
 
116
 
 
117
        if (cbstack == NIL(Agcbstack_t*)) return;
 
118
        agupdcb(obj,sym,cbstack->prev);
 
119
        fn = NIL(agobjupdfn_t);
 
120
        switch (AGTYPE(obj)) {
 
121
        case AGRAPH:
 
122
                fn = cbstack->f->graph.mod;
 
123
                break;
 
124
        case AGNODE:
 
125
                fn = cbstack->f->node.mod;
 
126
                break;
 
127
        case AGEDGE:
 
128
                fn = cbstack->f->edge.mod;
 
129
                break;
 
130
        }
 
131
        if (fn) fn(obj,cbstack->state,sym);
 
132
}
 
133
 
 
134
void agmethod_delete(Agraph_t *g, void *obj)
 
135
{
 
136
        if (g->clos->callbacks_enabled)
 
137
                agdelcb(obj,g->clos->cb);
 
138
        else agrecord_callback(obj, CB_DELETION, NILsym);
 
139
}
 
140
 
 
141
void agdelcb(void *obj, Agcbstack_t *cbstack)
 
142
{
 
143
        agobjfn_t               fn;
 
144
 
 
145
        if (cbstack == NIL(Agcbstack_t*)) return;
 
146
        agdelcb(obj,cbstack->prev);
 
147
        fn = NIL(agobjfn_t);
 
148
        switch (AGTYPE(obj)) {
 
149
        case AGRAPH:
 
150
                fn = cbstack->f->graph.del;
 
151
                break;
 
152
        case AGNODE:
 
153
                fn = cbstack->f->node.del;
 
154
                break;
 
155
        case AGEDGE:
 
156
                fn = cbstack->f->edge.del;
 
157
                break;
 
158
        }
 
159
        if (fn) fn(obj,cbstack->state);
 
160
}
 
161
 
 
162
Agraph_t        *agraphof(void *obj)
 
163
{
 
164
        switch (AGTYPE(obj)) {
 
165
                case AGINEDGE: case AGOUTEDGE:
 
166
                        return ((Agedge_t*)obj)->node->g;
 
167
                case AGNODE:
 
168
                        return ((Agnode_t*)obj)->g;
 
169
                case AGRAPH:
 
170
                        return (Agraph_t*)obj;
 
171
                default:                /* actually can't occur if only 2 bit tags */
 
172
                        agerror(AGERROR_BADOBJ,"agraphof");
 
173
                        return NILgraph;
 
174
        }
 
175
}
 
176
 
 
177
int             agisarootobj(void *obj)
 
178
{
 
179
        return (agraphof(obj)->desc.maingraph);
 
180
}
 
181
 
 
182
/* to manage disciplines */
 
183
 
 
184
void agpushdisc(Agraph_t *g, Agcbdisc_t *cbd, void *state)
 
185
{
 
186
        Agcbstack_t     *stack_ent;
 
187
 
 
188
        stack_ent = AGNEW(g,Agcbstack_t);
 
189
        stack_ent->f = cbd;
 
190
        stack_ent->state = state;
 
191
        stack_ent->prev = g->clos->cb;
 
192
        g->clos->cb = stack_ent;
 
193
}
 
194
 
 
195
int agpopdisc(Agraph_t *g, Agcbdisc_t *cbd)
 
196
{
 
197
        Agcbstack_t     *stack_ent;
 
198
 
 
199
        stack_ent = g->clos->cb;
 
200
        if (stack_ent) {
 
201
                if (stack_ent->f == cbd) g->clos->cb = stack_ent->prev;
 
202
                else {
 
203
                        while (stack_ent && (stack_ent->prev->f != cbd))
 
204
                                stack_ent = stack_ent->prev;
 
205
                        if (stack_ent && stack_ent->prev)
 
206
                                stack_ent->prev = stack_ent->prev->prev;
 
207
                }
 
208
                if (stack_ent) {agfree(g,stack_ent); return SUCCESS;}
 
209
        }
 
210
        return FAILURE;
 
211
}
 
212
 
 
213
void *aggetuserptr(Agraph_t *g, Agcbdisc_t *cbd)
 
214
{
 
215
        Agcbstack_t     *stack_ent;
 
216
 
 
217
        for (stack_ent = g->clos->cb; stack_ent; stack_ent = stack_ent->prev)
 
218
                if (stack_ent->f == cbd) return stack_ent->state;
 
219
        return NIL(void*);
 
220
}
 
221
 
 
222
Dtdisc_t Ag_obj_id_disc = {
 
223
        0,              /* pass object ptr      */
 
224
        0,              /* size (ignored)       */
 
225
        offsetof(Agobj_t,id_link),      /* link offset */
 
226
        NIL(Dtmake_f),
 
227
        NIL(Dtfree_f),
 
228
        agobjidcmpf,
 
229
        NIL(Dthash_f),
 
230
        agdictobjmem,
 
231
        NIL(Dtevent_f)
 
232
};
 
233
 
 
234
Dtdisc_t Ag_obj_seq_disc = {
 
235
        0,              /* pass object ptr      */
 
236
        0,              /* size (ignored)       */
 
237
        offsetof(Agobj_t,seq_link),     /* link offset */
 
238
        NIL(Dtmake_f),
 
239
        NIL(Dtfree_f),
 
240
        agobjseqcmpf,
 
241
        NIL(Dthash_f),
 
242
        agdictobjmem,
 
243
        NIL(Dtevent_f)
 
244
};