Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
tcldot-id.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <stdint.h>
12#include <util/alloc.h>
13#include <util/unreachable.h>
14#include "tcldot.h"
15
16// Agiddisc functions
17static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
18 ictx_t *ictx = (ictx_t *)disc;
19 gctx_t *gctx;
20
21 gctx = gv_alloc(sizeof(gctx_t));
22 gctx->g = g;
23 gctx->ictx = ictx;
24 return gctx;
25}
26static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag) {
27 (void)objtype;
28
29 gctx_t *gctx = state;
30 ictx_t *ictx = gctx->ictx;
31 char *s;
32
33 if (str) {
34 if (createflag)
35 s = agstrdup(gctx->g, str);
36 else
37 s = agstrbind(gctx->g, str);
38 *id = (uint64_t)(uintptr_t)s;
39 } else {
40 *id = ictx->ctr; /* counter maintained in per-interp space, so that
41 ids are unique across all graphs in the interp */
42 ictx->ctr += 2;
43 }
44 return 1;
45}
46/* we don't allow users to explicitly set IDs, either */
47static long myiddisc_alloc(void *state, int objtype, uint64_t request_id) {
48 (void)state;
49 (void)objtype;
50 (void)request_id;
51 return 0;
52}
53static void myiddisc_free(void *state, int objtype, uint64_t id) {
54 (void)objtype;
55
56 gctx_t *gctx = state;
57
58/* FIXME no obj* available
59 ictx_t *ictx = gctx->ictx;
60 char buf[32] = "";
61
62 switch (objtype) {
63 case AGRAPH: sprintf(buf,"graph%lu",id); break;
64 case AGNODE: sprintf(buf,"node%lu",id); break;
65 case AGINEDGE:
66 case AGOUTEDGE: sprintf(buf,"edge%lu",id); break;
67 }
68 Tcl_DeleteCommand(ictx->interp, buf);
69*/
70 if (id % 2 == 0)
71 agstrfree(gctx->g, (char *)(uintptr_t)id);
72}
73static char *myiddisc_print(void *state, int objtype, uint64_t id) {
74 (void)state;
75 (void)objtype;
76 if (id % 2 == 0)
77 return (char *)(uintptr_t)id;
78 else
79 return "";
80}
81
82static void myiddisc_idregister(void *state, int objtype, void *obj) {
83 gctx_t *gctx = state;
84 ictx_t *ictx = gctx->ictx;
85 Tcl_Interp *interp = ictx->interp;
86 Tcl_CmdProc *proc = NULL;
87
88 switch (objtype) {
89 case AGRAPH: proc=graphcmd; break;
90 case AGNODE: proc=nodecmd; break;
91 case AGINEDGE:
92 case AGOUTEDGE: proc=edgecmd; break;
93 default: UNREACHABLE();
94 }
95 Tcl_CreateCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, NULL);
96}
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
static Dtdisc_t disc
Definition exparse.y:209
void free(void *)
node NULL
Definition grammar.y:163
@ AGOUTEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGINEDGE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
int agstrfree(Agraph_t *, const char *)
Definition refstr.c:139
char * agstrdup(Agraph_t *, const char *)
returns a pointer to a reference-counted copy of the argument string, creating one if necessary
Definition refstr.c:131
char * agstrbind(Agraph_t *g, const char *)
Definition refstr.c:96
textitem scanner parser str
Definition htmlparse.y:224
user's discipline
Definition cgraph.h:337
object ID allocator discipline
Definition cgraph.h:316
graph or subgraph
Definition cgraph.h:425
Agraph_t * g
Definition tcldot.h:37
ictx_t * ictx
Definition tcldot.h:38
Tcl_Interp * interp
Definition tcldot.h:29
uint64_t ctr
Definition tcldot.h:28
int edgecmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
int graphcmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
static void myiddisc_free(void *state, int objtype, uint64_t id)
Definition tcldot-id.c:53
static char * myiddisc_print(void *state, int objtype, uint64_t id)
Definition tcldot-id.c:73
static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag)
Definition tcldot-id.c:26
static long myiddisc_alloc(void *state, int objtype, uint64_t request_id)
Definition tcldot-id.c:47
Agiddisc_t myiddisc
Definition tcldot-id.c:97
static void * myiddisc_open(Agraph_t *g, Agdisc_t *disc)
Definition tcldot-id.c:17
static void myiddisc_idregister(void *state, int objtype, void *obj)
Definition tcldot-id.c:82
int nodecmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
char * obj2cmd(void *obj)
Definition tcldot-util.c:66
Definition grammar.c:93
#define UNREACHABLE()
Definition unreachable.h:30