-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (51 loc) · 1.61 KB
/
main.cpp
File metadata and controls
58 lines (51 loc) · 1.61 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
#include <string>
#include "run-length.h"
#include "dictionary.h"
#include "compare-methods.h"
#define REPS 100
int main (int argc, char *argv[])
{
if (argc < 3) {
printf("HOW TO USE:\n");
printf("\texecutable -r [file/file.rle] :"
" compress/decompress using run length encoding\n");
printf("\texecutable -d [file/file.dc] :"
" compress/decompress using dictionary encoding\n");
printf("\texecutable -t file [file2 file3...] :"
" compare coding algorithms\n");
exit(0);
}
std::string mode = (std::string) argv[1];
if (mode == "-r") {
for (int i = 2; i < argc; i++) {
std::string file = (std::string) argv[i];
std::string extension = file.substr(file.size()-4, file.size());
if (extension == ".rle")
rle::decompress(file);
else
rle::compress(file);
}
}
else if (mode == "-d") {
for (int i = 2; i < argc; i++) {
std::string file = (std::string) argv[i];
std::string extension = file.substr(file.size()-3, file.size());
if (extension == ".dc")
dict::decompress(file);
else {
dict::compress(file);
printf("Do not erase the .dic file,"
" you will need it to decompress\n");
}
}
}
else if (mode == "-t") {
for (int i = 2; i < argc; i++) {
compare_methods(argv[i]);
}
}
else {
printf("Error: not a valid parameter\n");
}
return 0;
}