Graphviz  2.41.20170921.2350
tcldot-edgecmd.c
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #include "tcldot.h"
15 
16 int edgecmd(ClientData clientData, Tcl_Interp * interp,
17 #ifndef TCLOBJ
18  int argc, char *argv[]
19 #else /* TCLOBJ */
20  int argc, Tcl_Obj * CONST objv[]
21 #endif /* TCLOBJ */
22  )
23 {
24  char c, *s, **argv2;
25  int i, j, length, argc2;
26  Agraph_t *g;
27  Agedge_t *e;
28  Agsym_t *a;
29  gctx_t *gctx = (gctx_t *)clientData;
30 
31  if (argc < 2) {
32  Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0], "\" option ?arg arg ...?", NULL);
33  return TCL_ERROR;
34  }
35  e = cmd2e(argv[0]);
36  if (!e) {
37  Tcl_AppendResult(interp, "Edge \"", argv[0], "\" not found", NULL);
38  return TCL_ERROR;
39  }
40  g = agraphof(agtail(e));
41 
42  c = argv[1][0];
43  length = strlen(argv[1]);
44 
45  if ((c == 'd') && (strncmp(argv[1], "delete", length) == 0)) {
46  deleteEdge(gctx, g, e);
47  return TCL_OK;
48 
49  } else if ((c == 'l')
50  && (strncmp(argv[1], "listattributes", length) == 0)) {
51  listEdgeAttrs (interp, g);
52  return TCL_OK;
53 
54  } else if ((c == 'l') && (strncmp(argv[1], "listnodes", length) == 0)) {
55  Tcl_AppendElement(interp, obj2cmd(agtail(e)));
56  Tcl_AppendElement(interp, obj2cmd(aghead(e)));
57  return TCL_OK;
58 
59  } else if ((c == 'q')
60  && (strncmp(argv[1], "queryattributes", length) == 0)) {
61  for (i = 2; i < argc; i++) {
62  if (Tcl_SplitList
63  (interp, argv[i], &argc2,
64  (CONST84 char ***) &argv2) != TCL_OK)
65  return TCL_ERROR;
66  for (j = 0; j < argc2; j++) {
67  if ((a = agfindedgeattr(g, argv2[j]))) {
68  Tcl_AppendElement(interp, agxget(e, a));
69  } else {
70  Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
71  return TCL_ERROR;
72  }
73  }
74  Tcl_Free((char *) argv2);
75  }
76  return TCL_OK;
77 
78  } else if ((c == 'q') && (strncmp(argv[1], "queryattributevalues", length) == 0)) {
79  for (i = 2; i < argc; i++) {
80  if (Tcl_SplitList
81  (interp, argv[i], &argc2,
82  (CONST84 char ***) &argv2) != TCL_OK)
83  return TCL_ERROR;
84  for (j = 0; j < argc2; j++) {
85  if ((a = agfindedgeattr(g, argv2[j]))) {
86  Tcl_AppendElement(interp, argv2[j]);
87  Tcl_AppendElement(interp, agxget(e, a));
88  } else {
89  Tcl_AppendResult(interp, "No attribute named \"", argv2[j], "\"", NULL);
90  return TCL_ERROR;
91  }
92  }
93  Tcl_Free((char *) argv2);
94  }
95  return TCL_OK;
96 
97  } else if ((c == 's') && (strncmp(argv[1], "setattributes", length) == 0)) {
98  if (argc == 3) {
99  if (Tcl_SplitList
100  (interp, argv[2], &argc2,
101  (CONST84 char ***) &argv2) != TCL_OK)
102  return TCL_ERROR;
103  if ((argc2 == 0) || (argc2 % 2)) {
104  Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
105  "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
106  NULL);
107  Tcl_Free((char *) argv2);
108  return TCL_ERROR;
109  }
110  setedgeattributes(agroot(g), e, argv2, argc2);
111  Tcl_Free((char *) argv2);
112  } else {
113  if ((argc < 4) || (argc % 2)) {
114  Tcl_AppendResult(interp, "Wrong # args: should be \"", argv[0],
115  "\" setattributes attributename attributevalue ?attributename attributevalue? ?...?",
116  NULL);
117  return TCL_ERROR;
118  }
119  setedgeattributes(agroot(g), e, &argv[2], argc - 2);
120  }
121  return TCL_OK;
122 
123  } else if ((c == 's') && (strncmp(argv[1], "showname", length) == 0)) {
124  if (agisdirected(g))
125  s = "->";
126  else
127  s = "--";
128  Tcl_AppendResult(interp, agnameof(agtail(e)), s, agnameof(aghead(e)), NULL);
129  return TCL_OK;
130 
131  } else {
132  Tcl_AppendResult(interp, "Bad option \"", argv[1],
133  "\": must be one of:",
134  "\n\tdelete, listattributes, listnodes,",
135  "\n\tueryattributes, queryattributevalues,",
136  "\n\tsetattributes, showname", NULL);
137  return TCL_ERROR;
138  }
139 }
char * obj2cmd(void *obj)
Definition: tcldot-util.c:55
CGRAPH_API int agisdirected(Agraph_t *g)
Definition: graph.c:182
int edgecmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
CGRAPH_API Agraph_t * agroot(void *obj)
Definition: obj.c:169
void listEdgeAttrs(Tcl_Interp *interp, Agraph_t *g)
Definition: tcldot-util.c:210
CGRAPH_API Agraph_t * agraphof(void *obj)
Definition: obj.c:185
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
Definition: edge.c:525
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
Definition: edge.c:533
CGRAPH_API char * agnameof(void *)
Definition: id.c:143
Agedge_t * cmd2e(char *cmd)
Definition: tcldot-util.c:44
void deleteEdge(gctx_t *gctx, Agraph_t *g, Agedge_t *e)
Definition: tcldot-util.c:68
#define agfindedgeattr(g, a)
Definition: types.h:614
Definition: grammar.c:79
#define NULL
Definition: logic.h:39
Definition: tcldot.h:57
void setedgeattributes(Agraph_t *g, Agedge_t *e, char *argv[], int argc)
Definition: tcldot-util.c:155
char * agxget(void *obj, Agsym_t *sym)
Definition: attr.c:444
#define CONST84
Definition: tcldot.h:25