-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
65 lines (59 loc) · 1.41 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <fstream>
#include <string.h>
#include "huff.h"
void help()
{
printf("------------\n");
printf(" Hufzip\n");
printf(" v1.0.0\n");
printf("------------\n");
printf("-h\t\t\t\tShow help and exit.\n");
printf("-c (filename)\tCompress the specified file.\n");
printf("-d (filename)\tDecompress the specified file.\n");
}
void notRecognized()
{
printf("Comando não reconhecido. Experimente adicionar algum dos parâmetros mostrados na ajuda.\n");
help();
}
int main(int argc, char* argv[])
{
if (argc == 1)
{
help();
return 0;
}
for(int i = 0; i < argc; i++)
{
if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0)
{
help();
return 0;
}
Huff* huff = new Huff();
if(strcmp(argv[i], "-c") == 0)
{
if ((i + 1) < argc)
{
string filename = (string)argv[i + 1];
huff->compress(filename);
}
else
{
notRecognized();
}
}
else if(strcmp(argv[i], "-d") == 0)
{
if ((i + 1) < argc)
{
string filename = (string)argv[i + 1];
huff->expand(filename);
}
else
{
notRecognized();
}
}
}
}