don't force double buffering
[sdl_omap.git] / src / video / omapdss / config.c
1 /*
2  * (C) GraÅžvydas "notaz" Ignotas, 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 <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <ctype.h>
13
14 #include "omapsdl.h"
15
16 int gcfg_force_vsync;
17 int gcfg_force_doublebuf;
18
19 static char *sskip(char *p)
20 {
21         while (*p && isspace(*p))
22                 p++;
23         return p;
24 }
25
26 static char *nsskip(char *p)
27 {
28         while (*p && !isspace(*p))
29                 p++;
30         return p;
31 }
32
33 static int check_token(char **p_, const char *token)
34 {
35         char *p = *p_;
36         int tlen = strlen(token);
37         int ret = strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]);
38         if (ret)
39                 *p_ = sskip(p + tlen + 1);
40
41         return ret;
42 }
43
44 static int check_token_eq(char **p_, const char *token)
45 {
46         char *p = *p_;
47         int ret = check_token(&p, token);
48         ret = ret && *p == '=';
49         if (ret)
50                 *p_ = sskip(p + 1);
51
52         return ret;
53 }
54
55 void omapsdl_config(void)
56 {
57         char buff[256];
58         FILE *f;
59
60         f = fopen("omapsdl.cfg", "r");
61         if (f == NULL)
62                 return;
63
64         while (!feof(f)) {
65                 char *p, *line = fgets(buff, sizeof(buff), f);
66                 if (line == NULL)
67                         break;
68                 p = line = sskip(line);
69                 if (*p == 0 || *p == '#')
70                         continue;
71
72                 if (check_token(&p, "bind")) {
73                         char *key, *key_end, *sdlkey, *sdlkey_end;
74                         key = p;
75                         key_end = nsskip(key);
76                         p = sskip(key_end);
77                         if (*p != '=')
78                                 goto bad;
79                         sdlkey = sskip(p + 1);
80                         sdlkey_end = nsskip(sdlkey);
81                         p = sskip(sdlkey_end);
82                         if (*key == 0 || *sdlkey == 0 || *p != 0)
83                                 goto bad;
84                         *key_end = *sdlkey_end = 0;
85
86                         omapsdl_input_bind(key, sdlkey);
87                         continue;
88                 }
89                 else if (check_token_eq(&p, "force_vsync")) {
90                         gcfg_force_vsync = strtol(p, NULL, 0);
91                         continue;
92                 }
93                 else if (check_token_eq(&p, "force_doublebuf")) {
94                         gcfg_force_doublebuf = strtol(p, NULL, 0);
95                         continue;
96                 }
97
98 bad:
99                 err("config: failed to parse: %s", line);
100         }
101         fclose(f);
102 }
103
104 void omapsdl_config_from_env(void)
105 {
106         const char *tmp;
107
108         tmp = getenv("SDL_OMAP_VSYNC");
109         if (tmp != NULL)
110                 gcfg_force_vsync = strtol(tmp, NULL, 0);
111         tmp = getenv("SDL_OMAP_FORCE_DOUBLEBUF");
112         if (tmp != NULL)
113                 gcfg_force_doublebuf = strtol(tmp, NULL, 0);
114 }
115