21 static char *usageFmt =
22 "Usage: %s [-Vv?] [-(GNE)name=val] [-(KTlso)<val>] <dot files>\n";
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";
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\
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";
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";
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";
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);
104 static char *getFlagOpt(
int argc,
char **argv,
int *idx)
114 if (*arg && (*arg !=
'-')) {
128 static char* dotneato_basename (
char*
path)
132 if (*s ==
'\0')
return path;
139 char* dotp = strrchr (s,
'.');
140 if (dotp && !
strcasecmp(dotp+1,
"exe")) *dotp =
'\0';
146 while ((s > path) && ((*s ==
'/') || (*s ==
'\\')))
148 if (s == path) ret =
path;
150 while ((s > path) && ((*s !=
'/') && (*s !=
'\\'))) s--;
151 if ((*s ==
'/') || (*s ==
'\\')) ret = s+1;
159 for (s = ret; (c = *s); s++)
166 static void use_library(
GVC_t *
gvc,
const char *name)
177 static void global_def(
agxbuf* xb,
char *dcl,
int kind,
184 if ((p = strchr(dcl,
'='))) {
194 static int gvg_init(
GVC_t *gvc,
graph_t *g,
char *fn,
int gidx)
215 gvg_init(gvc, P_graph,
"<internal>", 0);
241 fprintf(stderr,
"%s - %s version %s (%s)\n",
259 for (i = 1; i < argc; i++)
260 if (argv[i] && argv[i][0] !=
'-')
265 for (i = 1; i < argc; i++) {
266 if (argv[i] && argv[i][0] ==
'-') {
267 rest = &(argv[i][2]);
268 switch (c = argv[i][1]) {
273 fprintf(stderr,
"Missing argument for -G flag\n");
281 fprintf(stderr,
"Missing argument for -N flag\n");
289 fprintf(stderr,
"Missing argument for -E flag\n");
294 val = getFlagOpt(argc, argv, &i);
296 fprintf(stderr,
"Missing argument for -T flag\n");
301 fprintf(stderr,
"Format: \"%s\" not recognized. Use one of:%s\n",
308 val = getFlagOpt(argc, argv, &i);
310 fprintf(stderr,
"Missing argument for -K flag\n");
315 fprintf(stderr,
"There is no layout engine support for \"%s\"\n", val);
316 if (
streq(val,
"dot")) {
317 fprintf(stderr,
"Perhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
320 fprintf(stderr,
"Use one of:%s\n",
332 fprintf(stderr,
"%s - %s version %s (%s)\n",
339 val = getFlagOpt(argc, argv, &i);
341 fprintf(stderr,
"Missing argument for -l flag\n");
344 use_library(gvc, val);
347 val = getFlagOpt(argc, argv, &i);
349 fprintf(stderr,
"Missing argument for -o flag\n");
360 "Invalid parameter \"%s\" for -q flag - ignored\n",
374 "Invalid parameter \"%s\" for -s flag\n",
405 if (
streq(layout,
"dot_static")
406 ||
streq(layout,
"dot_builtins")
407 ||
streq(layout,
"lt-dot")
408 ||
streq(layout,
"lt-dot_builtins")
414 fprintf(stderr,
"There is no layout engine support for \"%s\"\n", layout);
415 if (
streq(layout,
"dot"))
416 fprintf(stderr,
"Perhaps \"dot -c\" needs to be run (with installer's privileges) to register the plugins?\n");
418 fprintf(stderr,
"Use one of:%s\n",
gvplugin_list(gvc, API_layout,
""));
431 "Unable to find even the default \"-Tdot\" renderer. Has the config\nfile been generated by running \"dot -c\" with installer's privileges?\n");
447 static boolean getdoubles2ptf(
graph_t * g,
char *name,
pointf * result)
455 if ((p =
agget(g, name))) {
456 i = sscanf(p,
"%lf,%lf%c", &xf, &yf, &c);
457 if ((i > 1) && (xf > 0) && (yf > 0)) {
465 i = sscanf(p,
"%lf%c", &xf, &c);
466 if ((i > 0) && (xf > 0)) {
468 if (c ==
'!') rv =
TRUE;
480 if ((p =
agget(g, name))) {
481 if (sscanf(p,
"%lf", &f) >= 1)
486 #ifdef EXPERIMENTAL_MYFGETS
499 static char *myfgets(
char * ubuf,
int n, FILE * fp)
502 static int bufsz, pos, len;
514 buf = realloc(buf, bufsz);
516 if (!(fgets(buf, bufsz, fp))) {
528 memcpy(ubuf, buf + pos, cnt);
543 static int fidx, gidx;
552 while ((fn = gvc->
input_filenames[fidx++]) && !(fp = fopen(fn,
"r"))) {
564 #ifdef EXPERIMENTAL_MYFGETS
570 gvg_init(gvc, g, fn, gidx++);
586 static int findCharset (
graph_t * g)
607 agerr(
AGWARN,
"Unsupported charset \"%s\" - assuming utf-8\n", p);
616 static void setRatio(
graph_t * g)
621 if ((p =
agget(g,
"ratio")) && ((c = p[0]))) {
624 if (
streq(p,
"auto"))
628 if (
streq(p,
"compress"))
632 if (
streq(p,
"expand"))
636 if (
streq(p,
"fill"))
658 static char *rankname[] = {
"local",
"global",
"none",
NULL };
660 static char *fontnamenames[] = {
"gd",
"ps",
"svg",
NULL};
666 if ((p =
agget(g,
"fontpath")) || (p = getenv(
"DOTFONTPATH"))) {
670 setenv(
"GDFONTPATH", p, 1);
672 static char *buf = 0;
674 buf =
grealloc(buf, strlen(
"GDFONTPATH=") + strlen(p) + 1);
675 strcpy(buf,
"GDFONTPATH=");
700 if ((p =
agget(g,
"rankdir"))) {
703 else if (
streq(p,
"BT"))
705 else if (
streq(p,
"RL"))
719 if (sscanf(p,
"%lf", &xf) == 0)
725 if (strstr(p,
"equally"))
737 getdoubles2ptf(g,
"size", &(
GD_drawing(g)->size));
738 getdoubles2ptf(g,
"page", &(
GD_drawing(g)->page));
742 if ((p =
agget(g,
"rotate")))
744 else if ((p =
agget(g,
"orientation")))
745 GD_drawing(g)->landscape = ((p[0] ==
'l') || (p[0] ==
'L'));
746 else if ((p =
agget(g,
"landscape")))
749 p =
agget(g,
"clusterrank");
751 p =
agget(g,
"concentrate");
757 if (((p =
agget(g,
"dpi")) && p[0])
758 || ((p =
agget(g,
"resolution")) && p[0]))
843 if ((p =
agget(g,
"id")) && *p)
881 agerr(
AGERR,
"Unsupported charset value %d\n", c);
894 char *
str, *pos, *just;
898 if ((str =
agget(sg,
"label")) && (*str !=
'\0')) {
913 pos =
agget(sg,
"labelloc");
915 if (pos && (pos[0] ==
'b'))
920 if (pos && (pos[0] ==
't'))
925 just =
agget(sg,
"labeljust");
929 else if (just[0] ==
'r')
void * zmalloc(size_t nbytes)
CGRAPH_API void agclean(Agraph_t *g, int kind, char *rec_name)
void free_label(textlabel_t *p)
EXTERN char * Gvimagepath
EXTERN Agsym_t * N_showboxes
EXTERN Agsym_t * N_comment
EXTERN Agsym_t * N_margin
EXTERN Agsym_t * E_labelfontcolor
Agsym_t * agattr(Agraph_t *g, int kind, char *name, char *value)
void * grealloc(void *ptr, size_t size)
CGRAPH_API int aghtmlstr(char *)
void gvconfig(GVC_t *gvc, boolean rescan)
EXTERN Agsym_t * E_tailclip
EXTERN Agsym_t * N_imagepos
bool layout(Agraph_t *g, const char *engine)
char * late_nnstring(void *obj, attrsym_t *attr, char *def)
EXTERN Agsym_t * N_fontname
EXTERN Agsym_t * N_fontcolor
CGRAPH_API void agsetfile(char *)
EXTERN Agsym_t * N_fontsize
#define ALLOC(size, ptr, type)
EXTERN char * HTTPServerEnVar
EXTERN Agsym_t * N_height
agerrlevel_t agseterr(agerrlevel_t lvl)
EXTERN Agsym_t * N_peripheries
#define SET_RANKDIR(g, rd)
EXTERN Agsym_t * E_labelfontname
size_t agxbput(agxbuf *xb, const char *s)
EXTERN Agsym_t * G_ordering
EXTERN int graphviz_errors
EXTERN Agsym_t * E_labeldistance
EXTERN Agsym_t * E_labelangle
EXTERN Agsym_t * G_margin
EXTERN Agsym_t * E_headlabel
CGRAPH_API Agraph_t * agread(void *chan, Agdisc_t *disc)
EXTERN double Initial_dist
EXTERN Agsym_t * E_fontcolor
boolean auto_outfile_names
EXTERN Agsym_t * N_gradientangle
EXTERN Agsym_t * E_label_float
int agerr(agerrlevel_t level, const char *fmt,...)
EXTERN Agsym_t * E_constr
CGRAPH_API Agraph_t * agroot(void *obj)
char * strdup_and_subst_obj(char *str, void *obj)
EXTERN Agsym_t * E_fillcolor
char * agget(void *obj, char *name)
int gvlayout_select(GVC_t *gvc, const char *str)
void * init_xdot(Agraph_t *g)
EXTERN Agsym_t * E_taillabel
EXTERN Agsym_t * N_imagescale
EXTERN Agsym_t * E_arrowhead
EXTERN Agsym_t * E_xlabel
EXTERN Agsym_t * E_showboxes
Agraph_t * gvplugin_graph(GVC_t *gvc)
EXTERN Agsym_t * E_arrowtail
EXTERN Agsym_t * N_xlabel
EXTERN Agsym_t * N_vertices
#define agfindedgeattr(g, a)
void agxbinit(agxbuf *xb, unsigned int hint, unsigned char *init)
EXTERN Agsym_t * E_comment
EXTERN Agsym_t * N_orientation
int late_int(void *obj, attrsym_t *attr, int def, int low)
EXTERN unsigned char Reduce
Agraph_t * agread_usergets(ictx_t *ictx, FILE *fp, int(*usergets)(void *chan, char *buf, int bufsize))
EXTERN Agsym_t * E_minlen
EXTERN Agsym_t * N_penwidth
EXTERN Agsym_t * G_gradientangle
#define GD_exact_ranksep(g)
EXTERN unsigned char Concentrate
#define agfindgraphattr(g, a)
EXTERN Agsym_t * E_weight
EXTERN Agsym_t * E_penwidth
EXTERN Agsym_t * E_fontname
EXTERN Agsym_t * N_nojustify
double late_double(void *obj, attrsym_t *attr, double def, double low)
EXTERN unsigned char Verbose
int strcasecmp(const char *s1, const char *s2)
char * gvplugin_list(GVC_t *gvc, api_t api, const char *str)
size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
EXTERN Agsym_t * N_ordering
EXTERN Agsym_t * E_labelfontsize
boolean gvjobs_output_langname(GVC_t *gvc, const char *name)
void gvjobs_output_filename(GVC_t *gvc, const char *name)
EXTERN Agsym_t * E_headclip
char * late_string(void *obj, attrsym_t *attr, char *def)
EXTERN double PSinputscale
EXTERN Agsym_t * E_fontsize
EXTERN Agsym_t * E_decorate
EXTERN Agsym_t * E_arrowsz
int maptoken(char *p, char **name, int *val)
#define agfindnodeattr(g, a)
EXTERN int EdgeLabelsDone
void agxbfree(agxbuf *xb)
EXTERN Agsym_t * N_fillcolor
const char * output_langname
EXTERN Agsym_t * N_distortion
textlabel_t * make_label(void *obj, char *str, int kind, double fontsize, char *fontname, char *fontcolor)