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