17 int argc,
char *argv[]) {
24 char buf[12], **argv2;
29 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
30 " option ?arg arg ...?\"",
NULL);
35 Tcl_AppendResult(interp,
"graph \"", argv[0],
"\" not found",
NULL);
39 if (
streq(
"addedge", argv[1])) {
40 if ((argc < 4) || (argc % 2)) {
42 interp,
"wrong # args: should be \"", argv[0],
43 " addedge tail head ?attributename attributevalue? ?...?\"",
NULL);
46 tail =
cmd2n(argv[2]);
49 Tcl_AppendResult(interp,
"tail node \"", argv[2],
"\" not found.",
55 Tcl_AppendResult(interp,
"tail node ", argv[2],
" is not in the graph.",
62 Tcl_AppendResult(interp,
"head node \"", argv[3],
"\" not found.",
68 Tcl_AppendResult(interp,
"head node ", argv[3],
" is not in the graph.",
77 }
else if (
streq(
"addnode", argv[1])) {
91 }
else if (
streq(
"addsubgraph", argv[1])) {
95 interp,
"wrong # args: should be \"", argv[0],
96 "\" addsubgraph ?name? ?attributename attributevalue? ?...?",
NULL);
100 sg =
agsubg(g, argv[2], 1);
110 }
else if (
streq(
"countnodes", argv[1])) {
111 snprintf(buf,
sizeof(buf),
"%d",
agnnodes(g));
112 Tcl_AppendResult(interp, buf,
NULL);
115 }
else if (
streq(
"countedges", argv[1])) {
116 snprintf(buf,
sizeof(buf),
"%d",
agnedges(g));
117 Tcl_AppendResult(interp, buf,
NULL);
120 }
else if (
streq(
"delete", argv[1])) {
124 }
else if (
streq(
"findedge", argv[1])) {
126 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
127 " findedge tailnodename headnodename\"",
NULL);
131 Tcl_AppendResult(interp,
"tail node \"", argv[2],
"\" not found.",
NULL);
135 Tcl_AppendResult(interp,
"head node \"", argv[3],
"\" not found.",
NULL);
139 Tcl_AppendResult(interp,
"edge \"", argv[2],
" - ", argv[3],
140 "\" not found.",
NULL);
143 Tcl_AppendElement(interp,
obj2cmd(e));
146 }
else if (
streq(
"findnode", argv[1])) {
148 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
149 " findnode nodename\"",
NULL);
153 Tcl_AppendResult(interp,
"node not found.",
NULL);
159 }
else if (
streq(
"layoutedges", argv[1])) {
161 if (!
aggetrec(g,
"Agraphinfo_t", 0))
165 }
else if (
streq(
"layoutnodes", argv[1])) {
167 if (!
aggetrec(g,
"Agraphinfo_t", 0))
171 }
else if (
streq(
"listattributes", argv[1])) {
175 }
else if (
streq(
"listedgeattributes", argv[1])) {
179 }
else if (
streq(
"listnodeattributes", argv[1])) {
183 }
else if (
streq(
"listedges", argv[1])) {
186 Tcl_AppendElement(interp,
obj2cmd(e));
191 }
else if (
streq(
"listnodes", argv[1])) {
193 Tcl_AppendElement(interp,
obj2cmd(n));
197 }
else if (
streq(
"listnodesrev", argv[1])) {
199 Tcl_AppendElement(interp,
obj2cmd(n));
203 }
else if (
streq(
"listsubgraphs", argv[1])) {
205 Tcl_AppendElement(interp,
obj2cmd(sg));
209 }
else if (
streq(
"queryattributes", argv[1])) {
210 for (
int i = 2; i < argc; i++) {
211 if (Tcl_SplitList(interp, argv[i], &argc2, (
const char ***)&argv2) !=
214 for (j = 0; j < argc2; j++) {
216 Tcl_AppendElement(interp,
agxget(g, a));
218 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
220 Tcl_Free((
char *)argv2);
224 Tcl_Free((
char *)argv2);
228 }
else if (
streq(
"queryattributevalues", argv[1])) {
229 for (
int i = 2; i < argc; i++) {
230 if (Tcl_SplitList(interp, argv[i], &argc2, (
const char ***)&argv2) !=
233 for (j = 0; j < argc2; j++) {
235 Tcl_AppendElement(interp, argv2[j]);
236 Tcl_AppendElement(interp,
agxget(g, a));
238 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
240 Tcl_Free((
char *)argv2);
244 Tcl_Free((
char *)argv2);
248 }
else if (
streq(
"queryedgeattributes", argv[1])) {
249 for (
int i = 2; i < argc; i++) {
250 if (Tcl_SplitList(interp, argv[i], &argc2, (
const char ***)&argv2) !=
253 for (j = 0; j < argc2; j++) {
255 Tcl_AppendElement(interp,
agxget(g, a));
257 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
259 Tcl_Free((
char *)argv2);
263 Tcl_Free((
char *)argv2);
267 }
else if (
streq(
"queryedgeattributevalues", argv[1])) {
268 for (
int i = 2; i < argc; i++) {
269 if (Tcl_SplitList(interp, argv[i], &argc2, (
const char ***)&argv2) !=
272 for (j = 0; j < argc2; j++) {
274 Tcl_AppendElement(interp, argv2[j]);
275 Tcl_AppendElement(interp,
agxget(g, a));
277 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
279 Tcl_Free((
char *)argv2);
283 Tcl_Free((
char *)argv2);
287 }
else if (
streq(
"querynodeattributes", argv[1])) {
288 for (
int i = 2; i < argc; i++) {
289 if (Tcl_SplitList(interp, argv[i], &argc2, (
const char ***)&argv2) !=
292 for (j = 0; j < argc2; j++) {
294 Tcl_AppendElement(interp,
agxget(g, a));
296 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
298 Tcl_Free((
char *)argv2);
302 Tcl_Free((
char *)argv2);
306 }
else if (
streq(
"querynodeattributevalues", argv[1])) {
307 for (
int i = 2; i < argc; i++) {
308 if (Tcl_SplitList(interp, argv[i], &argc2, (
const char ***)&argv2) !=
311 for (j = 0; j < argc2; j++) {
313 Tcl_AppendElement(interp, argv2[j]);
314 Tcl_AppendElement(interp,
agxget(g, a));
316 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
318 Tcl_Free((
char *)argv2);
322 Tcl_Free((
char *)argv2);
326 }
else if (
streq(
"render", argv[1])) {
340 if (!
aggetrec(g,
"Agraphinfo_t", 0) || argc > 3)
351 }
else if (
streq(
"setattributes", argv[1])) {
353 if (Tcl_SplitList(interp, argv[2], &argc2, (
const char ***)&argv2) !=
356 if ((argc2 == 0) || (argc2 % 2)) {
357 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
358 "\" setattributes attributename attributevalue "
359 "?attributename attributevalue? ?...?",
361 Tcl_Free((
char *)argv2);
365 Tcl_Free((
char *)argv2);
367 if (argc == 4 &&
streq(argv[2],
"viewport")) {
371 if ((argc < 4) || (argc % 2)) {
372 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
373 "\" setattributes attributename attributevalue "
374 "?attributename attributevalue? ?...?",
382 }
else if (
streq(
"setedgeattributes", argv[1])) {
384 if (Tcl_SplitList(interp, argv[2], &argc2, (
const char ***)&argv2) !=
387 if ((argc2 == 0) || (argc2 % 2)) {
388 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
389 "\" setedgeattributes attributename attributevalue "
390 "?attributename attributevalue? ?...?",
392 Tcl_Free((
char *)argv2);
396 Tcl_Free((
char *)argv2);
398 if ((argc < 4) || (argc % 2)) {
399 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
400 "\" setedgeattributes attributename attributevalue "
401 "?attributename attributevalue? ?...?",
408 }
else if (
streq(
"setnodeattributes", argv[1])) {
410 if (Tcl_SplitList(interp, argv[2], &argc2, (
const char ***)&argv2) !=
413 if ((argc2 == 0) || (argc2 % 2)) {
414 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
415 "\" setnodeattributes attributename attributevalue "
416 "?attributename attributevalue? ?...?",
418 Tcl_Free((
char *)argv2);
422 Tcl_Free((
char *)argv2);
424 if ((argc < 4) || (argc % 2)) {
425 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
426 "\" setnodeattributes attributename attributevalue "
427 "?attributename attributevalue? ?...?",
434 }
else if (
streq(
"showname", argv[1])) {
435 Tcl_SetResult(interp,
agnameof(g), TCL_STATIC);
437 }
else if (
streq(
"write", argv[1])) {
441 interp,
"wrong # args: should be \"", argv[0],
442 " write fileHandle ?language ?DOT|NEATO|TWOPI|FDP|CIRCO|NOP??\"",
453 chan = Tcl_GetChannel(interp, argv[2], &
mode);
456 Tcl_AppendResult(interp,
"channel not open: \"", argv[2],
NULL);
459 if (!(
mode & TCL_WRITABLE)) {
460 Tcl_AppendResult(interp,
"channel not writable: \"", argv[2],
NULL);
466 if (!
aggetrec(g,
"Agraphinfo_t", 0) || argc > 4)
470 if (
gvRender(
gvc, g, argc < 4 ?
"dot" : argv[3], (FILE *)chan) != 0) {
477 interp,
"bad option \"", argv[1],
"\": must be one of:",
478 "\n\taddedge, addnode, addsubgraph, countedges, countnodes,",
479 "\n\tlayout, listattributes, listedgeattributes, listnodeattributes,",
480 "\n\tlistedges, listnodes, listsubgraphs, render, rendergd,",
481 "\n\tqueryattributes, queryedgeattributes, querynodeattributes,",
482 "\n\tqueryattributevalues, queryedgeattributevalues, "
483 "querynodeattributevalues,",
484 "\n\tsetattributes, setedgeattributes, setnodeattributes,",
485 "\n\tshowname, write.",
NULL);
context used to convey information between commands and a renderer