diff --git a/ChangeLog b/ChangeLog index 90ecc7e..5cb12c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2002-10-03 Bruno Haible + * src/read-line.h (Read_Line::read_next_line): Renamed from + Read_Line::get_line. + * src/read-line.icc: Likewise. + * src/read-line.cc: Update. + * src/key-list.cc: Update. + * lib/getline.h: New file. * lib/getline.cc: New file. * lib/Makefile.in (OBJECTS): Add getline.o. diff --git a/src/key-list.cc b/src/key-list.cc index a6373cf..ee9b115 100644 --- a/src/key-list.cc +++ b/src/key-list.cc @@ -354,7 +354,7 @@ Key_List::read_keys (void) set_output_types (); /* Oops, problem with the input file. */ - if (! (ptr = Read_Line::get_line ())) + if (! (ptr = Read_Line::read_next_line ())) { fprintf (stderr, "No words in input file, did you forget to prepend %s or use -t accidentally?\n", "%%"); exit (1); @@ -369,7 +369,7 @@ Key_List::read_keys (void) head = parse_line (ptr, delimiter); for (temp = head; - (ptr = Read_Line::get_line ()) && strcmp (ptr, "%%"); + (ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%"); temp = temp->next) { temp->next = parse_line (ptr, delimiter); diff --git a/src/read-line.cc b/src/read-line.cc index 4cce91c..d21eae8 100644 --- a/src/read-line.cc +++ b/src/read-line.cc @@ -21,9 +21,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include "read-line.h" -#include -#include /* declares memcpy() */ - #ifndef __OPTIMIZE__ #define INLINE /* not inline */ diff --git a/src/read-line.h b/src/read-line.h index 8f036ad..6bf3c52 100644 --- a/src/read-line.h +++ b/src/read-line.h @@ -22,23 +22,29 @@ You should have received a copy of the GNU General Public License along with GNU GPERF; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ -/* Returns a pointer to an arbitrary length string. Returns NULL on error or EOF - The storage for the string is dynamically allocated by new. */ - #ifndef read_line_h #define read_line_h 1 #include #include "getline.h" +/* An instance of this class is used for repeatedly reading lines of text + from an input stream. */ class Read_Line { +public: + + /* Initializes the instance with a given input stream. */ + Read_Line (FILE *stream = stdin) : 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 + through delete[]. */ + char *read_next_line (void); + private: FILE *fp; /* FILE pointer to the input stream. */ - -public: - Read_Line (FILE *stream = stdin) : fp (stream) {} - char *get_line (void); }; #ifdef __OPTIMIZE__ diff --git a/src/read-line.icc b/src/read-line.icc index c4ea9a6..fd8bbdd 100644 --- a/src/read-line.icc +++ b/src/read-line.icc @@ -23,9 +23,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ //#include //#include "getline.h" -/* Returns the "next" line, ignoring comments beginning with '#'. */ +/* 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 + through delete[]. */ INLINE char * -Read_Line::get_line (void) +Read_Line::read_next_line (void) { int c; @@ -45,7 +48,7 @@ Read_Line::get_line (void) char *line = (char *)0; size_t linesize = 0; - int length = ::get_line (&line, &linesize, fp); + int length = get_line (&line, &linesize, fp); if (length < 0) { delete[] line;