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