libStatGen Software 1
UncompressedFileType.cpp
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "UncompressedFileType.h"
19#include <string.h>
20
21UncompressedFileType::UncompressedFileType(const char * filename,
22 const char * mode)
23 : filePtr(NULL),
24 kfilePtr(NULL),
25 keof(false)
26{
27 // Check if opening for read.
28 if((mode[0] == 'r') || (mode[0] == 'R'))
29 {
30 if(strcmp(filename, "-") == 0)
31 {
32 // read from stdin
33 filePtr = stdin;
34 }
35 else if((strstr(filename, "ftp://") == filename) ||
36 (strstr(filename, "http://") == filename))
37 {
38 // Reading http/ftp, so open the file using knetfile.
39 kfilePtr = knet_open(filename, mode);
40 }
41 else
42 {
43 // Open the file.
44 filePtr = fopen(filename, mode);
45 }
46 }
47 else
48 {
49 // Not for read.
50 // If the file is for write and is '-', then write to stdout.
51 if(((mode[0] == 'w') || (mode[0] == 'W')) &&
52 (strcmp(filename, "-") == 0))
53 {
54 // Write to stdout.
55 filePtr = stdout;
56 }
57 else
58 {
59 // Open the file.
60 filePtr = fopen(filename, mode);
61 }
62 }
63};
64
65