diff --git a/stepmania/src/archutils/Darwin/arch_setup.h b/stepmania/src/archutils/Darwin/arch_setup.h index fff1f5bc0d..14c67e7482 100644 --- a/stepmania/src/archutils/Darwin/arch_setup.h +++ b/stepmania/src/archutils/Darwin/arch_setup.h @@ -8,38 +8,6 @@ typedef unsigned long long UInt64; #define __TYPES__ #include #undef __TYPES__ -#include -#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3) -# define NEED_POWF -# define NEED_SQRTF -# define NEED_SINF -# define NEED_COSF -# define NEED_TANF -# define NEED_ACOSF -# define NEED_STRTOF -# include -# include -# include -namespace std -{ - typedef basic_string wstring; -} -typedef int socklen_t; -/* cmath #undefs all of the math.h macros but fails to replace some of them -* with functions if _GLIBCPP_USE_C99 is not defined. As such, yank the -* definition out of math.h. -*/ -# include -# define isnan( x ) ( ( sizeof ( x ) == sizeof(double) ) ? \ - __isnand ( x ) : \ - ( sizeof ( x ) == sizeof( float) ) ? \ - __isnanf ( x ) : \ - __isnan ( x ) ) -// llabs is not defined either, copy it -inline long long llabs(long long __x) { return __x >= 0 ? __x : -__x; } -#else -# define NEED_CSTDLIB_WORKAROUND -#endif #define BACKTRACE_LOOKUP_METHOD_DARWIN_DYLD #define BACKTRACE_METHOD_POWERPC_DARWIN #define HAVE_VERSION_INFO @@ -47,8 +15,14 @@ inline long long llabs(long long __x) { return __x >= 0 ? __x : -__x; } #define HAVE_FFMPEG #define HAVE_SDL #define CRASH_HANDLER +// Looking ahead to "Universal binaries." +#ifdef __BIG_ENDIAN__ +# define ENDIAN_BIG +#else +# define ENDIAN_LITTLE +#endif #define ENDIAN_BIG -#define CRYPTOPP_UNIX_AVAILABLE + #ifndef __MACOSX__ # define __MACOSX__ #endif @@ -56,6 +30,140 @@ inline long long llabs(long long __x) { return __x >= 0 ? __x : -__x; } #define ArchSwap24(n) (OSSwapInt32((n)) >> 8) #define ArchSwap16(n) OSSwapInt16((n)) #define HAVE_BYTE_SWAPS + +#include +#if ! _GLIBCPP_HAVE_POWF +# define NEED_POWF +#endif + +#if ! _GLIBCPP_HAVE_SQRTF +# define NEED_SQRTF +#endif + +#if ! _GLIBCPP_HAVE_SINF +# define NEED_SINF +#endif + +#if ! _GLIBCPP_HAVE_TANF +# define NEED_TANF +#endif + +#if ! _GLIBCPP_HAVE_COSF +# define NEED_COSF +#endif + +#if ! _GLIBCPP_HAVE_ACOSF +# define NEED_ACOSF +#endif + +#if ! _GLIBCPP_HAVE_STRTOF +# define NEED_STRTOF +#endif + +// Define the work around if needed. +#include +#if _GLIBCPP_USE_C99 +# define NEED_CSTDLIB_WORKAROUND +#else +inline int64_t llabs(int64_t x) { return x < 0LL ? -x : x; } + +/* This is not correct. It's possible that _GLIBCPP_USE_C99 could be false + * and yet have socklen_t defined. In the BSD world, this seems to come from + * . However, all apple headers that include this have: + * #ifndef __APPLE__ + * #include + * #endif + * Since it appears we shouldn't include that for OS X builds, let's just + * make the assumption that if we can use c99 that socklen_t is defined and + * if we cannot, then it isn't. For the only two builds (on OS X) we care about, + * namely supporting 10.2.8 and the current OS, this _should_ hold true. + */ +typedef int socklen_t; + +/* cmath #undefs all of the math.h macros but fails to replace some of them + * with functions if _GLIBCPP_USE_C99 is not defined. As such, yank the + * definition out of math.h. + */ +# include +# define isnan( x ) ( ( sizeof ( x ) == sizeof(double) ) ? \ + __isnand ( x ) : \ + ( sizeof ( x ) == sizeof( float) ) ? \ + __isnanf ( x ) : \ + __isnan ( x ) ) +#endif + +#include +#if ! _GLIBCPP_USE_WCHAR_T + +extern "C" +{ + extern size_t wcslen(const wchar_t *ws); + extern wchar_t *wmemchr(const wchar_t *ws, wchar_t wc, size_t n); + extern int wmemcmp(const wchar_t *ws1, const wchar_t *ws2, size_t n); + extern wchar_t *wmemcpy(wchar_t *ws1, const wchar_t *ws2, size_t n); + extern wchar_t *wmemmove(wchar_t *ws1, const wchar_t *ws2, size_t n); + extern wchar_t *wmemset(wchar_t *ws , wchar_t wc, size_t n); +} +// C++ defines the wchar_t type even if glibc++ doesn't have the functions +namespace std +{ + /* This is actually illegal but it should work. =) + * In addition, it's not complete, but it's good enough for us. + * http://www.unl.csi.cuny.edu/faqs/g++-faq/wp/sep96/lib-strings.html + */ + template<> struct char_traits + { + typedef wchar_t char_type; + typedef wchar_t int_type; // it's big enough + /* streampos and wstreampos are both required to be typedefs for + * fpos as per clause 27.2--whatever that is. + */ + typedef streampos pos_type; + typedef streamoff off_type; + typedef mbstate_t state_type; + + static void assign(char_type& c1, const char_type c2) + { + c1 = c2; + } + + static void assign(char_type *s, size_t n, char_type c) + { + wmemset(s, c, n); + } + + static int compare(const char_type *s1, const char_type *s2, + size_t n) + { + return wmemcmp(s1, s2, n); + } + + static char_type *copy(char_type *s1, const char_type *s2, size_t n) + { + return wmemcpy(s1, s2, n); + } + + static const char_type *find(const char_type *s, size_t n, + const char_type& c) + { + return wmemchr(s, c, n); + } + + static size_t length(const char_type *s) + { + return wcslen(s); + } + + static char_type *move(char_type *s1, const char_type *s2, size_t n) + { + return wmemmove(s1, s2, n); + } + }; + + typedef basic_string wstring; +} +#endif + #endif /* diff --git a/stepmania/src/archutils/Darwin/wchar.cpp b/stepmania/src/archutils/Darwin/wchar.cpp index 286e7ef16d..a588a59af1 100644 --- a/stepmania/src/archutils/Darwin/wchar.cpp +++ b/stepmania/src/archutils/Darwin/wchar.cpp @@ -1,32 +1,20 @@ -#include - -/* The Mac OS X 10.2.8 sdk is lacking wchar.h and all that goes with it. - * wchar_t is a fundamental type in c++ but is essentially useless with this - * sdk. As a result, this file contains all of the code required to actually - * use wchar_t, at least in StepMania. If this file is compiled with - * MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 then the included - * wchar_t (and friends) is used. - * - * For maximum usability, this hack must be maintained as long as 10.2.8 is - * required to be supported. - */ -#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3) -#include -#include +#include #include -#include -#define WEOF -1 -__BEGIN_DECLS +extern "C" +{ +#if ! _GLIBCPP_HAVE_WCLEN size_t wcslen(const wchar_t *ws) { - size_t n = 0; - - while (*(ws++) != 0) - ++n; - return n; + size_t n = 0; + + while (*(ws++) != L'\0') + ++n; + return n; } +#endif +#if ! _GLIBCPP_HAVE_WMEMCHR wchar_t *wmemchr(const wchar_t *ws, wchar_t wc, size_t n) { for (unsigned i=0; i - struct char_traits - { - typedef wchar_t char_type; - typedef wint_t int_type; - typedef streamoff off_type; - typedef wstreampos pos_type; - typedef mbstate_t state_type; - - // gcc is being stupid and not allowing me to define it here - static void assign(char_type& __c1, const char_type& __c2); - - static bool eq(const char_type& __c1, const char_type& __c2) - { - return __c1 == __c2; - } - - static bool lt(const char_type& __c1, const char_type& __c2) - { - return __c1 < __c2; - } - - static int compare(const char_type* __s1, const char_type* __s2, - size_t __n) - { - return wmemcmp(__s1, __s2, __n); - } - - // same here - static size_t length(const char_type* __s); - - static const char_type* find(const char_type* __s, size_t __n, - const char_type& __a) - { - return wmemchr(__s, __a, __n); - } - - static char_type* move(char_type* __s1, const char_type* __s2, - int_type __n) - { - return wmemmove(__s1, __s2, __n); - } - - // and here - static char_type* copy(char_type* __s1, const char_type* __s2, - size_t __n); - - static char_type* assign(char_type* __s, size_t __n, char_type __a) - { - return wmemset(__s, __a, __n); - } - - static char_type to_char_type(const int_type& __c) - { - return char_type(__c); - } - - static int_type to_int_type(const char_type& __c) - { - return int_type(__c); - } - - static bool eq_int_type(const int_type& __c1, const int_type& __c2) - { - return __c1 == __c2; - } - - static int_type eof() - { - return static_cast(WEOF); - } - - static int_type not_eof(const int_type& __c) - { - return eq_int_type(__c, eof()) ? 0 : __c; - } - }; - // So, let's just do it here - void char_traits::assign(wchar_t& __c1, wchar_t const& __c2) - { - __c1 = __c2; - } - - size_t char_traits::length(const char_type* __s) - { - return wcslen(__s); - } - - // This return type should be char_traits::char_type*. wchar_t - // is shorter. - wchar_t* char_traits::copy(char_type* __s1, const char_type* __s2, - size_t __n) - { - return wmemcpy(__s1, __s2, __n); - } -} - -template class std::basic_string; #endif +} /* * (c) 2003-2005 Steve Checkoway