-
Notifications
You must be signed in to change notification settings - Fork 8
/
frontend.c
93 lines (86 loc) · 1.98 KB
/
frontend.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
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "frontend.h"
#ifdef FEATURE_SDL
extern struct frontend_def front_sdl;
#endif
#ifdef FEATURE_VNC
extern struct frontend_def front_vnc;
#endif
#ifdef FEATURE_STATISTICS
extern struct frontend_def front_statistics;
#endif
#ifdef FEATURE_FBDEV
extern struct frontend_def front_linuxfb;
#endif
struct frontend_id frontends[] = {
#ifdef FEATURE_SDL
{ "sdl", &front_sdl },
#endif
#ifdef FEATURE_VNC
{ "vnc", &front_vnc },
#endif
#ifdef FEATURE_STATISTICS
{ "statistics", &front_statistics },
#endif
#ifdef FEATURE_FBDEV
{ "fbdev", &front_linuxfb },
#endif
{ NULL, NULL }
};
struct frontend_def* frontend_get_def(char* id) {
struct frontend_id* front = frontends;
for(; front->def != NULL; front++) {
if(strcmp(id, front->id) == 0) {
return front->def;
}
}
return NULL;
}
char* frontend_spec_extract_name(char* spec) {
char* sep = strchr(spec, ',');
char* limit = spec + strlen(spec);
if(sep) {
*sep = '\0';
return sep + 1 < limit ? sep + 1 : NULL;
}
return NULL;
}
static int frontend_configure_option(struct frontend* front, char* option) {
char* sep = strchr(option, '=');
char* sep_limit = strchr(option, ',');
char* limit = option + strlen(option);
char* value = NULL;
const struct frontend_arg* args = front->def->args;
if(sep && (sep < sep_limit || !sep_limit)) {
*sep = '\0';
value = sep + 1 < limit ? sep + 1 : NULL;
}
while(args && strlen(args->name)) {
if(strcmp(option, args->name) == 0) {
return args->configure(front, value);
}
args++;
}
return -ENOENT;
}
int frontend_configure(struct frontend* front, char* options) {
int err;
char* sep = NULL;
char* limit = options + strlen(options);
while(options < limit && (sep = strchr(options, ','))) {
*sep = '\0';
if((err = frontend_configure_option(front, options))) {
return err;
}
options = sep + 1;
}
if(options < limit) {
if((err = frontend_configure_option(front, options))) {
return err;
}
}
return 0;
}