From 605ad52197a73e902d43ec8031733c325eac2e3e Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 24 Sep 1998 15:22:17 +0000 Subject: [PATCH] Additional enhancements. --- Misc/fgstream.cxx | 68 +++++++++++++++++++++++++++++++++++++++++++++-- Misc/fgstream.hxx | 16 +++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/Misc/fgstream.cxx b/Misc/fgstream.cxx index 32c69192..60887c17 100644 --- a/Misc/fgstream.cxx +++ b/Misc/fgstream.cxx @@ -33,6 +33,15 @@ fg_gzifstream::fg_gzifstream( const string& name, int io_mode ) open( name, io_mode ); } +//----------------------------------------------------------------------------- +// +// Attach a stream to an already opened file descriptor. +// +fg_gzifstream::fg_gzifstream( int fd, int io_mode ) + : gzstream( fd, io_mode ) +{ +} + //----------------------------------------------------------------------------- // // Open a possibly gzipped file for reading. @@ -51,7 +60,8 @@ fg_gzifstream::open( const string& name, int io_mode ) if ( s.substr( s.length() - 3, 3 ) == ".gz" ) { // remove ".gz" suffix - s.erase( s.length() - 3, 3 ); + s.replace( s.length() - 3, 3, "" ); +// s.erase( s.length() - 3, 3 ); } else { @@ -106,14 +116,68 @@ fg_gzifstream::eat_comments() } // skip to end of line. - while ( gzstream.get(c) && c != '\n' ) + while ( gzstream.get(c) && (c != '\n' && c != '\r') ) ; } return gzstream; } +// +// Manipulators +// + +istream& +skipeol( istream& in ) +{ + char c = 0; + // skip to end of line. + while ( in.get(c) && (c != '\n' && c != '\r') ) + ; + + // \r\n ? + return in; +} + +istream& +skipws( istream& in ) +{ + char c; + while ( in.get(c) ) + { + if ( ! isspace( c ) ) + { + // put pack the non-space character + in.putback(c); + break; + } + } + return in; +} + +istream& +skipcomment( istream& in ) +{ + while ( in ) + { + // skip whitespace + in >> skipws; + + char c; + if ( in.get( c ) && c != '#' ) + { + // not a comment + in.putback(c); + break; + } + in >> skipeol; + } + return in; +} // $Log$ +// Revision 1.2 1998/09/24 15:22:17 curt +// Additional enhancements. +// // Revision 1.1 1998/09/01 19:06:29 curt // Initial revision. // diff --git a/Misc/fgstream.hxx b/Misc/fgstream.hxx index f9f74b6a..46cd6e5d 100644 --- a/Misc/fgstream.hxx +++ b/Misc/fgstream.hxx @@ -50,6 +50,9 @@ public: fg_gzifstream( const string& name, int io_mode = ios::in|ios::binary ); + // + fg_gzifstream( int fd, int io_mode = ios::in|ios::binary ); + // Attempt to open a file with and without ".gz" extension. void open( const string& name, int io_mode = ios::in|ios::binary ); @@ -86,9 +89,22 @@ private: fg_gzifstream( const fg_gzifstream& ); }; +// istream manipulator that skips to end of line. +istream& skipeol( istream& in ); + +// istream manipulator that skips over white space. +istream& skipws( istream& in ); + +// istream manipulator that skips comments and white space. +// A comment starts with '#'. +istream& skipcomment( istream& in ); + #endif /* _FGSTREAM_HXX */ // $Log$ +// Revision 1.2 1998/09/24 15:22:18 curt +// Additional enhancements. +// // Revision 1.1 1998/09/01 19:06:29 curt // Initial revision. // -- 2.39.5