13#include "../tcl-compat.h"
30 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
31 " option ?arg arg ...?\"",
NULL);
36 Tcl_AppendResult(interp,
"node \"", argv[0],
"\" not found",
NULL);
41 if (
streq(
"addedge", argv[1])) {
42 if (argc < 3 || argc % 2 == 0) {
43 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
44 " addedge head ?attributename attributevalue? ?...?\"",
51 Tcl_AppendResult(interp,
"head node \"", argv[2],
"\" not found.",
57 Tcl_AppendResult(interp,
"nodes ", argv[0],
" and ", argv[2],
58 " are not in the same graph.",
NULL);
66 }
else if (
streq(
"delete", argv[1])) {
70 }
else if (
streq(
"findedge", argv[1])) {
72 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
73 " findedge headnodename\"",
NULL);
77 Tcl_AppendResult(interp,
"head node \"", argv[2],
"\" not found.",
NULL);
81 Tcl_AppendResult(interp,
"edge \"", argv[0],
" - ",
obj2cmd(
head),
82 "\" not found.",
NULL);
88 }
else if (
streq(
"listattributes", argv[1])) {
92 }
else if (
streq(
"listedges", argv[1])) {
94 Tcl_AppendElement(interp,
obj2cmd(e));
98 }
else if (
streq(
"listinedges", argv[1])) {
100 Tcl_AppendElement(interp,
obj2cmd(e));
104 }
else if (
streq(
"listoutedges", argv[1])) {
106 Tcl_AppendElement(interp,
obj2cmd(e));
110 }
else if (
streq(
"queryattributes", argv[1])) {
111 for (i = 2; i < argc; i++) {
113 if (Tcl_SplitList(interp, argv[i], &argc2, &argv2) != TCL_OK)
115 for (
Tcl_Size j = 0; j < argc2; j++) {
116 char *arg = strdup(argv2[j]);
118 Tcl_AppendElement(interp,
agxget(n, a));
120 Tcl_AppendResult(interp,
"no attribute named \"", arg,
"\"",
NULL);
122 Tcl_Free((
char *)argv2);
127 Tcl_Free((
char *)argv2);
131 }
else if (
streq(
"queryattributevalues", argv[1])) {
132 for (i = 2; i < argc; i++) {
134 if (Tcl_SplitList(interp, argv[i], &argc2, &argv2) != TCL_OK)
136 for (
Tcl_Size j = 0; j < argc2; j++) {
137 char *arg = strdup(argv2[j]);
139 Tcl_AppendElement(interp, arg);
140 Tcl_AppendElement(interp,
agxget(n, a));
142 Tcl_AppendResult(interp,
"no attribute named \"", arg,
"\"",
NULL);
144 Tcl_Free((
char *)argv2);
149 Tcl_Free((
char *)argv2);
153 }
else if (
streq(
"setattributes", argv[1])) {
157 if (Tcl_SplitList(interp, argv[2], &argc2, &argv2) != TCL_OK)
159 if (argc2 == 0 || argc2 % 2 != 0) {
160 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
161 "\" setattributes attributename attributevalue "
162 "?attributename attributevalue? ?...?",
164 Tcl_Free((
char *)argv2);
170 Tcl_Free((
char *)argv2);
172 if (argc < 4 || argc % 2 != 0) {
173 Tcl_AppendResult(interp,
"wrong # args: should be \"", argv[0],
174 "\" setattributes attributename attributevalue "
175 "?attributename attributevalue? ?...?",
183 }
else if (
streq(
"showname", argv[1])) {
184 Tcl_SetResult(interp,
agnameof(n), TCL_STATIC);
188 Tcl_AppendResult(interp,
"bad option \"", argv[1],
"\": must be one of:",
189 "\n\taddedge, listattributes, listedges, listinedges,",
190 "\n\tlistoutedges, queryattributes, queryattributevalues,",
191 "\n\tsetattributes, showname.",
NULL);
196int nodecmd(ClientData clientData, Tcl_Interp *interp,
int argc,
197 const char *argv[]) {
char * agxget(void *obj, Agsym_t *sym)
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
#define agfindedge(g, t, h)
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
#define agfindnodeattr(g, a)
Agraph_t * agraphof(void *obj)
char * agnameof(void *)
returns a string descriptor for the object.
Agraph_t * agroot(void *obj)
static bool streq(const char *a, const char *b)
are a and b equal?
static int nodecmd_internal(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
int nodecmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
void tcldot_argv_free(Tcl_Size argc, char *argv[])
free the strings pointed to by argv
void listNodeAttrs(Tcl_Interp *interp, Agraph_t *g)
void deleteNode(gctx_t *gctx, Agraph_t *g, Agnode_t *n)
char * obj2cmd(void *obj)
void setnodeattributes(Agraph_t *g, Agnode_t *n, char *argv[], Tcl_Size argc)
char ** tcldot_argv_dup(Tcl_Size argc, const char *argv[])
duplicate the strings pointed to by argv as non-const strings
void setedgeattributes(Agraph_t *g, Agedge_t *e, char *argv[], Tcl_Size argc)
Agnode_t * cmd2n(const char *cmd)