diff --git a/src/utils/tabFile/Makefile b/src/utils/tabFile/Makefile index 30749e6cdfcc400087575e8b6ea6a27b313e8db1..7bba86fcd2b4676724e5aecf4742f2c3f6369b50 100644 --- a/src/utils/tabFile/Makefile +++ b/src/utils/tabFile/Makefile @@ -4,7 +4,9 @@ UTILITIES_DIR = ../../utils/ # ------------------- # define our includes # ------------------- -INCLUDES = -I$(UTILITIES_DIR)/lineFileUtilities/ -I$(UTILITIES_DIR)/gzstream/ -I$(UTILITIES_DIR)/fileType/ +INCLUDES = -I$(UTILITIES_DIR)/lineFileUtilities/ \ + -I$(UTILITIES_DIR)/gzstream/ \ + -I$(UTILITIES_DIR)/fileType/ # ---------------------------------- # define our source and object files diff --git a/src/utils/tabFile/tabFile.cpp b/src/utils/tabFile/tabFile.cpp index 20153a2e043344cdea7582e9fd35a42c946fb7fa..e226a064611304b5c7c1139babaac32b2f8c29bd 100644 --- a/src/utils/tabFile/tabFile.cpp +++ b/src/utils/tabFile/tabFile.cpp @@ -25,45 +25,20 @@ TabFile::TabFile(const string &tabFile) TabFile::~TabFile(void) { } - void TabFile::Open(void) { if (_tabFile == "stdin" || _tabFile == "-") { _tabStream = &cin; } else { - size_t foundPos; - foundPos = _tabFile.find_last_of(".gz"); - // is this a GZIPPED TAB file? - if (foundPos == _tabFile.size() - 1) { - igzstream tabs(_tabFile.c_str(), ios::in); - if ( !tabs ) { - cerr << "Error: The requested file (" << _tabFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - else { - // if so, close it (this was just a test) - tabs.close(); - // now set a pointer to the stream so that we - // can read the file later on. - _tabStream = new igzstream(_tabFile.c_str(), ios::in); - } + _tabStream = new ifstream(_tabFile.c_str(), ios::in); + + if( isGzipFile(_tabStream) ) { + delete _tabStream; + _tabStream = new igzstream(_tabFile.c_str(), ios::in); } - // not GZIPPED. - else { - - ifstream tabs(_tabFile.c_str(), ios::in); - // can we open the file? - if ( !tabs ) { - cerr << "Error: The requested file (" << _tabFile << ") could not be opened. Exiting!" << endl; - exit (1); - } - else { - // if so, close it (this was just a test) - tabs.close(); - // now set a pointer to the stream so that we - // can read the file later on. - _tabStream = new ifstream(_tabFile.c_str(), ios::in); - } + if ( !(_tabStream->good()) ) { + cerr << "Error: The requested file (" << _tabFile << ") could not be opened. Exiting!" << endl; + exit (1); } } } diff --git a/src/utils/tabFile/tabFile.h b/src/utils/tabFile/tabFile.h index 4674ee9bd842c729d80f8bf58684a7546b276392..7452d44c2d47d160af832885ac562bf179194e6d 100644 --- a/src/utils/tabFile/tabFile.h +++ b/src/utils/tabFile/tabFile.h @@ -13,6 +13,7 @@ #define TABFILE_H #include "gzstream.h" +#include "fileType.h" #include <vector> #include <string> #include <iostream>