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