From ebc7fe61881637eaeccbe18bebedd0f089c78029 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 11 Dec 2002 18:50:41 +0000 Subject: [PATCH] Rework the Read_Line class. --- ChangeLog | 7 +++++++ src/input.cc | 4 ++-- src/input.h | 2 +- src/main.cc | 4 ++-- src/read-line.cc | 2 +- src/read-line.h | 5 +++-- src/read-line.icc | 7 +++++++ 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a983be..4843992 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2002-11-02 Bruno Haible + * src/read-line.h (Read_Line::Read_Line): Make FILE* argument + mandatory. Move body to read-line.icc. + * src/read-line.icc (Read_Line::Read_Line): New constructor. + * src/input.h (Input::Input): Add FILE* argument. + * src/input.cc (Input::Input): Likewise. + * src/main.cc (main): Pass stdin to Input constructor. + * src/options.h (DEFAULTCHARS): Remove. (Positions::MAX_KEY_POS): Set to 255. (Positions::_positions): Increase array size. diff --git a/src/input.cc b/src/input.cc index d152fe0..6645570 100644 --- a/src/input.cc +++ b/src/input.cc @@ -29,8 +29,8 @@ #include /* defines UCHAR_MAX etc. */ #include "options.h" -Input::Input (Keyword_Factory *keyword_factory) - : _factory (keyword_factory) +Input::Input (FILE *stream, Keyword_Factory *keyword_factory) + : Read_Line (stream), _factory (keyword_factory) { } diff --git a/src/input.h b/src/input.h index 7745fce..fa7be68 100644 --- a/src/input.h +++ b/src/input.h @@ -32,7 +32,7 @@ class Input : private Read_Line { public: - Input (Keyword_Factory *keyword_factory); + Input (FILE *stream, Keyword_Factory *keyword_factory); void read_keys (); private: #ifndef strcspn diff --git a/src/main.cc b/src/main.cc index 78e966f..ad98d91 100644 --- a/src/main.cc +++ b/src/main.cc @@ -45,12 +45,12 @@ KeywordExt_Factory::create_keyword (const char *allchars, int allchars_length, c int main (int argc, char *argv[]) { - /* Set the Options. */ + /* Set the Options. Open the input file and assign stdin to it. */ option.parse_options (argc, argv); /* Initialize the key word list. */ KeywordExt_Factory factory; - Input inputter (&factory); + Input inputter (stdin, &factory); inputter.read_keys (); /* We can cast the keyword list to KeywordExt_List* because its list elements were created by KeywordExt_Factory. */ diff --git a/src/read-line.cc b/src/read-line.cc index 7459afe..ba24345 100644 --- a/src/read-line.cc +++ b/src/read-line.cc @@ -1,4 +1,4 @@ -/* Correctly reads an arbitrarily size string. +/* Correctly reads an arbitrarily long string. Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc. Written by Douglas C. Schmidt diff --git a/src/read-line.h b/src/read-line.h index e264331..d1cbdc9 100644 --- a/src/read-line.h +++ b/src/read-line.h @@ -37,7 +37,7 @@ class Read_Line public: /* Initializes the instance with a given input stream. */ - Read_Line (FILE *stream = stdin) : _fp (stream) {} + Read_Line (FILE *stream); /* Reads the next line and returns it, excluding the terminating newline, and ignoring lines starting with '#'. Returns NULL on error or EOF. @@ -46,7 +46,8 @@ public: char * read_next_line (); private: - FILE * const _fp; /* FILE pointer to the input stream. */ + /* FILE pointer to the input stream. */ + FILE * const _fp; }; #ifdef __OPTIMIZE__ diff --git a/src/read-line.icc b/src/read-line.icc index a1b5ca1..c03d514 100644 --- a/src/read-line.icc +++ b/src/read-line.icc @@ -25,6 +25,13 @@ //#include //#include "getline.h" +/* Initializes the instance with a given input stream. */ +INLINE +Read_Line::Read_Line (FILE *stream) + : _fp (stream) +{ +} + /* Reads the next line and returns it, excluding the terminating newline, and ignoring lines starting with '#'. Returns NULL on error or EOF. The storage for the string is dynamically allocated and must be freed