2
This software may only be used by you under license from AT&T Corp.
3
("AT&T"). A copy of AT&T's Source Code Agreement is available at
4
AT&T's Internet website having the URL:
5
<http://www.research.att.com/sw/tools/graphviz/license/source.html>
6
If you received this software without first entering into a license
7
with AT&T, you have an infringing copy of this software and cannot use
8
it without violating AT&T's intellectual property rights.
19
* reference counted strings.
22
typedef struct refstr_t {
26
char store[1]; /* this is actually a dynamic array */
29
static Dtdisc_t Refstrdisc = {
30
offsetof(refstr_t,s), /* key */
41
static Dict_t *Refdict_default;
43
static Dict_t *refdict(Agraph_t *g)
47
if (g) dictref = &(g->clos->strdict);
48
else dictref = &Refdict_default;
49
if (*dictref == NIL(Dict_t*))
50
*dictref = agdtopen(g,&Refstrdisc,Dttree);
54
void agstrclose(Agraph_t *g)
56
agdtclose(g,refdict(g));
59
static refstr_t *refsymbind(Dict_t *strdict, char *s)
63
r = (refstr_t*) dtsearch(strdict,&key);
67
static char *refstrbind(Dict_t *strdict, char *s)
70
r = refsymbind(strdict, s);
72
else return NIL(char*);
75
char *agstrbind(Agraph_t *g, char *s)
77
return refstrbind(refdict(g),s);
80
char *agstrdup(Agraph_t *g, char *s)
86
if (s == NIL(char*)) return NIL(char*);
88
r = refsymbind(strdict,s);
91
sz = sizeof(refstr_t)+strlen(s);
92
if (g) r = (refstr_t*) agalloc(g,sz);
93
else r = (refstr_t*)malloc(sz);
102
int agstrfree(Agraph_t *g, char *s)
110
strdict = refdict(g);
111
r = refsymbind(strdict,s);
112
if (r && (r->s == s)) {
114
if (r->refcnt <= 0) {
115
agdtdelete(g,strdict,r);
122
if (r == NIL(refstr_t*)) return FAILURE;
127
static int refstrprint(Dict_t *dict, void *ptr, void *user)
134
write(2,r->s,strlen(r->s));
139
void agrefstrdump(Agraph_t *g)
141
dtwalk(Refdict_default,refstrprint,0);