-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
105 lines (97 loc) · 2.54 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
95
96
97
98
99
100
101
102
103
104
105
/* Jmeno: Petr Kubat
* Login: xkubat11
* Datum: 11.05.2014
* Nazev: main.cpp
* Popis: Cast programu slouzici pro volani funkci pro kompresi a
* dekompresi souboru.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#include <iostream>
#include <string>
#include <fstream>
#include "bwted.hpp"
using namespace std;
int main(int argc, char **argv) {
string inputf = "";
string outputf = "";
string logf = "";
string helpstr;
helpstr = "Usage: bwted [-i inputfile] [-o outputfile] [-l logfile] ";
helpstr += "-c/-x [-h]\n";
helpstr += "Arguments: \n";
helpstr += " -i: inputfile, if not used will read from stdin\n";
helpstr += " -o: outputfile, if not used will write to stdout\n";
helpstr += " -l: logfile for log output, if not used will skip\n";
helpstr += " -c: the appliaction will compress input\n";
helpstr += " -x: the appliaction will extract intput\n";
helpstr += " -h: prints this help message\n";
tBWTED logstruct;
logstruct.uncodedSize = 0;
logstruct.codedSize = 0;
int opt;
// compression/extraction flags
uint8_t comp = 0;
uint8_t ext = 0;
FILE *fp;
FILE *fo;
// get args
while ((opt = getopt(argc, argv, "i:o:l:cxh")) != -1) {
switch (opt) {
case 'i':
inputf = optarg;
break;
case 'o':
outputf = optarg;
break;
case 'l':
logf = optarg;
break;
case 'c':
comp = 1;
break;
case 'x':
ext = 1;
break;
case 'h':
cout << helpstr;
return (EXIT_SUCCESS);
default:
cout << helpstr;
return (EXIT_FAILURE);
}
}
// cannot compress and extract at the same time
if (comp == ext) {
cout << helpstr;
return (EXIT_FAILURE);
}
if (inputf == "")
fp = stdin;
else
fp = fopen(inputf.c_str(), "rb");
if (outputf == "")
fo = stdout;
else
fo = fopen(outputf.c_str(), "wb");
if (comp)
BWTEncoding(&logstruct, fp, fo);
else
BWTDecoding(&logstruct, fp, fo);
// write log into file
if (logf != "") {
ofstream logs;
logs.open (logf);
logs << "login = xkubat11" << endl;
logs << "unCodedSize = " << logstruct.uncodedSize << endl;
logs << "codedSize = " << logstruct.codedSize << endl;
logs.close();
}
fclose (fp);
fclose (fo);
return 0;
}