~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to cmd/dot/dot.c

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: dot.c,v 1.29 2007/07/17 21:45:10 erg Exp $ $Revision: 1.29 $ */
 
1
/* $Id: dot.c,v 1.51 2010/01/07 14:58:48 arif Exp $ $Revision: 1.51 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
22
22
#include "config.h"
23
23
#endif
24
24
 
25
 
#include "builddate.h"
26
25
#include "gvc.h"
 
26
#include "gvio.h"
 
27
 
 
28
#ifndef WIN32_DLL
27
29
#ifdef GVDLL
28
30
__declspec(dllimport) boolean MemTest;
29
31
#else
30
32
#include "globals.h"
31
33
#endif
32
 
 
 
34
#endif
 
35
 
 
36
#ifdef WIN32_DLL
 
37
__declspec(dllimport) boolean MemTest;
 
38
#endif
 
39
 
 
40
#include <stdlib.h>
33
41
#include <time.h>
34
42
#ifdef HAVE_UNISTD_H
35
43
#include <unistd.h>
48
56
# include <sys/fpu.h>
49
57
#endif
50
58
 
51
 
char *Info[] = {
52
 
    "Graphviz",                 /* Program */
53
 
    VERSION,                    /* Version */
54
 
    BUILDDATE                   /* Build Date */
55
 
};
56
 
 
57
59
static GVC_t *Gvc;
58
60
static graph_t * G;
59
61
 
60
62
#ifndef WIN32
61
63
static void intr(int s)
62
64
{
 
65
/* if interrupted we try to produce a partial rendering before exiting */
63
66
    if (G)
64
67
        gvRenderJobs(Gvc, G);
 
68
/* Note that we don't call gvFinalize() so that we don't start event-driven
 
69
 * devices like -Tgtk or -Txlib */
65
70
    exit (gvFreeContext(Gvc));
66
71
}
67
72
 
126
131
    char name[10];
127
132
 
128
133
    /* Create a new graph */
 
134
#ifndef WITH_CGRAPH
 
135
    aginit();
 
136
    agsetiodisc(NULL, gvfwrite, gvferror);
129
137
    g = agopen("new_graph", AGDIGRAPH);
 
138
#else /* WITH_CGRAPH */
 
139
    g = agopen("new_graph", Agdirected,NIL(Agdisc_t *));
 
140
#endif /* WITH_CGRAPH */
130
141
 
131
142
    /* Add nodes */
132
143
    for (j = 0; j < NUMNODES; j++) {
133
144
        sprintf(name, "%d", j);
 
145
#ifndef WITH_CGRAPH
134
146
        node[j] = agnode(g, name);
 
147
#else /* WITH_CGRAPH */
 
148
        node[j] = agnode(g, name, 1);
 
149
        agbindrec(node[j], "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data
 
150
 
 
151
#endif /* WITH_CGRAPH */
135
152
    }
136
153
 
137
154
    /* Connect nodes */
138
155
    for (j = 0; j < NUMNODES; j++) {
139
156
        for (k = j + 1; k < NUMNODES; k++) {
 
157
#ifndef WITH_CGRAPH
140
158
            agedge(g, node[j], node[k]);
 
159
#else /* WITH_CGRAPH */
 
160
            agedge(g, node[j], node[k], NULL, 1);
 
161
#endif /* WITH_CGRAPH */
141
162
        }
142
163
    }
143
164
    return g;
146
167
int main(int argc, char **argv)
147
168
{
148
169
    graph_t *prev = NULL;
149
 
 
150
 
    Gvc = gvNEWcontext(Info, gvUsername());
 
170
#ifndef WITH_CGRAPH
 
171
 
 
172
#endif /* WITH_CGRAPH */
 
173
 
 
174
    Gvc = gvContextPlugins(lt_preloaded_symbols, DEMAND_LOADING);
151
175
    gvParseArgs(Gvc, argc, argv);
152
 
 
153
176
#ifndef WIN32
154
177
    signal(SIGUSR1, gvToggle);
155
178
    signal(SIGINT, intr);
167
190
            /* Perform layout and cleanup */
168
191
            gvLayoutJobs(Gvc, G);  /* take layout engine from command line */
169
192
            gvFreeLayout(Gvc, G);
170
 
 
171
 
            /* Delete graph */
172
 
            agclose(G);
 
193
            agclose (G);
173
194
        }
174
 
    } else {
 
195
    }
 
196
    else if ((G = gvPluginsGraph(Gvc))) {
 
197
            gvLayoutJobs(Gvc, G);  /* take layout engine from command line */
 
198
            gvRenderJobs(Gvc, G);
 
199
    }
 
200
    else {
175
201
        while ((G = gvNextInputGraph(Gvc))) {
 
202
#ifdef WITH_CGRAPH
 
203
 
 
204
 
 
205
#endif /* WITH_CGRAPH */
176
206
            if (prev) {
177
207
                gvFreeLayout(Gvc, prev);
178
208
                agclose(prev);
182
212
            prev = G;
183
213
        }
184
214
    }
 
215
    gvFinalize(Gvc);
185
216
    return (gvFreeContext(Gvc));
186
217
}