-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.c
62 lines (56 loc) · 1.32 KB
/
config.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
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "config.h"
char *current_config[CONFIG_MAX] = {
/* UINPUT_DEV */
"/dev/uinput",
/* EVENT_DEV */
"/dev/input/event",
NULL,
};
char *cmdline_arg[CONFIG_MAX] = {
/* UINPUT_DEV */
"--uinput_dev",
/* EVENT_DEV */
"--event_dev",
NULL,
};
char *get_config(int key) {
if ((key >= CONFIG_MAX) || (key < 0)) {
fprintf(stderr, "ERR: Invalid config key in code: %d\n", key);
exit(1);
}
return current_config[key];
}
char *set_config(int key, char *value) {
char *old;
if ((key >= CONFIG_MAX) || (key < 0)) {
fprintf(stderr, "ERR: Invalid config key in code: %d\n", key);
exit(1);
}
old = current_config[key];
current_config[key] = value;
return old;
}
int match_config(char *arg) {
int i=0;
while (cmdline_arg[i] != NULL) {
if (strcmp(cmdline_arg[i], arg) == 0)
return i;
i++;
}
return -1;
}
void cmdline_config(int argc, char *argv[]) {
int i, index;
for (i=0; i<argc; i++) {
index = match_config(argv[i]);
if (index >= 0) {
if (i + 1 >= argc) {
fprintf(stderr, "Missing argument for: %s\n", argv[i]);
}
current_config[index] = argv[++i];
}
}
}