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.
23 #include <ctype.h> // isspace()
24 #include <Misc/fgstream.hxx>
26 fg_gzifstream::fg_gzifstream()
31 //-----------------------------------------------------------------------------
33 // Open a possibly gzipped file for reading.
35 fg_gzifstream::fg_gzifstream( const string& name, ios_openmode io_mode )
38 this->open( name, io_mode );
41 //-----------------------------------------------------------------------------
43 // Attach a stream to an already opened file descriptor.
45 fg_gzifstream::fg_gzifstream( int fd, ios_openmode io_mode )
48 gzbuf.attach( fd, io_mode );
51 //-----------------------------------------------------------------------------
53 // Open a possibly gzipped file for reading.
54 // If the initial open fails and the filename has a ".gz" extension then
55 // remove the extension and try again.
56 // If the initial open fails and the filename doesn't have a ".gz" extension
57 // then append ".gz" and try again.
60 fg_gzifstream::open( const string& name, ios_openmode io_mode )
62 gzbuf.open( name.c_str(), io_mode );
63 if ( ! gzbuf.is_open() )
66 if ( s.substr( s.length() - 3, 3 ) == ".gz" )
68 // remove ".gz" suffix
69 s.replace( s.length() - 3, 3, "" );
70 // s.erase( s.length() - 3, 3 );
74 // Append ".gz" suffix
79 gzbuf.open( s.c_str(), io_mode );
84 fg_gzifstream::attach( int fd, ios_openmode io_mode )
86 gzbuf.attach( fd, io_mode );
94 skipeol( istream& in )
97 // skip to end of line.
98 while ( in.get(c) && (c != '\n' && c != '\r') )
101 #ifdef __MWERKS // -dw- need to strip line ending!
109 skipws( istream& in ) {
111 while ( in.get(c) ) {
112 #ifdef __MWERKS__ // -dw- for unix file compatibility
113 if ( ! (isspace( c ) ) || c != '\0' || c!='\n' || c != '\r' ) {
115 if ( ! isspace( c ) ) {
117 // put pack the non-space character
126 skipcomment( istream& in )
134 if ( in.get( c ) && c != '#' )