Commit 8797323c authored by John Ellson's avatar John Ellson

Merge branch 'tcldot-fixes' into 'master'

Tcldot fixes

See merge request !1288
parents 31128093 071ddaa9
Pipeline #29710874 passed with stages
in 13 minutes and 41 seconds
......@@ -29,12 +29,12 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
gctx_t *gctx = (gctx_t *)clientData;
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;
}
e = cmd2e(argv[0]);
if (!e) {
Tcl_AppendResult(interp, "Edge \"", argv[0], "\" not found", NULL);
Tcl_AppendResult(interp, "edge \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
}
g = agraphof(agtail(e));
......@@ -42,22 +42,20 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
c = argv[1][0];
length = strlen(argv[1]);
if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
if (MATCHES_OPTION("delete", argv[1], c, length)) {
deleteEdge(gctx, g, e);
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listattributes", length) == 0)) {
} else if (MATCHES_OPTION("listattributes", argv[1], c, length)) {
listEdgeAttrs (interp, g);
return TCL_OK;
} else if ((c == 'l') && (strncmp(argv[1], "listnodes", length) == 0)) {
} else if (MATCHES_OPTION("listnodes", argv[1], c, length)) {
Tcl_AppendElement(interp, obj2cmd(agtail(e)));
Tcl_AppendElement(interp, obj2cmd(aghead(e)));
return TCL_OK;
} else if ((c == 'q')
&& (strncmp(argv[1], "queryattributes", length) == 0)) {
} else if (MATCHES_OPTION("queryattributes", argv[1], c, length)) {
for (i = 2; i < argc; i++) {
if (Tcl_SplitList
(interp, argv[i], &argc2,
......@@ -67,7 +65,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
if ((a = agfindedgeattr(g, argv2[j]))) {
Tcl_AppendElement(interp, agxget(e, a));
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
Tcl_AppendResult(interp, "no attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
}
}
......@@ -75,7 +73,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
}
return TCL_OK;
} else if ((c == 'q') && (strncmp(argv[1], "queryattributevalues", length) == 0)) {
} else if (MATCHES_OPTION("queryattributevalues", argv[1], c, length)) {
for (i = 2; i < argc; i++) {
if (Tcl_SplitList
(interp, argv[i], &argc2,
......@@ -86,7 +84,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
Tcl_AppendElement(interp, argv2[j]);
Tcl_AppendElement(interp, agxget(e, a));
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
Tcl_AppendResult(interp, "no attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
}
}
......@@ -94,14 +92,14 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
}
return TCL_OK;
} else if ((c == 's') && (strncmp(argv[1], "setattributes", length) == 0)) {
} else if (MATCHES_OPTION("setattributes", argv[1], c, length)) {
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);
......@@ -111,7 +109,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;
......@@ -120,7 +118,7 @@ int edgecmd(ClientData clientData, Tcl_Interp * interp,
}
return TCL_OK;
} else if ((c == 's') && (strncmp(argv[1], "showname", length) == 0)) {
} else if (MATCHES_OPTION("showname", argv[1], c, length)) {
if (agisdirected(g))
s = "->";
else
......@@ -129,7 +127,7 @@ int edgecmd(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\tdelete, listattributes, listnodes,",
"\n\tueryattributes, queryattributevalues,",
......
This diff is collapsed.
......@@ -22,7 +22,8 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
)
{
char c, **argv2;
int i, j, length, argc2;
int i, j, argc2;
size_t length;
Agraph_t *g;
Agnode_t *n, *head;
Agedge_t *e;
......@@ -30,12 +31,12 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
gctx_t *gctx = (gctx_t *)clientData;
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;
}
n = cmd2n(argv[0]);
if (!n) {
Tcl_AppendResult(interp, "Node \"", argv[0], "\" not found", NULL);
Tcl_AppendResult(interp, "node \"", argv[0], "\" not found", NULL);
return TCL_ERROR;
}
g = agraphof(n);
......@@ -44,20 +45,20 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
length = strlen(argv[1]);
if ((c == 'a') && (strncmp(argv[1], "addedge", length) == 0)) {
if (MATCHES_OPTION("addedge", argv[1], c, length)) {
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;
}
head = cmd2n(argv[2]);
if (!head) {
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 (agroot(g) != agroot(agraphof(head))) {
Tcl_AppendResult(interp, "Nodes ", argv[0], " and ", argv[2], " are not in the same graph.", NULL);
Tcl_AppendResult(interp, "nodes ", argv[0], " and ", argv[2], " are not in the same graph.", NULL);
return TCL_ERROR;
}
e = agedge(g, n, head, NULL, 1);
......@@ -65,53 +66,49 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
setedgeattributes(agroot(g), e, &argv[3], argc - 3);
return TCL_OK;
} else if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
} else if (MATCHES_OPTION("delete", argv[1], c, length)) {
deleteNode(gctx, g, n);
return TCL_OK;
} else if ((c == 'f') && (strncmp(argv[1], "findedge", length) == 0)) {
} else if (MATCHES_OPTION("findedge", argv[1], c, length)) {
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))) {
Tcl_AppendResult(interp, "Edge \"", argv[0], " - ", obj2cmd(head), "\" not found.", NULL);
Tcl_AppendResult(interp, "edge \"", argv[0], " - ", obj2cmd(head), "\" not found.", NULL);
return TCL_ERROR;
}
Tcl_AppendElement(interp, obj2cmd(head));
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listattributes", length) == 0)) {
} else if (MATCHES_OPTION("listattributes", argv[1], c, length)) {
listNodeAttrs (interp, g);
return TCL_OK;
} else if ((c == 'l') && (strncmp(argv[1], "listedges", length) == 0)) {
} else if (MATCHES_OPTION("listedges", argv[1], c, length)) {
for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
Tcl_AppendElement(interp, obj2cmd(e));
}
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listinedges", length) == 0)) {
} else if (MATCHES_OPTION("listinedges", argv[1], c, length)) {
for (e = agfstin(g, n); e; e = agnxtin(g, e)) {
Tcl_AppendElement(interp, obj2cmd(e));
}
return TCL_OK;
} else if ((c == 'l')
&& (strncmp(argv[1], "listoutedges", length) == 0)) {
} else if (MATCHES_OPTION("listoutedges", argv[1], c, length)) {
for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
Tcl_AppendElement(interp, obj2cmd(e));
}
return TCL_OK;
} else if ((c == 'q')
&& (strncmp(argv[1], "queryattributes", length) == 0)) {
} else if (MATCHES_OPTION("queryattributes", argv[1], c, length)) {
for (i = 2; i < argc; i++) {
if (Tcl_SplitList
(interp, argv[i], &argc2,
......@@ -121,7 +118,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
if ((a = agfindnodeattr(g, argv2[j]))) {
Tcl_AppendElement(interp, agxget(n, a));
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
Tcl_AppendResult(interp, "no attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
}
}
......@@ -129,9 +126,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
}
return TCL_OK;
} else if ((c == 'q')
&& (strncmp(argv[1], "queryattributevalues", length) ==
0)) {
} else if (MATCHES_OPTION("queryattributevalues", argv[1], c, length)) {
for (i = 2; i < argc; i++) {
if (Tcl_SplitList
(interp, argv[i], &argc2,
......@@ -142,7 +137,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
Tcl_AppendElement(interp, argv2[j]);
Tcl_AppendElement(interp, agxget(n, a));
} else {
Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
Tcl_AppendResult(interp, "no attribute named \"", argv2[j], "\"", NULL);
return TCL_ERROR;
}
}
......@@ -150,8 +145,7 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
}
return TCL_OK;
} else if ((c == 's')
&& (strncmp(argv[1], "setattributes", length) == 0)) {
} else if (MATCHES_OPTION("setattributes", argv[1], c, length)) {
g = agroot(g);
if (argc == 3) {
if (Tcl_SplitList
......@@ -159,7 +153,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);
......@@ -169,7 +163,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;
......@@ -178,12 +172,12 @@ int nodecmd(ClientData clientData, Tcl_Interp * interp,
}
return TCL_OK;
} else if ((c == 's') && (strncmp(argv[1], "showname", length) == 0)) {
} else if (MATCHES_OPTION("showname", argv[1], c, length)) {
Tcl_SetResult(interp, agnameof(n), TCL_STATIC);
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,",
......
......@@ -25,7 +25,8 @@ static int dotnew(ClientData clientData, Tcl_Interp * interp,
ictx_t *ictx = (ictx_t *)clientData;
Agraph_t *g;
char c;
int i, length;
int i;
size_t length;
Agdesc_t kind;
if ((argc < 2)) {
......@@ -36,15 +37,13 @@ static int dotnew(ClientData clientData, Tcl_Interp * interp,
}
c = argv[1][0];
length = strlen(argv[1]);
if ((c == 'd') && (strncmp(argv[1], "digraph", length) == 0)) {
if (MATCHES_OPTION("digraph", argv[1], c, length)) {
kind = Agdirected;
} else if ((c == 'd')
&& (strncmp(argv[1], "digraphstrict", length) == 0)) {
} else if (MATCHES_OPTION("digraphstrict", argv[1], c, length)) {
kind = Agstrictdirected;
} else if ((c == 'g') && (strncmp(argv[1], "graph", length) == 0)) {
} else if (MATCHES_OPTION("graph", argv[1], c, length)) {
kind = Agundirected;
} else if ((c == 'g')
&& (strncmp(argv[1], "graphstrict", length) == 0)) {
} else if (MATCHES_OPTION("graphstrict", argv[1], c, length)) {
kind = Agstrictundirected;
} else {
Tcl_AppendResult(interp, "bad graphtype \"", argv[1], "\": must be one of:",
......@@ -86,7 +85,7 @@ static int dotread(ClientData clientData, Tcl_Interp * interp,
ictx->myioDisc.afread = myiodisc_afread; /* replace afread to use Tcl Channels */
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);
......@@ -128,15 +127,16 @@ static int dotstring(ClientData clientData, Tcl_Interp * interp,
ictx_t *ictx = (ictx_t *)clientData;
rdr_t rdr;
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " string\"", NULL);
return TCL_ERROR;
}
ictx->myioDisc.afread = myiodisc_memiofread; /* replace afread to use memory range */
rdr.data = argv[1];
rdr.len = strlen(rdr.data);
rdr.cur = 0;
if (argc < 2) {
Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], " string\"", NULL);
return TCL_ERROR;
}
/* agmemread() is broken for our use because it replaces the id disc */
g = agread(&rdr, (Agdisc_t *)clientData);
if (!g) {
......
......@@ -117,3 +117,11 @@ extern size_t Tcldot_string_writer(GVJ_t *job, const char *s, size_t len);
extern size_t Tcldot_channel_writer(GVJ_t *job, const char *s, size_t len);
extern void tcldot_layout(GVC_t *gvc, Agraph_t * g, char *engine);
/* Check whether string str corresponds to option opname.
* opname: literal string.
* str: the string to check.
* str0: first character of str.
* strn: length of str. */
#define MATCHES_OPTION(opname, str, str0, strn) \
(opname[0] == str0) && (sizeof(opname)-1 == strn) && (strncmp(opname, str, sizeof(opname)) == 0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment