b78828bf |
1 | /* |
83b5751b |
2 | * (C) GraÅžvydas "notaz" Ignotas, 2010 |
b78828bf |
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> |
0aab059f |
9 | #include <stdlib.h> |
b78828bf |
10 | #include <string.h> |
11 | #include <strings.h> |
12 | #include <ctype.h> |
13 | |
9ab462cd |
14 | #include "osdl.h" |
b78828bf |
15 | |
16 | static char *sskip(char *p) |
17 | { |
18 | while (*p && isspace(*p)) |
19 | p++; |
20 | return p; |
21 | } |
22 | |
23 | static char *nsskip(char *p) |
24 | { |
25 | while (*p && !isspace(*p)) |
26 | p++; |
27 | return p; |
28 | } |
29 | |
0aab059f |
30 | static int check_token(char **p_, const char *token) |
b78828bf |
31 | { |
0aab059f |
32 | char *p = *p_; |
b78828bf |
33 | int tlen = strlen(token); |
0aab059f |
34 | int ret = strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]); |
35 | if (ret) |
36 | *p_ = sskip(p + tlen + 1); |
37 | |
38 | return ret; |
39 | } |
40 | |
41 | static int check_token_eq(char **p_, const char *token) |
42 | { |
43 | char *p = *p_; |
44 | int ret = check_token(&p, token); |
45 | ret = ret && *p == '='; |
46 | if (ret) |
47 | *p_ = sskip(p + 1); |
48 | |
49 | return ret; |
b78828bf |
50 | } |
51 | |
5f4b1fd3 |
52 | void omapsdl_config(struct SDL_PrivateVideoData *pdata) |
b78828bf |
53 | { |
54 | char buff[256]; |
55 | FILE *f; |
56 | |
57 | f = fopen("omapsdl.cfg", "r"); |
58 | if (f == NULL) |
59 | return; |
60 | |
61 | while (!feof(f)) { |
62 | char *p, *line = fgets(buff, sizeof(buff), f); |
63 | if (line == NULL) |
64 | break; |
65 | p = line = sskip(line); |
b3747abb |
66 | if (*p == 0 || *p == '#') |
b78828bf |
67 | continue; |
68 | |
0aab059f |
69 | if (check_token(&p, "bind")) { |
b78828bf |
70 | char *key, *key_end, *sdlkey, *sdlkey_end; |
0aab059f |
71 | key = p; |
b78828bf |
72 | key_end = nsskip(key); |
73 | p = sskip(key_end); |
74 | if (*p != '=') |
75 | goto bad; |
76 | sdlkey = sskip(p + 1); |
77 | sdlkey_end = nsskip(sdlkey); |
78 | p = sskip(sdlkey_end); |
79 | if (*key == 0 || *sdlkey == 0 || *p != 0) |
80 | goto bad; |
81 | *key_end = *sdlkey_end = 0; |
82 | |
83 | omapsdl_input_bind(key, sdlkey); |
84 | continue; |
85 | } |
0aab059f |
86 | else if (check_token_eq(&p, "force_vsync")) { |
5f4b1fd3 |
87 | pdata->cfg_force_vsync = !!strtol(p, NULL, 0); |
0aab059f |
88 | continue; |
89 | } |
0bb19c41 |
90 | else if (check_token_eq(&p, "force_doublebuf")) { |
5f4b1fd3 |
91 | pdata->cfg_force_doublebuf = !!strtol(p, NULL, 0); |
92 | continue; |
93 | } |
5cc6dcb7 |
94 | else if (check_token_eq(&p, "force_directbuf")) { |
95 | pdata->cfg_force_directbuf = !!strtol(p, NULL, 0); |
96 | continue; |
97 | } |
5f4b1fd3 |
98 | else if (check_token_eq(&p, "no_ts_translate")) { |
99 | pdata->cfg_no_ts_translate = !!strtol(p, NULL, 0); |
0bb19c41 |
100 | continue; |
101 | } |
e1837b2c |
102 | else if (check_token_eq(&p, "ts_force_tslib")) { |
103 | pdata->cfg_ts_force_tslib = !!strtol(p, NULL, 0); |
104 | continue; |
105 | } |
b78828bf |
106 | |
107 | bad: |
108 | err("config: failed to parse: %s", line); |
109 | } |
110 | fclose(f); |
111 | } |
112 | |
5f4b1fd3 |
113 | void omapsdl_config_from_env(struct SDL_PrivateVideoData *pdata) |
f641fccb |
114 | { |
115 | const char *tmp; |
116 | |
117 | tmp = getenv("SDL_OMAP_VSYNC"); |
118 | if (tmp != NULL) |
5f4b1fd3 |
119 | pdata->cfg_force_vsync = !!strtol(tmp, NULL, 0); |
0bb19c41 |
120 | tmp = getenv("SDL_OMAP_FORCE_DOUBLEBUF"); |
121 | if (tmp != NULL) |
5f4b1fd3 |
122 | pdata->cfg_force_doublebuf = !!strtol(tmp, NULL, 0); |
5cc6dcb7 |
123 | tmp = getenv("SDL_OMAP_FORCE_DIRECTBUF"); |
124 | if (tmp != NULL) |
125 | pdata->cfg_force_directbuf = !!strtol(tmp, NULL, 0); |
5f4b1fd3 |
126 | tmp = getenv("SDL_OMAP_NO_TS_TRANSLATE"); |
127 | if (tmp != NULL) |
128 | pdata->cfg_no_ts_translate = !!strtol(tmp, NULL, 0); |
e1837b2c |
129 | tmp = getenv("SDL_OMAP_TS_FORCE_TSLIB"); |
130 | if (tmp != NULL) |
131 | pdata->cfg_ts_force_tslib = !!strtol(tmp, NULL, 0); |
455c8c43 |
132 | tmp = getenv("SDL_OMAP_BORDER_CUT"); |
133 | if (tmp != NULL) { |
134 | int l, r, t, b; |
135 | if (sscanf(tmp, "%d,%d,%d,%d", &l, &r, &t, &b) == 4 |
136 | && l >= 0 && r >= 0 && t >= 0 && b >= 0) { |
137 | pdata->border_l = l, pdata->border_r = r; |
138 | pdata->border_t = t, pdata->border_b = b; |
139 | } |
140 | else |
141 | err("border incorrectly specified, ignored"); |
142 | } |
f641fccb |
143 | } |
b78828bf |
144 | |