-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (72 loc) · 1.95 KB
/
Copy pathmain.cpp
File metadata and controls
82 lines (72 loc) · 1.95 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <cstring>
#include <fstream>
#include <sstream>
#include "Huffman.h"
int main(int argc, char** argv)
{
enum Mode {Comression, Decompression, Adaptive, Debug}; //Различни режими за работа с програмата
short mode = Mode::Comression;
std::string fileName, outputName;
for(int i=0; i < argc; i++)
{
if(strcmp(argv[i], "-c") == 0)
{
mode = Mode::Comression;
} else if(strcmp(argv[i], "-d") == 0)
{
mode = Mode::Decompression;
} else if(strcmp(argv[i], "-debug") == 0)
{
mode = Mode::Debug;
} else if(strcmp(argv[i], "-i") == 0)
{
fileName = argv[++i];
} else if(strcmp(argv[i], "-o") == 0)
{
outputName = argv[++i];
}
}
std::cout << fileName << " " << outputName << std::endl;
Huffman table;
switch (mode)
{
case Mode::Comression:
{
std::cout << "COMPRESSING" << std::endl;
std::ifstream iFile(fileName);
std::ofstream oFile(outputName, std::ios::binary | std::ios::out);
table.addSymbol(iFile);
table.createTree();
table.serialize(iFile, oFile);
iFile.close();
oFile.close();
break;
}
case Mode::Decompression:
{
std::cout << "DECOMPRESSING" << std::endl;
std::ifstream iFile(fileName, std::ios::binary | std::ios::in);
std::ofstream oFile(outputName);
table.deserialize(iFile, oFile);
break;
}
case Mode::Debug:
{
std::ifstream iFile(fileName);
table.addSymbol(iFile);
table.createTree();
table.printTree();
table.setDebug(true);
std::stringstream temp;
table.serialize(iFile, temp);
iFile.close();
break;
}
case Mode::Adaptive:
break;
default:
break;
}
return 0;
}