16 int graphcmd(ClientData clientData, Tcl_Interp * interp,
18 int argc,
char *argv[]
20 int argc, Tcl_Obj * CONST objv[]
31 char c, buf[256], **argv2;
32 int i, j, length, argc2, rc;
37 Tcl_AppendResult(interp,
"Wrong # args: should be \"", argv[0],
" option ?arg arg ...?\"",
NULL);
42 Tcl_AppendResult(interp,
"Graph \"", argv[0],
"\" not found",
NULL);
47 length = strlen(argv[1]);
49 if ((c ==
'a') && (strncmp(argv[1],
"addedge", length) == 0)) {
50 if ((argc < 4) || (argc % 2)) {
51 Tcl_AppendResult(interp,
"Wrong # args: should be \"", argv[0],
52 " addedge tail head ?attributename attributevalue? ?...?\"",
56 tail =
cmd2n(argv[2]);
59 Tcl_AppendResult(interp,
"Tail node \"", argv[2],
"\" not found.",
NULL);
64 Tcl_AppendResult(interp,
"Tail node ", argv[2],
" is not in the graph.",
NULL);
67 head =
cmd2n(argv[3]);
70 Tcl_AppendResult(interp,
"Head node \"", argv[3],
"\" not found.",
NULL);
75 Tcl_AppendResult(interp,
"Head node ", argv[3],
" is not in the graph.",
NULL);
83 }
else if ((c ==
'a') && (strncmp(argv[1],
"addnode", length) == 0)) {
97 && (strncmp(argv[1],
"addsubgraph", length) == 0)) {
99 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
100 "\" addsubgraph ?name? ?attributename attributevalue? ?...?",
105 sg =
agsubg(g, argv[2], 1);
115 }
else if ((c ==
'c') && (strncmp(argv[1],
"countnodes", length) == 0)) {
117 Tcl_AppendResult(interp, buf,
NULL);
120 }
else if ((c ==
'c') && (strncmp(argv[1],
"countedges", length) == 0)) {
122 Tcl_AppendResult(interp, buf,
NULL);
125 }
else if ((c ==
'd') && (strncmp(argv[1],
"delete", length) == 0)) {
129 }
else if ((c ==
'f') && (strncmp(argv[1],
"findedge", length) == 0)) {
131 Tcl_AppendResult(interp,
"wrong # args: should be \"",
132 argv[0],
" findedge tailnodename headnodename\"",
NULL);
136 Tcl_AppendResult(interp,
"Tail node \"", argv[2],
"\" not found.",
NULL);
140 Tcl_AppendResult(interp,
"Head node \"", argv[3],
"\" not found.",
NULL);
144 Tcl_AppendResult(interp,
"Edge \"", argv[2],
" - ", argv[3],
"\" not found.",
NULL);
147 Tcl_AppendElement(interp,
obj2cmd(e));
150 }
else if ((c ==
'f') && (strncmp(argv[1],
"findnode", length) == 0)) {
152 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
" findnode nodename\"",
NULL);
156 Tcl_AppendResult(interp,
"Node not found.",
NULL);
162 }
else if ((c ==
'l')
163 && (strncmp(argv[1],
"layoutedges", length) == 0)) {
165 if (!
aggetrec (g,
"Agraphinfo_t",0))
169 }
else if ((c ==
'l')
170 && (strncmp(argv[1],
"layoutnodes", length) == 0)) {
172 if (!
aggetrec (g,
"Agraphinfo_t",0))
176 }
else if ((c ==
'l')
177 && (strncmp(argv[1],
"listattributes", length) == 0)) {
181 }
else if ((c ==
'l')
182 && (strncmp(argv[1],
"listedgeattributes", length) == 0)) {
186 }
else if ((c ==
'l')
187 && (strncmp(argv[1],
"listnodeattributes", length) == 0)) {
191 }
else if ((c ==
'l') && (strncmp(argv[1],
"listedges", length) == 0)) {
194 Tcl_AppendElement(interp,
obj2cmd(e));
199 }
else if ((c ==
'l') && (strncmp(argv[1],
"listnodes", length) == 0)) {
201 Tcl_AppendElement(interp,
obj2cmd(n));
206 }
else if ((c ==
'l')
207 && (strncmp(argv[1],
"listnodesrev", length) == 0)) {
209 Tcl_AppendElement(interp,
obj2cmd(n));
213 }
else if ((c ==
'l')
214 && (strncmp(argv[1],
"listsubgraphs", length) == 0)) {
216 Tcl_AppendElement(interp,
obj2cmd(g));
220 }
else if ((c ==
'q')
221 && (strncmp(argv[1],
"queryattributes", length) == 0)) {
222 for (i = 2; i < argc; i++) {
224 (interp, argv[i], &argc2,
225 (
CONST84 char ***) &argv2) != TCL_OK)
227 for (j = 0; j < argc2; j++) {
229 Tcl_AppendElement(interp,
agxget(g, a));
231 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
NULL);
235 Tcl_Free((
char *) argv2);
239 }
else if ((c ==
'q')
240 && (strncmp(argv[1],
"queryattributevalues", length) ==
242 for (i = 2; i < argc; i++) {
244 (interp, argv[i], &argc2,
245 (
CONST84 char ***) &argv2) != TCL_OK)
247 for (j = 0; j < argc2; j++) {
249 Tcl_AppendElement(interp, argv2[j]);
250 Tcl_AppendElement(interp,
agxget(g, a));
252 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
NULL);
256 Tcl_Free((
char *) argv2);
260 }
else if ((c ==
'q')
261 && (strncmp(argv[1],
"queryedgeattributes", length) == 0)) {
262 for (i = 2; i < argc; i++) {
264 (interp, argv[i], &argc2,
265 (
CONST84 char ***) &argv2) != TCL_OK)
267 for (j = 0; j < argc2; j++) {
269 Tcl_AppendElement(interp,
agxget(g, a));
271 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
NULL);
275 Tcl_Free((
char *) argv2);
279 }
else if ((c ==
'q')
280 && (strncmp(argv[1],
"queryedgeattributevalues", length) == 0)) {
281 for (i = 2; i < argc; i++) {
283 (interp, argv[i], &argc2,
284 (
CONST84 char ***) &argv2) != TCL_OK)
286 for (j = 0; j < argc2; j++) {
288 Tcl_AppendElement(interp, argv2[j]);
289 Tcl_AppendElement(interp,
agxget(g, a));
291 Tcl_AppendResult(interp,
" No attribute named \"",
292 argv2[j],
"\"",
NULL);
296 Tcl_Free((
char *) argv2);
300 }
else if ((c ==
'q')
301 && (strncmp(argv[1],
"querynodeattributes", length) == 0)) {
302 for (i = 2; i < argc; i++) {
304 (interp, argv[i], &argc2,
305 (
CONST84 char ***) &argv2) != TCL_OK)
307 for (j = 0; j < argc2; j++) {
309 Tcl_AppendElement(interp,
agxget(g, a));
311 Tcl_AppendResult(interp,
" No attribute named \"",
312 argv2[j],
"\"",
NULL);
316 Tcl_Free((
char *) argv2);
320 }
else if ((c ==
'q')
321 && (strncmp(argv[1],
"querynodeattributevalues", length) ==
323 for (i = 2; i < argc; i++) {
325 (interp, argv[i], &argc2,
326 (
CONST84 char ***) &argv2) != TCL_OK)
328 for (j = 0; j < argc2; j++) {
330 Tcl_AppendElement(interp, argv2[j]);
331 Tcl_AppendElement(interp,
agxget(g, a));
333 Tcl_AppendResult(interp,
" No attribute named \"", argv2[j],
"\"",
NULL);
337 Tcl_Free((
char *) argv2);
341 }
else if ((c ==
'r') && (strncmp(argv[1],
"render", length) == 0)) {
350 tkgendata.eval =
FALSE;
352 if ((Tcl_GetBoolean(interp, argv[3], &tkgendata.eval)) !=
354 Tcl_AppendResult(interp,
" Invalid boolean: \"",
355 argv[3],
"\"",
NULL);
363 Tcl_AppendResult(interp,
" Format: \"tk\" not recognized.\n",
NULL);
376 if (!
aggetrec (g,
"Agraphinfo_t",0) || argc > 3)
390 }
else if ((c ==
'r') && (strncmp(argv[1],
"rendergd", length) == 0)) {
396 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
397 " rendergd gdhandle ?DOT|NEATO|TWOPI|FDP|CIRCO?\"",
NULL);
402 Tcl_AppendResult(interp,
" Format: \"gd\" not recognized.\n",
NULL);
408 if (! (hdl = tclhandleXlate(GDHandleTable, argv[2]))) {
409 Tcl_AppendResult(interp,
"GD Image not found.",
NULL);
414 job->
context = (
void*)(((Tcl_Obj*)(argv[2]))->internalRep.otherValuePtr);
420 if (!
aggetrec (g,
"Agraphinfo_t",0) || argc > 4)
429 Tcl_AppendResult(interp, argv[2], NULL);
434 }
else if ((c ==
's')
435 && (strncmp(argv[1],
"setattributes", length) == 0)) {
438 (interp, argv[2], &argc2,
439 (
CONST84 char ***) &argv2) != TCL_OK)
441 if ((argc2 == 0) || (argc2 % 2)) {
442 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
443 "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
445 Tcl_Free((
char *) argv2);
449 Tcl_Free((
char *) argv2);
451 if (argc == 4 && strcmp(argv[2],
"viewport") == 0) {
455 if ((argc < 4) || (argc % 2)) {
456 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
457 "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
465 }
else if ((c ==
's')
466 && (strncmp(argv[1],
"setedgeattributes", length) == 0)) {
469 (interp, argv[2], &argc2,
470 (
CONST84 char ***) &argv2) != TCL_OK)
472 if ((argc2 == 0) || (argc2 % 2)) {
473 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
474 "\" setedgeattributes attributename attributevalue ?attributename attributevalue? ?...?",
476 Tcl_Free((
char *) argv2);
480 Tcl_Free((
char *) argv2);
482 if ((argc < 4) || (argc % 2)) {
483 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
484 "\" setedgeattributes attributename attributevalue ?attributename attributevalue? ?...?",
491 }
else if ((c ==
's')
492 && (strncmp(argv[1],
"setnodeattributes", length) == 0)) {
495 (interp, argv[2], &argc2,
496 (
CONST84 char ***) &argv2) != TCL_OK)
498 if ((argc2 == 0) || (argc2 % 2)) {
499 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
500 "\" setnodeattributes attributename attributevalue ?attributename attributevalue? ?...?",
502 Tcl_Free((
char *) argv2);
506 Tcl_Free((
char *) argv2);
508 if ((argc < 4) || (argc % 2)) {
509 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
510 "\" setnodeattributes attributename attributevalue ?attributename attributevalue? ?...?",
517 }
else if ((c ==
's') && (strncmp(argv[1],
"showname", length) == 0)) {
518 Tcl_SetResult(interp,
agnameof(g), TCL_STATIC);
521 }
else if ((c ==
'w') && (strncmp(argv[1],
"write", length) == 0)) {
524 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
525 " write fileHandle ?language ?DOT|NEATO|TWOPI|FDP|CIRCO|NOP??\"",
538 Tcl_AppendResult(interp,
"Bad langname: \"", argv[3],
"\". Use one of:", s,
NULL);
556 chan = Tcl_GetChannel(interp, argv[2], &mode);
559 Tcl_AppendResult(interp,
"Channel not open: \"", argv[2],
NULL);
562 if (!(mode & TCL_WRITABLE)) {
563 Tcl_AppendResult(interp,
"Channel not writable: \"", argv[2],
NULL);
582 Tcl_AppendResult(interp,
"bad option \"", argv[1],
583 "\": must be one of:",
584 "\n\taddedge, addnode, addsubgraph, countedges, countnodes,",
585 "\n\tlayout, listattributes, listedgeattributes, listnodeattributes,",
586 "\n\tlistedges, listnodes, listsubgraphs, render, rendergd,",
587 "\n\tqueryattributes, queryedgeattributes, querynodeattributes,",
588 "\n\tqueryattributevalues, queryedgeattributevalues, querynodeattributevalues,",
589 "\n\tsetattributes, setedgeattributes, setnodeattributes,",
590 "\n\tshowname, write.",
NULL);
Agraph_t * cmd2g(char *cmd)
CGRAPH_API Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
#define LAYOUT_NOT_REQUIRED
void listNodeAttrs(Tcl_Interp *interp, Agraph_t *g)
Agnode_t * cmd2n(char *cmd)
void setgraphattributes(Agraph_t *g, char *argv[], int argc)
char * obj2cmd(void *obj)
CGRAPH_API Agnode_t * agprvnode(Agraph_t *g, Agnode_t *n)
void listGraphAttrs(Tcl_Interp *interp, Agraph_t *g)
int gvRenderJobs(GVC_t *gvc, graph_t *g)
const char * output_filename
CGRAPH_API Agraph_t * agfstsubg(Agraph_t *g)
CGRAPH_API Agraph_t * agroot(void *obj)
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
void listEdgeAttrs(Tcl_Interp *interp, Agraph_t *g)
CGRAPH_API Agraph_t * agraphof(void *obj)
CGRAPH_API Agraph_t * agnxtsubg(Agraph_t *subg)
size_t Tcldot_channel_writer(GVJ_t *job, const char *s, size_t len)
CGRAPH_API Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
void gvdevice_finalize(GVJ_t *job)
CGRAPH_API char * agnameof(void *)
size_t Tcldot_string_writer(GVJ_t *job, const char *s, size_t len)
#define agfindedgeattr(g, a)
CGRAPH_API Agnode_t * aglstnode(Agraph_t *g)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
CGRAPH_API Agrec_t * aggetrec(void *obj, char *name, int move_to_front)
#define agfindgraphattr(g, a)
void setedgeattributes(Agraph_t *g, Agedge_t *e, char *argv[], int argc)
CGRAPH_API int agnnodes(Agraph_t *g)
char * gvplugin_list(GVC_t *gvc, api_t api, const char *str)
CGRAPH_API Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
int graphcmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
boolean gvjobs_output_langname(GVC_t *gvc, const char *name)
void setnodeattributes(Agraph_t *g, Agnode_t *n, char *argv[], int argc)
#define agfindedge(g, t, h)
void deleteGraph(gctx_t *gctx, Agraph_t *g)
CGRAPH_API int agnedges(Agraph_t *g)
void gvrender_end_job(GVJ_t *job)
int gvrender_select(GVJ_t *job, const char *lang)
char * agxget(void *obj, Agsym_t *sym)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
void tcldot_layout(GVC_t *gvc, Agraph_t *g, char *engine)
void gvjobs_delete(GVC_t *gvc)
#define agfindnodeattr(g, a)
const char * output_langname
size_t(* write_fn)(GVJ_t *job, const char *s, size_t len)