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