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

« back to all changes in this revision

Viewing changes to cdt/dtmethod.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
#include        "dthdr.h"
 
11
 
 
12
#ifdef DMALLOC
 
13
#include "dmalloc.h"
 
14
#endif
 
15
 
 
16
/*      Change search method.
 
17
**
 
18
**      Written by Kiem-Phong Vo (05/25/96)
 
19
*/
 
20
 
 
21
#if __STD_C
 
22
Dtmethod_t* dtmethod(Dt_t* dt, Dtmethod_t* meth)
 
23
#else
 
24
Dtmethod_t* dtmethod(dt, meth)
 
25
Dt_t*           dt;
 
26
Dtmethod_t*     meth;
 
27
#endif
 
28
{
 
29
        reg Dtlink_t    *list, *r;
 
30
        reg Dtdisc_t*   disc = dt->disc;
 
31
        reg Dtmethod_t* oldmeth = dt->meth;
 
32
 
 
33
        if(!meth || meth->type == oldmeth->type)
 
34
                return oldmeth;
 
35
 
 
36
        if(disc->eventf &&
 
37
           (*disc->eventf)(dt,DT_METH,(Void_t*)meth,disc) < 0)
 
38
                return NIL(Dtmethod_t*);
 
39
 
 
40
        /* get the list of elements */
 
41
        list = dtflatten(dt);
 
42
 
 
43
        if(dt->data->type&(DT_LIST|DT_STACK|DT_QUEUE) )
 
44
                dt->data->head = NIL(Dtlink_t*);
 
45
        else if(dt->data->type&(DT_SET|DT_BAG) )
 
46
        {       if(dt->data->ntab > 0)
 
47
                        (*dt->memoryf)(dt,(Void_t*)dt->data->htab,0,disc);
 
48
                dt->data->ntab = 0;
 
49
                dt->data->htab = NIL(Dtlink_t**);
 
50
        }
 
51
 
 
52
        dt->data->here = NIL(Dtlink_t*);
 
53
        dt->data->type = (dt->data->type&~(DT_METHODS|DT_FLATTEN)) | meth->type;
 
54
        dt->meth = meth;
 
55
        if(dt->searchf == oldmeth->searchf)
 
56
                dt->searchf = meth->searchf;
 
57
 
 
58
        if(meth->type&(DT_LIST|DT_STACK|DT_QUEUE) )
 
59
        {       if(!(oldmeth->type&(DT_LIST|DT_STACK|DT_QUEUE)) )
 
60
                {       if((r = list) )
 
61
                        {       reg Dtlink_t*   t;
 
62
                                for(t = r->right; t; r = t, t = t->right )
 
63
                                        t->left = r;
 
64
                                list->left = r;
 
65
                        }
 
66
                }
 
67
                dt->data->head = list;
 
68
        }
 
69
        else if(meth->type&(DT_OSET|DT_OBAG))
 
70
        {       dt->data->size = 0;
 
71
                while(list)
 
72
                {       r = list->right;
 
73
                        (*meth->searchf)(dt,(Void_t*)list,DT_RENEW);
 
74
                        list = r;
 
75
                }
 
76
        }
 
77
        else if(!((meth->type&DT_BAG) && (oldmeth->type&DT_SET)) )
 
78
        {       int     rehash;
 
79
                if((meth->type&(DT_SET|DT_BAG)) && !(oldmeth->type&(DT_SET|DT_BAG)))
 
80
                        rehash = 1;
 
81
                else    rehash = 0;
 
82
 
 
83
                dt->data->size = dt->data->loop = 0;
 
84
                while(list)
 
85
                {       r = list->right;
 
86
                        if(rehash)
 
87
                        {       reg Void_t* key = OBJ(list,disc->link);
 
88
                                key = KEY(key,disc->key,disc->size);
 
89
                                list->hash = HASH(dt,key,disc,disc->size);
 
90
                        }
 
91
                        (void)(*meth->searchf)(dt,(Void_t*)list,DT_RENEW);
 
92
                        list = r;
 
93
                }
 
94
        }
 
95
 
 
96
        return oldmeth;
 
97
}