standalone: refactor for becoming also a SDL driver
authornotaz <notasas@gmail.com>
Wed, 10 Nov 2010 16:19:15 +0000 (18:19 +0200)
committernotaz <notasas@gmail.com>
Fri, 12 Nov 2010 22:23:19 +0000 (00:23 +0200)
src/video/omapdss/Makefile
src/video/omapdss/config.c [new file with mode: 0644]
src/video/omapdss/input.c [moved from src/video/omapdss/pmsdl_input.c with 94% similarity]
src/video/omapdss/omapsdl.h [new file with mode: 0644]
src/video/omapdss/pmsdl.h [deleted file]
src/video/omapdss/standalone.c [moved from src/video/omapdss/main.c with 89% similarity]

index 98c2984..b70fbb0 100644 (file)
@@ -8,14 +8,14 @@ endif
 ARCH ?= arm
 
 TARGET = libSDL-1.2.so.0
-OBJS += main.o pmsdl_input.o \
+OBJS += standalone.o input.o config.o \
        common/input.o linux/fbdev.o linux/in_evdev.o linux/oshide.o linux/plat.o
 ifeq ($(ARCH),arm)
 OBJS += arm_utils.o
 else
 CFLAGS += -fPIC
 endif
-CFLAGS += -DIN_EVDEV
+CFLAGS += -DIN_EVDEV -DSTANDALONE
 
 all: $(TARGET)
 
@@ -25,4 +25,4 @@ $(TARGET): $(OBJS)
 clean:
        $(RM) $(TARGET) $(OBJS)
 
-*.o: pmsdl.h
+*.o: omapsdl.h
diff --git a/src/video/omapdss/config.c b/src/video/omapdss/config.c
new file mode 100644 (file)
index 0000000..e526c36
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * (C) notaz, 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 <string.h>
+#include <strings.h>
+#include <ctype.h>
+
+#include "omapsdl.h"
+
+static char *sskip(char *p)
+{
+       while (*p && isspace(*p))
+               p++;
+       return p;
+}
+
+static char *nsskip(char *p)
+{
+       while (*p && !isspace(*p))
+               p++;
+       return p;
+}
+
+static int check_token(const char *p, const char *token)
+{
+       int tlen = strlen(token);
+       return strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]);
+}
+
+void omapsdl_config(void)
+{
+       char buff[256];
+       FILE *f;
+
+       f = fopen("omapsdl.cfg", "r");
+       if (f == NULL)
+               return;
+
+       while (!feof(f)) {
+               char *p, *line = fgets(buff, sizeof(buff), f);
+               if (line == NULL)
+                       break;
+               p = line = sskip(line);
+               if (*p == '#')
+                       continue;
+
+               if (check_token(p, "bind")) {
+                       char *key, *key_end, *sdlkey, *sdlkey_end;
+                       key = sskip(p + 5);
+                       key_end = nsskip(key);
+                       p = sskip(key_end);
+                       if (*p != '=')
+                               goto bad;
+                       sdlkey = sskip(p + 1);
+                       sdlkey_end = nsskip(sdlkey);
+                       p = sskip(sdlkey_end);
+                       if (*key == 0 || *sdlkey == 0 || *p != 0)
+                               goto bad;
+                       *key_end = *sdlkey_end = 0;
+
+                       omapsdl_input_bind(key, sdlkey);
+                       continue;
+               }
+
+bad:
+               err("config: failed to parse: %s", line);
+       }
+       fclose(f);
+}
+
+
similarity index 94%
rename from src/video/omapdss/pmsdl_input.c
rename to src/video/omapdss/input.c
index 1eb4235..6fb8884 100644 (file)
@@ -1,8 +1,15 @@
+/*
+ * (C) notaz, 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 <strings.h>
 #include <SDL/SDL.h>
 #include <linux/input.h>
 
-#include "pmsdl.h"
+#include "omapsdl.h"
 #include "common/input.h"
 
 static unsigned char g_keystate[SDLK_LAST];
@@ -333,7 +340,7 @@ static const char *sdl_keynames[SDLK_LAST] = {
        DNKEY(COMPOSE),
 };
 
-void pmsdl_input_bind(const char *kname, const char *sdlname)
+void omapsdl_input_bind(const char *kname, const char *sdlname)
 {
        int i, kc;
 
@@ -363,14 +370,15 @@ bad_sdlkey:
        err("can't resolve SDL key '%s'", sdlname);
 }
 
-void pmsdl_input_init(void)
+void omapsdl_input_init(void)
 {
        in_init();
        in_probe();
 }
 
-static int do_event(SDL_Event *event, int timeout)
+int omapsdl_input_get_event(void *event_, int timeout)
 {
+       SDL_Event *event = event_;
        int key, is_down;
 
        while (1) {
@@ -402,12 +410,14 @@ static int do_event(SDL_Event *event, int timeout)
 }
 
 /* SDL */
+#ifdef STANDALONE
+
 DECLSPEC int SDLCALL
 SDL_WaitEvent(SDL_Event *event)
 {
        trace("%p", event);
 
-       return do_event(event, -1);
+       return omapsdl_input_get_event(event, -1);
 }
 
 DECLSPEC int SDLCALL
@@ -415,7 +425,7 @@ SDL_PollEvent(SDL_Event *event)
 {
        trace("%p", event);
 
-       return do_event(event, 0);
+       return omapsdl_input_get_event(event, 0);
 }
 
 DECLSPEC Uint8 * SDLCALL
@@ -505,3 +515,4 @@ SDL_JoystickOpen(int device_index)
        return NULL;
 }
 
+#endif // STANDALONE
diff --git a/src/video/omapdss/omapsdl.h b/src/video/omapdss/omapsdl.h
new file mode 100644 (file)
index 0000000..f0f1ac4
--- /dev/null
@@ -0,0 +1,21 @@
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+#define err(fmt, ...) fprintf(stderr, "omapsdl: " fmt "\n", ##__VA_ARGS__)
+#define not_supported() fprintf(stderr, "omapsdl: %s not supported\n", __FUNCTION__)
+#if 1
+#define trace(fmt, ...) printf(" %s(" fmt ")\n", __FUNCTION__, ##__VA_ARGS__)
+#define dbg err
+#else
+#define trace(...)
+#define dbg(...)
+#endif
+
+void omapsdl_input_init(void);
+void omapsdl_input_bind(const char *kname, const char *sdlname);
+int  omapsdl_input_get_event(void *event_, int timeout);
+
+void omapsdl_config(void);
+
+/* functions for standalone */
+void do_clut(void *dest, void *src, unsigned short *pal, int count);
diff --git a/src/video/omapdss/pmsdl.h b/src/video/omapdss/pmsdl.h
deleted file mode 100644 (file)
index 0050e4d..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-
-#define err(fmt, ...) fprintf(stderr, "psdl: " fmt "\n", ##__VA_ARGS__)
-#define not_supported() fprintf(stderr, "psdl: %s not supported\n", __FUNCTION__)
-#if 0
-#define trace(fmt, ...) printf(" %s(" fmt ")\n", __FUNCTION__, ##__VA_ARGS__)
-#define dbg err
-#else
-#define trace(...)
-#define dbg(...)
-#endif
-
-void pmsdl_input_init(void);
-void pmsdl_input_bind(const char *kname, const char *sdlname);
-
-void do_clut(void *dest, void *src, unsigned short *pal, int count);
similarity index 89%
rename from src/video/omapdss/main.c
rename to src/video/omapdss/standalone.c
index 0444382..8c0e6bc 100644 (file)
@@ -1,12 +1,17 @@
+/*
+ * (C) notaz, 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 <sys/time.h>
 #include <SDL/SDL.h>
 
-#include "pmsdl.h"
+#include "omapsdl.h"
 #include "common/input.h"
 #include "linux/fbdev.h"
 #include "linux/oshide.h"
@@ -46,76 +51,15 @@ static SDL_Surface *alloc_surface(int w, int h, int bpp)
        return &ret->s;
 }
 
-static char *sskip(char *p)
-{
-       while (*p && isspace(*p))
-               p++;
-       return p;
-}
-
-static char *nsskip(char *p)
-{
-       while (*p && !isspace(*p))
-               p++;
-       return p;
-}
-
-static int check_token(const char *p, const char *token)
-{
-       int tlen = strlen(token);
-       return strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]);
-}
-
-static void do_config(void)
-{
-       char buff[256];
-       FILE *f;
-
-       f = fopen("pmsdl.cfg", "r");
-       if (f == NULL)
-               return;
-
-       while (!feof(f)) {
-               char *p, *line = fgets(buff, sizeof(buff), f);
-               if (line == NULL)
-                       break;
-               p = line = sskip(line);
-               if (*p == '#')
-                       continue;
-
-               if (check_token(p, "bind")) {
-                       char *key, *key_end, *sdlkey, *sdlkey_end;
-                       key = sskip(p + 5);
-                       key_end = nsskip(key);
-                       p = sskip(key_end);
-                       if (*p != '=')
-                               goto bad;
-                       sdlkey = sskip(p + 1);
-                       sdlkey_end = nsskip(sdlkey);
-                       p = sskip(sdlkey_end);
-                       if (*key == 0 || *sdlkey == 0 || *p != 0)
-                               goto bad;
-                       *key_end = *sdlkey_end = 0;
-
-                       pmsdl_input_bind(key, sdlkey);
-                       continue;
-               }
-
-bad:
-               err("config: failed to parse: %s", line);
-       }
-       fclose(f);
-}
-
 DECLSPEC int SDLCALL
 SDL_Init(Uint32 flags)
 {
        trace("%08x", flags);
 
        if (g_start_ticks == 0) {
-               pmsdl_input_init();
+               omapsdl_input_init();
                oshide_init();
-               do_config();
+               omapsdl_config();
        }
 
        g_start_ticks = 0;