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