-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
44 lines (38 loc) · 996 Bytes
/
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
/*!
\file
\brief Îñíîâíîé ôàéë, ñîäåðæàùèé main()
*/
#include "Haffman Algorithm.h"
#include <iostream>
int check_task(char* argv[]) {
if (!argv[1] || !argv[2] || argv[1] == 0 || argv[2] == 0)
return 0;
else {
if (strcmp(argv[2], "-en") == 0 || strcmp(argv[2], "-encode") == 0)
return 1;
else {
if (strcmp(argv[2], "-de") == 0 || strcmp(argv[2], "-decode") == 0)
return -1;
else
return 0;
}
}
}
int main(int argc, char* argv[]) {
int task_id;
if ((task_id = check_task(argv)) == 0) {
std::cout << "\n Usage: HaffmansAlgorithm <filename> [-en | -encode | -de | -decode]\n";
return -1;
}
std::cout << "\n\t HAFFMAN'S CODE";
std::string name(argv[1]);
if (task_id == 1) {
if (!pack(name))
return -2;
}
if (strcmp(argv[2], "-de") == 0) {
if (!unpack(name))
return -2;
}
return 0;
}