From: erg <devnull@localhost> Date: Fri, 7 Aug 2009 16:45:04 +0000 (+0000) Subject: Fix bug 1738 X-Git-Tag: LAST_LIBGRAPH~32^2~1750 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00899ddd1b19b61ee44ee5e0cd1c93af82d753e4;p=graphviz Fix bug 1738 --- diff --git a/cmd/tools/sccmap.1 b/cmd/tools/sccmap.1 index b9da08264..75c7b2476 100644 --- a/cmd/tools/sccmap.1 +++ b/cmd/tools/sccmap.1 @@ -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 diff --git a/cmd/tools/sccmap.c b/cmd/tools/sccmap.c index 55e9a7fbb..562051450 100644 --- a/cmd/tools/sccmap.c +++ b/cmd/tools/sccmap.c @@ -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)