libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include "UncompressedFileType.h" 00019 #include <string.h> 00020 00021 UncompressedFileType::UncompressedFileType(const char * filename, 00022 const char * mode) 00023 : filePtr(NULL), 00024 kfilePtr(NULL), 00025 keof(false) 00026 { 00027 // Check if opening for read. 00028 if((mode[0] == 'r') || (mode[0] == 'R')) 00029 { 00030 if(strcmp(filename, "-") == 0) 00031 { 00032 // read from stdin 00033 filePtr = stdin; 00034 } 00035 else if((strstr(filename, "ftp://") == filename) || 00036 (strstr(filename, "http://") == filename)) 00037 { 00038 // Reading http/ftp, so open the file using knetfile. 00039 kfilePtr = knet_open(filename, mode); 00040 } 00041 else 00042 { 00043 // Open the file. 00044 filePtr = fopen(filename, mode); 00045 } 00046 } 00047 else 00048 { 00049 // Not for read. 00050 // If the file is for write and is '-', then write to stdout. 00051 if(((mode[0] == 'w') || (mode[0] == 'W')) && 00052 (strcmp(filename, "-") == 0)) 00053 { 00054 // Write to stdout. 00055 filePtr = stdout; 00056 } 00057 else 00058 { 00059 // Open the file. 00060 filePtr = fopen(filename, mode); 00061 } 00062 } 00063 }; 00064 00065