Graphviz  2.39.20150424.0445
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 (!val) {
348  fprintf(stderr, "Missing argument for -o flag\n");
349  return (dotneato_usage(1));
350  }
351  if (! gvc->common.auto_outfile_names)
352  gvjobs_output_filename(gvc, val);
353  break;
354  case 'q':
355  if (*rest) {
356  v = atoi(rest);
357  if (v <= 0) {
358  fprintf(stderr,
359  "Invalid parameter \"%s\" for -q flag - ignored\n",
360  rest);
361  } else if (v == 1)
362  agseterr(AGERR);
363  else
364  agseterr(AGMAX);
365  } else
366  agseterr(AGERR);
367  break;
368  case 's':
369  if (*rest) {
370  PSinputscale = atof(rest);
371  if (PSinputscale < 0) {
372  fprintf(stderr,
373  "Invalid parameter \"%s\" for -s flag\n",
374  rest);
375  return (dotneato_usage(1));
376  }
377  else if (PSinputscale == 0)
378  PSinputscale = POINTS_PER_INCH;
379  } else
380  PSinputscale = POINTS_PER_INCH;
381  break;
382  case 'x':
383  Reduce = TRUE;
384  break;
385  case 'y':
386  Y_invert = TRUE;
387  break;
388  case '?':
389  return (dotneato_usage(0));
390  break;
391  default:
392  agerr(AGERR, "%s: option -%c unrecognized\n\n", gvc->common.cmdname,
393  c);
394  return (dotneato_usage(1));
395  }
396  } else if (argv[i])
397  gvc->input_filenames[nfiles++] = argv[i];
398  }
399  agxbfree (&xb);
400 
401  /* if no -K, use cmd name to set layout type */
402  if (!Kflag) {
403  layout = gvc->common.cmdname;
404  if (streq(layout, "dot_static")
405  || streq(layout, "dot_builtins")
406  || streq(layout, "lt-dot")
407  || streq(layout, "lt-dot_builtins")
408  || streq(layout, "") /* when run as a process from Gvedit on Windows */
409  )
410  layout = "dot";
411  i = gvlayout_select(gvc, layout);
412  if (i == NO_SUPPORT) {
413  fprintf(stderr, "There is no layout engine support for \"%s\"\n", layout);
414  if (streq(layout, "dot"))
415  fprintf(stderr, "Perhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
416  else
417  fprintf(stderr, "Use one of:%s\n", gvplugin_list(gvc, API_layout, ""));
418 
419  if (GvExitOnUsage) exit(1);
420  return(2);
421  }
422  }
423 
424  /* if no -Txxx, then set default format */
425  if (!gvc->jobs || !gvc->jobs->output_langname) {
426  v = gvjobs_output_langname(gvc, "dot");
427  if (!v) {
428 // assert(v); /* "dot" should always be available as an output format */
429  fprintf(stderr,
430  "Unable to find even the default \"-Tdot\" renderer. Has the config\nfile been generated by running \"dot -c\" with installer's priviledges?\n");
431  return(2);
432  }
433  }
434 
435  /* set persistent attributes here (if not already set from command line options) */
436  if (!agattr(NULL, AGNODE, "label", 0))
437  agattr(NULL, AGNODE, "label", NODENAME_ESC);
438  return 0;
439 }
440 
441 /* getdoubles2ptf:
442  * converts a graph attribute in inches to a pointf in points.
443  * If only one number is given, it is used for both x and y.
444  * Returns true if the attribute ends in '!'.
445  */
446 static boolean getdoubles2ptf(graph_t * g, char *name, pointf * result)
447 {
448  char *p;
449  int i;
450  double xf, yf;
451  char c = '\0';
452  boolean rv = FALSE;
453 
454  if ((p = agget(g, name))) {
455  i = sscanf(p, "%lf,%lf%c", &xf, &yf, &c);
456  if ((i > 1) && (xf > 0) && (yf > 0)) {
457  result->x = POINTS(xf);
458  result->y = POINTS(yf);
459  if (c == '!')
460  rv = TRUE;
461  }
462  else {
463  c = '\0';
464  i = sscanf(p, "%lf%c", &xf, &c);
465  if ((i > 0) && (xf > 0)) {
466  result->y = result->x = POINTS(xf);
467  if (c == '!') rv = TRUE;
468  }
469  }
470  }
471  return rv;
472 }
473 
474 void getdouble(graph_t * g, char *name, double *result)
475 {
476  char *p;
477  double f;
478 
479  if ((p = agget(g, name))) {
480  if (sscanf(p, "%lf", &f) >= 1)
481  *result = f;
482  }
483 }
484 
485 #ifdef EXPERIMENTAL_MYFGETS
486 /*
487  * Potential input filter - e.g. for iconv
488  */
489 
490 /*
491  * myfgets - same api as fgets
492  *
493  * gets n chars at a time
494  *
495  * returns pointer to user buffer,
496  * or returns NULL on eof or error.
497  */
498 static char *myfgets(char * ubuf, int n, FILE * fp)
499 {
500  static char *buf;
501  static int bufsz, pos, len;
502  int cnt;
503 
504  if (!n) { /* a call with n==0 (from aglexinit) resets */
505  ubuf[0] = '\0';
506  pos = len = 0;
507  return NULL;
508  }
509 
510  if (!len) {
511  if (n > bufsz) {
512  bufsz = n;
513  buf = realloc(buf, bufsz);
514  }
515  if (!(fgets(buf, bufsz, fp))) {
516  ubuf[0] = '\0';
517  return NULL;
518  }
519  len = strlen(buf);
520  pos = 0;
521  }
522 
523  cnt = n - 1;
524  if (len < cnt)
525  cnt = len;
526 
527  memcpy(ubuf, buf + pos, cnt);
528  pos += cnt;
529  len -= cnt;
530  ubuf[cnt] = '\0';
531 
532  return ubuf;
533 }
534 #endif
535 
537 {
538  graph_t *g = NULL;
539  static char *fn;
540  static FILE *fp;
541  static FILE *oldfp;
542  static int fidx, gidx;
543 
544  while (!g) {
545  if (!fp) {
546  if (!(fn = gvc->input_filenames[0])) {
547  if (fidx++ == 0)
548  fp = stdin;
549  }
550  else {
551  while ((fn = gvc->input_filenames[fidx++]) && !(fp = fopen(fn, "r"))) {
552  agerr(AGERR, "%s: can't open %s\n", gvc->common.cmdname, fn);
553  graphviz_errors++;
554  }
555  }
556  }
557  if (fp == NULL)
558  break;
559  if (oldfp != fp) {
560  agsetfile(fn ? fn : "<stdin>");
561  oldfp = fp;
562  }
563 #ifdef EXPERIMENTAL_MYFGETS
564  g = agread_usergets(fp, myfgets);
565 #else
566  g = agread(fp,NIL(Agdisc_t*));
567 #endif
568  if (g) {
569  gvg_init(gvc, g, fn, gidx++);
570  break;
571  }
572  if (fp != stdin)
573  fclose (fp);
574  fp = NULL;
575  gidx = 0;
576  }
577  return g;
578 }
579 
580 /* findCharset:
581  * Check if the charset attribute is defined for the graph and, if
582  * so, return the corresponding internal value. If undefined, return
583  * CHAR_UTF8
584  */
585 static int findCharset (graph_t * g)
586 {
587  int enc;
588  char* p;
589 
590  p = late_nnstring(g,agfindgraphattr(g,"charset"),"utf-8");
591  if (!strcasecmp(p,"latin-1")
592  || !strcasecmp(p,"latin1")
593  || !strcasecmp(p,"l1")
594  || !strcasecmp(p,"ISO-8859-1")
595  || !strcasecmp(p,"ISO_8859-1")
596  || !strcasecmp(p,"ISO8859-1")
597  || !strcasecmp(p,"ISO-IR-100"))
598  enc = CHAR_LATIN1;
599  else if (!strcasecmp(p,"big-5")
600  || !strcasecmp(p,"big5"))
601  enc = CHAR_BIG5;
602  else if (!strcasecmp(p,"utf-8")
603  || !strcasecmp(p,"utf8"))
604  enc = CHAR_UTF8;
605  else {
606  agerr(AGWARN, "Unsupported charset \"%s\" - assuming utf-8\n", p);
607  enc = CHAR_UTF8;
608  }
609  return enc;
610 }
611 
612 /* setRatio:
613  * Checks "ratio" attribute, if any, and sets enum type.
614  */
615 static void setRatio(graph_t * g)
616 {
617  char *p, c;
618  double ratio;
619 
620  if ((p = agget(g, "ratio")) && ((c = p[0]))) {
621  switch (c) {
622  case 'a':
623  if (streq(p, "auto"))
624  GD_drawing(g)->ratio_kind = R_AUTO;
625  break;
626  case 'c':
627  if (streq(p, "compress"))
628  GD_drawing(g)->ratio_kind = R_COMPRESS;
629  break;
630  case 'e':
631  if (streq(p, "expand"))
632  GD_drawing(g)->ratio_kind = R_EXPAND;
633  break;
634  case 'f':
635  if (streq(p, "fill"))
636  GD_drawing(g)->ratio_kind = R_FILL;
637  break;
638  default:
639  ratio = atof(p);
640  if (ratio > 0.0) {
641  GD_drawing(g)->ratio_kind = R_VALUE;
642  GD_drawing(g)->ratio = ratio;
643  }
644  break;
645  }
646  }
647 }
648 
649 /*
650  cgraph requires
651 
652 */
653 void graph_init(graph_t * g, boolean use_rankdir)
654 {
655  char *p;
656  double xf;
657  static char *rankname[] = { "local", "global", "none", NULL };
658  static int rankcode[] = { LOCAL, GLOBAL, NOCLUST, LOCAL };
659  static char *fontnamenames[] = {"gd","ps","svg", NULL};
660  static int fontnamecodes[] = {NATIVEFONTS,PSFONTS,SVGFONTS,-1};
661  int rankdir;
662  GD_drawing(g) = NEW(layout_t);
663 
664  /* set this up fairly early in case any string sizes are needed */
665  if ((p = agget(g, "fontpath")) || (p = getenv("DOTFONTPATH"))) {
666  /* overide GDFONTPATH in local environment if dot
667  * wants its own */
668 #ifdef HAVE_SETENV
669  setenv("GDFONTPATH", p, 1);
670 #else
671  static char *buf = 0;
672 
673  buf = grealloc(buf, strlen("GDFONTPATH=") + strlen(p) + 1);
674  strcpy(buf, "GDFONTPATH=");
675  strcat(buf, p);
676  putenv(buf);
677 #endif
678  }
679 
680  GD_charset(g) = findCharset (g);
681 
682  if (!HTTPServerEnVar) {
683  Gvimagepath = agget (g, "imagepath");
684  if (!Gvimagepath)
686  }
687 
688  GD_drawing(g)->quantum =
689  late_double(g, agfindgraphattr(g, "quantum"), 0.0, 0.0);
690 
691  /* setting rankdir=LR is only defined in dot,
692  * but having it set causes shape code and others to use it.
693  * The result is confused output, so we turn it off unless requested.
694  * This effective rankdir is stored in the bottom 2 bits of g->u.rankdir.
695  * Sometimes, the code really needs the graph's rankdir, e.g., neato -n
696  * with record shapes, so we store the real rankdir in the next 2 bits.
697  */
698  rankdir = RANKDIR_TB;
699  if ((p = agget(g, "rankdir"))) {
700  if (streq(p, "LR"))
701  rankdir = RANKDIR_LR;
702  else if (streq(p, "BT"))
703  rankdir = RANKDIR_BT;
704  else if (streq(p, "RL"))
705  rankdir = RANKDIR_RL;
706  }
707  if (use_rankdir)
708  SET_RANKDIR (g, (rankdir << 2) | rankdir);
709  else
710  SET_RANKDIR (g, (rankdir << 2));
711 
712  xf = late_double(g, agfindgraphattr(g, "nodesep"),
714  GD_nodesep(g) = POINTS(xf);
715 
716  p = late_string(g, agfindgraphattr(g, "ranksep"), NULL);
717  if (p) {
718  if (sscanf(p, "%lf", &xf) == 0)
719  xf = DEFAULT_RANKSEP;
720  else {
721  if (xf < MIN_RANKSEP)
722  xf = MIN_RANKSEP;
723  }
724  if (strstr(p, "equally"))
725  GD_exact_ranksep(g) = TRUE;
726  } else
727  xf = DEFAULT_RANKSEP;
728  GD_ranksep(g) = POINTS(xf);
729 
730  GD_showboxes(g) = late_int(g, agfindgraphattr(g, "showboxes"), 0, 0);
731  p = late_string(g, agfindgraphattr(g, "fontnames"), NULL);
732  GD_fontnames(g) = maptoken(p, fontnamenames, fontnamecodes);
733 
734  setRatio(g);
735  GD_drawing(g)->filled =
736  getdoubles2ptf(g, "size", &(GD_drawing(g)->size));
737  getdoubles2ptf(g, "page", &(GD_drawing(g)->page));
738 
739  GD_drawing(g)->centered = mapbool(agget(g, "center"));
740 
741  if ((p = agget(g, "rotate")))
742  GD_drawing(g)->landscape = (atoi(p) == 90);
743  else if ((p = agget(g, "orientation")))
744  GD_drawing(g)->landscape = ((p[0] == 'l') || (p[0] == 'L'));
745  else if ((p = agget(g, "landscape")))
746  GD_drawing(g)->landscape = mapbool(p);
747 
748  p = agget(g, "clusterrank");
749  CL_type = maptoken(p, rankname, rankcode);
750  p = agget(g, "concentrate");
751  Concentrate = mapbool(p);
752  State = GVBEGIN;
753  EdgeLabelsDone = 0;
754 
755  GD_drawing(g)->dpi = 0.0;
756  if (((p = agget(g, "dpi")) && p[0])
757  || ((p = agget(g, "resolution")) && p[0]))
758  GD_drawing(g)->dpi = atof(p);
759 
760  do_graph_label(g);
761 
763 
764  G_ordering = agfindgraphattr(g, "ordering");
765  G_gradientangle = agfindgraphattr(g,"gradientangle");
766  G_margin = agfindgraphattr(g, "margin");
767 
768  /* initialize nodes */
769  N_height = agfindnodeattr(g, "height");
770  N_width = agfindnodeattr(g, "width");
771  N_shape = agfindnodeattr(g, "shape");
772  N_color = agfindnodeattr(g, "color");
773  N_fillcolor = agfindnodeattr(g, "fillcolor");
774  N_style = agfindnodeattr(g, "style");
775  N_fontsize = agfindnodeattr(g, "fontsize");
776  N_fontname = agfindnodeattr(g, "fontname");
777  N_fontcolor = agfindnodeattr(g, "fontcolor");
778  N_label = agfindnodeattr(g, "label");
779  if (!N_label)
780  N_label = agattr(g, AGNODE, "label", NODENAME_ESC);
781  N_xlabel = agfindnodeattr(g, "xlabel");
782  N_showboxes = agfindnodeattr(g, "showboxes");
783  N_penwidth = agfindnodeattr(g, "penwidth");
784  N_ordering = agfindnodeattr(g, "ordering");
785  N_margin = agfindnodeattr(g, "margin");
786  /* attribs for polygon shapes */
787  N_sides = agfindnodeattr(g, "sides");
788  N_peripheries = agfindnodeattr(g, "peripheries");
789  N_skew = agfindnodeattr(g, "skew");
790  N_orientation = agfindnodeattr(g, "orientation");
791  N_distortion = agfindnodeattr(g, "distortion");
792  N_fixed = agfindnodeattr(g, "fixedsize");
793  N_imagescale = agfindnodeattr(g, "imagescale");
794  N_nojustify = agfindnodeattr(g, "nojustify");
795  N_layer = agfindnodeattr(g, "layer");
796  N_group = agfindnodeattr(g, "group");
797  N_comment = agfindnodeattr(g, "comment");
798  N_vertices = agfindnodeattr(g, "vertices");
799  N_z = agfindnodeattr(g, "z");
800  N_gradientangle = agfindnodeattr(g,"gradientangle");
801 
802  /* initialize edges */
803  E_weight = agfindedgeattr(g, "weight");
804  E_color = agfindedgeattr(g, "color");
805  E_fillcolor = agfindedgeattr(g, "fillcolor");
806  E_fontsize = agfindedgeattr(g, "fontsize");
807  E_fontname = agfindedgeattr(g, "fontname");
808  E_fontcolor = agfindedgeattr(g, "fontcolor");
809  E_label = agfindedgeattr(g, "label");
810  E_xlabel = agfindedgeattr(g, "xlabel");
811  E_label_float = agfindedgeattr(g, "labelfloat");
812  /* vladimir */
813  E_dir = agfindedgeattr(g, "dir");
814  E_arrowhead = agfindedgeattr(g, "arrowhead");
815  E_arrowtail = agfindedgeattr(g, "arrowtail");
816  E_headlabel = agfindedgeattr(g, "headlabel");
817  E_taillabel = agfindedgeattr(g, "taillabel");
818  E_labelfontsize = agfindedgeattr(g, "labelfontsize");
819  E_labelfontname = agfindedgeattr(g, "labelfontname");
820  E_labelfontcolor = agfindedgeattr(g, "labelfontcolor");
821  E_labeldistance = agfindedgeattr(g, "labeldistance");
822  E_labelangle = agfindedgeattr(g, "labelangle");
823  /* end vladimir */
824  E_minlen = agfindedgeattr(g, "minlen");
825  E_showboxes = agfindedgeattr(g, "showboxes");
826  E_style = agfindedgeattr(g, "style");
827  E_decorate = agfindedgeattr(g, "decorate");
828  E_arrowsz = agfindedgeattr(g, "arrowsize");
829  E_constr = agfindedgeattr(g, "constraint");
830  E_layer = agfindedgeattr(g, "layer");
831  E_comment = agfindedgeattr(g, "comment");
832  E_tailclip = agfindedgeattr(g, "tailclip");
833  E_headclip = agfindedgeattr(g, "headclip");
834  E_penwidth = agfindedgeattr(g, "penwidth");
835 
836  /* background */
837  GD_drawing(g)->xdots = init_xdot (g);
838 
839  /* initialize id, if any */
840 
841  if ((p = agget(g, "id")) && *p)
842  GD_drawing(g)->id = strdup_and_subst_obj(p, g);
843 }
844 
846 {
847  if (GD_drawing(g) && GD_drawing(g)->xdots)
848  freeXDot ((xdot*)GD_drawing(g)->xdots);
849  if (GD_drawing(g) && GD_drawing(g)->id)
850  free (GD_drawing(g)->id);
851  free(GD_drawing(g));
852  GD_drawing(g) = NULL;
853  free_label(GD_label(g));
854  //FIX HERE , STILL SHALLOW
855  //memset(&(g->u), 0, sizeof(Agraphinfo_t));
856  agclean(g, AGRAPH,"Agraphinfo_t");
857 }
858 
859 /* charsetToStr:
860  * Given an internal charset value, return a canonical string
861  * representation.
862  */
863 char*
865 {
866  char* s;
867 
868  switch (c) {
869  case CHAR_UTF8 :
870  s = "UTF-8";
871  break;
872  case CHAR_LATIN1 :
873  s = "ISO-8859-1";
874  break;
875  case CHAR_BIG5 :
876  s = "BIG-5";
877  break;
878  default :
879  agerr(AGERR, "Unsupported charset value %d\n", c);
880  s = "UTF-8";
881  break;
882  }
883  return s;
884 }
885 
886 /* do_graph_label:
887  * Set characteristics of graph label if it exists.
888  *
889  */
891 {
892  char *str, *pos, *just;
893  int pos_ix;
894 
895  /* it would be nice to allow multiple graph labels in the future */
896  if ((str = agget(sg, "label")) && (*str != '\0')) {
897  char pos_flag;
898  pointf dimen;
899 
901 
902  GD_label(sg) = make_label((void*)sg, str, (aghtmlstr(str) ? LT_HTML : LT_NONE),
903  late_double(sg, agfindgraphattr(sg, "fontsize"),
905  late_nnstring(sg, agfindgraphattr(sg, "fontname"),
907  late_nnstring(sg, agfindgraphattr(sg, "fontcolor"),
908  DEFAULT_COLOR));
909 
910  /* set label position */
911  pos = agget(sg, "labelloc");
912  if (sg != agroot(sg)) {
913  if (pos && (pos[0] == 'b'))
914  pos_flag = LABEL_AT_BOTTOM;
915  else
916  pos_flag = LABEL_AT_TOP;
917  } else {
918  if (pos && (pos[0] == 't'))
919  pos_flag = LABEL_AT_TOP;
920  else
921  pos_flag = LABEL_AT_BOTTOM;
922  }
923  just = agget(sg, "labeljust");
924  if (just) {
925  if (just[0] == 'l')
926  pos_flag |= LABEL_AT_LEFT;
927  else if (just[0] == 'r')
928  pos_flag |= LABEL_AT_RIGHT;
929  }
930  GD_label_pos(sg) = pos_flag;
931 
932  if (sg == agroot(sg))
933  return;
934 
935  /* Set border information for cluster labels to allow space
936  */
937  dimen = GD_label(sg)->dimen;
938  PAD(dimen);
939  if (!GD_flip(agroot(sg))) {
940  if (GD_label_pos(sg) & LABEL_AT_TOP)
941  pos_ix = TOP_IX;
942  else
943  pos_ix = BOTTOM_IX;
944  GD_border(sg)[pos_ix] = dimen;
945  } else {
946  /* when rotated, the labels will be restored to TOP or BOTTOM */
947  if (GD_label_pos(sg) & LABEL_AT_TOP)
948  pos_ix = RIGHT_IX;
949  else
950  pos_ix = LEFT_IX;
951  GD_border(sg)[pos_ix].x = dimen.y;
952  GD_border(sg)[pos_ix].y = dimen.x;
953  }
954  }
955 }
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:474
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:890
int agerr(agerrlevel_t level, const char *fmt,...)
Definition: agerror.c:141
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:536
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:653
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:864
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:845
#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