1 // zlib input file stream wrapper.
3 // Written by Bernie Bright, 1998
5 // Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 // (Log is kept at end of this file)
24 #include <ctype.h> // isspace()
25 #include "fgstream.hxx"
27 //-----------------------------------------------------------------------------
29 // Open a possibly gzipped file for reading.
31 fg_gzifstream::fg_gzifstream( const string& name, int io_mode )
33 open( name, io_mode );
36 //-----------------------------------------------------------------------------
38 // Attach a stream to an already opened file descriptor.
40 fg_gzifstream::fg_gzifstream( int fd, int io_mode )
41 : gzstream( fd, io_mode )
45 //-----------------------------------------------------------------------------
47 // Open a possibly gzipped file for reading.
48 // If the initial open fails and the filename has a ".gz" extension then
49 // remove the extension and try again.
50 // If the initial open fails and the filename doesn't have a ".gz" extension
51 // then append ".gz" and try again.
54 fg_gzifstream::open( const string& name, int io_mode )
56 gzstream.open( name.c_str(), io_mode );
57 if ( gzstream.fail() )
60 if ( s.substr( s.length() - 3, 3 ) == ".gz" )
62 // remove ".gz" suffix
63 s.replace( s.length() - 3, 3, "" );
64 // s.erase( s.length() - 3, 3 );
68 // Append ".gz" suffix
73 gzstream.open( s.c_str(), io_mode );
77 //-----------------------------------------------------------------------------
79 // Remove whitespace characters from the stream.
82 fg_gzifstream::eat_whitespace()
85 while ( gzstream.get(c) )
89 // put pack the non-space character
97 //-----------------------------------------------------------------------------
99 // Remove whitspace chatacters and comment lines from a stream.
102 fg_gzifstream::eat_comments()
118 // skip to end of line.
119 while ( gzstream.get(c) && (c != '\n' && c != '\r') )
130 skipeol( istream& in )
133 // skip to end of line.
134 while ( in.get(c) && (c != '\n' && c != '\r') )
142 skipws( istream& in )
147 if ( ! isspace( c ) )
149 // put pack the non-space character
158 skipcomment( istream& in )
166 if ( in.get( c ) && c != '#' )
178 // Revision 1.2 1998/09/24 15:22:17 curt
179 // Additional enhancements.
181 // Revision 1.1 1998/09/01 19:06:29 curt