From: erg Date: Thu, 10 Feb 2011 02:43:41 +0000 (+0000) Subject: Add support for node and graph names in gvgen X-Git-Tag: LAST_LIBGRAPH~32^2~1056 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=431f7e722560e67fc4149d7867ef3dde18b4c0a3;p=graphviz Add support for node and graph names in gvgen --- diff --git a/cmd/tools/gvgen.1 b/cmd/tools/gvgen.1 index 7c65e4a35..ff02517fb 100644 --- a/cmd/tools/gvgen.1 +++ b/cmd/tools/gvgen.1 @@ -46,6 +46,12 @@ gvgen \- generate graphs .BI -w n ] [ +.BI -n prefix +] +[ +.BI -N name +] +[ .BI -o outfile ] .SH DESCRIPTION @@ -117,6 +123,14 @@ This will have \fIx*y\fP vertices and Generate a path on \fIn\fP vertices. This will have \fIn-1\fP edges. .TP +.BI \-n " prefix" +Normally, integers are used as node names. If \fIprefix\fP is specified, +this will be prepended to the integer to create the name. +.TP +.BI \-N " name" +Use \fIname\fP as the name of the graph. +By default, the graph is anonymous. +.TP .BI \-o " outfile" If specified, the generated graph is written into the file .I outfile. diff --git a/cmd/tools/gvgen.c b/cmd/tools/gvgen.c index 5c5baa4f4..00ebac882 100644 --- a/cmd/tools/gvgen.c +++ b/cmd/tools/gvgen.c @@ -51,6 +51,8 @@ typedef struct { int foldVal; int directed; FILE *outfile; + char* pfx; + char* name; } opts_t; static char *cmd; @@ -81,6 +83,8 @@ static char *Usage = "Usage: %s [-dV?] [options]\n\ -h : hypercube \n\ -k : complete \n\ -b : complete bipartite\n\ + -n : use in node names (\"\")\n\ + -N : use for the graph (\"\")\n\ -o : put output in (stdout)\n\ -p : path \n\ -s : star\n\ @@ -177,7 +181,7 @@ static char* setFold(char *s, opts_t* opts) return next; } -static char *optList = ":c:C:dg:G:h:k:b:o:p:s:S:t:T:Vw:"; +static char *optList = ":n:N:c:C:dg:G:h:k:b:o:p:s:S:t:T:Vw:"; static GraphType init(int argc, char *argv[], opts_t* opts) { @@ -224,6 +228,12 @@ static GraphType init(int argc, char *argv[], opts_t* opts) if (setTwo(optarg, opts)) errexit(c); break; + case 'n': + opts->pfx = optarg; + break; + case 'N': + opts->name = optarg; + break; case 'o': opts->outfile = openFile(optarg, "w"); break; @@ -287,24 +297,27 @@ static opts_t opts; static void dirfn (int t, int h) { if (h > 0) - fprintf (opts.outfile, " %d -> %d\n", t, h); + fprintf (opts.outfile, " %s%d -> %s%d\n", opts.pfx, t, opts.pfx, h); else - fprintf (opts.outfile, " %d\n", t); + fprintf (opts.outfile, " %s%d\n", opts.pfx, t); } static void undirfn (int t, int h) { if (h > 0) - fprintf (opts.outfile, " %d -- %d\n", t, h); + fprintf (opts.outfile, " %s%d -- %s%d\n", opts.pfx, t, opts.pfx, h); else - fprintf (opts.outfile, " %d\n", t); + fprintf (opts.outfile, " %s%d\n", opts.pfx, t); } int main(int argc, char *argv[]) { - GraphType graphType = init(argc, argv, &opts); + GraphType graphType; edgefn ef; + opts.pfx = ""; + opts.name = ""; + graphType = init(argc, argv, &opts); if (opts.directed) { fprintf(opts.outfile, "digraph {\n"); ef = dirfn;