Graphviz 14.1.3~dev.20260204.1019
Loading...
Searching...
No Matches
attr.c
Go to the documentation of this file.
1
7 /*************************************************************************
8 * Copyright (c) 2011 AT&T Intellectual Property
9 * All rights reserved. This program and the accompanying materials
10 * are made available under the terms of the Eclipse Public License v1.0
11 * which accompanies this distribution, and is available at
12 * https://www.eclipse.org/legal/epl-v10.html
13 *
14 * Contributors: Details at https://graphviz.org
15 *************************************************************************/
16
17#include "config.h"
18
19#include <cgraph/cghdr.h>
20#include <stdbool.h>
21#include <stdlib.h>
22#include <util/alloc.h>
23#include <util/streq.h>
24#include <util/unreachable.h>
25
26/*
27 * dynamic attributes
28 */
29
30/* to create a graph's data dictionary */
31
32static void freesym(void *obj);
33
35 (int) offsetof(Agsym_t, name), /* use symbol name as key */
36 -1,
37 (int) offsetof(Agsym_t, link),
38 NULL,
39 freesym,
40 NULL,
41};
42
43static char DataDictName[] = "_AG_datadict";
44static void init_all_attrs(Agraph_t * g);
45static Agdesc_t ProtoDesc = {.directed = true, .no_loop = true,
46 .no_write = true};
48
51 if (rv || !cflag)
52 return rv;
54 rv = (Agdatadict_t *) aggetrec(g, DataDictName, 0);
55 return rv;
56}
57
58static Dict_t *agdictof(Agraph_t * g, int kind)
59{
60 Agdatadict_t *const dd = agdatadict(g, false);
61 if (dd)
62 switch (kind) {
63 case AGRAPH:
64 return dd->dict.g;
65 case AGNODE:
66 return dd->dict.n;
67 case AGINEDGE:
68 case AGOUTEDGE:
69 return dd->dict.e;
70 default:
71 agerrorf("agdictof: unknown kind %d\n", kind);
72 break;
73 }
74 return NULL;
75}
76
78static Agsym_t *agnewsym(Agraph_t * g, const char *name, const char *value,
79 bool is_html, int id, int kind) {
80 Agsym_t *sym = gv_alloc(sizeof(Agsym_t));
81 sym->kind = (unsigned char) kind;
82 sym->name = agstrdup(g, name);
83 sym->defval = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
84 sym->id = id;
85 sym->owner = g;
86 return sym;
87}
88
89static void agcopydict(Dict_t * src, Dict_t * dest, Agraph_t * g, int kind)
90{
91 assert(dtsize(dest) == 0);
92 for (Agsym_t *sym = dtfirst(src); sym; sym = dtnext(src, sym)) {
93 const bool is_html = aghtmlstr(sym->defval);
94 Agsym_t *const newsym = agnewsym(g, sym->name, sym->defval, is_html, sym->id,
95 kind);
96 newsym->print = sym->print;
97 newsym->fixed = sym->fixed;
98 dtinsert(dest, newsym);
99 }
100}
101
103{
104 Agraph_t *par;
105
106 Agdatadict_t *const dd = agbindrec(g, DataDictName, sizeof(Agdatadict_t),
107 false);
111 if ((par = agparent(g))) {
112 Agdatadict_t *const parent_dd = agdatadict(par, false);
113 assert(dd != parent_dd);
114 dtview(dd->dict.n, parent_dd->dict.n);
115 dtview(dd->dict.e, parent_dd->dict.e);
116 dtview(dd->dict.g, parent_dd->dict.g);
117 } else {
118 if (ProtoGraph && g != ProtoGraph) {
119 /* it's not ok to dtview here for several reasons. the proto
120 graph could change, and the sym indices don't match */
121 Agdatadict_t *const parent_dd = agdatadict(ProtoGraph, false);
122 agcopydict(parent_dd->dict.n, dd->dict.n, g, AGNODE);
123 agcopydict(parent_dd->dict.e, dd->dict.e, g, AGEDGE);
124 agcopydict(parent_dd->dict.g, dd->dict.g, g, AGRAPH);
125 }
126 }
127 return dd;
128}
129
130/* look up an attribute with possible viewpathing */
131static Agsym_t *agdictsym(Dict_t * dict, char *name)
132{
133 Agsym_t key = {.name = name};
134 return dtsearch(dict, &key);
135}
136
137/* look up attribute in local dictionary with no view pathing */
138static Agsym_t *aglocaldictsym(Dict_t * dict, char *name)
139{
140 Dict_t *const view = dtview(dict, NULL);
141 Agsym_t *const rv = agdictsym(dict, name);
142 dtview(dict, view);
143 return rv;
144}
145
146Agsym_t *agattrsym(void *obj, char *name)
147{
148 Agattr_t *const data = agattrrec(obj);
149 if (data)
150 return agdictsym(data->dict, name);
151 return NULL;
152}
153
154/* to create a graph's, node's edge's string attributes */
155
156const char AgDataRecName[] = "_AG_strdata";
157
158static int topdictsize(Agobj_t * obj)
159{
160 Dict_t *const d = agdictof(agroot(agraphof(obj)), AGTYPE(obj));
161 return d ? dtsize(d) : 0;
162}
163
164/* g can be either the enclosing graph, or ProtoGraph */
165static Agrec_t *agmakeattrs(Agraph_t * context, void *obj)
166{
167 Agattr_t *const rec = agbindrec(obj, AgDataRecName, sizeof(Agattr_t),
168 false);
169 Dict_t *const datadict = agdictof(context, AGTYPE(obj));
170 assert(datadict);
171 if (rec->dict == NULL) {
172 rec->dict = agdictof(agroot(context), AGTYPE(obj));
173 const int sz = topdictsize(obj);
174 rec->str = gv_calloc((size_t)sz, sizeof(char *));
175 /* doesn't call agxset() so no obj-modified callbacks occur */
176 for (Agsym_t *sym = dtfirst(datadict); sym; sym = dtnext(datadict, sym)) {
177 if (aghtmlstr(sym->defval)) {
178 rec->str[sym->id] = agstrdup_html(agraphof(obj), sym->defval);
179 } else {
180 rec->str[sym->id] = agstrdup(agraphof(obj), sym->defval);
181 }
182 }
183 } else {
184 assert(rec->dict == datadict);
185 }
186 return &rec->h;
187}
188
189static void freeattr(Agobj_t * obj, Agattr_t * attr)
190{
191 int i, sz;
192 Agraph_t *g;
193
194 g = agraphof(obj);
195 sz = topdictsize(obj);
196 for (i = 0; i < sz; i++)
197 agstrfree(g, attr->str[i], aghtmlstr(attr->str[i]));
198 free(attr->str);
199}
200
201static void freesym(void *obj) {
202 Agsym_t *const sym = obj;
203 agstrfree(sym->owner, sym->name, false);
204 agstrfree(sym->owner, sym->defval, aghtmlstr(sym->defval));
205 free(sym);
206}
207
209{
210 return (Agattr_t *)aggetrec(obj, AgDataRecName, 0);
211}
212
213static void addattr(Agraph_t *g, Agobj_t *obj, void *symbol) {
214 Agsym_t *const sym = symbol;
215 Agattr_t *attr = agattrrec(obj);
216 assert(attr != NULL);
217 attr->str = gv_recalloc(attr->str, (size_t)sym->id, (size_t)sym->id + 1,
218 sizeof(char *));
219 if (aghtmlstr(sym->defval)) {
220 attr->str[sym->id] = agstrdup_html(g, sym->defval);
221 } else {
222 attr->str[sym->id] = agstrdup(g, sym->defval);
223 }
224}
225
226static Agsym_t *getattr(Agraph_t *g, int kind, char *name) {
227 Agsym_t *rv = 0;
228 Dict_t *dict = agdictof(g, kind);
229 if (dict) {
230 rv = agdictsym(dict, name); // viewpath up to root
231 }
232 return rv;
233}
234
235static void unviewsubgraphsattr(Agraph_t *parent, char *name) {
236 Agraph_t *subg;
237 Agsym_t *psym, *lsym;
238 Dict_t *ldict;
239
240 psym = getattr(parent, AGRAPH, name);
241 if (!psym) {
242 return; // supposedly can't happen, see setattr()
243 }
244 for (subg = agfstsubg(parent); subg; subg = agnxtsubg(subg)) {
245 ldict = agdatadict(subg, true)->dict.g;
246 lsym = aglocaldictsym(ldict, name);
247 if (lsym) {
248 continue;
249 }
250 char *const value = agxget(subg, psym);
251 const bool is_html = aghtmlstr(value);
252 lsym = agnewsym(agroot(subg), name, value, is_html, psym->id, AGRAPH);
253 dtinsert(ldict, lsym);
254 }
255}
256
257static int agxset_(void *obj, Agsym_t *sym, const char *value, bool is_html);
258
260static Agsym_t *setattr(Agraph_t * g, int kind, char *name, const char *value,
261 bool is_html) {
262 Agsym_t *rv;
263
264 assert(value);
265 Agraph_t *root = agroot(g);
266 agdatadict(g, true); /* force initialization of string attributes */
267 Dict_t *ldict = agdictof(g, kind);
268 Agsym_t *lsym = aglocaldictsym(ldict, name);
269 if (lsym) { /* update old local definition */
270 if (g != root && streq(name, "layout"))
271 agwarningf("layout attribute is invalid except on the root graph\n");
272 if (kind == AGRAPH) {
273 unviewsubgraphsattr(g,name);
274 }
275 agstrfree(g, lsym->defval, aghtmlstr(lsym->defval));
276 lsym->defval = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
277 rv = lsym;
278 } else {
279 Agsym_t *psym = agdictsym(ldict, name); // search with viewpath up to root
280 if (psym) { /* new local definition */
281 lsym = agnewsym(g, name, value, is_html, psym->id, kind);
282 dtinsert(ldict, lsym);
283 rv = lsym;
284 } else { /* new global definition */
285 Dict_t *rdict = agdictof(root, kind);
286 Agsym_t *rsym = agnewsym(root, name, value, is_html, dtsize(rdict), kind);
287 dtinsert(rdict, rsym);
288 switch (kind) {
289 case AGRAPH:
290 agapply(root, &root->base, addattr, rsym, true);
291 break;
292 case AGNODE:
293 for (Agnode_t *n = agfstnode(root); n; n = agnxtnode(root, n))
294 addattr(g, &n->base, rsym);
295 break;
296 case AGINEDGE:
297 case AGOUTEDGE:
298 for (Agnode_t *n = agfstnode(root); n; n = agnxtnode(root, n))
299 for (Agedge_t *e = agfstout(root, n); e; e = agnxtout(root, e))
300 addattr(g, &e->base, rsym);
301 break;
302 default:
303 UNREACHABLE();
304 }
305 rv = rsym;
306 }
307 }
308 if (rv && kind == AGRAPH)
309 agxset_(g, rv, value, is_html);
310 agmethod_upd(g, g, rv);
311 return rv;
312}
313
314/*
315 * create or update an existing attribute and return its descriptor.
316 * if the new value is NULL, this is only a search, no update.
317 * when a new attribute is created, existing graphs/nodes/edges
318 * receive its default value.
319 */
320static Agsym_t *agattr_(Agraph_t *g, int kind, char *name, const char *value,
321 bool is_html) {
322 Agsym_t *rv;
323
324 if (g == NULL) {
325 if (ProtoGraph == NULL)
327 g = ProtoGraph;
328 }
329 if (value)
330 rv = setattr(g, kind, name, value, is_html);
331 else
332 rv = getattr(g, kind, name);
333 return rv;
334}
335
336Agsym_t *agattr_text(Agraph_t *g, int kind, char *name, const char *value) {
337 return agattr_(g, kind, name, value, false);
338}
339
340Agsym_t *agattr_html(Agraph_t *g, int kind, char *name, const char *value) {
341 return agattr_(g, kind, name, value, true);
342}
343
344Agsym_t *agattr(Agraph_t *g, int kind, char *name, const char *value) {
345 if (g == NULL) {
346 if (ProtoGraph == NULL) {
348 }
349 g = ProtoGraph;
350 }
351
352 // Is the value we were passed a previously created HTML-like string? We
353 // essentially want to ask `aghtmlstr(value)` but cannot safely because
354 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
355 if (value != NULL) {
356 const char *const alias = agstrbind_html(g, value);
357 if (alias == value && aghtmlstr(alias)) {
358 return agattr_html(g, kind, name, value);
359 }
360 }
361
362 return agattr_text(g, kind, name, value);
363}
364
365Agsym_t *agnxtattr(Agraph_t * g, int kind, Agsym_t * attr)
366{
367 Dict_t *d;
368 Agsym_t *rv;
369
370 if ((d = agdictof(g, kind))) {
371 if (attr)
372 rv = dtnext(d, attr);
373 else
374 rv = dtfirst(d);
375 } else
376 rv = 0;
377 return rv;
378}
379
380/* Create or delete attributes associated with an object */
381
383{
384 Agraph_t *context;
385
386 g->desc.has_attrs = true;
388 if (!(context = agparent(g)))
389 context = g;
390 agmakeattrs(context, g);
391}
392
394{
395 Agdatadict_t *dd;
396 Agattr_t *attr;
397
398 if ((attr = agattrrec(g))) {
399 freeattr(&g->base, attr);
400 agdelrec(g, attr->h.name);
401 }
402
403 if ((dd = agdatadict(g, false))) {
404 if (agdtclose(g, dd->dict.n)) return 1;
405 if (agdtclose(g, dd->dict.e)) return 1;
406 if (agdtclose(g, dd->dict.g)) return 1;
407 agdelrec(g, dd->h.name);
408 }
409 return 0;
410}
411
413{
414 Agattr_t *data;
415
416 data = agattrrec(n);
417 if (!data || !data->dict)
418 (void) agmakeattrs(g, n);
419}
420
422{
423 Agattr_t *rec;
424
425 if ((rec = agattrrec(n))) {
426 freeattr(&n->base, rec);
428 }
429}
430
432{
433 Agattr_t *data;
434
435 data = agattrrec(e);
436 if (!data || !data->dict)
437 (void) agmakeattrs(g, e);
438}
439
441{
442 Agattr_t *rec;
443
444 if ((rec = agattrrec(e))) {
445 freeattr(&e->base, rec);
447 }
448}
449
450char *agget(void *obj, char *name)
451{
452 Agsym_t *const sym = agattrsym(obj, name);
453 if (sym == NULL) {
454 return NULL; // note was "", but this provides more info
455 }
456 Agattr_t *const data = agattrrec(obj);
457 return data->str[sym->id];
458}
459
460char *agxget(void *obj, Agsym_t * sym)
461{
462 Agattr_t *const data = agattrrec(obj);
463 assert(sym->id >= 0 && sym->id < topdictsize(obj));
464 return data->str[sym->id];
465}
466
467static int agset_(void *obj, char *name, const char *value, bool is_html) {
468 Agsym_t *const sym = agattrsym(obj, name);
469 if (sym == NULL)
470 return FAILURE;
471 if (is_html) {
472 return agxset_html(obj, sym, value);
473 }
474 return agxset_text(obj, sym, value);
475}
476
477int agset(void *obj, char *name, const char *value) {
478
479 // Is the value we were passed a previously created HTML-like string? We
480 // essentially want to ask `aghtmlstr(value)` but cannot safely because
481 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
482 if (value != NULL) {
483 const char *const alias = agstrbind_html(agraphof(obj), value);
484 if (alias == value && aghtmlstr(alias)) {
485 return agset_html(obj, name, value);
486 }
487 }
488
489 return agset_text(obj, name, value);
490}
491
492int agset_text(void *obj, char *name, const char *value) {
493 return agset_(obj, name, value, false);
494}
495
496int agset_html(void *obj, char *name, const char *value) {
497 return agset_(obj, name, value, true);
498}
499
500static int agxset_(void *obj, Agsym_t *sym, const char *value, bool is_html) {
501 Agsym_t *lsym;
502
503 Agraph_t *g = agraphof(obj);
504 Agobj_t *hdr = obj;
505 Agattr_t *data = agattrrec(hdr);
506 assert(sym->id >= 0 && sym->id < topdictsize(obj));
507 agstrfree(g, data->str[sym->id], aghtmlstr(data->str[sym->id]));
508 data->str[sym->id] = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
509 if (hdr->tag.objtype == AGRAPH) {
510 /* also update dict default */
511 Dict_t *dict = agdatadict(g, false)->dict.g;
512 if ((lsym = aglocaldictsym(dict, sym->name))) {
513 agstrfree(g, lsym->defval, aghtmlstr(lsym->defval));
514 lsym->defval = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
515 } else {
516 lsym = agnewsym(g, sym->name, value, is_html, sym->id, AGTYPE(hdr));
517 dtinsert(dict, lsym);
518 }
519 }
520 agmethod_upd(g, obj, sym);
521 return SUCCESS;
522}
523
524int agxset(void *obj, Agsym_t *sym, const char *value) {
525
526 // Is the value we were passed a previously created HTML-like string? We
527 // essentially want to ask `aghtmlstr(value)` but cannot safely because
528 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
529 if (value != NULL) {
530 const char *const alias = agstrbind_html(agraphof(obj), value);
531 if (alias == value && aghtmlstr(alias)) {
532 return agxset_html(obj, sym, value);
533 }
534 }
535
536 return agxset_text(obj, sym, value);
537}
538
539int agxset_text(void *obj, Agsym_t *sym, const char *value) {
540 return agxset_(obj, sym, value, false);
541}
542
543int agxset_html(void *obj, Agsym_t *sym, const char *value) {
544 return agxset_(obj, sym, value, true);
545}
546
547int agsafeset_text(void *obj, char *name, const char *value, const char *def) {
548 Agsym_t *a = agattr_text(agraphof(obj), AGTYPE(obj), name, NULL);
549 if (!a)
550 a = agattr_text(agraphof(obj), AGTYPE(obj), name, def);
551 return agxset(obj, a, value);
552}
553
554int agsafeset_html(void *obj, char *name, const char *value, const char *def) {
555 Agsym_t *a = agattr_html(agraphof(obj), AGTYPE(obj), name, NULL);
556 if (a == NULL) {
557 a = agattr_html(agraphof(obj), AGTYPE(obj), name, def);
558 }
559 return agxset_html(obj, a, value);
560}
561
562int agsafeset(void *obj, char *name, const char *value, const char *def) {
563
564 // find the graph containing the target object
565 Agraph_t *const graph = agraphof(obj);
566
567 // get the existing attribute, if there is one
568 Agsym_t *a = agattr_text(graph, AGTYPE(obj), name, NULL);
569
570 if (a == NULL) {
571 // Is the default we were passed a previously created HTML-like string? We
572 // essentially want to ask `aghtmlstr(def)` but cannot safely because `def`
573 // may not have originated from `agstrdup`/`agstrdup_html`.
574 bool is_def_html = false;
575 if (def != NULL) {
576 const char *const alias = agstrbind_html(graph, def);
577 if (alias == def && aghtmlstr(alias)) {
578 is_def_html = true;
579 }
580 }
581
582 if (is_def_html) {
583 a = agattr_html(graph, AGTYPE(obj), name, def);
584 } else {
585 a = agattr_text(graph, AGTYPE(obj), name, def);
586 }
587 }
588
589 // Is the value we were passed a previously created HTML-like string? We
590 // essentially want to ask `aghtmlstr(value)` but cannot safely because
591 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
592 if (value != NULL) {
593 const char *const alias = agstrbind_html(graph, value);
594 if (alias == value && aghtmlstr(alias)) {
595 return agxset_html(obj, a, value);
596 }
597 }
598
599 return agxset(obj, a, value);
600}
601
602static void agraphattr_init_wrapper(Agraph_t *g, Agobj_t *ignored1,
603 void *ignored2) {
604 (void)ignored1;
605 (void)ignored2;
606
608}
609
610/*
611 * attach attributes to the already created graph objs.
612 * presumably they were already initialized, so we don't invoke
613 * any of the old methods.
614 */
615static void init_all_attrs(Agraph_t * g)
616{
617 Agraph_t *root;
618 Agnode_t *n;
619 Agedge_t *e;
620
621 root = agroot(g);
622 agapply(root, &root->base, agraphattr_init_wrapper, NULL, true);
623 for (n = agfstnode(root); n; n = agnxtnode(root, n)) {
624 agnodeattr_init(g, n);
625 for (e = agfstout(root, n); e; e = agnxtout(root, e)) {
626 agedgeattr_init(g, e);
627 }
628 }
629}
630
631/* Assumes attributes have already been declared.
632 * Do not copy key attribute for edges, as this must be distinct.
633 * Returns non-zero on failure or if objects have different type.
634 */
635int agcopyattr(void *oldobj, void *newobj)
636{
637 Agraph_t *g;
638 Agsym_t *sym;
639 Agsym_t *newsym;
640 char* val;
641 int r = 1;
642
643 g = agraphof(oldobj);
644 if (AGTYPE(oldobj) != AGTYPE(newobj))
645 return 1;
646 sym = 0;
647 while ((sym = agnxtattr(g, AGTYPE(oldobj), sym))) {
648 newsym = agattrsym(newobj, sym->name);
649 if (!newsym)
650 return 1;
651 val = agxget(oldobj, sym);
652 if (aghtmlstr(val)) {
653 r = agxset_html(newobj, newsym, val);
654 } else {
655 r = agxset(newobj, newsym, val);
656 }
657 }
658 return r;
659}
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
Definition alloc.h:73
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
static void * gv_alloc(size_t size)
Definition alloc.h:47
int agapply(Agraph_t *g, Agobj_t *obj, agobjfn_t fn, void *arg, int preorder)
Definition apply.c:62
static void agraphattr_init_wrapper(Agraph_t *g, Agobj_t *ignored1, void *ignored2)
Definition attr.c:602
static Agsym_t * agdictsym(Dict_t *dict, char *name)
Definition attr.c:131
const char AgDataRecName[]
Definition attr.c:156
static int agxset_(void *obj, Agsym_t *sym, const char *value, bool is_html)
Definition attr.c:500
static void freeattr(Agobj_t *obj, Agattr_t *attr)
Definition attr.c:189
static Agdatadict_t * agmakedatadict(Agraph_t *g)
Definition attr.c:102
static Agraph_t * ProtoGraph
Definition attr.c:47
static Agsym_t * setattr(Agraph_t *g, int kind, char *name, const char *value, bool is_html)
Definition attr.c:260
static int topdictsize(Agobj_t *obj)
Definition attr.c:158
static Agdesc_t ProtoDesc
Definition attr.c:45
static Dict_t * agdictof(Agraph_t *g, int kind)
Definition attr.c:58
static void init_all_attrs(Agraph_t *g)
Definition attr.c:615
static Agsym_t * agnewsym(Agraph_t *g, const char *name, const char *value, bool is_html, int id, int kind)
Definition attr.c:78
Dtdisc_t AgDataDictDisc
Definition attr.c:34
static void addattr(Agraph_t *g, Agobj_t *obj, void *symbol)
Definition attr.c:213
static Agrec_t * agmakeattrs(Agraph_t *context, void *obj)
Definition attr.c:165
static void unviewsubgraphsattr(Agraph_t *parent, char *name)
Definition attr.c:235
static Agsym_t * aglocaldictsym(Dict_t *dict, char *name)
Definition attr.c:138
static void agcopydict(Dict_t *src, Dict_t *dest, Agraph_t *g, int kind)
Definition attr.c:89
static void freesym(void *obj)
Definition attr.c:201
static Agsym_t * agattr_(Agraph_t *g, int kind, char *name, const char *value, bool is_html)
Definition attr.c:320
static char DataDictName[]
Definition attr.c:43
static Agsym_t * getattr(Agraph_t *g, int kind, char *name)
Definition attr.c:226
static int agset_(void *obj, char *name, const char *value, bool is_html)
Definition attr.c:467
#define dtsearch(d, o)
Definition cdt.h:184
CDT_API int dtsize(Dt_t *)
Definition dtsize.c:14
#define dtinsert(d, o)
Definition cdt.h:186
CDT_API Dt_t * dtview(Dt_t *, Dt_t *)
Definition dtview.c:92
CDT_API Dtmethod_t * Dttree
Definition dttree.c:310
#define dtnext(d, o)
Definition cdt.h:181
#define dtfirst(d)
Definition cdt.h:180
cgraph.h additions
Dict_t * agdtopen(Dtdisc_t *disc, Dtmethod_t *method)
Definition utils.c:23
#define FAILURE
Definition cghdr.h:45
#define SUCCESS
Definition cghdr.h:44
int agdtclose(Agraph_t *g, Dict_t *dict)
Definition utils.c:33
#define parent(i)
Definition closest.c:75
void free(void *)
node NULL
Definition grammar.y:181
Agattr_t * agattrrec(void *obj)
Definition attr.c:208
void agnodeattr_init(Agraph_t *g, Agnode_t *n)
Definition attr.c:412
int agsafeset_html(void *obj, char *name, const char *value, const char *def)
set an attribute’s value and default, ensuring it is declared before setting it locally
Definition attr.c:554
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Definition attr.c:336
void agnodeattr_delete(Agnode_t *n)
Definition attr.c:421
Agsym_t * agattrsym(void *obj, char *name)
looks up a string attribute for a graph object given as an argument
Definition attr.c:146
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up an attribute, without specifying desired form
Definition attr.c:344
int agset(void *obj, char *name, const char *value)
Definition attr.c:477
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:365
void agedgeattr_init(Agraph_t *g, Agedge_t *e)
Definition attr.c:431
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:524
void agraphattr_init(Agraph_t *g)
Definition attr.c:382
int agxset_html(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:543
char * agget(void *obj, char *name)
Definition attr.c:450
int agsafeset(void *obj, char *name, const char *value, const char *def)
set an attribute’s value and default, ensuring it is declared before setting it locally
Definition attr.c:562
int agset_html(void *obj, char *name, const char *value)
Definition attr.c:496
int agset_text(void *obj, char *name, const char *value)
Definition attr.c:492
void agedgeattr_delete(Agedge_t *e)
Definition attr.c:440
Agdatadict_t * agdatadict(Agraph_t *g, bool cflag)
Definition attr.c:49
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:460
int agcopyattr(void *oldobj, void *newobj)
copies all of the attributes from one object to another
Definition attr.c:635
int agsafeset_text(void *obj, char *name, const char *value, const char *def)
set an attribute’s value and default, ensuring it is declared before setting it locally
Definition attr.c:547
int agraphattr_delete(Agraph_t *g)
Definition attr.c:393
Agsym_t * agattr_html(Agraph_t *g, int kind, char *name, const char *value)
agattr_text, but creates HTML-like values
Definition attr.c:340
int agxset_text(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:539
void agmethod_upd(Agraph_t *g, void *obj, Agsym_t *sym)
Definition obj.c:110
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:28
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:43
void agwarningf(const char *fmt,...)
Definition agerror.c:175
void agerrorf(const char *fmt,...)
Definition agerror.c:167
Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
creates a new graph with the given name and kind
Definition graph.c:44
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:50
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
Agraph_t * agraphof(void *obj)
Definition obj.c:187
#define AGTYPE(obj)
returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
Definition cgraph.h:216
Agraph_t * agroot(void *obj)
Definition obj.c:170
@ AGOUTEDGE
Definition cgraph.h:207
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGINEDGE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
Agrec_t * aggetrec(void *obj, const char *name, int move_to_front)
find record in circular list and do optional move-to-front and lock
Definition rec.c:43
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
Definition rec.c:91
int agdelrec(void *obj, const char *name)
deletes a named record from one object
Definition rec.c:139
char * agstrbind_html(Agraph_t *g, const char *)
Definition refstr.c:356
int aghtmlstr(const char *)
Definition refstr.c:440
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 * agstrdup_html(Agraph_t *, const char *)
returns a pointer to a reference-counted HTML-like copy of the argument string, creating one if neces...
Definition refstr.c:397
Agraph_t * agparent(Agraph_t *g)
Definition subg.c:88
Agraph_t * agfstsubg(Agraph_t *g)
Definition subg.c:75
Agraph_t * agnxtsubg(Agraph_t *subg)
Definition subg.c:80
static uint64_t id
Definition gv2gml.c:42
Agraph_t * graph(char *name)
Definition gv.cpp:34
ViewInfo * view
Definition viewport.c:40
static bool streq(const char *a, const char *b)
are a and b equal?
Definition streq.h:11
string attribute container
Definition cgraph.h:632
char ** str
the attribute string values indexed by Agsym_s.id
Definition cgraph.h:635
Dict_t * dict
shared dict of Agsym_s to interpret Agattr_s.str
Definition cgraph.h:634
Agrec_t h
Definition cgraph.h:633
Dict_t * n
Definition cgraph.h:655
struct Agdatadict_s::@32 dict
Dict_t * e
Definition cgraph.h:655
Dict_t * g
Definition cgraph.h:655
Agrec_t h
< set of dictionaries per graph
Definition cgraph.h:653
graph descriptor
Definition cgraph.h:284
unsigned has_attrs
Definition cgraph.h:290
unsigned directed
Definition cgraph.h:285
Agobj_t base
Definition cgraph.h:269
Agobj_t base
Definition cgraph.h:260
a generic header of Agraph_s, Agnode_s and Agedge_s
Definition cgraph.h:210
Agtag_t tag
access with AGTAG
Definition cgraph.h:211
graph or subgraph
Definition cgraph.h:424
Agobj_t base
Definition cgraph.h:425
Agdesc_t desc
Definition cgraph.h:426
implementation of Agrec_t
Definition cgraph.h:172
char * name
Definition cgraph.h:173
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:640
char * name
Definition cgraph.h:642
unsigned char kind
Definition cgraph.h:645
Agraph_t * owner
Definition cgraph.h:648
int id
index in Agattr_s.str
Definition cgraph.h:644
unsigned char fixed
Definition cgraph.h:646
char * defval
Definition cgraph.h:643
unsigned char print
Definition cgraph.h:647
unsigned objtype
access with AGTYPE
Definition cgraph.h:199
Definition cdt.h:98
#define UNREACHABLE()
Definition unreachable.h:30