-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (46 loc) · 1.42 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
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include"./include/tree/prefix-tree.hpp"
#include"./include/tree/node.hpp"
#include"./include/compressor.hpp"
int main(int argc, char const* argv[]){
if(argc < 3){
std::cout << "Not enough arguments...\n";
exit(1);
}
std::string input_file_name(argv[2]);
std::string output_file_name;
std::stringstream output_file_name_stream;
if(argc >= 4){
output_file_name = std::string(argv[3]);
}
else{
int name_slice_pos = input_file_name.find_last_of('.');
output_file_name_stream << input_file_name.substr(0, name_slice_pos);
}
if(strncmp(argv[1], "-c", 3) == 0){
if(argc < 4){
output_file_name_stream << ".z78";
output_file_name = output_file_name_stream.str();
}
std::cout << "compressing...\t\n";
smal::Compressor::compress(input_file_name, output_file_name);
std::cout << "\bdone!\n";
}
else if(strncmp(argv[1], "-x", 3) == 0){
if(argc < 4){
output_file_name_stream << ".txt";
output_file_name = output_file_name_stream.str();
}
std::cout << "decompressing...\t\n";
smal::Compressor::decompress(input_file_name, output_file_name);
std::cout << "\bdone!\n";
}
else{
std::cout << "Unknown option " << argv[1] << "\n";
exit(1);
}
return 0;
}