Graphviz 14.1.3~dev.20260227.0545
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 Agraph_t *const g = agraphof(obj);
192 const int sz = topdictsize(obj);
193 for (int i = 0; i < sz; i++)
194 agstrfree(g, attr->str[i], aghtmlstr(attr->str[i]));
195 free(attr->str);
196}
197
198static void freesym(void *obj) {
199 Agsym_t *const sym = obj;
200 agstrfree(sym->owner, sym->name, false);
201 agstrfree(sym->owner, sym->defval, aghtmlstr(sym->defval));
202 free(sym);
203}
204
206{
207 return (Agattr_t *)aggetrec(obj, AgDataRecName, 0);
208}
209
210static void addattr(Agraph_t *g, Agobj_t *obj, void *symbol) {
211 Agsym_t *const sym = symbol;
212 Agattr_t *attr = agattrrec(obj);
213 assert(attr != NULL);
214 attr->str = gv_recalloc(attr->str, (size_t)sym->id, (size_t)sym->id + 1,
215 sizeof(char *));
216 if (aghtmlstr(sym->defval)) {
217 attr->str[sym->id] = agstrdup_html(g, sym->defval);
218 } else {
219 attr->str[sym->id] = agstrdup(g, sym->defval);
220 }
221}
222
223static Agsym_t *getattr(Agraph_t *g, int kind, char *name) {
224 Agsym_t *rv = 0;
225 Dict_t *dict = agdictof(g, kind);
226 if (dict) {
227 rv = agdictsym(dict, name); // viewpath up to root
228 }
229 return rv;
230}
231
232static void unviewsubgraphsattr(Agraph_t *parent, char *name) {
233 Agraph_t *subg;
234 Agsym_t *psym, *lsym;
235 Dict_t *ldict;
236
237 psym = getattr(parent, AGRAPH, name);
238 if (!psym) {
239 return; // supposedly can't happen, see setattr()
240 }
241 for (subg = agfstsubg(parent); subg; subg = agnxtsubg(subg)) {
242 ldict = agdatadict(subg, true)->dict.g;
243 lsym = aglocaldictsym(ldict, name);
244 if (lsym) {
245 continue;
246 }
247 char *const value = agxget(subg, psym);
248 const bool is_html = aghtmlstr(value);
249 lsym = agnewsym(agroot(subg), name, value, is_html, psym->id, AGRAPH);
250 dtinsert(ldict, lsym);
251 }
252}
253
254static int agxset_(void *obj, Agsym_t *sym, const char *value, bool is_html);
255
257static Agsym_t *setattr(Agraph_t * g, int kind, char *name, const char *value,
258 bool is_html) {
259 Agsym_t *rv;
260
261 assert(value);
262 Agraph_t *root = agroot(g);
263 agdatadict(g, true); /* force initialization of string attributes */
264 Dict_t *ldict = agdictof(g, kind);
265 Agsym_t *lsym = aglocaldictsym(ldict, name);
266 if (lsym) { /* update old local definition */
267 if (g != root && streq(name, "layout"))
268 agwarningf("layout attribute is invalid except on the root graph\n");
269 if (kind == AGRAPH) {
270 unviewsubgraphsattr(g,name);
271 }
272 agstrfree(g, lsym->defval, aghtmlstr(lsym->defval));
273 lsym->defval = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
274 rv = lsym;
275 } else {
276 Agsym_t *psym = agdictsym(ldict, name); // search with viewpath up to root
277 if (psym) { /* new local definition */
278 lsym = agnewsym(g, name, value, is_html, psym->id, kind);
279 dtinsert(ldict, lsym);
280 rv = lsym;
281 } else { /* new global definition */
282 Dict_t *rdict = agdictof(root, kind);
283 Agsym_t *rsym = agnewsym(root, name, value, is_html, dtsize(rdict), kind);
284 dtinsert(rdict, rsym);
285 switch (kind) {
286 case AGRAPH:
287 agapply(root, &root->base, addattr, rsym, true);
288 break;
289 case AGNODE:
290 for (Agnode_t *n = agfstnode(root); n; n = agnxtnode(root, n))
291 addattr(g, &n->base, rsym);
292 break;
293 case AGINEDGE:
294 case AGOUTEDGE:
295 for (Agnode_t *n = agfstnode(root); n; n = agnxtnode(root, n))
296 for (Agedge_t *e = agfstout(root, n); e; e = agnxtout(root, e))
297 addattr(g, &e->base, rsym);
298 break;
299 default:
300 UNREACHABLE();
301 }
302 rv = rsym;
303 }
304 }
305 if (rv && kind == AGRAPH)
306 agxset_(g, rv, value, is_html);
307 agmethod_upd(g, g, rv);
308 return rv;
309}
310
311/*
312 * create or update an existing attribute and return its descriptor.
313 * if the new value is NULL, this is only a search, no update.
314 * when a new attribute is created, existing graphs/nodes/edges
315 * receive its default value.
316 */
317static Agsym_t *agattr_(Agraph_t *g, int kind, char *name, const char *value,
318 bool is_html) {
319 Agsym_t *rv;
320
321 if (g == NULL) {
322 if (ProtoGraph == NULL)
324 g = ProtoGraph;
325 }
326 if (value)
327 rv = setattr(g, kind, name, value, is_html);
328 else
329 rv = getattr(g, kind, name);
330 return rv;
331}
332
333Agsym_t *agattr_text(Agraph_t *g, int kind, char *name, const char *value) {
334 return agattr_(g, kind, name, value, false);
335}
336
337Agsym_t *agattr_html(Agraph_t *g, int kind, char *name, const char *value) {
338 return agattr_(g, kind, name, value, true);
339}
340
341Agsym_t *agattr(Agraph_t *g, int kind, char *name, const char *value) {
342 if (g == NULL) {
343 if (ProtoGraph == NULL) {
345 }
346 g = ProtoGraph;
347 }
348
349 // Is the value we were passed a previously created HTML-like string? We
350 // essentially want to ask `aghtmlstr(value)` but cannot safely because
351 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
352 if (value != NULL) {
353 const char *const alias = agstrbind_html(g, value);
354 if (alias == value && aghtmlstr(alias)) {
355 return agattr_html(g, kind, name, value);
356 }
357 }
358
359 return agattr_text(g, kind, name, value);
360}
361
362Agsym_t *agnxtattr(Agraph_t * g, int kind, Agsym_t * attr)
363{
364 Dict_t *d;
365 Agsym_t *rv;
366
367 if ((d = agdictof(g, kind))) {
368 if (attr)
369 rv = dtnext(d, attr);
370 else
371 rv = dtfirst(d);
372 } else
373 rv = 0;
374 return rv;
375}
376
377/* Create or delete attributes associated with an object */
378
380{
381 Agraph_t *context;
382
383 g->desc.has_attrs = true;
385 if (!(context = agparent(g)))
386 context = g;
387 agmakeattrs(context, g);
388}
389
391{
392 Agdatadict_t *dd;
393 Agattr_t *attr;
394
395 if ((attr = agattrrec(g))) {
396 freeattr(&g->base, attr);
397 agdelrec(g, attr->h.name);
398 }
399
400 if ((dd = agdatadict(g, false))) {
401 if (agdtclose(g, dd->dict.n)) return 1;
402 if (agdtclose(g, dd->dict.e)) return 1;
403 if (agdtclose(g, dd->dict.g)) return 1;
404 agdelrec(g, dd->h.name);
405 }
406 return 0;
407}
408
410{
411 Agattr_t *data;
412
413 data = agattrrec(n);
414 if (!data || !data->dict)
415 (void) agmakeattrs(g, n);
416}
417
419{
420 Agattr_t *rec;
421
422 if ((rec = agattrrec(n))) {
423 freeattr(&n->base, rec);
425 }
426}
427
429{
430 Agattr_t *data;
431
432 data = agattrrec(e);
433 if (!data || !data->dict)
434 (void) agmakeattrs(g, e);
435}
436
438{
439 Agattr_t *rec;
440
441 if ((rec = agattrrec(e))) {
442 freeattr(&e->base, rec);
444 }
445}
446
447char *agget(void *obj, char *name)
448{
449 Agsym_t *const sym = agattrsym(obj, name);
450 if (sym == NULL) {
451 return NULL; // note was "", but this provides more info
452 }
453 Agattr_t *const data = agattrrec(obj);
454 return data->str[sym->id];
455}
456
457char *agxget(void *obj, Agsym_t * sym)
458{
459 Agattr_t *const data = agattrrec(obj);
460 assert(sym->id >= 0 && sym->id < topdictsize(obj));
461 return data->str[sym->id];
462}
463
464static int agset_(void *obj, char *name, const char *value, bool is_html) {
465 Agsym_t *const sym = agattrsym(obj, name);
466 if (sym == NULL)
467 return FAILURE;
468 if (is_html) {
469 return agxset_html(obj, sym, value);
470 }
471 return agxset_text(obj, sym, value);
472}
473
474int agset(void *obj, char *name, const char *value) {
475
476 // Is the value we were passed a previously created HTML-like string? We
477 // essentially want to ask `aghtmlstr(value)` but cannot safely because
478 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
479 if (value != NULL) {
480 const char *const alias = agstrbind_html(agraphof(obj), value);
481 if (alias == value && aghtmlstr(alias)) {
482 return agset_html(obj, name, value);
483 }
484 }
485
486 return agset_text(obj, name, value);
487}
488
489int agset_text(void *obj, char *name, const char *value) {
490 return agset_(obj, name, value, false);
491}
492
493int agset_html(void *obj, char *name, const char *value) {
494 return agset_(obj, name, value, true);
495}
496
497static int agxset_(void *obj, Agsym_t *sym, const char *value, bool is_html) {
498 Agsym_t *lsym;
499
500 Agraph_t *g = agraphof(obj);
501 Agobj_t *hdr = obj;
502 Agattr_t *data = agattrrec(hdr);
503 assert(sym->id >= 0 && sym->id < topdictsize(obj));
504 agstrfree(g, data->str[sym->id], aghtmlstr(data->str[sym->id]));
505 data->str[sym->id] = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
506 if (hdr->tag.objtype == AGRAPH) {
507 /* also update dict default */
508 Dict_t *dict = agdatadict(g, false)->dict.g;
509 if ((lsym = aglocaldictsym(dict, sym->name))) {
510 agstrfree(g, lsym->defval, aghtmlstr(lsym->defval));
511 lsym->defval = is_html ? agstrdup_html(g, value) : agstrdup(g, value);
512 } else {
513 lsym = agnewsym(g, sym->name, value, is_html, sym->id, AGTYPE(hdr));
514 dtinsert(dict, lsym);
515 }
516 }
517 agmethod_upd(g, obj, sym);
518 return SUCCESS;
519}
520
521int agxset(void *obj, Agsym_t *sym, const char *value) {
522
523 // Is the value we were passed a previously created HTML-like string? We
524 // essentially want to ask `aghtmlstr(value)` but cannot safely because
525 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
526 if (value != NULL) {
527 const char *const alias = agstrbind_html(agraphof(obj), value);
528 if (alias == value && aghtmlstr(alias)) {
529 return agxset_html(obj, sym, value);
530 }
531 }
532
533 return agxset_text(obj, sym, value);
534}
535
536int agxset_text(void *obj, Agsym_t *sym, const char *value) {
537 return agxset_(obj, sym, value, false);
538}
539
540int agxset_html(void *obj, Agsym_t *sym, const char *value) {
541 return agxset_(obj, sym, value, true);
542}
543
544int agsafeset_text(void *obj, char *name, const char *value, const char *def) {
545 Agsym_t *a = agattr_text(agraphof(obj), AGTYPE(obj), name, NULL);
546 if (!a)
547 a = agattr_text(agraphof(obj), AGTYPE(obj), name, def);
548 return agxset(obj, a, value);
549}
550
551int agsafeset_html(void *obj, char *name, const char *value, const char *def) {
552 Agsym_t *a = agattr_html(agraphof(obj), AGTYPE(obj), name, NULL);
553 if (a == NULL) {
554 a = agattr_html(agraphof(obj), AGTYPE(obj), name, def);
555 }
556 return agxset_html(obj, a, value);
557}
558
559int agsafeset(void *obj, char *name, const char *value, const char *def) {
560
561 // find the graph containing the target object
562 Agraph_t *const graph = agraphof(obj);
563
564 // get the existing attribute, if there is one
565 Agsym_t *a = agattr_text(graph, AGTYPE(obj), name, NULL);
566
567 if (a == NULL) {
568 // Is the default we were passed a previously created HTML-like string? We
569 // essentially want to ask `aghtmlstr(def)` but cannot safely because `def`
570 // may not have originated from `agstrdup`/`agstrdup_html`.
571 bool is_def_html = false;
572 if (def != NULL) {
573 const char *const alias = agstrbind_html(graph, def);
574 if (alias == def && aghtmlstr(alias)) {
575 is_def_html = true;
576 }
577 }
578
579 if (is_def_html) {
580 a = agattr_html(graph, AGTYPE(obj), name, def);
581 } else {
582 a = agattr_text(graph, AGTYPE(obj), name, def);
583 }
584 }
585
586 // Is the value we were passed a previously created HTML-like string? We
587 // essentially want to ask `aghtmlstr(value)` but cannot safely because
588 // `value` may not have originated from `agstrdup`/`agstrdup_html`.
589 if (value != NULL) {
590 const char *const alias = agstrbind_html(graph, value);
591 if (alias == value && aghtmlstr(alias)) {
592 return agxset_html(obj, a, value);
593 }
594 }
595
596 return agxset(obj, a, value);
597}
598
599static void agraphattr_init_wrapper(Agraph_t *g, Agobj_t *ignored1,
600 void *ignored2) {
601 (void)ignored1;
602 (void)ignored2;
603
605}
606
607/*
608 * attach attributes to the already created graph objs.
609 * presumably they were already initialized, so we don't invoke
610 * any of the old methods.
611 */
612static void init_all_attrs(Agraph_t * g)
613{
614 Agraph_t *root;
615 Agnode_t *n;
616 Agedge_t *e;
617
618 root = agroot(g);
619 agapply(root, &root->base, agraphattr_init_wrapper, NULL, true);
620 for (n = agfstnode(root); n; n = agnxtnode(root, n)) {
621 agnodeattr_init(g, n);
622 for (e = agfstout(root, n); e; e = agnxtout(root, e)) {
623 agedgeattr_init(g, e);
624 }
625 }
626}
627
628/* Assumes attributes have already been declared.
629 * Do not copy key attribute for edges, as this must be distinct.
630 * Returns non-zero on failure or if objects have different type.
631 */
632int agcopyattr(void *oldobj, void *newobj)
633{
634 Agraph_t *g;
635 Agsym_t *sym;
636 Agsym_t *newsym;
637 char* val;
638 int r = 1;
639
640 g = agraphof(oldobj);
641 if (AGTYPE(oldobj) != AGTYPE(newobj))
642 return 1;
643 sym = 0;
644 while ((sym = agnxtattr(g, AGTYPE(oldobj), sym))) {
645 newsym = agattrsym(newobj, sym->name);
646 if (!newsym)
647 return 1;
648 val = agxget(oldobj, sym);
649 if (aghtmlstr(val)) {
650 r = agxset_html(newobj, newsym, val);
651 } else {
652 r = agxset(newobj, newsym, val);
653 }
654 }
655 return r;
656}
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:599
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:497
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:257
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:612
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:210
static Agrec_t * agmakeattrs(Agraph_t *context, void *obj)
Definition attr.c:165
static void unviewsubgraphsattr(Agraph_t *parent, char *name)
Definition attr.c:232
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:198
static Agsym_t * agattr_(Agraph_t *g, int kind, char *name, const char *value, bool is_html)
Definition attr.c:317
static char DataDictName[]
Definition attr.c:43
static Agsym_t * getattr(Agraph_t *g, int kind, char *name)
Definition attr.c:223
static int agset_(void *obj, char *name, const char *value, bool is_html)
Definition attr.c:464
#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:205
void agnodeattr_init(Agraph_t *g, Agnode_t *n)
Definition attr.c:409
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:551
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:333
void agnodeattr_delete(Agnode_t *n)
Definition attr.c:418
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:341
int agset(void *obj, char *name, const char *value)
Definition attr.c:474
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:362
void agedgeattr_init(Agraph_t *g, Agedge_t *e)
Definition attr.c:428
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:521
void agraphattr_init(Agraph_t *g)
Definition attr.c:379
int agxset_html(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:540
char * agget(void *obj, char *name)
Definition attr.c:447
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:559
int agset_html(void *obj, char *name, const char *value)
Definition attr.c:493
int agset_text(void *obj, char *name, const char *value)
Definition attr.c:489
void agedgeattr_delete(Agedge_t *e)
Definition attr.c:437
Agdatadict_t * agdatadict(Agraph_t *g, bool cflag)
Definition attr.c:49
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:457
int agcopyattr(void *oldobj, void *newobj)
copies all of the attributes from one object to another
Definition attr.c:632
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:544
int agraphattr_delete(Agraph_t *g)
Definition attr.c:390
Agsym_t * agattr_html(Agraph_t *g, int kind, char *name, const char *value)
agattr_text, but creates HTML-like values
Definition attr.c:337
int agxset_text(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:536
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