-.TH GML2GV 1 "9 July 2009"
+.TH GML2GV 1 "30 September 2010"
.SH NAME
gml2gv \- GML-DOT converter
.SH SYNOPSIS
.B gml2gv
[
-.B \-?
+.B \-?v
+]
+[
+.BI -g gname
]
[
.BI -o outfile
.SH OPTIONS
The following options are supported:
.TP
+.B \-v
+Turns on verbose mode
+.TP
.B \-?
Prints usage information and exits.
.TP
+.BI \-g "gname"
+The string \fIgname\fP is used as the name of the generated graph.
+If multiple graphs are generated, subsequent graphs use the name
+\fIgname\fP appended with an integer.
+.TP
.BI \-o "outfile"
Prints output to the file \fIoutfile\fP. If not given, \fBgml2gv\fP
uses stdout.
#include "compat_getopt.h"
#endif
+#define N_NEW(n,t) (t*)malloc((n)*sizeof(t))
+
+static int Verbose;
+static char* gname = "";
static FILE *outFile;
static char *CmdName;
static char **Files;
}
-static char *useString = "Usage: %s [-p?] <files>\n\
+static char *useString = "Usage: %s [-v?] [-g<name>] [-o<file>] <files>\n\
+ -g<name> : use <name> as template for graph names\n\
+ -v : verbose mode\n\
-o<file> : output to <file> (stdout)\n\
- -? - print usage\n\
+ -? : print usage\n\
If no files are specified, stdin is used\n";
static void usage(int v)
CmdName = cmdName(argv[0]);
opterr = 0;
- while ((c = getopt(argc, argv, ":gdo:")) != -1) {
+ while ((c = getopt(argc, argv, ":g:vo:")) != -1) {
switch (c) {
+ case 'g':
+ gname = optarg;
+ break;
+ case 'v':
+ Verbose = 1;
+ break;
case 'o':
outFile = openFile(optarg, "w");
break;
outFile = stdout;
}
+static char*
+nameOf (char* name, int cnt)
+{
+ static char* buf = 0;
+
+ if (*name == '\0')
+ return name;
+ if (cnt) {
+ if (!buf)
+ buf = N_NEW (strlen(name)+32,char); /* 32 to handle any integer plus null byte */
+ sprintf (buf, "%s%d", name, cnt);
+ return buf;
+ }
+ else
+ return name;
+}
+
int main(int argc, char **argv)
{
Agraph_t *G;
Agraph_t *prev = 0;
FILE *inFile;
- int cnt, rv;
+ int gcnt, cnt, rv;
rv = 0;
+ gcnt = 0;
initargs(argc, argv);
while ((inFile = getFile())) {
cnt = 0;
- while ((G = gml_to_gv(inFile, cnt, &rv))) {
+ while ((G = gml_to_gv(nameOf(gname, gcnt), inFile, cnt, &rv))) {
cnt++;
+ gcnt++;
if (prev)
agclose(prev);
prev = G;
+ if (Verbose)
+ fprintf (stderr, "%s: %d nodes %d edges\n",
+ agnameof (G), agnnodes(G), agnedges(G));
agwrite(G, outFile);
fflush(outFile);
}
}
exit(rv);
}
+
extern void gmlerror(char *);
extern int gmlerrors(void);
extern void initgmlscan (FILE*);
-extern Agraph_t* gml_to_gv (FILE*, int, int*);
+extern Agraph_t* gml_to_gv (char*, FILE*, int, int*);
}
static Agraph_t*
-mkGraph (gmlgraph* G, Agraph_t* parent, agxbuf* xb, agxbuf* unk)
+mkGraph (gmlgraph* G, Agraph_t* parent, char* name, agxbuf* xb, agxbuf* unk)
{
Agraph_t* g;
Agnode_t* n;
g = agsubg (parent, NULL, 1);
}
else if (G->directed >= 1)
- g = agopen ("", Agdirected, 0);
+ g = agopen (name, Agdirected, 0);
else
- g = agopen ("", Agundirected, 0);
+ g = agopen (name, Agundirected, 0);
if (!parent && L) {
addAttrs ((Agobj_t*)g, L, xb, unk);
addAttrs ((Agobj_t*)e, ep->attrlist, xb, unk);
}
for (gp = dtfirst(G->graphlist); gp; gp = dtnext (G->graphlist, gp)) {
- mkGraph (gp, g, xb, unk);
+ mkGraph (gp, g, NULL, xb, unk);
}
addAttrs ((Agobj_t*)g, G->attrlist, xb, unk);
}
Agraph_t*
-gml_to_gv (FILE* fp, int cnt, int* errors)
+gml_to_gv (char* name, FILE* fp, int cnt, int* errors)
{
Agraph_t* g;
agxbuf xb;
else {
agxbinit (&xb, BUFSIZ, buf);
agxbinit (&unk, BUFSIZ, unknownb);
- g = mkGraph (G, NULL, &xb, &unk);
+ g = mkGraph (G, name, NULL, &xb, &unk);
agxbfree (&xb);
}