#endif /* TCLOBJ */
)
{
- char c, buf[32], *s, **argv2;
+ char c, *s, **argv2;
int i, j, length, argc2;
Agraph_t *g;
Agedge_t *e;
Agsym_t *a;
#ifndef WITH_CGRAPH
+ buf[32];
Agedge_t **ep;
ictx_t *ictx = (ictx_t *)clientData;
#else
}
e = *ep;
#else
- e = cmd2e(gctx,argv[0]);
+ e = cmd2e(argv[0]);
if (!e) {
Tcl_AppendResult(interp, "Edge \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
} 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
- sprintf(buf,"node%p",agtail(e));
+ Tcl_AppendElement(interp, obj2cmd(agtail(e)));
#endif
- Tcl_AppendElement(interp, buf);
#ifndef WITH_CGRAPH
tclhandleString(ictx->nodeTblPtr, buf, AGID(aghead(e)));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"node%p",aghead(e));
+ Tcl_AppendElement(interp, obj2cmd(aghead(e)));
#endif
- Tcl_AppendElement(interp, buf);
return TCL_OK;
} else if ((c == 'q')
}
g = *gp;
#else
- g = cmd2g(gctx,argv[0]);
+ g = cmd2g(argv[0]);
if (!g) {
Tcl_AppendResult(interp, "Graph \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
tail = *np;
}
#else
- tail = cmd2n(gctx,argv[2]);
+ tail = cmd2n(argv[2]);
if (!tail) {
if (!(tail = agfindnode(g, argv[2]))) {
Tcl_AppendResult(interp, "Tail node \"", argv[2], "\" not found.", NULL);
head = *np;
}
#else
- head = cmd2n(gctx,argv[2]);
+ head = cmd2n(argv[2]);
if (!head) {
if (!(head = agfindnode(g, argv[3]))) {
Tcl_AppendResult(interp, "Head node \"", argv[3], "\" not found.", NULL);
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
+#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) {
np = (Agnode_t **)tclhandleXlateIndex(ictx->nodeTblPtr, AGID(n));
*np = n;
#else
- sprintf(buf,"node%p",n);
- Tcl_AppendResult(interp, buf, NULL);
+ Tcl_AppendResult(interp, obj2cmd(n), NULL);
#endif
setnodeattributes(agroot(g), n, &argv[i], argc - i);
reset_layout(gvc, g);
/* 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);
+ Tcl_AppendResult(interp, obj2cmd(sg), NULL);
#else
sg = agsubg(g, argv[2]);
if (! (sgp = (Agraph_t **) tclhandleXlateIndex(ictx->graphTblPtr, AGID(sg))) || *sgp != sg) {
}
#ifndef WITH_CGRAPH
tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"edge%p",e);
+ Tcl_AppendElement(interp, obj2cmd(e));
#endif
- Tcl_AppendElement(interp, buf);
return TCL_OK;
} else if ((c == 'f') && (strncmp(argv[1], "findnode", length) == 0)) {
}
#ifndef WITH_CGRAPH
tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
+ Tcl_AppendResult(interp, buf, NULL);
#else
- sprintf(buf,"node%p",n);
+ Tcl_AppendResult(interp, obj2cmd(n), NULL);
#endif
- Tcl_AppendResult(interp, buf, NULL);
return TCL_OK;
} else if ((c == 'l')
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
#ifndef WITH_CGRAPH
tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"edge%p",e);
+ Tcl_AppendElement(interp, obj2cmd(e));
#endif
- Tcl_AppendElement(interp, buf);
}
}
return TCL_OK;
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
#ifndef WITH_CGRAPH
tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"node%p",n);
+ Tcl_AppendElement(interp, obj2cmd(n));
#endif
- Tcl_AppendElement(interp, buf);
}
return TCL_OK;
for (n = aglstnode(g); n; n = agprvnode(g, n)) {
#ifndef WITH_CGRAPH
tclhandleString(ictx->nodeTblPtr, buf, AGID(n));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"node%p",n);
+ Tcl_AppendElement(interp, obj2cmd(n));
#endif
- Tcl_AppendElement(interp, buf);
}
return TCL_OK;
&& (strncmp(argv[1], "listsubgraphs", length) == 0)) {
#ifdef WITH_CGRAPH
for (sg = agfstsubg(g); sg; sg = agnxtsubg(sg)) {
- sprintf(buf,"graph%p",sg);
- Tcl_AppendElement(interp, buf);
+ Tcl_AppendElement(interp, obj2cmd(g));
}
#else
if (g->meta_node) {
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 AGRAPH: proc=graphcmd; break;
+ case AGNODE: proc=nodecmd; break;
case AGINEDGE:
- case AGOUTEDGE: sprintf(buf,"edge%p",obj); proc=edgecmd; break;
+ case AGOUTEDGE: proc=edgecmd; break;
}
#ifndef TCLOBJ
- Tcl_CreateCommand(interp, buf, proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
+ Tcl_CreateCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
#else
- Tcl_CreateObjCommand(interp, buf, proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
+ Tcl_CreateObjCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
#endif
}
Agiddisc_t myiddisc = {
#endif /* TCLOBJ */
)
{
- char c, buf[32], **argv2;
+ char c, **argv2;
int i, j, length, argc2;
Agraph_t *g;
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;
}
n = *np;
#else
- n = cmd2n(gctx,argv[0]);
+ n = cmd2n(argv[0]);
if (!n) {
Tcl_AppendResult(interp, "Node \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
head = *np;
}
#else
- head = cmd2n(gctx,argv[2]);
+ head = cmd2n(argv[2]);
if (!head) {
if (!(head = agfindnode(g, argv[2]))) {
Tcl_AppendResult(interp, "Head node \"", argv[2], "\" not found.", NULL);
}
#ifdef WITH_CGRAPH
e = agedge(g, n, head, NULL, 1);
- sprintf(buf,"edge%p",e);
- Tcl_AppendResult(interp, buf, NULL);
+ Tcl_AppendResult(interp, obj2cmd(e), NULL);
#else
e = agedge(g, n, head);
if (!(ep = (Agedge_t **) tclhandleXlateIndex(ictx->edgeTblPtr, AGID(e))) || *ep != e) {
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);
+ Tcl_AppendResult(interp, "Edge \"", argv[0], " - ", obj2cmd(head), "\" not found.", NULL);
#endif
- Tcl_AppendResult(interp, "Edge \"", argv[0], " - ", buf, "\" not found.", NULL);
return TCL_ERROR;
}
#ifndef WITH_CGRAPH
tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"edge%p",head);
+ Tcl_AppendElement(interp, obj2cmd(head));
#endif
- Tcl_AppendElement(interp, buf);
return TCL_OK;
} else if ((c == 'l')
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
- sprintf(buf,"edge%p",e);
+ Tcl_AppendElement(interp, obj2cmd(e));
#endif
- Tcl_AppendElement(interp, buf);
}
return TCL_OK;
for (e = agfstin(g, n); e; e = agnxtin(g, e)) {
#ifndef WITH_CGRAPH
tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"edge%p",e);
+ Tcl_AppendElement(interp, obj2cmd(e));
#endif
- Tcl_AppendElement(interp, buf);
}
return TCL_OK;
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
#ifndef WITH_CGRAPH
tclhandleString(ictx->edgeTblPtr, buf, AGID(e));
+ Tcl_AppendElement(interp, buf);
#else
- sprintf(buf,"edge%p",e);
+ Tcl_AppendElement(interp, obj2cmd(e));
#endif
- Tcl_AppendElement(interp, buf);
}
return TCL_OK;
#ifdef WITH_CGRAPH
/* handles (tcl commands) to obj* */
-Agraph_t *cmd2g(gctx_t *gctx, char *cmd) {
+Agraph_t *cmd2g(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 *cmd2n(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 *cmd2e(char *cmd) {
Agedge_t *e = NULL;
if (sscanf(cmd, "edge%p", &e) != 1 || !e)
return NULL;
return e;
}
+
+
+/* obj* to handles (tcl commands) */
+
+char *obj2cmd (void *obj) {
+ static char buf[32];
+
+ switch (AGTYPE(obj)) {
+ case AGRAPH: sprintf(buf,"graph%p",obj); break;
+ case AGNODE: sprintf(buf,"node%p",obj); break;
+ case AGINEDGE:
+ case AGOUTEDGE: sprintf(buf,"edge%p",obj); break;
+ }
+ return buf;
+}
+
#endif // WITH_CGRAPH
#ifdef WITH_CGRAPH
void deleteEdge(gctx_t *gctx, Agraph_t * g, Agedge_t *e)
{
- char buf[32];
+ char *hndl;
- sprintf(buf,"edge%p",e);
+ hndl = obj2cmd(e);
agdelete(gctx->g, e); /* delete edge from root graph */
- Tcl_DeleteCommand(gctx->ictx->interp, buf);
+ Tcl_DeleteCommand(gctx->ictx->interp, hndl);
}
static void deleteNodeEdges(gctx_t *gctx, Agraph_t *g, Agnode_t *n)
{
}
void deleteNode(gctx_t * gctx, Agraph_t *g, Agnode_t *n)
{
- char buf[32];
+ char *hndl;
deleteNodeEdges(gctx, gctx->g, n); /* delete all edges to/from node in root graph */
- sprintf(buf,"node%p",n);
+ hndl = obj2cmd(n);
agdelete(gctx->g, n); /* delete node from root graph */
- Tcl_DeleteCommand(gctx->ictx->interp, buf);
+ Tcl_DeleteCommand(gctx->ictx->interp, hndl);
}
static void deleteGraphNodes(gctx_t * gctx, Agraph_t *g)
{
void deleteGraph(gctx_t * gctx, Agraph_t *g)
{
Agraph_t *sg;
- char buf[32];
+ char *hndl;
for (sg = agfstsubg (g); sg; sg = agnxtsubg (sg)) {
deleteGraph(gctx, sg);
}
deleteGraphNodes(gctx, g);
- sprintf(buf,"graph%p",g);
+ hndl = obj2cmd(g);
if (g == agroot(g)) {
agclose(g);
} else {
agdelsubg(agroot(g), g);
}
- Tcl_DeleteCommand(gctx->ictx->interp, buf);
+ Tcl_DeleteCommand(gctx->ictx->interp, hndl);
}
#else
void deleteEdge(ictx_t * ictx, Agraph_t * g, Agedge_t *e)
int kind;
unsigned long id;
#else
- char buf[32];
Agdesc_t kind;
#endif
GD_drawing(g) = NULL;
#ifdef WITH_CGRAPH
- sprintf(buf, "graph%p", g);
- Tcl_AppendResult(interp, buf, NULL);
+ Tcl_AppendResult(interp, obj2cmd(g), NULL);
#endif
return TCL_OK;
Tcl_Channel channel;
int mode;
#ifdef WITH_CGRAPH
- char buf[32];
ictx_t *ictx = (ictx_t *)clientData;
ictx->myioDisc.afread = myiodisc_afread; /* replace afread to use Tcl Channels */
#ifndef WITH_CGRAPH
return (tcldot_fixup((ictx_t *)clientData, g));
#else
- sprintf(buf, "graph%p", g);
- Tcl_AppendResult(interp, buf, NULL);
+ Tcl_AppendResult(interp, obj2cmd(g), NULL);
return TCL_OK;
#endif
}
{
Agraph_t *g;
#ifdef WITH_CGRAPH
- char buf[32];
ictx_t *ictx = (ictx_t *)clientData;
rdr_t rdr;
#ifndef WITH_CGRAPH
return (tcldot_fixup((ictx_t *)clientData, g));
#else
- sprintf(buf, "graph%p", g);
- Tcl_AppendResult(interp, buf, NULL);
+ Tcl_AppendResult(interp, obj2cmd(g), NULL);
return TCL_OK;
#endif
}
extern int myiodisc_memiofread(void *chan, char *buf, int bufsize);
extern Agiddisc_t myiddisc;
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 Agraph_t *cmd2g(char *cmd);
+extern Agnode_t *cmd2n(char *cmd);
+extern Agedge_t *cmd2e(char *cmd);
+extern char *obj2cmd(void *obj);
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);