]> granicus.if.org Git - graphviz/commitdiff
mostly working checkpoint
authorJohn Ellson <ellson@research.att.com>
Tue, 14 Aug 2012 17:55:59 +0000 (13:55 -0400)
committerJohn Ellson <ellson@research.att.com>
Tue, 14 Aug 2012 17:55:59 +0000 (13:55 -0400)
tclpkg/tcldot/Makefile.am
tclpkg/tcldot/tcldot-edgecmd.c
tclpkg/tcldot/tcldot-graphcmd.c
tclpkg/tcldot/tcldot-id.c [new file with mode: 0644]
tclpkg/tcldot/tcldot-io.c [moved from tclpkg/tcldot/tcldot-mygets.c with 91% similarity]
tclpkg/tcldot/tcldot-mem.c [new file with mode: 0644]
tclpkg/tcldot/tcldot-nodecmd.c
tclpkg/tcldot/tcldot-util.c
tclpkg/tcldot/tcldot.c
tclpkg/tcldot/tcldot.h

index b282a6407c42d271a8e7488f56d3ea0733aa995e..9a855bdbc9a7164585db4d80a0a77d5ff434d61a 100644 (file)
@@ -9,6 +9,10 @@ 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
+
 pdfdir = $(pkgdatadir)/doc/pdf
 htmldir = $(pkgdatadir)/doc/html
 
@@ -20,8 +24,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/common \
        -I$(top_srcdir)/lib/$(GRAPH) \
        -I$(top_srcdir)/lib/cdt \
-       -I$(top_srcdir)/lib/pathplan \
-       -I$(top_srcdir)/tclpkg/tclhandle $(GD_INCLUDES) $(TCL_INCLUDES)
+       -I$(top_srcdir)/lib/pathplan $(TCLHANDLE_INCLUDES) $(GD_INCLUDES) $(TCL_INCLUDES)
 
 LIBS = -lc
 
@@ -49,12 +52,14 @@ libtcldot_la_SOURCES = \
        tcldot-nodecmd.c \
        tcldot-edgecmd.c \
        tcldot-util.c \
-       tcldot-mygets.c \
+       tcldot-id.c \
+       tcldot-io.c \
+       tcldot-mem.c \
        no_builtins.c $(GDTCLFT)
 libtcldot_la_CPPFLAGS = $(AM_CPPFLAGS) -DDEMAND_LOADING=1
 libtcldot_la_LDFLAGS = -no-undefined 
 
-libtcldot_la_LIBADD = $(top_builddir)/tclpkg/tclhandle/libtclhandle_C.la \
+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 \
@@ -76,13 +81,14 @@ libtcldot_builtin_la_SOURCES = \
        tcldot-nodecmd.c \
        tcldot-edgecmd.c \
        tcldot-util.c \
-       tcldot-mygets.c \
+       tcldot-id.c \
+       tcldot-io.c \
+       tcldot-mem.c \
        tcldot_builtins.c $(GDTCLFT)
 libtcldot_builtin_la_CPPFLAGS = $(AM_CPPFLAGS) -DDEMAND_LOADING=1
 libtcldot_builtin_la_LDFLAGS =
 
-libtcldot_builtin_la_LIBADD = \
-       $(top_builddir)/tclpkg/tclhandle/libtclhandle_C.la \
+libtcldot_builtin_la_LIBADD = $(TCLHANDLE_LIBS) \
        $(top_builddir)/plugin/dot_layout/libgvplugin_dot_layout_C.la \
        $(top_builddir)/plugin/neato_layout/libgvplugin_neato_layout_C.la \
        $(top_builddir)/plugin/core/libgvplugin_core_C.la \
index be56b52585dc9a7b71a4500cbf1ba3d66426cb0b..340004402d4697797b6c5d0213015076acfc9ab6 100644 (file)
@@ -21,25 +21,37 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
 #endif                         /* TCLOBJ */
     )
 {
-    char c, buf[16], *s, **argv2;
+    char c, buf[32], *s, **argv2;
     int i, j, length, argc2;
     Agraph_t *g;
-    Agedge_t **ep, *e;
+    Agedge_t *e;
     Agsym_t *a;
+#ifndef WITH_CGRAPH
+    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);
+       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, " \"", argv[0], "\"", NULL);
+       Tcl_AppendResult(interp, "Edge \"", argv[0], "\" not found", NULL);
        return TCL_ERROR;
     }
     e = *ep;
+#else
+    e = cmd2e(gctx,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];
@@ -47,10 +59,10 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
 
     if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
 #ifndef WITH_CGRAPH
-       tclhandleFreeIndex(ictx->edgeTblPtr, AGID(e));
-       Tcl_DeleteCommand(interp, argv[0]);
+       deleteEdge(ictx, g, e);
+#else
+       deleteEdge(gctx, g, e);
 #endif
-       agdelete(g, e);
        reset_layout(gvc, g);
        return TCL_OK;
 
@@ -60,9 +72,17 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
        return TCL_OK;
 
     } else if ((c == 'l') && (strncmp(argv[1], "listnodes", length) == 0)) {
+#ifndef WITH_CGRAPH
        tclhandleString(ictx->nodeTblPtr, buf, AGID(agtail(e)));
+#else
+       sprintf(buf,"node%p",agtail(e));
+#endif
        Tcl_AppendElement(interp, buf);
+#ifndef WITH_CGRAPH
        tclhandleString(ictx->nodeTblPtr, buf, AGID(aghead(e)));
+#else
+       sprintf(buf,"node%p",aghead(e));
+#endif
        Tcl_AppendElement(interp, buf);
        return TCL_OK;
 
@@ -81,8 +101,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
                    Tcl_AppendElement(interp, agxget(e, a));
 #endif
                } else {
-                   Tcl_AppendResult(interp, " No attribute named \"",
-                                    argv2[j], "\"", NULL);
+                   Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
                    return TCL_ERROR;
                }
            }
@@ -90,9 +109,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
        }
        return TCL_OK;
 
-    } else if ((c == 'q')
-              && (strncmp(argv[1], "queryattributevalues", length) ==
-                  0)) {
+    } else if ((c == 'q') && (strncmp(argv[1], "queryattributevalues", length) == 0)) {
        for (i = 2; i < argc; i++) {
            if (Tcl_SplitList
                (interp, argv[i], &argc2,
@@ -107,7 +124,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
                    Tcl_AppendElement(interp, agxget(e, a));
 #endif
                } else {
-                   Tcl_AppendResult(interp, " No attribute named \"", argv2[j], "\"", NULL);
+                   Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
                    return TCL_ERROR;
                }
            }
@@ -115,15 +132,14 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
        }
        return TCL_OK;
 
-    } else if ((c == 's')
-              && (strncmp(argv[1], "setattributes", length) == 0)) {
+    } else if ((c == 's') && (strncmp(argv[1], "setattributes", length) == 0)) {
        if (argc == 3) {
            if (Tcl_SplitList
                (interp, argv[2], &argc2,
                 (CONST84 char ***) &argv2) != TCL_OK)
                return TCL_ERROR;
            if ((argc2 == 0) || (argc2 % 2)) {
-               Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
+               Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
                                 "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
                                 NULL);
                Tcl_Free((char *) argv2);
@@ -133,8 +149,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
            Tcl_Free((char *) argv2);
        } else {
            if ((argc < 4) || (argc % 2)) {
-               Tcl_AppendResult(interp, "wrong # args: should be \"",
-                                argv[0],
+               Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
                                 "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
                                 NULL);
                return TCL_ERROR;
@@ -149,12 +164,11 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
            s = "->";
        else
            s = "--";
-       Tcl_AppendResult(interp,
-                        agnameof(agtail(e)), s, agnameof(aghead(e)), NULL);
+       Tcl_AppendResult(interp, agnameof(agtail(e)), s, agnameof(aghead(e)), NULL);
        return TCL_OK;
 
     } else {
-       Tcl_AppendResult(interp, "bad option \"", argv[1],
+       Tcl_AppendResult(interp, "Bad option \"", argv[1],
                         "\": must be one of:",
                         "\n\tdelete, listattributes, listnodes,",
                         "\n\tueryattributes, queryattributevalues,",
index e3b5e80230f1553f0af8de753ab594212bd34735..73b1cf421d0497c0ef3560aa626e05af98df596e 100644 (file)
 
 #include "tcldot.h"
 
-Agraph_t *cmd2g(gctx_t *gctx, char *cmd) {
-    Agraph_t *g = NULL;
-
-    if (sscanf(cmd, "graph%p", &g) != 1 || !g) {
-       Tcl_AppendResult(gctx->ictx->interp, " \"", cmd, "\" not found", NULL);
-       return NULL;
-    }
-    return g;
-}
-Agnode_t *cmd2n(gctx_t *gctx, char *cmd) {
-    Agnode_t *n = NULL;
-
-    if (sscanf(cmd, "node%p", &n) != 1 || !n) {
-       Tcl_AppendResult(gctx->ictx->interp, " \"", cmd, "\" not found", NULL);
-       return NULL;
-    }
-    return n;
-}
-Agedge_t *cmd2e(gctx_t *gctx, char *cmd) {
-    Agedge_t *e = NULL;
-
-    if (sscanf(cmd, "edge%p", &e) != 1 || !e) {
-       Tcl_AppendResult(gctx->ictx->interp, " \"", cmd, "\" not found", NULL);
-       return NULL;
-    }
-    return e;
-}
-
 int graphcmd(ClientData clientData, Tcl_Interp * interp,
 #ifndef TCLOBJ
                    int argc, char *argv[]
@@ -53,12 +25,9 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
     Agraph_t *g, *sg;
     Agnode_t *n, *tail, *head;
     Agedge_t *e;
-// FIXME #ifndef WITH_CGRAPH
-    Agraph_t **sgp;
-    Agnode_t **np;
-//       #endif
 #ifndef WITH_CGRAPH
-    Agraph_t **gp;
+    Agraph_t **gp, **sgp;
+    Agnode_t **np;
     Agedge_t **ep;
     ictx_t *ictx = (ictx_t *)clientData;
     unsigned long id;
@@ -73,21 +42,21 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
     GVJ_t *job = gvc->job;
 
     if (argc < 2) {
-       Tcl_AppendResult(interp, "wrong # args: should be \"",
-                        argv[0], " option ?arg arg ...?\"",
-                        NULL);
+       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, " \"", argv[0], "\"", NULL);
+       Tcl_AppendResult(interp, "Graph \"", argv[0], "\" not found", NULL);
        return TCL_ERROR;
     }
     g = *gp;
 #else
     g = cmd2g(gctx,argv[0]);
-    if (!g)
+    if (!g) {
+       Tcl_AppendResult(interp, "Graph \"", argv[0], "\" not found", NULL);
        return TCL_ERROR;
+    }
 #endif
 
     c = argv[1][0];
@@ -95,7 +64,7 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 
     if ((c == 'a') && (strncmp(argv[1], "addedge", length) == 0)) {
        if ((argc < 4) || (argc % 2)) {
-           Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
+           Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
                             " addedge tail head ?attributename attributevalue? ?...?\"",
                             NULL);
            return TCL_ERROR;
@@ -103,53 +72,53 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 #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);
+               Tcl_AppendResult(interp, "Tail node \"", argv[2], "\" not found.", NULL);
                return TCL_ERROR;
            }
         }
+       else {
+           tail = *np;
+       }
 #else
         tail = cmd2n(gctx,argv[2]);
         if (!tail) {
-           return TCL_ERROR;
-        }
-#endif
-       else {
-#ifndef WITH_CGRAPH
-           tail = *np;
-#endif
-           if (agroot(g) != agroot(agraphof(tail))) {
-               Tcl_AppendResult(interp, "Node ", argv[2],
-                                " is not in the graph.", NULL);
+           if (!(tail = agfindnode(g, argv[2]))) {
+               Tcl_AppendResult(interp, "Tail node \"", argv[2], "\" not found.", NULL);
                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);
+               Tcl_AppendResult(interp, "Head node \"", argv[3], "\" not found.", NULL);
                return TCL_ERROR;
            }
        }
+       else {
+           head = *np;
+       }
 #else
         head = cmd2n(gctx,argv[2]);
         if (!head) {
-           return TCL_ERROR;
-        }
-#endif
-       else {
-#ifndef WITH_CGRAPH
-           head = *np;
-#endif
-           if (agroot(g) != agroot(agraphof(head))) {
-               Tcl_AppendResult(interp, "Node ", argv[3],
-                                " is not in the graph.", NULL);
+           if (!(head = agfindnode(g, argv[3]))) {
+               Tcl_AppendResult(interp, "Head node \"", argv[3], "\" not found.", NULL);
                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;
        }
 #ifdef WITH_CGRAPH
        e = agedge(g, tail, head, NULL, 1);
+       sprintf(buf,"edge%p",e);
+       Tcl_AppendResult(interp, buf, NULL);
 #else
        e = agedge(g, tail, head);
 #endif
@@ -197,10 +166,10 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 #endif
            i = 3;
        } else {
-           /* else use handle as name */
 #ifdef WITH_CGRAPH
-           n = agnode(g, Tcl_GetStringResult(interp), 1);
+           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;
@@ -215,9 +184,12 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 #endif
            i = 2;
        }
-#ifdef WITH_CGRAPH
+#ifndef WITH_CGRAPH
        np = (Agnode_t **)tclhandleXlateIndex(ictx->nodeTblPtr, AGID(n));
        *np = n;
+#else
+       sprintf(buf,"node%p",n);
+       Tcl_AppendResult(interp, buf, NULL);
 #endif
        setnodeattributes(agroot(g), n, &argv[i], argc - i);
        reset_layout(gvc, g);
@@ -234,6 +206,8 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
            /* if odd number of args then argv[2] is name */
 #ifdef WITH_CGRAPH
            sg = agsubg(g, argv[2], 1);
+           sprintf(buf,"graph%p",sg);
+           Tcl_AppendResult(interp, buf, NULL);
 #else
            sg = agsubg(g, argv[2]);
            if (!  (sgp = (Agraph_t **) tclhandleXlateIndex(ictx->graphTblPtr, AGID(sg))) || *sgp != sg) {
@@ -253,10 +227,10 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 #endif
            i = 3;
        } else {
-           /* else use handle as name */
 #ifdef WITH_CGRAPH
-           sg = agsubg(g, Tcl_GetStringResult(interp), 1);
+           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;
@@ -271,7 +245,7 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 #endif
            i = 2;
        }
-#ifdef WITH_CGRAPH
+#ifndef WITH_CGRAPH
        sgp = (Agraph_t **)tclhandleXlateIndex(ictx->graphTblPtr, AGID(sg));
        *sgp = sg;
 #endif
@@ -292,11 +266,9 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
     } else if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
        reset_layout(gvc, g);
 #ifndef WITH_CGRAPH
-       deleteNodes(ictx, g);
        deleteGraph(ictx, g);
 #else
-       deleteNodes(g);
-       deleteGraph(g);
+       deleteGraph(gctx, g);
 #endif
        return TCL_OK;
 
@@ -318,7 +290,11 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
            Tcl_AppendResult(interp, "Edge \"", argv[2], " - ", argv[3], "\" not found.", NULL);
            return TCL_ERROR;
        }
+#ifndef WITH_CGRAPH
        tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+#else
+       sprintf(buf,"edge%p",e);
+#endif
        Tcl_AppendElement(interp, buf);
        return TCL_OK;
 
@@ -331,7 +307,11 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
            Tcl_AppendResult(interp, "Node not found.", NULL);
            return TCL_ERROR;
        }
+#ifndef WITH_CGRAPH
        tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
+#else
+       sprintf(buf,"node%p",n);
+#endif
        Tcl_AppendResult(interp, buf, NULL);
        return TCL_OK;
 
@@ -367,7 +347,11 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
     } 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));
+#else
+               sprintf(buf,"edge%p",e);
+#endif
                Tcl_AppendElement(interp, buf);
            }
        }
@@ -375,15 +359,24 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
 
     } 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));
+#else
+           sprintf(buf,"node%p",n);
+#endif
            Tcl_AppendElement(interp, buf);
+           
        }
        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));
+#else
+           sprintf(buf,"node%p",n);
+#endif
            Tcl_AppendElement(interp, buf);
        }
        return TCL_OK;
@@ -392,7 +385,7 @@ int graphcmd(ClientData clientData, Tcl_Interp * interp,
               && (strncmp(argv[1], "listsubgraphs", length) == 0)) {
 #ifdef WITH_CGRAPH
        for (sg = agfstsubg(g); sg; sg = agnxtsubg(sg)) {
-           tclhandleString(ictx->graphTblPtr, buf, AGID(sg));
+           sprintf(buf,"graph%p",sg);
            Tcl_AppendElement(interp, buf);
        }
 #else
diff --git a/tclpkg/tcldot/tcldot-id.c b/tclpkg/tcldot/tcldot-id.c
new file mode 100644 (file)
index 0000000..4a3be38
--- /dev/null
@@ -0,0 +1,111 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+
+#include "tcldot.h"
+
+#ifdef WITH_CGRAPH
+
+// Agiddisc functions
+static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
+    ictx_t *ictx = (ictx_t *)disc;
+    gctx_t *gctx;
+
+    gctx = (gctx_t *)malloc(sizeof(gctx_t));
+    gctx->g = g;
+    gctx->ictx = ictx;
+    return (void *)gctx;
+}
+static long myiddisc_map(void *state, int objtype, char *str, unsigned long *id, int createflag) {
+    gctx_t *gctx = (gctx_t *)state;
+    ictx_t *ictx = gctx->ictx;
+    char *s;
+
+    if (str) {
+        if (createflag)
+            s = agstrdup(gctx->g, str);
+        else
+            s = agstrbind(gctx->g, str);
+        *id = (unsigned long) s;
+    } else {
+        *id = ictx->ctr;  /* counter maintained in per-interp space, so that
+               ids are unique across all graphs in the interp */
+        ictx->ctr += 2;
+    }
+    return TRUE;
+}
+/* we don't allow users to explicitly set IDs, either */
+static long myiddisc_alloc(void *state, int objtype, unsigned long request_id) {
+    NOTUSED(state);
+    NOTUSED(objtype);
+    NOTUSED(request_id);
+    return FALSE;
+}
+static void myiddisc_free(void *state, int objtype, unsigned long id) {
+    gctx_t *gctx = (gctx_t *)state;
+
+/* FIXME no obj* available
+    ictx_t *ictx = gctx->ictx;
+    char buf[32] = "";
+
+    switch (objtype) {
+        case AGRAPH: sprintf(buf,"graph%lu",id); break;
+        case AGNODE: sprintf(buf,"node%lu",id); break;
+        case AGINEDGE:
+        case AGOUTEDGE: sprintf(buf,"edge%lu",id); break;
+    }
+    Tcl_DeleteCommand(ictx->interp, buf);
+*/
+    if (id % 2 == 0)
+        agstrfree(gctx->g, (char *) id);
+}
+static char *myiddisc_print(void *state, int objtype, unsigned long id) {
+    NOTUSED(state);
+    NOTUSED(objtype);
+    if (id % 2 == 0)
+        return (char *) id;
+    else
+        return "";
+}
+static void myiddisc_close(void *state) {
+    free(state);
+}
+static void myiddisc_register(void *state, int objtype, void *obj) {
+    gctx_t *gctx = (gctx_t *)state;
+    ictx_t *ictx = gctx->ictx;
+    Tcl_Interp *interp = ictx->interp;
+    Tcl_CmdProc *proc = NULL;
+    char buf[32] = "";
+
+    switch (objtype) {
+        case AGRAPH: sprintf(buf,"graph%p",obj); proc=graphcmd; break;
+        case AGNODE: sprintf(buf,"node%p",obj); proc=nodecmd; break;
+        case AGINEDGE:
+        case AGOUTEDGE: sprintf(buf,"edge%p",obj); proc=edgecmd; break;
+    }
+#ifndef TCLOBJ
+    Tcl_CreateCommand(interp, buf, proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
+#else
+    Tcl_CreateObjCommand(interp, buf, proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
+#endif           
+}
+Agiddisc_t myiddisc = {
+    myiddisc_open,
+    myiddisc_map,
+    myiddisc_alloc,
+    myiddisc_free,
+    myiddisc_print,
+    myiddisc_close,
+    myiddisc_register
+};
+#endif
similarity index 91%
rename from tclpkg/tcldot/tcldot-mygets.c
rename to tclpkg/tcldot/tcldot-io.c
index 170dbf28524d75915f6e9802da7cd61e1fac4562..c257ba06ca4a211a963cd650876a4a50f00ed8f1 100644 (file)
@@ -157,3 +157,22 @@ char *mygets(char *ubuf, int n, FILE * channel)
 #endif
 }
 #endif /* WITH_CGRAPH */
+
+#ifdef WITH_CGRAPH
+
+Agraph_t *agread_usergets (ictx_t *ictx, FILE * fp, int (*usergets)(void *chan, char *buf, int bufsize))
+{
+    Agraph_t* g;
+    Agiodisc_t ioDisc;
+
+    ioDisc.afread = usergets;
+    ioDisc.putstr = AgIoDisc.putstr;
+    ioDisc.flush = AgIoDisc.flush;
+
+    ictx->mydisc.io = &ioDisc;
+    g = agread (fp, (Agdisc_t *)ictx);
+    ictx->mydisc.io = &AgIoDisc;   /* restore io */
+    return g;
+}
+
+#endif
diff --git a/tclpkg/tcldot/tcldot-mem.c b/tclpkg/tcldot/tcldot-mem.c
new file mode 100644 (file)
index 0000000..ee57971
--- /dev/null
@@ -0,0 +1,18 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/*************************************************************************
+ * Copyright (c) 2011 AT&T Intellectual Property 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: See CVS logs. Details at http://www.graphviz.org/
+ *************************************************************************/
+
+
+#include "tcldot.h"
+
+#ifdef WITH_CGRAPH
+#endif
index f48a0c2f883a03261c2ac927e39d3bf662bd8f37..c92a7873ea7fec5eb8879b9918957fb7a0bde361 100644 (file)
@@ -21,27 +21,40 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
 #endif                         /* TCLOBJ */
     )
 {
-    unsigned long id;
-    char c, buf[16], **argv2;
+    char c, buf[32], **argv2;
     int i, j, length, argc2;
     Agraph_t *g;
-    Agnode_t **np, *n, *head;
-    Agedge_t **ep, *e;
+    Agnode_t *n, *head;
+    Agedge_t *e;
     Agsym_t *a;
+#ifndef WITH_CGRAPH
+    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);
+       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, " \"", argv[0], "\"", NULL);
+       Tcl_AppendResult(interp, "Node \"", argv[0], "\" not found", NULL);
        return TCL_ERROR;
     }
     n = *np;
+#else
+    n = cmd2n(gctx,argv[0]);
+    if (!n) {
+       Tcl_AppendResult(interp, "Node \"", argv[0], "\" not found", NULL);
+       return TCL_ERROR;
+    }
+#endif
     g = agraphof(n);
 
     c = argv[1][0];
@@ -50,37 +63,39 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
 
     if ((c == 'a') && (strncmp(argv[1], "addedge", length) == 0)) {
        if ((argc < 3) || (!(argc % 2))) {
-           Tcl_AppendResult(interp, "wrong # args: should be \"",
-                            argv[0],
-                            " addedge head ?attributename attributevalue? ?...?\"",
-                            NULL);
+           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);
+               Tcl_AppendResult(interp, "Head node \"", argv[2], "\" not found.", NULL);
                return TCL_ERROR;
            }
        } else {
            head = *np;
-           if (agroot(g) != agroot(agraphof(head))) {
-               Tcl_AppendResult(interp, "Nodes ", argv[0], " and ",
-                                argv[2], " are not in the same graph.",
-                                NULL);
+       }
+#else
+       head = cmd2n(gctx,argv[2]);
+       if (!head) {
+           if (!(head = agfindnode(g, argv[2]))) {
+               Tcl_AppendResult(interp, "Head node \"", argv[2], "\" not found.", NULL);
                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);
+        sprintf(buf,"edge%p",e);
+        Tcl_AppendResult(interp, buf, NULL);
 #else
        e = agedge(g, n, head);
-#endif
-       if (!
-           (ep = (Agedge_t **) tclhandleXlateIndex(ictx->edgeTblPtr, AGID(e)))
-           || *ep != e) {
-           ep = (Agedge_t **) tclhandleAlloc(ictx->edgeTblPtr, Tcl_GetStringResult(interp),
-                                             &id);
+       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
@@ -95,41 +110,43 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
        } 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
-       deleteEdges(ictx, g, n);
-       tclhandleFreeIndex(ictx->nodeTblPtr, AGID(n));
-       Tcl_DeleteCommand(interp, argv[0]);
+       deleteNode(ictx, g, n);
 #else
-       deleteEdges(g, n);
+       deleteNode(gctx, g, n);
 #endif
-       agdelete(g, n);
        reset_layout(gvc, g);
        return TCL_OK;
 
     } else if ((c == 'f') && (strncmp(argv[1], "findedge", length) == 0)) {
        if (argc < 3) {
-           Tcl_AppendResult(interp, "wrong # args: should be \"",
-                            argv[0], " findedge headnodename\"",
-                            NULL);
+           Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " findedge headnodename\"", NULL);
            return TCL_ERROR;
        }
        if (!(head = agfindnode(g, argv[2]))) {
-           Tcl_AppendResult(interp, "Head node \"", argv[2],
-                            "\" not found.", NULL);
+           Tcl_AppendResult(interp, "Head node \"", argv[2], "\" not found.", NULL);
            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
+           sprintf(buf,"node%p",head);
+#endif
+           Tcl_AppendResult(interp, "Edge \"", argv[0], " - ", buf, "\" not found.", NULL);
            return TCL_ERROR;
        }
+#ifndef WITH_CGRAPH
        tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+#else
+       sprintf(buf,"edge%p",head);
+#endif
        Tcl_AppendElement(interp, buf);
        return TCL_OK;
 
@@ -140,7 +157,11 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
 
     } 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));
+#else
+           sprintf(buf,"edge%p",e);
+#endif
            Tcl_AppendElement(interp, buf);
        }
        return TCL_OK;
@@ -148,7 +169,11 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
     } 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));
+#else
+           sprintf(buf,"edge%p",e);
+#endif
            Tcl_AppendElement(interp, buf);
        }
        return TCL_OK;
@@ -156,7 +181,11 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
     } 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));
+#else
+           sprintf(buf,"edge%p",e);
+#endif
            Tcl_AppendElement(interp, buf);
        }
        return TCL_OK;
@@ -176,8 +205,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
                    Tcl_AppendElement(interp, agxget(n, a));
 #endif
                } else {
-                   Tcl_AppendResult(interp, " No attribute named \"",
-                                    argv2[j], "\"", NULL);
+                   Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
                    return TCL_ERROR;
                }
            }
@@ -202,8 +230,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
                    Tcl_AppendElement(interp, agxget(n, a));
 #endif
                } else {
-                   Tcl_AppendResult(interp, " No attribute named \"",
-                                    argv2[j], "\"", NULL);
+                   Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
                    return TCL_ERROR;
                }
            }
@@ -220,8 +247,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
                 (CONST84 char ***) &argv2) != TCL_OK)
                return TCL_ERROR;
            if ((argc2 == 0) || (argc2 % 2)) {
-               Tcl_AppendResult(interp, "wrong # args: should be \"",
-                                argv[0],
+               Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
                                 "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
                                 NULL);
                Tcl_Free((char *) argv2);
@@ -231,8 +257,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
            Tcl_Free((char *) argv2);
        } else {
            if ((argc < 4) || (argc % 2)) {
-               Tcl_AppendResult(interp, "wrong # args: should be \"",
-                                argv[0],
+               Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
                                 "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
                                 NULL);
                return TCL_ERROR;
@@ -247,7 +272,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
        return TCL_OK;
 
     } else {
-       Tcl_AppendResult(interp, "bad option \"", argv[1],
+       Tcl_AppendResult(interp, "Bad option \"", argv[1],
                         "\": must be one of:",
                         "\n\taddedge, listattributes, listedges, listinedges,",
                         "\n\tlistoutedges, queryattributes, queryattributevalues,",
index 91b84ce961badd1bcb9d5a7917b9c273dcd5db98..ea09f4e737904228177fbc9b85cc15d599e8245e 100644 (file)
@@ -36,37 +36,71 @@ void reset_layout(GVC_t *gvc, Agraph_t * sg)
 }
 
 #ifdef WITH_CGRAPH
-void deleteEdges(Agraph_t * g, Agnode_t * n)
+/* handles (tcl commands) to obj* */
+
+Agraph_t *cmd2g(gctx_t *gctx, char *cmd) {
+    Agraph_t *g = NULL;
+
+    if (sscanf(cmd, "graph%p", &g) != 1 || !g)
+        return NULL;
+    return g;
+}
+Agnode_t *cmd2n(gctx_t *gctx, char *cmd) {
+    Agnode_t *n = NULL;
+
+    if (sscanf(cmd, "node%p", &n) != 1 || !n)
+        return NULL;
+    return n;
+}
+Agedge_t *cmd2e(gctx_t *gctx, char *cmd) {
+    Agedge_t *e = NULL;
+
+    if (sscanf(cmd, "edge%p", &e) != 1 || !e)
+        return NULL;
+    return e;
+}
+#endif // WITH_CGRAPH
+
+#ifdef WITH_CGRAPH
+void deleteEdge(gctx_t *gctx, Agraph_t * g, Agedge_t *e)
+{
+    agdelete(gctx->g, e);  /* delete edge from root graph */
+}
+static void deleteNodeEdges(gctx_t *gctx, Agraph_t *g, Agnode_t *n)
 {
     Agedge_t *e, *e1;
 
     e = agfstedge(g, n);
     while (e) {
        e1 = agnxtedge(g, e, n);
-       agdelete(agroot(g), e);
+       deleteEdge(gctx, g, e);
        e = e1;
     }
 }
-
-void deleteNodes(Agraph_t * g)
+void deleteNode(gctx_t * gctx, Agraph_t *g, Agnode_t *n)
+{
+    deleteNodeEdges(gctx, gctx->g, n); /* delete all edges to/from node in root graph */
+    agdelete(gctx->g, n); /* delete node from root graph */
+}
+static void deleteGraphNodes(gctx_t * gctx, Agraph_t *g)
 {
     Agnode_t *n, *n1;
 
     n = agfstnode(g);
     while (n) {
-       deleteEdges(agroot(g), n);
        n1 = agnxtnode(g, n);
-       agdelete(agroot(g), n);
+       deleteNode(gctx, g, n);
        n = n1;
     }
 }
-void deleteGraph(Agraph_t * g)
+void deleteGraph(gctx_t * gctx, Agraph_t *g)
 {
     Agraph_t *sg;
 
     for (sg = agfstsubg (g); sg; sg = agnxtsubg (sg)) {
-       deleteGraph(sg);
+       deleteGraph(gctx, sg);
     }
+    deleteGraphNodes(gctx, g);
     if (g == agroot(g)) {
        agclose(g);
     } else {
@@ -74,40 +108,52 @@ void deleteGraph(Agraph_t * g)
     }
 }
 #else
-void deleteEdges(ictx_t * ictx, Agraph_t * g, Agnode_t * n)
+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 **ep, *e, *e1;
-    char buf[16];
+    Agedge_t *e, *e1;
 
     e = agfstedge(g, n);
     while (e) {
-       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));
        e1 = agnxtedge(g, e, n);
-       agdelete(agroot(g), e);
+        deleteEdge(ictx, g, e);
        e = e1;
     }
 }
-void deleteNodes(ictx_t * ictx, Agraph_t * g)
+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 **np, *n, *n1;
-    char buf[16];
+    Agnode_t *n, *n1;
 
     n = agfstnode(g);
     while (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));
-       deleteEdges(ictx, agroot(g), n);
        n1 = agnxtnode(g, n);
-       agdelete(agroot(g), n);
+       deleteNode(ictx, g, n);
        n = n1;
     }
 }
@@ -115,7 +161,7 @@ void deleteGraph(ictx_t * ictx, Agraph_t * g)
 {
     Agraph_t **sgp;
     Agedge_t *e;
-    char buf[16];
+    char buf[32];
 
     if (g->meta_node) {
        for (e = agfstout(g->meta_node->graph, g->meta_node); e;
@@ -128,6 +174,7 @@ void deleteGraph(ictx_t * ictx, Agraph_t * 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 {
index 28850750fa9b892fc7794c73baa3987f6395d76f..89ba5e55dbff3dfa3eff109634e8a041b0c04d6c 100644 (file)
 
 #include "tcldot.h"
 
-#ifdef WITH_CGRAPH
-
-// Agiddisc functions
-static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
-    ictx_t *ictx = (ictx_t *)disc;
-    gctx_t *gctx;
-
-    gctx = (gctx_t *)malloc(sizeof(gctx_t));
-    gctx->g = g;
-    gctx->ictx = ictx;
-    return (void *)gctx;
-}
-static long myiddisc_map(void *state, int objtype, char *str, unsigned long *id, int createflag) {
-    gctx_t *gctx = (gctx_t *)state;
-    ictx_t *ictx = gctx->ictx;
-    char *s;
-
-    if (str) {
-        if (createflag)
-            s = agstrdup(gctx->g, str);
-        else
-            s = agstrbind(gctx->g, str);
-        *id = (unsigned long) s;
-    } else {
-        *id = ictx->ctr;  /* counter maintained in per-interp space, so that
-               ids are unique across all graphs in the interp */
-        ictx->ctr += 2;
-    }
-    return TRUE;
-}
-/* we don't allow users to explicitly set IDs, either */
-static long myiddisc_alloc(void *state, int objtype, unsigned long request_id) {
-    NOTUSED(state);
-    NOTUSED(objtype);
-    NOTUSED(request_id);
-    return FALSE;
-}
-static void myiddisc_free(void *state, int objtype, unsigned long id) {
-    gctx_t *gctx = (gctx_t *)state;
-
-/* FIXME no obj* available
-    ictx_t *ictx = gctx->ictx;
-    char buf[30] = "";
-
-    switch (objtype) {
-        case AGRAPH: sprintf(buf,"graph%lu",id); break;
-        case AGNODE: sprintf(buf,"node%lu",id); break;
-        case AGINEDGE:
-        case AGOUTEDGE: sprintf(buf,"edge%lu",id); break;
-    }
-    Tcl_DeleteCommand(ictx->interp, buf);
-*/
-    if (id % 2 == 0)
-        agstrfree(gctx->g, (char *) id);
-}
-static char *myiddisc_print(void *state, int objtype, unsigned long id) {
-    NOTUSED(state);
-    NOTUSED(objtype);
-    if (id % 2 == 0)
-        return (char *) id;
-    else
-        return "";
-}
-static void myiddisc_close(void *state) {
-    free(state);
-}
-static void myiddisc_register(void *state, int objtype, void *obj) {
-    gctx_t *gctx = (gctx_t *)state;
-    ictx_t *ictx = gctx->ictx;
-    Tcl_Interp *interp = ictx->interp;
-    Tcl_CmdProc *proc = NULL;
-    char buf[30] = "";
-
-    switch (objtype) {
-        case AGRAPH: sprintf(buf,"graph%p",obj); proc=graphcmd; break;
-        case AGNODE: sprintf(buf,"node%p",obj); proc=nodecmd; break;
-        case AGINEDGE:
-        case AGOUTEDGE: sprintf(buf,"edge%p",obj); proc=edgecmd; break;
-    }
-    Tcl_AppendResult(interp, buf, NULL);
-#ifndef TCLOBJ
-    Tcl_CreateCommand(interp, Tcl_GetStringResult(interp), proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
-#else
-    Tcl_CreateObjCommand(interp, Tcl_GetStringResult(interp), proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
-#endif           
-}
-static Agiddisc_t myiddisc = {
-    myiddisc_open,
-    myiddisc_map,
-    myiddisc_alloc,
-    myiddisc_free,
-    myiddisc_print,
-    myiddisc_close,
-    myiddisc_register
-};
-
-#endif // WITH_CGRAPH
-
 static int dotnew(ClientData clientData, Tcl_Interp * interp,
 #ifndef TCLOBJ
                  int argc, char *argv[]
@@ -129,6 +31,7 @@ static int dotnew(ClientData clientData, Tcl_Interp * interp,
     int kind;
     unsigned long id;
 #else
+    char buf[32];
     Agdesc_t kind;
 #endif
 
@@ -214,34 +117,15 @@ static int dotnew(ClientData clientData, Tcl_Interp * interp,
      * so we make sure that it is initialized to "not done" */
     GD_drawing(g) = NULL;
 
-    return TCL_OK;
-}
-
 #ifdef WITH_CGRAPH
-static void
-init_graphs (ictx_t *ictx, graph_t* g)
-{
-    Agraph_t *sg, **sgp;
-    unsigned long id;
-    char buf[16];
-    Tcl_Interp *interp = ictx->interp;
-
-    for (sg = agfstsubg (g); sg; sg = agnxtsubg (sg))
-       init_graphs (ictx, sg);
+    sprintf(buf, "graph%p", g);
+    Tcl_AppendResult(interp, buf, NULL);
+#endif
 
-    sgp = (Agraph_t **) tclhandleAlloc(ictx->graphTblPtr, buf, &id);
-    *sgp = g;
-    AGID(g) = 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 (agroot(g) == g)
-       Tcl_SetResult(interp, buf, TCL_VOLATILE);
+    return TCL_OK;
 }
-#endif
 
+#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 
@@ -249,18 +133,13 @@ init_graphs (ictx_t *ictx, graph_t* g)
  */
 static int tcldot_fixup(ictx_t *ictx, graph_t * g)
 {
-#ifndef WITH_CGRAPH
     Agraph_t **gp, *sg, **sgp;
-#endif
     Agnode_t *n, **np;
     Agedge_t *e, **ep;
-    char buf[16];
+    char buf[32];
     unsigned long id;
     Tcl_Interp *interp = ictx->interp;
 
-#ifdef WITH_CGRAPH
-    init_graphs (ictx, g);
-#else
     if (g->meta_node) {
        for (n = agfstnode(g->meta_node->graph); n;
             n = agnxtnode(g->meta_node->graph, n)) {
@@ -290,7 +169,6 @@ static int tcldot_fixup(ictx_t *ictx, graph_t * g)
                             (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
 #endif                         /* TCLOBJ */
     }
-#endif /* WITH_CGRAPH */
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        np = (Agnode_t **) tclhandleAlloc(ictx->nodeTblPtr, buf, &id);
        *np = n;
@@ -318,24 +196,7 @@ static int tcldot_fixup(ictx_t *ictx, graph_t * g)
     return TCL_OK;
 }
 
-#ifdef WITH_CGRAPH
-Agraph_t *agread_usergets (FILE * fp, int (*usergets)(void *chan, char *buf, int bufsize))
-{
-    Agraph_t* g;
-    Agdisc_t disc;
-    Agiodisc_t ioDisc;
-
-    ioDisc.afread = usergets;
-    ioDisc.putstr = AgIoDisc.putstr;
-    ioDisc.flush = AgIoDisc.flush;
-
-    disc.mem = &AgMemDisc;
-    disc.id = &AgIdDisc;
-    disc.io = &ioDisc;
-    g = agread (fp, &disc);
-    return g;
-}
-#endif
+#endif /* WITH_CGRAPH */
 
 static int dotread(ClientData clientData, Tcl_Interp * interp,
 #ifndef TCLOBJ
@@ -348,11 +209,12 @@ static int dotread(ClientData clientData, Tcl_Interp * interp,
     Agraph_t *g;
     Tcl_Channel channel;
     int mode;
-    ictx_t *ictx = (ictx_t *)clientData;
+#ifdef WITH_CGRAPH
+    char buf[32];
+#endif
 
     if (argc < 2) {
-       Tcl_AppendResult(interp, "wrong # args: should be \"",
-                        argv[0], " fileHandle\"", NULL);
+       Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " fileHandle\"", NULL);
        return TCL_ERROR;
     }
     channel = Tcl_GetChannel(interp, argv[1], &mode);
@@ -366,7 +228,7 @@ static int dotread(ClientData clientData, Tcl_Interp * interp,
      *   a properly parsed graph. If the graph doesn't parse
      *   during reading then the channel will be left at EOF
      */
-    g = agread_usergets((FILE *) channel, (mygets));
+    g = agread_usergets((ictx_t *)clientData, (FILE *) channel, (mygets));
     if (!g) {
        Tcl_AppendResult(interp, "\nFailure to read graph \"", argv[1], "\"", NULL);
        if (agerrors()) {
@@ -382,7 +244,13 @@ static int dotread(ClientData clientData, Tcl_Interp * interp,
      * so we make sure that it is initialized to "not done" */
     GD_drawing(g) = NULL;
 
-    return (tcldot_fixup(ictx, g));
+#ifndef WITH_CGRAPH
+    return (tcldot_fixup((ictx_t *)clientData, g));
+#else
+    sprintf(buf, "graph%p", g);
+    Tcl_AppendResult(interp, buf, NULL);
+    return TCL_OK;
+#endif
 }
 
 static int dotstring(ClientData clientData, Tcl_Interp * interp,
@@ -394,10 +262,12 @@ static int dotstring(ClientData clientData, Tcl_Interp * interp,
     )
 {
     Agraph_t *g;
-    ictx_t *ictx = (ictx_t *)clientData;
+#ifdef WITH_CGRAPH
+    char buf[32];
+#endif
 
     if (argc < 2) {
-       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " string\"", NULL);
+       Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " string\"", NULL);
        return TCL_ERROR;
     }
     if (!(g = agmemread(argv[1]))) {
@@ -415,7 +285,13 @@ static int dotstring(ClientData clientData, Tcl_Interp * interp,
      * so we make sure that it is initialized to "not done" */
     GD_drawing(g) = NULL;
 
-    return (tcldot_fixup(ictx, g));
+#ifndef WITH_CGRAPH
+    return (tcldot_fixup((ictx_t *)clientData, g));
+#else
+    sprintf(buf, "graph%p", g);
+    Tcl_AppendResult(interp, buf, NULL);
+    return TCL_OK;
+#endif
 }
 
 #if defined(_BLD_tcldot) && defined(_DLL)
@@ -432,7 +308,9 @@ int Tcldot_Init(Tcl_Interp * interp)
 
     ictx->interp = interp;
 #ifdef WITH_CGRAPH    
+    ictx->mydisc.mem = &AgMemDisc;
     ictx->mydisc.id = &myiddisc;
+    ictx->mydisc.io = &AgIoDisc;
     ictx->ctr = 1;  /* init to first odd number,  increment by 2 */
 #endif
 
@@ -486,9 +364,7 @@ int Tcldot_Init(Tcl_Interp * interp)
                         (ClientData) ictx, (Tcl_CmdDeleteProc *) NULL);
 #endif                         /* TCLOBJ */
 
-#ifdef WITH_CGRAPH  
-    ictx->graphTblPtr = (void *) tclhandleInit("tcldot", sizeof(gctx_t *), 10);
-#else
+#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);
index 007d9c38d50c20989e77dabeea4ba0710a4e4b48..d4ebaec80bc5556d5fec65589e08d093f39c3c03 100644 (file)
@@ -46,11 +46,10 @@ Tcl_GetString(Tcl_Obj *obj) {
 typedef struct {
 #ifdef WITH_CGRAPH
     Agdisc_t mydisc;    /* must be first to allow casting mydisc to ictx */
-    unsigned long int ctr; /* odd number counter for anon objects over all g's in interp */
-#endif
-/* **FIXME**  #ifndef WITH_CGRAPH */
+    unsigned long ctr;  /* odd number counter for anon objects over all g's in interp */
+#else
     void *graphTblPtr, *nodeTblPtr, *edgeTblPtr;
-/*            #endif */
+#endif
     Tcl_Interp *interp;
     GVC_t *gvc;
 } ictx_t;
@@ -62,7 +61,7 @@ typedef struct {
 typedef struct {
     Agraph_t *g;        /* the graph */
     ictx_t *ictx;
-    unsigned long int idx; 
+    unsigned long idx; 
 } gctx_t;
 #endif
 
@@ -99,16 +98,23 @@ extern int edgecmd(ClientData clientData, Tcl_Interp * interp,
     );
 
 #ifdef WITH_CGRAPH
-extern void deleteEdges(Agraph_t * g, Agnode_t * n);
-extern void deleteNodes(Agraph_t * g);
-extern void deleteGraph(Agraph_t * g);
+extern Agiddisc_t myiddisc;
+extern Agiodisc_t myiodisc;
+extern Agmemdisc_t mymemdisc;
+extern Agraph_t *agread_usergets (ictx_t *ictx, FILE * fp, int (*usergets)(void *chan, char *buf, int bufsize));
+extern Agraph_t *cmd2g(gctx_t *gctx, char *cmd);
+extern Agnode_t *cmd2n(gctx_t *gctx, char *cmd);
+extern Agedge_t *cmd2e(gctx_t *gctx, char *cmd);
+extern void deleteEdge(gctx_t *gctx, Agraph_t * g, Agedge_t * e);
+extern void deleteNode(gctx_t *gctx, Agraph_t * g, Agnode_t * n);
+extern void deleteGraph(gctx_t *gctx, 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 int mygets(void* channel, char *ubuf, int n);
 #else
-extern void deleteEdges(ictx_t * ictx, Agraph_t * g, Agnode_t * n);
-extern void deleteNodes(ictx_t * ictx, Agraph_t * g);
+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);