b78828bf |
1 | /* |
2 | * (C) notaz, 2010 |
3 | * |
4 | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. |
5 | * See the COPYING file in the top-level directory. |
6 | */ |
7 | |
8 | #include <stdio.h> |
9 | #include <string.h> |
10 | #include <strings.h> |
11 | #include <ctype.h> |
12 | |
13 | #include "omapsdl.h" |
14 | |
15 | static char *sskip(char *p) |
16 | { |
17 | while (*p && isspace(*p)) |
18 | p++; |
19 | return p; |
20 | } |
21 | |
22 | static char *nsskip(char *p) |
23 | { |
24 | while (*p && !isspace(*p)) |
25 | p++; |
26 | return p; |
27 | } |
28 | |
29 | static int check_token(const char *p, const char *token) |
30 | { |
31 | int tlen = strlen(token); |
32 | return strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]); |
33 | } |
34 | |
35 | void omapsdl_config(void) |
36 | { |
37 | char buff[256]; |
38 | FILE *f; |
39 | |
40 | f = fopen("omapsdl.cfg", "r"); |
41 | if (f == NULL) |
42 | return; |
43 | |
44 | while (!feof(f)) { |
45 | char *p, *line = fgets(buff, sizeof(buff), f); |
46 | if (line == NULL) |
47 | break; |
48 | p = line = sskip(line); |
49 | if (*p == '#') |
50 | continue; |
51 | |
52 | if (check_token(p, "bind")) { |
53 | char *key, *key_end, *sdlkey, *sdlkey_end; |
54 | key = sskip(p + 5); |
55 | key_end = nsskip(key); |
56 | p = sskip(key_end); |
57 | if (*p != '=') |
58 | goto bad; |
59 | sdlkey = sskip(p + 1); |
60 | sdlkey_end = nsskip(sdlkey); |
61 | p = sskip(sdlkey_end); |
62 | if (*key == 0 || *sdlkey == 0 || *p != 0) |
63 | goto bad; |
64 | *key_end = *sdlkey_end = 0; |
65 | |
66 | omapsdl_input_bind(key, sdlkey); |
67 | continue; |
68 | } |
69 | |
70 | bad: |
71 | err("config: failed to parse: %s", line); |
72 | } |
73 | fclose(f); |
74 | } |
75 | |
76 | |