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