-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.cpp
74 lines (64 loc) · 1.9 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
#include <unistd.h>
#include <iostream>
#include <string>
#include "issw_config.h"
#include "input_source_controller.h"
enum RunMode { RM_showSelected, RM_listAvailable, RM_showUsage, RM_showVersion, RM_skip };
int
main(int argc, char* argv[]) {
// Workaround from http://lists.apple.com/archives/carbon-dev/2008/Sep/msg00009.html
//
ReceiveNextEvent(0, NULL, 0, 0, NULL);
RunMode runMode = RM_showSelected;
int ch;
while ((ch = getopt(argc, argv, "hlV")) != -1) {
switch (ch) {
case 'l':
runMode = RM_listAvailable;
break;
case 'V':
runMode = RM_showVersion;
break;
case 'h':
case '?':
default:
runMode = RM_showUsage;
}
}
InputSourceController ctrl;
if (optind < argc) {
argc -= optind;
argv += optind;
if (argc == 1) {
try {
ctrl.select(std::string(argv[0]));
runMode = RM_showSelected;
}
catch (program_error& e) {
std::cerr << e.what() << std::endl;
runMode = RM_showUsage;
}
}
else {
std::cerr << "Error: too many arguments" << std::endl;
runMode = RM_showUsage;
}
}
switch (runMode) {
case RM_showSelected:
ctrl.showSelected();
break;
case RM_listAvailable:
ctrl.listAvailable();
break;
case RM_showUsage:
std::cout << "Usage: issw [-hlV] [<input-source-id>]" << std::endl;
break;
case RM_showVersion:
std::cout << "Input Source Switcher version " << InputSourceSwitcher_VERSION_MAJOR << "." << InputSourceSwitcher_VERSION_MINOR << std::endl;
break;
case RM_skip:
break;
}
return 0;
}