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