summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-01-28 12:18:10 +0000
committerBruno Haible <bruno@clisp.org>2003-01-28 12:18:10 +0000
commitf54d310530bf4e5c66deefe1ffe0b21f35a72162 (patch)
treeaecaf0af1d5571faac5a52213c5977d42a3e1395 /src
parent281d151d8e984e38b6bc437c89a6aed7720c8f40 (diff)
downloadgperf-f54d310530bf4e5c66deefe1ffe0b21f35a72162.tar.gz
New option --output-file.
Diffstat (limited to 'src')
-rw-r--r--src/main.cc11
-rw-r--r--src/options.cc16
-rw-r--r--src/options.h6
-rw-r--r--src/options.icc7
4 files changed, 40 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc
index a688143..7552b3c 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "options.h"
#include "input.h"
#include "search.h"
@@ -78,6 +79,16 @@ main (int argc, char *argv[])
searcher.optimize ();
list = searcher._head;
+ /* Open the output file. */
+ if (option.get_output_file_name ())
+ if (strcmp (option.get_output_file_name (), "-") != 0)
+ if (!freopen (option.get_output_file_name (), "w", stdout))
+ {
+ fprintf (stderr, "Cannot open output file '%s'\n",
+ option.get_output_file_name ());
+ exit (1);
+ }
+
{
/* Output the hash function code. */
Output outputter (searcher._head,
diff --git a/src/options.cc b/src/options.cc
index 5a912dd..aed4af2 100644
--- a/src/options.cc
+++ b/src/options.cc
@@ -27,6 +27,7 @@
#include <stdlib.h> /* declares atoi(), abs(), exit() */
#include <string.h> /* declares strcmp() */
#include <ctype.h> /* declares isdigit() */
+#include <limits.h> /* defines CHAR_MAX */
#include "getopt.h"
#include "version.h"
@@ -85,6 +86,14 @@ Options::long_usage (FILE * stream) const
"for the equivalent short option also.\n");
fprintf (stream, "\n");
fprintf (stream,
+ "Output file location:\n");
+ fprintf (stream,
+ " --output-file=FILE Write output to specified file.\n");
+ fprintf (stream,
+ "The results are written to standard output if no output file is specified\n"
+ "or if it is -.\n");
+ fprintf (stream, "\n");
+ fprintf (stream,
"Input file interpretation:\n");
fprintf (stream,
" -e, --delimiters=DELIMITER-LIST\n"
@@ -417,6 +426,7 @@ PositionStringParser::nextPosition ()
Options::Options ()
: _option_word (C),
_input_file_name (NULL),
+ _output_file_name (NULL),
_iterations (0),
_jump (DEFAULT_JUMP_VALUE),
_initial_asso_value (0),
@@ -521,6 +531,7 @@ Options::~Options ()
static const struct option long_options[] =
{
+ { "output-file", required_argument, NULL, CHAR_MAX + 1 },
{ "delimiters", required_argument, NULL, 'e' },
{ "struct-type", no_argument, NULL, 't' },
{ "language", required_argument, NULL, 'L' },
@@ -826,6 +837,11 @@ Options::parse_options (int argc, char *argv[])
_option_word |= SEVENBIT;
break;
}
+ case CHAR_MAX + 1: /* Set the output file name. */
+ {
+ _output_file_name = /*getopt*/optarg;
+ break;
+ }
default:
short_usage (stderr);
exit (1);
diff --git a/src/options.h b/src/options.h
index 874ca2a..a8d9468 100644
--- a/src/options.h
+++ b/src/options.h
@@ -184,6 +184,9 @@ public:
/* Returns the input file name. */
const char * get_input_file_name () const;
+ /* Returns the output file name. */
+ const char * get_output_file_name () const;
+
/* Returns the iterations value. */
int get_iterations () const;
@@ -250,6 +253,9 @@ private:
/* Name of input file. */
char * _input_file_name;
+ /* Name of output file. */
+ char * _output_file_name;
+
/* Amount to iterate when a collision occurs. */
int _iterations;
diff --git a/src/options.icc b/src/options.icc
index f053898..d4069f6 100644
--- a/src/options.icc
+++ b/src/options.icc
@@ -132,6 +132,13 @@ Options::get_input_file_name () const
return _input_file_name;
}
+/* Returns the output file name. */
+INLINE const char *
+Options::get_output_file_name () const
+{
+ return _output_file_name;
+}
+
/* Returns the iterations value. */
INLINE int
Options::get_iterations () const