# $Id$ $Revision$
## Process this file with automake to produce Makefile.in
-if WITH_CGRAPH
-GRAPH = cgraph
-else
-GRAPH = graph
-endif
-
pdfdir = $(pkgdatadir)/doc/pdf
linkedman = neato.1 twopi.1 fdp.1 circo.1
-I$(top_srcdir)/lib/common \
-I$(top_srcdir)/lib/gvc \
-I$(top_srcdir)/lib/pathplan \
- -I$(top_srcdir)/lib/$(GRAPH) \
+ -I$(top_srcdir)/lib/cgraph \
-I$(top_srcdir)/lib/cdt
if ENABLE_SHARED
dot_CPPFLAGS = $(AM_CPPFLAGS) -DDEMAND_LOADING=1
dot_LDADD = \
$(top_builddir)/lib/gvc/libgvc.la \
- $(top_builddir)/lib/$(GRAPH)/lib$(GRAPH).la
+ $(top_builddir)/lib/cgraph/libcgraph.la
install-data-hook:
(cd $(DESTDIR)$(man1dir); for i in $(linkedman); do rm -f $$i; $(LN_S) dot.1 $$i; done;)
$(top_builddir)/plugin/core/libgvplugin_core_C.la \
$(top_builddir)/lib/gvc/libgvc_C.la \
$(top_builddir)/lib/pathplan/libpathplan_C.la \
- $(top_builddir)/lib/$(GRAPH)/lib$(GRAPH)_C.la \
+ $(top_builddir)/lib/cgraph/libcgraph_C.la \
$(top_builddir)/lib/xdot/libxdot_C.la \
$(top_builddir)/lib/cdt/libcdt_C.la \
$(PANGOCAIRO_LIBS) $(PANGOFT2_LIBS) $(GTS_LIBS) $(EXPAT_LIBS) $(Z_LIBS) $(LIBGEN_LIBS) $(SOCKET_LIBS) $(IPSEPCOLA_LIBS) $(MATH_LIBS)
$(top_builddir)/plugin/core/libgvplugin_core.la \
$(top_builddir)/lib/gvc/libgvc.la \
$(top_builddir)/lib/pathplan/libpathplan.la \
- $(top_builddir)/lib/$(GRAPH)/lib$(GRAPH).la \
+ $(top_builddir)/lib/cgraph/libcgraph.la \
$(top_builddir)/lib/xdot/libxdot.la \
$(top_builddir)/lib/cdt/libcdt.la \
$(GTS_LIBS) $(EXPAT_LIBS) $(Z_LIBS) $(LIBGEN_LIBS) $(SOCKET_LIBS) $(IPSEPCOLA_LIBS) $(MATH_LIBS)
__declspec(dllimport) boolean MemTest;
__declspec(dllimport) int GvExitOnUsage;
/*gvc.lib cgraph.lib*/
-#ifdef WITH_CGRAPH
#pragma comment( lib, "cgraph.lib" )
-#else
- #pragma comment( lib, "graph.lib" )
-#endif
#pragma comment( lib, "gvc.lib" )
#else /* not WIN32_DLL */
#include "globals.h"
char name[10];
/* Create a new graph */
-#ifndef WITH_CGRAPH
- aginit();
- agsetiodisc(NULL, gvfwrite, gvferror);
- g = agopen("new_graph", AGDIGRAPH);
-#else /* WITH_CGRAPH */
g = agopen("new_graph", Agdirected,NIL(Agdisc_t *));
-#endif /* WITH_CGRAPH */
/* Add nodes */
for (j = 0; j < NUMNODES; j++) {
sprintf(name, "%d", j);
-#ifndef WITH_CGRAPH
- node[j] = agnode(g, name);
-#else /* WITH_CGRAPH */
node[j] = agnode(g, name, 1);
agbindrec(node[j], "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data
-#endif /* WITH_CGRAPH */
}
/* Connect nodes */
for (j = 0; j < NUMNODES; j++) {
for (k = j + 1; k < NUMNODES; k++) {
-#ifndef WITH_CGRAPH
- agedge(g, node[j], node[k]);
-#else /* WITH_CGRAPH */
e = agedge(g, node[j], node[k], NULL, 1);
agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //edge custom data
-#endif /* WITH_CGRAPH */
}
}
-
-#ifndef WITH_CGRAPH
- sg = agsubg (g, "cluster1");
- aginsert (sg, node[0]);
-#else /* WITH_CGRAPH */
sg = agsubg (g, "cluster1", 1);
agsubnode (sg, node[0], 1);
-#endif /* WITH_CGRAPH */
return g;
}
# $Id$ $Revision$
## Process this file with automake to produce Makefile.in
-if WITH_CGRAPH
-GRAPH = cgraph
-else
-GRAPH = graph
-endif
-
SUBDIRS = ui images
pdfdir = $(pkgdatadir)/doc/pdf
-I$(top_srcdir)/lib/common \
-I$(top_srcdir)/lib/gvc \
-I$(top_srcdir)/lib/pathplan \
- -I$(top_srcdir)/lib/$(GRAPH) \
+ -I$(top_srcdir)/lib/cgraph \
-I$(top_srcdir)/lib/cdt
gvedit_CPPFLAGS = \
return fileName.left(idx);
}
-#ifndef WITH_CGRAPH
-static char*
-graph_reader(char *str, int num, FILE * stream) //helper function to load / parse graphs from tstring
-{
- if (num == 0)
- return str;
- const char *ptr;
- char *optr;
- char c;
- int l;
- rdr_t *s = (rdr_t *) stream;
- if (s->cur >= s->len)
- return NULL;
- l = 0;
- ptr = s->data + s->cur;
- optr = str;
- do {
- *optr++ = c = *ptr++;
- l++;
- } while (c && (c != '\n') && (l < num - 1));
- *optr = '\0';
- s->cur += l;
- return str;
-}
-#endif
-
CFrmSettings::CFrmSettings()
{
this->gvc = gvContext();
rdr.data = bytes.constData();
rdr.len = strlen(rdr.data);
rdr.cur = 0;
-#ifdef WITH_CGRAPH
graph = agmemread(rdr.data);
-#else
- graph = agread_usergets((FILE *) & rdr, (gets_f) graph_reader);
- /* graph=agread_usergets(reinterpret_cast<FILE*>(this),(gets_f)graph_reader); */
-#endif
if (!graph)
return false;
if (agerrors()) {
#ifdef WIN32
/*gvc.lib cgraph.lib*/
-#ifdef WITH_CGRAPH
#pragma comment( lib, "cgraph.lib" )
-#else
-#pragma comment( lib, "graph.lib" )
-#pragma comment( lib, "gvc.lib" )
-#pragma comment( lib, "glib-2.0.lib" )
-#pragma comment( lib, "pango-1.0.lib" )
-#pragma comment( lib, "pangocairo-1.0.lib" )
-#pragma comment( lib, "cairo.lib" )
-#pragma comment( lib, "gobject-2.0.lib" )
-
-#endif
#pragma comment( lib, "gvc.lib" )
#pragma comment( lib, "ingraphs.lib" )
extern "C" {
#endif
-#define WITH_CGRAPH 1
-
-
#ifdef WIN32 //this is needed on WIN32 to get libglade see the callback
#define _BB __declspec(dllexport)
#else
#include "ingraphs.h"
#include "pack.h"
-#ifndef WITH_CGRAPH
-extern Agdict_t *agdictof(void *);
-#endif
-
#ifdef WIN32 /*dependencies*/
-#ifdef WITH_CGRAPH
#pragma comment( lib, "cgraph.lib" )
-#else
- #pragma comment( lib, "graph.lib" )
-#endif
#pragma comment( lib, "gvc.lib" )
#pragma comment( lib, "ingraphs.lib" )
#pragma comment( lib, "neatogen.lib" )
#pragma comment( lib, "glib-2.0.lib" )
#pragma comment( lib, "cdt.lib" )
#pragma comment( lib, "gvplugin_neato_layout.lib" )
-
-
#endif
static char **myFiles = 0;
static int nGraphs = 0; /* Guess as to no. of graphs */
static FILE *outfp; /* output; stdout by default */
-#ifndef WITH_CGRAPH
-static int kind; /* type of graph */
-#else
static Agdesc_t kind; /* type of graph */
-#endif
static int G_cnt; /* No. of -G arguments */
static int G_sz; /* Storage size for -G arguments */
static attr_t *G_args; /* Storage for -G arguments */
return 0;
}
-#ifdef WITH_CGRAPH
static Agsym_t *agraphattr(Agraph_t *g, char *name, char *value)
{
return agattr(g, AGRAPH, name, value);
return agattr(g, AGEDGE, name, value);
}
-#endif
-
/* init:
*/
static void init(int argc, char *argv[], pack_info* pinfo)
char buf[BUFSIZ];
char* bp;
-#ifndef WITH_CGRAPH
- aginit();
-#endif
agnodeattr(NULL, "label", NODENAME_ESC);
pinfo->mode = l_clust;
pinfo->margin = CL_OFFSET;
node_t *n;
edge_t *e;
-#ifdef WITH_CGRAPH
aginit (g, AGRAPH, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
aginit (g, AGNODE, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);
aginit (g, AGEDGE, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
-#endif
GD_gvc(g) = gvc;
graph_init(g, FALSE);
d = late_int(g, agfindgraphattr(g, "dim"), 2, 2);
* Copy all attributes from old object to new. Assume
* attributes have been initialized.
*/
-#ifdef WITH_CGRAPH
static void cloneDfltAttrs(Agraph_t *old, Agraph_t *new, int kind)
{
Agsym_t *a;
agset(new, a->name, s);
}
}
-#else
-static void cloneAttrs(void *old, void *new)
-{
- int j;
- Agsym_t *a;
- Agdict_t *dict = agdictof(old);
-
- for (j = 0; j < dtsize(dict->dict); j++) {
- a = dict->list[j];
- agset(new, a->name, agxget(old, a->index));
- }
-}
-#endif
/* cloneEdge:
* Note that here, and in cloneNode and cloneCluster,
* objp. If the attribute has already been defined and
* has a different default, set default to "".
*/
-#ifdef WITH_CGRAPH
static void fillDict(Dt_t * newdict, Agraph_t* g, int kind)
{
Agsym_t *a;
rv->value = "";
}
}
-#else
-static void fillDict(Dt_t * newdict, void *objp)
-{
- int j;
- Agsym_t *a;
- Agdict_t *olddict = agdictof(objp);
- char *name;
- char *value;
- attr_t *rv;
-
- for (j = 0; j < dtsize(olddict->dict); j++) {
- a = olddict->list[j];
- name = a->name;
- value = agxget(objp, a->index);
- rv = (attr_t *) dtmatch(newdict, name);
- if (!rv) {
- rv = NEW(attr_t);
- rv->name = name;
- rv->value = value;
- dtinsert(newdict, rv);
- } else if (strcmp(value, rv->value))
- rv->value = "";
- }
-}
-#endif
/* fillGraph:
* Use all the name-value entries in the dictionary d to define
for (i = 0; i < cnt; i++) {
g = gs[i];
-#ifdef WITH_CGRAPH
fillDict(g_attrs, g, AGRAPH);
fillDict(n_attrs, g, AGNODE);
fillDict(e_attrs, g, AGEDGE);
-#else
- fillDict(g_attrs, g);
- fillDict(n_attrs, g->proto->n);
- fillDict(e_attrs, g->proto->e);
-#endif
}
fillGraph(root, g_attrs, agraphattr);
static void cloneGraphAttr(Agraph_t * g, Agraph_t * ng)
{
cloneAttrs(g, ng);
-#ifdef WITH_CGRAPH
cloneDfltAttrs(g, ng, AGNODE);
cloneDfltAttrs(g, ng, AGEDGE);
-#else
- cloneAttrs(g->proto->n, ng->proto->n);
- cloneAttrs(g->proto->e, ng->proto->e);
-#endif
}
#ifdef UNIMPL
static void
cloneSubg(Agraph_t * g, Agraph_t * ng, Agsym_t * G_bb, Dt_t * gnames)
{
-#ifndef WITH_CGRAPH
- graph_t *mg;
- edge_t *me;
- node_t *mn;
-#endif
node_t *n;
node_t *nn;
edge_t *e;
cloneGraphAttr(g, ng);
if (doPack)
-#ifdef WITH_CGRAPH
agxset(ng, G_bb, ""); /* Unset all subgraph bb */
-#else
- agxset(ng, G_bb->index, ""); /* Unset all subgraph bb */
-#endif
/* clone subgraphs */
-#ifdef WITH_CGRAPH
for (subg = agfstsubg (g); subg; subg = agfstsubg (subg)) {
nsubg = agsubg(ng, xName(gnames, agnameof(subg)), 1);
agbindrec (nsubg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
-#else
- mg = g->meta_node->graph;
- for (me = agfstout(mg, g->meta_node); me; me = agnxtout(mg, me)) {
- mn = aghead(me);
- subg = agusergraph(mn);
- nsubg = agsubg(ng, xName(gnames, agnameof(subg)));
-#endif
cloneSubg(subg, nsubg, G_bb, gnames);
/* if subgraphs are clusters, point to the new
* one so we can find it later.
/* add remaining nodes */
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
nn = NEWNODE(n);
-#ifndef WITH_CGRAPH
- if (!agfindnode(ng, agnameof(nn)))
- aginsert(ng, nn);
-#else
agsubnode(ng, nn, 1);
-#endif
}
/* add remaining edges. libgraph doesn't provide a way to find
continue;
nt = NEWNODE(agtail(e));
nh = NEWNODE(aghead(e));
-#ifndef WITH_CGRAPH
- ne = agedge(ng, nt, nh);
-#else
ne = agedge(ng, nt, nh, NULL, 1);
agbindrec (ne, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);
-#endif
cloneEdge(e, ne);
MARK(e);
}
if (verbose)
fprintf(stderr, "Creating clone graph\n");
-#ifndef WITH_CGRAPH
- root = agopen(gname, kind);
-#else
root = agopen(gname, kind, &AgDefaultDisc);
-#endif
initAttrs(root, gs, cnt);
G_bb = agfindgraphattr(root, "bb");
if (doPack) assert(G_bb);
for (i = 0; i < G_cnt; i++) {
rv = agfindgraphattr(root, G_args[i].name);
if (rv)
-#ifndef WITH_CGRAPH
- agxset(root, rv->index, G_args[i].value);
- else
- agraphattr(root, G_args[i].name, G_args[i].value);
-#else
agxset(root, rv, G_args[i].value);
else
agattr(root, AGRAPH, G_args[i].name, G_args[i].value);
-#endif
}
/* do common initialization. This will handle root's label. */
fprintf(stderr, "Some nodes will be renamed.\n");
doWarn = FALSE;
}
-#ifndef WITH_CGRAPH
- np = agnode(root, xName(nnames, agnameof(n)));
-#else
np = agnode(root, xName(nnames, agnameof(n)), 1);
agbindrec (np, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);
-#endif
ND_alg(n) = np;
cloneNode(n, np);
}
/* wrap the clone of g in a subgraph of root */
-#ifndef WITH_CGRAPH
- subg = agsubg(root, xName(gnames, agnameof(g)));
-#else
subg = agsubg(root, xName(gnames, agnameof(g)), 1);
agbindrec (subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
-#endif
cloneSubg(g, subg, G_bb, gnames);
}
dtclose(gnames);
return root;
}
-#ifdef WITH_CGRAPH
static Agraph_t *gread(FILE * fp)
{
return agread(fp, (Agdisc_t *) 0);
}
-#else
-static Agraph_t *gread(FILE * fp)
-{
- return agread(fp);
-}
-#endif
/* readGraphs:
* Read input, parse the graphs, use init_nop (neato -n) to
sz += nGraphs;
gs = ALLOC(sz, gs, Agraph_t *);
}
-#ifndef WITH_CGRAPH
- if (kindUnset) {
- kindUnset = 0;
- kind = g->kind;
- }
- else if ((kind & AGFLAG_DIRECTED) != AG_IS_DIRECTED(g)) {
- fprintf(stderr,
- "Error: all graphs must be directed or undirected\n");
- exit(1);
- } else if (!AG_IS_STRICT(g))
- kind = g->kind;
-#else
if (kindUnset) {
kindUnset = 0;
kind = g->desc;
exit(1);
} else if (!agisstrict(g))
kind = g->desc;
-#endif
init_graph(g, doPack, gvc);
gs[cnt++] = g;
}
}
}
-#ifndef WITH_CGRAPH
-void dumps(Agraph_t * g)
-{
- graph_t *subg;
- graph_t *mg;
- edge_t *me;
- node_t *mn;
-
- mg = g->meta_node->graph;
- for (me = agfstout(mg, g->meta_node); me; me = agnxtout(mg, me)) {
- mn = aghead(me);
- subg = agusergraph(mn);
- dump(subg);
- fprintf(stderr, "====\n");
- }
-}
-#else
void dumps(Agraph_t * g)
{
graph_t *subg;
}
}
#endif
-#endif
int main(int argc, char *argv[])
{
fi
AM_CONDITIONAL(WITH_SMYRNA, [test "x$use_smyrna" = "xYes"])
-dnl -----------------------------------
-dnl CGRAPH
-
-AC_ARG_WITH(cgraph,
- [AS_HELP_STRING([--with-cgraph=yes],[Use CGRAPH library])],
- [], [with_cgraph=yes])
-
-if test "x$with_cgraph" != "xyes"; then
- use_cgraph="No (disabled)"
- use_graph="Yes"
-else
- use_cgraph="Yes"
- use_graph="No (disabled deprecated)"
- AC_DEFINE_UNQUOTED(WITH_CGRAPH,1,[Define if you want CGRAPH])
-fi
-AM_CONDITIONAL(WITH_CGRAPH, [test "x$use_cgraph" = "xYes"])
-
dnl -----------------------------------
dnl ORTHO
lib/Makefile
lib/cdt/Makefile
lib/cdt/libcdt.pc
- lib/graph/Makefile
- lib/graph/libgraph.pc
lib/cgraph/Makefile
lib/cgraph/libcgraph.pc
lib/rbtree/Makefile
# Available features are:
# SHARP GHOSTSCRIPT GUILE _IO JAVA LUA OCAML ORTHO PERL PHP
# PYTHON RUBY R_LANG TCL IPSEPCOLA MYLIBGD PANGOCAIRO RSVG
-# GTK GLITZ SMYRNA DEVIL MING GDK_PIXBUF _QT WEBP CGRAPH
+# GTK GLITZ SMYRNA DEVIL MING GDK_PIXBUF _QT WEBP
# SuSE uses a different mechanism to generate BuildRequires
# norootforbuild
#-- All platforms
%define __X 1
-%define CGRAPH 1
#-- Red Hat Enterprise Linux (also Centos) specific Build Requirements
%if 0%{?rhel}
%defattr(-,root,root,-)
%{_libdir}/libcdt.so.*
%{_libdir}/libcgraph.so.*
-%if ! 0%{?CGRAPH}
-%{_libdir}/libgraph.so.*
-%endif
%{_libdir}/libgvc.so.*
%{_libdir}/libgvpr.so.*
%{_libdir}/libpathplan.so.*
%{_libdir}/libcgraph.so
%{_mandir}/man3/cgraph.3.*
%{_libdir}/pkgconfig/libcgraph.pc
-%if ! 0%{?CGRAPH}
-%{_libdir}/libgraph.so
-%{_mandir}/man3/graph.3.*
-%{_libdir}/pkgconfig/libgraph.pc
-%else
%exclude %{_mandir}/man3/graph.3.*
-%endif
%{_libdir}/libgvc.so
%{_mandir}/man3/gvc.3.*
%{_libdir}/pkgconfig/libgvc.pc
--enable-r%{!?R_LANG:=no} \
--enable-ruby%{!?RUBY:=no} \
--enable-tcl%{!?TCL:=no} \
- --with%{!?CGRAPH:out}-cgraph \
--with%{!?DEVIL:out}-devil \
--with%{!?WEBP:out}-webp \
--with%{!?GDK_PIXBUF:out}-gdk-pixbuf \
-I$(top_srcdir) \
-I$(top_srcdir)/lib/cdt
-if WITH_CGRAPH
-else
pkginclude_HEADERS = agraph.h
noinst_HEADERS = aghdr.h malloc.h vmstub.h grammar.h
noinst_LTLIBRARIES = libagraph_C.la
pkgconfig_DATA = libagraph.pc
man_MANS = agraph.3
pdf_DATA = agraph.3.pdf
-endif
libagraph_C_la_SOURCES = agerror.c apply.c attr.c \
edge.c flatten.c grammar.y graph.c id.c imap.c io.c \
-I$(top_srcdir)/lib/agraph \
-I$(top_srcdir)/lib/cdt
-if WITH_CGRAPH
-else
noinst_HEADERS = agutil.h
noinst_LTLIBRARIES = libagutil_C.la
-endif
libagutil_C_la_SOURCES = dynattr.c nodeq.c agutil.h
#ifndef GV_TYPES_H
#define GV_TYPES_H
-/* Define if you want CGRAPH */
-#undef WITH_CGRAPH
-
#include <stdio.h>
#include <assert.h>
#include <signal.h>
#include "gvcext.h"
#include "pathgeom.h"
#include "textpara.h"
+#include "cgraph.h"
#ifdef __cplusplus
extern "C" {
#define ED_dist(e) (((Agedgeinfo_t*)AGDATA(e))->dist)
#define ED_weight(e) (((Agedgeinfo_t*)AGDATA(e))->weight)
-#include "cgraph.h"
#define ag_xget(x,a) agxget(x,a)
#define SET_RANKDIR(g,rd) (GD_rankdir2(g) = rd)
#define agfindedge(g,t,h) (agedge(g,t,h,NULL,0))
-I$(top_srcdir)/lib/cdt
man_MANS = graph.3
-if WITH_CGRAPH
-else
pkginclude_HEADERS = graph.h
noinst_HEADERS = libgraph.h triefa.h parser.h agxbuf.h
noinst_LTLIBRARIES = libgraph_C.la
lib_LTLIBRARIES = libgraph.la
pkgconfig_DATA = libgraph.pc
pdf_DATA = graph.3.pdf
-endif
libgraph_C_la_SOURCES = \
attribs.c agxbuf.c edge.c graph.c graphio.c lexer.c \
libdir=@libdir@
includedir=@includedir@/@PACKAGE@
plugins=@GVPLUGIN_VERSION@
-@WITH_CGRAPH_FALSE@GRAPH = graph
-@WITH_CGRAPH_TRUE@GRAPH = cgraph
-
Name: libgvc
Description: The GraphVizContext library
Version: @VERSION@
-Libs: -L${libdir} -lgvc -l${GRAPH} -lcdt
+Libs: -L${libdir} -lgvc -lcgraph -lcdt
Cflags: -I${includedir}
gvputs(job, "<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
-#ifndef WITH_CGRAPH
- name = obj->u.g->name;
-#else
name = agnameof(obj->u.g);
-#endif
if (name[0]) {
gvputs(job, "<TITLE>");
gvputs(job, html_string(name));
libgvplugin_dot_layout_C_la_SOURCES = \
gvplugin_dot_layout.c \
gvlayout_dot_layout.c
-if WITH_CGRAPH
libgvplugin_dot_layout_C_la_LIBADD = \
$(top_builddir)/lib/dotgen/libdotgen_C.la
-else
-libgvplugin_dot_layout_C_la_LIBADD = \
- $(top_builddir)/lib/dotgen/libdotgen_C.la
-endif
libgvplugin_dot_layout_la_LDFLAGS = -version-info $(GVPLUGIN_VERSION_INFO)
libgvplugin_dot_layout_la_SOURCES = $(libgvplugin_dot_layout_C_la_SOURCES)
_graphics[0],
beginId == _nodeIds.end() ? 0 : beginId->second,
endId == _nodeIds.end() ? 0 : endId->second,
-#ifdef WITH_CGRAPH
EDGE_TYPE(agroot(edge))))
-#else
- EDGE_TYPE(edge->head->graph->root)))
-#endif
firstConnector = false;
else
PrintOuterShape(job, *nextGraphic);
#include "gvcjob.h"
#include "gvio.h"
-#ifdef WITH_CGRAPH
#include <string.h>
-#endif
extern "C" char *xml_string(char* str);
Run::Run(boxf bounds, char* text):
_bounds(bounds),
-#ifdef WITH_CGRAPH
_text(strdup(text)) /* copy text */
-#else
- _text(agstrdup(text)) /* copy text */
-#endif
{
}
Run::~Run()
{
/* since we copied, we need to free */
-#ifdef WITH_CGRAPH
free(_text);
-#else
- agstrfree(_text);
-#endif
}
boxf Run::GetBounds() const
}
Hyperlink::Hyperlink(char* description, char* address, char* frame):
-#ifdef WITH_CGRAPH
_description(strdup(description)),
_address(strdup(address)),
_frame(strdup(frame))
-#else
- _description(agstrdup(description)),
- _address(agstrdup(address)),
- _frame(agstrdup(frame))
-#endif
{
}
Hyperlink::~Hyperlink()
{
-#ifdef WITH_CGRAPH
free(_description);
free(_address);
free(_frame);
-#else
- agstrfree(_description);
- agstrfree(_address);
- agstrfree(_frame);
-#endif
}
/* output the hyperlink */
SUBDIRS = demo
-if WITH_CGRAPH
-GRAPH = cgraph
-DEFS += -DWITH_CGRAPH
-else
-GRAPH = graph
-endif
-
pdfdir = $(pkgdatadir)/doc/pdf
AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/lib/gvc \
-I$(top_srcdir)/lib/common \
- -I$(top_srcdir)/lib/$(GRAPH) \
+ -I$(top_srcdir)/lib/cgraph \
-I$(top_srcdir)/lib/cdt \
-I$(top_srcdir)/lib/pathplan
BASESOURCES = gv.cpp gv.i gv_builtins.c
BASELIBS = $(top_builddir)/lib/gvc/libgvc.la \
- $(top_builddir)/lib/$(GRAPH)/lib$(GRAPH).la \
+ $(top_builddir)/lib/cgraph/libcgraph.la \
$(top_builddir)/lib/cdt/libcdt.la
BASECPPFLAGS = $(AM_CPPFLAGS) -DDEMAND_LOADING=1
extern void gv_channel_writer_init(GVC_t *gvc);
}
-#ifdef WITH_CGRAPH
#define agfindattr(x,s) agattrsym(x,s)
#define agraphattr(g,n,s) agattr(g,AGRAPH,n,s)
#define agnodeattr(g,n,s) agattr(g,AGNODE,n,s)
#define agedgeattr(g,n,s) agattr(g,AGEDGE,n,s)
-#endif
static char emptystring[] = {'\0'};
{
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
return agopen(name, Agundirected, 0);
-#else
- return agopen(name, AGRAPH);
-#endif
}
Agraph_t *digraph(char *name)
{
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
return agopen(name, Agdirected, 0);
-#else
- return agopen(name, AGDIGRAPH);
-#endif
}
Agraph_t *strictgraph(char *name)
{
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
return agopen(name, Agstrictundirected, 0);
-#else
- return agopen(name, AGRAPHSTRICT);
-#endif
}
Agraph_t *strictdigraph(char *name)
{
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
return agopen(name, Agstrictdirected, 0);
-#else
- return agopen(name, AGDIGRAPHSTRICT);
-#endif
}
Agraph_t *readstring(char *string)
{
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
return agread(f, NULL);
-#else
- return agread(f);
-#endif
}
Agraph_t *read(const char *filename)
return NULL;
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
g = agread(f, NULL);
-#else
- g = agread(f);
-#endif
fclose(f);
return g;
}
{
if (!gvc)
gv_init();
-#ifdef WITH_CGRAPH
return agsubg(g, name, 1);
-#else
- return agsubg(g, name);
-#endif
}
Agnode_t *node(Agraph_t *g, char *name)
{
if (!gvc)
return NULL;
-#ifdef WITH_CGRAPH
return agnode(g, name, 1);
-#else
- // creating a protonode is not permitted
- if (name[0] == '\001' && strcmp (name, "\001proto") == 0)
- return NULL;
- return agnode(g, name);
-#endif
}
Agedge_t *edge(Agnode_t *t, Agnode_t *h)
{
if (!gvc || !t || !h)
return NULL;
-#ifdef WITH_CGRAPH
// edges from/to the protonode are not permitted
if (AGTYPE(t) == AGRAPH || AGTYPE(h) == AGRAPH)
return NULL;
return agedge(agraphof(t), t, h, NULL, 1);
-#else
- // edges from/to the protonode are not permitted
- if ((agnameof(t)[0] == '\001' && strcmp (agnameof(t), "\001proto") == 0)
- || (agnameof(h)[0] == '\001' && strcmp (agnameof(h), "\001proto") == 0))
- return NULL;
- return agedge(t->graph, t, h);
-#endif
}
// induce tail if necessary
Agedge_t *edge(char *tname, Agnode_t *h)
{
-#ifdef WITH_CGRAPH
return edge(node(agraphof(h), tname), h);
-#else
- return edge(node(h->graph, tname), h);
-#endif
}
// induce head if necessary
Agedge_t *edge(Agnode_t *t, char *hname)
{
-#ifdef WITH_CGRAPH
return edge(t, node(agraphof(t), hname));
-#else
- return edge(t, node(t->graph, hname));
-#endif
}
// induce tail/head if necessary
if (!obj || !a)
return emptystring;
-#ifndef WITH_CGRAPH
- val = agxget(obj, a->index);
-#else
val = agxget(obj, a);
-#endif
if (!val)
return emptystring;
if (a->name[0] == 'l' && strcmp(a->name, "label") == 0 && aghtmlstr(val)) {
if (val[len-1] == '>') {
hs = strdup(val+1);
*(hs+len-2) = '\0';
-#ifdef WITH_CGRAPH
val = agstrdup_html(agraphof(obj),hs);
-#else
- val = agstrdup_html(hs);
-#endif
free(hs);
}
}
-#ifndef WITH_CGRAPH
- agxset(obj, a->index, val);
-#else
agxset(obj, a, val);
-#endif
}
char *setv(Agraph_t *g, Agsym_t *a, char *val)
{
{
if (!n || !a)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(n) == AGRAPH) // protonode
return NULL; // FIXME ??
-#endif
return myagxget(n, a);
}
char *getv(Agnode_t *n, char *attr)
if (!n || !attr)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(n) == AGRAPH) // protonode
return NULL; // FIXME ??
-#endif
g = agroot(agraphof(n));
-#ifdef WITH_CGRAPH
a = agattr(g, AGNODE, attr, NULL);
-#else
- a = agfindattr(g->proto->n, attr);
-#endif
return myagxget(n, a);
}
char *setv(Agnode_t *n, Agsym_t *a, char *val)
{
if (!n || !a || !val)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(n) == AGRAPH) // protonode
return NULL; // FIXME ??
-#endif
myagxset(n, a, val);
return val;
}
if (!n || !attr || !val)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(n) == AGRAPH) { // protonode
g = (Agraph_t*)n;
a = agattr(g, AGNODE, attr, val); // create default attribute in psuodo protonode
// FIXME? - deal with html in "label" attributes
return val;
}
-#endif
g = agroot(agraphof(n));
-#ifdef WITH_CGRAPH
a = agattr(g, AGNODE, attr, NULL);
-#else
- a = agfindattr(g->proto->n, attr);
-#endif
if (!a)
a = agnodeattr(g, attr, emptystring);
myagxset(n, a, val);
{
if (!e || !a)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH) // protoedge
return NULL; // FIXME ??
-#endif
return myagxget(e, a);
}
char *getv(Agedge_t *e, char *attr)
if (!e || !attr)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH) // protoedge
return NULL; // FIXME ??
-#endif
g = agraphof(agtail(e));
-#ifndef WITH_CGRAPH
- a = agfindattr(g->proto->e, attr);
-#else
a = agattr(g, AGEDGE, attr, NULL);
-#endif
return myagxget(e, a);
}
char *setv(Agedge_t *e, Agsym_t *a, char *val)
{
if (!e || !a || !val)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH) // protoedge
return NULL; // FIXME ??
-#endif
myagxset(e, a, val);
return val;
}
if (!e || !attr || !val)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH) { // protoedge
g = (Agraph_t*)e;
a = agattr(g, AGEDGE, attr, val); // create default attribute in pseudo protoedge
// FIXME? - deal with html in "label" attributes
return val;
}
-#endif
g = agroot(agraphof(agtail(e)));
-#ifndef WITH_CGRAPH
- a = agfindattr(g->proto->e, attr);
- if (!a)
- a = agedgeattr(g, attr, emptystring);
-#else
a = agattr(g, AGEDGE, attr, NULL);
if (!a)
a = agattr(g, AGEDGE, attr, emptystring);
-#endif
myagxset(e, a, val);
return val;
}
{
if (!g || !name)
return NULL;
-#ifndef WITH_CGRAPH
- return agfindsubg(g, name);
-#else
return agsubg(g, name, 0);
-#endif
}
Agnode_t *findnode(Agraph_t *g, char *name)
{
if (!g || !name)
return NULL;
-#ifndef WITH_CGRAPH
- return agfindnode(g, name);
-#else
return agnode(g, name, 0);
-#endif
}
Agedge_t *findedge(Agnode_t *t, Agnode_t *h)
{
if (!t || !h)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(t) == AGRAPH || AGTYPE(h) == AGRAPH)
return NULL;
-#endif
return agfindedge(agraphof(t), t, h);
}
{
if (!e)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH)
return NULL;
-#endif
return aghead(e);
}
{
if (!e)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH)
return NULL;
-#endif
return agtail(e);
}
{
if (!e)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(e) == AGRAPH)
return (Agraph_t*)e; /* graph of protoedge is itself recast */
-#endif
return agraphof(agtail(e));
}
{
if (!n)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(n) == AGRAPH)
return (Agraph_t*)n; /* graph of protonode is itself recast */
-#endif
return agraphof(n);
}
{
if (!g)
return NULL;
-#ifdef WITH_CGRAPH
return (Agnode_t *)g; // gross abuse of the type system!
-#else
- return g->proto->n;
-#endif
}
Agedge_t *protoedge(Agraph_t *g)
{
if (!g)
return NULL;
-#ifdef WITH_CGRAPH
return (Agedge_t *)g; // gross abuse of the type system!
-#else
- return g->proto->e;
-#endif
}
//-------------------------------------------------
{
if (!n)
return NULL;
-#ifdef WITH_CGRAPH
if (AGTYPE(n) == AGRAPH)
return NULL;
-#endif
return agnameof(n);
}
//char *nameof(Agedge_t *e)
//{
// if (!e)
// return NULL;
-//#ifdef WITH_CGRAPH
// if (AGTYPE(e) == AGRAPH)
// return NULL;
-//#endif
// return agnameof(e);
//}
char *nameof(Agsym_t *a)
//-------------------------------------------------
Agraph_t *firstsubg(Agraph_t *g)
{
-#ifndef WITH_CGRAPH
- Agraph_t *mg;
- Agnode_t *n;
- Agedge_t *e;
-#endif
-
if (!g)
return NULL;
-#ifdef WITH_CGRAPH
return agfstsubg(g);
-#else
- n = g->meta_node;
- if (!n)
- return NULL;
- mg = agraphof(n);
- if (!mg)
- return NULL;
- e = agfstout(mg, n);
- if (!e)
- return NULL;
- return agusergraph(aghead(e));
-#endif
}
Agraph_t *nextsubg(Agraph_t *g, Agraph_t *sg)
{
-#ifndef WITH_CGRAPH
- Agraph_t *mg;
- Agnode_t *ng, *nsg;
- Agedge_t *e;
-#endif
if (!g || !sg)
return NULL;
-#ifdef WITH_CGRAPH
return agnxtsubg(sg);
-#else
- ng = g->meta_node;
- nsg = sg->meta_node;
- if (!ng || !nsg)
- return NULL;
- mg = agraphof(ng);
- if (!mg)
- return NULL;
- e = agfindedge(mg, ng, nsg);
- if (!e)
- return NULL;
- e = agnxtout(mg, e);
- if (!e)
- return NULL;
- return agusergraph(aghead(e));
-#endif
}
-#ifdef WITH_CGRAPH
Agraph_t *firstsupg(Agraph_t *g)
{
return g->parent;
{
return NULL;
}
-#else
-Agraph_t *firstsupg(Agraph_t *g)
-{
- Agraph_t *mg;
- Agnode_t *n;
- Agedge_t *e;
-
- if (!g)
- return NULL;
- n = g->meta_node;
- if (!n)
- return NULL;
- mg = agraphof(n);
- if (!mg)
- return NULL;
- e = agfstin(mg, n);
- if (!e)
- return NULL;
- return agusergraph(agtail(e));
-}
-
-Agraph_t *nextsupg(Agraph_t *g, Agraph_t *sg)
-{
- Agraph_t *mg;
- Agnode_t *ng, *nsg;
- Agedge_t *e;
-
- if (!g || !sg)
- return NULL;
- ng = g->meta_node;
- nsg = sg->meta_node;
- if (!ng || !nsg)
- return NULL;
- mg = agraphof(ng);
- if (!mg)
- return NULL;
- e = agfindedge(mg, nsg, ng);
- if (!e)
- return NULL;
- e = agnxtin(mg, e);
- if (!e)
- return NULL;
- return agusergraph(agtail(e));
-}
-#endif
Agedge_t *firstout(Agraph_t *g)
{
if (!g)
return NULL;
g = agroot(g);
-#ifdef WITH_CGRAPH
return agnxtattr(g,AGRAPH,NULL);
-#else
- if (dtsize(g->univ->globattr->dict) == 0)
- return NULL;
- return g->univ->globattr->list[0];
-#endif
}
Agsym_t *nextattr(Agraph_t *g, Agsym_t *a)
if (!g || !a)
return NULL;
g = agroot(g);
-#ifdef WITH_CGRAPH
return agnxtattr(g,AGRAPH,a);
-#else
- for (i = 0; i < dtsize(g->univ->globattr->dict); i++)
- if (a == g->univ->globattr->list[i])
- break;
- i++;
- if (i > dtsize(g->univ->globattr->dict))
- return NULL;
- return g->univ->globattr->list[i];
-#endif
}
Agsym_t *firstattr(Agnode_t *n)
if (!n)
return NULL;
g = agraphof(n);
-#ifdef WITH_CGRAPH
return agnxtattr(g,AGNODE,NULL);
-#else
- if (dtsize(g->univ->nodeattr->dict) == 0)
- return NULL;
- return g->univ->nodeattr->list[0];
-#endif
}
Agsym_t *nextattr(Agnode_t *n, Agsym_t *a)
if (!n || !a)
return NULL;
g = agraphof(n);
-#ifdef WITH_CGRAPH
return agnxtattr(g,AGNODE,a);
-#else
- for (i = 0; i < dtsize(g->univ->nodeattr->dict); i++)
- if (a == g->univ->nodeattr->list[i])
- break;
- i++;
- if (i > dtsize(g->univ->nodeattr->dict))
- return NULL;
- return g->univ->nodeattr->list[i];
-#endif
}
Agsym_t *firstattr(Agedge_t *e)
if (!e)
return NULL;
g = agraphof(agtail(e));
-#ifdef WITH_CGRAPH
return agnxtattr(g,AGEDGE,NULL);
-#else
- if (dtsize(g->univ->edgeattr->dict) == 0)
- return NULL;
- return g->univ->edgeattr->list[0];
-#endif
}
Agsym_t *nextattr(Agedge_t *e, Agsym_t *a)
if (!e || !a)
return NULL;
g = agraphof(agtail(e));
-#ifdef WITH_CGRAPH
return agnxtattr(g,AGEDGE,a);
-#else
- for (i = 0; i < dtsize(g->univ->edgeattr->dict); i++)
- if (a == g->univ->edgeattr->list[i])
- break;
- i++;
- if (i > dtsize(g->univ->edgeattr->dict))
- return NULL;
- return g->univ->edgeattr->list[i];
-#endif
}
bool rm(Agraph_t *g)
if (!g)
return false;
-#ifdef WITH_CGRAPH
Agraph_t* sg;
for (sg = agfstsubg (g); sg; sg = agnxtsubg (sg))
rm(sg);
else
agdelete(agroot(g), g);
return true;
-#else
- if (g->meta_node) {
- for (e = agfstout(g->meta_node->graph, g->meta_node); e;
- e = agnxtout(g->meta_node->graph, e)) {
- rm(agusergraph(aghead(e)));
- }
- if (g == agroot(g)) {
- agclose(g);
- } else {
- agdelete(g->meta_node->graph, g);
- }
- return true;
- }
- fprintf(stderr, "subgraph has no meta_node\n");
- return false;
-#endif
}
bool rm(Agnode_t *n)
SUBDIRS = demo
-if WITH_CGRAPH
-GRAPH = cgraph
-else
-GRAPH = graph
-endif
-
# tclhandle still needed for gd
TCLHANDLE_INCLUDES=-I$(top_srcdir)/tclpkg/tclhandle
TCLHANDLE_LIBS=$(top_builddir)/tclpkg/tclhandle/libtclhandle_C.la
-I$(top_srcdir) \
-I$(top_srcdir)/lib/gvc \
-I$(top_srcdir)/lib/common \
- -I$(top_srcdir)/lib/$(GRAPH) \
+ -I$(top_srcdir)/lib/cgraph \
-I$(top_srcdir)/lib/cdt \
-I$(top_srcdir)/lib/pathplan $(TCLHANDLE_INCLUDES) $(GD_INCLUDES) $(TCL_INCLUDES)
libtcldot_la_LIBADD = $(TCLHANDLE_LIBS) \
$(top_builddir)/tclpkg/tclstubs/libtclstubs_C.la \
$(top_builddir)/lib/cdt/libcdt.la \
- $(top_builddir)/lib/$(GRAPH)/lib$(GRAPH).la \
+ $(top_builddir)/lib/cgraph/libcgraph.la \
$(top_builddir)/lib/pathplan/libpathplan_C.la \
$(top_builddir)/lib/gvc/libgvc.la
$(top_builddir)/plugin/neato_layout/libgvplugin_neato_layout_C.la \
$(top_builddir)/plugin/core/libgvplugin_core_C.la \
$(top_builddir)/lib/gvc/libgvc_C.la \
- $(top_builddir)/lib/$(GRAPH)/lib$(GRAPH)_C.la \
+ $(top_builddir)/lib/cgraph/libcgraph_C.la \
$(top_builddir)/lib/cdt/libcdt_C.la \
$(top_builddir)/lib/pathplan/libpathplan_C.la \
$(top_builddir)/tclpkg/tclstubs/libtclstubs_C.la $(GTS_LIBS)
Agraph_t *g;
Agedge_t *e;
Agsym_t *a;
-#ifndef WITH_CGRAPH
- char buf[32];
- Agedge_t **ep;
- ictx_t *ictx = (ictx_t *)clientData;
-#else
gctx_t *gctx = (gctx_t *)clientData;
ictx_t *ictx = gctx->ictx;
-#endif
GVC_t *gvc = ictx->gvc;
if (argc < 2) {
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], "\" option ?arg arg ...?", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- if (!(ep = (Agedge_t **) tclhandleXlate(ictx->edgeTblPtr, argv[0]))) {
- Tcl_AppendResult(interp, "Edge \"", argv[0], "\" not found", NULL);
- return TCL_ERROR;
- }
- e = *ep;
-#else
e = cmd2e(argv[0]);
if (!e) {
Tcl_AppendResult(interp, "Edge \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
}
-#endif
g = agraphof(agtail(e));
c = argv[1][0];
length = strlen(argv[1]);
if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
-#ifndef WITH_CGRAPH
- deleteEdge(ictx, g, e);
-#else
deleteEdge(gctx, g, e);
-#endif
reset_layout(gvc, g);
return TCL_OK;
return TCL_OK;
} else if ((c == 'l') && (strncmp(argv[1], "listnodes", length) == 0)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->nodeTblPtr, buf, AGID(agtail(e)));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(agtail(e)));
-#endif
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->nodeTblPtr, buf, AGID(aghead(e)));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(aghead(e)));
-#endif
return TCL_OK;
} else if ((c == 'q')
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindedgeattr(g, argv2[j]))) {
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(e, a->index));
-#else
Tcl_AppendElement(interp, agxget(e, a));
-#endif
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindedgeattr(g, argv2[j]))) {
Tcl_AppendElement(interp, argv2[j]);
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(e, a->index));
-#else
Tcl_AppendElement(interp, agxget(e, a));
-#endif
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
Agraph_t *g, *sg;
Agnode_t *n, *tail, *head;
Agedge_t *e;
-#ifndef WITH_CGRAPH
- Agraph_t **gp, **sgp;
- Agnode_t **np;
- Agedge_t **ep;
- ictx_t *ictx = (ictx_t *)clientData;
- unsigned long id;
-#else
gctx_t *gctx = (gctx_t *)clientData;
ictx_t *ictx = gctx->ictx;
-#endif
Agsym_t *a;
char c, buf[256], **argv2;
int i, j, length, argc2, rc;
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " option ?arg arg ...?\"", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- if (!(gp = (Agraph_t **) tclhandleXlate(ictx->graphTblPtr, argv[0]))) {
- Tcl_AppendResult(interp, "Graph \"", argv[0], "\" not found", NULL);
- return TCL_ERROR;
- }
- g = *gp;
-#else
g = cmd2g(argv[0]);
if (!g) {
Tcl_AppendResult(interp, "Graph \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
}
-#endif
c = argv[1][0];
length = strlen(argv[1]);
NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- if (!(np = (Agnode_t **) tclhandleXlate(ictx->nodeTblPtr, argv[2]))) {
- if (!(tail = agfindnode(g, argv[2]))) {
- Tcl_AppendResult(interp, "Tail node \"", argv[2], "\" not found.", NULL);
- return TCL_ERROR;
- }
- }
- else {
- tail = *np;
- }
-#else
tail = cmd2n(argv[2]);
if (!tail) {
if (!(tail = agfindnode(g, argv[2]))) {
return TCL_ERROR;
}
}
-#endif
if (agroot(g) != agroot(agraphof(tail))) {
Tcl_AppendResult(interp, "Tail node ", argv[2], " is not in the graph.", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- if (!(np = (Agnode_t **) tclhandleXlate(ictx->nodeTblPtr, argv[3]))) {
- if (!(head = agfindnode(g, argv[3]))) {
- Tcl_AppendResult(interp, "Head node \"", argv[3], "\" not found.", NULL);
- return TCL_ERROR;
- }
- }
- else {
- head = *np;
- }
-#else
head = cmd2n(argv[2]);
if (!head) {
if (!(head = agfindnode(g, argv[3]))) {
return TCL_ERROR;
}
}
-#endif
if (agroot(g) != agroot(agraphof(head))) {
Tcl_AppendResult(interp, "Head node ", argv[3], " is not in the graph.", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- e = agedge(g, tail, head);
-#else
e = agedge(g, tail, head, NULL, 1);
Tcl_AppendResult(interp, obj2cmd(e), NULL);
-#endif
-#ifndef WITH_CGRAPH
- if (!(ep = (Agedge_t **) tclhandleXlateIndex(ictx->edgeTblPtr, AGID(e))) || *ep != e) {
- ep = (Agedge_t **) tclhandleAlloc(ictx->edgeTblPtr, Tcl_GetStringResult(interp), &id);
- *ep = e;
- AGID(e) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), edgecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), edgecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- } else {
- tclhandleString(ictx->edgeTblPtr, Tcl_GetStringResult(interp), AGID(e));
- }
-#endif
setedgeattributes(agroot(g), e, &argv[4], argc - 4);
reset_layout(gvc, g);
return TCL_OK;
} else if ((c == 'a') && (strncmp(argv[1], "addnode", length) == 0)) {
if (argc % 2) {
/* if odd number of args then argv[2] is name */
-#ifdef WITH_CGRAPH
n = agnode(g, argv[2], 1);
-#else
- n = agnode(g, argv[2]);
- if (!(np = (Agnode_t **) tclhandleXlateIndex(ictx->nodeTblPtr, AGID(n))) || *np != n) {
- np = (Agnode_t **) tclhandleAlloc(ictx->nodeTblPtr, Tcl_GetStringResult(interp), &id);
- *np = n;
- AGID(n) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), nodecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), nodecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- } else {
- tclhandleString(ictx->nodeTblPtr, Tcl_GetStringResult(interp), AGID(n));
- }
-#endif
i = 3;
} else {
-#ifdef WITH_CGRAPH
n = agnode(g, NULL, 1); /* anon node */
-#else
- /* else use handle as name */
- np = (Agnode_t **) tclhandleAlloc(ictx->nodeTblPtr, Tcl_GetStringResult(interp), &id);
- n = agnode(g, Tcl_GetStringResult(interp));
- *np = n;
- AGID(n) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), nodecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), nodecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
-#endif
i = 2;
}
-#ifndef WITH_CGRAPH
- np = (Agnode_t **)tclhandleXlateIndex(ictx->nodeTblPtr, AGID(n));
- *np = n;
-#else
Tcl_AppendResult(interp, obj2cmd(n), NULL);
-#endif
setnodeattributes(agroot(g), n, &argv[i], argc - i);
reset_layout(gvc, g);
return TCL_OK;
}
if (argc % 2) {
/* if odd number of args then argv[2] is name */
-#ifdef WITH_CGRAPH
sg = agsubg(g, argv[2], 1);
Tcl_AppendResult(interp, obj2cmd(sg), NULL);
-#else
- sg = agsubg(g, argv[2]);
- if (! (sgp = (Agraph_t **) tclhandleXlateIndex(ictx->graphTblPtr, AGID(sg))) || *sgp != sg) {
- sgp = (Agraph_t **) tclhandleAlloc(ictx->graphTblPtr, Tcl_GetStringResult(interp), &id);
- *sgp = sg;
- AGID(sg) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif
- } else {
- tclhandleString(ictx->graphTblPtr, Tcl_GetStringResult(interp), AGID(sg));
- }
-#endif
i = 3;
} else {
-#ifdef WITH_CGRAPH
sg = agsubg(g, NULL, 1); /* anon subgraph */
-#else
- /* else use handle as name */
- sgp = (Agraph_t **) tclhandleAlloc(ictx->graphTblPtr, Tcl_GetStringResult(interp), &id);
- sg = agsubg(g, Tcl_GetStringResult(interp));
- *sgp = sg;
- AGID(sg) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif
-#endif
i = 2;
}
-#ifndef WITH_CGRAPH
- sgp = (Agraph_t **)tclhandleXlateIndex(ictx->graphTblPtr, AGID(sg));
- *sgp = sg;
-#endif
setgraphattributes(sg, &argv[i], argc - i);
reset_layout(gvc, g);
return TCL_OK;
} else if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
reset_layout(gvc, g);
-#ifndef WITH_CGRAPH
- deleteGraph(ictx, g);
-#else
deleteGraph(gctx, g);
-#endif
return TCL_OK;
} else if ((c == 'f') && (strncmp(argv[1], "findedge", length) == 0)) {
Tcl_AppendResult(interp, "Edge \"", argv[2], " - ", argv[3], "\" not found.", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(e));
-#endif
return TCL_OK;
} else if ((c == 'f') && (strncmp(argv[1], "findnode", length) == 0)) {
Tcl_AppendResult(interp, "Node not found.", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
- Tcl_AppendResult(interp, buf, NULL);
-#else
Tcl_AppendResult(interp, obj2cmd(n), NULL);
-#endif
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "layoutedges", length) == 0)) {
g = agroot(g);
-#ifndef WITH_CGRAPH
- if (!GD_drawing(g))
-#else
if (!aggetrec (g, "Agraphinfo_t",0))
-#endif
tcldot_layout(gvc, g, (argc > 2) ? argv[2] : NULL);
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "layoutnodes", length) == 0)) {
g = agroot(g);
-#ifndef WITH_CGRAPH
- if (!GD_drawing(g))
-#else
if (!aggetrec (g, "Agraphinfo_t",0))
-#endif
tcldot_layout(gvc, g, (argc > 2) ? argv[2] : NULL);
return TCL_OK;
} else if ((c == 'l') && (strncmp(argv[1], "listedges", length) == 0)) {
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(e));
-#endif
}
}
return TCL_OK;
} else if ((c == 'l') && (strncmp(argv[1], "listnodes", length) == 0)) {
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(n));
-#endif
}
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listnodesrev", length) == 0)) {
for (n = aglstnode(g); n; n = agprvnode(g, n)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(n));
-#endif
}
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listsubgraphs", length) == 0)) {
-#ifdef WITH_CGRAPH
for (sg = agfstsubg(g); sg; sg = agnxtsubg(sg)) {
Tcl_AppendElement(interp, obj2cmd(g));
}
-#else
- if (g->meta_node) {
- for (e = agfstout(g->meta_node->graph, g->meta_node); e;
- e = agnxtout(g->meta_node->graph, e)) {
- sg = agusergraph(aghead(e));
- tclhandleString(ictx->graphTblPtr, buf, AGID(sg));
- Tcl_AppendElement(interp, buf);
- }
- }
-#endif
return TCL_OK;
} else if ((c == 'q')
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindgraphattr(g, argv2[j]))) {
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(g, a->index));
-#else
Tcl_AppendElement(interp, agxget(g, a));
-#endif
} else {
Tcl_AppendResult(interp, " No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindgraphattr(g, argv2[j]))) {
Tcl_AppendElement(interp, argv2[j]);
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(g, a->index));
-#else
Tcl_AppendElement(interp, agxget(g, a));
-#endif
} else {
Tcl_AppendResult(interp, " No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindedgeattr(g, argv2[j]))) {
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(g->proto->e, a->index));
-#else
Tcl_AppendElement(interp, agxget(g, a));
-#endif
} else {
Tcl_AppendResult(interp, " No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindedgeattr(g, argv2[j]))) {
Tcl_AppendElement(interp, argv2[j]);
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(g->proto->e, a->index));
-#else
Tcl_AppendElement(interp, agxget(g, a));
-#endif
} else {
Tcl_AppendResult(interp, " No attribute named \"",
argv2[j], "\"", NULL);
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindnodeattr(g, argv2[j]))) {
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(g->proto->n, a->index));
-#else
Tcl_AppendElement(interp, agxget(g, a));
-#endif
} else {
Tcl_AppendResult(interp, " No attribute named \"",
argv2[j], "\"", NULL);
for (j = 0; j < argc2; j++) {
if ((a = agfindnodeattr(g, argv2[j]))) {
Tcl_AppendElement(interp, argv2[j]);
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(g->proto->n, a->index));
-#else
Tcl_AppendElement(interp, agxget(g, a));
-#endif
} else {
Tcl_AppendResult(interp, " No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
/* make sure that layout is done */
g = agroot(g);
-#ifndef WITH_CGRAPH
- if (!GD_drawing(g) || argc > 3)
-#else
if (!aggetrec (g, "Agraphinfo_t",0) || argc > 3)
-#endif
tcldot_layout (gvc, g, (argc > 3) ? argv[3] : NULL);
/* render graph TK canvas commands */
/* make sure that layout is done */
g = agroot(g);
-#ifndef WITH_CGRAPH
- if (!GD_drawing(g) || argc > 4)
-#else
if (!aggetrec (g, "Agraphinfo_t",0) || argc > 4)
-#endif
tcldot_layout(gvc, g, (argc > 4) ? argv[4] : NULL);
gvc->common.viewNum = 0;
Tcl_Free((char *) argv2);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- setedgeattributes(g, g->proto->e, argv2, argc2);
-#else
setedgeattributes(g, NULL, argv2, argc2);
-#endif
Tcl_Free((char *) argv2);
} else {
if ((argc < 4) || (argc % 2)) {
"\" setedgeattributes attributename attributevalue ?attributename attributevalue? ?...?",
NULL);
}
-#ifndef WITH_CGRAPH
- setedgeattributes(g, g->proto->e, &argv[2], argc - 2);
-#else
setedgeattributes(g, NULL, &argv[2], argc - 2);
-#endif
}
reset_layout(gvc, g);
return TCL_OK;
Tcl_Free((char *) argv2);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- setnodeattributes(g, g->proto->n, argv2, argc2);
-#else
setnodeattributes(g, NULL, argv2, argc2);
-#endif
Tcl_Free((char *) argv2);
} else {
if ((argc < 4) || (argc % 2)) {
"\" setnodeattributes attributename attributevalue ?attributename attributevalue? ?...?",
NULL);
}
-#ifndef WITH_CGRAPH
- setnodeattributes(g, g->proto->n, &argv[2], argc - 2);
-#else
setnodeattributes(g, NULL, &argv[2], argc - 2);
-#endif
}
reset_layout(gvc, g);
return TCL_OK;
job->output_filename = NULL;
/* make sure that layout is done - unless canonical output */
-#ifndef WITH_CGRAPH
- if ((!GD_drawing(g) || argc > 4) && !(job->flags & LAYOUT_NOT_REQUIRED))
-#else
if ((!aggetrec (g, "Agraphinfo_t",0) || argc > 4) && !(job->flags & LAYOUT_NOT_REQUIRED))
-#endif
tcldot_layout(gvc, g, (argc > 4) ? argv[4] : NULL);
gvc->common.viewNum = 0;
#include "tcldot.h"
-#ifdef WITH_CGRAPH
-
// Agiddisc functions
static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
ictx_t *ictx = (ictx_t *)disc;
myiddisc_close,
myiddisc_idregister
};
-#endif
#include "tcldot.h"
-#ifdef WITH_CGRAPH
/*
* myiodisc_afread - same api as read for libcgraph
*
return l;
}
-#else
-/*
- * mygets - same api as gets
- *
- * gets one line at a time from a Tcl_Channel and places it in a user buffer
- * up to a maximum of n characters
- *
- * returns pointer to obtained line in user buffer, or
- * returns NULL when last line read from memory buffer
- *
- * This is probably innefficient because it introduces
- * one more stage of line buffering during reads (at least)
- * but it is needed so that we can take full advantage
- * of the Tcl_Channel mechanism.
- */
-
-char *mygets(char *ubuf, int n, FILE * channel)
-{
- static Tcl_DString dstr;
- static int strpos;
-
- if (!n) { /* a call with n==0 (from aglexinit) resets */
- *ubuf = '\0';
- strpos = 0;
- return NULL;
- }
-
- /*
- * the user buffer might not be big enough to hold the line.
- */
- if (strpos) {
- if (Tcl_DStringLength(&dstr) > (n + strpos)) {
- /* chunk between first and last */
- strncpy(ubuf, (strpos + Tcl_DStringValue(&dstr)), n - 1);
- strpos += (n - 1);
- ubuf[n] = '\0';
- } else {
- /* last chunk */
- strcpy(ubuf, (strpos + Tcl_DStringValue(&dstr)));
- strpos = 0;
- }
- } else {
- Tcl_DStringFree(&dstr);
- Tcl_DStringInit(&dstr);
- if (Tcl_Gets((Tcl_Channel) channel, &dstr) < 0) {
- /* probably EOF, but could be other read errors */
- *ubuf = '\0';
- return NULL;
- }
- /* linend char(s) were stripped off by Tcl_Gets,
- * append a canonical linenend. */
- Tcl_DStringAppend(&dstr, "\n", 1);
- if (Tcl_DStringLength(&dstr) >= n) {
- /* first chunk */
- strncpy(ubuf, Tcl_DStringValue(&dstr), n - 1);
- strpos = n - 1;
- ubuf[n] = '\0';
- } else {
- /* single chunk */
- strcpy(ubuf, Tcl_DStringValue(&dstr));
- }
- }
- return ubuf;
-
-#if 0
- if (!n) { /* a call with n==0 (from aglexinit) resets */
- mempos = (char *) mbuf; /* cast from FILE* required by API */
- }
-
- clp = to = ubuf;
- for (i = 0; i < n - 1; i++) { /* leave room for terminator */
- if (*mempos == '\0') {
- if (i) { /* if mbuf doesn't end in \n, provide one */
- *to++ = '\n';
- } else { /* all done */
- clp = NULL;
- mempos = NULL;
- }
- break; /* last line or end-of-buffer */
- }
- if (*mempos == '\n') {
- *to++ = *mempos++;
- break; /* all done with this line */
- }
- *to++ = *mempos++; /* copy character */
- }
- *to++ = '\0'; /* place terminator in ubuf */
- return clp;
-#endif
-}
-#endif /* WITH_CGRAPH */
-
#if 0
Agraph_t *agread_usergets (ictx_t *ictx, FILE * fp, int (*usergets)(void *chan, char *buf, int bufsize))
{
Agnode_t *n, *head;
Agedge_t *e;
Agsym_t *a;
-#ifndef WITH_CGRAPH
- char buf[32];
- unsigned long id;
- Agnode_t **np;
- Agedge_t **ep;
- ictx_t *ictx = (ictx_t *)clientData;
-#else
gctx_t *gctx = (gctx_t *)clientData;
ictx_t *ictx = gctx->ictx;
-#endif
GVC_t *gvc = ictx->gvc;
if (argc < 2) {
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " option ?arg arg ...?\"", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- if (!(np = (Agnode_t **) tclhandleXlate(ictx->nodeTblPtr, argv[0]))) {
- Tcl_AppendResult(interp, "Node \"", argv[0], "\" not found", NULL);
- return TCL_ERROR;
- }
- n = *np;
-#else
n = cmd2n(argv[0]);
if (!n) {
Tcl_AppendResult(interp, "Node \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
}
-#endif
g = agraphof(n);
c = argv[1][0];
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " addedge head ?attributename attributevalue? ?...?\"", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- if (!(np = (Agnode_t **) tclhandleXlate(ictx->nodeTblPtr, argv[2]))) {
- if (!(head = agfindnode(g, argv[2]))) {
- Tcl_AppendResult(interp, "Head node \"", argv[2], "\" not found.", NULL);
- return TCL_ERROR;
- }
- } else {
- head = *np;
- }
-#else
head = cmd2n(argv[2]);
if (!head) {
if (!(head = agfindnode(g, argv[2]))) {
return TCL_ERROR;
}
}
-#endif
if (agroot(g) != agroot(agraphof(head))) {
Tcl_AppendResult(interp, "Nodes ", argv[0], " and ", argv[2], " are not in the same graph.", NULL);
return TCL_ERROR;
}
-#ifdef WITH_CGRAPH
- e = agedge(g, n, head, NULL, 1);
+ e = agedge(g, n, head, NULL, 1);
Tcl_AppendResult(interp, obj2cmd(e), NULL);
-#else
- e = agedge(g, n, head);
- if (!(ep = (Agedge_t **) tclhandleXlateIndex(ictx->edgeTblPtr, AGID(e))) || *ep != e) {
- ep = (Agedge_t **) tclhandleAlloc(ictx->edgeTblPtr, Tcl_GetStringResult(interp), &id);
- *ep = e;
- AGID(e) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), edgecmd,
- (ClientData) ictx,
- (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), edgecmd,
- (ClientData) ictx,
- (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- } else {
- tclhandleString(ictx->edgeTblPtr, Tcl_GetStringResult(interp), AGID(e));
- }
-#endif
setedgeattributes(agroot(g), e, &argv[3], argc - 3);
reset_layout(gvc, g);
return TCL_OK;
} else if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
-#ifndef WITH_CGRAPH
- deleteNode(ictx, g, n);
-#else
deleteNode(gctx, g, n);
-#endif
reset_layout(gvc, g);
return TCL_OK;
return TCL_ERROR;
}
if (!(e = agfindedge(g, n, head))) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->nodeTblPtr, buf, AGID(head));
- Tcl_AppendResult(interp, "Edge \"", argv[0], " - ", buf, "\" not found.", NULL);
-#else
Tcl_AppendResult(interp, "Edge \"", argv[0], " - ", obj2cmd(head), "\" not found.", NULL);
-#endif
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(head));
-#endif
return TCL_OK;
} else if ((c == 'l')
} else if ((c == 'l') && (strncmp(argv[1], "listedges", length) == 0)) {
for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(e));
-#endif
}
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listinedges", length) == 0)) {
for (e = agfstin(g, n); e; e = agnxtin(g, e)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(e));
-#endif
}
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listoutedges", length) == 0)) {
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
-#ifndef WITH_CGRAPH
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_AppendElement(interp, buf);
-#else
Tcl_AppendElement(interp, obj2cmd(e));
-#endif
}
return TCL_OK;
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindnodeattr(g, argv2[j]))) {
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(n, a->index));
-#else
Tcl_AppendElement(interp, agxget(n, a));
-#endif
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
for (j = 0; j < argc2; j++) {
if ((a = agfindnodeattr(g, argv2[j]))) {
Tcl_AppendElement(interp, argv2[j]);
-#ifndef WITH_CGRAPH
- Tcl_AppendElement(interp, agxget(n, a->index));
-#else
Tcl_AppendElement(interp, agxget(n, a));
-#endif
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
return Tcl_Write((Tcl_Channel)(job->output_file), s, len);
}
-void reset_layout(GVC_t *gvc, Agraph_t * sg)
-{
-#ifndef WITH_CGRAPH
- Agraph_t *g = agroot(sg);
-
- if (GD_drawing(g)) { /* only cleanup once between layouts */
- gvFreeLayout(gvc, g);
- GD_drawing(g) = NULL;
- }
-#endif
-}
-
-#ifdef WITH_CGRAPH
/* handles (tcl commands) to obj* */
Agraph_t *cmd2g(char *cmd) {
return buf;
}
-#endif // WITH_CGRAPH
-#ifdef WITH_CGRAPH
void deleteEdge(gctx_t *gctx, Agraph_t * g, Agedge_t *e)
{
char *hndl;
}
Tcl_DeleteCommand(gctx->ictx->interp, hndl);
}
-#else
-void deleteEdge(ictx_t * ictx, Agraph_t * g, Agedge_t *e)
-{
- Agedge_t **ep;
- char buf[32];
-
- tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
- Tcl_DeleteCommand(ictx->interp, buf);
- ep = (Agedge_t **) tclhandleXlateIndex(ictx->edgeTblPtr, AGID(e));
- if (!ep)
- fprintf(stderr, "Bad entry in edgeTbl\n");
- tclhandleFreeIndex(ictx->edgeTblPtr, AGID(e));
- agdelete(agroot(g), e);
-}
-static void deleteNodeEdges(ictx_t * ictx, Agraph_t * g, Agnode_t * n)
-{
- Agedge_t *e, *e1;
-
- e = agfstedge(g, n);
- while (e) {
- e1 = agnxtedge(g, e, n);
- deleteEdge(ictx, g, e);
- e = e1;
- }
-}
-void deleteNode(ictx_t * ictx, Agraph_t * g, Agnode_t *n)
-{
- Agnode_t **np;
- char buf[32];
-
- deleteNodeEdges(ictx, agroot(g), n);
- tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
- Tcl_DeleteCommand(ictx->interp, buf);
- np = (Agnode_t **) tclhandleXlateIndex(ictx->nodeTblPtr, AGID(n));
- if (!np)
- fprintf(stderr, "Bad entry in nodeTbl\n");
- tclhandleFreeIndex(ictx->nodeTblPtr, AGID(n));
- agdelete(agroot(g), n);
-}
-static void deleteGraphNodes(ictx_t * ictx, Agraph_t * g)
-{
- Agnode_t *n, *n1;
-
- n = agfstnode(g);
- while (n) {
- n1 = agnxtnode(g, n);
- deleteNode(ictx, g, n);
- n = n1;
- }
-}
-void deleteGraph(ictx_t * ictx, Agraph_t * g)
-{
- Agraph_t **sgp;
- Agedge_t *e;
- char buf[32];
-
- if (g->meta_node) {
- for (e = agfstout(g->meta_node->graph, g->meta_node); e;
- e = agnxtout(g->meta_node->graph, e)) {
- deleteGraph(ictx, agusergraph(aghead(e)));
- }
- tclhandleString(ictx->graphTblPtr, buf, AGID(g));
- Tcl_DeleteCommand(ictx->interp, buf);
- sgp = (Agraph_t **) tclhandleXlateIndex(ictx->graphTblPtr, AGID(g));
- if (!sgp)
- fprintf(stderr, "Bad entry in graphTbl\n");
- tclhandleFreeIndex(ictx->graphTblPtr, AGID(g));
- deleteGraphNodes(ictx, g);
- if (g == agroot(g)) {
- agclose(g);
- } else {
- agdelete(g->meta_node->graph, g->meta_node);
- }
- } else {
- fprintf(stderr, "Subgraph has no meta_node\n");
- }
-}
-#endif
void setgraphattributes(Agraph_t * g, char *argv[], int argc)
{
Agsym_t *a;
for (i = 0; i < argc; i++) {
-#ifndef WITH_CGRAPH
- if (!(a = agfindgraphattr(agroot(g), argv[i])))
- a = agraphattr(agroot(g), argv[i], "");
- agxset(g, a->index, argv[++i]);
-#else
if (!(a = agfindgraphattr(agroot(g), argv[i])))
a = agattr(agroot(g), AGRAPH, argv[i], "");
agxset(g, a, argv[++i]);
-#endif
}
}
i++;
continue;
}
-#ifndef WITH_CGRAPH
- if (!(a = agfindedgeattr(g, argv[i])))
- a = agedgeattr(agroot(g), argv[i], "");
- agxset(e, a->index, argv[++i]);
-#else
if (e) {
if (!(a = agfindedgeattr(g, argv[i])))
a = agattr(agroot(g), AGEDGE, argv[i], "");
agattr(g, AGEDGE, argv[i], argv[i+1]);
i++;
}
-#endif
}
}
Agsym_t *a;
for (i = 0; i < argc; i++) {
-#ifndef WITH_CGRAPH
- if (!(a = agfindnodeattr(g, argv[i])))
- a = agnodeattr(agroot(g), argv[i], "");
- agxset(n, a->index, argv[++i]);
-#else
if (n) {
if (!(a = agfindnodeattr(g, argv[i])))
a = agattr(agroot(g), AGNODE, argv[i], "");
agattr(g, AGNODE, argv[i], argv[i+1]);
i++;
}
-#endif
}
}
-#ifdef WITH_CGRAPH
void listGraphAttrs (Tcl_Interp * interp, Agraph_t* g)
{
Agsym_t *a = NULL;
Tcl_AppendElement(interp, a->name);
}
}
-#else
-void listGraphAttrs (Tcl_Interp * interp, Agraph_t* g)
-{
- int i;
- Agsym_t *a;
-
- for (i = 0; i < dtsize(g->univ->globattr->dict); i++) {
- a = g->univ->globattr->list[i];
- Tcl_AppendElement(interp, a->name);
- }
-}
-void listNodeAttrs (Tcl_Interp * interp, Agraph_t* g)
-{
- int i;
- Agsym_t *a;
-
- for (i = 0; i < dtsize(g->univ->nodeattr->dict); i++) {
- a = g->univ->nodeattr->list[i];
- Tcl_AppendElement(interp, a->name);
- }
-}
-void listEdgeAttrs (Tcl_Interp * interp, Agraph_t* g)
-{
- int i;
- Agsym_t *a;
-
- for (i = 0; i < dtsize(g->univ->edgeattr->dict); i++) {
- a = g->univ->edgeattr->list[i];
- Tcl_AppendElement(interp, a->name);
- }
-}
-#endif
void tcldot_layout(GVC_t *gvc, Agraph_t * g, char *engine)
{
Agsym_t *a;
int rc;
-#ifndef WITH_CGRAPH
- reset_layout(gvc, g); /* in case previously drawn */
-#else
gvFreeLayout(gvc, g); /* in case previously drawn */
-#endif
/* support old behaviors if engine isn't specified*/
if (!engine || *engine == '\0') {
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));
-#ifndef WITH_CGRAPH
- if (!(a = agfindgraphattr(g, "bb")))
- a = agraphattr(g, "bb", "");
- agxset(g, a->index, buf);
-#else
if (!(a = agattr(g, AGRAPH, "bb", NULL)))
a = agattr(g, AGRAPH, "bb", "");
agxset(g, a, buf);
-#endif
}
Agraph_t *g;
char c;
int i, length;
-#ifndef WITH_CGRAPH
- Agraph_t **gp;
- int kind;
- unsigned long id;
-#else
Agdesc_t kind;
-#endif
if ((argc < 2)) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
c = argv[1][0];
length = strlen(argv[1]);
if ((c == 'd') && (strncmp(argv[1], "digraph", length) == 0)) {
-#ifndef WITH_CGRAPH
- kind = AGDIGRAPH;
-#else
kind = Agdirected;
-#endif
} else if ((c == 'd')
&& (strncmp(argv[1], "digraphstrict", length) == 0)) {
-#ifndef WITH_CGRAPH
- kind = AGDIGRAPHSTRICT;
-#else
kind = Agstrictdirected;
-#endif
} else if ((c == 'g') && (strncmp(argv[1], "graph", length) == 0)) {
-#ifndef WITH_CGRAPH
- kind = AGRAPH;
-#else
kind = Agundirected;
-#endif
} else if ((c == 'g')
&& (strncmp(argv[1], "graphstrict", length) == 0)) {
-#ifndef WITH_CGRAPH
- kind = AGRAPHSTRICT;
-#else
kind = Agstrictundirected;
-#endif
} else {
Tcl_AppendResult(interp, "bad graphtype \"", argv[1], "\": must be one of:",
"\n\tdigraph, digraphstrict, graph, graphstrict.", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- gp = (Agraph_t **) tclhandleAlloc(ictx->graphTblPtr, Tcl_GetStringResult(interp), &id);
-#endif
if (argc % 2) {
/* if odd number of args then argv[2] is name */
-#ifndef WITH_CGRAPH
- g = agopen(argv[2], kind);
-#else
g = agopen(argv[2], kind, (Agdisc_t*)ictx);
-#endif
i = 3;
} else {
/* else use handle as name */
-#ifndef WITH_CGRAPH
- g = agopen(Tcl_GetStringResult(interp), kind);
-#else
g = agopen(Tcl_GetStringResult(interp), kind, (Agdisc_t*)ictx);
-#endif
i = 2;
}
if (!g) {
Tcl_AppendResult(interp, "\nFailure to open graph.", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- *gp = g;
- AGID(g) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
-#endif
setgraphattributes(g, &argv[i], argc - i);
-
-#ifndef WITH_CGRAPH
- /* we use GD_drawing(g) as a flag that layout has been done.
- * so we make sure that it is initialized to "not done" */
- GD_drawing(g) = NULL;
-#else
Tcl_AppendResult(interp, obj2cmd(g), NULL);
-#endif
return TCL_OK;
}
-#ifndef WITH_CGRAPH
-/*
- * when a graph is read in from a file or string we need to walk
- * it to create the handles and tcl commands for each
- * graph, subgraph, node, and edge.
- */
-static int tcldot_fixup(ictx_t *ictx, graph_t * g)
-{
- Agraph_t **gp, *sg, **sgp;
- Agnode_t *n, **np;
- Agedge_t *e, **ep;
- char buf[32];
- unsigned long id;
- Tcl_Interp *interp = ictx->interp;
-
- if (g->meta_node) {
- for (n = agfstnode(g->meta_node->graph); n;
- n = agnxtnode(g->meta_node->graph, n)) {
- sg = agusergraph(n);
- sgp = (Agraph_t **) tclhandleAlloc(ictx->graphTblPtr, buf, &id);
- *sgp = sg;
- AGID(sg) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, buf, graphcmd, (ClientData) ictx,
- (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, buf, graphcmd, (ClientData) ictx,
- (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- if (sg == g)
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- } else {
- gp = (Agraph_t **) tclhandleAlloc(ictx->graphTblPtr, Tcl_GetStringResult(interp), &id);
- *gp = g;
- AGID(g) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), graphcmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- }
- for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
- np = (Agnode_t **) tclhandleAlloc(ictx->nodeTblPtr, buf, &id);
- *np = n;
- AGID(n) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, buf, nodecmd,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, buf, nodecmd,
- (ClientData) gvc, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
- ep = (Agedge_t **) tclhandleAlloc(ictx->edgeTblPtr, buf, &id);
- *ep = e;
- AGID(e) = id;
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, buf, edgecmd, (ClientData) ictx,
- (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
- Tcl_CreateObjCommand(interp, buf, edgecmd, (ClientData) gvc,
- (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
- }
- }
- return TCL_OK;
-}
-
-#endif /* WITH_CGRAPH */
-
static int dotread(ClientData clientData, Tcl_Interp * interp,
#ifndef TCLOBJ
int argc, char *argv[]
Agraph_t *g;
Tcl_Channel channel;
int mode;
-#ifdef WITH_CGRAPH
ictx_t *ictx = (ictx_t *)clientData;
ictx->myioDisc.afread = myiodisc_afread; /* replace afread to use Tcl Channels */
-#endif
if (argc < 2) {
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " fileHandle\"", NULL);
* a properly parsed graph. If the graph doesn't parse
* during reading then the channel will be left at EOF
*/
-#ifndef WITH_CGRAPH
- g = agread_usergets((FILE *) channel, (mygets));
-#else
g = agread ((FILE*)channel, (Agdisc_t *)clientData);
-#endif
if (!g) {
Tcl_AppendResult(interp, "\nFailure to read graph \"", argv[1], "\"", NULL);
if (agerrors()) {
Tcl_AppendResult(interp, "\nSyntax errors in file \"", argv[1], " \"", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- /* we use GD_drawing(g) as a flag that layout has been done.
- * so we make sure that it is initialized to "not done" */
- GD_drawing(g) = NULL;
- return (tcldot_fixup((ictx_t *)clientData, g));
-#else
Tcl_AppendResult(interp, obj2cmd(g), NULL);
return TCL_OK;
-#endif
}
static int dotstring(ClientData clientData, Tcl_Interp * interp,
)
{
Agraph_t *g;
-#ifdef WITH_CGRAPH
ictx_t *ictx = (ictx_t *)clientData;
rdr_t rdr;
rdr.data = argv[1];
rdr.len = strlen(rdr.data);
rdr.cur = 0;
-#endif
if (argc < 2) {
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " string\"", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- g = agmemread(argv[1]);
-#else
/* agmemread() is broken for our use because it replaces the id disc */
g = agread(&rdr, (Agdisc_t *)clientData);
-#endif
if (!g) {
Tcl_AppendResult(interp, "\nFailure to read string \"", argv[1], "\"", NULL);
if (agerrors()) {
Tcl_AppendResult(interp, "\nSyntax errors in string \"", argv[1], " \"", NULL);
return TCL_ERROR;
}
-#ifndef WITH_CGRAPH
- /* we use GD_drawing(g) as a flag that layout has been done.
- * so we make sure that it is initialized to "not done" */
- GD_drawing(g) = NULL;
- return (tcldot_fixup((ictx_t *)clientData, g));
-#else
Tcl_AppendResult(interp, obj2cmd(g), NULL);
return TCL_OK;
-#endif
}
#if defined(_BLD_tcldot) && defined(_DLL)
return TCL_ERROR;
ictx->interp = interp;
-#ifdef WITH_CGRAPH
/* build disciplines dynamically so we can selectively replace functions */
ictx->myioDisc.afread = NULL; /* set in dotread() or dotstring() according to need */
ictx->mydisc.io = &(ictx->myioDisc); /* change parts */
ictx->ctr = 1; /* init to first odd number, increment by 2 */
-#endif
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
Gdtclft_Init(interp);
#endif
-#ifdef WITH_CGRAPH
/* set persistent attributes here */
agattr(NULL, AGNODE, "label", NODENAME_ESC);
-#else
- aginit();
- agsetiodisc(NULL, gvfwrite, gvferror);
- /* set persistent attributes here */
- agnodeattr(NULL, "label", NODENAME_ESC);
-#endif
/* create a GraphViz Context and pass a pointer to it in clientdata */
gvc = gvNEWcontext(lt_preloaded_symbols, DEMAND_LOADING);
/* configure for available plugins */
gvconfig(gvc, FALSE);
-#ifndef TCLOBJ
- Tcl_CreateCommand(interp, "dotnew", dotnew,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
- Tcl_CreateCommand(interp, "dotread", dotread,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
- Tcl_CreateCommand(interp, "dotstring", dotstring,
- (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#else /* TCLOBJ */
Tcl_CreateObjCommand(interp, "dotnew", dotnew,
(ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "dotread", dotread,
(ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateObjCommand(interp, "dotstring", dotstring,
(ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
-#endif /* TCLOBJ */
-
-#ifndef WITH_CGRAPH
- ictx->graphTblPtr = (void *) tclhandleInit("graph", sizeof(Agraph_t *), 10);
- ictx->nodeTblPtr = (void *) tclhandleInit("node", sizeof(Agnode_t *), 100);
- ictx->edgeTblPtr = (void *) tclhandleInit("edge", sizeof(Agedge_t *), 100);
-#endif
return TCL_OK;
}
* ictx - one per tcl interpreter, may support multiple graph namespaces
*/
typedef struct {
-#ifdef WITH_CGRAPH
Agdisc_t mydisc; /* must be first to allow casting mydisc to ictx */
Agiodisc_t myioDisc;
unsigned long ctr; /* odd number counter for anon objects over all g's in interp */
-#else
- void *graphTblPtr, *nodeTblPtr, *edgeTblPtr;
-#endif
Tcl_Interp *interp;
GVC_t *gvc;
} ictx_t;
-#ifdef WITH_CGRAPH
/*
* gctx - one for each graph in a tcl interp
*/
ictx_t *ictx;
unsigned long idx;
} gctx_t;
-#endif
#if HAVE_LIBGD
extern void *GDHandleTable;
extern int Gdtclft_Init(Tcl_Interp *);
#endif
-#ifndef WITH_CGRAPH
-#undef AGID
-#define AGID(x) ((x)->handle)
-#endif
-
extern int graphcmd(ClientData clientData, Tcl_Interp * interp,
#ifndef TCLOBJ
int argc, char *argv[]
#endif
);
-#ifdef WITH_CGRAPH
/* rdr_t isn't exposed by cgraph/io.c */
typedef struct {
const char *data;
extern void listGraphAttrs (Tcl_Interp * interp, Agraph_t* g);
extern void listNodeAttrs (Tcl_Interp * interp, Agraph_t* g);
extern void listEdgeAttrs (Tcl_Interp * interp, Agraph_t* g);
-#else
-extern void deleteEdge(ictx_t * ictx, Agraph_t * g, Agedge_t * e);
-extern void deleteNode(ictx_t * ictx, Agraph_t * g, Agnode_t * n);
-extern void deleteGraph(ictx_t * ictx, Agraph_t * g);
-extern void listGraphAttrs (Tcl_Interp * interp, Agraph_t* g);
-extern void listNodeAttrs (Tcl_Interp * interp, Agraph_t* g);
-extern void listEdgeAttrs (Tcl_Interp * interp, Agraph_t* g);
-extern char *mygets(char *ubuf, int n, FILE * channel);
-#endif
extern void setgraphattributes(Agraph_t * g, char *argv[], int argc);
extern void setedgeattributes(Agraph_t * g, Agedge_t * e, char *argv[], int argc);
extern void tcldot_layout(GVC_t *gvc, Agraph_t * g, char *engine);
extern void reset_layout(GVC_t *gvc, Agraph_t * sg);
-
-