From 14394010364572f68331732d6921086c2bf94476 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 May 2014 07:34:51 +0800 Subject: [PATCH] Add gvc.c --- configure | 18 +++++++++--------- src/Makefile.am | 2 +- src/Makefile.in | 5 +++-- src/gvc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 src/gvc.c diff --git a/configure b/configure index f710333..0972494 100755 --- a/configure +++ b/configure @@ -13131,12 +13131,12 @@ if test -n "$DEPS_CFLAGS"; then pkg_cv_DEPS_CFLAGS="$DEPS_CFLAGS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpcre check\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libpcre check") 2>&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpcre check gvc\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libpcre check gvc") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - pkg_cv_DEPS_CFLAGS=`$PKG_CONFIG --cflags "libpcre check" 2>/dev/null` + pkg_cv_DEPS_CFLAGS=`$PKG_CONFIG --cflags "libpcre check gvc" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes @@ -13148,12 +13148,12 @@ if test -n "$DEPS_LIBS"; then pkg_cv_DEPS_LIBS="$DEPS_LIBS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ - { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpcre check\""; } >&5 - ($PKG_CONFIG --exists --print-errors "libpcre check") 2>&5 + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpcre check gvc\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libpcre check gvc") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - pkg_cv_DEPS_LIBS=`$PKG_CONFIG --libs "libpcre check" 2>/dev/null` + pkg_cv_DEPS_LIBS=`$PKG_CONFIG --libs "libpcre check gvc" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes @@ -13174,14 +13174,14 @@ else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then - DEPS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libpcre check" 2>&1` + DEPS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libpcre check gvc" 2>&1` else - DEPS_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libpcre check" 2>&1` + DEPS_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libpcre check gvc" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$DEPS_PKG_ERRORS" >&5 - as_fn_error $? "Package requirements (libpcre check) were not met: + as_fn_error $? "Package requirements (libpcre check gvc) were not met: $DEPS_PKG_ERRORS diff --git a/src/Makefile.am b/src/Makefile.am index 230a1c4..e6711bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ lib_LTLIBRARIES=libr3.la -libr3_la_SOURCES=node.c edge.c list.c str.c token.c +libr3_la_SOURCES=node.c edge.c list.c str.c token.c gvc.c libr3_la_LIBADD=$(DEPS_LIBS) AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include # AM_CFLAGS=$(DEPS_CFLAGS) diff --git a/src/Makefile.in b/src/Makefile.in index d1281ce..8f9af8f 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -123,7 +123,7 @@ am__installdirs = "$(DESTDIR)$(libdir)" LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = libr3_la_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_libr3_la_OBJECTS = node.lo edge.lo list.lo str.lo token.lo +am_libr3_la_OBJECTS = node.lo edge.lo list.lo str.lo token.lo gvz.lo libr3_la_OBJECTS = $(am_libr3_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -312,7 +312,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ lib_LTLIBRARIES = libr3.la -libr3_la_SOURCES = node.c edge.c list.c str.c token.c +libr3_la_SOURCES = node.c edge.c list.c str.c token.c gvz.c libr3_la_LIBADD = $(DEPS_LIBS) AM_CFLAGS = $(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include all: all-am @@ -395,6 +395,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/edge.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gvz.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/node.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str.Plo@am__quote@ diff --git a/src/gvc.c b/src/gvc.c new file mode 100644 index 0000000..cd47844 --- /dev/null +++ b/src/gvc.c @@ -0,0 +1,44 @@ +/* + * gvz.c + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ + +#include +#include +#include +#include "r3.h" + +// int main(int argc, char **argv) +int r3_tree_render_file(node * tree, char * format, char * filename) +{ + Agraph_t *g; + Agnode_t *n, *m; + Agedge_t *e; + + /* set up a graphviz context - but only once even for multiple graphs */ + static GVC_t *gvc; + + if (!gvc) { + gvc = gvContext(); + } + + /* Create a simple digraph */ + g = agopen("g", Agdirected, 0); + + n = agnode(g, "n", 1); + m = agnode(g, "m", 1); + e = agedge(g, n, m, 0, 1); + + /* Set an attribute - in this case one that affects the visible rendering */ + agsafeset(n, "color", "red", ""); + /* Use the directed graph layout engine */ + gvLayout(gvc, g, "dot"); + gvRenderFilename(gvc, g, format, filename); + gvFreeLayout(gvc, g); + + agclose(g); + return 0; +} +