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()
25 #include "fgstream.hxx"
27 fg_gzifstream::fg_gzifstream()
32 //-----------------------------------------------------------------------------
34 // Open a possibly gzipped file for reading.
36 fg_gzifstream::fg_gzifstream( const string& name, ios_openmode io_mode )
39 this->open( name, io_mode );
42 //-----------------------------------------------------------------------------
44 // Attach a stream to an already opened file descriptor.
46 fg_gzifstream::fg_gzifstream( int fd, ios_openmode io_mode )
49 gzbuf.attach( fd, io_mode );
52 //-----------------------------------------------------------------------------
54 // Open a possibly gzipped file for reading.
55 // If the initial open fails and the filename has a ".gz" extension then
56 // remove the extension and try again.
57 // If the initial open fails and the filename doesn't have a ".gz" extension
58 // then append ".gz" and try again.
61 fg_gzifstream::open( const string& name, ios_openmode io_mode )
63 gzbuf.open( name.c_str(), io_mode );
64 if ( ! gzbuf.is_open() )
67 if ( s.substr( s.length() - 3, 3 ) == ".gz" )
69 // remove ".gz" suffix
70 s.replace( s.length() - 3, 3, "" );
71 // s.erase( s.length() - 3, 3 );
75 // Append ".gz" suffix
80 gzbuf.open( s.c_str(), io_mode );
85 fg_gzifstream::attach( int fd, ios_openmode io_mode )
87 gzbuf.attach( fd, io_mode );
95 skipeol( istream& in )
98 // skip to end of line.
101 while ( in.get(c) && c != '\0' ) {
103 while ( in.get(c) ) {
105 if ( (c == '\n') || (c == '\r') ) {
114 skipws( istream& in ) {
117 while ( in.get(c) && c != '\0' ) {
119 while ( in.get(c) ) {
123 if ( ! isspace( c ) && c != '\n' ) {
125 if ( ! isspace( c ) ) {
127 // put pack the non-space character
136 skipcomment( istream& in )
148 if ( in.get( c ) && c != '#' )