-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (52 loc) · 1.62 KB
/
main.cpp
File metadata and controls
61 lines (52 loc) · 1.62 KB
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
/**
* Created by Zakharov Sergey (aka Zakhse),
* Student of NRU HSE, the Faculty of Computer Science, Software Engineering
*
* 2k16, November
*/
#include "for_debug.h"
#include <iostream>
#include <fstream>
#include <locale>
#include <chrono>
#include <bitset>
int main(int argc, char* argv[])
{
std::setlocale(LC_ALL, "");
// Title of table:
// file.txt | compress huff ops | compress shan ops| decompress huff ops| decompress shan ops
dbg if (argc == 3 && std::string(argv[1]) == "debug")
{
test_table(std::string(argv[2]));
return 0;
}
if ((argc != 3 && argc != 4) || (argc == 4 && argv[1] == "decompress"))
{
std::cout << "Usage of arguments: MODE ALGORITHM PATH\n" <<
"MODE - compress/decompress\n" <<
"ALGORITHM - H for Huffman or SF for Shannon-Fano (only use it for compressing)\n" <<
"PATH - path to file.txt with UTF-8 to compress it or to file.huff/file.shan to decompress it\n";
return 0;
}
if (std::string(argv[1]) == "compress")
{
if (std::string(argv[2]) == "H")
{
compress(std::string(argv[3]), compression_algorithm::HUFFMAN);
}
else if (std::string(argv[2]) == "SF")
{
compress(std::string(argv[3]), compression_algorithm::SHANNON_FANO);
}
else
{
std::cout << "Wrong usage!\n";
return 0;
}
}
else if (std::string(argv[1]) == "decompress")
decompress(std::string(argv[2]));
else
std::cout << "Wrong usage!\n";
dbg std::cout << "Number of steps: " << Counter::get() << "\n";
}