From a17336b57614030b5c3da922e60876b25d832e3c Mon Sep 17 00:00:00 2001 From: ellson Date: Tue, 19 Jul 2005 17:12:53 +0000 Subject: [PATCH] add gvLayout() gvRender() gvCleanup() wrappers and provide new simple.c demo --- cmd/dot/dotneato.c | 82 +++++++++++++++++++++++++++++++++++++++++++++- cmd/dot/dotneato.h | 3 ++ dot.demo/Makefile | 10 ++++-- dot.demo/simple.c | 42 ++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 dot.demo/simple.c diff --git a/cmd/dot/dotneato.c b/cmd/dot/dotneato.c index ea1c210fa..402de0ff4 100644 --- a/cmd/dot/dotneato.c +++ b/cmd/dot/dotneato.c @@ -24,5 +24,85 @@ char *Info[] = { GVC_t *gvContext(void) { - return gvNEWcontext(Info, ""); + GVC_t *gvc; + + aginit(); + agnodeattr(NULL, "label", NODENAME_ESC); + gvc = gvNEWcontext(Info, username()); + gvconfig(gvc); /* configure for available plugins and codegens */ + return gvc; +} + +int gvLayout(GVC_t *gvc, graph_t *g, char *engine) +{ + char buf[256]; + Agsym_t *a; + int rc; + + g = g->root; + if (GD_drawing(g)) { /* only cleanup once between layouts */ + gvlayout_cleanup(gvc, g); + GD_drawing(g) = NULL; + } + rc = gvlayout_select(gvc, engine); + if (rc == NO_SUPPORT) { + fprintf(stderr, "Layout type: \"%s\" not recognized. Use one of:%s\n", + engine, gvplugin_list(gvc, API_layout, engine)); + return -1; + } + + gvlayout_layout(gvc, g); + +/* set bb attribute for basic layout. + * doesn't yet include margins, scaling or page sizes because + * those depend on the renderer being used. */ + if (GD_drawing(g)->landscape) + sprintf(buf, "%d %d %d %d", + ROUND(GD_bb(g).LL.y), ROUND(GD_bb(g).LL.x), + ROUND(GD_bb(g).UR.y), ROUND(GD_bb(g).UR.x)); + else + sprintf(buf, "%d %d %d %d", + ROUND(GD_bb(g).LL.x), ROUND(GD_bb(g).LL.y), + ROUND(GD_bb(g).UR.x), ROUND(GD_bb(g).UR.y)); + if (!(a = agfindattr(g, "bb"))) { + a = agraphattr(g, "bb", ""); + } + agxset(g, a->index, buf); + + return 0; +} + +int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out) +{ + int rc; + GVJ_t *job; + + g = g->root; + + /* create a job for the required format */ + rc = gvrender_output_langname_job(gvc, format); + if (rc == NO_SUPPORT) { + fprintf(stderr, "Renderer type: \"%s\" not recognized. Use one of:%s\n", + format, gvplugin_list(gvc, API_render, format)); + return -1; + } + + job = gvc->job; + job->output_lang = gvrender_select(job, job->output_langname); + if (!GD_drawing(g) && job->output_lang != CANONICAL_DOT) { + fprintf(stderr, "Layout was not done\n"); + return -1; + } + job->output_file = out; + + emit_jobs(gvc, g); + gvrender_delete_jobs(gvc); + + return 0; +} + + +void gvCleanup(GVC_t *gvc) +{ + gvFREEcontext(gvc); } diff --git a/cmd/dot/dotneato.h b/cmd/dot/dotneato.h index df5b1abe4..c8a344f57 100644 --- a/cmd/dot/dotneato.h +++ b/cmd/dot/dotneato.h @@ -25,6 +25,9 @@ extern "C" { #endif extern GVC_t *gvContext(void); +extern int gvLayout(GVC_t *gvc, graph_t *g, char *engine); +extern int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out); +extern void gvCleanup(GVC_t *gvc); #ifdef __cplusplus } diff --git a/dot.demo/Makefile b/dot.demo/Makefile index 6f83caf03..1d288ca72 100644 --- a/dot.demo/Makefile +++ b/dot.demo/Makefile @@ -4,7 +4,7 @@ LINK=libtool --tag=CC --mode=link ${CC} CFLAGS=`pkg-config libdotneato --cflags` LDFLAGS=`pkg-config libdotneato --libs` -all: dot demo +all: dot demo simple dot: dot.lo ${LINK} ${LDFLAGS} -o $@ dot.lo @@ -18,5 +18,11 @@ demo: demo.lo demo.lo: demo.c ${COMPILE} ${CFLAGS} -o $@ demo.c +simple: simple.lo + ${LINK} ${LDFLAGS} -o $@ simple.lo + +simple.lo: simple.c + ${COMPILE} ${CFLAGS} -o $@ simple.c + clean: - rm -rf .libs dot demo *.o *.lo + rm -rf .libs dot demo simple *.o *.lo diff --git a/dot.demo/simple.c b/dot.demo/simple.c new file mode 100644 index 000000000..0d4ba289c --- /dev/null +++ b/dot.demo/simple.c @@ -0,0 +1,42 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#include + +int main(int argc, char **argv) +{ + GVC_t *gvc; + graph_t *g; + FILE *fp; + + gvc = gvContext(); + + if (argc > 1) + fp = fopen(argv[1], "r"); + else + fp = stdin; + g = agread(fp); + + gvLayout(gvc, g, "dot"); + + gvRender(gvc, g, "plain", stdout); + + gvCleanup(gvc); + + agclose(g); + + return 0; +} -- 2.40.0