-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
94 lines (79 loc) · 2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Project name: Huffman Coding
Project version: 1.0
File name: main.cpp
Project description: David Huffman algorithm based text files encoding/decoding script
Created by Michał Grochowski on 20 Feb 2022.
Copyright © 2022 Michał Grochowski. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <iostream>
#include <string>
//
#include "code.hpp"
// defining possible to obtain cases
enum option { ENCODE, DECODE, UNDEFINED };
void UsageDescrip() {
std::cout << "Possible script options:"
<< "\n"
<< "--encode"
<< "\n"
<< "--decode"
<< "\n"
<< "\n"
<< "Usage example:"
<< "\n"
<< "./huff --encode sample_text_file.txt -o encoded_sample_text_file.txt"
<< "\n"
<< "./huff --decode encoded_sample_text_file.txt -o decoded_sample_text_file.txt"
<< std::endl;
}
option getOptionForArgument(const std::string &argument) {
if (argument == "--encode") {
return ENCODE;
}
if (argument == "--decode") {
return DECODE;
}
return UNDEFINED;
}
#include "vector.hpp"
#include <cstdint>
int main(int argc, char *argv[]) {
if (argc < 5) {
// if there is not enough number of arguments -> above defined function is printing the usage description
UsageDescrip();
return 1;
}
const std::string option = argv[1];
const std::string inputFile = argv[2];
const std::string outputArgument = argv[3];
const std::string outputFile = argv[4];
// argument 3 ( argv[3] ) has to be -o
if (outputArgument != "-o") {
UsageDescrip();
return 1;
}
// initialization of possible to obtain cases
HuffCode j = HuffCode();
switch (getOptionForArgument(option)) {
case ENCODE:
j.fileEncode(inputFile, outputFile);
break;
case DECODE:
j.fileDecode(inputFile, outputFile);
break;
case UNDEFINED:
UsageDescrip();
return 1;
}
return 0;
}