1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

Rework the Read_Line class.

This commit is contained in:
Bruno Haible
2002-12-11 18:50:41 +00:00
parent c3412a80e7
commit ebc7fe6188
7 changed files with 23 additions and 8 deletions

View File

@@ -1,5 +1,12 @@
2002-11-02 Bruno Haible <bruno@clisp.org> 2002-11-02 Bruno Haible <bruno@clisp.org>
* 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. * src/options.h (DEFAULTCHARS): Remove.
(Positions::MAX_KEY_POS): Set to 255. (Positions::MAX_KEY_POS): Set to 255.
(Positions::_positions): Increase array size. (Positions::_positions): Increase array size.

View File

@@ -29,8 +29,8 @@
#include <limits.h> /* defines UCHAR_MAX etc. */ #include <limits.h> /* defines UCHAR_MAX etc. */
#include "options.h" #include "options.h"
Input::Input (Keyword_Factory *keyword_factory) Input::Input (FILE *stream, Keyword_Factory *keyword_factory)
: _factory (keyword_factory) : Read_Line (stream), _factory (keyword_factory)
{ {
} }

View File

@@ -32,7 +32,7 @@
class Input : private Read_Line class Input : private Read_Line
{ {
public: public:
Input (Keyword_Factory *keyword_factory); Input (FILE *stream, Keyword_Factory *keyword_factory);
void read_keys (); void read_keys ();
private: private:
#ifndef strcspn #ifndef strcspn

View File

@@ -45,12 +45,12 @@ KeywordExt_Factory::create_keyword (const char *allchars, int allchars_length, c
int int
main (int argc, char *argv[]) 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); option.parse_options (argc, argv);
/* Initialize the key word list. */ /* Initialize the key word list. */
KeywordExt_Factory factory; KeywordExt_Factory factory;
Input inputter (&factory); Input inputter (stdin, &factory);
inputter.read_keys (); inputter.read_keys ();
/* We can cast the keyword list to KeywordExt_List* because its list /* We can cast the keyword list to KeywordExt_List* because its list
elements were created by KeywordExt_Factory. */ elements were created by KeywordExt_Factory. */

View File

@@ -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. Copyright (C) 1989-1998, 2002 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu> Written by Douglas C. Schmidt <schmidt@ics.uci.edu>

View File

@@ -37,7 +37,7 @@ class Read_Line
public: public:
/* Initializes the instance with a given input stream. */ /* 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, /* Reads the next line and returns it, excluding the terminating newline,
and ignoring lines starting with '#'. Returns NULL on error or EOF. and ignoring lines starting with '#'. Returns NULL on error or EOF.
@@ -46,7 +46,8 @@ public:
char * read_next_line (); char * read_next_line ();
private: private:
FILE * const _fp; /* FILE pointer to the input stream. */ /* FILE pointer to the input stream. */
FILE * const _fp;
}; };
#ifdef __OPTIMIZE__ #ifdef __OPTIMIZE__

View File

@@ -25,6 +25,13 @@
//#include <stdio.h> //#include <stdio.h>
//#include "getline.h" //#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, /* Reads the next line and returns it, excluding the terminating newline,
and ignoring lines starting with '#'. Returns NULL on error or EOF. and ignoring lines starting with '#'. Returns NULL on error or EOF.
The storage for the string is dynamically allocated and must be freed The storage for the string is dynamically allocated and must be freed