]> granicus.if.org Git - graphviz/commitdiff
Update gml2gv to allow the user to specify the graph name;
authorerg <devnull@localhost>
Thu, 30 Sep 2010 15:03:39 +0000 (15:03 +0000)
committererg <devnull@localhost>
Thu, 30 Sep 2010 15:03:39 +0000 (15:03 +0000)
support verbose mode

cmd/tools/gml2gv.1
cmd/tools/gml2gv.c
cmd/tools/gml2gv.h
cmd/tools/gmlparse.y

index 14fa6a6ec629e5ace1a0bb331ced14e36d9d2b44..8678c06386df9c33ce47da092ebe8e98639f8e53 100644 (file)
@@ -1,10 +1,13 @@
-.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
@@ -19,9 +22,17 @@ converts a graph specified in the GML format to a graph in the GV (formerly DOT)
 .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.
index 2f2d37bac7ef6177eaf2760f6cd86824b40481a3..05b9e9f60fca43bbb709ef8c8a0df6c2aee7516f 100644 (file)
 #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;
@@ -79,9 +83,11 @@ static FILE *openFile(char *name, char *mode)
 }
 
 
-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)
@@ -108,8 +114,14 @@ static void initargs(int argc, char **argv)
 
     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;
@@ -133,25 +145,48 @@ static void initargs(int argc, char **argv)
        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);
 }
+
index b7e5cce7a25c3b1ee60eed94b5a0b49f06f1d090..eb70a7e724bb84b64ac34021dd6f85578efa703e 100644 (file)
@@ -43,4 +43,4 @@ extern void gmllexeof(void);
 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*);
index 5306265a2191ff27b01e1daba0ac22eb44cc1a9b..906bed6557ec1cd672c1839240e0e19988d14853 100644 (file)
@@ -732,7 +732,7 @@ addAttrs (Agobj_t* obj, Dt_t* alist, agxbuf* xb, agxbuf* unk)
 }
 
 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;
@@ -746,9 +746,9 @@ mkGraph (gmlgraph* G, Agraph_t* parent, agxbuf* xb, agxbuf* unk)
        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);
@@ -777,7 +777,7 @@ mkGraph (gmlgraph* G, Agraph_t* parent, agxbuf* xb, agxbuf* 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);
@@ -786,7 +786,7 @@ mkGraph (gmlgraph* G, Agraph_t* parent, agxbuf* xb, agxbuf* 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;
@@ -812,7 +812,7 @@ gml_to_gv (FILE* fp, int cnt, int* errors)
     else {
        agxbinit (&xb, BUFSIZ, buf);
        agxbinit (&unk, BUFSIZ, unknownb);
-       g = mkGraph (G, NULL, &xb, &unk);
+       g = mkGraph (G, name, NULL, &xb, &unk);
        agxbfree (&xb);
     }