Graphviz 14.1.3~dev.20260227.0545
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 v1.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/legal/epl-v10.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 bool onetime = true;
269 static char *pathlist = NULL;
270 static strviews_t dirs;
271
272 if (!filename || !filename[0])
273 return NULL;
274
275 if (HTTPServerEnVar) { /* If used as a server */
276 if (onetime) {
278 "file loading is disabled because the environment contains SERVER_NAME=\"%s\"\n",
280 onetime = false;
281 }
282 return NULL;
283 }
284
285 if (Gvfilepath != NULL) {
286 if (pathlist == NULL) {
287 LIST_FREE(&dirs);
288 pathlist = Gvfilepath;
289 dirs = mkDirlist(pathlist);
290 }
291
292 const char *str = filename;
293 for (const char *sep = "/\\:"; *sep != '\0'; ++sep) {
294 const char *p = strrchr(str, *sep);
295 if (p != NULL) {
296 str = ++p;
297 }
298 }
299
300 return findPath(dirs, str);
301 }
302
303 if (pathlist != Gvimagepath) {
304 LIST_FREE(&dirs);
305 pathlist = Gvimagepath;
306 if (pathlist && *pathlist)
307 dirs = mkDirlist(pathlist);
308 }
309
310 if (*filename == PATH_SEPARATOR || LIST_IS_EMPTY(&dirs))
311 return filename;
312
313 return findPath(dirs, filename);
314}
315
316int maptoken(char *p, char **name, int *val) {
317 char *q;
318
319 int i = 0;
320 for (; (q = name[i]) != 0; i++)
321 if (p && streq(p, q))
322 break;
323 return val[i];
324}
325
326bool mapBool(const char *p, bool defaultValue) {
327 if (!p || *p == '\0')
328 return defaultValue;
329 if (!strcasecmp(p, "false"))
330 return false;
331 if (!strcasecmp(p, "no"))
332 return false;
333 if (!strcasecmp(p, "true"))
334 return true;
335 if (!strcasecmp(p, "yes"))
336 return true;
337 if (gv_isdigit(*p))
338 return atoi(p) != 0;
339 return defaultValue;
340}
341
342bool mapbool(const char *p)
343{
344 return mapBool(p, false);
345}
346
348{
349 double d2, dlow2, dhigh2; /* squares of distances */
350 double low, high, t;
351 pointf c[4], pt2;
352 bezier bz;
353
354 size_t besti = SIZE_MAX;
355 size_t bestj = SIZE_MAX;
356 double bestdist2 = DBL_MAX;
357 for (size_t i = 0; i < spl->size; i++) {
358 bz = spl->list[i];
359 for (size_t j = 0; j < bz.size; j++) {
360 pointf b;
361
362 b.x = bz.list[j].x;
363 b.y = bz.list[j].y;
364 d2 = DIST2(b, pt);
365 if (bestj == SIZE_MAX || d2 < bestdist2) {
366 besti = i;
367 bestj = j;
368 bestdist2 = d2;
369 }
370 }
371 }
372
373 bz = spl->list[besti];
374 /* Pick best Bézier. If bestj is the last point in the B-spline, decrement.
375 * Then set j to be the first point in the corresponding Bézier by dividing
376 * then multiplying be 3. Thus, 0,1,2 => 0; 3,4,5 => 3, etc.
377 */
378 if (bestj == bz.size-1)
379 bestj--;
380 const size_t j = 3 * (bestj / 3);
381 for (size_t k = 0; k < 4; k++) {
382 c[k].x = bz.list[j + k].x;
383 c[k].y = bz.list[j + k].y;
384 }
385 low = 0.0;
386 high = 1.0;
387 dlow2 = DIST2(c[0], pt);
388 dhigh2 = DIST2(c[3], pt);
389 do {
390 t = (low + high) / 2.0;
391 pt2 = Bezier(c, t, NULL, NULL);
392 if (fabs(dlow2 - dhigh2) < 1.0)
393 break;
394 if (fabs(high - low) < .00001)
395 break;
396 if (dlow2 < dhigh2) {
397 high = t;
398 dhigh2 = DIST2(pt2, pt);
399 } else {
400 low = t;
401 dlow2 = DIST2(pt2, pt);
402 }
403 } while (1);
404 return pt2;
405}
406
407static int Tflag;
408void gvToggle(int s)
409{
410 (void)s;
411 Tflag = !Tflag;
412#if !defined(_WIN32)
413 signal(SIGUSR1, gvToggle);
414#endif
415}
416
417int test_toggle(void)
418{
419 return Tflag;
420}
421
422struct fontinfo {
423 double fontsize;
424 char *fontname;
426};
427
429{
430 struct fontinfo fi;
431 char *str;
432 ND_width(n) =
434 ND_height(n) =
436 ND_shape(n) =
438 str = agxget(n, N_label);
443 fi.fontsize, fi.fontname, fi.fontcolor);
444 if (N_xlabel && (str = agxget(n, N_xlabel)) && str[0]) {
445 ND_xlabel(n) = make_label(n, str, aghtmlstr(str), false,
446 fi.fontsize, fi.fontname, fi.fontcolor);
448 }
449
450 {
451 const int showboxes = imin(late_int(n, N_showboxes, 0, 0), UCHAR_MAX);
452 ND_showboxes(n) = (unsigned char)showboxes;
453 }
454 ND_shape(n)->fns->initfn(n);
455}
456
463
464static void
466 struct fontinfo *lfi)
467{
468 if (!fi->fontname) initFontEdgeAttr(e, fi);
472}
473
475static bool
477{
478 char *str;
479 bool rv = false;
480
481 if (sym) { /* mapbool isn't a good fit, because we want "" to mean true */
482 str = agxget(e,sym);
483 if (str && str[0]) rv = !mapbool(str);
484 else rv = false;
485 }
486 return rv;
487}
488
489static port
490chkPort (port (*pf)(node_t*, char*, char*), node_t* n, char* s)
491{
492 port pt;
493 char* cp=NULL;
494 if(s)
495 cp= strchr(s,':');
496 if (cp) {
497 *cp = '\0';
498 pt = pf(n, s, cp+1);
499 *cp = ':';
500 pt.name = cp+1;
501 }
502 else {
503 pt = pf(n, s, NULL);
504 pt.name = s;
505 }
506 return pt;
507}
508
509/* return true if edge has label */
511 char *str;
512 struct fontinfo fi;
513 struct fontinfo lfi;
514 graph_t *sg = agraphof(agtail(e));
515
516 fi.fontname = NULL;
517 lfi.fontname = NULL;
518 if (E_label && (str = agxget(e, E_label)) && str[0]) {
519 initFontEdgeAttr(e, &fi);
520 ED_label(e) = make_label(e, str, aghtmlstr(str), false,
521 fi.fontsize, fi.fontname, fi.fontcolor);
524 }
525
526 if (E_xlabel && (str = agxget(e, E_xlabel)) && str[0]) {
527 if (!fi.fontname)
528 initFontEdgeAttr(e, &fi);
529 ED_xlabel(e) = make_label(e, str, aghtmlstr(str), false,
530 fi.fontsize, fi.fontname, fi.fontcolor);
532 }
533
534 if (E_headlabel && (str = agxget(e, E_headlabel)) && str[0]) {
535 initFontLabelEdgeAttr(e, &fi, &lfi);
536 ED_head_label(e) = make_label(e, str, aghtmlstr(str), false,
537 lfi.fontsize, lfi.fontname, lfi.fontcolor);
539 }
540 if (E_taillabel && (str = agxget(e, E_taillabel)) && str[0]) {
541 if (!lfi.fontname)
542 initFontLabelEdgeAttr(e, &fi, &lfi);
543 ED_tail_label(e) = make_label(e, str, aghtmlstr(str), false,
544 lfi.fontsize, lfi.fontname, lfi.fontcolor);
546 }
547
548 /* We still accept ports beginning with colons but this is deprecated
549 * That is, we allow tailport = ":abc" as well as the preferred
550 * tailport = "abc".
551 */
552 str = agget(e, TAIL_ID);
553 /* libgraph always defines tailport/headport; libcgraph doesn't */
554 if (!str) str = "";
555 if (str && str[0])
556 ND_has_port(agtail(e)) = true;
557 ED_tail_port(e) = chkPort (ND_shape(agtail(e))->fns->portfn, agtail(e), str);
558 if (noClip(e, E_tailclip))
559 ED_tail_port(e).clip = false;
560 str = agget(e, HEAD_ID);
561 /* libgraph always defines tailport/headport; libcgraph doesn't */
562 if (!str) str = "";
563 if (str && str[0])
564 ND_has_port(aghead(e)) = true;
565 ED_head_port(e) = chkPort(ND_shape(aghead(e))->fns->portfn, aghead(e), str);
566 if (noClip(e, E_headclip))
567 ED_head_port(e).clip = false;
568}
569
570static boxf addLabelBB(boxf bb, textlabel_t * lp, bool flipxy)
571{
572 double width, height;
573 pointf p = lp->pos;
574 double min, max;
575
576 if (flipxy) {
577 height = lp->dimen.x;
578 width = lp->dimen.y;
579 }
580 else {
581 width = lp->dimen.x;
582 height = lp->dimen.y;
583 }
584 min = p.x - width / 2.;
585 max = p.x + width / 2.;
586 if (min < bb.LL.x)
587 bb.LL.x = min;
588 if (max > bb.UR.x)
589 bb.UR.x = max;
590
591 min = p.y - height / 2.;
592 max = p.y + height / 2.;
593 if (min < bb.LL.y)
594 bb.LL.y = min;
595 if (max > bb.UR.y)
596 bb.UR.y = max;
597
598 return bb;
599}
600
604boxf
606{
607 const size_t sides = poly->sides;
608 const size_t peris = MAX(poly->peripheries, (size_t)1);
609 pointf* verts = poly->vertices + (peris-1)*sides;
610 boxf bb;
611
612 bb.LL = bb.UR = verts[0];
613 for (size_t i = 1; i < sides; i++) {
614 bb.LL.x = MIN(bb.LL.x,verts[i].x);
615 bb.LL.y = MIN(bb.LL.y,verts[i].y);
616 bb.UR.x = MAX(bb.UR.x,verts[i].x);
617 bb.UR.y = MAX(bb.UR.y,verts[i].y);
618 }
619 return bb;
620}
621
626{
627 GD_bb(g) = addLabelBB(GD_bb(g), lp, GD_flip(g));
628}
629
635{
636 node_t *n;
637 edge_t *e;
638 boxf b, bb;
639 boxf BF;
640 pointf ptf, s2;
641
642 if (agnnodes(g) == 0 && GD_n_cluster(g) == 0) {
643 bb.LL = (pointf){0};
644 bb.UR = (pointf){0};
645 return;
646 }
647
648 bb.LL = (pointf){INT_MAX, INT_MAX};
649 bb.UR = (pointf){-INT_MAX, -INT_MAX};
650 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
651 ptf = coord(n);
652 s2.x = ND_xsize(n) / 2.0;
653 s2.y = ND_ysize(n) / 2.0;
654 b.LL = sub_pointf(ptf, s2);
655 b.UR = add_pointf(ptf, s2);
656
657 EXPANDBB(&bb, b);
658 if (ND_xlabel(n) && ND_xlabel(n)->set) {
659 bb = addLabelBB(bb, ND_xlabel(n), GD_flip(g));
660 }
661 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
662 if (ED_spl(e) == 0)
663 continue;
664 for (size_t i = 0; i < ED_spl(e)->size; i++) {
665 for (size_t j = 0; j < (((Agedgeinfo_t*)AGDATA(e))->spl)->list[i].size; j++) {
666 ptf = ED_spl(e)->list[i].list[j];
667 expandbp(&bb, ptf);
668 }
669 }
670 if (ED_label(e) && ED_label(e)->set) {
671 bb = addLabelBB(bb, ED_label(e), GD_flip(g));
672 }
673 if (ED_head_label(e) && ED_head_label(e)->set) {
674 bb = addLabelBB(bb, ED_head_label(e), GD_flip(g));
675 }
676 if (ED_tail_label(e) && ED_tail_label(e)->set) {
677 bb = addLabelBB(bb, ED_tail_label(e), GD_flip(g));
678 }
679 if (ED_xlabel(e) && ED_xlabel(e)->set) {
680 bb = addLabelBB(bb, ED_xlabel(e), GD_flip(g));
681 }
682 }
683 }
684
685 for (int i = 1; i <= GD_n_cluster(g); i++) {
686 B2BF(GD_bb(GD_clust(g)[i]), BF);
687 EXPANDBB(&bb, BF);
688 }
689 if (GD_label(g) && GD_label(g)->set) {
690 bb = addLabelBB(bb, GD_label(g), GD_flip(g));
691 }
692
693 GD_bb(g) = bb;
694}
695
697{
698 return g == g->root || !strncasecmp(agnameof(g), "cluster", 7) ||
699 mapbool(agget(g, "cluster"));
700}
701
705Agsym_t *setAttr(graph_t * g, void *obj, char *name, char *value,
706 Agsym_t * ap)
707{
708 if (ap == NULL) {
709 switch (agobjkind(obj)) {
710 case AGRAPH:
711 ap = agattr_text(g, AGRAPH,name, "");
712 break;
713 case AGNODE:
714 ap = agattr_text(g,AGNODE, name, "");
715 break;
716 case AGEDGE:
717 ap = agattr_text(g,AGEDGE, name, "");
718 break;
719 }
720 }
721 agxset(obj, ap, value);
722 return ap;
723}
724
730static node_t *clustNode(node_t * n, graph_t * cg, agxbuf * xb,
731 graph_t * clg)
732{
733 node_t *cn;
734 static int idx = 0;
735
736 agxbprint(xb, "__%d:%s", idx++, agnameof(cg));
737
738 cn = agnode(agroot(cg), agxbuse(xb), 1);
739 agbindrec(cn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
740
741 SET_CLUST_NODE(cn);
742 agsubnode(cg,cn,1);
743 agsubnode(clg,n,1);
744
745 /* set attributes */
746 N_label = setAttr(agraphof(cn), cn, "label", "", N_label);
747 N_style = setAttr(agraphof(cn), cn, "style", "invis", N_style);
748 N_shape = setAttr(agraphof(cn), cn, "shape", "box", N_shape);
749
750 return cn;
751}
752
753typedef struct {
754 Dtlink_t link; /* cdt data */
755 void *p[2]; /* key */
758} item;
759
760static int cmpItem(void *pp1, void *pp2) {
761 const void **p1 = pp1;
762 const void **p2 = pp2;
763 if ((uintptr_t)p1[0] < (uintptr_t)p2[0])
764 return -1;
765 if ((uintptr_t)p1[0] > (uintptr_t)p2[0])
766 return 1;
767 if ((uintptr_t)p1[1] < (uintptr_t)p2[1])
768 return -1;
769 if ((uintptr_t)p1[1] > (uintptr_t)p2[1])
770 return 1;
771 return 0;
772}
773
774static void *newItem(void *p, Dtdisc_t *disc) {
775 item *objp = p;
776 item *newp = gv_alloc(sizeof(item));
777
778 (void)disc;
779 newp->p[0] = objp->p[0];
780 newp->p[1] = objp->p[1];
781 newp->t = objp->t;
782 newp->h = objp->h;
783
784 return newp;
785}
786
788 .key = offsetof(item, p),
789 .size = sizeof(2 * sizeof(void *)),
790 .link = offsetof(item, link),
791 .makef = newItem,
792 .freef = free,
793 .comparf = cmpItem,
794};
795
797static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch)
798{
799 graph_t *g = agraphof(ct);
800 edge_t *ce = agedge(g, ct, ch,NULL,1);
801 agbindrec(ce, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true);
802 agcopyattr(e, ce);
803 ED_compound(ce) = true;
804
805 return ce;
806}
807
808static void insertEdge(Dt_t * map, void *t, void *h, edge_t * e)
809{
810 item dummy1 = {.p = {t, h}, .t = agtail(e), .h = aghead(e)};
811 dtinsert(map, &dummy1);
812
813 item dummy2 = {.p = {h, t}, .t = aghead(e), .h = agtail(e)};
814 dtinsert(map, &dummy2);
815}
816
818static item *mapEdge(Dt_t * map, edge_t * e)
819{
820 void *key[] = {agtail(e), aghead(e)};
821 return dtmatch(map, &key);
822}
823
824static graph_t *mapc(Dt_t *cmap, node_t *n) {
825 if (startswith(agnameof(n), "cluster")) {
826 return findCluster(cmap, agnameof(n));
827 }
828 return NULL;
829}
830
846static int
847checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map, Dt_t* cmap)
848{
849 node_t *cn;
850 node_t *cn1;
851 node_t *t = agtail(e);
852 node_t *h = aghead(e);
853 edge_t *ce;
854 item *ip;
855
856 if (IS_CLUST_NODE(h)) return 0;
857 graph_t *const tg = mapc(cmap, t);
858 graph_t *const hg = mapc(cmap, h);
859 if (!tg && !hg)
860 return 0;
861 if (tg == hg) {
862 agwarningf("cluster cycle %s -- %s not supported\n", agnameof(t),
863 agnameof(t));
864 return 0;
865 }
866 ip = mapEdge(map, e);
867 if (ip) {
868 cloneEdge(e, ip->t, ip->h);
869 return 1;
870 }
871
872 if (hg) {
873 if (tg) {
874 if (agcontains(hg, tg)) {
875 agwarningf("tail cluster %s inside head cluster %s\n",
876 agnameof(tg), agnameof(hg));
877 return 0;
878 }
879 if (agcontains(tg, hg)) {
880 agwarningf("head cluster %s inside tail cluster %s\n",
881 agnameof(hg),agnameof(tg));
882 return 0;
883 }
884 cn = clustNode(t, tg, xb, clg);
885 cn1 = clustNode(h, hg, xb, clg);
886 ce = cloneEdge(e, cn, cn1);
887 insertEdge(map, t, h, ce);
888 } else {
889 if (agcontains(hg, t)) {
890 agwarningf("tail node %s inside head cluster %s\n",
891 agnameof(t), agnameof(hg));
892 return 0;
893 }
894 cn = clustNode(h, hg, xb, clg);
895 ce = cloneEdge(e, t, cn);
896 insertEdge(map, t, h, ce);
897 }
898 } else {
899 if (agcontains(tg, h)) {
900 agwarningf("head node %s inside tail cluster %s\n", agnameof(h),
901 agnameof(tg));
902 return 0;
903 }
904 cn = clustNode(t, tg, xb, clg);
905 ce = cloneEdge(e, cn, h);
906 insertEdge(map, t, h, ce);
907 }
908 return 1;
909}
910
911typedef struct {
914} cl_edge_t;
915
916static int
918{
919 cl_edge_t* cl_info = (cl_edge_t*)HAS_CLUST_EDGE(g);
920 if (cl_info)
921 return cl_info->n_cluster_edges;
922 return 0;
923}
924
932{
933 int num_cl_edges = 0;
934 node_t *n;
935 node_t *nxt;
936 edge_t *e;
937 graph_t *clg;
938 agxbuf xb = {0};
939 Dt_t *map;
940 Dt_t *cmap = mkClustMap (g);
941
942 map = dtopen(&mapDisc, Dtoset);
943 clg = agsubg(g, "__clusternodes",1);
944 agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
945 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
946 if (IS_CLUST_NODE(n)) continue;
947 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
948 num_cl_edges += checkCompound(e, clg, &xb, map, cmap);
949 }
950 }
951 agxbfree(&xb);
952 dtclose(map);
953 for (n = agfstnode(clg); n; n = nxt) {
954 nxt = agnxtnode(clg, n);
955 agdelete(g, n);
956 }
957 agclose(clg);
958 if (num_cl_edges) {
959 cl_edge_t* cl_info;
960 cl_info = agbindrec(g, CL_EDGE_TAG, sizeof(cl_edge_t), false);
961 cl_info->n_cluster_edges = num_cl_edges;
962 }
963 dtclose(cmap);
964}
965
973static node_t *mapN(node_t * n, graph_t * clg)
974{
975 node_t *nn;
976 char *name;
977 graph_t *g = agraphof(n);
978 Agsym_t *sym;
979
980 if (!IS_CLUST_NODE(n))
981 return n;
982 agsubnode(clg, n, 1);
983 name = strchr(agnameof(n), ':');
984 assert(name);
985 name++;
986 if ((nn = agfindnode(g, name)))
987 return nn;
988 nn = agnode(g, name, 1);
989 agbindrec(nn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
990 SET_CLUST_NODE(nn);
991
992 /* Set all attributes to default */
993 for (sym = agnxtattr(g, AGNODE, NULL); sym; (sym = agnxtattr(g, AGNODE, sym))) {
994 if (agxget(nn, sym) != sym->defval)
995 agxset(nn, sym, sym->defval);
996 }
997 return nn;
998}
999
1000static void undoCompound(edge_t * e, graph_t * clg)
1001{
1002 node_t *t = agtail(e);
1003 node_t *h = aghead(e);
1004 node_t *ntail;
1005 node_t *nhead;
1006 edge_t* ce;
1007
1008 ntail = mapN(t, clg);
1009 nhead = mapN(h, clg);
1010 ce = cloneEdge(e, ntail, nhead);
1011
1012 /* transfer drawing information */
1013 ED_spl(ce) = ED_spl(e);
1014 ED_spl(e) = NULL;
1015 ED_label(ce) = ED_label(e);
1016 ED_label(e) = NULL;
1017 ED_xlabel(ce) = ED_xlabel(e);
1018 ED_xlabel(e) = NULL;
1020 ED_head_label(e) = NULL;
1022 ED_tail_label(e) = NULL;
1023 gv_cleanup_edge(e);
1024}
1025
1031{
1032 node_t *n;
1033 node_t *nextn;
1034 edge_t *e;
1035 graph_t *clg;
1036 int ecnt = num_clust_edges(g);
1037 int i = 0;
1038
1039 if (!ecnt) return;
1040 clg = agsubg(g, "__clusternodes",1);
1041 agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
1042 edge_t **edgelist = gv_calloc(ecnt, sizeof(edge_t*));
1043 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
1044 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
1045 if (ED_compound(e))
1046 edgelist[i++] = e;
1047 }
1048 }
1049 assert(i == ecnt);
1050 for (i = 0; i < ecnt; i++)
1051 undoCompound(edgelist[i], clg);
1052 free (edgelist);
1053 for (n = agfstnode(clg); n; n = nextn) {
1054 nextn = agnxtnode(clg, n);
1055 gv_cleanup_node(n);
1056 agdelete(g, n);
1057 }
1058 agclose(clg);
1059}
1060
1065attrsym_t *safe_dcl(graph_t *g, int obj_kind, char *name, char *defaultValue) {
1066 attrsym_t *a = agattr_text(g,obj_kind,name, NULL);
1067 if (!a) /* attribute does not exist */
1068 a = agattr_text(g, obj_kind, name, defaultValue);
1069 return a;
1070}
1071
1072static int comp_entities(const void *e1, const void *e2) {
1073 const strview_t *key = e1;
1074 const struct entities_s *candidate = e2;
1075 return strview_cmp(*key, strview(candidate->name, '\0'));
1076}
1077
1082char* scanEntity (char* t, agxbuf* xb)
1083{
1084 const strview_t key = strview(t, ';');
1085 struct entities_s *res;
1086
1087 agxbputc(xb, '&');
1088 if (key.data[key.size] == '\0') return t;
1089 if (key.size > ENTITY_NAME_LENGTH_MAX || key.size < 2) return t;
1090 res = bsearch(&key, entities, NR_OF_ENTITIES,
1091 sizeof(entities[0]), comp_entities);
1092 if (!res) return t;
1093 agxbprint(xb, "#%d;", res->value);
1094 return t + key.size + 1;
1095}
1096
1103static int
1105{
1106 struct entities_s *res;
1107 unsigned char* str = *(unsigned char**)s;
1108 unsigned int byte;
1109 int i, n = 0;
1110
1111 byte = *str;
1112 if (byte == '#') {
1113 byte = *(str + 1);
1114 if (byte == 'x' || byte == 'X') {
1115 for (i = 2; i < 8; i++) {
1116 byte = *(str + i);
1117 if (byte >= 'A' && byte <= 'F')
1118 byte = byte - 'A' + 10;
1119 else if (byte >= 'a' && byte <= 'f')
1120 byte = byte - 'a' + 10;
1121 else if (byte >= '0' && byte <= '9')
1122 byte = byte - '0';
1123 else
1124 break;
1125 n = n * 16 + (int)byte;
1126 }
1127 }
1128 else {
1129 for (i = 1; i < 8; i++) {
1130 byte = *(str + i);
1131 if (byte >= '0' && byte <= '9')
1132 n = n * 10 + ((int)byte - '0');
1133 else
1134 break;
1135 }
1136 }
1137 if (byte == ';') {
1138 str += i+1;
1139 }
1140 else {
1141 n = 0;
1142 }
1143 }
1144 else {
1145 strview_t key = {.data = (char *)str};
1146 for (i = 0; i < ENTITY_NAME_LENGTH_MAX; i++) {
1147 byte = *(str + i);
1148 if (byte == '\0') break;
1149 if (byte == ';') {
1150 res = bsearch(&key, entities, NR_OF_ENTITIES,
1151 sizeof(entities[0]), comp_entities);
1152 if (res) {
1153 n = res->value;
1154 str += i+1;
1155 }
1156 break;
1157 }
1158 ++key.size;
1159 }
1160 }
1161 *s = (char*)str;
1162 return n;
1163}
1164
1165static unsigned char
1166cvtAndAppend (unsigned char c, agxbuf* xb)
1167{
1168 char buf[] = {c, '\0'};
1169 char *s = latin1ToUTF8(buf);
1170 char *p = s;
1171 size_t len = strlen(s);
1172 while (len-- > 1)
1173 agxbputc(xb, *p++);
1174 c = *p;
1175 free (s);
1176 return c;
1177}
1178
1183char* htmlEntityUTF8 (char* s, graph_t* g)
1184{
1185 static graph_t* lastg;
1186 static atomic_flag warned;
1187 unsigned char c;
1188 unsigned int v;
1189
1190 int uc;
1191 int ui;
1192
1193 if (lastg != g) {
1194 lastg = g;
1195 atomic_flag_clear(&warned);
1196 }
1197
1198 agxbuf xb = {0};
1199
1200 while ((c = *(unsigned char*)s++)) {
1201 if (c < 0xC0)
1202 /*
1203 * Handles properly formed UTF-8 characters between
1204 * 0x01 and 0x7F. Also treats \0 and naked trail
1205 * bytes 0x80 to 0xBF as valid characters representing
1206 * themselves.
1207 */
1208 uc = 0;
1209 else if (c < 0xE0)
1210 uc = 1;
1211 else if (c < 0xF0)
1212 uc = 2;
1213 else if (c < 0xF8)
1214 uc = 3;
1215 else {
1216 uc = -1;
1217 if (!atomic_flag_test_and_set(&warned)) {
1218 agwarningf("UTF8 codes > 4 bytes are not currently supported (graph %s) - treated as Latin-1. Perhaps \"-Gcharset=latin1\" is needed?\n", agnameof(g));
1219 }
1220 c = cvtAndAppend (c, &xb);
1221 }
1222
1223 if (uc == 0 && c == '&') {
1224 /* replace html entity sequences like: &amp;
1225 * and: &#123; with their UTF8 equivalents */
1226 v = htmlEntity (&s);
1227 if (v) {
1228 if (v < 0x7F) /* entity needs 1 byte in UTF8 */
1229 c = v;
1230 else if (v < 0x07FF) { /* entity needs 2 bytes in UTF8 */
1231 agxbputc(&xb, (char)((v >> 6) | 0xC0));
1232 c = (v & 0x3F) | 0x80;
1233 }
1234 else { /* entity needs 3 bytes in UTF8 */
1235 agxbputc(&xb, (char)((v >> 12) | 0xE0));
1236 agxbputc(&xb, (char)(((v >> 6) & 0x3F) | 0x80));
1237 c = (v & 0x3F) | 0x80;
1238 }
1239 }
1240 }
1241 else /* copy n byte UTF8 characters */
1242 for (ui = 0; ui < uc; ++ui)
1243 if ((*s & 0xC0) == 0x80) {
1244 agxbputc(&xb, (char)c);
1245 c = *(unsigned char*)s++;
1246 }
1247 else {
1248 if (!atomic_flag_test_and_set(&warned)) {
1249 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));
1250 }
1251 c = cvtAndAppend (c, &xb);
1252 break;
1253 }
1254 agxbputc(&xb, (char)c);
1255 }
1256 return agxbdisown(&xb);
1257}
1258
1260char* latin1ToUTF8 (char* s)
1261{
1262 agxbuf xb = {0};
1263 unsigned int v;
1264
1265 /* Values are either a byte (<= 256) or come from htmlEntity, whose
1266 * values are all less than 0x07FF, so we need at most 3 bytes.
1267 */
1268 while ((v = *(unsigned char*)s++)) {
1269 if (v == '&') {
1270 v = htmlEntity (&s);
1271 if (!v) v = '&';
1272 }
1273 if (v < 0x7F)
1274 agxbputc(&xb, (char)v);
1275 else if (v < 0x07FF) {
1276 agxbputc(&xb, (char)((v >> 6) | 0xC0));
1277 agxbputc(&xb, (char)((v & 0x3F) | 0x80));
1278 }
1279 else {
1280 agxbputc(&xb, (char)((v >> 12) | 0xE0));
1281 agxbputc(&xb, (char)(((v >> 6) & 0x3F) | 0x80));
1282 agxbputc(&xb, (char)((v & 0x3F) | 0x80));
1283 }
1284 }
1285 return agxbdisown(&xb);
1286}
1287
1292char*
1294{
1295 agxbuf xb = {0};
1296 unsigned char c;
1297
1298 while ((c = *(unsigned char*)s++)) {
1299 if (c < 0x7F)
1300 agxbputc(&xb, (char)c);
1301 else {
1302 unsigned char outc = (c & 0x03) << 6;
1303 c = *(unsigned char *)s++;
1304 outc = outc | (c & 0x3F);
1305 agxbputc(&xb, (char)outc);
1306 }
1307 }
1308 return agxbdisown(&xb);
1309}
1310
1312 if (! OVERLAP(b, ND_bb(n)))
1313 return false;
1314
1315 /* FIXME - need to do something better about CLOSEENOUGH */
1316 pointf p = sub_pointf(ND_coord(n), mid_pointf(b.UR, b.LL));
1317
1318 inside_t ictxt = {.s.n = n};
1319
1320 return ND_shape(n)->fns->insidefn(&ictxt, p);
1321}
1322
1324{
1325 const pointf s = {.x = lp->dimen.x / 2.0, .y = lp->dimen.y / 2.0};
1326 boxf bb = {.LL = sub_pointf(lp->pos, s), .UR = add_pointf(lp->pos, s)};
1327 return OVERLAP(b, bb);
1328}
1329
1330static bool overlap_arrow(pointf p, pointf u, double scale, boxf b)
1331{
1332 // FIXME - check inside arrow shape
1333 return OVERLAP(b, arrow_bb(p, u, scale));
1334}
1335
1336static bool overlap_bezier(bezier bz, boxf b) {
1337 assert(bz.size);
1338 pointf u = bz.list[0];
1339 for (size_t i = 1; i < bz.size; i++) {
1340 pointf p = bz.list[i];
1341 if (lineToBox(p, u, b) != -1)
1342 return true;
1343 u = p;
1344 }
1345
1346 /* check arrows */
1347 if (bz.sflag) {
1348 if (overlap_arrow(bz.sp, bz.list[0], 1, b))
1349 return true;
1350 }
1351 if (bz.eflag) {
1352 if (overlap_arrow(bz.ep, bz.list[bz.size - 1], 1, b))
1353 return true;
1354 }
1355 return false;
1356}
1357
1359{
1360 splines *spl = ED_spl(e);
1361 if (spl && boxf_overlap(spl->bb, b))
1362 for (size_t i = 0; i < spl->size; i++)
1363 if (overlap_bezier(spl->list[i], b))
1364 return true;
1365
1366 textlabel_t *lp = ED_label(e);
1367 if (lp && overlap_label(lp, b))
1368 return true;
1369
1370 return false;
1371}
1372
1374static int edgeType(const char *s, int defaultValue) {
1375 if (s == NULL || strcmp(s, "") == 0) {
1376 return defaultValue;
1377 }
1378
1379 if (*s == '0') { /* false */
1380 return EDGETYPE_LINE;
1381 } else if (*s >= '1' && *s <= '9') { /* true */
1382 return EDGETYPE_SPLINE;
1383 } else if (strcasecmp(s, "curved") == 0) {
1384 return EDGETYPE_CURVED;
1385 } else if (strcasecmp(s, "compound") == 0) {
1386 return EDGETYPE_COMPOUND;
1387 } else if (strcasecmp(s, "false") == 0) {
1388 return EDGETYPE_LINE;
1389 } else if (strcasecmp(s, "line") == 0) {
1390 return EDGETYPE_LINE;
1391 } else if (strcasecmp(s, "none") == 0) {
1392 return EDGETYPE_NONE;
1393 } else if (strcasecmp(s, "no") == 0) {
1394 return EDGETYPE_LINE;
1395 } else if (strcasecmp(s, "ortho") == 0) {
1396 return EDGETYPE_ORTHO;
1397 } else if (strcasecmp(s, "polyline") == 0) {
1398 return EDGETYPE_PLINE;
1399 } else if (strcasecmp(s, "spline") == 0) {
1400 return EDGETYPE_SPLINE;
1401 } else if (strcasecmp(s, "true") == 0) {
1402 return EDGETYPE_SPLINE;
1403 } else if (strcasecmp(s, "yes") == 0) {
1404 return EDGETYPE_SPLINE;
1405 }
1406
1407 agwarningf("Unknown \"splines\" value: \"%s\" - ignored\n", s);
1408 return defaultValue;
1409}
1410
1423void setEdgeType(graph_t *g, int defaultValue) {
1424 char* s = agget(g, "splines");
1425 int et;
1426
1427 if (!s) {
1428 et = defaultValue;
1429 }
1430 else if (*s == '\0') {
1431 et = EDGETYPE_NONE;
1432 } else {
1433 et = edgeType(s, defaultValue);
1434 }
1435 GD_flags(g) |= et;
1436}
1437
1446void get_gradient_points(pointf *A, pointf *G, size_t n, double angle, int flags) {
1447 pointf min,max,center;
1448 int isRadial = flags & 1;
1449 int isRHS = flags & 2;
1450
1451 if (n == 2) {
1452 double rx = A[1].x - A[0].x;
1453 double ry = A[1].y - A[0].y;
1454 min.x = A[0].x - rx;
1455 max.x = A[0].x + rx;
1456 min.y = A[0].y - ry;
1457 max.y = A[0].y + ry;
1458 }
1459 else {
1460 min.x = max.x = A[0].x;
1461 min.y = max.y = A[0].y;
1462 for (size_t i = 0; i < n; i++) {
1463 min.x = MIN(A[i].x, min.x);
1464 min.y = MIN(A[i].y, min.y);
1465 max.x = MAX(A[i].x, max.x);
1466 max.y = MAX(A[i].y, max.y);
1467 }
1468 }
1469 center.x = min.x + (max.x - min.x)/2;
1470 center.y = min.y + (max.y - min.y)/2;
1471 if (isRadial) {
1472 double inner_r, outer_r;
1473 outer_r = hypot(center.x - min.x, center.y - min.y);
1474 inner_r = outer_r /4.;
1475 if (isRHS) {
1476 G[0].y = center.y;
1477 }
1478 else {
1479 G[0].y = -center.y;
1480 }
1481 G[0].x = center.x;
1482 G[1].x = inner_r;
1483 G[1].y = outer_r;
1484 }
1485 else {
1486 double half_x = max.x - center.x;
1487 double half_y = max.y - center.y;
1488 double sina = sin(angle);
1489 double cosa = cos(angle);
1490 if (isRHS) {
1491 G[0].y = center.y - half_y * sina;
1492 G[1].y = center.y + half_y * sina;
1493 }
1494 else {
1495 G[0].y = -center.y + (max.y - center.y) * sin(angle);
1496 G[1].y = -center.y - (center.y - min.y) * sin(angle);
1497 }
1498 G[0].x = center.x - half_x * cosa;
1499 G[1].x = center.x + half_x * cosa;
1500 }
1501}
1502
1504 if (ED_spl(e)) {
1505 for (size_t i = 0; i < ED_spl(e)->size; i++)
1506 free(ED_spl(e)->list[i].list);
1507 free(ED_spl(e)->list);
1508 free(ED_spl(e));
1509 }
1510 ED_spl(e) = NULL;
1511}
1512
1514{
1515 free(ED_path(e).ps);
1516 gv_free_splines(e);
1517 free_label(ED_label(e));
1521 /*FIX HERE , shallow cleaning may not be enough here */
1522 agdelrec(e, "Agedgeinfo_t");
1523}
1524
1526{
1527 free(ND_pos(n));
1528 if (ND_shape(n))
1529 ND_shape(n)->fns->freefn(n);
1530 free_label(ND_label(n));
1532 /*FIX HERE , shallow cleaning may not be enough here */
1533 agdelrec(n, "Agnodeinfo_t");
1534}
1535
1536void gv_nodesize(node_t *n, bool flip) {
1537 if (flip) {
1538 double w = INCH2PS(ND_height(n));
1539 ND_lw(n) = ND_rw(n) = w / 2;
1540 ND_ht(n) = INCH2PS(ND_width(n));
1541 }
1542 else {
1543 double w = INCH2PS(ND_width(n));
1544 ND_lw(n) = ND_rw(n) = w / 2;
1545 ND_ht(n) = INCH2PS(ND_height(n));
1546 }
1547}
1548
1549#ifndef HAVE_DRAND48
1550double drand48(void)
1551{
1552 double d;
1553 d = rand();
1554 d = d / RAND_MAX;
1555 return d;
1556}
1557#endif
1558typedef struct {
1560 char* name;
1562} clust_t;
1563
1565 .key = offsetof(clust_t, name),
1566 .size = -1,
1567 .link = offsetof(clust_t, link),
1568 .freef = free,
1569};
1570
1571static void fillMap (Agraph_t* g, Dt_t* map)
1572{
1573 for (int c = 1; c <= GD_n_cluster(g); c++) {
1574 Agraph_t *cl = GD_clust(g)[c];
1575 char *s = agnameof(cl);
1576 if (dtmatch(map, s)) {
1577 agwarningf("Two clusters named %s - the second will be ignored\n", s);
1578 } else {
1579 clust_t *ip = gv_alloc(sizeof(clust_t));
1580 ip->name = s;
1581 ip->clp = cl;
1582 dtinsert (map, ip);
1583 }
1584 fillMap (cl, map);
1585 }
1586}
1587
1593{
1594 Dt_t* map = dtopen (&strDisc, Dtoset);
1595
1596 fillMap (g, map);
1597
1598 return map;
1599}
1600
1601Agraph_t*
1602findCluster (Dt_t* map, char* name)
1603{
1604 clust_t* clp = dtmatch (map, name);
1605 if (clp)
1606 return clp->clp;
1607 return NULL;
1608}
1609
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:931
void undoClusterEdges(graph_t *g)
Definition utils.c:1030
char * late_nnstring(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:91
char * scanEntity(char *t, agxbuf *xb)
Definition utils.c:1082
#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:797
bool mapbool(const char *p)
Definition utils.c:342
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:407
static node_t * mapN(node_t *n, graph_t *clg)
Definition utils.c:973
Dt_t * mkClustMap(Agraph_t *g)
Definition utils.c:1592
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:1000
void setEdgeType(graph_t *g, int defaultValue)
Definition utils.c:1423
static port chkPort(port(*pf)(node_t *, char *, char *), node_t *n, char *s)
Definition utils.c:490
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:85
void gv_free_splines(edge_t *e)
Definition utils.c:1503
boxf polyBB(polygon_t *poly)
Definition utils.c:605
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:40
static Dtdisc_t mapDisc
Definition utils.c:787
void gv_cleanup_edge(edge_t *e)
Definition utils.c:1513
static void insertEdge(Dt_t *map, void *t, void *h, edge_t *e)
Definition utils.c:808
void common_init_node(node_t *n)
Definition utils.c:428
pointf Bezier(const pointf *V, double t, pointf *Left, pointf *Right)
Definition utils.c:175
bool overlap_label(textlabel_t *lp, boxf b)
Definition utils.c:1323
int maptoken(char *p, char **name, int *val)
Definition utils.c:316
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:465
bool overlap_node(node_t *n, boxf b)
Definition utils.c:1311
static int comp_entities(const void *e1, const void *e2)
Definition utils.c:1072
void common_init_edge(edge_t *e)
Definition utils.c:510
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:476
const char * safefile(const char *filename)
Definition utils.c:266
pointf dotneato_closest(splines *spl, pointf pt)
Definition utils.c:347
static bool overlap_bezier(bezier bz, boxf b)
Definition utils.c:1336
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:774
attrsym_t * safe_dcl(graph_t *g, int obj_kind, char *name, char *defaultValue)
Definition utils.c:1065
void UF_singleton(node_t *u)
Definition utils.c:143
static void initFontEdgeAttr(edge_t *e, struct fontinfo *fi)
Definition utils.c:457
char * utf8ToLatin1(char *s)
Definition utils.c:1293
static int cmpItem(void *pp1, void *pp2)
Definition utils.c:760
char * latin1ToUTF8(char *s)
Converts string from Latin1 encoding to utf8. Also translates HTML entities.
Definition utils.c:1260
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:1374
static boxf addLabelBB(boxf bb, textlabel_t *lp, bool flipxy)
Definition utils.c:570
void updateBB(graph_t *g, textlabel_t *lp)
Definition utils.c:625
static bool overlap_arrow(pointf p, pointf u, double scale, boxf b)
Definition utils.c:1330
static int checkCompound(edge_t *e, graph_t *clg, agxbuf *xb, Dt_t *map, Dt_t *cmap)
Definition utils.c:847
bool overlap_edge(edge_t *e, boxf b)
Definition utils.c:1358
static unsigned char cvtAndAppend(unsigned char c, agxbuf *xb)
Definition utils.c:1166
void compute_bb(graph_t *g)
Definition utils.c:634
static void fillMap(Agraph_t *g, Dt_t *map)
Definition utils.c:1571
static Dtdisc_t strDisc
Definition utils.c:1564
static node_t * clustNode(node_t *n, graph_t *cg, agxbuf *xb, graph_t *clg)
Definition utils.c:730
void gv_cleanup_node(node_t *n)
Definition utils.c:1525
bool mapBool(const char *p, bool defaultValue)
Definition utils.c:326
char * htmlEntityUTF8(char *s, graph_t *g)
Definition utils.c:1183
static int num_clust_edges(graph_t *g)
Definition utils.c:917
#define PATHSEP
Definition utils.c:238
void get_gradient_points(pointf *A, pointf *G, size_t n, double angle, int flags)
Definition utils.c:1446
void gv_nodesize(node_t *n, bool flip)
Definition utils.c:1536
int test_toggle(void)
Definition utils.c:417
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:818
static int htmlEntity(char **s)
Definition utils.c:1104
bool is_a_cluster(Agraph_t *g)
Definition utils.c:696
static graph_t * mapc(Dt_t *cmap, node_t *n)
Definition utils.c:824
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:1602
double drand48(void)
Definition utils.c:1550
Agsym_t * setAttr(graph_t *g, void *obj, char *name, char *value, Agsym_t *ap)
Definition utils.c:705
#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:75
Agsym_t * E_labelfontsize
Definition globals.h:89
Agsym_t * E_fontcolor
Definition globals.h:83
Agsym_t * N_width
Definition globals.h:74
Agsym_t * E_headclip
Definition globals.h:91
Agsym_t * E_headlabel
Definition globals.h:88
Agsym_t * N_showboxes
Definition globals.h:76
Agsym_t * N_fontname
Definition globals.h:75
Agsym_t * E_fontname
Definition globals.h:83
Agsym_t * N_style
Definition globals.h:76
char * HTTPServerEnVar
Definition globals.h:53
char * Gvimagepath
Definition globals.h:49
Agsym_t * E_label
Definition globals.h:84
double PSinputscale
Definition globals.h:56
char * Gvfilepath
Definition globals.h:48
Agsym_t * N_shape
Definition globals.h:74
Agsym_t * N_xlabel
Definition globals.h:76
Agsym_t * E_label_float
Definition globals.h:86
Agsym_t * E_taillabel
Definition globals.h:88
Agsym_t * N_label
Definition globals.h:76
Agsym_t * E_fontsize
Definition globals.h:83
Agsym_t * E_labelfontname
Definition globals.h:89
Agsym_t * E_xlabel
Definition globals.h:84
Agsym_t * N_fontcolor
Definition globals.h:75
Agsym_t * E_labelfontcolor
Definition globals.h:89
Agsym_t * E_tailclip
Definition globals.h:91
Agsym_t * N_height
Definition globals.h:74
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:157
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:255
#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:977
#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:978
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:55
void gvToggle(int s)
Definition utils.c:408
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:67
static int imin(int a, int b)
minimum of two integers
Definition gv_math.h:32
Graphviz context library.
static bool onetime
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(type)
Definition list.h:55
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_APPEND(list, item)
Definition list.h:120
#define LIST_FREE(list)
Definition list.h:370
#define LIST_IS_EMPTY(list)
Definition list.h:90
#define LIST_GET(list, index)
Definition list.h:155
#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:3994
static double cg(SparseMatrix A, const double *precond, int 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:640
char * defval
Definition cgraph.h:643
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:912
int n_cluster_edges
Definition utils.c:913
Agraph_t * clp
Definition utils.c:1561
char * name
Definition utils.c:1560
Dtlink_t link
Definition utils.c:1559
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:423
char * fontcolor
Definition utils.c:425
char * fontname
Definition utils.c:424
Definition utils.c:753
node_t * t
Definition utils.c:756
node_t * h
Definition utils.c:757
void * p[2]
Definition utils.c:755
Dtlink_t link
Definition utils.c:754
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:398