-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (58 loc) · 1.39 KB
/
main.cpp
File metadata and controls
67 lines (58 loc) · 1.39 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
#include <iostream>
#include <cstdint>
#include <vector>
#include <fstream>
#include <sstream>
#include "BitBuffer.h"
#include "Matrix.h"
#include "Hamming_encoded_block.h"
#include "StreamEncoder.h"
#include "FileInterface.h"
#include "StdInputInterface.h"
using namespace std;
void show_syntax(const string &progName){
cout << "Usage: " << progName << " file|terminal [<src_filename> <dst_filename> encode|decode]" << endl;
cout << "Example 1: " << progName << " file input.txt output.txt decode" << endl;
cout << "Example 2: " << progName << " terminal" << endl;
}
int main(int argc, char **argv){
if(argc < 2){
show_syntax(argv[0]);
return 0;
}
string mode(argv[1]);
if(mode == "file"){
if(argc < 5){
show_syntax(argv[0]);
return 0;
}
string srcFile(argv[2]);
string dstFile(argv[3]);
string action(argv[4]);
FileInterface fi(srcFile, dstFile);
if(action == "encode")
fi.encode();
else if(action == "decode")
fi.decode();
else{
show_syntax(argv[0]);
return 0;
}
}
else if(mode == "terminal"){
cout << "Input some text: ";
char buf[256];
cin.get(buf, 256);
string text(buf);
StdInputInterface sio1;
string encoded = sio1.encode(text);
StdInputInterface sio2;
string decoded = sio2.decode(encoded);
cout << "Encoded text: " << encoded << endl;
cout << "Decoded text: " << decoded << endl;
}
else{
show_syntax(argv[0]);
return 0;
}
}