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.
20
typedef struct refstr_t {
26
static Dtdisc_t Refstrdisc = {
27
offsetof(refstr_t,s[0]),
32
((Dtcompar_f)0), /* use strcmp */
38
static Dict_t* StringDict;
41
static int refstrprint(refstr_t* r)
43
fprintf(stderr,"%s\n",r->s); return 0;
48
dtwalk(StringDict,refstrprint);
52
static void initialize_strings(void)
54
StringDict = dtopen(&Refstrdisc,Dttree);
57
char *agstrdup(char* s)
61
if (StringDict == NULL) initialize_strings();
62
if (s == NULL) return s;
64
key = (refstr_t*)(s - offsetof(refstr_t,s[0]));
65
r = (refstr_t*) dtsearch(StringDict,key);
68
r = (refstr_t*) malloc(sizeof(refstr_t)+strlen(s));
71
dtinsert(StringDict,r);
76
void agstrfree(char* s)
80
if ((StringDict == NULL) || (s == NULL)) return;
81
key = (refstr_t*)(s - offsetof(refstr_t,s[0]));
82
r = (refstr_t*) dtsearch(StringDict,key);
87
dtdelete(StringDict,r);
91
else fprintf(stderr,"agstrfree lost %s\n",s);