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

« back to all changes in this revision

Viewing changes to shape/shape.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
#include "shape.h"
 
2
 
 
3
#ifdef DMALLOC
 
4
#include "dmalloc.h"
 
5
#endif
 
6
 
 
7
static void *zmalloc(Vmalloc_t *arena, size_t request)
 
8
{
 
9
        void    *rv;
 
10
 
 
11
        rv = vmalloc(arena, request);
 
12
        if (rv) memset(rv, request, '\0');
 
13
        return rv;
 
14
}
 
15
 
 
16
ilcurve_t *il_newcurve(Vmalloc_t *arena, ilcurvetype_t kind, int maxpts) {
 
17
        ilcurve_t *rv;
 
18
 
 
19
        rv = zmalloc(arena,sizeof(ilcurve_t));
 
20
        rv->type = kind;
 
21
        rv->n = 0;
 
22
        rv->p = zmalloc(arena,sizeof(ilcoord_t)*maxpts);
 
23
        return rv;
 
24
}
 
25
 
 
26
/* note that the value of contents is copied and contents is freed */
 
27
ilshape_t *il_newshape(Vmalloc_t *arena, ilcurve_t *contents, ilshape_t *link) {
 
28
        ilshape_t *rv;
 
29
 
 
30
        rv = zmalloc(arena, sizeof(ilshape_t));
 
31
        if (contents) {
 
32
                if (contents->type == IL_POLYLINE)
 
33
                        rv->type = IL_POLYGON;
 
34
                else
 
35
                        rv->type = IL_SPLINEGON;
 
36
                rv->def.curve = *contents;
 
37
                        /* i designed the interface wrong.  either def.curve should
 
38
                        be a pointer, or the contents arg should be a value not a
 
39
                        pointer, but this is the easiest way to deal with the error
 
40
                        right now. */
 
41
                vmfree(vmregion(contents),contents);
 
42
        }
 
43
        else rv->type = IL_NOSHAPE;
 
44
        rv->next = link;
 
45
        return rv;
 
46
}
 
47
 
 
48
void il_freeshape(Vmalloc_t *arena, ilshape_t *shape)
 
49
{
 
50
        ilshape_t       *link;
 
51
 
 
52
 
 
53
        while (shape) {
 
54
                link = shape->next;
 
55
                switch(shape->type) {
 
56
                        case IL_POLYGON:
 
57
                        case IL_SPLINEGON:
 
58
                                if (shape->def.curve.p)
 
59
                                        vmfree(arena,shape->def.curve.p);
 
60
                                break;
 
61
                        default:
 
62
                                break;
 
63
                }
 
64
                vmfree(arena,shape);
 
65
                shape = link;
 
66
        }
 
67
}
 
68
 
 
69
void il_freecurve(Vmalloc_t *arena, ilcurve_t *curve)
 
70
{
 
71
        vmfree(arena,curve->p);
 
72
        vmfree(arena,curve);
 
73
}
 
74
 
 
75
ilshape_t *il_copyshape(Vmalloc_t *arena, ilshape_t *src)
 
76
{
 
77
        ilshape_t       *rv;
 
78
        size_t          sz;
 
79
 
 
80
        rv = zmalloc(arena,sizeof(ilshape_t));
 
81
        rv->type = src->type;
 
82
        switch (rv->type) {
 
83
                case IL_POLYGON:
 
84
                case IL_SPLINEGON:
 
85
                        rv->def.curve.type = src->def.curve.type;
 
86
                        rv->def.curve.n = src->def.curve.n;
 
87
                        sz = rv->def.curve.n * sizeof(ilcoord_t);
 
88
                        rv->def.curve.p = zmalloc(arena,sz);
 
89
                        memcpy(rv->def.curve.p,src->def.curve.p,sz);
 
90
                        break;
 
91
                case IL_ELLIPSE:
 
92
                case IL_CIRCLE:
 
93
                        rv->def.ellipse = src->def.ellipse;
 
94
                        break;
 
95
                default:
 
96
                        abort();
 
97
        }
 
98
        return rv;
 
99
}