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

« back to all changes in this revision

Viewing changes to cdt/dtdisc.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 discipline.
 
17
**      dt :    dictionary
 
18
**      disc :  discipline
 
19
**
 
20
**      Written by Kiem-Phong Vo (5/26/96)
 
21
*/
 
22
 
 
23
#if __STD_C
 
24
static Void_t* dtmemory(Dt_t* dt,Void_t* addr,size_t size,Dtdisc_t* disc)
 
25
#else
 
26
static Void_t* dtmemory(dt, addr, size, disc)
 
27
Dt_t*           dt;     /* dictionary                   */
 
28
Void_t*         addr;   /* address to be manipulate     */
 
29
size_t          size;   /* size to obtain               */
 
30
Dtdisc_t*       disc;   /* discipline                   */
 
31
#endif
 
32
{
 
33
        if(addr)
 
34
        {       if(size == 0)
 
35
                {       free(addr);
 
36
                        return NIL(Void_t*);
 
37
                }
 
38
                else    return realloc(addr,size);
 
39
        }
 
40
        else    return size > 0 ? malloc(size) : NIL(Void_t*);
 
41
}
 
42
 
 
43
#if __STD_C
 
44
Dtdisc_t* dtdisc(Dt_t* dt, Dtdisc_t* disc, int type)
 
45
#else
 
46
Dtdisc_t* dtdisc(dt,disc,type)
 
47
Dt_t*           dt;
 
48
Dtdisc_t*       disc;
 
49
int             type;
 
50
#endif
 
51
{
 
52
        reg Dtsearch_f  searchf;
 
53
        reg Dtlink_t    *r, *t;
 
54
        reg char*       k;
 
55
        reg Dtdisc_t*   old;
 
56
 
 
57
        if(!(old = dt->disc) )  /* initialization call from dtopen() */
 
58
        {       dt->disc = disc;
 
59
                if(!(dt->memoryf = disc->memoryf) )
 
60
                        dt->memoryf = dtmemory;
 
61
                return disc;
 
62
        }
 
63
 
 
64
        if(!disc)       /* only want to know current discipline */
 
65
                return old;
 
66
 
 
67
        searchf = dt->meth->searchf;
 
68
 
 
69
        UNFLATTEN(dt);
 
70
 
 
71
        if(old->eventf && (*old->eventf)(dt,DT_DISC,(Void_t*)disc,old) < 0)
 
72
                return NIL(Dtdisc_t*);
 
73
 
 
74
        dt->disc = disc;
 
75
        if(!(dt->memoryf = disc->memoryf) )
 
76
                dt->memoryf = dtmemory;
 
77
 
 
78
        if(dt->data->type&(DT_STACK|DT_QUEUE|DT_LIST))
 
79
                goto done;
 
80
        else if(dt->data->type&DT_BAG)
 
81
        {       if(type&DT_SAMEHASH)
 
82
                        goto done;
 
83
                else    goto dt_renew;
 
84
        }
 
85
        else if(dt->data->type&(DT_SET|DT_BAG))
 
86
        {       if((type&DT_SAMEHASH) && (type&DT_SAMECMP))
 
87
                        goto done;
 
88
                else    goto dt_renew;
 
89
        }
 
90
        else /*if(dt->data->type&(DT_OSET|DT_OBAG))*/
 
91
        {       if(type&DT_SAMECMP)
 
92
                        goto done;
 
93
        dt_renew:
 
94
                r = dtflatten(dt);
 
95
                dt->data->type &= ~DT_FLATTEN;
 
96
                dt->data->here = NIL(Dtlink_t*);
 
97
                dt->data->size = 0;
 
98
 
 
99
                if(dt->data->type&(DT_SET|DT_BAG))
 
100
                {       reg Dtlink_t    **s, **ends;
 
101
                        ends = (s = dt->data->htab) + dt->data->ntab;
 
102
                        while(s < ends)
 
103
                                *s++ = NIL(Dtlink_t*);
 
104
                }
 
105
 
 
106
                /* reinsert them */
 
107
                while(r)
 
108
                {       t = r->right;
 
109
                        if(!(type&DT_SAMEHASH)) /* new hash value */
 
110
                        {       k = (char*)OBJ(r,disc->link);
 
111
                                k = KEY((Void_t*)k,disc->key,disc->size);
 
112
                                r->hash = HASH(dt,k,disc,disc->size);
 
113
                        }
 
114
                        (void)(*searchf)(dt,(Void_t*)r,DT_RENEW);
 
115
                        r = t;
 
116
                }
 
117
        }
 
118
 
 
119
done:
 
120
        return old;
 
121
}