Graphviz 13.0.0~dev.20250607.1528
Loading...
Searching...
No Matches
input.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 <common/htmltable.h>
15#include <errno.h>
16#include <gvc/gvc.h>
17#include <xdot/xdot.h>
18#include <limits.h>
19#include <stdbool.h>
20#include <stdlib.h>
21#include <string.h>
22#include <util/agxbuf.h>
23#include <util/alloc.h>
24#include <util/exit.h>
25#include <util/gv_ctype.h>
26#include <util/gv_fopen.h>
27#include <util/gv_math.h>
28#include <util/startswith.h>
29#include <util/strcasecmp.h>
30#include <util/streq.h>
31
32static char *usageFmt =
33 "Usage: %s [-Vv?] [-(GNE)name=val] [-(KTlso)<val>] <dot files>\n";
34
35static char *genericItems = "\n\
36 -V - Print version and exit\n\
37 -v - Enable verbose mode \n\
38 -Gname=val - Set graph attribute 'name' to 'val'\n\
39 -Nname=val - Set node attribute 'name' to 'val'\n\
40 -Ename=val - Set edge attribute 'name' to 'val'\n\
41 -Tv - Set output format to 'v'\n\
42 -Kv - Set layout engine to 'v' (overrides default based on command name)\n\
43 -lv - Use external library 'v'\n\
44 -ofile - Write output to 'file'\n\
45 -O - Automatically generate an output filename based on the input filename with a .'format' appended. (Causes all -ofile options to be ignored.) \n\
46 -P - Internally generate a graph of the current plugins. \n\
47 -q[l] - Set level of message suppression (=1)\n\
48 -s[v] - Scale input by 'v' (=72)\n\
49 -y - Invert y coordinate in output\n";
50
51static char *neatoFlags =
52 "(additional options for neato) [-x] [-n<v>]\n";
53static char *neatoItems = "\n\
54 -n[v] - No layout mode 'v' (=1)\n\
55 -x - Reduce graph\n";
56
57static char *fdpFlags =
58 "(additional options for fdp) [-L(gO)] [-L(nUCT)<val>]\n";
59static char *fdpItems = "\n\
60 -Lg - Don't use grid\n\
61 -LO - Use old attractive force\n\
62 -Ln<i> - Set number of iterations to i\n\
63 -LU<i> - Set unscaled factor to i\n\
64 -LC<v> - Set overlap expansion factor to v\n\
65 -LT[*]<v> - Set temperature (temperature factor) to v\n";
66
67static char *configFlags = "(additional options for config) [-cv]\n";
68static char *configItems = "\n\
69 -c - Configure plugins (Writes $prefix/lib/graphviz/config \n\
70 with available plugin information. Needs write privilege.)\n\
71 -? - Print usage and exit\n";
72
73/* Print usage information. If GvExitOnUsage is set, exit with
74 * given exval, else return exval+1.
75 *
76 * @param argv0 Command name to use in usage message
77 */
78int dotneato_usage(const char *argv0, int exval) {
79 FILE *outs;
80
81 if (exval > 0)
82 outs = stderr;
83 else
84 outs = stdout;
85
86 fprintf(outs, usageFmt, argv0);
87 fputs(neatoFlags, outs);
88 fputs(fdpFlags, outs);
89 fputs(configFlags, outs);
90 fputs(genericItems, outs);
91 fputs(neatoItems, outs);
92 fputs(fdpItems, outs);
93 fputs(configItems, outs);
94
95 if (GvExitOnUsage && exval >= 0)
96 graphviz_exit(exval);
97 return exval + 1;
98}
99
100/* Look for flag parameter. idx is index of current argument.
101 * We assume argv[*idx] has the form "-x..." If there are characters
102 * after the x, return
103 * these, else if there are more arguments, return the next one,
104 * else return NULL.
105 */
106static char *getFlagOpt(int argc, char **argv, int *idx)
107{
108 int i = *idx;
109 char *arg = argv[i];
110
111 if (arg[2])
112 return arg + 2;
113 if (i < argc - 1) {
114 i++;
115 arg = argv[i];
116 if (*arg && *arg != '-') {
117 *idx = i;
118 return arg;
119 }
120 }
121 return 0;
122}
123
124/* Partial implementation of real basename.
125 * Skip over any trailing slashes or backslashes; then
126 * find next (back)slash moving left; return string to the right.
127 * If no next slash is found, return the whole string.
128 */
129static char *dotneato_basename(char *pathname) {
130 char* ret;
131 char* s = pathname;
132 if (*s == '\0') return pathname; /* empty string */
133#ifdef _WIN32
134 /* On Windows, executables, by convention, end in ".exe". Thus,
135 * this may be part of the path name and must be removed for
136 * matching to work.
137 */
138 {
139 char* dotp = strrchr (s, '.');
140 if (dotp && !strcasecmp(dotp+1,"exe")) *dotp = '\0';
141 }
142#endif
143 while (*s) s++;
144 s--;
145 /* skip over trailing slashes, nulling out as we go */
146 while (s > pathname && (*s == '/' || *s == '\\'))
147 *s-- = '\0';
148 if (s == pathname) ret = pathname;
149 else {
150 while (s > pathname && *s != '/' && *s != '\\') s--;
151 if (*s == '/' || *s == '\\') ret = s+1;
152 else ret = pathname;
153 }
154#ifdef _WIN32
155 /* On Windows, names are case-insensitive, so make name lower-case
156 */
157 gv_tolower_str(ret);
158#endif
159 return ret;
160}
161
162static void use_library(GVC_t *gvc, const char *name)
163{
164 static size_t cnt = 0;
165 if (name) {
166 const size_t old_nmemb = cnt == 0 ? cnt : cnt + 1;
167 Lib = gv_recalloc(Lib, old_nmemb, cnt + 2, sizeof(const char *));
168 Lib[cnt++] = name;
169 Lib[cnt] = NULL;
170 }
171 gvc->common.lib = Lib;
172}
173
174static void global_def(char *dcl, int kind) {
175 char *p;
176 char *rhs = "true";
177 agxbuf xb = {0};
178
179 attrsym_t *sym;
180 if ((p = strchr(dcl, '='))) {
181 agxbput_n(&xb, dcl, (size_t)(p - dcl));
182 rhs = p+1;
183 }
184 else
185 agxbput(&xb, dcl);
186 sym = agattr_text(NULL, kind, agxbuse(&xb), rhs);
187 sym->fixed = 1;
188 agxbfree(&xb);
189}
190
191static int gvg_init(GVC_t *gvc, graph_t *g, char *fn, int gidx)
192{
193 GVG_t *gvg = gv_alloc(sizeof(GVG_t));
194 if (!gvc->gvgs)
195 gvc->gvgs = gvg;
196 else
197 gvc->gvg->next = gvg;
198 gvc->gvg = gvg;
199 gvg->gvc = gvc;
200 gvg->g = g;
201 gvg->input_filename = fn;
202 gvg->graph_index = gidx;
203 return 0;
204}
205
207
209{
210 gvg_init(gvc, P_graph, "<internal>", 0);
211 return P_graph;
212}
213
214/* Scan argv[] for allowed flags.
215 * Return 0 on success; v+1 if calling function should call exit(v).
216 * If -c is set, config file is created and we exit.
217 */
218int dotneato_args_initialize(GVC_t * gvc, int argc, char **argv)
219{
220 char c;
221 bool Kflag = false;
222
223 /* establish if we are running in a CGI environment */
224 HTTPServerEnVar = getenv("SERVER_NAME");
225
226 // test `$GV_FILE_PATH`, a legacy knob, is not set
227 if (getenv("GV_FILE_PATH") != NULL) {
228 fprintf(stderr, "$GV_FILE_PATH environment variable set; exiting\n"
229 "\n"
230 "This sandboxing mechanism is no longer supported\n");
231 graphviz_exit(EXIT_FAILURE);
232 }
233
235 if (gvc->common.verbose) {
236 fprintf(stderr, "%s - %s version %s (%s)\n",
238 gvc->common.info[1], gvc->common.info[2]);
239 }
240
241 /* configure for available plugins */
242 /* needs to know if "dot -c" is set (gvc->common.config) */
243 /* must happen before trying to select any plugins */
244 if (gvc->common.config) {
246 graphviz_exit(0);
247 }
248
249 /* feed the globals */
250 Verbose = gvc->common.verbose > UCHAR_MAX
251 ? UCHAR_MAX
252 : (unsigned char)gvc->common.verbose;
253
254 size_t nfiles = 0;
255 for (int i = 1; i < argc; i++)
256 if (argv[i] && argv[i][0] != '-')
257 nfiles++;
258 gvc->input_filenames = gv_calloc(nfiles + 1, sizeof(char *));
259 nfiles = 0;
260 for (int i = 1; i < argc; i++) {
261 if (argv[i] &&
262 (startswith(argv[i], "-V") || strcmp(argv[i], "--version") == 0)) {
263 fprintf(stderr, "%s - %s version %s (%s)\n",
265 gvc->common.info[1], gvc->common.info[2]);
267 return 1;
268 } else if (argv[i] &&
269 (startswith(argv[i], "-?") || strcmp(argv[i], "--help") == 0)) {
270 return dotneato_usage(argv[0], 0);
271 } else if (argv[i] && startswith(argv[i], "--filepath=")) {
273 Gvfilepath = gv_strdup(argv[i] + strlen("--filepath="));
274 } else if (argv[i] && argv[i][0] == '-') {
275 char *const rest = &argv[i][2];
276 switch (c = argv[i][1]) {
277 case 'G':
278 if (*rest)
279 global_def(rest, AGRAPH);
280 else {
281 fprintf(stderr, "Missing argument for -G flag\n");
282 return dotneato_usage(argv[0], 1);
283 }
284 break;
285 case 'N':
286 if (*rest)
287 global_def(rest, AGNODE);
288 else {
289 fprintf(stderr, "Missing argument for -N flag\n");
290 return dotneato_usage(argv[0], 1);
291 }
292 break;
293 case 'E':
294 if (*rest)
295 global_def(rest, AGEDGE);
296 else {
297 fprintf(stderr, "Missing argument for -E flag\n");
298 return dotneato_usage(argv[0], 1);
299 }
300 break;
301 case 'T': {
302 const char *const val = getFlagOpt(argc, argv, &i);
303 if (!val) {
304 fprintf(stderr, "Missing argument for -T flag\n");
305 return dotneato_usage(argv[0], 1);
306 }
307 if (!gvjobs_output_langname(gvc, val)) {
308 const char *const fmts = gvplugin_list(gvc, API_device, val);
309 fprintf(stderr, "Format: \"%s\" not recognized.", val);
310 if (strlen(fmts) > 1) {
311 fprintf(stderr, " Use one of:%s\n", fmts);
312 } else {
313 /* Q: Should 'dot -c' be suggested generally or only when val = "dot"? */
314 fprintf(stderr, " No formats found.\nPerhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
315 }
317 return 2;
318 }
319 break;
320 }
321 case 'K': {
322 const char *const val = getFlagOpt(argc, argv, &i);
323 if (!val) {
324 fprintf(stderr, "Missing argument for -K flag\n");
325 return dotneato_usage(argv[0], 1);
326 }
327 const int v = gvlayout_select(gvc, val);
328 if (v == NO_SUPPORT) {
329 fprintf(stderr, "There is no layout engine support for \"%s\"\n", val);
330 if (streq(val, "dot")) {
331 fprintf(stderr, "Perhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
332 }
333 else {
334 const char *const lyts = gvplugin_list(gvc, API_layout, val);
335 if (strlen(lyts) > 1) {
336 fprintf(stderr, " Use one of:%s\n", lyts);
337 } else {
338 /* Q: Should 'dot -c' be suggested generally or only when val = "dot"? */
339 fprintf(stderr, " No layouts found.\nPerhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
340 }
341 }
343 return 2;
344 }
345 Kflag = true;
346 break;
347 }
348 case 'P':
350 break;
351 case 'l': {
352 const char *const val = getFlagOpt(argc, argv, &i);
353 if (!val) {
354 fprintf(stderr, "Missing argument for -l flag\n");
355 return dotneato_usage(argv[0], 1);
356 }
357 use_library(gvc, val);
358 break;
359 }
360 case 'o': {
361 const char *const val = getFlagOpt(argc, argv, &i);
362 if (!val) {
363 fprintf(stderr, "Missing argument for -o flag\n");
364 return dotneato_usage(argv[0], 1);
365 }
368 break;
369 }
370 case 'q':
371 if (*rest) {
372 const int v = atoi(rest);
373 if (v <= 0) {
374 fprintf(stderr,
375 "Invalid parameter \"%s\" for -q flag - ignored\n",
376 rest);
377 } else if (v == 1)
379 else
381 } else
383 break;
384 case 's':
385 if (*rest) {
386 PSinputscale = atof(rest);
387 if (PSinputscale < 0) {
388 fprintf(stderr,
389 "Invalid parameter \"%s\" for -s flag\n",
390 rest);
391 return dotneato_usage(argv[0], 1);
392 }
395 } else
397 break;
398 case 'x':
399 Reduce = true;
400 break;
401 case 'y':
402 Y_invert = true;
403 break;
404 default:
405 agerrorf("%s: option -%c unrecognized\n\n", gvc->common.cmdname,
406 c);
407 return dotneato_usage(argv[0], 1);
408 }
409 } else if (argv[i])
410 gvc->input_filenames[nfiles++] = argv[i];
411 }
412
413 /* if no -K, use cmd name to set layout type */
414 if (!Kflag) {
415 const char *layout = gvc->common.cmdname;
416 if (streq(layout, "dot_static")
417 || streq(layout, "dot_builtins")
418 || streq(layout, "lt-dot")
419 || streq(layout, "lt-dot_builtins")
420 || streq(layout, "") /* when run as a process from Gvedit on Windows */
421 )
422 layout = "dot";
423 const int i = gvlayout_select(gvc, layout);
424 if (i == NO_SUPPORT) {
425 fprintf(stderr, "There is no layout engine support for \"%s\"\n", layout);
426 if (streq(layout, "dot")) {
427 fprintf(stderr, "Perhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
428 } else {
429 const char *const lyts = gvplugin_list(gvc, API_layout, "");
430 if (strlen(lyts) > 1) {
431 fprintf(stderr, " Use one of:%s\n", lyts);
432 } else {
433 /* Q: Should 'dot -c' be suggested generally or only when val = "dot"? */
434 fprintf(stderr, " No layouts found.\nPerhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
435 }
436 }
437
439 return 2;
440 }
441 }
442
443 /* if no -Txxx, then set default format */
444 if (!gvc->jobs || !gvc->jobs->output_langname) {
445 if (!gvjobs_output_langname(gvc, "dot")) {
446 fprintf(stderr,
447 "Unable to find even the default \"-Tdot\" renderer. Has the config\nfile been generated by running \"dot -c\" with installer's privileges?\n");
448 return 2;
449 }
450 }
451
452 /* set persistent attributes here (if not already set from command line options) */
453 if (!agattr_text(NULL, AGNODE, "label", 0))
455 return 0;
456}
457
458/* converts a graph attribute in inches to a pointf in points.
459 * If only one number is given, it is used for both x and y.
460 * Returns true if the attribute ends in '!'.
461 */
462static bool getdoubles2ptf(graph_t *g, char *name, pointf *result) {
463 char *p;
464 int i;
465 double xf, yf;
466 char c = '\0';
467 bool rv = false;
468
469 if ((p = agget(g, name))) {
470 i = sscanf(p, "%lf,%lf%c", &xf, &yf, &c);
471 if (i > 1 && xf > 0 && yf > 0) {
472 result->x = POINTS(xf);
473 result->y = POINTS(yf);
474 if (c == '!')
475 rv = true;
476 }
477 else {
478 c = '\0';
479 i = sscanf(p, "%lf%c", &xf, &c);
480 if (i > 0 && xf > 0) {
481 result->y = result->x = POINTS(xf);
482 if (c == '!') rv = true;
483 }
484 }
485 }
486 return rv;
487}
488
489void getdouble(graph_t * g, char *name, double *result)
490{
491 char *p;
492 double f;
493
494 if ((p = agget(g, name))) {
495 if (sscanf(p, "%lf", &f) >= 1)
496 *result = f;
497 }
498}
499
501{
502 graph_t *g = NULL;
503 static char *fn;
504 static FILE *fp;
505 static int gidx;
506
507 while (!g) {
508 if (!fp) {
509 if (!(fn = gvc->input_filenames[0])) {
510 if (gvc->fidx++ == 0)
511 fp = stdin;
512 }
513 else {
514 while ((fn = gvc->input_filenames[gvc->fidx++]) && !(fp = gv_fopen(fn, "r"))) {
515 agerrorf("%s: can't open %s: %s\n", gvc->common.cmdname, fn, strerror(errno));
517 }
518 }
519 }
520 if (fp == NULL)
521 break;
522 g = agconcat(NULL, fn ? fn : "<stdin>", fp, NULL);
523 if (g) {
524 gvg_init(gvc, g, fn, gidx++);
525 break;
526 }
527 if (fp != stdin)
528 fclose (fp);
529 fp = NULL;
530 gidx = 0;
531 }
532 return g;
533}
534
535/* Check if the charset attribute is defined for the graph and, if
536 * so, return the corresponding internal value. If undefined, return
537 * CHAR_UTF8
538 */
539static unsigned char findCharset(graph_t *g) {
540 char* p;
541
542 p = late_nnstring(g,agfindgraphattr(g,"charset"),"utf-8");
543 if (!strcasecmp(p,"latin-1")
544 || !strcasecmp(p,"latin1")
545 || !strcasecmp(p,"l1")
546 || !strcasecmp(p,"ISO-8859-1")
547 || !strcasecmp(p,"ISO_8859-1")
548 || !strcasecmp(p,"ISO8859-1")
549 || !strcasecmp(p,"ISO-IR-100"))
550 return CHAR_LATIN1;
551 if (!strcasecmp(p,"big-5")
552 || !strcasecmp(p,"big5"))
553 return CHAR_BIG5;
554 if (!strcasecmp(p,"utf-8")
555 || !strcasecmp(p,"utf8"))
556 return CHAR_UTF8;
557 agwarningf("Unsupported charset \"%s\" - assuming utf-8\n", p);
558 return CHAR_UTF8;
559}
560
562static void setRatio(graph_t * g)
563{
564 char *p;
565 double ratio;
566
567 if ((p = agget(g, "ratio"))) {
568 if (streq(p, "auto")) {
569 GD_drawing(g)->ratio_kind = R_AUTO;
570 } else if (streq(p, "compress")) {
571 GD_drawing(g)->ratio_kind = R_COMPRESS;
572 } else if (streq(p, "expand")) {
573 GD_drawing(g)->ratio_kind = R_EXPAND;
574 } else if (streq(p, "fill")) {
575 GD_drawing(g)->ratio_kind = R_FILL;
576 } else {
577 ratio = atof(p);
578 if (ratio > 0.0) {
579 GD_drawing(g)->ratio_kind = R_VALUE;
580 GD_drawing(g)->ratio = ratio;
581 }
582 }
583 }
584}
585
586void graph_init(graph_t * g, bool use_rankdir)
587{
588 char *p;
589 double xf;
590 static char *rankname[] = { "local", "global", "none", NULL };
591 static int rankcode[] = { LOCAL, GLOBAL, NOCLUST, LOCAL };
592 static char *fontnamenames[] = {"gd","ps","svg", NULL};
593 static int fontnamecodes[] = {NATIVEFONTS,PSFONTS,SVGFONTS,-1};
594 int rankdir;
595 GD_drawing(g) = gv_alloc(sizeof(layout_t));
596
597 /* reparseable input */
598 if ((p = agget(g, "postaction"))) { /* requires a graph wrapper for yyparse */
599 agxbuf buf = {0};
600 agxbprint(&buf, "%s { %s }", agisdirected(g) ? "digraph" : "graph", p);
601 agmemconcat(g, agxbuse(&buf));
602 agxbfree(&buf);
603 }
604
605 /* set this up fairly early in case any string sizes are needed */
606 if ((p = agget(g, "fontpath")) || (p = getenv("DOTFONTPATH"))) {
607 /* overide GDFONTPATH in local environment if dot
608 * wants its own */
609#ifdef HAVE_SETENV
610 setenv("GDFONTPATH", p, 1);
611#else
612 static agxbuf buf;
613 agxbprint(&buf, "GDFONTPATH=%s", p);
614 putenv(agxbuse(&buf));
615#endif
616 }
617
618 GD_charset(g) = findCharset (g);
619
620 if (!HTTPServerEnVar) {
621 Gvimagepath = agget (g, "imagepath");
622 if (!Gvimagepath) {
624 }
625 }
626
627 GD_drawing(g)->quantum =
628 late_double(g, agfindgraphattr(g, "quantum"), 0.0, 0.0);
629
630 /* setting rankdir=LR is only defined in dot,
631 * but having it set causes shape code and others to use it.
632 * The result is confused output, so we turn it off unless requested.
633 * This effective rankdir is stored in the bottom 2 bits of g->u.rankdir.
634 * Sometimes, the code really needs the graph's rankdir, e.g., neato -n
635 * with record shapes, so we store the real rankdir in the next 2 bits.
636 */
637 rankdir = RANKDIR_TB;
638 if ((p = agget(g, "rankdir"))) {
639 if (streq(p, "LR"))
640 rankdir = RANKDIR_LR;
641 else if (streq(p, "BT"))
642 rankdir = RANKDIR_BT;
643 else if (streq(p, "RL"))
644 rankdir = RANKDIR_RL;
645 }
646 if (use_rankdir)
647 SET_RANKDIR (g, (rankdir << 2) | rankdir);
648 else
649 SET_RANKDIR(g, rankdir << 2);
650
651 xf = late_double(g, agfindgraphattr(g, "nodesep"),
653 GD_nodesep(g) = POINTS(xf);
654
655 p = late_string(g, agfindgraphattr(g, "ranksep"), NULL);
656 if (p) {
657 if (sscanf(p, "%lf", &xf) == 0)
658 xf = DEFAULT_RANKSEP;
659 else {
660 if (xf < MIN_RANKSEP)
661 xf = MIN_RANKSEP;
662 }
663 if (strstr(p, "equally"))
664 GD_exact_ranksep(g) = true;
665 } else
666 xf = DEFAULT_RANKSEP;
667 GD_ranksep(g) = POINTS(xf);
668
669 {
670 int showboxes = late_int(g, agfindgraphattr(g, "showboxes"), 0, 0);
671 if (showboxes > UCHAR_MAX) {
672 showboxes = UCHAR_MAX;
673 }
674 GD_showboxes(g) = (unsigned char)showboxes;
675 }
676 p = late_string(g, agfindgraphattr(g, "fontnames"), NULL);
677 GD_fontnames(g) = maptoken(p, fontnamenames, fontnamecodes);
678
679 setRatio(g);
680 GD_drawing(g)->filled = getdoubles2ptf(g, "size", &GD_drawing(g)->size);
681 getdoubles2ptf(g, "page", &GD_drawing(g)->page);
682
683 GD_drawing(g)->centered = mapbool(agget(g, "center"));
684
685 if ((p = agget(g, "rotate")))
686 GD_drawing(g)->landscape = atoi(p) == 90;
687 else if ((p = agget(g, "orientation")))
688 GD_drawing(g)->landscape = p[0] == 'l' || p[0] == 'L';
689 else if ((p = agget(g, "landscape")))
690 GD_drawing(g)->landscape = mapbool(p);
691
692 p = agget(g, "clusterrank");
693 CL_type = maptoken(p, rankname, rankcode);
694 p = agget(g, "concentrate");
695 Concentrate = mapbool(p);
696 State = GVBEGIN;
697 EdgeLabelsDone = 0;
698
699 GD_drawing(g)->dpi = 0.0;
700 if (((p = agget(g, "dpi")) && p[0])
701 || ((p = agget(g, "resolution")) && p[0]))
702 GD_drawing(g)->dpi = atof(p);
703
705
707
708 G_ordering = agfindgraphattr(g, "ordering");
709 G_gradientangle = agfindgraphattr(g,"gradientangle");
710 G_margin = agfindgraphattr(g, "margin");
711
712 /* initialize nodes */
713 N_height = agfindnodeattr(g, "height");
714 N_width = agfindnodeattr(g, "width");
715 N_shape = agfindnodeattr(g, "shape");
716 N_color = agfindnodeattr(g, "color");
717 N_fillcolor = agfindnodeattr(g, "fillcolor");
718 N_style = agfindnodeattr(g, "style");
719 N_fontsize = agfindnodeattr(g, "fontsize");
720 N_fontname = agfindnodeattr(g, "fontname");
721 N_fontcolor = agfindnodeattr(g, "fontcolor");
722 N_label = agfindnodeattr(g, "label");
723 if (!N_label)
724 N_label = agattr_text(g, AGNODE, "label", NODENAME_ESC);
725 N_xlabel = agfindnodeattr(g, "xlabel");
726 N_showboxes = agfindnodeattr(g, "showboxes");
727 N_penwidth = agfindnodeattr(g, "penwidth");
728 N_ordering = agfindnodeattr(g, "ordering");
729 /* attribs for polygon shapes */
730 N_sides = agfindnodeattr(g, "sides");
731 N_peripheries = agfindnodeattr(g, "peripheries");
732 N_skew = agfindnodeattr(g, "skew");
733 N_orientation = agfindnodeattr(g, "orientation");
734 N_distortion = agfindnodeattr(g, "distortion");
735 N_fixed = agfindnodeattr(g, "fixedsize");
736 N_imagescale = agfindnodeattr(g, "imagescale");
737 N_imagepos = agfindnodeattr(g, "imagepos");
738 N_nojustify = agfindnodeattr(g, "nojustify");
739 N_layer = agfindnodeattr(g, "layer");
740 N_group = agfindnodeattr(g, "group");
741 N_comment = agfindnodeattr(g, "comment");
742 N_vertices = agfindnodeattr(g, "vertices");
743 N_z = agfindnodeattr(g, "z");
744 N_gradientangle = agfindnodeattr(g,"gradientangle");
745
746 /* initialize edges */
747 E_weight = agfindedgeattr(g, "weight");
748 E_color = agfindedgeattr(g, "color");
749 E_fillcolor = agfindedgeattr(g, "fillcolor");
750 E_fontsize = agfindedgeattr(g, "fontsize");
751 E_fontname = agfindedgeattr(g, "fontname");
752 E_fontcolor = agfindedgeattr(g, "fontcolor");
753 E_label = agfindedgeattr(g, "label");
754 E_xlabel = agfindedgeattr(g, "xlabel");
755 E_label_float = agfindedgeattr(g, "labelfloat");
756 E_dir = agfindedgeattr(g, "dir");
757 E_headlabel = agfindedgeattr(g, "headlabel");
758 E_taillabel = agfindedgeattr(g, "taillabel");
759 E_labelfontsize = agfindedgeattr(g, "labelfontsize");
760 E_labelfontname = agfindedgeattr(g, "labelfontname");
761 E_labelfontcolor = agfindedgeattr(g, "labelfontcolor");
762 E_labeldistance = agfindedgeattr(g, "labeldistance");
763 E_labelangle = agfindedgeattr(g, "labelangle");
764 E_minlen = agfindedgeattr(g, "minlen");
765 E_showboxes = agfindedgeattr(g, "showboxes");
766 E_style = agfindedgeattr(g, "style");
767 E_decorate = agfindedgeattr(g, "decorate");
768 E_arrowsz = agfindedgeattr(g, "arrowsize");
769 E_constr = agfindedgeattr(g, "constraint");
770 E_layer = agfindedgeattr(g, "layer");
771 E_comment = agfindedgeattr(g, "comment");
772 E_tailclip = agfindedgeattr(g, "tailclip");
773 E_headclip = agfindedgeattr(g, "headclip");
774 E_penwidth = agfindedgeattr(g, "penwidth");
775
776 /* background */
777 GD_drawing(g)->xdots = init_xdot (g);
778
779 /* initialize id, if any */
780 if ((p = agget(g, "id")) && *p)
781 GD_drawing(g)->id = strdup_and_subst_obj(p, g);
782}
783
785{
786 if (GD_drawing(g) && GD_drawing(g)->xdots)
787 freeXDot(GD_drawing(g)->xdots);
788 if (GD_drawing(g))
789 free (GD_drawing(g)->id);
790 free(GD_drawing(g));
791 GD_drawing(g) = NULL;
793 //FIX HERE , STILL SHALLOW
794 //memset(&(g->u), 0, sizeof(Agraphinfo_t));
795 agclean(g, AGRAPH,"Agraphinfo_t");
796}
797
799char*
801{
802 char* s;
803
804 switch (c) {
805 case CHAR_UTF8 :
806 s = "UTF-8";
807 break;
808 case CHAR_LATIN1 :
809 s = "ISO-8859-1";
810 break;
811 case CHAR_BIG5 :
812 s = "BIG-5";
813 break;
814 default :
815 agerrorf("Unsupported charset value %d\n", c);
816 s = "UTF-8";
817 break;
818 }
819 return s;
820}
821
824{
825 char *str, *pos, *just;
826 int pos_ix;
827
828 /* it would be nice to allow multiple graph labels in the future */
829 if ((str = agget(sg, "label")) && *str != '\0') {
830 char pos_flag;
831 pointf dimen;
832
834
836 late_double(sg, agfindgraphattr(sg, "fontsize"),
838 late_nnstring(sg, agfindgraphattr(sg, "fontname"),
840 late_nnstring(sg, agfindgraphattr(sg, "fontcolor"),
842
843 /* set label position */
844 pos = agget(sg, "labelloc");
845 if (sg != agroot(sg)) {
846 if (pos && pos[0] == 'b')
847 pos_flag = LABEL_AT_BOTTOM;
848 else
849 pos_flag = LABEL_AT_TOP;
850 } else {
851 if (pos && pos[0] == 't')
852 pos_flag = LABEL_AT_TOP;
853 else
854 pos_flag = LABEL_AT_BOTTOM;
855 }
856 just = agget(sg, "labeljust");
857 if (just) {
858 if (just[0] == 'l')
859 pos_flag |= LABEL_AT_LEFT;
860 else if (just[0] == 'r')
861 pos_flag |= LABEL_AT_RIGHT;
862 }
863 GD_label_pos(sg) = pos_flag;
864
865 if (sg == agroot(sg))
866 return;
867
868 /* Set border information for cluster labels to allow space
869 */
870 dimen = GD_label(sg)->dimen;
871 PAD(dimen);
872 if (!GD_flip(agroot(sg))) {
873 if (GD_label_pos(sg) & LABEL_AT_TOP)
874 pos_ix = TOP_IX;
875 else
876 pos_ix = BOTTOM_IX;
877 GD_border(sg)[pos_ix] = dimen;
878 } else {
879 /* when rotated, the labels will be restored to TOP or BOTTOM */
880 if (GD_label_pos(sg) & LABEL_AT_TOP)
881 pos_ix = RIGHT_IX;
882 else
883 pos_ix = LEFT_IX;
884 GD_border(sg)[pos_ix].x = dimen.y;
885 GD_border(sg)[pos_ix].y = dimen.x;
886 }
887 }
888}
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:78
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
Definition agxbuf.h:250
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
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 char * gv_strdup(const char *original)
Definition alloc.h:101
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
char * late_nnstring(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:86
bool mapbool(const char *p)
Definition utils.c:337
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:80
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:35
int maptoken(char *p, char **name, int *val)
Definition utils.c:311
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:50
#define DEFAULT_RANKSEP
Definition const.h:87
#define CHAR_UTF8
Definition const.h:196
#define LABEL_AT_LEFT
Definition const.h:186
#define BOTTOM_IX
Definition const.h:111
#define TOP_IX
Definition const.h:113
#define CHAR_LATIN1
Definition const.h:197
#define NO_SUPPORT
Definition const.h:147
#define MIN_NODESEP
Definition const.h:86
#define MIN_RANKSEP
Definition const.h:88
#define GRAPH_LABEL
Definition const.h:179
#define NODENAME_ESC
Definition const.h:80
#define LOCAL
Definition const.h:43
#define RANKDIR_BT
Definition const.h:192
#define GLOBAL
Definition const.h:44
#define DEFAULT_NODESEP
Definition const.h:85
#define LEFT_IX
Definition const.h:114
#define RANKDIR_TB
Definition const.h:190
#define CHAR_BIG5
Definition const.h:198
#define DEFAULT_COLOR
Definition const.h:48
#define RANKDIR_LR
Definition const.h:191
#define LABEL_AT_TOP
Definition const.h:185
#define MYHUGE
Definition const.h:168
#define DEFAULT_FONTSIZE
Definition const.h:61
#define MIN_FONTSIZE
Definition const.h:63
#define NOCLUST
Definition const.h:45
#define LT_NONE
Definition const.h:237
#define DEFAULT_FONTNAME
Definition const.h:67
#define LABEL_AT_RIGHT
Definition const.h:187
#define GVBEGIN
Definition const.h:172
#define RANKDIR_RL
Definition const.h:193
#define LABEL_AT_BOTTOM
Definition const.h:184
#define LT_HTML
Definition const.h:238
#define RIGHT_IX
Definition const.h:112
void * init_xdot(Agraph_t *g)
Definition emit.c:59
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
#define POINTS(a_inches)
Definition geom.h:62
#define POINTS_PER_INCH
Definition geom.h:58
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_group
Definition globals.h:79
Agsym_t * N_imagescale
Definition globals.h:78
Agsym_t * N_width
Definition globals.h:74
Agsym_t * N_layer
Definition globals.h:78
Agsym_t * E_weight
Definition globals.h:82
int State
Definition globals.h:63
Agsym_t * E_comment
Definition globals.h:86
Agsym_t * N_orientation
Definition globals.h:77
Agsym_t * N_sides
Definition globals.h:77
bool Concentrate
Definition globals.h:59
double Initial_dist
Definition globals.h:65
Agsym_t * E_headclip
Definition globals.h:91
int GvExitOnUsage
Definition globals.h:68
Agsym_t * E_decorate
Definition globals.h:84
Agsym_t * G_ordering
Definition globals.h:71
Agsym_t * E_headlabel
Definition globals.h:88
Agsym_t * E_style
Definition globals.h:84
Agsym_t * G_margin
Definition globals.h:72
Agsym_t * N_showboxes
Definition globals.h:76
int graphviz_errors
Definition globals.h:54
Agsym_t * N_fontname
Definition globals.h:75
Agsym_t * N_z
Definition globals.h:79
Agsym_t * E_fontname
Definition globals.h:83
Agsym_t * N_comment
Definition globals.h:79
Agsym_t * N_style
Definition globals.h:76
char * HTTPServerEnVar
Definition globals.h:53
int EdgeLabelsDone
Definition globals.h:64
Agsym_t * N_penwidth
Definition globals.h:80
char * Gvimagepath
Definition globals.h:49
Agsym_t * N_gradientangle
Definition globals.h:80
Agsym_t * E_fillcolor
Definition globals.h:82
Agsym_t * E_dir
Definition globals.h:84
Agsym_t * E_label
Definition globals.h:84
Agsym_t * N_skew
Definition globals.h:78
double PSinputscale
Definition globals.h:56
char * Gvfilepath
Definition globals.h:48
Agsym_t * E_minlen
Definition globals.h:82
Agsym_t * N_shape
Definition globals.h:74
Agsym_t * N_xlabel
Definition globals.h:76
int CL_type
Definition globals.h:58
Agsym_t * E_label_float
Definition globals.h:86
Agsym_t * N_nojustify
Definition globals.h:76
Agsym_t * E_color
Definition globals.h:82
Agsym_t * E_taillabel
Definition globals.h:88
bool Reduce
Definition globals.h:52
Agsym_t * N_label
Definition globals.h:76
Agsym_t * E_labelangle
Definition globals.h:90
Agsym_t * N_fillcolor
Definition globals.h:74
Agsym_t * E_fontsize
Definition globals.h:83
Agsym_t * E_arrowsz
Definition globals.h:85
Agsym_t * G_gradientangle
Definition globals.h:72
Agsym_t * N_vertices
Definition globals.h:79
Agsym_t * N_fixed
Definition globals.h:78
Agsym_t * N_peripheries
Definition globals.h:77
Agsym_t * E_labelfontname
Definition globals.h:89
Agsym_t * N_distortion
Definition globals.h:78
Agsym_t * N_imagepos
Definition globals.h:78
bool Y_invert
invert y in dot & plain output
Definition globals.h:67
Agsym_t * E_xlabel
Definition globals.h:84
Agsym_t * E_penwidth
Definition globals.h:92
Agsym_t * E_layer
Definition globals.h:85
Agsym_t * E_constr
Definition globals.h:85
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_color
Definition globals.h:74
Agsym_t * E_showboxes
Definition globals.h:85
Agsym_t * E_labeldistance
Definition globals.h:90
Agsym_t * N_ordering
Definition globals.h:77
Agsym_t * N_height
Definition globals.h:74
const char ** Lib
Definition globals.h:47
static bool Verbose
Definition gml2gv.c:23
void free(void *)
node NULL
Definition grammar.y:180
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:198
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:348
char * agget(void *obj, char *name)
Definition attr.c:462
#define agfindedgeattr(g, a)
Definition types.h:617
void agwarningf(const char *fmt,...)
Definition agerror.c:173
void agerrorf(const char *fmt,...)
Definition agerror.c:165
agerrlevel_t agseterr(agerrlevel_t lvl)
Definition agerror.c:38
@ AGMAX
Definition cgraph.h:957
@ AGERR
Definition cgraph.h:957
#define agfindgraphattr(g, a)
Definition types.h:613
#define GD_fontnames(g)
Definition types.h:402
#define GD_drawing(g)
Definition types.h:353
#define GD_border(g)
Definition types.h:359
#define GD_has_labels(g)
Definition types.h:368
int agisdirected(Agraph_t *g)
Definition graph.c:178
Agraph_t * agconcat(Agraph_t *g, const char *filename, void *chan, Agdisc_t *disc)
merges the file contents with a pre-existing graph
Definition grammar.c:2036
#define GD_label_pos(g)
Definition types.h:400
#define GD_showboxes(g)
Definition types.h:401
Agraph_t * agmemconcat(Agraph_t *g, const char *cp)
Definition io.c:95
#define GD_label(g)
Definition types.h:374
#define GD_nodesep(g)
Definition types.h:394
#define GD_charset(g)
Definition types.h:367
#define GD_flip(g)
Definition types.h:378
#define GD_exact_ranksep(g)
Definition types.h:363
#define GD_ranksep(g)
Definition types.h:397
#define agfindnodeattr(g, a)
Definition types.h:615
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 agclean(Agraph_t *g, int kind, char *rec_name)
calls agdelrec for all objects of the same class in an entire graph
Definition rec.c:202
int aghtmlstr(const char *)
Definition refstr.c:438
graph_t * gvNextInputGraph(GVC_t *gvc)
Definition input.c:500
graph_t * gvPluginsGraph(GVC_t *gvc)
Definition input.c:208
static GVC_t * gvc
Definition gv.cpp:23
replacements for ctype.h functions
static void gv_tolower_str(char *s)
Definition gv_ctype.h:87
FILE * gv_fopen(const char *filename, const char *mode)
Definition gv_fopen.c:32
wrapper around fopen for internal library usage
Arithmetic helper functions.
static bool is_exactly_zero(double v)
is a value precisely 0.0?
Definition gv_math.h:64
Graphviz context library.
void gvconfig(GVC_t *gvc, bool rescan)
Definition gvconfig.c:552
void gvjobs_output_filename(GVC_t *gvc, const char *name)
Definition gvjobs.c:44
bool gvjobs_output_langname(GVC_t *gvc, const char *name)
Definition gvjobs.c:63
int gvlayout_select(GVC_t *gvc, const char *str)
Definition gvlayout.c:31
Agraph_t * gvplugin_graph(GVC_t *gvc)
Definition gvplugin.c:487
char * gvplugin_list(GVC_t *gvc, api_t api, const char *str)
Definition gvplugin.c:359
agxbput(xb, staging)
textitem scanner parser str
Definition htmlparse.y:224
static char * configFlags
Definition input.c:67
static char * fdpItems
Definition input.c:59
static char * configItems
Definition input.c:68
static char * usageFmt
Definition input.c:32
static void use_library(GVC_t *gvc, const char *name)
Definition input.c:162
static char * fdpFlags
Definition input.c:57
static void setRatio(graph_t *g)
Checks "ratio" attribute, if any, and sets enum type.
Definition input.c:562
char * charsetToStr(int c)
Given an internal charset value, return a canonical string representation.
Definition input.c:800
int dotneato_usage(const char *argv0, int exval)
Definition input.c:78
static char * neatoFlags
Definition input.c:51
void graph_init(graph_t *g, bool use_rankdir)
Definition input.c:586
int dotneato_args_initialize(GVC_t *gvc, int argc, char **argv)
Definition input.c:218
static void global_def(char *dcl, int kind)
Definition input.c:174
static char * neatoItems
Definition input.c:53
static int gvg_init(GVC_t *gvc, graph_t *g, char *fn, int gidx)
Definition input.c:191
static unsigned char findCharset(graph_t *g)
Definition input.c:539
static char * dotneato_basename(char *pathname)
Definition input.c:129
void graph_cleanup(graph_t *g)
Definition input.c:784
void getdouble(graph_t *g, char *name, double *result)
Definition input.c:489
static char * genericItems
Definition input.c:35
void do_graph_label(graph_t *sg)
Set characteristics of graph label if it exists.
Definition input.c:823
static graph_t * P_graph
Definition input.c:206
static char * getFlagOpt(int argc, char **argv, int *idx)
Definition input.c:106
static bool getdoubles2ptf(graph_t *g, char *name, pointf *result)
Definition input.c:462
char * strdup_and_subst_obj(char *str, void *obj)
Definition labels.c:385
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 layout(graph_t *g, layout_info *infop)
Definition layout.c:814
#define PAD(d)
Definition macros.h:29
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
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:651
unsigned char fixed
Definition cgraph.h:657
char * cmdname
Definition gvcommon.h:21
bool auto_outfile_names
Definition gvcommon.h:23
const char ** lib
Definition gvcommon.h:26
char ** info
Definition gvcommon.h:20
bool config
Definition gvcommon.h:23
int verbose
Definition gvcommon.h:22
Definition gvcint.h:81
int fidx
Definition gvcint.h:89
GVG_t * gvgs
Definition gvcint.h:92
GVCOMMON_t common
Definition gvcint.h:82
GVG_t * gvg
Definition gvcint.h:93
GVJ_t * jobs
Definition gvcint.h:115
char ** input_filenames
Definition gvcint.h:88
Definition gvcint.h:70
char * input_filename
Definition gvcint.h:74
GVG_t * next
Definition gvcint.h:72
int graph_index
Definition gvcint.h:75
GVC_t * gvc
Definition gvcint.h:71
graph_t * g
Definition gvcint.h:76
const char * output_langname
Definition gvcjob.h:282
double x
Definition geom.h:29
double y
Definition geom.h:29
@ NATIVEFONTS
Definition types.h:274
@ PSFONTS
Definition types.h:274
@ SVGFONTS
Definition types.h:274
#define SET_RANKDIR(g, rd)
Definition types.h:607
@ R_AUTO
Definition types.h:216
@ R_COMPRESS
Definition types.h:216
@ R_VALUE
Definition types.h:216
@ R_FILL
Definition types.h:216
@ R_EXPAND
Definition types.h:216
Definition grammar.c:89
void freeXDot(xdot *x)
Definition xdot.c:760
parsing and deparsing of xdot operations