summaryrefslogtreecommitdiff
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
parent281d151d8e984e38b6bc437c89a6aed7720c8f40 (diff)
downloadgperf-f54d310530bf4e5c66deefe1ffe0b21f35a72162.tar.gz
New option --output-file.
-rw-r--r--ChangeLog13
-rw-r--r--NEWS1
-rw-r--r--doc/gperf.texi16
-rw-r--r--src/main.cc11
-rw-r--r--src/options.cc16
-rw-r--r--src/options.h6
-rw-r--r--src/options.icc7
-rw-r--r--tests/test-6.exp5
8 files changed, 73 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7bc3e89..a932ac1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-11-12 Bruno Haible <bruno@clisp.org>
+
+ * src/options.h (Output::get_output_file_name): New method.
+ (Output::_output_file_name): New field.
+ * src/options.icc (Options::get_output_file_name): New method.
+ * src/options.cc (Options::long_usage): Document option --output-file.
+ (Options::Options): Initialize _output_file_name.
+ (long_options): Add --output-file.
+ (Options::parse_options): Handle it.
+ * src/main.cc (main): Open the output file if given by name.
+ * doc/gperf.texi (Output File): New section.
+ * tests/test-6.exp: Update.
+
2002-11-10 Bruno Haible <bruno@clisp.org>
* src/input.cc (pretty_input_file_name): New function.
diff --git a/NEWS b/NEWS
index a0f1715..97cf035 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ New in 2.8:
* Added option -m/--multiple-iterations that reduces the size of the
generated table.
+* Added option --output that allows to specify the output file name.
* If the input file is given by name, the output file will now contain
#line directives referring to the input file.
* Bug fixes.
diff --git a/doc/gperf.texi b/doc/gperf.texi
index 38b6bdc..bbf9fb3 100644
--- a/doc/gperf.texi
+++ b/doc/gperf.texi
@@ -7,7 +7,7 @@
@c some day we should @include version.texi instead of defining
@c these values at hand.
-@set UPDATED 9 November 2002
+@set UPDATED 12 November 2002
@set EDITION 2.7.2
@set VERSION 2.7.2
@c ---------------------
@@ -550,6 +550,7 @@ help is readily available via the @samp{--help} option. Here is the
complete list of options.
@menu
+* Output File:: Specifying the Location of the Output File
* Input Details:: Options that affect Interpretation of the Input File
* Output Language:: Specifying the Language for the Output Code
* Output Details:: Fine tuning Details in the Output Code
@@ -557,7 +558,18 @@ complete list of options.
* Verbosity:: Informative Output
@end menu
-@node Input Details, Output Language, Options, Options
+@node Output File, Input Details, Options, Options
+@section Specifying the Location of the Output File
+
+@table @samp
+@item --output-file=@var{file}
+Allows you to specify the name of the file to which the output is written to.
+@end table
+
+The results are written to standard output if no output file is specified
+or if it is @samp{-}.
+
+@node Input Details, Output Language, Output File, Options
@section Options that affect Interpretation of the Input File
@table @samp
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
diff --git a/tests/test-6.exp b/tests/test-6.exp
index 62ae824..856390b 100644
--- a/tests/test-6.exp
+++ b/tests/test-6.exp
@@ -5,6 +5,11 @@ Usage: ../src/gperf [OPTION]... [INPUT-FILE]
If a long option shows an argument as mandatory, then it is mandatory
for the equivalent short option also.
+Output file location:
+ --output-file=FILE Write output to specified file.
+The results are written to standard output if no output file is specified
+or if it is -.
+
Input file interpretation:
-e, --delimiters=DELIMITER-LIST
Allow user to provide a string containing delimiters