summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-01-21 12:00:44 +0000
committerBruno Haible <bruno@clisp.org>2003-01-21 12:00:44 +0000
commitd3a9c2f7ade30d8d77be7c66d746c1fa5aa8dce1 (patch)
tree1931bae2c3476c1a714357a19547950a861c08dd
parent0a3597e6c284ec8235f54c1d2daaf800bf648358 (diff)
downloadgperf-d3a9c2f7ade30d8d77be7c66d746c1fa5aa8dce1.tar.gz
Open the input file in main.cc, not in class Options.
-rw-r--r--ChangeLog9
-rw-r--r--src/main.cc15
-rw-r--r--src/options.cc13
-rw-r--r--src/options.h6
-rw-r--r--src/options.icc7
5 files changed, 41 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index ae6c7e4..4f36570 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2002-11-10 Bruno Haible <bruno@clisp.org>
+ * src/options.h (Options::get_input_file_name): New declaration.
+ (Options::_input_file_name): New field.
+ * src/options.icc (Options::get_input_file_name): New method.
+ * src/options.cc (Options::Options): Initialize _input_file_name.
+ (Options::parse_options): Don't open input file, only store it in
+ _input_file_name.
+ * src/main.cc (main): Open input file here.
+ Print an error message upon write error on the output file.
+
Upgrade to autoconf-2.52.
* configure.in: Use AC_CONFIG_SUBDIRS instead of AC_OUTPUT_SUBDIRS.
* Makefile.devel (configure, lib/configure, src/configure,
diff --git a/src/main.cc b/src/main.cc
index c55901a..22ebd46 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -21,6 +21,7 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <stdio.h>
+#include <stdlib.h>
#include "options.h"
#include "input.h"
#include "search.h"
@@ -51,6 +52,15 @@ main (int argc, char *argv[])
/* Set the Options. Open the input file and assign stdin to it. */
option.parse_options (argc, argv);
+ /* Open the input file. */
+ if (option.get_input_file_name ())
+ if (!freopen (option.get_input_file_name (), "r", stdin))
+ {
+ fprintf (stderr, "Cannot open input file '%s'\n",
+ option.get_input_file_name ());
+ exit (1);
+ }
+
/* Initialize the keyword list. */
KeywordExt_Factory factory;
Input inputter (stdin, &factory);
@@ -82,7 +92,10 @@ main (int argc, char *argv[])
/* Check for write error on stdout. */
int status = 0;
if (fflush (stdout) || ferror (stdout))
- status = 1;
+ {
+ fprintf (stderr, "error while writing output file\n");
+ status = 1;
+ }
/* Don't use exit() here, it skips the destructors. */
return status;
diff --git a/src/options.cc b/src/options.cc
index f207ff9..5a912dd 100644
--- a/src/options.cc
+++ b/src/options.cc
@@ -416,6 +416,7 @@ PositionStringParser::nextPosition ()
Options::Options ()
: _option_word (C),
+ _input_file_name (NULL),
_iterations (0),
_jump (DEFAULT_JUMP_VALUE),
_initial_asso_value (0),
@@ -832,16 +833,12 @@ Options::parse_options (int argc, char *argv[])
}
- if (/*getopt*/optind + 1 < argc)
- {
- fprintf (stderr, "Extra trailing arguments to %s.\n", program_name);
- short_usage (stderr);
- exit (1);
- }
+ if (/*getopt*/optind < argc)
+ _input_file_name = argv[/*getopt*/optind++];
- if (argv[/*getopt*/optind] && ! freopen (argv[/*getopt*/optind], "r", stdin))
+ if (/*getopt*/optind < argc)
{
- fprintf (stderr, "Cannot open keyword file `%s'\n", argv[/*getopt*/optind]);
+ fprintf (stderr, "Extra trailing arguments to %s.\n", program_name);
short_usage (stderr);
exit (1);
}
diff --git a/src/options.h b/src/options.h
index e2e12b9..874ca2a 100644
--- a/src/options.h
+++ b/src/options.h
@@ -181,6 +181,9 @@ public:
/* Tests a given boolean option. Returns true if set, false otherwise. */
bool operator[] (Option_Type option) const;
+ /* Returns the input file name. */
+ const char * get_input_file_name () const;
+
/* Returns the iterations value. */
int get_iterations () const;
@@ -244,6 +247,9 @@ private:
/* Holds the boolean options. */
int _option_word;
+ /* Name of input file. */
+ char * _input_file_name;
+
/* Amount to iterate when a collision occurs. */
int _iterations;
diff --git a/src/options.icc b/src/options.icc
index 2585570..f053898 100644
--- a/src/options.icc
+++ b/src/options.icc
@@ -125,6 +125,13 @@ Options::operator[] (Option_Type option) const
return _option_word & option;
}
+/* Returns the input file name. */
+INLINE const char *
+Options::get_input_file_name () const
+{
+ return _input_file_name;
+}
+
/* Returns the iterations value. */
INLINE int
Options::get_iterations () const