1.Fixed a memory leak inside XInput2 code
authorDimitris Zenios <dimitris.zenios@gmail.com>
Thu, 31 May 2012 19:23:30 +0300
changeset 6318 49b2cb56db6e
parent 6317 df009b78a763
child 6319 698c98b83cbb
1.Fixed a memory leak inside XInput2 code 2.Replaced XKeycodeToKeysym with XkbKeycodeToKeysym since XKeycodeToKeysym is deprecated in newer X11 version 3.Rewrote testime.c since it was disabled after SDL_compat.c removal 4.Take into account common arguments also in testrelative.c
configure.in
include/SDL_config.h.in
include/SDL_config_macosx.h
src/video/x11/SDL_x11dyn.h
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11keyboard.c
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11xinput2.c
test/Makefile.in
test/testime.c
test/testrelative.c
--- a/configure.in	Thu May 31 09:06:47 2012 -0400
+++ b/configure.in	Thu May 31 19:23:30 2012 +0300
@@ -1111,6 +1111,7 @@
             AC_MSG_RESULT($have_const_param_XextAddDisplay)
 
             AC_CHECK_LIB(X11, XGetEventData, AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS, 1, [Have XGenericEvent]))
+            AC_CHECK_LIB(X11, XkbKeycodeToKeysym, AC_DEFINE(SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM, 1, [Have XkbKeycodeToKeysym]))
 
             AC_ARG_ENABLE(video-x11-xcursor,
 AC_HELP_STRING([--enable-video-x11-xcursor], [enable X11 Xcursor support [[default=yes]]]),
--- a/include/SDL_config.h.in	Thu May 31 09:06:47 2012 -0400
+++ b/include/SDL_config.h.in	Thu May 31 19:23:30 2012 +0300
@@ -271,6 +271,7 @@
 #undef SDL_VIDEO_DRIVER_X11_XVIDMODE
 #undef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
 #undef SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY
+#undef SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
 
 #undef SDL_VIDEO_RENDER_D3D
 #undef SDL_VIDEO_RENDER_OGL
--- a/include/SDL_config_macosx.h	Thu May 31 09:06:47 2012 -0400
+++ b/include/SDL_config_macosx.h	Thu May 31 19:23:30 2012 +0300
@@ -146,6 +146,7 @@
 #define SDL_VIDEO_DRIVER_X11_XSHAPE 1
 #define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
 #define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
+#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
 
 #ifndef SDL_VIDEO_RENDER_OGL
 #define SDL_VIDEO_RENDER_OGL	1
--- a/src/video/x11/SDL_x11dyn.h	Thu May 31 09:06:47 2012 -0400
+++ b/src/video/x11/SDL_x11dyn.h	Thu May 31 19:23:30 2012 +0300
@@ -27,6 +27,10 @@
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+#include <X11/XKBlib.h>
+#endif
+
 /* Apparently some X11 systems can't include this multiple times... */
 #ifndef SDL_INCLUDED_XLIBINT_H
 #define SDL_INCLUDED_XLIBINT_H 1
--- a/src/video/x11/SDL_x11events.c	Thu May 31 09:06:47 2012 -0400
+++ b/src/video/x11/SDL_x11events.c	Thu May 31 19:23:30 2012 +0300
@@ -265,7 +265,11 @@
             if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN) {
                 int min_keycode, max_keycode;
                 XDisplayKeycodes(display, &min_keycode, &max_keycode);
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+                keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
+#else
                 keysym = XKeycodeToKeysym(display, keycode, 0);
+#endif
                 fprintf(stderr,
                         "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n",
                         keycode, keycode - min_keycode, keysym,
@@ -563,7 +567,7 @@
             XResetScreenSaver(data->display);
             data->screensaver_activity = now;
         }
-    }
+    }   
 
     /* Keep processing pending events */
     while (X11_Pending(data->display)) {
--- a/src/video/x11/SDL_x11keyboard.c	Thu May 31 09:06:47 2012 -0400
+++ b/src/video/x11/SDL_x11keyboard.c	Thu May 31 19:23:30 2012 +0300
@@ -151,7 +151,11 @@
     unsigned int ucs4;
     int i;
 
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+    keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
+#else
     keysym = XKeycodeToKeysym(display, keycode, 0);
+#endif
     if (keysym == NoSymbol) {
         return SDLK_UNKNOWN;
     }
@@ -232,7 +236,11 @@
         SDL_GetDefaultKeymap(keymap);
         for (i = min_keycode; i <= max_keycode; ++i) {
             KeySym sym;
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+            sym = XkbKeycodeToKeysym(data->display, i, 0, 0);
+#else
             sym = XKeycodeToKeysym(data->display, i, 0);
+#endif
             if (sym != NoSymbol) {
                 SDL_Keycode key;
                 printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
--- a/src/video/x11/SDL_x11sym.h	Thu May 31 09:06:47 2012 -0400
+++ b/src/video/x11/SDL_x11sym.h	Thu May 31 19:23:30 2012 +0300
@@ -132,6 +132,14 @@
 SDL_X11_SYM(void,XFreeEventData,(Display* a,XGenericEventCookie* b),(a,b),)    
 #endif
 
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+#if NeedWidePrototypes
+SDL_X11_SYM(KeySym,XkbKeycodeToKeysym,(Display* a,unsigned int b,int c,int d),(a,b,c,d),return)
+#else
+SDL_X11_SYM(KeySym,XkbKeycodeToKeysym,(Display* a,KeyCode b,int c,int d),(a,b,c,d),return)
+#endif
+#endif
+
 #if NeedWidePrototypes
 SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
 #else
--- a/src/video/x11/SDL_x11xinput2.c	Thu May 31 09:06:47 2012 -0400
+++ b/src/video/x11/SDL_x11xinput2.c	Thu May 31 19:23:30 2012 +0300
@@ -210,6 +210,7 @@
             }
         }
     }
+    XIFreeDeviceInfo(info);
 #endif
 }
 
--- a/test/Makefile.in	Thu May 31 09:06:47 2012 -0400
+++ b/test/Makefile.in	Thu May 31 19:23:30 2012 +0300
@@ -105,8 +105,8 @@
 testiconv$(EXE): $(srcdir)/testiconv.c
 	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
 
-testime$(EXE): $(srcdir)/testime.c
-	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
+testime$(EXE): $(srcdir)/testime.c $(srcdir)/common.c
+	$(CC) -o $@ $(srcdir)/testime.c $(srcdir)/common.c $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
 
 testjoystick$(EXE): $(srcdir)/testjoystick.c
 	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
--- a/test/testime.c	Thu May 31 09:06:47 2012 -0400
+++ b/test/testime.c	Thu May 31 19:23:30 2012 +0300
@@ -11,15 +11,6 @@
 */
 /* A simple program to test the Input Method support in the SDL library (2.0+) */
 
-#if 1 /* FIXME: Rework this using the 2.0 API */
-#include <stdio.h>
-
-int main(int argc, char *argv[])
-{
-    printf("FIXME\n");
-    return 0;
-}
-#else
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -29,20 +20,22 @@
 #include "SDL_ttf.h"
 #endif
 
+#include "common.h"
+
 #define DEFAULT_PTSIZE  30
 #define DEFAULT_FONT    "/System/Library/Fonts/华文细黑.ttf"
 #define MAX_TEXT_LENGTH 256
 
-SDL_Surface *screen;
-
+static CommonState *state;
+static SDL_Rect textRect, markedRect;
+static SDL_Color lineColor = {0,0,0,0};
+static SDL_Color backColor = {255,255,255,0};
+static SDL_Color textColor = {0,0,0,0};
+static char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
+static int cursor = 0;
 #ifdef HAVE_SDL_TTF
-TTF_Font *font;
+static TTF_Font *font;
 #endif
-SDL_Rect textRect, markedRect;
-Uint32 lineColor, backColor;
-SDL_Color textColor = { 0, 0, 0 };
-char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
-int cursor = 0;
 
 size_t utf8_length(unsigned char c)
 {
@@ -87,24 +80,150 @@
 
 void usage()
 {
-    printf("usage: testime [--font fontfile] [--fullscreen]\n");
+    printf("usage: testime [--font fontfile]\n");
     exit(0);
 }
 
-void InitVideo(int argc, char *argv[])
+void InitInput()
+{
+
+    /* Prepare a rect for text input */
+    textRect.x = textRect.y = 100;
+    textRect.w = DEFAULT_WINDOW_WIDTH - 2 * textRect.x;
+    textRect.h = 50;
+
+    text[0] = 0;
+    markedRect = textRect;
+    markedText[0] = 0;
+
+    SDL_StartTextInput();
+}
+
+void CleanupVideo()
 {
-    int width = 640, height = 480;
-    int flags = SDL_HWSURFACE;
+    SDL_StopTextInput();
+#ifdef HAVE_SDL_TTF
+    TTF_CloseFont(font);
+    TTF_Quit();
+#endif
+}
+
+
+void _Redraw(SDL_Renderer * renderer) {
+    int w = 0, h = textRect.h;
+    SDL_Rect cursorRect, underlineRect;
+
+    SDL_SetRenderDrawColor(renderer, 255,255,255,255);
+    SDL_RenderFillRect(renderer,&textRect);
+
+#ifdef HAVE_SDL_TTF
+    if (*text)
+    {
+        SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, textColor);
+        SDL_Rect dest = {textRect.x, textRect.y, textSur->w, textSur->h };
+
+        SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,textSur);
+        SDL_FreeSurface(textSur);
+
+        SDL_RenderCopy(renderer,texture,NULL,&dest);
+        SDL_DestroyTexture(texture);
+        TTF_SizeUTF8(font, text, &w, &h);
+    }
+#endif
+
+    markedRect.x = textRect.x + w;
+    markedRect.w = textRect.w - w;
+    if (markedRect.w < 0)
+    {
+        // Stop text input because we cannot hold any more characters
+        SDL_StopTextInput();
+        return;
+    }
+    else
+    {
+        SDL_StartTextInput();
+    }
+
+    cursorRect = markedRect;
+    cursorRect.w = 2;
+    cursorRect.h = h;
+
+    SDL_SetRenderDrawColor(renderer, 255,255,255,255);
+    SDL_RenderFillRect(renderer,&markedRect);
+
+    if (markedText[0])
+    {
+#ifdef HAVE_SDL_TTF
+        if (cursor)
+        {
+            char *p = utf8_advance(markedText, cursor);
+            char c = 0;
+            if (!p)
+                p = &markedText[strlen(markedText)];
+
+            c = *p;
+            *p = 0;
+            TTF_SizeUTF8(font, markedText, &w, 0);
+            cursorRect.x += w;
+            *p = c;
+        }
+        SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, markedText, textColor);
+        SDL_Rect dest = {markedRect.x, markedRect.y, textSur->w, textSur->h };
+        TTF_SizeUTF8(font, markedText, &w, &h);
+        SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,textSur);
+        SDL_FreeSurface(textSur);
+
+        SDL_RenderCopy(renderer,texture,NULL,&dest);
+        SDL_DestroyTexture(texture);
+#endif
+
+        underlineRect = markedRect;
+        underlineRect.y += (h - 2);
+        underlineRect.h = 2;
+        underlineRect.w = w;
+
+        SDL_SetRenderDrawColor(renderer, 0,0,0,0);
+        SDL_RenderFillRect(renderer,&markedRect);
+    }
+
+    SDL_SetRenderDrawColor(renderer, 0,0,0,0);
+    SDL_RenderFillRect(renderer,&cursorRect);
+
+    SDL_SetTextInputRect(&markedRect);
+}
+
+void Redraw() {
+    int i;
+    for (i = 0; i < state->num_windows; ++i) {
+        SDL_Renderer *renderer = state->renderers[i];
+        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
+        SDL_RenderClear(renderer);
+
+        _Redraw(renderer);
+
+        SDL_RenderPresent(renderer);
+    }
+}
+
+int main(int argc, char *argv[]) {
+    int i, done;
+    SDL_Event event;
     const char *fontname = DEFAULT_FONT;
-    int fullscreen = 0;
 
+    /* Initialize test framework */
+    state = CommonCreateState(argv, SDL_INIT_VIDEO);
+    if (!state) {
+        return 1;
+    }
+    for (i = 1; i < argc;i++) {
+        CommonArg(state, i);
+    }
     for (argc--, argv++; argc > 0; argc--, argv++)
     {
-        if (strcmp(argv[0], "--help") == 0)
+        if (strcmp(argv[0], "--help") == 0) {
             usage();
-
-        else if (strcmp(argv[0], "--fullscreen") == 0)
-            fullscreen = 1;
+            return 0;
+        }
 
         else if (strcmp(argv[0], "--font") == 0)
         {
@@ -113,17 +232,17 @@
 
             if (argc > 0)
                 fontname = argv[0];
-            else
+            else {
                 usage();
+                return 0;
+            }
         }
     }
+    
+    if (!CommonInit(state)) {
+        return 2;
+    }
 
-    SDL_setenv("SDL_VIDEO_WINDOW_POS", "center", 1);
-    if (SDL_Init(SDL_INIT_VIDEO) < 0)
-    {
-        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
-        exit(-1);
-    }
 
 #ifdef HAVE_SDL_TTF
     /* Initialize fonts */
@@ -140,258 +259,111 @@
     printf("Using font: %s\n", fontname);
     atexit(SDL_Quit);
 
-    if (fullscreen)
-    {
-        /* Use the desktop mode */
-        width = 0;
-        height = 0;
-        flags |= SDL_FULLSCREEN;
+    InitInput();
+    /* Create the windows and initialize the renderers */
+    for (i = 0; i < state->num_windows; ++i) {
+        SDL_Renderer *renderer = state->renderers[i];
+        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
+        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
+        SDL_RenderClear(renderer);
     }
+    Redraw();    
+    /* Main render loop */
+    done = 0;
+    while (!done) {
+        /* Check for events */
+        while (SDL_PollEvent(&event)) {
+            CommonEvent(state, &event, &done);
+            switch(event.type) {
+                case SDL_KEYDOWN: {
+                    switch (event.key.keysym.sym)
+                    {
+                        case SDLK_RETURN:
+                             text[0]=0x00;
+                             Redraw();
+                             break;
+                        case SDLK_BACKSPACE:
+                             {
+                                 int textlen=SDL_strlen(text);
 
-    /* Create window */
-    screen = SDL_SetVideoMode(width, height, 32, flags);
-    if (screen == NULL)
-    {
-        fprintf(stderr, "Unable to set %dx%d video: %s\n",
-                width, height, SDL_GetError());
-        exit(-1);
-    }
-}
+                                 do {
+                                     if (textlen==0)
+                                     {
+                                         break;
+                                     }
+                                     if ((text[textlen-1] & 0x80) == 0x00)
+                                     {
+                                         /* One byte */
+                                         text[textlen-1]=0x00;
+                                         break;
+                                     }
+                                     if ((text[textlen-1] & 0xC0) == 0x80)
+                                     {
+                                         /* Byte from the multibyte sequence */
+                                         text[textlen-1]=0x00;
+                                         textlen--;
+                                     }
+                                     if ((text[textlen-1] & 0xC0) == 0xC0)
+                                     {
+                                         /* First byte of multibyte sequence */
+                                         text[textlen-1]=0x00;
+                                         break;
+                                     }
+                                 } while(1);
 
-void CleanupVideo()
-{
-    SDL_StopTextInput();
-#ifdef HAVE_SDL_TTF
-    TTF_CloseFont(font);
-    TTF_Quit();
-#endif
-}
+                                 Redraw();
+                             }
+                             break;
+                    }
+
+                    if (done)
+                    {
+                        break;
+                    }
+
+                    fprintf(stderr,
+                            "Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
+                            event.key.keysym.scancode,
+                            SDL_GetScancodeName(event.key.keysym.scancode),
+                            event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym));
+                    break;
+
+                case SDL_TEXTINPUT:
+                    if (SDL_strlen(event.text.text) == 0 || event.text.text[0] == '\n' ||
+                        markedRect.w < 0)
+                        break;
+
+                    fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
 
-void InitInput()
-{
-    backColor = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF);
-    lineColor = SDL_MapRGB(screen->format, 0x0, 0x0, 0x0);
+                    if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
+                        SDL_strlcat(text, event.text.text, sizeof(text));
+
+                    fprintf(stderr, "text inputed: %s\n", text);
+
+                    // After text inputed, we can clear up markedText because it
+                    // is committed
+                    markedText[0] = 0;
+                    Redraw();
+                    break;
 
-    /* Prepare a rect for text input */
-    textRect.x = textRect.y = 100;
-    textRect.w = screen->w - 2 * textRect.x;
-    textRect.h = 50;
+                case SDL_TEXTEDITING:
+                    fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
+                            event.edit.text, event.edit.start, event.edit.length);
 
-    text[0] = 0;
-    markedRect = textRect;
-    markedText[0] = 0;
-
-    SDL_StartTextInput();
+                    strcpy(markedText, event.edit.text);
+                    cursor = event.edit.start;
+                    Redraw();
+                    break;
+                }
+                break;
+                    
+            }
+        }
+    }
+    CleanupVideo();
+    CommonQuit(state);
+    return 0;
 }
 
-#ifdef HAVE_SDL_TTF
-static void RenderText(SDL_Surface *sur,
-                        TTF_Font *font,
-                        const char *text,
-                        int x, int y,
-                        SDL_Color color)
-{
-    if (text && *text) {
-        SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, color);
-        SDL_Rect dest = { x, y, textSur->w, textSur->h };
-
-        SDL_BlitSurface(textSur, NULL, sur, &dest);
-        SDL_FreeSurface(textSur);
-    }
-}
-#endif
-
-void Redraw()
-{
-    int w = 0, h = textRect.h;
-    SDL_Rect cursorRect, underlineRect;
-
-    SDL_FillRect(screen, &textRect, backColor);
-
-#ifdef HAVE_SDL_TTF
-    if (*text)
-    {
-        RenderText(screen, font, text, textRect.x, textRect.y, textColor);
-        TTF_SizeUTF8(font, text, &w, &h);
-    }
-#endif
-
-    markedRect.x = textRect.x + w;
-    markedRect.w = textRect.w - w;
-    if (markedRect.w < 0)
-    {
-        SDL_Flip(screen);
-        // Stop text input because we cannot hold any more characters
-        SDL_StopTextInput();
-        return;
-    }
-    else
-    {
-        SDL_StartTextInput();
-    }
-
-    cursorRect = markedRect;
-    cursorRect.w = 2;
-    cursorRect.h = h;
-
-    SDL_FillRect(screen, &markedRect, backColor);
-    if (markedText[0])
-    {
-#ifdef HAVE_SDL_TTF
-        if (cursor)
-        {
-            char *p = utf8_advance(markedText, cursor);
-            char c = 0;
-            if (!p)
-                p = &markedText[strlen(markedText)];
-
-            c = *p;
-            *p = 0;
-            TTF_SizeUTF8(font, markedText, &w, 0);
-            cursorRect.x += w;
-            *p = c;
-        }
-        RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor);
-        TTF_SizeUTF8(font, markedText, &w, &h);
-#endif
-
-        underlineRect = markedRect;
-        underlineRect.y += (h - 2);
-        underlineRect.h = 2;
-        underlineRect.w = w;
-
-        SDL_FillRect(screen, &underlineRect, lineColor);
-    }
-
-    SDL_FillRect(screen, &cursorRect, lineColor);
-
-    SDL_Flip(screen);
-
-    SDL_SetTextInputRect(&markedRect);
-}
-
-void
-HotKey_ToggleFullScreen(void)
-{
-    SDL_Surface *screen;
-
-    screen = SDL_GetVideoSurface();
-    if (SDL_WM_ToggleFullScreen(screen)) {
-        printf("Toggled fullscreen mode - now %s\n",
-               (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
-    } else {
-        printf("Unable to toggle fullscreen mode\n");
-    }
-}
-
-int main(int argc, char *argv[])
-{
-    SDL_Event event;
-    int done = 0;
-
-    InitVideo(argc, argv);
-    InitInput();
-    Redraw();
-
-    while (! done && SDL_WaitEvent(&event))
-    {
-        switch (event.type)
-        {
-        case SDL_KEYDOWN:
-            switch (event.key.keysym.sym)
-            {
-                case SDLK_ESCAPE:
-                     done = 1;
-                     break;
-                case SDLK_RETURN:
-                     text[0]=0x00;
-                     Redraw();
-                     break;
-                case SDLK_BACKSPACE:
-                     {
-                         int textlen=SDL_strlen(text);
-
-                         do {
-                             if (textlen==0)
-                             {
-                                 break;
-                             }
-                             if ((text[textlen-1] & 0x80) == 0x00)
-                             {
-                                 /* One byte */
-                                 text[textlen-1]=0x00;
-                                 break;
-                             }
-                             if ((text[textlen-1] & 0xC0) == 0x80)
-                             {
-                                 /* Byte from the multibyte sequence */
-                                 text[textlen-1]=0x00;
-                                 textlen--;
-                             }
-                             if ((text[textlen-1] & 0xC0) == 0xC0)
-                             {
-                                 /* First byte of multibyte sequence */
-                                 text[textlen-1]=0x00;
-                                 break;
-                             }
-                         } while(1);
-
-                         Redraw();
-                     }
-                     break;
-            }
-
-            if (done)
-            {
-                break;
-            }
-
-            fprintf(stderr,
-                    "Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
-                    event.key.keysym.scancode,
-                    SDL_GetScancodeName(event.key.keysym.scancode),
-                    event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym));
-            break;
-
-        case SDL_TEXTINPUT:
-            if (SDL_strlen(event.text.text) == 0 || event.text.text[0] == '\n' ||
-                markedRect.w < 0)
-                break;
-
-            fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
-
-            if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
-                SDL_strlcat(text, event.text.text, sizeof(text));
-
-            fprintf(stderr, "text inputed: %s\n", text);
-
-            // After text inputed, we can clear up markedText because it
-            // is committed
-            markedText[0] = 0;
-            Redraw();
-            break;
-
-        case SDL_TEXTEDITING:
-            fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
-                    event.edit.text, event.edit.start, event.edit.length);
-
-            strcpy(markedText, event.edit.text);
-            cursor = event.edit.start;
-            Redraw();
-            break;
-
-        case SDL_QUIT:
-            done = 1;
-            break;
-
-        default:
-            break;
-        }
-    }
-
-    CleanupVideo();
-    return 0;
-}
-#endif
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/test/testrelative.c	Thu May 31 09:06:47 2012 -0400
+++ b/test/testrelative.c	Thu May 31 19:23:30 2012 +0300
@@ -41,6 +41,9 @@
     if (!state) {
         return 1;
     }
+    for (i = 1; i < argc;i++) {
+        CommonArg(state, i);
+    }
     if (!CommonInit(state)) {
         return 2;
     }