sdl12-compat: filled in more functions.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 07 Mar 2013 01:57:55 -0500
changeset 11ed314328463b
parent 10 e6176c053187
child 12 f9cfb7f12b95
sdl12-compat: filled in more functions.

Note that this counts on _every_ stdinc API to exist in the SDL2 binary.
We'll need to change how SDL2 handles this to always offer those symbols,
even if they're just passthroughs to the C runtime or whatever.
src/SDL12_compat.c
src/SDL20_syms.h
     1.1 --- a/src/SDL12_compat.c	Thu Mar 07 00:59:19 2013 -0500
     1.2 +++ b/src/SDL12_compat.c	Thu Mar 07 01:57:55 2013 -0500
     1.3 @@ -29,18 +29,17 @@
     1.4  
     1.5  #include "SDL_syswm.h"
     1.6  
     1.7 +#include <stdarg.h>
     1.8 +
     1.9  //#include "video/SDL_sysvideo.h"
    1.10  //#include "video/SDL_pixels_c.h"
    1.11  //#include "render/SDL_yuv_sw_c.h"
    1.12  
    1.13 -// !!! IMPLEMENT_ME SDL_AudioInit
    1.14 -// !!! IMPLEMENT_ME SDL_AudioQuit
    1.15  // !!! IMPLEMENT_ME SDL_ConvertSurface
    1.16  // !!! IMPLEMENT_ME SDL_CreateCursor
    1.17  // !!! IMPLEMENT_ME SDL_CreateRGBSurface
    1.18  // !!! IMPLEMENT_ME SDL_CreateRGBSurfaceFrom
    1.19  // !!! IMPLEMENT_ME SDL_CreateThread
    1.20 -// !!! IMPLEMENT_ME SDL_Error
    1.21  // !!! IMPLEMENT_ME SDL_EventState
    1.22  // !!! IMPLEMENT_ME SDL_FillRect
    1.23  // !!! IMPLEMENT_ME SDL_FreeCursor
    1.24 @@ -62,7 +61,6 @@
    1.25  // !!! IMPLEMENT_ME SDL_GetRGB
    1.26  // !!! IMPLEMENT_ME SDL_GetRGBA
    1.27  // !!! IMPLEMENT_ME SDL_GetRelativeMouseState
    1.28 -// !!! IMPLEMENT_ME SDL_InitSubSystem
    1.29  // !!! IMPLEMENT_ME SDL_LoadBMP_RW
    1.30  // !!! IMPLEMENT_ME SDL_LoadWAV_RW
    1.31  // !!! IMPLEMENT_ME SDL_LockSurface
    1.32 @@ -73,34 +71,17 @@
    1.33  // !!! IMPLEMENT_ME SDL_PollEvent
    1.34  // !!! IMPLEMENT_ME SDL_PumpEvents
    1.35  // !!! IMPLEMENT_ME SDL_PushEvent
    1.36 -// !!! IMPLEMENT_ME SDL_QuitSubSystem
    1.37  // !!! IMPLEMENT_ME SDL_SaveBMP_RW
    1.38  // !!! IMPLEMENT_ME SDL_SetClipRect
    1.39  // !!! IMPLEMENT_ME SDL_SetColorKey
    1.40  // !!! IMPLEMENT_ME SDL_SetCursor
    1.41 -// !!! IMPLEMENT_ME SDL_SetError
    1.42  // !!! IMPLEMENT_ME SDL_SetEventFilter
    1.43  // !!! IMPLEMENT_ME SDL_SetModState
    1.44  // !!! IMPLEMENT_ME SDL_ShowCursor
    1.45  // !!! IMPLEMENT_ME SDL_SoftStretch
    1.46  // !!! IMPLEMENT_ME SDL_UnlockSurface
    1.47  // !!! IMPLEMENT_ME SDL_UpperBlit
    1.48 -// !!! IMPLEMENT_ME SDL_VideoInit
    1.49 -// !!! IMPLEMENT_ME SDL_VideoQuit
    1.50  // !!! IMPLEMENT_ME SDL_WaitEvent
    1.51 -// !!! IMPLEMENT_ME SDL_WasInit
    1.52 -// !!! IMPLEMENT_ME SDL_iconv
    1.53 -// !!! IMPLEMENT_ME SDL_iconv_string
    1.54 -// !!! IMPLEMENT_ME SDL_lltoa
    1.55 -// !!! IMPLEMENT_ME SDL_ltoa
    1.56 -// !!! IMPLEMENT_ME SDL_revcpy
    1.57 -// !!! IMPLEMENT_ME SDL_strlcat
    1.58 -// !!! IMPLEMENT_ME SDL_strlcpy
    1.59 -// !!! IMPLEMENT_ME SDL_strlwr
    1.60 -// !!! IMPLEMENT_ME SDL_strrev
    1.61 -// !!! IMPLEMENT_ME SDL_strupr
    1.62 -// !!! IMPLEMENT_ME SDL_ulltoa
    1.63 -// !!! IMPLEMENT_ME SDL_ultoa
    1.64  // !!! IMPLEMENT_ME X11_KeyToUnicode
    1.65  
    1.66  
    1.67 @@ -113,6 +94,8 @@
    1.68  #undef SDL20_SYM_PASSTHROUGH
    1.69  #undef SDL20_SYM
    1.70  
    1.71 +typedef void (*SDL20_SetError_t)(const char *fmt, ...);
    1.72 +static SDL20_SetError_t SDL20_SetError = NULL;
    1.73  
    1.74  
    1.75  
    1.76 @@ -207,6 +190,7 @@
    1.77  static SDL_Surface *SDL_VideoIcon;
    1.78  static int SDL_enabled_UNICODE = 0;
    1.79  static int SDL_VideoDisplayIndex = 0;
    1.80 +static int SDL_CDRomInit = 0;
    1.81  
    1.82  /* Obviously we can't use SDL_LoadObject() to load SDL2.  :)  */
    1.83  #if defined(_WINDOWS)
    1.84 @@ -250,6 +234,7 @@
    1.85      #include "SDL20_syms.h"
    1.86      #undef SDL20_SYM_PASSTHROUGH
    1.87      #undef SDL20_SYM
    1.88 +    SDL20_SetError = NULL;
    1.89      CloseSDL20Library();
    1.90  }
    1.91  
    1.92 @@ -265,6 +250,7 @@
    1.93          #include "SDL20_syms.h"
    1.94          #undef SDL20_SYM_PASSTHROUGH
    1.95          #undef SDL20_SYM
    1.96 +        SDL20_SetError = (SDL20_SetError_t) LoadSDL20Symbol("SDL_SetError", &okay);
    1.97          if (!okay)
    1.98              UnloadSDL20();
    1.99      }
   1.100 @@ -287,8 +273,8 @@
   1.101      }
   1.102  }
   1.103  
   1.104 -int
   1.105 -SDL_Init(Uint32 sdl12flags)
   1.106 +static int
   1.107 +DoSDLInit(const int justsubs, Uint32 sdl12flags)
   1.108  {
   1.109      Uint32 sdl20flags = 0;
   1.110      int rc;
   1.111 @@ -302,15 +288,74 @@
   1.112      SETFLAG(VIDEO);
   1.113      SETFLAG(JOYSTICK);
   1.114      SETFLAG(NOPARACHUTE);
   1.115 +    #undef SETFLAG
   1.116 +
   1.117 +    // There's no CDROM in 2.0, but we'll just pretend it succeeded.
   1.118 +    if (sdl12flags & SDL12_INIT_CDROM)
   1.119 +        SDL_CDRomInit = 1;
   1.120 +
   1.121 +    // !!! FIXME: do something about SDL12_INIT_EVENTTHREAD
   1.122 +
   1.123 +    rc = justsubs ? SDL20_InitSubSystem(sdl20flags) : SDL20_Init(sdl20flags);
   1.124 +    if ((rc == 0) && (sdl20flags & SDL_INIT_VIDEO))
   1.125 +        SDL_VideoDisplayIndex = GetVideoDisplay();
   1.126 +    return rc;
   1.127 +}
   1.128 +
   1.129 +int
   1.130 +SDL_InitSubSystem(Uint32 sdl12flags)
   1.131 +{
   1.132 +    return DoSDLInit(1, sdl12flags);
   1.133 +}
   1.134 +
   1.135 +int
   1.136 +SDL_Init(Uint32 sdl12flags)
   1.137 +{
   1.138 +    return DoSDLInit(0, sdl12flags);
   1.139 +}
   1.140 +
   1.141 +Uint32
   1.142 +SDL_WasInit(Uint32 sdl12flags)
   1.143 +{
   1.144 +    // !!! FIXME: this is cut and pasted several places.
   1.145 +    Uint32 sdl20flags = 0;
   1.146 +    Uint32 extraflags = 0;
   1.147 +
   1.148 +    #define SETFLAG(x) if (sdl12flags & SDL12_INIT_##flag) sdl20flags |= SDL_INIT_##flag)
   1.149 +    SETFLAG(TIMER);
   1.150 +    SETFLAG(AUDIO);
   1.151 +    SETFLAG(VIDEO);
   1.152 +    SETFLAG(JOYSTICK);
   1.153 +    SETFLAG(NOPARACHUTE);
   1.154 +    #undef SETFLAG
   1.155 +
   1.156 +    if ((sdl12flags & SDL12_INIT_CDROM) && (SDL_CDRomInit))
   1.157 +        extraflags |= SDL12_INIT_CDROM;
   1.158 +
   1.159 +    // !!! FIXME: do something about SDL12_INIT_EVENTTHREAD
   1.160 +
   1.161 +    // !!! FIXME: convert back to 1.2
   1.162 +    return SDL20_WasInit(sdl20flags) | extraflags;
   1.163 +}
   1.164 +
   1.165 +void
   1.166 +SDL_QuitSubSystem(Uint32 sdl12flags)
   1.167 +{
   1.168 +    Uint32 sdl20flags = 0;
   1.169 +
   1.170 +    #define SETFLAG(x) if (sdl12flags & SDL12_INIT_##flag) sdl20flags |= SDL_INIT_##flag)
   1.171 +    SETFLAG(TIMER);
   1.172 +    SETFLAG(AUDIO);
   1.173 +    SETFLAG(VIDEO);
   1.174 +    SETFLAG(JOYSTICK);
   1.175 +    SETFLAG(NOPARACHUTE);
   1.176      // There's no CDROM in 2.0, but we'll just pretend it succeeded.
   1.177      #undef SETFLAG
   1.178  
   1.179      // !!! FIXME: do something about SDL12_INIT_EVENTTHREAD
   1.180 +    SDL20_QuitSubSystem(sdl20flags);
   1.181  
   1.182 -    rc = SDL20_Init(sdl20flags);
   1.183 -    if ((rc == 0) && (sdl20flags & SDL_INIT_VIDEO))
   1.184 -        SDL_VideoDisplayIndex = GetVideoDisplay();
   1.185 -    return rc;
   1.186 +    // !!! FIXME: UnloadSDL20() ?
   1.187  }
   1.188  
   1.189  void
   1.190 @@ -320,6 +365,13 @@
   1.191      UnloadSDL20();
   1.192  }
   1.193  
   1.194 +void
   1.195 +SDL_SetError(const char *fmt, ...)
   1.196 +{
   1.197 +    if (!Loaded_SDL20)
   1.198 +        return;
   1.199 +
   1.200 +}
   1.201  
   1.202  char *
   1.203  SDL_GetError(void)
   1.204 @@ -2279,4 +2331,21 @@
   1.205  #undef SDL20_SYM_PASSTHROUGH
   1.206  #undef SDL20_SYM
   1.207  
   1.208 +void
   1.209 +SDL_SetError(const char *fmt, ...)
   1.210 +{
   1.211 +    char *str = NULL;
   1.212 +    va_list ap;
   1.213 +    va_start(ap, fmt);
   1.214 +    vasprintf(&str, fmt, ap);
   1.215 +    va_end(ap);
   1.216 +    if (!str)
   1.217 +        SDL20_OutOfMemory();
   1.218 +    else
   1.219 +    {
   1.220 +        SDL20_SetError("%s", str);
   1.221 +        free(str);
   1.222 +    }
   1.223 +}
   1.224 +
   1.225  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/SDL20_syms.h	Thu Mar 07 00:59:19 2013 -0500
     2.2 +++ b/src/SDL20_syms.h	Thu Mar 07 01:57:55 2013 -0500
     2.3 @@ -22,10 +22,17 @@
     2.4  /* don't #pragma once this file, it gets #included multiple times! */
     2.5  
     2.6  SDL20_SYM(int,Init,(Uint32 a),(a),return)
     2.7 +SDL20_SYM(int,InitSubSystem,(Uint32 a),(a),return)
     2.8  SDL20_SYM(char*,GetError,(void),(),return)
     2.9 +SDL20_SYM_PASSTHROUGH(void,SDL_Error,(SDL_errorcode a),(a),)
    2.10  /*SDL20_SYM_PASSTHROUGH(void,SetError,(const char *fmt, ...);*/
    2.11  SDL20_SYM_PASSTHROUGH(void,ClearError,(void),(),)
    2.12  SDL20_SYM(void,Quit,(void),(),)
    2.13 +SDL20_SYM(void,QuitSubSystem,(Uint32 a),(a),)
    2.14 +SDL20_SYM_PASSTHROUGH(int,VideoInit,(const char *a),(a),return)
    2.15 +SDL20_SYM_PASSTHROUGH(void,VideoQuit,(void),(),)
    2.16 +SDL20_SYM_PASSTHROUGH(int,AudioInit,(const char *a),(a),return)
    2.17 +SDL20_SYM_PASSTHROUGH(void,AudioQuit,(void),(),)
    2.18  
    2.19  SDL20_SYM_PASSTHROUGH(Uint32,GetThreadID,(SDL_Thread *a),(a),return)
    2.20  SDL20_SYM_PASSTHROUGH(Uint32,ThreadID,(void),(),return)
    2.21 @@ -101,5 +108,46 @@
    2.22  SDL20_SYM(SDL_RWops *,SDL_RWFromMem,(void *a, int b),(a,b),return)
    2.23  SDL20_SYM(SDL_RWops *,SDL_RWFromConstMem,(const void *a, int b),(a,b),return)
    2.24  
    2.25 +SDL20_SYM_PASSTHROUGH(void *,SDL_malloc,(size_t a),(a),return)
    2.26 +SDL20_SYM_PASSTHROUGH(void *,SDL_calloc,(size_t a, size_t b),(a,b),return)
    2.27 +SDL20_SYM_PASSTHROUGH(void *,SDL_realloc,(void *a, size_t b),(a,b),return)
    2.28 +SDL20_SYM_PASSTHROUGH(void,SDL_free,(void *a),(a),)
    2.29 +SDL20_SYM_PASSTHROUGH(char *,SDL_getenv,(const char *a),(a),return)
    2.30 +SDL20_SYM_PASSTHROUGH(void,SDL_qsort,(void *a, size_t b, size_t c, int (*d)(const void *, const void *)),(a,b,c,d),)
    2.31 +SDL20_SYM_PASSTHROUGH(void *,SDL_memset,(void *a, int b, size_t c),(a,b,c),return)
    2.32 +SDL20_SYM_PASSTHROUGH(void *,SDL_memcpy,(void *a, const void *b, size_t c),(a,b,c),return)
    2.33 +SDL20_SYM_PASSTHROUGH(void *,SDL_revcpy,(void *a, const void *b, size_t c),(a,b,c),return)
    2.34 +SDL20_SYM_PASSTHROUGH(int,SDL_memcmp,(const void *a, const void *b, size_t c),(a,b,c),return)
    2.35 +SDL20_SYM_PASSTHROUGH(size_t,SDL_strlen,(const char *a),(a),return)
    2.36 +SDL20_SYM_PASSTHROUGH(size_t,SDL_strlcpy,(char *a, const char *b, size_t c),(a,b,c),return)
    2.37 +SDL20_SYM_PASSTHROUGH(size_t,SDL_strlcat,(char *a, const char *b, size_t c),(a,b,c),return)
    2.38 +SDL20_SYM_PASSTHROUGH(char *,SDL_strdup,(const char *a),(a),return)
    2.39 +SDL20_SYM_PASSTHROUGH(char *,SDL_strrev,(char *a),(a),return)
    2.40 +SDL20_SYM_PASSTHROUGH(char *,SDL_strupr,(char *a),(a),return)
    2.41 +SDL20_SYM_PASSTHROUGH(char *,SDL_strlwr,(char *a),(a),return)
    2.42 +SDL20_SYM_PASSTHROUGH(char *,SDL_strchr,(const char *a, int b),(a,b),return)
    2.43 +SDL20_SYM_PASSTHROUGH(char *,SDL_strrchr,(const char *a, int b),(a,b),return)
    2.44 +SDL20_SYM_PASSTHROUGH(char *,SDL_strstr,(const char *a, const char *b),(a,b),return)
    2.45 +SDL20_SYM_PASSTHROUGH(char *,SDL_ltoa,(long a, char *b, int c),(a,b,c),return)
    2.46 +SDL20_SYM_PASSTHROUGH(char *,SDL_ultoa,(unsigned long a, char *b, int c),(a,b,c),return)
    2.47 +SDL20_SYM_PASSTHROUGH(long,SDL_strtol,(const char *a, char **b, int c),(a,b,c),return)
    2.48 +SDL20_SYM_PASSTHROUGH(unsigned long,SDL_strtoul,(const char *a, char **b, int c),(a,b,c),return)
    2.49 +SDL20_SYM_PASSTHROUGH(char*,SDL_lltoa,(Sint64 a, char *b, int c),(a,b,c),return)
    2.50 +SDL20_SYM_PASSTHROUGH(char*,SDL_ulltoa,(Uint64 a, char *b, int c),(a,b,c),return)
    2.51 +SDL20_SYM_PASSTHROUGH(Sint64,SDL_strtoll,(const char *a, char **b, int c),(a,b,c),return)
    2.52 +SDL20_SYM_PASSTHROUGH(Uint64,SDL_strtoull,(const char *a, char **b, int c),(a,b,c),return)
    2.53 +SDL20_SYM_PASSTHROUGH(double,SDL_strtod,(const char *a, char **b),(a,b),return)
    2.54 +SDL20_SYM_PASSTHROUGH(int,SDL_strcmp,(const char *a, const char *b),(a,b),return)
    2.55 +SDL20_SYM_PASSTHROUGH(int,SDL_strncmp,(const char *a, const char *b, size_t c),(a,b,c),return)
    2.56 +SDL20_SYM_PASSTHROUGH(int,SDL_strcasecmp,(const char *a, const char *b),(a,b),return)
    2.57 +SDL20_SYM_PASSTHROUGH(int,SDL_strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return)
    2.58 +//SDL20_SYM_PASSTHROUGH(int,SDL_sscanf,(const char *text, const char *fmt, ...);
    2.59 +//SDL20_SYM_PASSTHROUGH(int,SDL_snprintf,(char *text, size_t maxlen, const char *fmt, ...);
    2.60 +SDL20_SYM_PASSTHROUGH(int,SDL_vsnprintf,(char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
    2.61 +SDL20_SYM_PASSTHROUGH(SDL_iconv_t,SDL_iconv_open,(const char *a, const char *b),(a,b),return)
    2.62 +SDL20_SYM_PASSTHROUGH(int,SDL_iconv_close,(SDL_iconv_t a),(a),return)
    2.63 +SDL20_SYM_PASSTHROUGH(size_t,SDL_iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return)
    2.64 +SDL20_SYM_PASSTHROUGH(char *,SDL_iconv_string,(const char *a, const char *b, const char *c, size_t d),(a,b,c,d),return)
    2.65 +
    2.66  /* vi: set ts=4 sw=4 expandtab: */
    2.67