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