]> granicus.if.org Git - graphviz/commitdiff
Fix bug 1738
authorerg <devnull@localhost>
Fri, 7 Aug 2009 16:45:04 +0000 (16:45 +0000)
committererg <devnull@localhost>
Fri, 7 Aug 2009 16:45:04 +0000 (16:45 +0000)
cmd/tools/sccmap.1
cmd/tools/sccmap.c

index b9da082643e63a7c6e89df9198e50c59c6759c97..75c7b247695d30eb9ed7bfa2dac259cd1a58e45a 100644 (file)
@@ -5,6 +5,9 @@ sccmap \- extract strongly connected components of directed graphs
 \fBsccmap\fR
 [\fB\-dsv\fR]
 [
+.BI \-o outfile
+]
+[
 .I files
 ]
 .SH DESCRIPTION
@@ -30,6 +33,10 @@ important.
 .B \-S
 Just print the resulting graphs. No statistics are printed.
 .TP
+.BI \-o "output"
+Prints output to the file \fIoutput\fP. If not given, \fBsccmap\fP
+uses stdout.
+.TP
 .B \-v
 Generate additional statistics. In particular,
 .B sccmap
index 55e9a7fbb4efcd7faf95db889efc8c9ac896066e..562051450f2fb6551d03c2089dfe57ef721f8a40 100644 (file)
@@ -138,12 +138,13 @@ typedef struct {
     int N_nodes_in_nontriv_SCC;
 } sccstate;
 
-int wantDegenerateComp;
-int Silent;
-int StatsOnly;
-int Verbose;
-char *CmdName;
-char **Files;
+static int wantDegenerateComp;
+static int Silent;
+static int StatsOnly;
+static int Verbose;
+static char *CmdName;
+static char **Files;
+static FILE *outfp;            /* output; stdout by default */
 
 static void nodeInduce(Agraph_t * g, Agraph_t* map)
 {
@@ -208,7 +209,7 @@ static int visit(Agnode_t * n, Agraph_t * map, Stack * sp, sccstate * st)
            } while (t != n);
            nodeInduce(subg, map);
            if (!StatsOnly)
-               agwrite(subg, stdout);
+               agwrite(subg, outfp);
        }
     }
     return min;
@@ -294,7 +295,7 @@ static void process(Agraph_t * G)
            visit(n, map, &stack, &state);
     freeStack(&stack);
     if (!StatsOnly)
-       agwrite(map, stdout);
+       agwrite(map, outfp);
     agclose(map);
 
     if (Verbose)
@@ -308,12 +309,31 @@ static void process(Agraph_t * G)
 
 }
 
+static FILE *openFile(char *name, char *mode)
+{
+    FILE *fp;
+    char *modestr;
+
+    fp = fopen(name, mode);
+    if (!fp) {
+       if (*mode == 'r')
+           modestr = "reading";
+       else
+           modestr = "writing";
+       fprintf(stderr, "gvpack: could not open file %s for %s\n",
+               name, modestr);
+       exit(1);
+    }
+    return (fp);
+}
+
 static char *useString = "Usage: %s [-sdv?] <files>\n\
-  -s - only produce statistics\n\
-  -S - silent\n\
-  -d - allow degenerate components\n\
-  -v - verbose\n\
-  -? - print usage\n\
+  -s           - only produce statistics\n\
+  -S           - silent\n\
+  -d           - allow degenerate components\n\
+  -o<outfile>  - allow degenerate components\n\
+  -v           - verbose\n\
+  -?           - print usage\n\
 If no files are specified, stdin is used\n";
 
 static void usage(int v)
@@ -327,7 +347,7 @@ static void scanArgs(int argc, char **argv)
     int c;
 
     CmdName = argv[0];
-    while ((c = getopt(argc, argv, ":sdvS?")) != EOF) {
+    while ((c = getopt(argc, argv, ":o:sdvS?")) != EOF) {
        switch (c) {
        case 's':
            StatsOnly = 1;
@@ -335,6 +355,9 @@ static void scanArgs(int argc, char **argv)
        case 'd':
            wantDegenerateComp = 1;
            break;
+       case 'o':
+           outfp = openFile(optarg, "w");
+           break;
        case 'v':
            Verbose = 1;
            break;
@@ -356,6 +379,8 @@ static void scanArgs(int argc, char **argv)
 
     if (argc)
        Files = argv;
+    if (!outfp)
+       outfp = stdout;         /* stdout the default */
 }
 
 static Agraph_t *gread(FILE * fp)