1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14/*
15 * Written by Stephen North and Eleftherios Koutsofios.
16 */
17
18#include "config.h"
19
20#include "gvc.h"
21#include "gvio.h"
22
23#ifdef WIN32_DLL
24__declspec(dllimport) boolean MemTest;
25__declspec(dllimport) int GvExitOnUsage;
26/*gvc.lib cgraph.lib*/
27#else /* not WIN32_DLL */
28#include "globals.h"
29#endif
30
31#include <stdlib.h>
32#include <time.h>
33#ifdef HAVE_UNISTD_H
34#include <unistd.h>
35#endif
36
37static GVC_t *Gvc;
38static graph_t * G;
39
40#ifndef _WIN32
41static void intr(int s)
42{
43/* if interrupted we try to produce a partial rendering before exiting */
44 if (G)
45 gvRenderJobs(Gvc, G);
46/* Note that we don't call gvFinalize() so that we don't start event-driven
47 * devices like -Tgtk or -Txlib */
48 exit (gvFreeContext(Gvc));
49}
50
51#ifndef NO_FPERR
52static void fperr(int s)
53{
54 fprintf(stderr, "caught SIGFPE %d\n", s);
55 /* signal (s, SIG_DFL); raise (s); */
56 exit(1);
57}
58#endif
59#endif
60
61static graph_t *create_test_graph(void)
62{
63#define NUMNODES 5
64
65 Agnode_t *node[NUMNODES];
66 Agedge_t *e;
67 Agraph_t *g;
68 Agraph_t *sg;
69 int j, k;
70 char name[10];
71
72 /* Create a new graph */
73 g = agopen("new_graph", Agdirected,NIL(Agdisc_t *));
74
75 /* Add nodes */
76 for (j = 0; j < NUMNODES; j++) {
77 sprintf(name, "%d", j);
78 node[j] = agnode(g, name, 1);
79 agbindrec(node[j], "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data
80 }
81
82 /* Connect nodes */
83 for (j = 0; j < NUMNODES; j++) {
84 for (k = j + 1; k < NUMNODES; k++) {
85 e = agedge(g, node[j], node[k], NULL, 1);
86 agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //edge custom data
87 }
88 }
89 sg = agsubg (g, "cluster1", 1);
90 agsubnode (sg, node[0], 1);
91
92 return g;
93}
94
95int main(int argc, char **argv)
96{
97 graph_t *prev = NULL;
98 int r, rc = 0;
99
100 Gvc = gvContextPlugins(lt_preloaded_symbols, DEMAND_LOADING);
101 GvExitOnUsage = 1;
102 gvParseArgs(Gvc, argc, argv);
103#ifndef _WIN32
104 signal(SIGUSR1, gvToggle);
105 signal(SIGINT, intr);
106#ifndef NO_FPERR
107 signal(SIGFPE, fperr);
108#endif
109#endif
110
111 if (MemTest) {
112 while (MemTest--) {
113 /* Create a test graph */
114 G = create_test_graph();
115
116 /* Perform layout and cleanup */
117 gvLayoutJobs(Gvc, G); /* take layout engine from command line */
118 gvFreeLayout(Gvc, G);
119 agclose (G);
120 }
121 }
122 else if ((G = gvPluginsGraph(Gvc))) {
123 gvLayoutJobs(Gvc, G); /* take layout engine from command line */
124 gvRenderJobs(Gvc, G);
125 }
126 else {
127 while ((G = gvNextInputGraph(Gvc))) {
128 if (prev) {
129 gvFreeLayout(Gvc, prev);
130 agclose(prev);
131 }
132 gvLayoutJobs(Gvc, G); /* take layout engine from command line */
133 gvRenderJobs(Gvc, G);
134 gvFinalize(Gvc);
135 r = agreseterrors();
136 rc = MAX(rc,r);
137 prev = G;
138 }
139 }
140 r = gvFreeContext(Gvc);
141 return (MAX(rc,r));
142}
143