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

« back to all changes in this revision

Viewing changes to tcldgl/dgl.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
 * Tcl extension for Dynamic Graphs by John Ellson (ellson@lucent.com)
 
3
 * 
 
4
 * Builds on libincr + libgraph by Stephen North (north@research.att.com)
 
5
 */
 
6
 
 
7
#include "dgl.h"
 
8
 
 
9
#ifdef DMALLOC
 
10
#include "dmalloc.h"
 
11
#endif
 
12
 
 
13
/* FIXME globally accessable structure.  not thread safe */
 
14
/* should be malloc'ed in Init and reference through ClientData */
 
15
dglInterp_t dglInterp;
 
16
 
 
17
/* available engines from dynagraph */
 
18
extern ILengine_t OrthoGrid;
 
19
extern ILengine_t DynaDag;
 
20
extern ILengine_t GeoGraph;  
 
21
extern ILengine_t FDPGraph;  
 
22
    
 
23
static int 
 
24
dglayoutprops(dgLayout_t *v, int argc, char **argv)
 
25
{
 
26
/*
 
27
  processes any combination of the following configuration switches:
 
28
        -engine                 (enum:dynadag,geograph,orthogrid) (default geograph)
 
29
        -orientation    (int)   (default 2)
 
30
        -resolution             (float) (default 1)
 
31
        -xseparation    (float) (default 10)
 
32
        -yseparation    (float) (default 40)
 
33
        -ticks                  (float) (default 1)
 
34
*/
 
35
 
 
36
        int                     res=TCL_OK, i=0, length;
 
37
        double          dtemp;
 
38
        char            c;
 
39
        Tcl_Interp      *interp;
 
40
 
 
41
        interp = v->dglInterp->interp;
 
42
 
 
43
        if (argc % 2) {
 
44
                Tcl_AppendResult(interp, 
 
45
                        "invalid number of args, must be even",
 
46
                        (char *) NULL);
 
47
                return TCL_ERROR;
 
48
        }
 
49
        while (i < argc) {
 
50
                if (argv[i][0] != '-') {
 
51
                        Tcl_AppendResult(interp, 
 
52
                                "invalid switch: \"", argv[i], (char *) NULL);
 
53
                        return TCL_ERROR;
 
54
                }
 
55
                length = strlen(argv[i]);
 
56
                if (strncmp(argv[i], "-engine", length) == 0) {
 
57
                        ++i;
 
58
                        res = TCL_OK;
 
59
                        length = strlen(argv[i]);
 
60
                        c = argv[i][0];
 
61
                        if (c == 'd' && strncasecmp(argv[i], "dynadag", length) == 0)
 
62
                                v->engine = &DynaDag;
 
63
                        else if (c == 'f' && strncasecmp(argv[i], "fdpgraph", length) == 0)
 
64
                                v->engine = &FDPGraph;
 
65
                        else if (c == 'g' && strncasecmp(argv[i], "geograph", length) == 0)
 
66
                                v->engine = &GeoGraph;
 
67
                        else if (c == 'o' && strncasecmp(argv[i], "orthogrid", length) == 0)
 
68
                                v->engine = &OrthoGrid;
 
69
                        else
 
70
                                res = TCL_ERROR;
 
71
                }
 
72
                else if (strncmp(argv[i], "-orientation", length) == 0)
 
73
                        res = Tcl_GetInt(interp, argv[++i], &v->orientation);
 
74
                else if (strncmp(argv[i], "-resolution", length) == 0) {
 
75
                        res = Tcl_GetDouble(interp, argv[++i], &dtemp);
 
76
                        if (res == TCL_OK) 
 
77
                                ((ILview_t *)v)->resolution = (float)dtemp;
 
78
                }
 
79
                else if (strncmp(argv[i], "-xseparation", length) == 0)
 
80
                        res = Tcl_GetDouble(interp, argv[++i], 
 
81
                                &((ILview_t *)v)->separation.x);
 
82
                else if (strncmp(argv[i], "-yseparation", length) == 0)
 
83
                        res = Tcl_GetDouble(interp, argv[++i], 
 
84
                                &((ILview_t *)v)->separation.y);
 
85
                else if (strncmp(argv[i], "-ticks", length) == 0) {
 
86
                        res = Tcl_GetDouble(interp, argv[++i], &dtemp);
 
87
                        if (res == TCL_OK) 
 
88
                                ((ILview_t *)v)->ticks = (float)dtemp;
 
89
                }
 
90
                else {
 
91
                        Tcl_AppendResult(interp, 
 
92
                                "unknown switch: \"", argv[i], (char *) NULL);
 
93
                        return TCL_ERROR;
 
94
                }
 
95
                if (res != TCL_OK) {
 
96
                        Tcl_AppendResult(interp, "invalid switch value: \"",
 
97
                                argv[i-1], " ", argv[i], (char *) NULL);
 
98
                        return TCL_ERROR;
 
99
                }
 
100
                i++;
 
101
        } 
 
102
        return TCL_OK;
 
103
}
 
104
 
 
105
static int 
 
106
dglayout(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
 
107
{
 
108
        dglInterp_t *dg = (dglInterp_t *)clientData;
 
109
        dgLayout_t         *v, **tv;
 
110
        char                    vbuf[16];
 
111
        unsigned long           id;
 
112
 
 
113
        tv = (dgLayout_t **) tclhandleAlloc(dg->layoutTable, (char *)NULL, &id);
 
114
        *tv = v = (dgLayout_t *) Tcl_Alloc(sizeof(dgLayout_t));
 
115
        v->id = id;
 
116
        layout_to_handle(v, vbuf);
 
117
        v->dglInterp = dg;
 
118
 
 
119
        Tcl_InitHashTable(&(v->edgetable), TCL_STRING_KEYS);
 
120
        Tcl_InitHashTable(&(v->nodetable), TCL_STRING_KEYS);
 
121
 
 
122
        ((ILview_t *)v)->base.tag = ILVIEW;
 
123
        ((ILview_t *)v)->ins = (ILevf_t)insert_obj;
 
124
        ((ILview_t *)v)->mod = (ILevf_t)modify_obj;
 
125
        ((ILview_t *)v)->del = (ILevf_t)delete_obj;
 
126
 
 
127
        v->batch_cmd = (char *) NULL;
 
128
        v->insert_node_cmd = (char *) NULL;
 
129
        v->insert_edge_cmd = (char *) NULL;
 
130
        v->modify_node_cmd = (char *) NULL;
 
131
        v->modify_edge_cmd = (char *) NULL;
 
132
        v->delete_node_cmd = (char *) NULL;
 
133
        v->delete_edge_cmd = (char *) NULL;
 
134
 
 
135
        /* callbacks are controlled by the "batch" command */
 
136
        /* default is "batch 0"  i.e. callbacks enabled */
 
137
        ((ILview_t *)v)->enable_immediate_callbacks = 1;
 
138
 
 
139
        /* TODO the following should be configure options with cget support */
 
140
        ((ILview_t *)v)->resolution = 1;
 
141
        ((ILview_t *)v)->separation.x = 10;
 
142
        ((ILview_t *)v)->separation.y = 40;
 
143
        ((ILview_t *)v)->ticks = 1;
 
144
        ((ILview_t *)v)->max_bb.x = 50;
 
145
        ((ILview_t *)v)->max_bb.y = 50;
 
146
        v->orientation = 0;
 
147
        v->engine = &GeoGraph;
 
148
 
 
149
        if (dglayoutprops(v, argc-1, &argv[1]) != TCL_OK) {
 
150
                tclhandleFreeIndex(dg->layoutTable, id);
 
151
                return TCL_ERROR;
 
152
        }
 
153
 
 
154
        /* create node and edge defaults */
 
155
        v->defaultedge = (ILedge_t *)Tcl_Alloc(sizeof(ILedge_t));
 
156
        assert (v->defaultedge);
 
157
        initedgespec(v->defaultedge);
 
158
        setedgeshape(v->defaultedge, IL_SPLINE);
 
159
 
 
160
        v->defaultnode = (ILnode_t *)Tcl_Alloc(sizeof(ILnode_t));
 
161
        assert (v->defaultnode);
 
162
        initnodespec(v->defaultnode);
 
163
        setnodeshape(v->defaultnode, IL_ELLIPSE);
 
164
 
 
165
        ilopen(v->engine, (ILview_t *)v);
 
166
 
 
167
        Tcl_CreateCommand(interp, vbuf, layoutcmd, clientData,
 
168
                (Tcl_CmdDeleteProc *) NULL);
 
169
        Tcl_AppendResult(interp, vbuf, (char *) NULL);
 
170
 
 
171
        return TCL_OK;
 
172
}
 
173
 
 
174
int 
 
175
Tcldgl_Init(Tcl_Interp * interp)
 
176
{
 
177
#ifdef USE_TCL_STUBS
 
178
    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
 
179
        return TCL_ERROR;
 
180
    }
 
181
#else
 
182
    if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) {
 
183
        return TCL_ERROR;
 
184
    }
 
185
#endif
 
186
    if (Tcl_PkgRequire(interp, "Tcldgr", VERSION, 0) == NULL) {
 
187
        return TCL_ERROR;
 
188
    }
 
189
        if (Tcl_PkgProvide(interp, "Tcldgl", VERSION) != TCL_OK) {
 
190
                return TCL_ERROR;
 
191
        }
 
192
 
 
193
        dglInterp.interp = interp;
 
194
        dglInterp.layoutTable = tclhandleInit("dgL",sizeof(dgLayout_t), 10);
 
195
 
 
196
        Tcl_CreateCommand(interp, "dglayout", dglayout, &dglInterp,
 
197
                (Tcl_CmdDeleteProc *) NULL);
 
198
 
 
199
        return TCL_OK;
 
200
}
 
201
 
 
202
int 
 
203
Tcldgl_SafeInit(Tcl_Interp * interp)
 
204
{
 
205
        return Tcldgl_Init(interp);
 
206
}
 
207
 
 
208
void __eprintf(const char *a, const char *b, unsigned c, const char *d) {}