-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (54 loc) · 1.42 KB
/
main.cpp
File metadata and controls
58 lines (54 loc) · 1.42 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
/*
* main.cpp
*
* Created on: 2016Äê8ÔÂ18ÈÕ
* Author: zhenlin
*/
#include"HuffmanCode.h"
#include<iostream>
#include<fstream>
#include<string>
#include<cstring> // for strcmp
#include<ctime>
#include<iomanip> // for setprecision
using namespace std;
bool DoesFileExist(char *path){
ifstream is(path);
if(!is)return false;
else return true;
}
int main(int argc, char *argv[])
{
if(argc != 4 || (strcmp(argv[1],"-c") && strcmp(argv[1],"-x"))){
cout << "\nUsage:\n\n"
<< "-c for creating a compressed file\n\t"
<< argv[0] << " -c original_file_path compressed_file_path\n\n"
<< "-x for extracting a file from the compressed file\n\t"
<< argv[0] << " -x compressed_file_path decompressed_file_path\n";
return 0;
}
if(strcmp(argv[1],"-c") == 0){
if(DoesFileExist(argv[2])){
time_t start, end;
start = clock();
HuffmanCode hc;
hc.Compress(argv[2], argv[3]);
end = clock();
cout << "Done! time: " << setprecision(2) << (end - start) / CLOCKS_PER_SEC << " seconds\n";
}else{
cout << "Error: " << argv[2] <<" doesn't exist!\n";
}
}else if(strcmp(argv[1],"-x") == 0){
if(DoesFileExist(argv[2])){
time_t start, end;
start = clock();
HuffmanCode hc;
hc.Decompress(argv[2], argv[3]);
end = clock();
cout << "Done! time: " << setprecision(2) << (end - start) / CLOCKS_PER_SEC << " seconds\n";
}else{
cout << "Error: " << argv[2] <<" doesn't exist!\n";
}
}
return 0;
}