-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
80 lines (67 loc) · 1.45 KB
/
main.cc
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
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
inline constexpr string_view version = "hirocc v0.0";
auto help() -> void {
cout << version << endl <<
"\n"
"Usage:\n"
" hirocc [options] [targets]\n"
"\n"
"Options:\n"
" -h: show this help\n"
" -v: show version\n"
"\n";
}
auto ver() -> void {
cout << version << endl;
}
auto main(int argc, char* argv[]) -> int {
vector<string> args{argv + 1, argv + argc};
vector<string> opts;
vector<string> paths;
for(size_t i = 0; i < args.size(); i++) {
auto arg = args[i];
if(arg[0] == '-') {
opts.push_back(arg);
} else {
paths.push_back(arg);
}
}
if(find(opts.begin(), opts.end(), "-h") != opts.end()) {
help();
return 0;
}
if(find(opts.begin(), opts.end(), "-v") != opts.end()) {
ver();
return 0;
}
if(!paths.size()) {
help();
return 1;
}
size_t errn = 0;
string buf;
for(auto path: paths) {
if(!filesystem::exists(path)) {
cerr << "File not found: "s << path << endl;
errn++;
continue;
}
ifstream fin{path};
cout << "----"s << path << "----"s << endl;
while(getline(fin, buf)) {
cout << buf << endl;
}
cout << "----"s << path << "----"s << endl;
}
if(errn) {
cerr << "There are "s << errn << " errors."s << endl;
return 1;
}
cout << "done"s << endl;
}