Graphviz  2.41.20170921.2350
tcldot-id.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 
15 #include "tcldot.h"
16 
17 // Agiddisc functions
18 static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
19  ictx_t *ictx = (ictx_t *)disc;
20  gctx_t *gctx;
21 
22  gctx = (gctx_t *)malloc(sizeof(gctx_t));
23  gctx->g = g;
24  gctx->ictx = ictx;
25  return (void *)gctx;
26 }
27 static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag) {
28  gctx_t *gctx = (gctx_t *)state;
29  ictx_t *ictx = gctx->ictx;
30  char *s;
31 
32  if (str) {
33  if (createflag)
34  s = agstrdup(gctx->g, str);
35  else
36  s = agstrbind(gctx->g, str);
37  *id = (uint64_t) s;
38  } else {
39  *id = ictx->ctr; /* counter maintained in per-interp space, so that
40  ids are unique across all graphs in the interp */
41  ictx->ctr += 2;
42  }
43  return TRUE;
44 }
45 /* we don't allow users to explicitly set IDs, either */
46 static long myiddisc_alloc(void *state, int objtype, uint64_t request_id) {
47  NOTUSED(state);
48  NOTUSED(objtype);
49  NOTUSED(request_id);
50  return FALSE;
51 }
52 static void myiddisc_free(void *state, int objtype, uint64_t id) {
53  gctx_t *gctx = (gctx_t *)state;
54 
55 /* FIXME no obj* available
56  ictx_t *ictx = gctx->ictx;
57  char buf[32] = "";
58 
59  switch (objtype) {
60  case AGRAPH: sprintf(buf,"graph%lu",id); break;
61  case AGNODE: sprintf(buf,"node%lu",id); break;
62  case AGINEDGE:
63  case AGOUTEDGE: sprintf(buf,"edge%lu",id); break;
64  }
65  Tcl_DeleteCommand(ictx->interp, buf);
66 */
67  if (id % 2 == 0)
68  agstrfree(gctx->g, (char *) id);
69 }
70 static char *myiddisc_print(void *state, int objtype, uint64_t id) {
71  NOTUSED(state);
72  NOTUSED(objtype);
73  if (id % 2 == 0)
74  return (char *) id;
75  else
76  return "";
77 }
78 static void myiddisc_close(void *state) {
79  free(state);
80 }
81 static void myiddisc_idregister(void *state, int objtype, void *obj) {
82  gctx_t *gctx = (gctx_t *)state;
83  ictx_t *ictx = gctx->ictx;
84  Tcl_Interp *interp = ictx->interp;
85  Tcl_CmdProc *proc = NULL;
86 
87  switch (objtype) {
88  case AGRAPH: proc=graphcmd; break;
89  case AGNODE: proc=nodecmd; break;
90  case AGINEDGE:
91  case AGOUTEDGE: proc=edgecmd; break;
92  }
93 #ifndef TCLOBJ
94  Tcl_CreateCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
95 #else
96  Tcl_CreateObjCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, (Tcl_CmdDeleteProc *) NULL);
97 #endif
98 }
100  myiddisc_open,
101  myiddisc_map,
102  myiddisc_alloc,
103  myiddisc_free,
104  myiddisc_print,
105  myiddisc_close,
106  myiddisc_idregister
107 };
Agraph_t * g
Definition: tcldot.h:58
Definition: tcldot.h:46
char * obj2cmd(void *obj)
Definition: tcldot-util.c:55
int edgecmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
#define NOTUSED(var)
Definition: cghdr.h:54
Agiddisc_t myiddisc
Definition: tcldot-id.c:99
#define AGOUTEDGE
Definition: cgraph.h:102
CGRAPH_API int agstrfree(Agraph_t *, char *)
Definition: refstr.c:149
CGRAPH_API char * agstrdup(Agraph_t *, char *)
Definition: refstr.c:97
Definition: grammar.c:79
#define AGNODE
Definition: cgraph.h:101
Tcl_Interp * interp
Definition: tcldot.h:50
ictx_t * ictx
Definition: tcldot.h:59
int nodecmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
#define NULL
Definition: logic.h:39
Definition: tcldot.h:57
uint64_t ctr
Definition: tcldot.h:49
int graphcmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
#define AGINEDGE
Definition: cgraph.h:103
agxbuf * str
Definition: htmlparse.c:85
CGRAPH_API char * agstrbind(Agraph_t *g, char *)
Definition: refstr.c:92
#define FALSE
Definition: cgraph.h:35
#define AGRAPH
Definition: cgraph.h:100
#define TRUE
Definition: cgraph.h:38