Graphviz 16.1.3~dev.20261128.0221
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/htmltable.h>
16#include <common/render.h>
17#include <errno.h>
18#include <gvc/gvc.h>
19#include <limits.h>
20#include <math.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#include <xdot/xdot.h>
34
35static char *usageFmt =
36 "Usage: %s [-Vv?] [-(GNEA)name=val] [-(KTlso)<val>] <dot files>\n";
37
38static char *genericItems = "\n\
39 -V - Print version and exit\n\
40 -v[n] - Enable verbose mode at level 1, or set to the level 'n' if provided\n\
41 -Gname=val - Set graph attribute 'name' to 'val'\n\
42 -Nname=val - Set node attribute 'name' to 'val'\n\
43 -Ename=val - Set edge attribute 'name' to 'val'\n\
44 -Aname=val - Set attribute 'name' to 'val' for graph, node, and edge\n\
45 -Tv - Set output format to 'v'\n\
46 -Kv - Set layout engine to 'v' (overrides default based on command name)\n\
47 -lv - Use external library 'v'\n\
48 -ofile - Write output to 'file'\n\
49 -O - Automatically generate an output filename based on the input filename with a .'format' appended. (Causes all -ofile options to be ignored.) \n\
50 -P - Internally generate a graph of the current plugins. \n\
51 -q[l] - Set level of message suppression (=1)\n\
52 -s[v] - Scale input by 'v' (=72)\n\
53 -y - Invert y coordinate in output\n";
54
55static char *neatoFlags = "(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 int i = *idx;
112 char *arg = argv[i];
113
114 if (arg[2])
115 return arg + 2;
116 if (i < argc - 1) {
117 i++;
118 arg = argv[i];
119 if (*arg && *arg != '-') {
120 *idx = i;
121 return arg;
122 }
123 }
124 return 0;
125}
126
127/* Partial implementation of real basename.
128 * Skip over any trailing slashes or backslashes; then
129 * find next (back)slash moving left; return string to the right.
130 * If no next slash is found, return the whole string.
131 */
132static char *dotneato_basename(char *pathname) {
133 char *ret;
134 char *s = pathname;
135 if (*s == '\0')
136 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"))
145 *dotp = '\0';
146 }
147#endif
148 while (*s)
149 s++;
150 s--;
151 /* skip over trailing slashes, nulling out as we go */
152 while (s > pathname && (*s == '/' || *s == '\\'))
153 *s-- = '\0';
154 if (s == pathname)
155 ret = pathname;
156 else {
157 while (s > pathname && *s != '/' && *s != '\\')
158 s--;
159 if (*s == '/' || *s == '\\')
160 ret = s + 1;
161 else
162 ret = pathname;
163 }
164#ifdef _WIN32
165 /* On Windows, names are case-insensitive, so make name lower-case
166 */
167 gv_tolower_str(ret);
168#endif
169 return ret;
170}
171
172static void use_library(GVC_t *gvc, const char *name) {
173 static size_t cnt = 0;
174 if (name) {
175 const size_t old_nmemb = cnt == 0 ? cnt : cnt + 1;
176 Lib = gv_recalloc(Lib, old_nmemb, cnt + 2, sizeof(const char *));
177 Lib[cnt++] = name;
178 Lib[cnt] = NULL;
179 }
180 gvc->common.lib = Lib;
181}
182
183static void global_def(char *dcl, int kind) {
184 char *p;
185 char *rhs = "true";
186 agxbuf xb = {0};
187
188 attrsym_t *sym;
189 if ((p = strchr(dcl, '='))) {
190 agxbput_n(&xb, dcl, (size_t)(p - dcl));
191 rhs = p + 1;
192 } else
193 agxbput(&xb, dcl);
194 sym = agattr_text(NULL, kind, agxbuse(&xb), rhs);
195 sym->fixed = 1;
196 agxbfree(&xb);
197}
198
199static int gvg_init(GVC_t *gvc, graph_t *g, char *fn, int gidx) {
200 GVG_t *gvg = gv_alloc(sizeof(GVG_t));
201 if (!gvc->gvgs)
202 gvc->gvgs = gvg;
203 else
204 gvc->gvg->next = gvg;
205 gvc->gvg = gvg;
206 gvg->gvc = gvc;
207 gvg->g = g;
208 gvg->input_filename = fn;
209 gvg->graph_index = gidx;
210 return 0;
211}
212
214
216 gvg_init(gvc, P_graph, "<internal>", 0);
217 return P_graph;
218}
219
220/* Scan argv[] for allowed flags.
221 * Return 0 on success; v+1 if calling function should call exit(v).
222 * If -c is set, config file is created and we exit.
223 */
224int dotneato_args_initialize(GVC_t *gvc, int argc, char **argv) {
225 char c;
226 bool Kflag = false;
227
228 /* establish if we are running in a CGI environment */
229 HTTPServerEnVar = getenv("SERVER_NAME");
230
231 // test `$GV_FILE_PATH`, a legacy knob, is not set
232 if (getenv("GV_FILE_PATH") != NULL) {
233 fprintf(stderr, "$GV_FILE_PATH environment variable set; exiting\n"
234 "\n"
235 "This sandboxing mechanism is no longer supported\n");
236 graphviz_exit(EXIT_FAILURE);
237 }
238
240 if (gvc->common.verbose) {
241 fprintf(stderr, "%s - %s version %s (%s)\n", gvc->common.cmdname,
242 gvc->common.info[0], 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", gvc->common.cmdname,
268 gvc->common.info[0], gvc->common.info[1], gvc->common.info[2]);
269 if (GvExitOnUsage)
270 graphviz_exit(0);
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 =
328 * "dot"? */
329 fprintf(stderr,
330 " No formats found.\nPerhaps \"dot -c\" needs to be run "
331 "(with installer's privileges) to register the plugins?\n");
332 }
333 if (GvExitOnUsage)
334 graphviz_exit(1);
335 return 2;
336 }
337 break;
338 }
339 case 'K': {
340 const char *const val = getFlagOpt(argc, argv, &i);
341 if (!val) {
342 fprintf(stderr, "Missing argument for -K flag\n");
343 return dotneato_usage(argv[0], 1);
344 }
345 const int v = gvlayout_select(gvc, val);
346 if (v == NO_SUPPORT) {
347 fprintf(stderr, "There is no layout engine support for \"%s\"\n",
348 val);
349 if (streq(val, "dot")) {
350 fprintf(stderr,
351 "Perhaps \"dot -c\" needs to be run (with installer's "
352 "privileges) to register the plugins?\n");
353 } else {
354 const char *const lyts = gvplugin_list(gvc, API_layout, val);
355 if (strlen(lyts) > 1) {
356 fprintf(stderr, " Use one of:%s\n", lyts);
357 } else {
358 /* Q: Should 'dot -c' be suggested generally or only when val =
359 * "dot"? */
360 fprintf(
361 stderr,
362 " No layouts found.\nPerhaps \"dot -c\" needs to be run "
363 "(with installer's privileges) to register the plugins?\n");
364 }
365 }
366 if (GvExitOnUsage)
367 graphviz_exit(1);
368 return 2;
369 }
370 Kflag = true;
371 break;
372 }
373 case 'P':
375 break;
376 case 'l': {
377 const char *const val = getFlagOpt(argc, argv, &i);
378 if (!val) {
379 fprintf(stderr, "Missing argument for -l flag\n");
380 return dotneato_usage(argv[0], 1);
381 }
382 use_library(gvc, val);
383 break;
384 }
385 case 'o': {
386 const char *const val = getFlagOpt(argc, argv, &i);
387 if (!val) {
388 fprintf(stderr, "Missing argument for -o flag\n");
389 return dotneato_usage(argv[0], 1);
390 }
393 break;
394 }
395 case 'q':
396 if (*rest) {
397 const int v = atoi(rest);
398 if (v <= 0) {
399 fprintf(stderr, "Invalid parameter \"%s\" for -q flag - ignored\n",
400 rest);
401 } else if (v == 1)
403 else
405 } else
407 break;
408 case 's':
409 if (*rest) {
410 PSinputscale = atof(rest);
411 if (PSinputscale < 0) {
412 fprintf(stderr, "Invalid parameter \"%s\" for -s flag\n", rest);
413 return dotneato_usage(argv[0], 1);
416 } else
418 break;
419 case 'x':
420 Reduce = true;
421 break;
422 case 'y':
423 Y_invert = true;
424 break;
425 default:
426 agerrorf("%s: option -%c unrecognized\n\n", gvc->common.cmdname, c);
427 return dotneato_usage(argv[0], 1);
428 }
429 } else if (argv[i])
430 gvc->input_filenames[nfiles++] = argv[i];
431 }
432
433 /* if no -K, use cmd name to set layout type */
434 if (!Kflag) {
435 const char *layout = gvc->common.cmdname;
436 if (streq(layout, "dot_static") || streq(layout, "dot_builtins") ||
437 streq(layout, "lt-dot") || streq(layout, "lt-dot_builtins") ||
438 streq(layout, "") /* when run as a process from Gvedit on Windows */
439 )
440 layout = "dot";
441 const int i = gvlayout_select(gvc, layout);
442 if (i == NO_SUPPORT) {
443 fprintf(stderr, "There is no layout engine support for \"%s\"\n", layout);
444 if (streq(layout, "dot")) {
445 fprintf(stderr, "Perhaps \"dot -c\" needs to be run (with installer's "
446 "privileges) to register the plugins?\n");
447 } else {
448 const char *const lyts = gvplugin_list(gvc, API_layout, "");
449 if (strlen(lyts) > 1) {
450 fprintf(stderr, " Use one of:%s\n", lyts);
451 } else {
452 /* Q: Should 'dot -c' be suggested generally or only when val = "dot"?
453 */
454 fprintf(stderr,
455 " No layouts found.\nPerhaps \"dot -c\" needs to be run "
456 "(with installer's privileges) to register the plugins?\n");
457 }
458 }
459
460 if (GvExitOnUsage)
461 graphviz_exit(1);
462 return 2;
463 }
464 }
465
466 /* if no -Txxx, then set default format */
467 if (!gvc->jobs || !gvc->jobs->output_langname) {
468 if (!gvjobs_output_langname(gvc, "dot")) {
469 fprintf(stderr, "Unable to find even the default \"-Tdot\" renderer. "
470 "Has the config\nfile been generated by running \"dot "
471 "-c\" with installer's privileges?\n");
472 return 2;
473 }
474 }
475
476 /* set persistent attributes here (if not already set from command line
477 * options) */
478 if (!agattr_text(NULL, AGNODE, "label", 0))
480 return 0;
481}
482
483/* converts a graph attribute in inches to a pointf in points.
484 * If only one number is given, it is used for both x and y.
485 * Returns true if the attribute ends in '!'.
486 */
487static bool getdoubles2ptf(graph_t *g, char *name, pointf *result) {
488 char *p;
489 int i;
490 double xf, yf;
491 char c = '\0';
492 bool rv = false;
493
494 if ((p = agget(g, name))) {
495 i = sscanf(p, "%lf,%lf%c", &xf, &yf, &c);
496 if (i > 1 && xf > 0 && yf > 0) {
497 result->x = round(INCH2PS(xf));
498 result->y = round(INCH2PS(yf));
499 if (c == '!')
500 rv = true;
501 } else {
502 c = '\0';
503 i = sscanf(p, "%lf%c", &xf, &c);
504 if (i > 0 && xf > 0) {
505 result->y = result->x = round(INCH2PS(xf));
506 if (c == '!')
507 rv = true;
508 }
509 }
510 }
511 return rv;
512}
513
514void getdouble(graph_t *g, char *name, double *result) {
515 char *p;
516 double f;
517
518 if ((p = agget(g, name))) {
519 if (sscanf(p, "%lf", &f) >= 1)
520 *result = f;
521 }
522}
523
525 graph_t *g = NULL;
526 static char *fn;
527 static FILE *fp;
528 static int gidx;
529
530 while (!g) {
531 if (!fp) {
532 if (!(fn = gvc->input_filenames[0])) {
533 if (gvc->fidx++ == 0)
534 fp = stdin;
535 } else {
536 while ((fn = gvc->input_filenames[gvc->fidx++]) &&
537 !(fp = gv_fopen(fn, "r"))) {
538 agerrorf("%s: can't open %s: %s\n", gvc->common.cmdname, fn,
539 strerror(errno));
541 }
542 }
543 }
544 if (fp == NULL)
545 break;
546 g = agconcat(NULL, fn ? fn : "<stdin>", fp, NULL);
547 if (g) {
548 gvg_init(gvc, g, fn, gidx++);
549 break;
550 }
551 if (fp != stdin)
552 fclose(fp);
553 fp = NULL;
554 gidx = 0;
555 }
556 return g;
557}
558
559/* Check if the charset attribute is defined for the graph and, if
560 * so, return the corresponding internal value. If undefined, return
561 * CHAR_UTF8
562 */
563static unsigned char findCharset(graph_t *g) {
564 char *p;
565
566 p = late_nnstring(g, agfindgraphattr(g, "charset"), "utf-8");
567 if (!strcasecmp(p, "latin-1") || !strcasecmp(p, "latin1") ||
568 !strcasecmp(p, "l1") || !strcasecmp(p, "ISO-8859-1") ||
569 !strcasecmp(p, "ISO_8859-1") || !strcasecmp(p, "ISO8859-1") ||
570 !strcasecmp(p, "ISO-IR-100"))
571 return CHAR_LATIN1;
572 if (!strcasecmp(p, "big-5") || !strcasecmp(p, "big5"))
573 return CHAR_BIG5;
574 if (!strcasecmp(p, "utf-8") || !strcasecmp(p, "utf8"))
575 return CHAR_UTF8;
576 agwarningf("Unsupported charset \"%s\" - assuming utf-8\n", p);
577 return CHAR_UTF8;
578}
579
581static void setRatio(graph_t *g) {
582 char *p;
583 double ratio;
584
585 if ((p = agget(g, "ratio"))) {
586 if (streq(p, "auto")) {
587 GD_drawing(g)->ratio_kind = R_AUTO;
588 } else if (streq(p, "compress")) {
589 GD_drawing(g)->ratio_kind = R_COMPRESS;
590 } else if (streq(p, "expand")) {
591 GD_drawing(g)->ratio_kind = R_EXPAND;
592 } else if (streq(p, "fill")) {
593 GD_drawing(g)->ratio_kind = R_FILL;
594 } else {
595 ratio = atof(p);
596 if (ratio > 0.0) {
597 GD_drawing(g)->ratio_kind = R_VALUE;
598 GD_drawing(g)->ratio = ratio;
599 }
600 }
601 }
602}
603
604void graph_init(graph_t *g, bool use_rankdir) {
605 char *p;
606 double xf;
607 static char *rankname[] = {"local", "global", "none", NULL};
608 static int rankcode[] = {LOCAL, GLOBAL, NOCLUST, LOCAL};
609 static char *fontnamenames[] = {"gd", "ps", "svg", NULL};
610 static int fontnamecodes[] = {NATIVEFONTS, PSFONTS, SVGFONTS, -1};
611 int rankdir;
612 GD_drawing(g) = gv_alloc(sizeof(layout_t));
613
614 /* set this up fairly early in case any string sizes are needed */
615 if ((p = agget(g, "fontpath")) || (p = getenv("DOTFONTPATH"))) {
616 /* overide GDFONTPATH in local environment if dot
617 * wants its own */
618#ifdef HAVE_SETENV
619 setenv("GDFONTPATH", p, 1);
620#else
621 static agxbuf buf;
622 agxbprint(&buf, "GDFONTPATH=%s", p);
623 putenv(agxbuse(&buf));
624#endif
625 }
626
627 GD_charset(g) = findCharset(g);
628
629 if (!HTTPServerEnVar) {
630 Gvimagepath = agget(g, "imagepath");
631 if (!Gvimagepath) {
633 }
634 }
635
636 GD_drawing(g)->quantum =
637 late_double(g, agfindgraphattr(g, "quantum"), 0.0, 0.0);
638
639 /* setting rankdir=LR is only defined in dot,
640 * but having it set causes shape code and others to use it.
641 * The result is confused output, so we turn it off unless requested.
642 * This effective rankdir is stored in the bottom 2 bits of g->u.rankdir.
643 * Sometimes, the code really needs the graph's rankdir, e.g., neato -n
644 * with record shapes, so we store the real rankdir in the next 2 bits.
645 */
646 rankdir = RANKDIR_TB;
647 if ((p = agget(g, "rankdir"))) {
648 if (streq(p, "LR"))
649 rankdir = RANKDIR_LR;
650 else if (streq(p, "BT"))
651 rankdir = RANKDIR_BT;
652 else if (streq(p, "RL"))
653 rankdir = RANKDIR_RL;
654 }
655 if (use_rankdir)
656 SET_RANKDIR(g, (rankdir << 2) | rankdir);
657 else
658 SET_RANKDIR(g, rankdir << 2);
659
660 xf = late_double(g, agfindgraphattr(g, "nodesep"), DEFAULT_NODESEP,
662 GD_nodesep(g) = d2i(round(INCH2PS(xf)));
663
664 p = late_string(g, agfindgraphattr(g, "ranksep"), NULL);
665 if (p) {
666 if (sscanf(p, "%lf", &xf) == 0)
667 xf = DEFAULT_RANKSEP;
668 else {
669 if (xf < MIN_RANKSEP)
670 xf = MIN_RANKSEP;
671 }
672 if (strstr(p, "equally"))
673 GD_exact_ranksep(g) = true;
674 } else
675 xf = DEFAULT_RANKSEP;
676 GD_ranksep(g) = d2i(round(INCH2PS(xf)));
677
678 {
679 int showboxes = late_int(g, agfindgraphattr(g, "showboxes"), 0, 0);
680 if (showboxes > UCHAR_MAX) {
681 showboxes = UCHAR_MAX;
682 }
683 GD_showboxes(g) = (unsigned char)showboxes;
684 }
685 p = late_string(g, agfindgraphattr(g, "fontnames"), NULL);
686 GD_fontnames(g) = maptoken(p, fontnamenames, fontnamecodes);
687
688 setRatio(g);
689 GD_drawing(g)->filled = getdoubles2ptf(g, "size", &GD_drawing(g)->size);
690 getdoubles2ptf(g, "page", &GD_drawing(g)->page);
691
692 GD_drawing(g)->centered = mapbool(agget(g, "center"));
693
694 if ((p = agget(g, "rotate")))
695 GD_drawing(g)->landscape = atoi(p) == 90;
696 else if ((p = agget(g, "orientation")))
697 GD_drawing(g)->landscape = p[0] == 'l' || p[0] == 'L';
698 else if ((p = agget(g, "landscape")))
699 GD_drawing(g)->landscape = mapbool(p);
700
701 p = agget(g, "clusterrank");
702 CL_type = maptoken(p, rankname, rankcode);
703 p = agget(g, "concentrate");
704 Concentrate = mapbool(p);
705 State = GVBEGIN;
706 EdgeLabelsDone = 0;
707
708 GD_drawing(g)->dpi =
709 late_double(g, agfindgraphattr(g, "dpi"),
710 late_double(g, agfindgraphattr(g, "resolution"), 0, 0), 0);
711
713
715
716 G_ordering = agfindgraphattr(g, "ordering");
717 G_gradientangle = agfindgraphattr(g, "gradientangle");
718 G_margin = agfindgraphattr(g, "margin");
719
720 /* initialize nodes */
721 N_height = agfindnodeattr(g, "height");
722 N_width = agfindnodeattr(g, "width");
723 N_shape = agfindnodeattr(g, "shape");
724 N_color = agfindnodeattr(g, "color");
725 N_fillcolor = agfindnodeattr(g, "fillcolor");
726 N_style = agfindnodeattr(g, "style");
727 N_fontsize = agfindnodeattr(g, "fontsize");
728 N_fontname = agfindnodeattr(g, "fontname");
729 N_fontcolor = agfindnodeattr(g, "fontcolor");
730 N_label = agfindnodeattr(g, "label");
731 if (!N_label)
732 N_label = agattr_text(g, AGNODE, "label", NODENAME_ESC);
733 N_xlabel = agfindnodeattr(g, "xlabel");
734 N_showboxes = agfindnodeattr(g, "showboxes");
735 N_penwidth = agfindnodeattr(g, "penwidth");
736 N_ordering = agfindnodeattr(g, "ordering");
737 /* attribs for polygon shapes */
738 N_sides = agfindnodeattr(g, "sides");
739 N_peripheries = agfindnodeattr(g, "peripheries");
740 N_skew = agfindnodeattr(g, "skew");
741 N_orientation = agfindnodeattr(g, "orientation");
742 N_distortion = agfindnodeattr(g, "distortion");
743 N_fixed = agfindnodeattr(g, "fixedsize");
744 N_imagescale = agfindnodeattr(g, "imagescale");
745 N_imagepos = agfindnodeattr(g, "imagepos");
746 N_nojustify = agfindnodeattr(g, "nojustify");
747 N_layer = agfindnodeattr(g, "layer");
748 N_group = agfindnodeattr(g, "group");
749 N_comment = agfindnodeattr(g, "comment");
750 N_vertices = agfindnodeattr(g, "vertices");
751 N_z = agfindnodeattr(g, "z");
752 N_gradientangle = agfindnodeattr(g, "gradientangle");
753
754 /* initialize edges */
755 E_weight = agfindedgeattr(g, "weight");
756 E_color = agfindedgeattr(g, "color");
757 E_fillcolor = agfindedgeattr(g, "fillcolor");
758 E_fontsize = agfindedgeattr(g, "fontsize");
759 E_fontname = agfindedgeattr(g, "fontname");
760 E_fontcolor = agfindedgeattr(g, "fontcolor");
761 E_label = agfindedgeattr(g, "label");
762 E_xlabel = agfindedgeattr(g, "xlabel");
763 E_label_float = agfindedgeattr(g, "labelfloat");
764 E_dir = agfindedgeattr(g, "dir");
765 E_headlabel = agfindedgeattr(g, "headlabel");
766 E_taillabel = agfindedgeattr(g, "taillabel");
767 E_labelfontsize = agfindedgeattr(g, "labelfontsize");
768 E_labelfontname = agfindedgeattr(g, "labelfontname");
769 E_labelfontcolor = agfindedgeattr(g, "labelfontcolor");
770 E_labeldistance = agfindedgeattr(g, "labeldistance");
771 E_labelangle = agfindedgeattr(g, "labelangle");
772 E_minlen = agfindedgeattr(g, "minlen");
773 E_showboxes = agfindedgeattr(g, "showboxes");
774 E_style = agfindedgeattr(g, "style");
775 E_decorate = agfindedgeattr(g, "decorate");
776 E_arrowsz = agfindedgeattr(g, "arrowsize");
777 E_constr = agfindedgeattr(g, "constraint");
778 E_layer = agfindedgeattr(g, "layer");
779 E_comment = agfindedgeattr(g, "comment");
780 E_tailclip = agfindedgeattr(g, "tailclip");
781 E_headclip = agfindedgeattr(g, "headclip");
782 E_penwidth = agfindedgeattr(g, "penwidth");
783
784 /* background */
785 GD_drawing(g)->xdots = init_xdot(g);
786
787 /* initialize id, if any */
788 if ((p = agget(g, "id")) && *p)
789 GD_drawing(g)->id = strdup_and_subst_obj(p, g);
790}
791
793 if (GD_drawing(g) && GD_drawing(g)->xdots)
794 freeXDot(GD_drawing(g)->xdots);
795 if (GD_drawing(g))
796 free(GD_drawing(g)->id);
797 free(GD_drawing(g));
798 GD_drawing(g) = NULL;
800 // FIX HERE , STILL SHALLOW
801 // memset(&(g->u), 0, sizeof(Agraphinfo_t));
802 agclean(g, AGRAPH, "Agraphinfo_t");
803}
804
806char *charsetToStr(int c) {
807 char *s;
808
809 switch (c) {
810 case CHAR_UTF8:
811 s = "UTF-8";
812 break;
813 case CHAR_LATIN1:
814 s = "ISO-8859-1";
815 break;
816 case CHAR_BIG5:
817 s = "BIG-5";
818 break;
819 default:
820 agerrorf("Unsupported charset value %d\n", c);
821 s = "UTF-8";
822 break;
823 }
824 return s;
825}
826
829 char *str, *pos;
830 int pos_ix;
831
832 /* it would be nice to allow multiple graph labels in the future */
833 if ((str = agget(sg, "label")) && *str != '\0') {
834 char pos_flag;
835 pointf dimen;
836
838
839 GD_label(sg) = make_label(
840 sg, str, aghtmlstr(str), false,
841 late_double(sg, agfindgraphattr(sg, "fontsize"), DEFAULT_FONTSIZE,
843 late_nnstring(sg, agfindgraphattr(sg, "fontname"), DEFAULT_FONTNAME),
844 late_nnstring(sg, agfindgraphattr(sg, "fontcolor"), DEFAULT_COLOR));
845
846 /* set label position */
847 pos = agget(sg, "labelloc");
848 if (sg != agroot(sg)) {
849 if (pos && pos[0] == 'b')
850 pos_flag = LABEL_AT_BOTTOM;
851 else
852 pos_flag = LABEL_AT_TOP;
853 } else {
854 if (pos && pos[0] == 't')
855 pos_flag = LABEL_AT_TOP;
856 else
857 pos_flag = LABEL_AT_BOTTOM;
858 }
859 const char *const just = agget(sg, "labeljust");
860 if (just) {
861 if (just[0] == 'l')
862 pos_flag |= LABEL_AT_LEFT;
863 else if (just[0] == 'r')
864 pos_flag |= LABEL_AT_RIGHT;
865 }
866 GD_label_pos(sg) = pos_flag;
867
868 if (sg == agroot(sg))
869 return;
870
871 /* Set border information for cluster labels to allow space
872 */
873 dimen = GD_label(sg)->dimen;
874 PAD(dimen);
875 if (!GD_flip(agroot(sg))) {
876 if (GD_label_pos(sg) & LABEL_AT_TOP)
877 pos_ix = TOP_IX;
878 else
879 pos_ix = BOTTOM_IX;
880 GD_border(sg)[pos_ix] = dimen;
881 } else {
882 /* when rotated, the labels will be restored to TOP or BOTTOM */
883 if (GD_label_pos(sg) & LABEL_AT_TOP)
884 pos_ix = RIGHT_IX;
885 else
886 pos_ix = LEFT_IX;
887 GD_border(sg)[pos_ix].x = dimen.y;
888 GD_border(sg)[pos_ix].y = dimen.x;
889 }
890 }
891}
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:92
bool mapbool(const char *p)
Definition utils.c:321
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:86
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:39
int maptoken(char *p, char **name, int *val)
Definition utils.c:295
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:54
#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:71
static NORETURN void graphviz_exit(int status)
Definition exit.h:23
#define POINTS_PER_INCH
Definition geom.h:58
#define INCH2PS(a_inches)
Definition geom.h:63
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:204
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:951
@ AGERR
Definition cgraph.h:951
#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
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
#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:524
graph_t * gvPluginsGraph(GVC_t *gvc)
Definition input.c:215
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 int d2i(double v)
Definition gv_math.h:153
static bool is_exactly_pos_zero(double v)
is a value precisely +0.0?
Definition gv_math.h:66
Graphviz context library.
void gvconfig(GVC_t *gvc, bool rescan)
Definition gvconfig.c:535
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:358
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:35
static void use_library(GVC_t *gvc, const char *name)
Definition input.c:172
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:581
char * charsetToStr(int c)
Given an internal charset value, return a canonical string representation.
Definition input.c:806
int dotneato_usage(const char *argv0, int exval)
Definition input.c:82
static char * neatoFlags
Definition input.c:55
void graph_init(graph_t *g, bool use_rankdir)
Definition input.c:604
int dotneato_args_initialize(GVC_t *gvc, int argc, char **argv)
Definition input.c:224
static void global_def(char *dcl, int kind)
Definition input.c:183
static char * neatoItems
Definition input.c:56
static int gvg_init(GVC_t *gvc, graph_t *g, char *fn, int gidx)
Definition input.c:199
static unsigned char findCharset(graph_t *g)
Definition input.c:563
static char * dotneato_basename(char *pathname)
Definition input.c:132
void graph_cleanup(graph_t *g)
Definition input.c:792
void getdouble(graph_t *g, char *name, double *result)
Definition input.c:514
static char * genericItems
Definition input.c:38
void do_graph_label(graph_t *sg)
Set characteristics of graph label if it exists.
Definition input.c:828
static graph_t * P_graph
Definition input.c:213
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:487
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:782
#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:641
unsigned char fixed
Definition cgraph.h:647
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:773
parsing and deparsing of xdot operations