// (Log is kept at end of this file)
#include <ctype.h> // isspace()
-#include "fgstream.hxx"
+#include <Misc/fgstream.hxx>
+
+fg_gzifstream::fg_gzifstream()
+ : istream(&gzbuf)
+{
+}
//-----------------------------------------------------------------------------
//
// Open a possibly gzipped file for reading.
//
-fg_gzifstream::fg_gzifstream( const string& name, int io_mode )
+fg_gzifstream::fg_gzifstream( const string& name, ios_openmode io_mode )
+ : istream(&gzbuf)
{
- open( name, io_mode );
+ this->open( name, io_mode );
+}
+
+//-----------------------------------------------------------------------------
+//
+// Attach a stream to an already opened file descriptor.
+//
+fg_gzifstream::fg_gzifstream( int fd, ios_openmode io_mode )
+ : istream(&gzbuf)
+{
+ gzbuf.attach( fd, io_mode );
}
//-----------------------------------------------------------------------------
// then append ".gz" and try again.
//
void
-fg_gzifstream::open( const string& name, int io_mode )
+fg_gzifstream::open( const string& name, ios_openmode io_mode )
{
- gzstream.open( name.c_str(), io_mode );
- if ( gzstream.fail() )
+ gzbuf.open( name.c_str(), io_mode );
+ if ( ! gzbuf.is_open() )
{
string s = name;
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
{
}
// Try again.
- gzstream.open( s.c_str(), io_mode );
+ gzbuf.open( s.c_str(), io_mode );
}
}
-//-----------------------------------------------------------------------------
+void
+fg_gzifstream::attach( int fd, ios_openmode io_mode )
+{
+ gzbuf.attach( fd, io_mode );
+}
+
//
-// Remove whitespace characters from the stream.
+// 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&
-fg_gzifstream::eat_whitespace()
+skipws( istream& in )
{
char c;
- while ( gzstream.get(c) )
+ while ( in.get(c) )
{
if ( ! isspace( c ) )
{
// put pack the non-space character
- gzstream.putback(c);
+ in.putback(c);
break;
}
}
- return gzstream;
+ return in;
}
-//-----------------------------------------------------------------------------
-//
-// Remove whitspace chatacters and comment lines from a stream.
-//
istream&
-fg_gzifstream::eat_comments()
+skipcomment( istream& in )
{
- for (;;)
+ while ( in )
{
// skip whitespace
- eat_whitespace();
+ in >> skipws;
char c;
- gzstream.get( c );
- if ( c != '#' )
+ if ( in.get( c ) && c != '#' )
{
// not a comment
- gzstream.putback(c);
+ in.putback(c);
break;
}
-
- // skip to end of line.
- while ( gzstream.get(c) && c != '\n' )
- ;
+ in >> skipeol;
}
- return gzstream;
+ return in;
}
-
// $Log$
+// Revision 1.3 1998/11/06 14:05:12 curt
+// More portability improvements by Bernie Bright.
+//
+// Revision 1.2 1998/09/24 15:22:17 curt
+// Additional enhancements.
+//
// Revision 1.1 1998/09/01 19:06:29 curt
// Initial revision.
//