Graphviz 13.0.0~dev.20250511.0440
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 <stdbool.h>
12#include <stddef.h>
13#include <stdint.h>
14#include <util/alloc.h>
15#include <util/unreachable.h>
16#include "tcldot.h"
17
18// Agiddisc functions
19static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
20 ictx_t *const ictx = (ictx_t *)((char *)disc - offsetof(ictx_t, mydisc));
21 gctx_t *const 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
47static void myiddisc_free(void *state, int objtype, uint64_t id) {
48 (void)objtype;
49
50 gctx_t *gctx = state;
51
52/* FIXME no obj* available
53 ictx_t *ictx = gctx->ictx;
54 char buf[32] = "";
55
56 switch (objtype) {
57 case AGRAPH: sprintf(buf,"graph%lu",id); break;
58 case AGNODE: sprintf(buf,"node%lu",id); break;
59 case AGINEDGE:
60 case AGOUTEDGE: sprintf(buf,"edge%lu",id); break;
61 }
62 Tcl_DeleteCommand(ictx->interp, buf);
63*/
64 if (id % 2 == 0)
65 agstrfree(gctx->g, (char *)(uintptr_t)id, false);
66}
67static char *myiddisc_print(void *state, int objtype, uint64_t id) {
68 (void)state;
69 (void)objtype;
70 if (id % 2 == 0)
71 return (char *)(uintptr_t)id;
72 else
73 return "";
74}
75
76static void myiddisc_idregister(void *state, int objtype, void *obj) {
77 gctx_t *gctx = state;
78 ictx_t *ictx = gctx->ictx;
79 Tcl_Interp *interp = ictx->interp;
80 Tcl_CmdProc *proc = NULL;
81
82 switch (objtype) {
83 case AGRAPH: proc=graphcmd; break;
84 case AGNODE: proc=nodecmd; break;
85 case AGINEDGE:
86 case AGOUTEDGE: proc=edgecmd; break;
87 default: UNREACHABLE();
88 }
89 Tcl_CreateCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, NULL);
90}
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:207
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 *, bool is_html)
Definition refstr.c:415
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:399
char * agstrbind(Agraph_t *g, const char *)
Definition refstr.c:339
textitem scanner parser str
Definition htmlparse.y:224
static Agcbdisc_t mydisc
Definition rank.c:998
user's discipline
Definition cgraph.h:336
object ID allocator discipline
Definition cgraph.h:316
graph or subgraph
Definition cgraph.h:424
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:47
static char * myiddisc_print(void *state, int objtype, uint64_t id)
Definition tcldot-id.c:67
static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag)
Definition tcldot-id.c:26
Agiddisc_t myiddisc
Definition tcldot-id.c:91
static void * myiddisc_open(Agraph_t *g, Agdisc_t *disc)
Definition tcldot-id.c:19
static void myiddisc_idregister(void *state, int objtype, void *obj)
Definition tcldot-id.c:76
int nodecmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
char * obj2cmd(void *obj)
Definition tcldot-util.c:65
Definition grammar.c:93
#define UNREACHABLE()
Definition unreachable.h:30