From 6f179a4dd31c1e0b0cffc693361b242f91214801 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 26 Sep 2009 10:32:14 +0000 Subject: [PATCH] Fixed bug #777 Implemented SDL_GetPlatform() --- include/SDL_platform.h | 25 ++++++++++++ src/SDL.c | 56 +++++++++++++++++++++++++++ test/automated/platform/platform.c | 62 +----------------------------- test/automated/testsdl.c | 2 +- test/testplatform.c | 53 +------------------------ 5 files changed, 84 insertions(+), 114 deletions(-) diff --git a/include/SDL_platform.h b/include/SDL_platform.h index bb35e378e..ec8627fd6 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -123,4 +123,29 @@ #define __NINTENDODS__ 1 #endif + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** + * \fn const char *SDL_GetPlatform(void) + * \brief Gets the name of the platform. + */ +extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + #endif /* _SDL_platform_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/SDL.c b/src/SDL.c index b06dbfb83..b6bace98c 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -277,6 +277,62 @@ SDL_GetRevision(void) return SDL_REVISION; } +/* Get the name of the platform */ +const char * +SDL_GetPlatform() +{ +#if __AIX__ + return "AIX"; +#elif __HAIKU__ +/* Haiku must appear here before BeOS, since it also defines __BEOS__ */ + return "Haiku"; +#elif __BEOS__ + return "BeOS"; +#elif __BSDI__ + return "BSDI"; +#elif __DREAMCAST__ + return "Dreamcast"; +#elif __FREEBSD__ + return "FreeBSD"; +#elif __HPUX__ + return "HP-UX"; +#elif __IRIX__ + return "Irix"; +#elif __LINUX__ + return "Linux"; +#elif __MINT__ + return "Atari MiNT"; +#elif __MACOS__ + return "MacOS Classic"; +#elif __MACOSX__ + return "Mac OS X"; +#elif __NETBSD__ + return "NetBSD"; +#elif __OPENBSD__ + return "OpenBSD"; +#elif __OS2__ + return "OS/2"; +#elif __OSF__ + return "OSF/1"; +#elif __QNXNTO__ + return "QNX Neutrino"; +#elif __RISCOS__ + return "RISC OS"; +#elif __SOLARIS__ + return "Solaris"; +#elif __WIN32__ +#ifdef _WIN32_WCE + return "Windows CE"; +#else + return "Windows"; +#endif +#elif __IPHONEOS__ + return "iPhone OS"; +#else + return "Unknown (see SDL_platform.h)"; +#endif +} + #if defined(__WIN32__) #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL)) diff --git a/test/automated/platform/platform.c b/test/automated/platform/platform.c index ceb88537b..a5d48b14d 100644 --- a/test/automated/platform/platform.c +++ b/test/automated/platform/platform.c @@ -131,66 +131,6 @@ static void plat_testEndian (void) } -/** - * @brief Gets the name of the platform. - */ -const char *platform_getPlatform (void) -{ - return -#if __AIX__ - "AIX" -#elif __HAIKU__ -/* Haiku must appear here before BeOS, since it also defines __BEOS__ */ - "Haiku" -#elif __BEOS__ - "BeOS" -#elif __BSDI__ - "BSDI" -#elif __DREAMCAST__ - "Dreamcast" -#elif __FREEBSD__ - "FreeBSD" -#elif __HPUX__ - "HP-UX" -#elif __IRIX__ - "Irix" -#elif __LINUX__ - "Linux" -#elif __MINT__ - "Atari MiNT" -#elif __MACOS__ - "MacOS Classic" -#elif __MACOSX__ - "Mac OS X" -#elif __NETBSD__ - "NetBSD" -#elif __OPENBSD__ - "OpenBSD" -#elif __OS2__ - "OS/2" -#elif __OSF__ - "OSF/1" -#elif __QNXNTO__ - "QNX Neutrino" -#elif __RISCOS__ - "RISC OS" -#elif __SOLARIS__ - "Solaris" -#elif __WIN32__ -#ifdef _WIN32_WCE - "Windows CE" -#else - "Windows" -#endif -#elif __IPHONEOS__ - "iPhone OS" -#else - "an unknown operating system! (see SDL_platform.h)" -#endif - ; -} - - /** * @brief Platform test entrypoint. */ @@ -207,7 +147,7 @@ int test_platform (void) SDL_ATinit( "Platform" ); /* Debug information. */ - SDL_ATprintVerbose( 1, "%s System detected\n", platform_getPlatform() ); + SDL_ATprintVerbose( 1, "%s System detected\n", SDL_GetPlatform() ); SDL_ATprintVerbose( 1, "System is %s endian\n", #ifdef SDL_LIL_ENDIAN "little" diff --git a/test/automated/testsdl.c b/test/automated/testsdl.c index 171faa684..caf98e51c 100644 --- a/test/automated/testsdl.c +++ b/test/automated/testsdl.c @@ -172,7 +172,7 @@ int main( int argc, char *argv[] ) SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n", ver.major, ver.minor, ver.patch, rev ); SDL_ATprintErr( "System is running %s and is %s endian\n", - platform_getPlatform(), + SDL_GetPlatform(), #ifdef SDL_LIL_ENDIAN "little" #else diff --git a/test/testplatform.c b/test/testplatform.c index 46cfa41c6..83cf36d61 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -157,58 +157,7 @@ main(int argc, char *argv[]) verbose = SDL_FALSE; } if (verbose) { - printf("This system is running %s\n", -#if __AIX__ - "AIX" -#elif __HAIKU__ -/* Haiku must appear here before BeOS, since it also defines __BEOS__ */ - "Haiku" -#elif __BEOS__ - "BeOS" -#elif __BSDI__ - "BSDI" -#elif __DREAMCAST__ - "Dreamcast" -#elif __FREEBSD__ - "FreeBSD" -#elif __HPUX__ - "HP-UX" -#elif __IRIX__ - "Irix" -#elif __LINUX__ - "Linux" -#elif __MINT__ - "Atari MiNT" -#elif __MACOS__ - "MacOS Classic" -#elif __MACOSX__ - "Mac OS X" -#elif __NETBSD__ - "NetBSD" -#elif __OPENBSD__ - "OpenBSD" -#elif __OS2__ - "OS/2" -#elif __OSF__ - "OSF/1" -#elif __QNXNTO__ - "QNX Neutrino" -#elif __RISCOS__ - "RISC OS" -#elif __SOLARIS__ - "Solaris" -#elif __WIN32__ -#ifdef _WIN32_WCE - "Windows CE" -#else - "Windows" -#endif -#elif __IPHONEOS__ - "iPhone OS" -#else - "an unknown operating system! (see SDL_platform.h)" -#endif - ); + printf("This system is running %s\n", SDL_GetPlatform()); } status += TestTypes(verbose);