-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (31 loc) · 858 Bytes
/
main.cpp
File metadata and controls
35 lines (31 loc) · 858 Bytes
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
#include <iostream>
#include <fstream>
#include "lib/headers/huffman.h"
void printUsage() {
std::cout << "usage: ./huffman <-c | -d> source target" << std::endl;
exit(0);
}
int main(int argc, char *argv[]) {
if (argc != 4) {
printUsage();
}
auto option = std::string(argv[1]);
auto source = std::string(argv[2]);
auto target = std::string(argv[3]);
std::ifstream in(source, std::ifstream::binary);
std::ofstream out(target, std::ofstream::binary);
if (!in.is_open() || !out.is_open()) {
std::cout << "File opening error\n";
return 0;
}
if (option == "-c") {
Huffman::compress(in, out);
} else if (option == "-d") {
if (!Huffman::decompress(in, out)) {
std::cout << "File invalid!\n";
}
} else {
printUsage();
}
return 0;
}