don't force double buffering
[sdl_omap.git] / src / video / omapdss / config.c
CommitLineData
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
14#include "omapsdl.h"
15
0aab059f 16int gcfg_force_vsync;
0bb19c41 17int gcfg_force_doublebuf;
0aab059f 18
b78828bf 19static char *sskip(char *p)
20{
21 while (*p && isspace(*p))
22 p++;
23 return p;
24}
25
26static char *nsskip(char *p)
27{
28 while (*p && !isspace(*p))
29 p++;
30 return p;
31}
32
0aab059f 33static int check_token(char **p_, const char *token)
b78828bf 34{
0aab059f 35 char *p = *p_;
b78828bf 36 int tlen = strlen(token);
0aab059f 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
44static 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;
b78828bf 53}
54
55void 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);
b3747abb 69 if (*p == 0 || *p == '#')
b78828bf 70 continue;
71
0aab059f 72 if (check_token(&p, "bind")) {
b78828bf 73 char *key, *key_end, *sdlkey, *sdlkey_end;
0aab059f 74 key = p;
b78828bf 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 }
0aab059f 89 else if (check_token_eq(&p, "force_vsync")) {
90 gcfg_force_vsync = strtol(p, NULL, 0);
91 continue;
92 }
0bb19c41 93 else if (check_token_eq(&p, "force_doublebuf")) {
94 gcfg_force_doublebuf = strtol(p, NULL, 0);
95 continue;
96 }
b78828bf 97
98bad:
99 err("config: failed to parse: %s", line);
100 }
101 fclose(f);
102}
103
f641fccb 104void omapsdl_config_from_env(void)
105{
106 const char *tmp;
107
108 tmp = getenv("SDL_OMAP_VSYNC");
109 if (tmp != NULL)
0bb19c41 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);
f641fccb 114}
b78828bf 115