-
Notifications
You must be signed in to change notification settings - Fork 1
/
bindconfig.cpp
94 lines (85 loc) · 2.11 KB
/
bindconfig.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
#include "bindconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern int doPrint;
void usage(char* progName)
{
printf("usage: %s [class dev|client|proto|service] [comp <id>] "
"[path <pathToken>] [enable|disable]\n", progName);
exit(255);
}
int __cdecl main(int argc, char* argv[])
{
int exitCode;
bool show = true;
CompClass cls = kCompClassDevice;
char *compStr = NULL;
char *pathStr = NULL;
BindingStatus status;
doPrint = 1;
int i = 1;
while (i < argc)
{
if (strcmp(argv[i], "class") == 0)
{
i++;
if (i >= argc)
usage(argv[0]);
if (strcmp(argv[i], "dev") == 0)
cls = kCompClassDevice;
else if (strcmp(argv[i], "client") == 0)
cls = kCompClassClient;
else if (strcmp(argv[i], "proto") == 0)
cls = kCompClassProtocol;
else if (strcmp(argv[i], "service") == 0)
cls = kCompClassService;
else
usage(argv[0]);
i++;
}
else if (strcmp(argv[i], "comp") == 0)
{
i++;
if (i >= argc)
usage(argv[0]);
compStr = argv[i];
i++;
}
else if (strcmp(argv[i], "path") == 0)
{
i++;
if (i >= argc)
usage(argv[0]);
pathStr = argv[i];
i++;
}
else if (strcmp(argv[i], "enable") == 0)
{
show = false;
status = kBindingEnabled;
i++;
}
else if (strcmp(argv[i], "disable") == 0)
{
show = false;
status = kBindingDisabled;
i++;
}
else
usage(argv[0]);
}
if (show)
{
status = bindingStatus(cls, compStr, pathStr);
exitCode = (status == kBindingEnabled) ? 1 : 0;
}
else
{
if (setBindingStatus(cls, compStr, pathStr, status))
exitCode = 0;
else
exitCode = 1;
}
return exitCode;
}