-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranger-explorer.cpp
71 lines (64 loc) · 1.42 KB
/
ranger-explorer.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
#include <iostream>
#include "ranger.h"
void help()
{
std::cout <<
"Commands:\n"
"+ START END add range [START,END)\n"
"- START END remove range [START,END)\n"
"q quit\n"
"p print current set of ranges\n"
"?/h print this help\n"
"\n";
}
void print(const ranger &r) { std::cout << r << "\n\n"; }
int update(ranger &r, char mode)
{
int start, end;
if (std::cin >> start >> end) {
if (start >= end) {
std::cout << "must specify START < END\n";
} else {
if (mode == '+') {
r.insert({start, end});
} else {
r.erase({start, end});
}
}
} else {
return -1;
}
return 0;
}
int main()
{
ranger r;
char c;
help();
while (std::cin >> c) {
switch (c) {
case '-':
case '+':
if (update(r, c) < 0)
return 1;
print(r);
break;
case 'p':
print(r);
break;
case 'q':
return 0;
case 'h':
case '?':
help();
break;
case '\n':
case ' ':
continue;
default:
std::cout << "Command '" << c << "' not understood\n\n";
help();
}
}
std::cout << "Goodbye!\n";
}