forked from pjmikkol/bwtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuncompress.cpp
103 lines (88 loc) · 2.85 KB
/
uncompress.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* @file uncompress.cpp
* @author Pekka Mikkola <[email protected]>
*
* @section LICENSE
*
* This file is part of bwtc.
*
* bwtc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* bwtc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bwtc. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
* Main program for decompression.
*/
/**Needed for allocating space for the bwtc::verbosity. */
#define MAIN
/* bwtc-decompressor main program */
#include <iostream>
#include <iterator>
#include <algorithm>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include "preprocessors/Postprocessor.hpp"
#include "EntropyCoders.hpp"
#include "Streams.hpp"
#include "globaldefs.hpp"
#include "bwtransforms/InverseBWT.hpp"
#include "Profiling.hpp"
#include "Decompressor.hpp"
using bwtc::verbosity;
int main(int argc, char** argv) {
std::string input_name, output_name;
bool stdout, stdin;
try {
po::options_description description(
"usage: "DECOMPRESSOR" [options] inputfile outputfile\n\nOptions");
description.add_options()
("help,h", "print help message")
("stdin,i", "input from standard in")
("stdout,c", "output to standard out")
("verb,v", po::value<int>(&verbosity)->default_value(0),
"verbosity level")
("input-file", po::value<std::string>(&input_name),
"file to decompress")
("output-file", po::value<std::string>(&output_name),
"target file")
;
/* Allow input files given in user friendly form (without "--*put-file") */
po::positional_options_description pos;
pos.add("input-file", 1);
pos.add("output-file",1);
po::variables_map varmap;
po::store(po::command_line_parser(argc, argv).options(description).
positional(pos).run(), varmap);
po::notify(varmap);
if (varmap.count("help")) {
std::cout << description << std::endl;
return 1;
}
stdout = varmap.count("stdout") != 0;
stdin = varmap.count("stdin") != 0;
} /* try-block */
catch(std::exception& e) {
std::cerr << "error: " << e.what() << std::endl;
return 1;
}
catch(...) {
std::cerr << "Exception of unknown type!" << std::endl;
return 1;
}
if (stdout) output_name = "";
if (stdin) input_name = "";
bwtc::Decompressor decompressor(input_name, output_name);
decompressor.decompress(1);
PRINT_PROFILE_DATA
return 0;
}