-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (43 loc) · 1.22 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (43 loc) · 1.22 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
#include <iostream>
#include <vector>
#include <stdexcept>
#include "unpacker.h"
#include "packer.h"
using namespace std;
int main(int argc, char **argv) {
try {
if (argc < 3) {
cout << "Too few arguments" << endl;
return 1;
}
string first(argv[1]);
if (first == "--decompress") {
string fileName(argv[2]);
unpack(fileName);
} else {
vector<string> files;
string outputFile;
for (int i = 1; i < argc; ++i) {
string s(argv[i]);
if (s == "--compress") {
if (!outputFile.empty() || i + 1 == argc) {
cerr << "Ill-formed input." << endl;
return 1;
}
i++;
outputFile = argv[i];
} else {
files.push_back(s);
}
}
if (outputFile.empty()) {
cerr << "Ill-formed input." << endl;
return 1;
}
pack(files, outputFile);
}
} catch (const runtime_error &e) {
cerr << "Error: " << e.what() << endl;
}
return 0;
}