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