-
Notifications
You must be signed in to change notification settings - Fork 2
/
args.c
109 lines (101 loc) · 2.25 KB
/
args.c
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
XRenderColor args_color(char* raw){
XRenderColor color = {
.alpha = -1
};
uint32_t mask = 0xFF;
uint32_t bytes = strtoul(raw, NULL, 16);
if(strlen(raw) == 8){
color.alpha = (bytes & mask) << 8 | (bytes & mask);
bytes >>= 8;
}
color.blue = (bytes & mask) << 8 | (bytes & mask);
bytes >>= 8;
color.green = (bytes & mask) << 8 | (bytes & mask);
bytes >>= 8;
color.red = (bytes & mask) << 8 | (bytes & mask);
bytes >>= 8;
//fprintf(stderr, "Read color r:%X g:%X b:%X a:%X\n", color.red, color.green, color.blue, color.alpha);
return color;
}
int args_parse(int argc, char** argv){
unsigned u;
char* offset;
for(u = 1; u < argc; u++){
if(argv[u][0] == '-'){
switch(argv[u][1]){
case 'b':
config.bindhost = argv[u + 1];
u++;
break;
case 'p':
config.port = argv[u + 1];
u++;
break;
case 'l':
config.frame_limit = strtoul(argv[u + 1], NULL, 0);
u++;
break;
case 'f':
config.frame_rate = strtoul(argv[u + 1], NULL, 0);
u++;
break;
case 'd':
if(argv[u + 1]){
config.width = strtoul(argv[u + 1], &offset, 0);
if(*offset != 'x'){
fprintf(stderr, "Invalid dimension specification\n");
return -1;
}
config.height = strtoul(offset + 1, NULL, 0);
}
u++;
break;
case 'e':
if(!strcmp(argv[u + 1], "ignore")){
config.limit_handling = ignore;
}
else if(!strcmp(argv[u + 1], "disconnect")){
config.limit_handling = disconnect;
}
else if(!strcmp(argv[u + 1], "none")){
config.limit_handling = none;
}
else{
config.limit_handling = limit;
}
u++;
break;
case 'u':
config.unsafe = true;
break;
case 'x':
config.exclusive = true;
break;
case 'w':
config.windowed = true;
break;
case 's':
config.scale_uniform = true;
break;
case 'c':
config.centered = true;
break;
case 'q':
config.quiet = true;
break;
default:
fprintf(stderr, "Unknown option: %s\n", argv[u]);
return -1;
}
}
else{
fprintf(stderr, "Unknown argument: %s\n", argv[u]);
return -1;
}
}
if(u - argc > 0){
fprintf(stderr, "Option expects a parameter: %s\n", argv[argc - 1]);
return -1;
}
return 0;
}