mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
Open the input file in main.cc, not in class Options.
This commit is contained in:
@@ -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,
|
||||
|
||||
13
src/main.cc
13
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))
|
||||
{
|
||||
fprintf (stderr, "error while writing output file\n");
|
||||
status = 1;
|
||||
}
|
||||
|
||||
/* Don't use exit() here, it skips the destructors. */
|
||||
return status;
|
||||
|
||||
@@ -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,19 +833,15 @@ Options::parse_options (int argc, char *argv[])
|
||||
|
||||
}
|
||||
|
||||
if (/*getopt*/optind + 1 < argc)
|
||||
if (/*getopt*/optind < argc)
|
||||
_input_file_name = argv[/*getopt*/optind++];
|
||||
|
||||
if (/*getopt*/optind < argc)
|
||||
{
|
||||
fprintf (stderr, "Extra trailing arguments to %s.\n", program_name);
|
||||
short_usage (stderr);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (argv[/*getopt*/optind] && ! freopen (argv[/*getopt*/optind], "r", stdin))
|
||||
{
|
||||
fprintf (stderr, "Cannot open keyword file `%s'\n", argv[/*getopt*/optind]);
|
||||
short_usage (stderr);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __OPTIMIZE__
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user