Fix compile for 10.2.8.

This commit is contained in:
Steve Checkoway
2005-08-20 06:20:16 +00:00
parent 6289241cdb
commit 7f49cdd5ab
2 changed files with 151 additions and 55 deletions
+32 -12
View File
@@ -8,15 +8,37 @@ typedef unsigned long long UInt64;
#define __TYPES__
#include <libkern/OSByteOrder.h>
#undef __TYPES__
#if 0
#define DARWIN 1
#define NEED_POWF
#define NEED_SQRTF
#define NEED_SINF
#define NEED_COSF
#define NEED_TANF
#define NEED_ACOSF
#define NEED_STRTOF
#include <AvailabilityMacros.h>
#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 <cstddef>
# include <string>
# include <cstdlib>
namespace std
{
typedef basic_string<wchar_t> 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 <cmath>
# 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
@@ -25,7 +47,6 @@ typedef unsigned long long UInt64;
#define HAVE_FFMPEG
#define HAVE_SDL
#define CRASH_HANDLER
#define _BSD_WCHAR_T_DEFINED_
#define ENDIAN_BIG
#define CRYPTOPP_UNIX_AVAILABLE
#ifndef __MACOSX__
@@ -35,11 +56,10 @@ typedef unsigned long long UInt64;
#define ArchSwap24(n) (OSSwapInt32((n)) >> 8)
#define ArchSwap16(n) OSSwapInt16((n))
#define HAVE_BYTE_SWAPS
#define NEED_CSTDLIB_WORKAROUND
#endif
/*
* (c) 2003-2004 Steve Checkoway
* (c) 2003-2005 Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
+119 -43
View File
@@ -1,34 +1,32 @@
/*
* wchar.cpp
* stepmania
*
* Created by Steve Checkoway on Tue Nov 25 2003.
* Copyright (c) 2003 Steve Checkoway. All rights reserved.
*
*/
#include <AvailabilityMacros.h>
/* 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)
#define _BSD_WCHAR_T_DEFINED_
#include <sys/cdefs.h>
#include <cstddef>
#include <string>
#include <cstring>
extern "C" {
#ifndef wcslen
#define WEOF -1
__BEGIN_DECLS
size_t wcslen(const wchar_t *ws)
{
size_t n = 0;
while (*(ws++) != NULL)
while (*(ws++) != 0)
++n;
return n;
}
#endif
#ifndef wmemchr
wchar_t *wmemchr(const wchar_t *ws, wchar_t wc, size_t n)
{
for (unsigned i=0; i<n; ++i, ++ws)
@@ -36,9 +34,7 @@ wchar_t *wmemchr(const wchar_t *ws, wchar_t wc, size_t n)
return (wchar_t *)ws;
return NULL;
}
#endif
#ifndef wmemcmp
int wmemcmp(const wchar_t *ws1, const wchar_t *ws2, size_t n)
{
for (unsigned i=0; i<n; ++i, ++ws1, ++ws2)
@@ -46,23 +42,17 @@ int wmemcmp(const wchar_t *ws1, const wchar_t *ws2, size_t n)
return *ws1 - *ws2;
return 0;
}
#endif
#ifndef wmemcpy
wchar_t *wmemcpy(wchar_t *ws1, const wchar_t *ws2, size_t n)
{
return (wchar_t *)memcpy(ws1, ws2, n * sizeof(wchar_t));
}
#endif
#ifndef wmemmove
wchar_t *wmemmove(wchar_t *ws1, const wchar_t *ws2, size_t n)
{
return (wchar_t *)memmove(ws1, ws2, n * sizeof(wchar_t));
}
#endif
#ifndef wmemset
wchar_t *wmemset(wchar_t *ws , wchar_t wc, size_t n)
{
wchar_t *temp = ws;
@@ -70,30 +60,116 @@ wchar_t *wmemset(wchar_t *ws , wchar_t wc, size_t n)
*temp = wc;
return ws;
}
#endif
__END_DECLS
// copy and paste for the most part
namespace std
{
typedef wchar_t wint_t;
typedef wint_t wstreampos;
template<>
struct char_traits<wchar_t>
{
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<int_type>(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<wchar_t>::assign(wchar_t& __c1, wchar_t const& __c2)
{
__c1 = __c2;
}
size_t char_traits<wchar_t>::length(const char_type* __s)
{
return wcslen(__s);
}
// This return type should be char_traits<wchar_t>::char_type*. wchar_t
// is shorter.
wchar_t* char_traits<wchar_t>::copy(char_type* __s1, const char_type* __s2,
size_t __n)
{
return wmemcpy(__s1, __s2, __n);
}
}
#ifndef wstring
template class std::basic_string<wchar_t, std::char_traits<wchar_t>,
std::allocator<wchar_t> >;
#endif
/* This has nothing to do with this file, but I might as well put it here
* rather than make a new file just for it.
*/
#include <iostream>
#include <fstream>
using namespace std;
template basic_istream<char, char_traits<char> >&
basic_istream<char, char_traits<char> >::seekg(fpos<__mbstate_t>);
template streampos
basic_streambuf<char, char_traits<char> >::pubseekpos(fpos<__mbstate_t>,
_Ios_Openmode);
template class std::basic_string<wchar_t>;
#endif
/*
* (c) 2003-2004 Steve Checkoway
* (c) 2003-2005 Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a