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