-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
62 lines (58 loc) · 1.13 KB
/
Main.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
#include <iostream>
#include "Huffman/Compressor.h"
#include "Huffman/Decompressor.h"
void printUsage()
{
std::cout << "Usage:\ncompress: -c in out \ndecompress: -d in out" << "\n";
}
int main(int argc, char* argv[])
{
bool compress = true;
std::string inputFile;
std::string outputFile;
if (argc == 4)
{
std::string first = argv[1];
if (first == "-c")
compress = true;
else
if (first == "-d")
compress = false;
else
{
std::cerr << "Invalid first parameter\n";
printUsage();
return 0;
}
inputFile = argv[2];
outputFile = argv[3];
}
else
{
printUsage();
return 0;
}
if (compress)
try
{
Huffman::Compressor compressor(inputFile);
compressor.compressTo(outputFile);
std::cout << "Compression succesful!" << "\n";
}
catch (const std::exception & e)
{
std::cerr << "Compression failed: " << e.what() << "\n";
}
else
try
{
Huffman::Decompressor decompressor(inputFile);
decompressor.decompressTo(outputFile);
std::cout << "Decompression succesful!" << "\n";
}
catch (const std::exception & e)
{
std::cerr << "Decompression failed: " << e.what() << "\n";
}
return 0;
}