Graphviz 13.0.0~dev.20250121.0651
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 <stdint.h>
13#include <util/alloc.h>
14#include <util/unreachable.h>
15#include "tcldot.h"
16
17// Agiddisc functions
18static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) {
19 ictx_t *ictx = (ictx_t *)disc;
20 gctx_t *gctx;
21
22 gctx = gv_alloc(sizeof(gctx_t));
23 gctx->g = g;
24 gctx->ictx = ictx;
25 return gctx;
26}
27static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag) {
28 (void)objtype;
29
30 gctx_t *gctx = state;
31 ictx_t *ictx = gctx->ictx;
32 char *s;
33
34 if (str) {
35 if (createflag)
36 s = agstrdup(gctx->g, str);
37 else
38 s = agstrbind(gctx->g, str);
39 *id = (uint64_t)(uintptr_t)s;
40 } else {
41 *id = ictx->ctr; /* counter maintained in per-interp space, so that
42 ids are unique across all graphs in the interp */
43 ictx->ctr += 2;
44 }
45 return 1;
46}
47
48static void myiddisc_free(void *state, int objtype, uint64_t id) {
49 (void)objtype;
50
51 gctx_t *gctx = state;
52
53/* FIXME no obj* available
54 ictx_t *ictx = gctx->ictx;
55 char buf[32] = "";
56
57 switch (objtype) {
58 case AGRAPH: sprintf(buf,"graph%lu",id); break;
59 case AGNODE: sprintf(buf,"node%lu",id); break;
60 case AGINEDGE:
61 case AGOUTEDGE: sprintf(buf,"edge%lu",id); break;
62 }
63 Tcl_DeleteCommand(ictx->interp, buf);
64*/
65 if (id % 2 == 0)
66 agstrfree(gctx->g, (char *)(uintptr_t)id, false);
67}
68static char *myiddisc_print(void *state, int objtype, uint64_t id) {
69 (void)state;
70 (void)objtype;
71 if (id % 2 == 0)
72 return (char *)(uintptr_t)id;
73 else
74 return "";
75}
76
77static void myiddisc_idregister(void *state, int objtype, void *obj) {
78 gctx_t *gctx = state;
79 ictx_t *ictx = gctx->ictx;
80 Tcl_Interp *interp = ictx->interp;
81 Tcl_CmdProc *proc = NULL;
82
83 switch (objtype) {
84 case AGRAPH: proc=graphcmd; break;
85 case AGNODE: proc=nodecmd; break;
86 case AGINEDGE:
87 case AGOUTEDGE: proc=edgecmd; break;
88 default: UNREACHABLE();
89 }
90 Tcl_CreateCommand(interp, obj2cmd(obj), proc, (ClientData) gctx, NULL);
91}
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 *, bool is_html)
Definition refstr.c:378
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:370
char * agstrbind(Agraph_t *g, const char *)
Definition refstr.c:337
textitem scanner parser str
Definition htmlparse.y:224
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:48
static char * myiddisc_print(void *state, int objtype, uint64_t id)
Definition tcldot-id.c:68
static long myiddisc_map(void *state, int objtype, char *str, uint64_t *id, int createflag)
Definition tcldot-id.c:27
Agiddisc_t myiddisc
Definition tcldot-id.c:92
static void * myiddisc_open(Agraph_t *g, Agdisc_t *disc)
Definition tcldot-id.c:18
static void myiddisc_idregister(void *state, int objtype, void *obj)
Definition tcldot-id.c:77
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