2 * Copyright (c) 2000-2001
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static hash_table node_hash_table
;
38 static region dot_region
;
39 static int node_count
;
40 static const char *edge_op
;
42 static void print_n_attrs(node_attr
*attrs
, int n
)
47 for (i
= 0; i
< n
; i
++)
50 switch (attrs
[i
].name
)
92 fprintf(of
,"%s = %s",name
,attrs
[i
].value
);
98 static void print_e_attrs(edge_attr
*attrs
, int n
)
102 for (i
= 0; i
< n
; i
++)
105 switch(attrs
[i
].name
)
150 fprintf(of
,"%s = %s",name
,attrs
[i
].value
);
155 static void print_g_attrs(graph_attr
*attrs
, int n
)
160 for (i
= 0; i
< n
; i
++)
163 switch (attrs
[i
].name
)
169 name
= "clusterrank";
175 name
= "concentrate";
208 name
= "orientation";
235 fprintf(of
,"%s = %s",name
,attrs
[i
].value
);
241 void dot_start(FILE *to
,const char *name
,bool is_directed
,bool is_strict
)
243 const char *graph_type
,*strict
;
247 dot_region
= newregion();
248 node_hash_table
= make_string_hash_table(dot_region
,8,TRUE
);
254 graph_type
= "digraph";
259 graph_type
= "graph";
267 fprintf(of
,"%s %s %s{\n",strict
,graph_type
,name
);
271 void dot_global_graph_style(graph_attr
*attrs
, int n
)
274 print_g_attrs(attrs
,n
);
279 void dot_global_edge_style(edge_attr
*attrs
, int n
)
282 print_e_attrs(attrs
,n
);
287 void dot_global_node_style(node_attr
*attrs
, int n
)
290 print_n_attrs(attrs
,n
);
295 /* by default, set the node's name to label */
296 static void declare_node(dot_node n
, char *label
)
301 if (label
[0] == '\"')
304 mangled
[0] = label
[0];
306 for (i
= 1; label
[i
] && i
< 512 ;i
++)
308 if (label
[i
] == '\"')
310 else mangled
[i
] = label
[i
];
314 fprintf(of
,"nd_%d [label=\"%s\"]\n",n
,mangled
);
317 dot_node
dot_get_node(char *label
) deletes
320 if (!hash_table_lookup(node_hash_table
,(hash_key
)label
,(hash_data
*)(char *)&result
))
322 dot_node newnode
= node_count
++;
324 declare_node(newnode
,label
);
325 hash_table_insert(node_hash_table
,
326 (hash_key
)rstrdup(dot_region
,label
),
336 void dot_node_style(dot_node node
,node_attr
*attrs
, int n
)
338 fprintf(of
,"nd_%d ",node
);
339 print_n_attrs(attrs
,n
);
344 void dot_plain_edge(dot_node from
, dot_node to
)
346 fprintf(of
,"nd_%d %s nd_%d;\n",from
,edge_op
,to
);
349 void dot_styled_edge(dot_node from
, dot_node to
, edge_attr
*attrs
, int n
)
351 fprintf(of
,"nd_%d %s nd_%d ",from
,edge_op
,to
);
352 print_e_attrs(attrs
,n
);
357 void dot_end(void) deletes
360 hash_table_delete(node_hash_table
);
361 deleteregion_ptr(&dot_region
);