Graphviz  2.41.20171026.1811
dot.c
Go to the documentation of this file.
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 
37 static GVC_t *Gvc;
38 static graph_t * G;
39 
40 #ifndef _WIN32
41 static 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
52 static 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 
61 static graph_t *create_test_graph(void)
62 {
63 #define NUMNODES 5
64 
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 
95 int 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 }
#define MAX(a, b)
Definition: agerror.c:17
CGRAPH_API Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition: node.c:142
CGRAPH_API Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
Definition: graph.c:44
int gvParseArgs(GVC_t *gvc, int argc, char **argv)
Definition: args.c:272
int agreseterrors()
Definition: agerror.c:172
unsigned char boolean
Definition: types.h:24
graph_t * gvPluginsGraph(GVC_t *gvc)
Definition: input.c:213
EXTERN int GvExitOnUsage
Definition: globals.h:85
int gvRenderJobs(GVC_t *gvc, graph_t *g)
Definition: emit.c:4094
int gvFreeLayout(GVC_t *gvc, graph_t *g)
Definition: gvlayout.c:102
void gvFinalize(GVC_t *gvc)
Definition: gvcontext.c:65
EXTERN int MemTest
Definition: globals.h:66
graph_t * gvNextInputGraph(GVC_t *gvc)
Definition: input.c:537
CGRAPH_API Agdesc_t Agdirected
Definition: cgraph.h:418
int gvLayoutJobs(GVC_t *gvc, graph_t *g)
Definition: gvlayout.c:55
CGRAPH_API Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
Definition: subg.c:52
#define NIL(t)
Definition: dthdr.h:13
lt_symlist_t lt_preloaded_symbols[]
Definition: dot_builtins.c:36
Definition: gvcint.h:70
CGRAPH_API int agclose(Agraph_t *g)
Definition: graph.c:93
void gvToggle(int s)
Definition: utils.c:610
GVC_t * gvContextPlugins(const lt_symlist_t *builtins, int demand_loading)
Definition: gvc.c:36
Definition: grammar.c:79
#define NULL
Definition: logic.h:39
Agnode_t * node(Agraph_t *g, char *name)
Definition: gv.cpp:103
CGRAPH_API Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition: edge.c:281
CGRAPH_API void * agbindrec(void *obj, char *name, unsigned int size, int move_to_front)
Definition: rec.c:86
int gvFreeContext(GVC_t *gvc)
Definition: gvcontext.c:72
#define NUMNODES
int main(int argc, char **argv)
Definition: dot.c:95
CGRAPH_API Agnode_t * agsubnode(Agraph_t *g, Agnode_t *n, int createflag)
Definition: node.c:254
#define TRUE
Definition: cgraph.h:38