Graphviz 16.1.1~dev.20260925.1638
Loading...
Searching...
No Matches
utils.c
Go to the documentation of this file.
1
3/*************************************************************************
4 * Copyright (c) 2011 AT&T Intellectual Property
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v2.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
9 *
10 * Contributors: Details at https://graphviz.org
11 *************************************************************************/
12
13#include "config.h"
14
15#include <common/render.h>
16#include <common/geomprocs.h>
17#include <common/htmltable.h>
18#include <common/entities.h>
19#include <float.h>
20#include <limits.h>
21#include <math.h>
22#include <gvc/gvc.h>
23#include <stdatomic.h>
24#include <stddef.h>
25#include <stdbool.h>
26#include <stdint.h>
27#include <unistd.h>
28#include <util/agxbuf.h>
29#include <util/alloc.h>
30#include <util/gv_ctype.h>
31#include <util/gv_math.h>
32#include <util/list.h>
33#include <util/path.h>
34#include <util/startswith.h>
35#include <util/strcasecmp.h>
36#include <util/streq.h>
37#include <util/strview.h>
38#include <util/tokenize.h>
39
40int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum) {
41 if (attr == NULL)
42 return defaultValue;
43 char *p = agxget(obj, attr);
44 if (!p || p[0] == '\0')
45 return defaultValue;
46 char *endp;
47 long rv = strtol(p, &endp, 10);
48 if (p == endp || rv > INT_MAX)
49 return defaultValue; /* invalid int format */
50 if (rv < minimum)
51 return minimum;
52 return (int)rv;
53}
54
55double late_double(void *obj, attrsym_t *attr, double defaultValue,
56 double minimum) {
57 if (!attr || !obj)
58 return defaultValue;
59 char *p = agxget(obj, attr);
60 if (!p || p[0] == '\0')
61 return defaultValue;
62 char *endp;
63 double rv = strtod(p, &endp);
64 if (p == endp)
65 return defaultValue; /* invalid double format */
66 if (rv < minimum)
67 return minimum;
68 return rv;
69}
70
79 if (PSinputscale > 0) return PSinputscale; /* command line flag prevails */
80 double d = late_double(g, agfindgraphattr(g, "inputscale"), -1, 0);
81 if (is_exactly_zero(d)) return POINTS_PER_INCH;
82 return d;
83}
84
85char *late_string(void *obj, attrsym_t *attr, char *defaultValue) {
86 if (!attr || !obj)
87 return defaultValue;
88 return agxget(obj, attr);
89}
90
91char *late_nnstring(void *obj, attrsym_t *attr, char *defaultValue) {
92 char *rv = late_string(obj, attr, defaultValue);
93 if (!rv || (rv[0] == '\0'))
94 return defaultValue;
95 return rv;
96}
97
98bool late_bool(void *obj, attrsym_t *attr, bool defaultValue) {
99 if (attr == NULL)
100 return defaultValue;
101
102 return mapbool(agxget(obj, attr));
103}
104
106{
107 while (ND_UF_parent(n) && ND_UF_parent(n) != n) {
110 n = ND_UF_parent(n);
111 }
112 return n;
113}
114
116{
117 if (u == v)
118 return u;
119 if (ND_UF_parent(u) == NULL) {
120 ND_UF_parent(u) = u;
121 ND_UF_size(u) = 1;
122 } else
123 u = UF_find(u);
124 if (ND_UF_parent(v) == NULL) {
125 ND_UF_parent(v) = v;
126 ND_UF_size(v) = 1;
127 } else
128 v = UF_find(v);
129 /* if we have two copies of the same node, their union is just that node */
130 if (u == v)
131 return u;
132 if (ND_id(u) > ND_id(v)) {
133 ND_UF_parent(u) = v;
134 ND_UF_size(v) += ND_UF_size(u);
135 } else {
136 ND_UF_parent(v) = u;
137 ND_UF_size(u) += ND_UF_size(v);
138 v = u;
139 }
140 return v;
141}
142
144{
145 ND_UF_size(u) = 1;
146 ND_UF_parent(u) = NULL;
147 ND_ranktype(u) = NORMAL;
148}
149
151{
152 assert(u == UF_find(u));
153 ND_UF_parent(u) = v;
154 ND_UF_size(v) += ND_UF_size(u);
155}
156
158{
159 pointf r;
160
161 r.x = POINTS_PER_INCH * ND_pos(n)[0];
162 r.y = POINTS_PER_INCH * ND_pos(n)[1];
163 return r;
164}
165
166/* from Glassner's Graphics Gems */
167#define W_DEGREE 5
168
169/*
170 * Evaluate a Bézier curve at a particular parameter value
171 * Fill in control points for resulting sub-curves if "Left" and
172 * "Right" are non-null.
173 *
174 */
175pointf Bezier(const pointf *V, double t, pointf *Left, pointf *Right) {
176 const int degree = 3;
177 int i, j; /* Index variables */
178 pointf Vtemp[W_DEGREE + 1][W_DEGREE + 1];
179
180 /* Copy control points */
181 for (j = 0; j <= degree; j++) {
182 Vtemp[0][j] = V[j];
183 }
184
185 /* Triangle computation */
186 for (i = 1; i <= degree; i++) {
187 for (j = 0; j <= degree - i; j++) {
188 Vtemp[i][j].x =
189 (1.0 - t) * Vtemp[i - 1][j].x + t * Vtemp[i - 1][j + 1].x;
190 Vtemp[i][j].y =
191 (1.0 - t) * Vtemp[i - 1][j].y + t * Vtemp[i - 1][j + 1].y;
192 }
193 }
194
195 if (Left != NULL)
196 for (j = 0; j <= degree; j++)
197 Left[j] = Vtemp[j][0];
198 if (Right != NULL)
199 for (j = 0; j <= degree; j++)
200 Right[j] = Vtemp[degree - j][j];
201
202 return Vtemp[degree][0];
203}
204
205#ifdef DEBUG
206edge_t *debug_getedge(graph_t * g, char *s0, char *s1)
207{
208 node_t *n0, *n1;
209 n0 = agfindnode(g, s0);
210 n1 = agfindnode(g, s1);
211 if (n0 && n1)
212 return agfindedge(g, n0, n1);
213 return NULL;
214}
215Agraphinfo_t* GD_info(graph_t * g) { return ((Agraphinfo_t*)AGDATA(g));}
216Agnodeinfo_t* ND_info(node_t * n) { return ((Agnodeinfo_t*)AGDATA(n));}
217#endif
218
219/* safefile:
220 * Check to make sure it is okay to read in files.
221 * It returns NULL if the filename is trivial.
222 *
223 * If the application has set the SERVER_NAME environment variable,
224 * this indicates it is web-active.
225 *
226 * If filename contains multiple components, the user is
227 * warned, once, that everything to the left is ignored.
228 *
229 * For non-server applications, we use the path list in Gvimagepath to
230 * resolve relative pathnames.
231 *
232 * N.B. safefile uses a fixed buffer, so functions using it should use the
233 * value immediately or make a copy.
234 */
235#ifdef _WIN32
236#define PATHSEP ";"
237#else
238#define PATHSEP ":"
239#endif
240
241typedef LIST(strview_t) strviews_t;
242
243static strviews_t mkDirlist(const char *list) {
244 strviews_t dirs = {0};
245
246 for (tok_t t = tok(list, PATHSEP); !tok_end(&t); tok_next(&t)) {
247 strview_t dir = tok_get(&t);
248 LIST_APPEND(&dirs, dir);
249 }
250 return dirs;
251}
252
253static char *findPath(const strviews_t dirs, const char *str) {
254 static agxbuf safefilename;
255
256 for (size_t i = 0; i < LIST_SIZE(&dirs); ++i) {
257 const strview_t d = LIST_GET(&dirs, i);
258 agxbprint(&safefilename, "%.*s%c%s", (int)d.size, d.data, PATH_SEPARATOR, str);
259 char *filename = agxbuse(&safefilename);
260 if (access(filename, R_OK) == 0)
261 return filename;
262 }
263 return NULL;
264}
265
266const char *safefile(const char *filename)
267{
268 static atomic_flag onetime;
269
270 if (!filename || !filename[0])
271 return NULL;
272
273 if (HTTPServerEnVar) { /* If used as a server */
274 if (!atomic_flag_test_and_set(&onetime)) {
276 "file loading is disabled because the environment contains SERVER_NAME=\"%s\"\n",
278 }
279 return NULL;
280 }
281
282 if (Gvfilepath != NULL) {
283 const char *const pathlist = Gvfilepath;
284 strviews_t dirs = mkDirlist(pathlist);
285
286 const char *str = filename;
287 for (const char *sep = "/\\:"; *sep != '\0'; ++sep) {
288 const char *p = strrchr(str, *sep);
289 if (p != NULL) {
290 str = ++p;
291 }
292 }
293
294 const char *const ret = findPath(dirs, str);
295 LIST_FREE(&dirs);
296 return ret;
297 }
298
299 const char *const pathlist = Gvimagepath;
300 strviews_t dirs = {0};
301 if (pathlist && *pathlist)
302 dirs = mkDirlist(pathlist);
303
304 const char *ret;
305 if (*filename == PATH_SEPARATOR || LIST_IS_EMPTY(&dirs)) {
306 ret = filename;
307 } else {
308 ret = findPath(dirs, filename);
309 }
310
311 LIST_FREE(&dirs);
312 return ret;
313}
314
315int maptoken(char *p, char **name, int *val) {
316 char *q;
317
318 int i = 0;
319 for (; (q = name[i]) != 0; i++)
320 if (p && streq(p, q))
321 break;
322 return val[i];
323}
324
325bool mapBool(const char *p, bool defaultValue) {
326 if (!p || *p == '\0')
327 return defaultValue;
328 if (!strcasecmp(p, "false"))
329 return false;
330 if (!strcasecmp(p, "no"))
331 return false;
332 if (!strcasecmp(p, "true"))
333 return true;
334 if (!strcasecmp(p, "yes"))
335 return true;
336 if (gv_isdigit(*p))
337 return atoi(p) != 0;
338 return defaultValue;
339}
340
341bool mapbool(const char *p)
342{
343 return mapBool(p, false);
344}
345
347{
348 pointf pt2;
349
350 size_t besti = SIZE_MAX;
351 size_t bestj = SIZE_MAX;
352 double bestdist2 = DBL_MAX;
353 for (size_t i = 0; i < spl->size; i++) {
354 const bezier bz = spl->list[i];
355 for (size_t j = 0; j < bz.size; j++) {
356 const pointf b = bz.list[j];
357 const double d2 = DIST2(b, pt);
358 if (bestj == SIZE_MAX || d2 < bestdist2) {
359 besti = i;
360 bestj = j;
361 bestdist2 = d2;
362 }
363 }
364 }
365
366 const bezier bz = spl->list[besti];
367 /* Pick best Bézier. If bestj is the last point in the B-spline, decrement.
368 * Then set j to be the first point in the corresponding Bézier by dividing
369 * then multiplying be 3. Thus, 0,1,2 => 0; 3,4,5 => 3, etc.
370 */
371 if (bestj == bz.size-1)
372 bestj--;
373 const size_t j = 3 * (bestj / 3);
374 const pointf c[] =
375 {bz.list[j], bz.list[j + 1], bz.list[j + 2], bz.list[j + 3]};
376 for (double low = 0, high = 1.0, dlow2 = DIST2(c[0], pt),
377 dhigh2 = DIST2(c[3], pt);;) {
378 const double t = (low + high) / 2.0;
379 pt2 = Bezier(c, t, NULL, NULL);
380 if (fabs(dlow2 - dhigh2) < 1.0)
381 break;
382 if (fabs(high - low) < .00001)
383 break;
384 if (dlow2 < dhigh2) {
385 high = t;
386 dhigh2 = DIST2(pt2, pt);
387 } else {
388 low = t;
389 dlow2 = DIST2(pt2, pt);
390 }
391 }
392 return pt2;
393}
394
395static int Tflag;
396void gvToggle(int s)
397{
398 (void)s;
399 Tflag = !Tflag;
400#if !defined(_WIN32)
401 signal(SIGUSR1, gvToggle);
402#endif
403}
404
405int test_toggle(void)
406{
407 return Tflag;
408}
409
410struct fontinfo {
411 double fontsize;
412 char *fontname;
414};
415
417{
418 struct fontinfo fi;
419 char *str;
420 ND_width(n) =
422 ND_height(n) =
424 ND_shape(n) =
426 str = agxget(n, N_label);
431 fi.fontsize, fi.fontname, fi.fontcolor);
432 if (N_xlabel && (str = agxget(n, N_xlabel)) && str[0]) {
433 ND_xlabel(n) = make_label(n, str, aghtmlstr(str), false,
434 fi.fontsize, fi.fontname, fi.fontcolor);
436 }
437
438 {
439 const int showboxes = imin(late_int(n, N_showboxes, 0, 0), UCHAR_MAX);
440 ND_showboxes(n) = (unsigned char)showboxes;
441 }
442 ND_shape(n)->fns->initfn(n);
443}
444
451
452static void
454 struct fontinfo *lfi)
455{
456 if (!fi->fontname) initFontEdgeAttr(e, fi);
460}
461
463static bool
465{
466 char *str;
467 bool rv = false;
468
469 if (sym) { /* mapbool isn't a good fit, because we want "" to mean true */
470 str = agxget(e,sym);
471 if (str && str[0]) rv = !mapbool(str);
472 else rv = false;
473 }
474 return rv;
475}
476
477static port
478chkPort (port (*pf)(node_t*, char*, char*), node_t* n, char* s)
479{
480 port pt;
481 char* cp=NULL;
482 if(s)
483 cp= strchr(s,':');
484 if (cp) {
485 *cp = '\0';
486 pt = pf(n, s, cp+1);
487 *cp = ':';
488 pt.name = cp+1;
489 }
490 else {
491 pt = pf(n, s, NULL);
492 pt.name = s;
493 }
494 return pt;
495}
496
497/* return true if edge has label */
499 char *str;
500 struct fontinfo fi;
501 struct fontinfo lfi;
502 graph_t *sg = agraphof(agtail(e));
503
504 fi.fontname = NULL;
505 lfi.fontname = NULL;
506 if (E_label && (str = agxget(e, E_label)) && str[0]) {
507 initFontEdgeAttr(e, &fi);
508 ED_label(e) = make_label(e, str, aghtmlstr(str), false,
509 fi.fontsize, fi.fontname, fi.fontcolor);
512 }
513
514 if (E_xlabel && (str = agxget(e, E_xlabel)) && str[0]) {
515 if (!fi.fontname)
516 initFontEdgeAttr(e, &fi);
517 ED_xlabel(e) = make_label(e, str, aghtmlstr(str), false,
518 fi.fontsize, fi.fontname, fi.fontcolor);
520 }
521
522 if (E_headlabel && (str = agxget(e, E_headlabel)) && str[0]) {
523 initFontLabelEdgeAttr(e, &fi, &lfi);
524 ED_head_label(e) = make_label(e, str, aghtmlstr(str), false,
525 lfi.fontsize, lfi.fontname, lfi.fontcolor);
527 }
528 if (E_taillabel && (str = agxget(e, E_taillabel)) && str[0]) {
529 if (!lfi.fontname)
530 initFontLabelEdgeAttr(e, &fi, &lfi);
531 ED_tail_label(e) = make_label(e, str, aghtmlstr(str), false,
532 lfi.fontsize, lfi.fontname, lfi.fontcolor);
534 }
535
536 /* We still accept ports beginning with colons but this is deprecated
537 * That is, we allow tailport = ":abc" as well as the preferred
538 * tailport = "abc".
539 */
540 str = agget(e, TAIL_ID);
541 /* libgraph always defines tailport/headport; libcgraph doesn't */
542 if (!str) str = "";
543 if (str && str[0])
544 ND_has_port(agtail(e)) = true;
545 ED_tail_port(e) = chkPort (ND_shape(agtail(e))->fns->portfn, agtail(e), str);
546 if (noClip(e, E_tailclip))
547 ED_tail_port(e).clip = false;
548 str = agget(e, HEAD_ID);
549 /* libgraph always defines tailport/headport; libcgraph doesn't */
550 if (!str) str = "";
551 if (str && str[0])
552 ND_has_port(aghead(e)) = true;
553 ED_head_port(e) = chkPort(ND_shape(aghead(e))->fns->portfn, aghead(e), str);
554 if (noClip(e, E_headclip))
555 ED_head_port(e).clip = false;
556}
557
558static boxf addLabelBB(boxf bb, textlabel_t * lp, bool flipxy)
559{
560 double width, height;
561 pointf p = lp->pos;
562 double min, max;
563
564 if (flipxy) {
565 height = lp->dimen.x;
566 width = lp->dimen.y;
567 }
568 else {
569 width = lp->dimen.x;
570 height = lp->dimen.y;
571 }
572 min = p.x - width / 2.;
573 max = p.x + width / 2.;
574 if (min < bb.LL.x)
575 bb.LL.x = min;
576 if (max > bb.UR.x)
577 bb.UR.x = max;
578
579 min = p.y - height / 2.;
580 max = p.y + height / 2.;
581 if (min < bb.LL.y)
582 bb.LL.y = min;
583 if (max > bb.UR.y)
584 bb.UR.y = max;
585
586 return bb;
587}
588
592boxf
594{
595 const size_t sides = poly->sides;
596 const size_t peris = MAX(poly->peripheries, (size_t)1);
597 pointf* verts = poly->vertices + (peris-1)*sides;
598 boxf bb;
599
600 bb.LL = bb.UR = verts[0];
601 for (size_t i = 1; i < sides; i++) {
602 bb.LL.x = MIN(bb.LL.x,verts[i].x);
603 bb.LL.y = MIN(bb.LL.y,verts[i].y);
604 bb.UR.x = MAX(bb.UR.x,verts[i].x);
605 bb.UR.y = MAX(bb.UR.y,verts[i].y);
606 }
607 return bb;
608}
609
614{
615 GD_bb(g) = addLabelBB(GD_bb(g), lp, GD_flip(g));
616}
617
623{
624 node_t *n;
625 edge_t *e;
626 boxf b, bb;
627 boxf BF;
628 pointf ptf, s2;
629
630 if (agnnodes(g) == 0 && GD_n_cluster(g) == 0) {
631 bb.LL = (pointf){0};
632 bb.UR = (pointf){0};
633 return;
634 }
635
636 bb.LL = (pointf){INT_MAX, INT_MAX};
637 bb.UR = (pointf){-INT_MAX, -INT_MAX};
638 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
639 ptf = coord(n);
640 s2.x = ND_xsize(n) / 2.0;
641 s2.y = ND_ysize(n) / 2.0;
642 b.LL = sub_pointf(ptf, s2);
643 b.UR = add_pointf(ptf, s2);
644
645 EXPANDBB(&bb, b);
646 if (ND_xlabel(n) && ND_xlabel(n)->set) {
647 bb = addLabelBB(bb, ND_xlabel(n), GD_flip(g));
648 }
649 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
650 if (ED_spl(e) == 0)
651 continue;
652 for (size_t i = 0; i < ED_spl(e)->size; i++) {
653 for (size_t j = 0; j < (((Agedgeinfo_t*)AGDATA(e))->spl)->list[i].size; j++) {
654 ptf = ED_spl(e)->list[i].list[j];
655 expandbp(&bb, ptf);
656 }
657 }
658 if (ED_label(e) && ED_label(e)->set) {
659 bb = addLabelBB(bb, ED_label(e), GD_flip(g));
660 }
661 if (ED_head_label(e) && ED_head_label(e)->set) {
662 bb = addLabelBB(bb, ED_head_label(e), GD_flip(g));
663 }
664 if (ED_tail_label(e) && ED_tail_label(e)->set) {
665 bb = addLabelBB(bb, ED_tail_label(e), GD_flip(g));
666 }
667 if (ED_xlabel(e) && ED_xlabel(e)->set) {
668 bb = addLabelBB(bb, ED_xlabel(e), GD_flip(g));
669 }
670 }
671 }
672
673 for (int i = 1; i <= GD_n_cluster(g); i++) {
674 B2BF(GD_bb(GD_clust(g)[i]), BF);
675 EXPANDBB(&bb, BF);
676 }
677 if (GD_label(g) && GD_label(g)->set) {
678 bb = addLabelBB(bb, GD_label(g), GD_flip(g));
679 }
680
681 GD_bb(g) = bb;
682}
683
685{
686 return g == g->root || !strncasecmp(agnameof(g), "cluster", 7) ||
687 mapbool(agget(g, "cluster"));
688}
689
693Agsym_t *setAttr(graph_t * g, void *obj, char *name, char *value,
694 Agsym_t * ap)
695{
696 if (ap == NULL) {
697 switch (agobjkind(obj)) {
698 case AGRAPH:
699 ap = agattr_text(g, AGRAPH,name, "");
700 break;
701 case AGNODE:
702 ap = agattr_text(g,AGNODE, name, "");
703 break;
704 case AGEDGE:
705 ap = agattr_text(g,AGEDGE, name, "");
706 break;
707 }
708 }
709 agxset(obj, ap, value);
710 return ap;
711}
712
721 int *idx) {
722 node_t *cn;
723
724 agxbprint(xb, "__%d:%s", *idx++, agnameof(cg));
725
726 cn = agnode(agroot(cg), agxbuse(xb), 1);
727 agbindrec(cn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
728
729 SET_CLUST_NODE(cn);
730 agsubnode(cg,cn,1);
731 agsubnode(clg,n,1);
732
733 /* set attributes */
734 N_label = setAttr(agraphof(cn), cn, "label", "", N_label);
735 N_style = setAttr(agraphof(cn), cn, "style", "invis", N_style);
736 N_shape = setAttr(agraphof(cn), cn, "shape", "box", N_shape);
737
738 return cn;
739}
740
741typedef struct {
742 Dtlink_t link; /* cdt data */
743 void *p[2]; /* key */
746} item;
747
748static int cmpItem(void *pp1, void *pp2) {
749 const void **p1 = pp1;
750 const void **p2 = pp2;
751 if ((uintptr_t)p1[0] < (uintptr_t)p2[0])
752 return -1;
753 if ((uintptr_t)p1[0] > (uintptr_t)p2[0])
754 return 1;
755 if ((uintptr_t)p1[1] < (uintptr_t)p2[1])
756 return -1;
757 if ((uintptr_t)p1[1] > (uintptr_t)p2[1])
758 return 1;
759 return 0;
760}
761
762static void *newItem(void *p, Dtdisc_t *disc) {
763 item *objp = p;
764 item *newp = gv_alloc(sizeof(item));
765
766 (void)disc;
767 newp->p[0] = objp->p[0];
768 newp->p[1] = objp->p[1];
769 newp->t = objp->t;
770 newp->h = objp->h;
771
772 return newp;
773}
774
776 .key = offsetof(item, p),
777 .size = sizeof(2 * sizeof(void *)),
778 .link = offsetof(item, link),
779 .makef = newItem,
780 .freef = free,
781 .comparf = cmpItem,
782};
783
785static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch)
786{
787 graph_t *g = agraphof(ct);
788 edge_t *ce = agedge(g, ct, ch,NULL,1);
789 agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true);
790 agcopyattr(e, ce);
791 ED_compound(ce) = true;
792
793 return ce;
794}
795
796static void insertEdge(Dt_t * map, void *t, void *h, edge_t * e)
797{
798 item dummy1 = {.p = {t, h}, .t = agtail(e), .h = aghead(e)};
799 dtinsert(map, &dummy1);
800
801 item dummy2 = {.p = {h, t}, .t = aghead(e), .h = agtail(e)};
802 dtinsert(map, &dummy2);
803}
804
806static item *mapEdge(Dt_t * map, edge_t * e)
807{
808 void *key[] = {agtail(e), aghead(e)};
809 return dtmatch(map, &key);
810}
811
812static graph_t *mapc(Dt_t *cmap, node_t *n) {
813 if (startswith(agnameof(n), "cluster")) {
814 return findCluster(cmap, agnameof(n));
815 }
816 return NULL;
817}
818
835static int checkCompound(edge_t *e, graph_t *clg, agxbuf *xb, Dt_t *map,
836 Dt_t *cmap, int *index_counter) {
837 node_t *cn;
838 node_t *cn1;
839 node_t *t = agtail(e);
840 node_t *h = aghead(e);
841 edge_t *ce;
842 item *ip;
843
844 if (IS_CLUST_NODE(h)) return 0;
845 graph_t *const tg = mapc(cmap, t);
846 graph_t *const hg = mapc(cmap, h);
847 if (!tg && !hg)
848 return 0;
849 if (tg == hg) {
850 agwarningf("cluster cycle %s -- %s not supported\n", agnameof(t),
851 agnameof(t));
852 return 0;
853 }
854 ip = mapEdge(map, e);
855 if (ip) {
856 cloneEdge(e, ip->t, ip->h);
857 return 1;
858 }
859
860 if (hg) {
861 if (tg) {
862 if (agcontains(hg, tg)) {
863 agwarningf("tail cluster %s inside head cluster %s\n",
864 agnameof(tg), agnameof(hg));
865 return 0;
866 }
867 if (agcontains(tg, hg)) {
868 agwarningf("head cluster %s inside tail cluster %s\n",
869 agnameof(hg),agnameof(tg));
870 return 0;
871 }
872 cn = clustNode(t, tg, xb, clg, index_counter);
873 cn1 = clustNode(h, hg, xb, clg, index_counter);
874 ce = cloneEdge(e, cn, cn1);
875 insertEdge(map, t, h, ce);
876 } else {
877 if (agcontains(hg, t)) {
878 agwarningf("tail node %s inside head cluster %s\n",
879 agnameof(t), agnameof(hg));
880 return 0;
881 }
882 cn = clustNode(h, hg, xb, clg, index_counter);
883 ce = cloneEdge(e, t, cn);
884 insertEdge(map, t, h, ce);
885 }
886 } else {
887 if (agcontains(tg, h)) {
888 agwarningf("head node %s inside tail cluster %s\n", agnameof(h),
889 agnameof(tg));
890 return 0;
891 }
892 cn = clustNode(t, tg, xb, clg, index_counter);
893 ce = cloneEdge(e, cn, h);
894 insertEdge(map, t, h, ce);
895 }
896 return 1;
897}
898
899typedef struct {
902} cl_edge_t;
903
904static int
906{
907 cl_edge_t* cl_info = (cl_edge_t*)HAS_CLUST_EDGE(g);
908 if (cl_info)
909 return cl_info->n_cluster_edges;
910 return 0;
911}
912
920{
921 int num_cl_edges = 0;
922 node_t *n;
923 node_t *nxt;
924 edge_t *e;
925 graph_t *clg;
926 agxbuf xb = {0};
927 Dt_t *map;
928 Dt_t *cmap = mkClustMap (g);
929 int index_counter = 0;
930
931 map = dtopen(&mapDisc, Dtoset);
932 clg = agsubg(g, "__clusternodes",1);
933 agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
934 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
935 if (IS_CLUST_NODE(n)) continue;
936 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
937 num_cl_edges += checkCompound(e, clg, &xb, map, cmap, &index_counter);
938 }
939 }
940 agxbfree(&xb);
941 dtclose(map);
942 for (n = agfstnode(clg); n; n = nxt) {
943 nxt = agnxtnode(clg, n);
944 agdelete(g, n);
945 }
946 agclose(clg);
947 if (num_cl_edges) {
948 cl_edge_t* cl_info;
949 cl_info = agbindrec(g, CL_EDGE_TAG, sizeof(cl_edge_t), false);
950 cl_info->n_cluster_edges = num_cl_edges;
951 }
952 dtclose(cmap);
953}
954
962static node_t *mapN(node_t * n, graph_t * clg)
963{
964 node_t *nn;
965 char *name;
966 graph_t *g = agraphof(n);
967 Agsym_t *sym;
968
969 if (!IS_CLUST_NODE(n))
970 return n;
971 agsubnode(clg, n, 1);
972 name = strchr(agnameof(n), ':');
973 assert(name);
974 name++;
975 if ((nn = agfindnode(g, name)))
976 return nn;
977 nn = agnode(g, name, 1);
978 agbindrec(nn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
979 SET_CLUST_NODE(nn);
980
981 /* Set all attributes to default */
982 for (sym = agnxtattr(g, AGNODE, NULL); sym; (sym = agnxtattr(g, AGNODE, sym))) {
983 if (agxget(nn, sym) != sym->defval)
984 agxset(nn, sym, sym->defval);
985 }
986 return nn;
987}
988
989static void undoCompound(edge_t * e, graph_t * clg)
990{
991 node_t *t = agtail(e);
992 node_t *h = aghead(e);
993 node_t *ntail;
994 node_t *nhead;
995 edge_t* ce;
996
997 ntail = mapN(t, clg);
998 nhead = mapN(h, clg);
999 ce = cloneEdge(e, ntail, nhead);
1000
1001 /* transfer drawing information */
1002 ED_spl(ce) = ED_spl(e);
1003 ED_spl(e) = NULL;
1004 ED_label(ce) = ED_label(e);
1005 ED_label(e) = NULL;
1006 ED_xlabel(ce) = ED_xlabel(e);
1007 ED_xlabel(e) = NULL;
1009 ED_head_label(e) = NULL;
1011 ED_tail_label(e) = NULL;
1012 gv_cleanup_edge(e);
1013}
1014
1020{
1021 node_t *n;
1022 node_t *nextn;
1023 edge_t *e;
1024 graph_t *clg;
1025 int ecnt = num_clust_edges(g);
1026 int i = 0;
1027
1028 if (!ecnt) return;
1029 clg = agsubg(g, "__clusternodes",1);
1030 agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
1031 edge_t **edgelist = gv_calloc(ecnt, sizeof(edge_t*));
1032 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
1033 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
1034 if (ED_compound(e))
1035 edgelist[i++] = e;
1036 }
1037 }
1038 assert(i == ecnt);
1039 for (i = 0; i < ecnt; i++)
1040 undoCompound(edgelist[i], clg);
1041 free (edgelist);
1042 for (n = agfstnode(clg); n; n = nextn) {
1043 nextn = agnxtnode(clg, n);
1044 gv_cleanup_node(n);
1045 agdelete(g, n);
1046 }
1047 agclose(clg);
1048}
1049
1054attrsym_t *safe_dcl(graph_t *g, int obj_kind, char *name, char *defaultValue) {
1055 attrsym_t *a = agattr_text(g,obj_kind,name, NULL);
1056 if (!a) /* attribute does not exist */
1057 a = agattr_text(g, obj_kind, name, defaultValue);
1058 return a;
1059}
1060
1061static int comp_entities(const void *e1, const void *e2) {
1062 const strview_t *key = e1;
1063 const struct entities_s *candidate = e2;
1064 return strview_cmp(*key, strview(candidate->name, '\0'));
1065}
1066
1071char* scanEntity (char* t, agxbuf* xb)
1072{
1073 const strview_t key = strview(t, ';');
1074 struct entities_s *res;
1075
1076 agxbputc(xb, '&');
1077 if (key.data[key.size] == '\0') return t;
1078 if (key.size > ENTITY_NAME_LENGTH_MAX || key.size < 2) return t;
1079 res = bsearch(&key, entities, NR_OF_ENTITIES,
1080 sizeof(entities[0]), comp_entities);
1081 if (!res) return t;
1082 agxbprint(xb, "#%d;", res->value);
1083 return t + key.size + 1;
1084}
1085
1092static int
1094{
1095 struct entities_s *res;
1096 unsigned char* str = *(unsigned char**)s;
1097 unsigned int byte;
1098 int i, n = 0;
1099
1100 byte = *str;
1101 if (byte == '#') {
1102 byte = *(str + 1);
1103 if (byte == 'x' || byte == 'X') {
1104 for (i = 2; i < 8; i++) {
1105 byte = *(str + i);
1106 if (byte >= 'A' && byte <= 'F')
1107 byte = byte - 'A' + 10;
1108 else if (byte >= 'a' && byte <= 'f')
1109 byte = byte - 'a' + 10;
1110 else if (byte >= '0' && byte <= '9')
1111 byte = byte - '0';
1112 else
1113 break;
1114 n = n * 16 + (int)byte;
1115 }
1116 }
1117 else {
1118 for (i = 1; i < 8; i++) {
1119 byte = *(str + i);
1120 if (byte >= '0' && byte <= '9')
1121 n = n * 10 + ((int)byte - '0');
1122 else
1123 break;
1124 }
1125 }
1126 if (byte == ';') {
1127 str += i+1;
1128 }
1129 else {
1130 n = 0;
1131 }
1132 }
1133 else {
1134 strview_t key = {.data = (char *)str};
1135 for (i = 0; i < ENTITY_NAME_LENGTH_MAX; i++) {
1136 byte = *(str + i);
1137 if (byte == '\0') break;
1138 if (byte == ';') {
1139 res = bsearch(&key, entities, NR_OF_ENTITIES,
1140 sizeof(entities[0]), comp_entities);
1141 if (res) {
1142 n = res->value;
1143 str += i+1;
1144 }
1145 break;
1146 }
1147 ++key.size;
1148 }
1149 }
1150 *s = (char*)str;
1151 return n;
1152}
1153
1154static unsigned char
1155cvtAndAppend (unsigned char c, agxbuf* xb)
1156{
1157 char buf[] = {c, '\0'};
1158 char *s = latin1ToUTF8(buf);
1159 char *p = s;
1160 size_t len = strlen(s);
1161 while (len-- > 1)
1162 agxbputc(xb, *p++);
1163 c = *p;
1164 free (s);
1165 return c;
1166}
1167
1172char* htmlEntityUTF8 (char* s, graph_t* g)
1173{
1174 static graph_t* lastg;
1175 static atomic_flag warned;
1176 unsigned char c;
1177 unsigned int v;
1178
1179 int uc;
1180 int ui;
1181
1182 if (lastg != g) {
1183 lastg = g;
1184 atomic_flag_clear(&warned);
1185 }
1186
1187 agxbuf xb = {0};
1188
1189 while ((c = *(unsigned char*)s++)) {
1190 if (c < 0xC0)
1191 /*
1192 * Handles properly formed UTF-8 characters between
1193 * 0x01 and 0x7F. Also treats \0 and naked trail
1194 * bytes 0x80 to 0xBF as valid characters representing
1195 * themselves.
1196 */
1197 uc = 0;
1198 else if (c < 0xE0)
1199 uc = 1;
1200 else if (c < 0xF0)
1201 uc = 2;
1202 else if (c < 0xF8)
1203 uc = 3;
1204 else {
1205 uc = -1;
1206 if (!atomic_flag_test_and_set(&warned)) {
1207 agwarningf("UTF8 codes > 4 bytes are not currently supported (graph %s) - treated as Latin-1. Perhaps \"-Gcharset=latin1\" is needed?\n", agnameof(g));
1208 }
1209 c = cvtAndAppend (c, &xb);
1210 }
1211
1212 if (uc == 0 && c == '&') {
1213 /* replace html entity sequences like: &amp;
1214 * and: &#123; with their UTF8 equivalents */
1215 v = htmlEntity (&s);
1216 if (v) {
1217 if (v < 0x7F) /* entity needs 1 byte in UTF8 */
1218 c = v;
1219 else if (v < 0x07FF) { /* entity needs 2 bytes in UTF8 */
1220 agxbputc(&xb, (char)((v >> 6) | 0xC0));
1221 c = (v & 0x3F) | 0x80;
1222 }
1223 else { /* entity needs 3 bytes in UTF8 */
1224 agxbputc(&xb, (char)((v >> 12) | 0xE0));
1225 agxbputc(&xb, (char)(((v >> 6) & 0x3F) | 0x80));
1226 c = (v & 0x3F) | 0x80;
1227 }
1228 }
1229 }
1230 else /* copy n byte UTF8 characters */
1231 for (ui = 0; ui < uc; ++ui)
1232 if ((*s & 0xC0) == 0x80) {
1233 agxbputc(&xb, (char)c);
1234 c = *(unsigned char*)s++;
1235 }
1236 else {
1237 if (!atomic_flag_test_and_set(&warned)) {
1238 agwarningf("Invalid %d-byte UTF8 found in input of graph %s - treated as Latin-1. Perhaps \"-Gcharset=latin1\" is needed?\n", uc + 1, agnameof(g));
1239 }
1240 c = cvtAndAppend (c, &xb);
1241 break;
1242 }
1243 agxbputc(&xb, (char)c);
1244 }
1245 return agxbdisown(&xb);
1246}
1247
1249char* latin1ToUTF8 (char* s)
1250{
1251 agxbuf xb = {0};
1252 unsigned int v;
1253
1254 /* Values are either a byte (<= 256) or come from htmlEntity, whose
1255 * values are all less than 0x07FF, so we need at most 3 bytes.
1256 */
1257 while ((v = *(unsigned char*)s++)) {
1258 if (v == '&') {
1259 v = htmlEntity (&s);
1260 if (!v) v = '&';
1261 }
1262 if (v < 0x7F)
1263 agxbputc(&xb, (char)v);
1264 else if (v < 0x07FF) {
1265 agxbputc(&xb, (char)((v >> 6) | 0xC0));
1266 agxbputc(&xb, (char)((v & 0x3F) | 0x80));
1267 }
1268 else {
1269 agxbputc(&xb, (char)((v >> 12) | 0xE0));
1270 agxbputc(&xb, (char)(((v >> 6) & 0x3F) | 0x80));
1271 agxbputc(&xb, (char)((v & 0x3F) | 0x80));
1272 }
1273 }
1274 return agxbdisown(&xb);
1275}
1276
1281char*
1283{
1284 agxbuf xb = {0};
1285 unsigned char c;
1286
1287 while ((c = *(unsigned char*)s++)) {
1288 if (c < 0x7F)
1289 agxbputc(&xb, (char)c);
1290 else {
1291 unsigned char outc = (c & 0x03) << 6;
1292 c = *(unsigned char *)s++;
1293 outc = outc | (c & 0x3F);
1294 agxbputc(&xb, (char)outc);
1295 }
1296 }
1297 return agxbdisown(&xb);
1298}
1299
1301 if (! OVERLAP(b, ND_bb(n)))
1302 return false;
1303
1304 /* FIXME - need to do something better about CLOSEENOUGH */
1305 pointf p = sub_pointf(ND_coord(n), mid_pointf(b.UR, b.LL));
1306
1307 inside_t ictxt = {.s.n = n};
1308
1309 return ND_shape(n)->fns->insidefn(&ictxt, p);
1310}
1311
1313{
1314 const pointf s = {.x = lp->dimen.x / 2.0, .y = lp->dimen.y / 2.0};
1315 boxf bb = {.LL = sub_pointf(lp->pos, s), .UR = add_pointf(lp->pos, s)};
1316 return OVERLAP(b, bb);
1317}
1318
1319static bool overlap_arrow(pointf p, pointf u, double scale, boxf b)
1320{
1321 // FIXME - check inside arrow shape
1322 return OVERLAP(b, arrow_bb(p, u, scale));
1323}
1324
1325static bool overlap_bezier(bezier bz, boxf b) {
1326 assert(bz.size);
1327 pointf u = bz.list[0];
1328 for (size_t i = 1; i < bz.size; i++) {
1329 pointf p = bz.list[i];
1330 if (lineToBox(p, u, b) != -1)
1331 return true;
1332 u = p;
1333 }
1334
1335 /* check arrows */
1336 if (bz.sflag) {
1337 if (overlap_arrow(bz.sp, bz.list[0], 1, b))
1338 return true;
1339 }
1340 if (bz.eflag) {
1341 if (overlap_arrow(bz.ep, bz.list[bz.size - 1], 1, b))
1342 return true;
1343 }
1344 return false;
1345}
1346
1348{
1349 splines *spl = ED_spl(e);
1350 if (spl && boxf_overlap(spl->bb, b))
1351 for (size_t i = 0; i < spl->size; i++)
1352 if (overlap_bezier(spl->list[i], b))
1353 return true;
1354
1355 textlabel_t *lp = ED_label(e);
1356 if (lp && overlap_label(lp, b))
1357 return true;
1358
1359 return false;
1360}
1361
1363static int edgeType(const char *s, int defaultValue) {
1364 if (s == NULL || strcmp(s, "") == 0) {
1365 return defaultValue;
1366 }
1367
1368 if (*s == '0') { /* false */
1369 return EDGETYPE_LINE;
1370 } else if (*s >= '1' && *s <= '9') { /* true */
1371 return EDGETYPE_SPLINE;
1372 } else if (strcasecmp(s, "curved") == 0) {
1373 return EDGETYPE_CURVED;
1374 } else if (strcasecmp(s, "compound") == 0) {
1375 return EDGETYPE_COMPOUND;
1376 } else if (strcasecmp(s, "false") == 0) {
1377 return EDGETYPE_LINE;
1378 } else if (strcasecmp(s, "line") == 0) {
1379 return EDGETYPE_LINE;
1380 } else if (strcasecmp(s, "none") == 0) {
1381 return EDGETYPE_NONE;
1382 } else if (strcasecmp(s, "no") == 0) {
1383 return EDGETYPE_LINE;
1384 } else if (strcasecmp(s, "ortho") == 0) {
1385 return EDGETYPE_ORTHO;
1386 } else if (strcasecmp(s, "polyline") == 0) {
1387 return EDGETYPE_PLINE;
1388 } else if (strcasecmp(s, "spline") == 0) {
1389 return EDGETYPE_SPLINE;
1390 } else if (strcasecmp(s, "true") == 0) {
1391 return EDGETYPE_SPLINE;
1392 } else if (strcasecmp(s, "yes") == 0) {
1393 return EDGETYPE_SPLINE;
1394 }
1395
1396 agwarningf("Unknown \"splines\" value: \"%s\" - ignored\n", s);
1397 return defaultValue;
1398}
1399
1412void setEdgeType(graph_t *g, int defaultValue) {
1413 char* s = agget(g, "splines");
1414 int et;
1415
1416 if (!s) {
1417 et = defaultValue;
1418 }
1419 else if (*s == '\0') {
1420 et = EDGETYPE_NONE;
1421 } else {
1422 et = edgeType(s, defaultValue);
1423 }
1424 GD_flags(g) |= et;
1425}
1426
1435void get_gradient_points(pointf *A, pointf *G, size_t n, double angle, int flags) {
1436 pointf min,max,center;
1437 int isRadial = flags & 1;
1438 int isRHS = flags & 2;
1439
1440 if (n == 2) {
1441 double rx = A[1].x - A[0].x;
1442 double ry = A[1].y - A[0].y;
1443 min.x = A[0].x - rx;
1444 max.x = A[0].x + rx;
1445 min.y = A[0].y - ry;
1446 max.y = A[0].y + ry;
1447 }
1448 else {
1449 min.x = max.x = A[0].x;
1450 min.y = max.y = A[0].y;
1451 for (size_t i = 0; i < n; i++) {
1452 min.x = MIN(A[i].x, min.x);
1453 min.y = MIN(A[i].y, min.y);
1454 max.x = MAX(A[i].x, max.x);
1455 max.y = MAX(A[i].y, max.y);
1456 }
1457 }
1458 center.x = min.x + (max.x - min.x)/2;
1459 center.y = min.y + (max.y - min.y)/2;
1460 if (isRadial) {
1461 double inner_r, outer_r;
1462 outer_r = hypot(center.x - min.x, center.y - min.y);
1463 inner_r = outer_r /4.;
1464 if (isRHS) {
1465 G[0].y = center.y;
1466 }
1467 else {
1468 G[0].y = -center.y;
1469 }
1470 G[0].x = center.x;
1471 G[1].x = inner_r;
1472 G[1].y = outer_r;
1473 }
1474 else {
1475 double half_x = max.x - center.x;
1476 double half_y = max.y - center.y;
1477 double sina = sin(angle);
1478 double cosa = cos(angle);
1479 if (isRHS) {
1480 G[0].y = center.y - half_y * sina;
1481 G[1].y = center.y + half_y * sina;
1482 }
1483 else {
1484 G[0].y = -center.y + (max.y - center.y) * sin(angle);
1485 G[1].y = -center.y - (center.y - min.y) * sin(angle);
1486 }
1487 G[0].x = center.x - half_x * cosa;
1488 G[1].x = center.x + half_x * cosa;
1489 }
1490}
1491
1493 if (ED_spl(e)) {
1494 for (size_t i = 0; i < ED_spl(e)->size; i++)
1495 free(ED_spl(e)->list[i].list);
1496 free(ED_spl(e)->list);
1497 free(ED_spl(e));
1498 }
1499 ED_spl(e) = NULL;
1500}
1501
1503{
1504 free(ED_path(e).ps);
1505 gv_free_splines(e);
1506 free_label(ED_label(e));
1510 /*FIX HERE , shallow cleaning may not be enough here */
1511 agdelrec(e, "Agedgeinfo_t");
1512}
1513
1515{
1516 free(ND_pos(n));
1517 if (ND_shape(n))
1518 ND_shape(n)->fns->freefn(n);
1519 free_label(ND_label(n));
1521 /*FIX HERE , shallow cleaning may not be enough here */
1522 agdelrec(n, "Agnodeinfo_t");
1523}
1524
1525void gv_nodesize(node_t *n, bool flip) {
1526 if (flip) {
1527 double w = INCH2PS(ND_height(n));
1528 ND_lw(n) = ND_rw(n) = w / 2;
1529 ND_ht(n) = INCH2PS(ND_width(n));
1530 }
1531 else {
1532 double w = INCH2PS(ND_width(n));
1533 ND_lw(n) = ND_rw(n) = w / 2;
1534 ND_ht(n) = INCH2PS(ND_height(n));
1535 }
1536}
1537
1538#ifndef HAVE_DRAND48
1539double drand48(void)
1540{
1541 double d;
1542 d = rand();
1543 d = d / RAND_MAX;
1544 return d;
1545}
1546#endif
1547typedef struct {
1549 char* name;
1551} clust_t;
1552
1554 .key = offsetof(clust_t, name),
1555 .size = -1,
1556 .link = offsetof(clust_t, link),
1557 .freef = free,
1558};
1559
1560static void fillMap (Agraph_t* g, Dt_t* map)
1561{
1562 for (int c = 1; c <= GD_n_cluster(g); c++) {
1563 Agraph_t *cl = GD_clust(g)[c];
1564 char *s = agnameof(cl);
1565 if (dtmatch(map, s)) {
1566 agwarningf("Two clusters named %s - the second will be ignored\n", s);
1567 } else {
1568 clust_t *ip = gv_alloc(sizeof(clust_t));
1569 ip->name = s;
1570 ip->clp = cl;
1571 dtinsert (map, ip);
1572 }
1573 fillMap (cl, map);
1574 }
1575}
1576
1582{
1583 Dt_t* map = dtopen (&strDisc, Dtoset);
1584
1585 fillMap (g, map);
1586
1587 return map;
1588}
1589
1590Agraph_t*
1591findCluster (Dt_t* map, char* name)
1592{
1593 clust_t* clp = dtmatch (map, name);
1594 if (clp)
1595 return clp->clp;
1596 return NULL;
1597}
1598
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:97
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:252
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:325
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Definition agxbuf.h:295
static char * agxbdisown(agxbuf *xb)
Definition agxbuf.h:345
Memory allocation wrappers that exit on failure.
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
#define MIN(a, b)
Definition arith.h:28
#define MAX(a, b)
Definition arith.h:33
boxf arrow_bb(pointf p, pointf u, double arrowsize)
Definition arrows.c:1107
#define dtmatch(d, o)
Definition cdt.h:185
#define dtinsert(d, o)
Definition cdt.h:186
CDT_API int dtclose(Dt_t *)
Definition dtclose.c:10
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
Definition dttree.c:306
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition dtopen.c:11
void processClusterEdges(graph_t *g)
Definition utils.c:919
void undoClusterEdges(graph_t *g)
Definition utils.c:1019
char * late_nnstring(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:91
char * scanEntity(char *t, agxbuf *xb)
Definition utils.c:1071
#define W_DEGREE
Definition utils.c:167
static edge_t * cloneEdge(edge_t *e, node_t *ct, node_t *ch)
Make a copy of e in e's graph but using ct and ch as nodes.
Definition utils.c:785
bool mapbool(const char *p)
Definition utils.c:341
node_t * UF_union(node_t *u, node_t *v)
Definition utils.c:115
node_t * UF_find(node_t *n)
Definition utils.c:105
static int Tflag
Definition utils.c:395
static node_t * mapN(node_t *n, graph_t *clg)
Definition utils.c:962
Dt_t * mkClustMap(Agraph_t *g)
Definition utils.c:1581
void UF_setname(node_t *u, node_t *v)
Definition utils.c:150
static void undoCompound(edge_t *e, graph_t *clg)
Definition utils.c:989
void setEdgeType(graph_t *g, int defaultValue)
Definition utils.c:1412
static port chkPort(port(*pf)(node_t *, char *, char *), node_t *n, char *s)
Definition utils.c:478
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:85
void gv_free_splines(edge_t *e)
Definition utils.c:1492
boxf polyBB(polygon_t *poly)
Definition utils.c:593
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:40
static Dtdisc_t mapDisc
Definition utils.c:775
void gv_cleanup_edge(edge_t *e)
Definition utils.c:1502
static void insertEdge(Dt_t *map, void *t, void *h, edge_t *e)
Definition utils.c:796
void common_init_node(node_t *n)
Definition utils.c:416
pointf Bezier(const pointf *V, double t, pointf *Left, pointf *Right)
Definition utils.c:175
static node_t * clustNode(node_t *n, graph_t *cg, agxbuf *xb, graph_t *clg, int *idx)
Definition utils.c:720
bool overlap_label(textlabel_t *lp, boxf b)
Definition utils.c:1312
int maptoken(char *p, char **name, int *val)
Definition utils.c:315
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:55
static void initFontLabelEdgeAttr(edge_t *e, struct fontinfo *fi, struct fontinfo *lfi)
Definition utils.c:453
bool overlap_node(node_t *n, boxf b)
Definition utils.c:1300
static int comp_entities(const void *e1, const void *e2)
Definition utils.c:1061
void common_init_edge(edge_t *e)
Definition utils.c:498
static bool noClip(edge_t *e, attrsym_t *sym)
Return true if head/tail end of edge should not be clipped to node.
Definition utils.c:464
const char * safefile(const char *filename)
Definition utils.c:266
pointf dotneato_closest(splines *spl, pointf pt)
Definition utils.c:346
static bool overlap_bezier(bezier bz, boxf b)
Definition utils.c:1325
pointf coord(node_t *n)
Definition utils.c:157
static char * findPath(const strviews_t dirs, const char *str)
Definition utils.c:253
static void * newItem(void *p, Dtdisc_t *disc)
Definition utils.c:762
attrsym_t * safe_dcl(graph_t *g, int obj_kind, char *name, char *defaultValue)
Definition utils.c:1054
void UF_singleton(node_t *u)
Definition utils.c:143
static void initFontEdgeAttr(edge_t *e, struct fontinfo *fi)
Definition utils.c:445
char * utf8ToLatin1(char *s)
Definition utils.c:1282
static int cmpItem(void *pp1, void *pp2)
Definition utils.c:748
char * latin1ToUTF8(char *s)
Converts string from Latin1 encoding to utf8. Also translates HTML entities.
Definition utils.c:1249
double get_inputscale(graph_t *g)
Definition utils.c:78
static int edgeType(const char *s, int defaultValue)
Convert string to edge type.
Definition utils.c:1363
static boxf addLabelBB(boxf bb, textlabel_t *lp, bool flipxy)
Definition utils.c:558
void updateBB(graph_t *g, textlabel_t *lp)
Definition utils.c:613
static bool overlap_arrow(pointf p, pointf u, double scale, boxf b)
Definition utils.c:1319
bool overlap_edge(edge_t *e, boxf b)
Definition utils.c:1347
static unsigned char cvtAndAppend(unsigned char c, agxbuf *xb)
Definition utils.c:1155
void compute_bb(graph_t *g)
Definition utils.c:622
static void fillMap(Agraph_t *g, Dt_t *map)
Definition utils.c:1560
static Dtdisc_t strDisc
Definition utils.c:1553
void gv_cleanup_node(node_t *n)
Definition utils.c:1514
bool mapBool(const char *p, bool defaultValue)
Definition utils.c:325
static int checkCompound(edge_t *e, graph_t *clg, agxbuf *xb, Dt_t *map, Dt_t *cmap, int *index_counter)
Definition utils.c:835
char * htmlEntityUTF8(char *s, graph_t *g)
Definition utils.c:1172
static int num_clust_edges(graph_t *g)
Definition utils.c:905
#define PATHSEP
Definition utils.c:238
void get_gradient_points(pointf *A, pointf *G, size_t n, double angle, int flags)
Definition utils.c:1435
void gv_nodesize(node_t *n, bool flip)
Definition utils.c:1525
int test_toggle(void)
Definition utils.c:405
static item * mapEdge(Dt_t *map, edge_t *e)
Check if we already have cluster edge corresponding to t->h, and return it.
Definition utils.c:806
static int htmlEntity(char **s)
Definition utils.c:1093
bool is_a_cluster(Agraph_t *g)
Definition utils.c:684
static graph_t * mapc(Dt_t *cmap, node_t *n)
Definition utils.c:812
bool late_bool(void *obj, attrsym_t *attr, bool defaultValue)
Definition utils.c:98
Agraph_t * findCluster(Dt_t *map, char *name)
Definition utils.c:1591
double drand48(void)
Definition utils.c:1539
Agsym_t * setAttr(graph_t *g, void *obj, char *name, char *value, Agsym_t *ap)
Definition utils.c:693
#define HEAD_LABEL
Definition const.h:168
#define NORMAL
Definition const.h:24
#define EDGETYPE_SPLINE
Definition const.h:239
#define EDGE_XLABEL
Definition const.h:172
#define DEFAULT_NODEHEIGHT
Definition const.h:72
#define TAIL_LABEL
Definition const.h:169
#define EDGE_LABEL
Definition const.h:167
#define EDGETYPE_CURVED
Definition const.h:236
#define DEFAULT_COLOR
Definition const.h:48
#define DEFAULT_NODEWIDTH
Definition const.h:74
#define EDGETYPE_ORTHO
Definition const.h:238
#define MIN_NODEWIDTH
Definition const.h:75
#define DEFAULT_FONTSIZE
Definition const.h:61
#define MIN_FONTSIZE
Definition const.h:63
#define EDGETYPE_PLINE
Definition const.h:237
#define EDGETYPE_LINE
Definition const.h:235
#define DEFAULT_FONTNAME
Definition const.h:67
#define EDGETYPE_NONE
Definition const.h:234
#define EDGETYPE_COMPOUND
Definition const.h:240
#define DEFAULT_NODESHAPE
Definition const.h:76
#define NODE_XLABEL
Definition const.h:171
#define MIN_NODEHEIGHT
Definition const.h:73
#define ENTITY_NAME_LENGTH_MAX
Definition entities.h:274
static const struct entities_s entities[]
#define NR_OF_ENTITIES
Definition entities.h:275
static Dtdisc_t disc
Definition exparse.y:209
#define A(n, t)
Definition expr.h:76
static int flags
Definition gc.c:63
#define G
Definition gdefs.h:7
#define V
Definition gdefs.h:5
int lineToBox(pointf p, pointf q, boxf b)
Definition geom.c:47
#define B2BF(b, bf)
Definition geom.h:69
#define OVERLAP(b0, b1)
Definition geom.h:48
struct pointf_s pointf
#define DIST2(p, q)
Definition geom.h:55
#define POINTS_PER_INCH
Definition geom.h:58
#define INCH2PS(a_inches)
Definition geom.h:63
geometric functions (e.g. on points and boxes)
static void expandbp(boxf *b, pointf p)
expand box b as needed to enclose point p
Definition geomprocs.h:45
static WUR pointf mid_pointf(pointf p, pointf q)
Definition geomprocs.h:104
static WUR pointf sub_pointf(pointf p, pointf q)
Definition geomprocs.h:96
static WUR pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
#define EXPANDBB(b0, b1)
Definition geomprocs.h:65
static WUR pointf scale(double c, pointf p)
Definition geomprocs.h:148
static WUR bool boxf_overlap(boxf b0, boxf b1)
Definition geomprocs.h:136
Agsym_t * N_fontsize
Definition globals.h:78
Agsym_t * E_labelfontsize
Definition globals.h:87
Agsym_t * E_fontcolor
Definition globals.h:84
Agsym_t * N_width
Definition globals.h:77
Agsym_t * E_headclip
Definition globals.h:88
Agsym_t * E_headlabel
Definition globals.h:86
Agsym_t * N_showboxes
Definition globals.h:79
Agsym_t * N_fontname
Definition globals.h:78
Agsym_t * E_fontname
Definition globals.h:84
Agsym_t * N_style
Definition globals.h:79
char * HTTPServerEnVar
Definition globals.h:55
char * Gvimagepath
Definition globals.h:50
Agsym_t * E_label
Definition globals.h:84
double PSinputscale
Definition globals.h:58
char * Gvfilepath
Definition globals.h:48
Agsym_t * N_shape
Definition globals.h:77
Agsym_t * N_xlabel
Definition globals.h:78
Agsym_t * E_label_float
Definition globals.h:86
Agsym_t * E_taillabel
Definition globals.h:87
Agsym_t * N_label
Definition globals.h:78
Agsym_t * E_fontsize
Definition globals.h:84
Agsym_t * E_labelfontname
Definition globals.h:87
Agsym_t * E_xlabel
Definition globals.h:84
Agsym_t * N_fontcolor
Definition globals.h:78
Agsym_t * E_labelfontcolor
Definition globals.h:87
Agsym_t * E_tailclip
Definition globals.h:88
Agsym_t * N_height
Definition globals.h:77
static double len(glCompPoint p)
Definition glutils.c:138
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:181
int agnnodes(Agraph_t *g)
Definition graph.c:163
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
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
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:521
char * agget(void *obj, char *name)
Definition attr.c:447
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
#define ED_compound(e)
Definition types.h:583
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:252
#define ED_xlabel(e)
Definition types.h:590
#define ED_label_ontop(e)
Definition types.h:591
#define ED_head_label(e)
Definition types.h:587
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:28
#define ED_spl(e)
Definition types.h:595
#define agtail(e)
Definition cgraph.h:982
#define ED_path(e)
Definition types.h:593
#define agfindedge(g, t, h)
Definition types.h:609
#define ED_tail_label(e)
Definition types.h:596
#define aghead(e)
Definition cgraph.h:983
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:43
#define ED_head_port(e)
Definition types.h:588
#define ED_label(e)
Definition types.h:589
#define ED_tail_port(e)
Definition types.h:597
void agwarningf(const char *fmt,...)
Definition agerror.c:175
#define agfindgraphattr(g, a)
Definition types.h:613
#define GD_has_labels(g)
Definition types.h:368
#define GD_clust(g)
Definition types.h:360
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:97
#define GD_flags(g)
Definition types.h:365
#define GD_bb(g)
Definition types.h:354
#define GD_n_cluster(g)
Definition types.h:389
#define GD_label(g)
Definition types.h:374
#define GD_flip(g)
Definition types.h:378
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition node.c:143
#define ND_ht(n)
Definition types.h:500
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:50
#define ND_bb(n)
Definition types.h:488
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
#define ND_showboxes(n)
Definition types.h:530
#define ND_has_port(n)
Definition types.h:495
#define ND_ysize(n)
Definition types.h:538
Agnode_t * agsubnode(Agraph_t *g, Agnode_t *n, int createflag)
Definition node.c:254
#define ND_label(n)
Definition types.h:502
#define ND_rw(n)
Definition types.h:525
#define ND_height(n)
Definition types.h:498
#define ND_width(n)
Definition types.h:536
#define ND_lw(n)
Definition types.h:506
#define ND_UF_parent(n)
Definition types.h:485
#define ND_xlabel(n)
Definition types.h:503
#define ND_UF_size(n)
Definition types.h:487
#define ND_pos(n)
Definition types.h:520
#define ND_ranktype(n)
Definition types.h:524
#define agfindnode(g, n)
Definition types.h:611
#define ND_coord(n)
Definition types.h:490
#define ND_shape(n)
Definition types.h:528
#define ND_xsize(n)
Definition types.h:537
Agraph_t * agraphof(void *obj)
Definition obj.c:187
#define AGDATA(obj)
returns Agrec_t
Definition cgraph.h:227
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:145
int agdelete(Agraph_t *g, void *obj)
deletes object. Equivalent to agclose, agdelnode, and agdeledge for obj being a graph,...
Definition obj.c:22
int agcontains(Agraph_t *, void *obj)
returns non-zero if obj is a member of (sub)graph
Definition obj.c:235
int agobjkind(void *obj)
Definition obj.c:254
Agraph_t * agroot(void *obj)
Definition obj.c:170
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
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
int aghtmlstr(const char *)
Definition refstr.c:440
Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
Definition subg.c:52
void gvToggle(int s)
Definition utils.c:396
replacements for ctype.h functions
static bool gv_isdigit(int c)
Definition gv_ctype.h:41
Arithmetic helper functions.
static bool is_exactly_zero(double v)
is a value precisely 0.0?
Definition gv_math.h:70
static int imin(int a, int b)
minimum of two integers
Definition gv_math.h:35
Graphviz context library.
textitem scanner parser str
Definition htmlparse.y:218
textlabel_t * make_label(void *obj, char *str, bool is_html, bool is_record, double fontsize, char *fontname, char *fontcolor)
Definition labels.c:110
void free_label(textlabel_t *p)
Definition labels.c:204
type-generic dynamically expanding list
#define LIST_APPEND(list,...)
Definition list.h:151
#define LIST(type)
Definition list.h:66
#define LIST_SIZE(list)
Definition list.h:92
#define LIST_FREE(list)
Definition list.h:413
#define LIST_IS_EMPTY(list)
Definition list.h:102
#define LIST_GET(list, index)
Definition list.h:197
#define IS_CLUST_NODE(n)
Definition macros.h:23
#define SET_CLUST_NODE(n)
Definition macros.h:22
#define CL_EDGE_TAG
Definition macros.h:21
#define HAS_CLUST_EDGE(g)
Definition macros.h:24
#define ND_id(n)
Definition mm2gv.c:41
NEATOPROCS_API void s1(graph_t *, node_t *)
Definition stuff.c:651
File system path helpers.
#define PATH_SEPARATOR
character for separating directory components in a file system path
Definition path.h:10
shape_kind shapeOf(node_t *)
Definition shapes.c:1908
shape_desc * bind_shape(char *name, node_t *)
Definition shapes.c:3970
static double cg(SparseMatrix A, const double *precond, size_t n, int dim, double *x0, double *rhs, double tol, double maxit)
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
Definition startswith.h:11
platform abstraction for case-insensitive string functions
static bool streq(const char *a, const char *b)
are a and b equal?
Definition streq.h:11
graph or subgraph
Definition cgraph.h:424
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:433
implementation of Agrec_t
Definition cgraph.h:172
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:641
char * defval
Definition cgraph.h:644
Definition types.h:89
size_t size
Definition types.h:91
pointf sp
Definition types.h:94
pointf * list
Definition types.h:90
uint32_t eflag
Definition types.h:93
pointf ep
Definition types.h:95
uint32_t sflag
Definition types.h:92
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
Agrec_t hdr
Definition utils.c:900
int n_cluster_edges
Definition utils.c:901
Agraph_t * clp
Definition utils.c:1550
char * name
Definition utils.c:1549
Dtlink_t link
Definition utils.c:1548
Definition cdt.h:98
int key
Definition cdt.h:85
char * name
Definition entities.h:17
int value
Definition entities.h:18
double fontsize
Definition utils.c:411
char * fontcolor
Definition utils.c:413
char * fontname
Definition utils.c:412
Definition utils.c:741
node_t * t
Definition utils.c:744
node_t * h
Definition utils.c:745
void * p[2]
Definition utils.c:743
Dtlink_t link
Definition utils.c:742
int y
Definition geom.h:27
int x
Definition geom.h:27
double x
Definition geom.h:29
double y
Definition geom.h:29
Definition types.h:48
char * name
Definition types.h:63
bezier * list
Definition types.h:99
boxf bb
Definition types.h:101
size_t size
Definition types.h:100
a non-owning string reference
Definition strview.h:20
const char * data
start of the pointed to string
Definition strview.h:21
size_t size
extent of the string in bytes
Definition strview.h:22
pointf pos
Definition types.h:114
pointf dimen
Definition types.h:110
state for an in-progress string tokenization
Definition tokenize.h:36
Non-owning string references.
static int strview_cmp(strview_t a, strview_t b)
compare two string references
Definition strview.h:71
static strview_t strview(const char *referent, char terminator)
create a string reference
Definition strview.h:26
static point center(point vertex[], size_t n)
String tokenization.
static strview_t tok_get(const tok_t *t)
get the current token
Definition tokenize.h:76
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
Definition tokenize.h:43
static bool tok_end(const tok_t *t)
is this tokenizer exhausted?
Definition tokenize.h:68
static void tok_next(tok_t *t)
advance to the next token in the string being scanned
Definition tokenize.h:85
#define TAIL_ID
Definition types.h:43
@ SH_RECORD
Definition types.h:187
#define HEAD_ID
Definition types.h:44
struct inside_t::@57 s
node_t * n
Definition types.h:160
Definition grammar.c:90
int(* pf)(void *, char *,...)
Definition xdot.c:392