allow empty lines in config
[sdl_omap.git] / src / video / omapdss / config.c
index e526c36..a70cd3c 100644 (file)
@@ -1,17 +1,20 @@
 /*
- * (C) notaz, 2010
+ * (C) GraÅžvydas "notaz" Ignotas, 2010
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
  * See the COPYING file in the top-level directory.
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <strings.h>
 #include <ctype.h>
 
 #include "omapsdl.h"
 
+int gcfg_force_vsync;
+
 static char *sskip(char *p)
 {
        while (*p && isspace(*p))
@@ -26,10 +29,26 @@ static char *nsskip(char *p)
        return p;
 }
 
-static int check_token(const char *p, const char *token)
+static int check_token(char **p_, const char *token)
 {
+       char *p = *p_;
        int tlen = strlen(token);
-       return strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]);
+       int ret = strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]);
+       if (ret)
+               *p_ = sskip(p + tlen + 1);
+
+       return ret;
+}
+
+static int check_token_eq(char **p_, const char *token)
+{
+       char *p = *p_;
+       int ret = check_token(&p, token);
+       ret = ret && *p == '=';
+       if (ret)
+               *p_ = sskip(p + 1);
+
+       return ret;
 }
 
 void omapsdl_config(void)
@@ -46,12 +65,12 @@ void omapsdl_config(void)
                if (line == NULL)
                        break;
                p = line = sskip(line);
-               if (*p == '#')
+               if (*p == 0 || *p == '#')
                        continue;
 
-               if (check_token(p, "bind")) {
+               if (check_token(&p, "bind")) {
                        char *key, *key_end, *sdlkey, *sdlkey_end;
-                       key = sskip(p + 5);
+                       key = p;
                        key_end = nsskip(key);
                        p = sskip(key_end);
                        if (*p != '=')
@@ -66,6 +85,10 @@ void omapsdl_config(void)
                        omapsdl_input_bind(key, sdlkey);
                        continue;
                }
+               else if (check_token_eq(&p, "force_vsync")) {
+                       gcfg_force_vsync = strtol(p, NULL, 0);
+                       continue;
+               }
 
 bad:
                err("config: failed to parse: %s", line);
@@ -73,4 +96,12 @@ bad:
        fclose(f);
 }
 
+void omapsdl_config_from_env(void)
+{
+       const char *tmp;
+
+       tmp = getenv("SDL_OMAP_VSYNC");
+       if (tmp != NULL)
+               gcfg_force_vsync = atoi(tmp);
+}