Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
actions.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/*
12 * Code for main functions in gpr
13 */
14
15#include <ast/ast.h>
16#include <ast/error.h>
17#include <cgraph/agxbuf.h>
18#include <cgraph/alloc.h>
19#include <cgraph/gv_ctype.h>
20#include <cgraph/strcasecmp.h>
21#include <cgraph/unreachable.h>
22#include <cgraph/unused.h>
23#include <gvpr/actions.h>
24#include <gvpr/compile.h>
25#include <limits.h>
26#include <stdbool.h>
27#include <stddef.h>
28#include <stdint.h>
29#include <stdio.h>
30#include <string.h>
31#include <unistd.h>
32
33#define KINDS(p) \
34 ((AGTYPE(p) == AGRAPH) ? "graph" : (AGTYPE(p) == AGNODE) ? "node" : "edge")
35
36static int iofread(void *chan, char *buf, int bufsize) {
37 FILE *fp = chan;
38
39 return (int)read(fileno(fp), buf, bufsize);
40}
41
42static int ioputstr(void *chan, const char *str) { return fputs(str, chan); }
43
44static int ioflush(void *chan) { return fflush(chan); }
45
47
48/* sameG:
49 * Return common root if objects belong to same root graph.
50 * NULL otherwise
51 */
52Agraph_t *sameG(void *p1, void *p2, char *fn, char *msg) {
53 Agobj_t *obj1 = OBJ(p1);
54 Agobj_t *obj2 = OBJ(p2);
55 Agraph_t *root;
56
57 root = agroot(agraphof(obj1));
58 if (root != agroot(agraphof(obj2))) {
59 if (msg)
60 error(ERROR_WARNING, "%s in %s() belong to different graphs", msg, fn);
61 else
62 error(ERROR_WARNING, "%s and %s in %s() belong to different graphs",
63 KINDS(obj1), KINDS(obj2), fn);
64 return 0;
65 } else
66 return root;
67}
68
69/* indexOf:
70 * Return index of leftmost string s2 in string s1, or -1
71 */
72int indexOf(char *s1, char *s2) {
73 char *s = strstr(s1, s2);
74 return s == NULL ? -1 : (int)(s - s1);
75}
76
77/* rindexOf:
78 * Return index of rightmost string s2 in string s1, or -1
79 */
80long rindexOf(char *s1, char *s2) {
81 char c1 = *s2;
82 char *p;
83 size_t len1 = strlen(s1);
84 size_t len2 = strlen(s2);
85
86 if (c1 == '\0') {
87 assert(len1 <= LONG_MAX);
88 return (long)len1;
89 }
90 if (len2 > len1)
91 return -1;
92 p = s1 + (len1 - len2);
93 while (true) {
94 if (strncmp(p, s2, len2) == 0)
95 return p - s1;
96 if (p == s1)
97 break;
98 p--;
99 }
100 return -1;
101}
102
103/* match:
104 * Return index of pattern pat in string str, or SIZE_MAX
105 */
106size_t match(char *str, char *pat) {
107 size_t sub[2];
108
109 if (strgrpmatch(str, pat, sub, 1, 0)) {
110 return (sub[0]);
111 } else
112 return SIZE_MAX;
113}
114
115/* copyAttr:
116 * Copy attributes from src to tgt. Overrides currently
117 * defined values.
118 * FIX: we should probably use the default value of the source
119 * graph when initializing the attribute, rather than "".
120 * NOTE: We do not assume src and tgt have the same kind.
121 */
122int copyAttr(Agobj_t *src, Agobj_t *tgt) {
123 Agraph_t *srcg;
124 Agraph_t *tgtg;
125 Agsym_t *sym = 0;
126 Agsym_t *tsym = 0;
127 int skind = AGTYPE(src);
128 int tkind = AGTYPE(tgt);
129 char *val;
130
131 srcg = agraphof(src);
132 tgtg = agraphof(tgt);
133 while ((sym = agnxtattr(srcg, skind, sym))) {
134 tsym = agattrsym(tgt, sym->name);
135 if (!tsym)
136 tsym = agattr(tgtg, tkind, sym->name, sym->defval);
137 val = agxget(src, sym);
138 if (aghtmlstr(val)) {
139 val = agstrdup_html(tgtg, val);
140 agxset(tgt, tsym, val);
141 agstrfree(tgtg, val);
142 } else
143 agxset(tgt, tsym, val);
144 }
145 return 0;
146}
147
148/* copy:
149 * Create new object of type AGTYPE(obj) with all of its
150 * attributes.
151 * If obj is an edge, only create end nodes if necessary.
152 * If obj is a graph, if g is null, create a top-level
153 * graph. Otherwise, create a subgraph of g.
154 * Assume obj != NULL.
155 */
157 Agobj_t *nobj = 0;
158 Agedge_t *e;
159 Agnode_t *h;
160 Agnode_t *t;
161 int kind = AGTYPE(obj);
162 char *name;
163
164 if (kind != AGRAPH && !g) {
165 exerror("NULL graph with non-graph object in copy()");
166 return 0;
167 }
168
169 switch (kind) {
170 case AGNODE:
171 name = agnameof(obj);
172 nobj = (Agobj_t *)openNode(g, name);
173 break;
174 case AGRAPH:
175 name = agnameof(obj);
176 if (g)
177 nobj = (Agobj_t *)openSubg(g, name);
178 else
179 nobj = (Agobj_t *)openG(name, ((Agraph_t *)obj)->desc);
180 break;
181 case AGINEDGE:
182 case AGOUTEDGE:
183 e = (Agedge_t *)obj;
184 t = openNode(g, agnameof(agtail(e)));
185 h = openNode(g, agnameof(aghead(e)));
186 name = agnameof(AGMKOUT(e));
187 nobj = (Agobj_t *)openEdge(g, t, h, name);
188 break;
189 default:
190 UNREACHABLE();
191 }
192 if (nobj)
193 copyAttr(obj, nobj);
194
195 return nobj;
196}
197
203
204static Agedge_t *mapEdge(Dt_t *emap, Agedge_t *e) {
205 edgepair_t *ep = dtmatch(emap, &e);
206 if (ep)
207 return ep->val;
208 else
209 return NULL;
210}
211
212/* cloneSubg:
213 * Clone subgraph sg in tgt.
214 */
215static Agraph_t *cloneSubg(Agraph_t *tgt, Agraph_t *g, Dt_t *emap) {
216 Agraph_t *ng;
217 Agraph_t *sg;
218 Agnode_t *t;
219 Agnode_t *newt;
220 Agedge_t *e;
221 Agedge_t *newe;
222 char *name;
223
224 ng = (Agraph_t *)copy(tgt, OBJ(g));
225 if (!ng)
226 return 0;
227 for (t = agfstnode(g); t; t = agnxtnode(g, t)) {
228 newt = agnode(tgt, agnameof(t), 0);
229 if (!newt) {
230 exerror("node %s not found in cloned graph %s", agnameof(t),
231 agnameof(tgt));
232 return 0;
233 } else
234 agsubnode(ng, newt, 1);
235 }
236 for (t = agfstnode(g); t; t = agnxtnode(g, t)) {
237 for (e = agfstout(g, t); e; e = agnxtout(g, e)) {
238 newe = mapEdge(emap, e);
239 if (!newe) {
240 name = agnameof(AGMKOUT(e));
241 if (name)
242 exerror("edge (%s,%s)[%s] not found in cloned graph %s",
243 agnameof(agtail(e)), agnameof(aghead(e)), name,
244 agnameof(tgt));
245 else
246 exerror("edge (%s,%s) not found in cloned graph %s",
247 agnameof(agtail(e)), agnameof(aghead(e)), agnameof(tgt));
248 return 0;
249 } else
250 agsubedge(ng, newe, 1);
251 }
252 }
253 for (sg = agfstsubg(g); sg; sg = agnxtsubg(sg)) {
254 if (!cloneSubg(ng, sg, emap)) {
255 exerror("error cloning subgraph %s from graph %s", agnameof(sg),
256 agnameof(g));
257 return 0;
258 }
259 }
260 return ng;
261}
262
263static int cmppair(void *k1, void *k2) {
264 const Agedge_t **key1 = k1;
265 const Agedge_t **key2 = k2;
266 if (*key1 > *key2)
267 return 1;
268 else if (*key1 < *key2)
269 return -1;
270 else
271 return 0;
272}
273
275 .key = offsetof(edgepair_t, key),
276 .size = sizeof(Agedge_t *),
277 .link = offsetof(edgepair_t, link),
278 .comparf = cmppair,
279};
280
281/* cloneGraph:
282 * Clone node, edge and subgraph structure from src to tgt.
283 */
284static void cloneGraph(Agraph_t *tgt, Agraph_t *src) {
285 Agedge_t *e;
286 Agedge_t *ne;
287 Agnode_t *t;
288 Agraph_t *sg;
289 char *name;
290 Dt_t *emap = dtopen(&edgepair, Dtoset);
291 edgepair_t *data = malloc(sizeof(edgepair_t) * agnedges(src));
292 edgepair_t *ep = data;
293
294 for (t = agfstnode(src); t; t = agnxtnode(src, t)) {
295 if (!copy(tgt, OBJ(t))) {
296 exerror("error cloning node %s from graph %s", agnameof(t),
297 agnameof(src));
298 }
299 }
300 for (t = agfstnode(src); t; t = agnxtnode(src, t)) {
301 for (e = agfstout(src, t); e; e = agnxtout(src, e)) {
302 if (!(ne = (Agedge_t *)copy(tgt, OBJ(e)))) {
303 name = agnameof(AGMKOUT(e));
304 if (name)
305 exerror("error cloning edge (%s,%s)[%s] from graph %s",
306 agnameof(agtail(e)), agnameof(aghead(e)), name,
307 agnameof(src));
308 else
309 exerror("error cloning edge (%s,%s) from graph %s",
310 agnameof(agtail(e)), agnameof(aghead(e)), agnameof(src));
311 goto done;
312 }
313 ep->key = e;
314 ep->val = ne;
315 dtinsert(emap, ep++);
316 }
317 }
318 for (sg = agfstsubg(src); sg; sg = agnxtsubg(sg)) {
319 if (!cloneSubg(tgt, sg, emap)) {
320 exerror("error cloning subgraph %s from graph %s", agnameof(sg),
321 agnameof(src));
322 }
323 }
324
325done:
326 dtclose(emap);
327 free(data);
328}
329
330/* cloneG:
331 */
332Agraph_t *cloneG(Agraph_t *g, char *name) {
333 Agraph_t *ng;
334
335 if (!name || *name == '\0')
336 name = agnameof(g);
337 ng = openG(name, g->desc);
338 if (ng) {
339 copyAttr((Agobj_t *)g, (Agobj_t *)ng);
340 cloneGraph(ng, g);
341 }
342 return ng;
343}
344
345/* cloneO:
346 * Create new object of type AGTYPE(obj) with all of its
347 * attributes and substructure.
348 * If obj is an edge, end nodes are cloned if necessary.
349 * If obj is a graph, if g is null, create a clone top-level
350 * graph. Otherwise, create a clone subgraph of g.
351 * Assume obj != NULL.
352 */
354 Agobj_t *nobj = 0;
355 Agedge_t *e;
356 Agnode_t *h;
357 Agnode_t *t;
358 int kind = AGTYPE(obj);
359 char *name;
360
361 if (kind != AGRAPH && !g) {
362 exerror("NULL graph with non-graph object in clone()");
363 return 0;
364 }
365
366 switch (kind) {
367 case AGNODE: /* same as copy node */
368 name = agnameof(obj);
369 nobj = (Agobj_t *)openNode(g, name);
370 if (nobj)
371 copyAttr(obj, nobj);
372 break;
373 case AGRAPH:
374 name = agnameof(obj);
375 if (g)
376 nobj = (Agobj_t *)openSubg(g, name);
377 else
378 nobj = (Agobj_t *)openG(name, ((Agraph_t *)obj)->desc);
379 if (nobj) {
380 copyAttr(obj, nobj);
381 cloneGraph((Agraph_t *)nobj, (Agraph_t *)obj);
382 }
383 break;
384 case AGINEDGE:
385 case AGOUTEDGE:
386 e = (Agedge_t *)obj;
387 t = (Agnode_t *)cloneO(g, OBJ(agtail(e)));
388 h = (Agnode_t *)cloneO(g, OBJ(aghead(e)));
389 name = agnameof(AGMKOUT(e));
390 nobj = (Agobj_t *)openEdge(g, t, h, name);
391 if (nobj)
392 copyAttr(obj, nobj);
393 break;
394 default:
395 UNREACHABLE();
396 }
397
398 return nobj;
399}
400
401#define CCMARKED(n) (((nData(n))->iu.integer) & 2)
402#define CCMARK(n) (((nData(n))->iu.integer) |= 2)
403#define CCUNMARK(n) (((nData(n))->iu.integer) &= ~2)
404
405static void cc_dfs(Agraph_t *g, Agraph_t *comp, Agnode_t *n) {
406 Agedge_t *e;
407 Agnode_t *other;
408
409 CCMARK(n);
410 agidnode(comp, AGID(n), 1);
411 for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
412 if (agtail(e) == n)
413 other = aghead(e);
414 else
415 other = agtail(e);
416 if (!CCMARKED(other))
417 cc_dfs(g, comp, other);
418 }
419}
420
421/* compOf:
422 * Return connected component of node.
423 */
425 Agraph_t *cg;
426 Agnode_t *np;
427 static int id;
428 char name[64];
429
430 if (!(n = agidnode(g, AGID(n), 0)))
431 return 0; /* n not in g */
432 for (np = agfstnode(g); np; np = agnxtnode(g, np))
433 CCUNMARK(np);
434
435 snprintf(name, sizeof(name), "_cc_%d", id++);
436 cg = openSubg(g, name);
437 cc_dfs(g, cg, n);
438
439 return cg;
440}
441
442/* isEdge:
443 * Return edge, if any, between t and h with given key.
444 * Edge is in g.
445 */
447 Agraph_t *root;
448
449 root = sameG(t, h, "isEdge", "tail and head node");
450 if (!root)
451 return 0;
452 if (g) {
453 if (root != agroot(g))
454 return 0;
455 } else
456 g = root;
457
458 return agedge(g, t, h, key, 0);
459}
460
461/* addNode:
462 * Insert node n into subgraph g.
463 * Return image of n
464 */
465Agnode_t *addNode(Agraph_t *gp, Agnode_t *np, int doAdd) {
466 if (!sameG(gp, np, "addNode", 0))
467 return 0;
468 return agsubnode(gp, np, doAdd);
469}
470
471/* addEdge:
472 * Insert edge e into subgraph g.
473 * Return image of e
474 */
475Agedge_t *addEdge(Agraph_t *gp, Agedge_t *ep, int doAdd) {
476 if (!sameG(gp, ep, "addEdge", 0))
477 return 0;
478 return agsubedge(gp, ep, doAdd);
479}
480
481/* lockGraph:
482 * Set lock so that graph g will not be deleted.
483 * g must be a root graph.
484 * If v > 0, set lock
485 * If v = 0, unset lock and delete graph is necessary.
486 * If v < 0, no op
487 * Always return previous lock state.
488 * Return -1 on error.
489 */
490int lockGraph(Agraph_t *g, int v) {
491 gdata *data;
492 int oldv;
493
494 if (g != agroot(g)) {
495 error(ERROR_WARNING, "Graph argument to lock() is not a root graph");
496 return -1;
497 }
498 data = gData(g);
499 oldv = data->lock & 1;
500 if (v > 0)
501 data->lock |= 1;
502 else if (v == 0 && oldv) {
503 if (data->lock & 2)
504 agclose(g);
505 else
506 data->lock = 0;
507 }
508 return oldv;
509}
510
511/* deleteObj:
512 * Remove obj from g.
513 * obj may belong to a subgraph of g, so we first must map
514 * obj to its version in g.
515 * If g is null, remove object from root graph.
516 * If obj is a (sub)graph, close it. The g parameter is unused.
517 * Return 0 on success, non-zero on failure.
518 */
520 gdata *data;
521 if (AGTYPE(obj) == AGRAPH) {
522 g = (Agraph_t *)obj;
523 if (g != agroot(g))
524 return agclose(g);
525 data = gData(g);
526 if (data->lock & 1) {
527 error(ERROR_WARNING, "Cannot delete locked graph %s", agnameof(g));
528 data->lock |= 2;
529 return -1;
530 } else
531 return agclose(g);
532 }
533
534 /* node or edge */
535 if (!g)
536 g = agroot(agraphof(obj));
537 if (obj)
538 return agdelete(g, obj);
539 else
540 return -1;
541}
542
543/* sfioWrite:
544 * If the graph is passed in from a library, its output discipline
545 * might not use sfio. In this case, we push an sfio discipline on
546 * the graph, write it, and then pop it off.
547 */
548int sfioWrite(Agraph_t *g, FILE *fp) {
549 int rv;
550
551 Agiodisc_t *saveio = g->clos->disc.io;
552 g->clos->disc.io = &gprIoDisc;
553 rv = agwrite(g, fp);
554 g->clos->disc.io = saveio;
555 return rv;
556}
557
558/* writeFile:
559 * Write graph into file f.
560 * Return 0 on success
561 */
562int writeFile(Agraph_t *g, char *f) {
563 int rv;
564
565 if (!f) {
566 exerror("NULL string passed to writeG");
567 return 1;
568 }
569 FILE *fp = fopen(f, "w");
570 if (!fp) {
571 exwarn("Could not open %s for writing in writeG", f);
572 return 1;
573 }
574 rv = sfioWrite(g, fp);
575 fclose(fp);
576 return rv;
577}
578
579/* readFile:
580 * Read graph from file f.
581 * Return 0 on failure
582 */
584 Agraph_t *gp;
585
586 if (!f) {
587 exerror("NULL string passed to readG");
588 return 0;
589 }
590 FILE *fp = fopen(f, "r");
591 if (!fp) {
592 exwarn("Could not open %s for reading in readG", f);
593 return 0;
594 }
595 gp = readG(fp);
596 fclose(fp);
597
598 return gp;
599}
600
601int fwriteFile(Expr_t *ex, Agraph_t *g, long long fd) {
602 FILE *sp;
603
604 if (fd < 0 || fd >= (long long)elementsof(ex->file) || !(sp = ex->file[fd])) {
605 exerror("fwriteG: %lld: invalid descriptor", fd);
606 return 0;
607 }
608 return sfioWrite(g, sp);
609}
610
611Agraph_t *freadFile(Expr_t *ex, long long fd) {
612 FILE *sp;
613
614 if (fd < 0 || fd >= (long long)elementsof(ex->file) || !(sp = ex->file[fd])) {
615 exerror("freadG: %lld: invalid descriptor", fd);
616 return 0;
617 }
618 return readG(sp);
619}
620
621int openFile(Expr_t *ex, const char *fname, const char *mode) {
622 int idx;
623
624 /* find open index */
625 for (idx = 3; idx < elementsof(ex->file); idx++)
626 if (!ex->file[idx])
627 break;
628 if (idx == elementsof(ex->file)) {
629 exerror("openF: no available descriptors");
630 return -1;
631 }
632 ex->file[idx] = fopen(fname, mode);
633 if (ex->file[idx])
634 return idx;
635 else
636 return -1;
637}
638
639int closeFile(Expr_t *ex, long long fd) {
640 int rv;
641
642 if (0 <= fd && fd <= 2) {
643 exerror("closeF: cannot close standard stream %lld", fd);
644 return -1;
645 }
646 if (fd < 0 || fd >= (long long)elementsof(ex->file)) {
647 exerror("closeG: %lld: invalid descriptor", fd);
648 return -1;
649 }
650 if (!ex->file[fd]) {
651 exerror("closeF: stream %lld not open", fd);
652 return -1;
653 }
654 rv = fclose(ex->file[fd]);
655 if (!rv)
656 ex->file[fd] = 0;
657 return rv;
658}
659
660/*
661 * Read single line from stream.
662 * Return "" on EOF.
663 */
664char *readLine(Expr_t *ex, long long fd) {
665 FILE *sp;
666 int c;
667 char *line;
668
669 if (fd < 0 || fd >= (long long)elementsof(ex->file) || !(sp = ex->file[fd])) {
670 exerror("readL: %lld: invalid descriptor", fd);
671 return "";
672 }
673
674 agxbuf tmps = {0};
675 while ((c = getc(sp)) > 0 && c != '\n')
676 agxbputc(&tmps, (char)c);
677 if (c == '\n')
678 agxbputc(&tmps, (char)c);
679 line = exstring(ex, agxbuse(&tmps));
680 agxbfree(&tmps);
681 return line;
682}
683
684/* compare:
685 * Lexicographic ordering of objects.
686 */
688 char lkind, rkind;
689 if (l == NULL) {
690 if (r == NULL)
691 return 0;
692 else
693 return -1;
694 } else if (r == NULL) {
695 return 1;
696 }
697 if (AGID(l) < AGID(r))
698 return -1;
699 else if (AGID(l) > AGID(r))
700 return 1;
701 lkind = AGTYPE(l);
702 rkind = AGTYPE(r);
703 if (lkind == 3)
704 lkind = 2;
705 if (rkind == 3)
706 rkind = 2;
707 if (lkind == rkind)
708 return 0;
709 else if (lkind < rkind)
710 return -1;
711 else
712 return 1;
713}
714
715/* toLower:
716 * Convert characters to lowercase
717 */
718char *toLower(Expr_t *pgm, char *src) {
719
720 const size_t len = strlen(src);
721 char *dst = exstralloc(pgm, len + 1);
722 if (dst == NULL) {
723 return NULL;
724 }
725
726 for (size_t i = 0; i < len; ++i) {
727 dst[i] = gv_tolower(src[i]);
728 }
729
730 dst[len] = '\0';
731 return dst;
732}
733
734/* toUpper:
735 * Convert characters to uppercase
736 */
737char *toUpper(Expr_t *pgm, char *src) {
738
739 const size_t len = strlen(src);
740 char *dst = exstralloc(pgm, len + 1);
741 if (dst == NULL) {
742 return NULL;
743 }
744
745 for (size_t i = 0; i < len; ++i) {
746 dst[i] = gv_toupper(src[i]);
747 }
748
749 dst[len] = '\0';
750 return dst;
751}
752
753/* toHtml:
754 * Create a string marked as HTML
755 */
756char *toHtml(Agraph_t *g, char *arg) { return agstrdup_html(g, arg); }
757
758/* canon:
759 * Canonicalize a string for printing.
760 */
761char *canon(Expr_t *pgm, char *arg) {
762 char *p;
763
764 p = agcanonStr(arg);
765 if (p != arg)
766 p = exstring(pgm, p);
767
768 return p;
769}
770
771#undef S
772
773// force the upcoming ../common/colxlate.c functions to not be exported
774#ifdef COLORPROCS_API
775#undef COLORPROCS_API
776#endif
777#ifdef GVDLL
778#undef GVDLL
779#endif
780#ifdef GVC_EXPORTS
781#undef GVC_EXPORTS
782#endif
783#define COLORPROCS_API static UNUSED
784
785#include "../common/colxlate.c"
786
787/* colorx:
788 * RGB, RGBA, HSV, HSVA
789 */
790char *colorx(Expr_t *ex, char *incolor, char *fmt) {
791 gvcolor_t color = {{{0}}, 0};
793 int rc;
794 int alpha;
795
796 if (*fmt == '\0' || *incolor == '\0')
797 return "";
798 if (*fmt == 'R') {
799 type = RGBA_BYTE;
800 if (!strcmp(fmt, "RGBA"))
801 alpha = 1;
802 else
803 alpha = 0;
804 } else if (*fmt == 'H') {
806 if (!strcmp(fmt, "HSVA"))
807 alpha = 1;
808 else
809 alpha = 0;
810 } else
811 return "";
812
813 rc = colorxlate(incolor, &color, type);
814 if (rc != COLOR_OK)
815 return "";
816
817 agxbuf fp = {0};
818
819 switch (type) {
820 case HSVA_DOUBLE:
821 agxbprint(&fp, "%.03f %.03f %.03f", color.u.HSVA[0], color.u.HSVA[1],
822 color.u.HSVA[2]);
823 if (alpha)
824 agxbprint(&fp, " %.03f", color.u.HSVA[3]);
825 break;
826 case RGBA_BYTE:
827 agxbprint(&fp, "#%02x%02x%02x", color.u.rgba[0], color.u.rgba[1],
828 color.u.rgba[2]);
829 if (alpha)
830 agxbprint(&fp, "%02x", color.u.rgba[3]);
831 break;
832 default:
833 break;
834 }
835
836 char *result = exstring(ex, agxbuse(&fp));
837 agxbfree(&fp);
838 return result;
839}
840
841#ifndef _WIN32
842
843#include <sys/param.h>
844#include <sys/times.h>
845#include <sys/types.h>
846#include <unistd.h>
847
848#ifndef HZ
849#define HZ 60
850#endif
851typedef struct tms mytime_t;
852#define GET_TIME(S) times(&(S))
853#define DIFF_IN_SECS(S, T) \
854 ((S.tms_utime + S.tms_stime - T.tms_utime - T.tms_stime) / (double)HZ)
855
856#else
857
858#include <time.h>
859
860typedef clock_t mytime_t;
861#define GET_TIME(S) S = clock()
862#define DIFF_IN_SECS(S, T) ((S - T) / (double)CLOCKS_PER_SEC)
863
864#endif
865
866static mytime_t T;
867
868void gvstart_timer(void) { GET_TIME(T); }
869
870double gvelapsed_sec(void) {
871 mytime_t S;
872 double rv;
873
874 GET_TIME(S);
875 rv = DIFF_IN_SECS(S, T);
876 return rv;
877}
Agedge_t * isEdge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *key)
Definition actions.c:446
int indexOf(char *s1, char *s2)
Definition actions.c:72
int openFile(Expr_t *ex, const char *fname, const char *mode)
Definition actions.c:621
char * colorx(Expr_t *ex, char *incolor, char *fmt)
Definition actions.c:790
Agraph_t * sameG(void *p1, void *p2, char *fn, char *msg)
Definition actions.c:52
static Agedge_t * mapEdge(Dt_t *emap, Agedge_t *e)
Definition actions.c:204
Agraph_t * freadFile(Expr_t *ex, long long fd)
Definition actions.c:611
Agobj_t * cloneO(Agraph_t *g, Agobj_t *obj)
Definition actions.c:353
#define CCUNMARK(n)
Definition actions.c:403
size_t match(char *str, char *pat)
Definition actions.c:106
int deleteObj(Agraph_t *g, Agobj_t *obj)
Definition actions.c:519
int writeFile(Agraph_t *g, char *f)
Definition actions.c:562
int fwriteFile(Expr_t *ex, Agraph_t *g, long long fd)
Definition actions.c:601
long rindexOf(char *s1, char *s2)
Definition actions.c:80
int sfioWrite(Agraph_t *g, FILE *fp)
Definition actions.c:548
struct tms mytime_t
Definition actions.c:851
static void cloneGraph(Agraph_t *tgt, Agraph_t *src)
Definition actions.c:284
#define DIFF_IN_SECS(S, T)
Definition actions.c:853
void gvstart_timer(void)
Definition actions.c:868
#define CCMARKED(n)
Definition actions.c:401
static int iofread(void *chan, char *buf, int bufsize)
Definition actions.c:36
char * toLower(Expr_t *pgm, char *src)
Definition actions.c:718
Agraph_t * cloneG(Agraph_t *g, char *name)
Definition actions.c:332
int lockGraph(Agraph_t *g, int v)
Definition actions.c:490
char * canon(Expr_t *pgm, char *arg)
Definition actions.c:761
#define CCMARK(n)
Definition actions.c:402
int copyAttr(Agobj_t *src, Agobj_t *tgt)
Definition actions.c:122
static void cc_dfs(Agraph_t *g, Agraph_t *comp, Agnode_t *n)
Definition actions.c:405
char * toHtml(Agraph_t *g, char *arg)
Definition actions.c:756
Agnode_t * addNode(Agraph_t *gp, Agnode_t *np, int doAdd)
Definition actions.c:465
static Dtdisc_t edgepair
Definition actions.c:274
int compare(Agobj_t *l, Agobj_t *r)
Definition actions.c:687
Agobj_t * copy(Agraph_t *g, Agobj_t *obj)
Definition actions.c:156
static int cmppair(void *k1, void *k2)
Definition actions.c:263
double gvelapsed_sec(void)
Definition actions.c:870
Agraph_t * readFile(char *f)
Definition actions.c:583
static mytime_t T
Definition actions.c:866
Agraph_t * compOf(Agraph_t *g, Agnode_t *n)
Definition actions.c:424
static Agraph_t * cloneSubg(Agraph_t *tgt, Agraph_t *g, Dt_t *emap)
Definition actions.c:215
Agedge_t * addEdge(Agraph_t *gp, Agedge_t *ep, int doAdd)
Definition actions.c:475
static int ioflush(void *chan)
Definition actions.c:44
static Agiodisc_t gprIoDisc
Definition actions.c:46
char * toUpper(Expr_t *pgm, char *src)
Definition actions.c:737
#define GET_TIME(S)
Definition actions.c:852
static int ioputstr(void *chan, const char *str)
Definition actions.c:42
#define KINDS(p)
Definition actions.c:33
char * readLine(Expr_t *ex, long long fd)
Definition actions.c:664
int closeFile(Expr_t *ex, long long fd)
Definition actions.c:639
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:77
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:213
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Definition agxbuf.h:256
static char * agxbuse(agxbuf *xb)
Definition agxbuf.h:286
Memory allocation wrappers that exit on failure.
#define elementsof(x)
Definition ast.h:33
int strgrpmatch(char *, char *, size_t *, int, int)
Definition strmatch.c:505
#define dtmatch(d, o)
Definition cdt.h:192
#define dtinsert(d, o)
Definition cdt.h:193
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
#define sub(h, i)
Definition closest.c:65
color_type_t
Definition color.h:26
@ HSVA_DOUBLE
Definition color.h:26
@ RGBA_BYTE
Definition color.h:26
#define COLOR_OK
Definition color.h:44
void colorxlate(char *str, agxbuf *buf)
Definition colxlate.c:48
Agedge_t * openEdge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *key)
Definition compile.c:2612
Agraph_t * openG(char *name, Agdesc_t desc)
Definition compile.c:2570
Agraph_t * openSubg(Agraph_t *g, char *name)
Definition compile.c:2586
Agnode_t * openNode(Agraph_t *g, char *name)
Definition compile.c:2599
Agraph_t * readG(FILE *fp)
Definition compile.c:2552
#define OBJ(p)
Definition compile.h:46
#define gData(g)
Definition compile.h:53
mode
Definition cvtgxl.c:33
static char * fname
void error(int level, const char *s,...)
Definition error.c:83
#define ERROR_WARNING
Definition error.h:35
void exwarn(const char *format,...)
Definition exerror.c:79
void exerror(const char *format,...)
Definition exerror.c:62
char * exstring(Expr_t *ex, char *s)
Definition exeval.c:2000
void * exstralloc(Expr_t *ex, size_t sz)
Definition exeval.c:2008
disc key
Definition exparse.y:214
expr procedure type
Definition exparse.y:211
#define S
Definition expr.h:72
static double len(glCompPoint p)
Definition glutils.c:150
void * malloc(YYSIZE_T)
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:149
int agnedges(Agraph_t *g)
Definition graph.c:164
Agsym_t * agattrsym(void *obj, char *name)
looks up a string attribute for a graph object given as an argument
Definition attr.c:156
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:341
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:356
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:481
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:458
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:260
#define AGMKOUT(e)
Definition cgraph.h:883
Agedge_t * agsubedge(Agraph_t *g, Agedge_t *e, int createflag)
Definition edge.c:355
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:23
#define agtail(e)
Definition cgraph.h:889
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition edge.c:93
#define aghead(e)
Definition cgraph.h:890
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:38
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Definition edge.c:84
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:96
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:708
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition node.c:147
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:47
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:40
Agnode_t * agsubnode(Agraph_t *g, Agnode_t *n, int createflag)
Definition node.c:261
Agnode_t * agidnode(Agraph_t *g, IDTYPE id, int createflag)
Definition node.c:124
Agraph_t * agraphof(void *obj)
Definition obj.c:184
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
#define AGID(obj)
returns the unique integer ID associated with the object
Definition cgraph.h:221
#define AGTYPE(obj)
returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
Definition cgraph.h:216
int agdelete(Agraph_t *g, void *obj)
deletes object. Equivalent to agclose, agdelnode, and agdeledge for obj being a graph,...
Definition obj.c:19
Agraph_t * agroot(void *obj)
Definition obj.c:167
@ AGOUTEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGINEDGE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
int aghtmlstr(const char *)
Definition refstr.c:163
int agstrfree(Agraph_t *, const char *)
Definition refstr.c:138
char * agcanonStr(char *str)
Definition write.c:237
char * agstrdup_html(Agraph_t *, const char *)
Definition refstr.c:134
Agraph_t * agfstsubg(Agraph_t *g)
Definition subg.c:77
Agraph_t * agnxtsubg(Agraph_t *subg)
Definition subg.c:82
static uint64_t id
Definition gv2gml.c:42
Agraph_t * read(FILE *f)
Definition gv.cpp:61
replacements for ctype.h functions
static char gv_toupper(int c)
Definition gv_ctype.h:93
static char gv_tolower(int c)
Definition gv_ctype.h:81
static void color(Agraph_t *g)
Definition gvcolor.c:128
static Agdesc_t kind
Definition gvpack.cpp:88
agxbuf * str
Definition htmlparse.c:97
NEATOPROCS_API void s1(graph_t *, node_t *)
Definition stuff.c:671
#define alpha
Definition shapes.c:4068
static double cg(SparseMatrix A, const double *precond, int n, int dim, double *x0, double *rhs, double tol, double maxit)
platform abstraction for case-insensitive string functions
Agdisc_t disc
Definition cgraph.h:412
Agiodisc_t * io
Definition cgraph.h:339
IO services.
Definition cgraph.h:327
a generic header of Agraph_s, Agnode_s and Agedge_s
Definition cgraph.h:210
graph or subgraph
Definition cgraph.h:425
Agclos_t * clos
shared resources
Definition cgraph.h:435
Agdesc_t desc
Definition cgraph.h:427
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:639
char * name
Definition cgraph.h:641
char * defval
Definition cgraph.h:642
Definition expr.h:202
FILE * file[10]
Definition expr.h:205
Definition cdt.h:104
int key
Definition cdt.h:89
union agxbuf::@59 u
Definition legal.c:50
Dtlink_t link
Definition actions.c:199
Agedge_t * key
Definition actions.c:200
Agedge_t * val
Definition actions.c:201
struct tms mytime_t
Definition timing.c:24
Definition grammar.c:93
#define UNREACHABLE()
Definition unreachable.h:30
abstraction for squashing compiler warnings for unused symbols