first commit

This commit is contained in:
Jose Caban
2025-06-07 11:34:38 -04:00
commit 0eb2d7c07d
4708 changed files with 1500614 additions and 0 deletions

117
extern/STLport/5.2.1/src/_stdio_file.h vendored Normal file
View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_STDIO_FILE_H
#define _STLP_STDIO_FILE_H
/* This file provides a low-level interface between the internal
* representation of struct FILE, from the C stdio library, and
* the C++ I/O library. */
#ifndef _STLP_CSTDIO
# include <cstdio>
#endif
#ifndef _STLP_CSTDDEF
# include <cstddef>
#endif
#if defined (__MSL__)
# include <unix.h> /* get the definition of fileno */
#endif
_STLP_BEGIN_NAMESPACE
#if defined (_STLP_WCE)
inline int _FILE_fd(const FILE *__f) {
/* Check if FILE is one of the three standard streams
We do this check first, because invoking _fileno() on one of them
causes a terminal window to be created. This also happens if you do
any IO on them, but merely retrieving the filedescriptor shouldn't
already do that.
Obviously this is pretty implementation-specific because it requires
that indeed the first three FDs are always the same, but that is not
only common but almost guaranteed. */
for (int __fd = 0; __fd != 3; ++__fd) {
if (__f == _getstdfilex(__fd))
return __fd;
}
/* Normal files. */
return (int)::_fileno((FILE*)__f);
}
# elif defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR)
inline int _FILE_fd(const FILE *__f) { return __f->__file; }
# elif defined (__sun) && defined (_LP64)
inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; }
#elif defined (__hpux) /* && defined(__hppa) && defined(__HP_aCC)) */ || \
defined (__MVS__) || \
defined (_STLP_USE_UCLIBC) /* should be before _STLP_USE_GLIBC */
inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE*, __f)); }
#elif defined (_STLP_USE_GLIBC)
inline int _FILE_fd(const FILE *__f) { return __f->_fileno; }
#elif defined (__BORLANDC__)
inline int _FILE_fd(const FILE *__f) { return __f->fd; }
#elif defined (__MWERKS__)
/* using MWERKS-specific defines here to detect other OS targets
* dwa: I'm not sure they provide fileno for all OS's, but this should
* work for Win32 and WinCE
* Hmm, at least for Novell NetWare __dest_os == __mac_os true too..
* May be both __dest_os and __mac_os defined and empty? - ptr */
# if __dest_os == __mac_os
inline int _FILE_fd(const FILE *__f) { return ::fileno(__CONST_CAST(FILE*, __f)); }
# else
inline int _FILE_fd(const FILE *__f) { return ::_fileno(__CONST_CAST(FILE*, __f)); }
# endif
#elif defined (__QNXNTO__) || defined (__WATCOMC__) || defined (__EMX__)
inline int _FILE_fd(const FILE *__f) { return __f->_handle; }
#elif defined (__Lynx__)
/* the prototypes are taken from LynxOS patch for STLport 4.0 */
inline int _FILE_fd(const FILE *__f) { return __f->_fd; }
#else /* The most common access to file descriptor. */
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
#endif
_STLP_END_NAMESPACE
#endif /* _STLP_STDIO_FILE_H */
/* Local Variables:
* mode:C++
* End: */

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef ACQUIRE_RELEASE_H
#define ACQUIRE_RELEASE_H
#include "c_locale.h"
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
_Locale_ctype* _STLP_CALL __acquire_ctype(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code);
_Locale_codecvt* _STLP_CALL __acquire_codecvt(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code);
_Locale_numeric* _STLP_CALL __acquire_numeric(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code);
_Locale_collate* _STLP_CALL __acquire_collate(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code);
_Locale_monetary* _STLP_CALL __acquire_monetary(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code);
_Locale_time* _STLP_CALL __acquire_time(const char* &name, char *buf, _Locale_name_hint*, int *__err_code);
_Locale_messages* _STLP_CALL __acquire_messages(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code);
void _STLP_CALL __release_ctype(_Locale_ctype* cat);
void _STLP_CALL __release_codecvt(_Locale_codecvt* cat);
void _STLP_CALL __release_numeric(_Locale_numeric* cat);
void _STLP_CALL __release_collate(_Locale_collate* cat);
void _STLP_CALL __release_monetary(_Locale_monetary* cat);
void _STLP_CALL __release_time(_Locale_time* __time);
void _STLP_CALL __release_messages(_Locale_messages* cat);
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE
#endif /* ACQUIRE_RELEASE_H */

View File

@@ -0,0 +1,21 @@
#ifndef ALIGNED_BUFFER_H
#define ALIGNED_BUFFER_H
_STLP_BEGIN_NAMESPACE
// this is for fake initialization
template<class T>
union _Stl_aligned_buffer {
char buf[sizeof(T)];
struct { double a; double b; } padding;
T* operator&() {
return __REINTERPRET_CAST(T*, this);
}
T const* operator&() const {
return __REINTERPRET_CAST(T const*, this);
}
};
_STLP_END_NAMESPACE
#endif

1121
extern/STLport/5.2.1/src/allocators.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

156
extern/STLport/5.2.1/src/bitset.cpp vendored Normal file
View File

@@ -0,0 +1,156 @@
/*
* Copyright (c) 1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <bitset>
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// ------------------------------------------------------------
// Lookup tables for find and count operations.
size_t _Bs_G::_S_count(const unsigned char *__first,
const unsigned char *__last)
{
static const unsigned char _bit_count[256] = {
0, /* 0 */ 1, /* 1 */ 1, /* 2 */ 2, /* 3 */ 1, /* 4 */
2, /* 5 */ 2, /* 6 */ 3, /* 7 */ 1, /* 8 */ 2, /* 9 */
2, /* 10 */ 3, /* 11 */ 2, /* 12 */ 3, /* 13 */ 3, /* 14 */
4, /* 15 */ 1, /* 16 */ 2, /* 17 */ 2, /* 18 */ 3, /* 19 */
2, /* 20 */ 3, /* 21 */ 3, /* 22 */ 4, /* 23 */ 2, /* 24 */
3, /* 25 */ 3, /* 26 */ 4, /* 27 */ 3, /* 28 */ 4, /* 29 */
4, /* 30 */ 5, /* 31 */ 1, /* 32 */ 2, /* 33 */ 2, /* 34 */
3, /* 35 */ 2, /* 36 */ 3, /* 37 */ 3, /* 38 */ 4, /* 39 */
2, /* 40 */ 3, /* 41 */ 3, /* 42 */ 4, /* 43 */ 3, /* 44 */
4, /* 45 */ 4, /* 46 */ 5, /* 47 */ 2, /* 48 */ 3, /* 49 */
3, /* 50 */ 4, /* 51 */ 3, /* 52 */ 4, /* 53 */ 4, /* 54 */
5, /* 55 */ 3, /* 56 */ 4, /* 57 */ 4, /* 58 */ 5, /* 59 */
4, /* 60 */ 5, /* 61 */ 5, /* 62 */ 6, /* 63 */ 1, /* 64 */
2, /* 65 */ 2, /* 66 */ 3, /* 67 */ 2, /* 68 */ 3, /* 69 */
3, /* 70 */ 4, /* 71 */ 2, /* 72 */ 3, /* 73 */ 3, /* 74 */
4, /* 75 */ 3, /* 76 */ 4, /* 77 */ 4, /* 78 */ 5, /* 79 */
2, /* 80 */ 3, /* 81 */ 3, /* 82 */ 4, /* 83 */ 3, /* 84 */
4, /* 85 */ 4, /* 86 */ 5, /* 87 */ 3, /* 88 */ 4, /* 89 */
4, /* 90 */ 5, /* 91 */ 4, /* 92 */ 5, /* 93 */ 5, /* 94 */
6, /* 95 */ 2, /* 96 */ 3, /* 97 */ 3, /* 98 */ 4, /* 99 */
3, /* 100 */ 4, /* 101 */ 4, /* 102 */ 5, /* 103 */ 3, /* 104 */
4, /* 105 */ 4, /* 106 */ 5, /* 107 */ 4, /* 108 */ 5, /* 109 */
5, /* 110 */ 6, /* 111 */ 3, /* 112 */ 4, /* 113 */ 4, /* 114 */
5, /* 115 */ 4, /* 116 */ 5, /* 117 */ 5, /* 118 */ 6, /* 119 */
4, /* 120 */ 5, /* 121 */ 5, /* 122 */ 6, /* 123 */ 5, /* 124 */
6, /* 125 */ 6, /* 126 */ 7, /* 127 */ 1, /* 128 */ 2, /* 129 */
2, /* 130 */ 3, /* 131 */ 2, /* 132 */ 3, /* 133 */ 3, /* 134 */
4, /* 135 */ 2, /* 136 */ 3, /* 137 */ 3, /* 138 */ 4, /* 139 */
3, /* 140 */ 4, /* 141 */ 4, /* 142 */ 5, /* 143 */ 2, /* 144 */
3, /* 145 */ 3, /* 146 */ 4, /* 147 */ 3, /* 148 */ 4, /* 149 */
4, /* 150 */ 5, /* 151 */ 3, /* 152 */ 4, /* 153 */ 4, /* 154 */
5, /* 155 */ 4, /* 156 */ 5, /* 157 */ 5, /* 158 */ 6, /* 159 */
2, /* 160 */ 3, /* 161 */ 3, /* 162 */ 4, /* 163 */ 3, /* 164 */
4, /* 165 */ 4, /* 166 */ 5, /* 167 */ 3, /* 168 */ 4, /* 169 */
4, /* 170 */ 5, /* 171 */ 4, /* 172 */ 5, /* 173 */ 5, /* 174 */
6, /* 175 */ 3, /* 176 */ 4, /* 177 */ 4, /* 178 */ 5, /* 179 */
4, /* 180 */ 5, /* 181 */ 5, /* 182 */ 6, /* 183 */ 4, /* 184 */
5, /* 185 */ 5, /* 186 */ 6, /* 187 */ 5, /* 188 */ 6, /* 189 */
6, /* 190 */ 7, /* 191 */ 2, /* 192 */ 3, /* 193 */ 3, /* 194 */
4, /* 195 */ 3, /* 196 */ 4, /* 197 */ 4, /* 198 */ 5, /* 199 */
3, /* 200 */ 4, /* 201 */ 4, /* 202 */ 5, /* 203 */ 4, /* 204 */
5, /* 205 */ 5, /* 206 */ 6, /* 207 */ 3, /* 208 */ 4, /* 209 */
4, /* 210 */ 5, /* 211 */ 4, /* 212 */ 5, /* 213 */ 5, /* 214 */
6, /* 215 */ 4, /* 216 */ 5, /* 217 */ 5, /* 218 */ 6, /* 219 */
5, /* 220 */ 6, /* 221 */ 6, /* 222 */ 7, /* 223 */ 3, /* 224 */
4, /* 225 */ 4, /* 226 */ 5, /* 227 */ 4, /* 228 */ 5, /* 229 */
5, /* 230 */ 6, /* 231 */ 4, /* 232 */ 5, /* 233 */ 5, /* 234 */
6, /* 235 */ 5, /* 236 */ 6, /* 237 */ 6, /* 238 */ 7, /* 239 */
4, /* 240 */ 5, /* 241 */ 5, /* 242 */ 6, /* 243 */ 5, /* 244 */
6, /* 245 */ 6, /* 246 */ 7, /* 247 */ 5, /* 248 */ 6, /* 249 */
6, /* 250 */ 7, /* 251 */ 6, /* 252 */ 7, /* 253 */ 7, /* 254 */
8 /* 255 */
};
size_t __result(0);
while ( __first < __last ) {
__result += _bit_count[*(__first++)];
}
return __result;
}
unsigned char _Bs_G::_S_first_one(unsigned char __byte)
{
static const unsigned char _first_one[256] = {
0, /* 0 */ 0, /* 1 */ 1, /* 2 */ 0, /* 3 */ 2, /* 4 */
0, /* 5 */ 1, /* 6 */ 0, /* 7 */ 3, /* 8 */ 0, /* 9 */
1, /* 10 */ 0, /* 11 */ 2, /* 12 */ 0, /* 13 */ 1, /* 14 */
0, /* 15 */ 4, /* 16 */ 0, /* 17 */ 1, /* 18 */ 0, /* 19 */
2, /* 20 */ 0, /* 21 */ 1, /* 22 */ 0, /* 23 */ 3, /* 24 */
0, /* 25 */ 1, /* 26 */ 0, /* 27 */ 2, /* 28 */ 0, /* 29 */
1, /* 30 */ 0, /* 31 */ 5, /* 32 */ 0, /* 33 */ 1, /* 34 */
0, /* 35 */ 2, /* 36 */ 0, /* 37 */ 1, /* 38 */ 0, /* 39 */
3, /* 40 */ 0, /* 41 */ 1, /* 42 */ 0, /* 43 */ 2, /* 44 */
0, /* 45 */ 1, /* 46 */ 0, /* 47 */ 4, /* 48 */ 0, /* 49 */
1, /* 50 */ 0, /* 51 */ 2, /* 52 */ 0, /* 53 */ 1, /* 54 */
0, /* 55 */ 3, /* 56 */ 0, /* 57 */ 1, /* 58 */ 0, /* 59 */
2, /* 60 */ 0, /* 61 */ 1, /* 62 */ 0, /* 63 */ 6, /* 64 */
0, /* 65 */ 1, /* 66 */ 0, /* 67 */ 2, /* 68 */ 0, /* 69 */
1, /* 70 */ 0, /* 71 */ 3, /* 72 */ 0, /* 73 */ 1, /* 74 */
0, /* 75 */ 2, /* 76 */ 0, /* 77 */ 1, /* 78 */ 0, /* 79 */
4, /* 80 */ 0, /* 81 */ 1, /* 82 */ 0, /* 83 */ 2, /* 84 */
0, /* 85 */ 1, /* 86 */ 0, /* 87 */ 3, /* 88 */ 0, /* 89 */
1, /* 90 */ 0, /* 91 */ 2, /* 92 */ 0, /* 93 */ 1, /* 94 */
0, /* 95 */ 5, /* 96 */ 0, /* 97 */ 1, /* 98 */ 0, /* 99 */
2, /* 100 */ 0, /* 101 */ 1, /* 102 */ 0, /* 103 */ 3, /* 104 */
0, /* 105 */ 1, /* 106 */ 0, /* 107 */ 2, /* 108 */ 0, /* 109 */
1, /* 110 */ 0, /* 111 */ 4, /* 112 */ 0, /* 113 */ 1, /* 114 */
0, /* 115 */ 2, /* 116 */ 0, /* 117 */ 1, /* 118 */ 0, /* 119 */
3, /* 120 */ 0, /* 121 */ 1, /* 122 */ 0, /* 123 */ 2, /* 124 */
0, /* 125 */ 1, /* 126 */ 0, /* 127 */ 7, /* 128 */ 0, /* 129 */
1, /* 130 */ 0, /* 131 */ 2, /* 132 */ 0, /* 133 */ 1, /* 134 */
0, /* 135 */ 3, /* 136 */ 0, /* 137 */ 1, /* 138 */ 0, /* 139 */
2, /* 140 */ 0, /* 141 */ 1, /* 142 */ 0, /* 143 */ 4, /* 144 */
0, /* 145 */ 1, /* 146 */ 0, /* 147 */ 2, /* 148 */ 0, /* 149 */
1, /* 150 */ 0, /* 151 */ 3, /* 152 */ 0, /* 153 */ 1, /* 154 */
0, /* 155 */ 2, /* 156 */ 0, /* 157 */ 1, /* 158 */ 0, /* 159 */
5, /* 160 */ 0, /* 161 */ 1, /* 162 */ 0, /* 163 */ 2, /* 164 */
0, /* 165 */ 1, /* 166 */ 0, /* 167 */ 3, /* 168 */ 0, /* 169 */
1, /* 170 */ 0, /* 171 */ 2, /* 172 */ 0, /* 173 */ 1, /* 174 */
0, /* 175 */ 4, /* 176 */ 0, /* 177 */ 1, /* 178 */ 0, /* 179 */
2, /* 180 */ 0, /* 181 */ 1, /* 182 */ 0, /* 183 */ 3, /* 184 */
0, /* 185 */ 1, /* 186 */ 0, /* 187 */ 2, /* 188 */ 0, /* 189 */
1, /* 190 */ 0, /* 191 */ 6, /* 192 */ 0, /* 193 */ 1, /* 194 */
0, /* 195 */ 2, /* 196 */ 0, /* 197 */ 1, /* 198 */ 0, /* 199 */
3, /* 200 */ 0, /* 201 */ 1, /* 202 */ 0, /* 203 */ 2, /* 204 */
0, /* 205 */ 1, /* 206 */ 0, /* 207 */ 4, /* 208 */ 0, /* 209 */
1, /* 210 */ 0, /* 211 */ 2, /* 212 */ 0, /* 213 */ 1, /* 214 */
0, /* 215 */ 3, /* 216 */ 0, /* 217 */ 1, /* 218 */ 0, /* 219 */
2, /* 220 */ 0, /* 221 */ 1, /* 222 */ 0, /* 223 */ 5, /* 224 */
0, /* 225 */ 1, /* 226 */ 0, /* 227 */ 2, /* 228 */ 0, /* 229 */
1, /* 230 */ 0, /* 231 */ 3, /* 232 */ 0, /* 233 */ 1, /* 234 */
0, /* 235 */ 2, /* 236 */ 0, /* 237 */ 1, /* 238 */ 0, /* 239 */
4, /* 240 */ 0, /* 241 */ 1, /* 242 */ 0, /* 243 */ 2, /* 244 */
0, /* 245 */ 1, /* 246 */ 0, /* 247 */ 3, /* 248 */ 0, /* 249 */
1, /* 250 */ 0, /* 251 */ 2, /* 252 */ 0, /* 253 */ 1, /* 254 */
0, /* 255 */
};
return _first_one[__byte];
}
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE

29
extern/STLport/5.2.1/src/c_locale.c vendored Normal file
View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include "c_locale.h"
#if defined (_STLP_WIN32) && !defined (_STLP_WCE)
# include "c_locale_win32/c_locale_win32.c"
#elif defined (_STLP_USE_GLIBC2_LOCALIZATION)
# include "c_locale_glibc/c_locale_glibc2.c" /* glibc 2.2 and newer */
#else
# include "c_locale_dummy/c_locale_dummy.c"
#endif

450
extern/STLport/5.2.1/src/c_locale.h vendored Normal file
View File

@@ -0,0 +1,450 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/*
* It is impossible to write the C++ locale library in terms of locales
* as defined in the C standard. Instead, we write the C++ locale and I/O
* library in terms of a low level C-like interface. This file defines
* that interface.
*
* The low-level locale interface can't be written portably; there
* must be a version of it for each platform that the C++ library
* is ported to. On many systems this interface may be a thin wrapper
* for existing functionality.
*/
#ifndef _STLP_C_LOCALE_IMPL_H
#define _STLP_C_LOCALE_IMPL_H
#include "stlport_prefix.h"
#include <wchar.h> /* for mbstate_t */
#include <stl/c_locale.h>
struct _Locale_name_hint;
#if defined (_GNU_SOURCE) && defined (__GLIBC__) && \
((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
# define _STLP_USE_GLIBC2_LOCALIZATION
# include <nl_types.h>
typedef nl_catd nl_catd_type;
#else
typedef int nl_catd_type;
#endif
/*
* A number: the maximum length of a simple locale name.
* (i.e. a name like like en_US, as opposed to a name like
* en_US/de_AT/de_AT/es_MX/en_US/en_US) */
#define _Locale_MAX_SIMPLE_NAME 256
#ifdef __cplusplus
extern "C" {
#endif
/*
* Typedefs:
*/
typedef unsigned short int _Locale_mask_t;
/* Function called during STLport library load phase. Might contain any
* code necessary to the platform localization layer.
*/
void _Locale_init(void);
/* Function called during STLport library unload. Might contain any
* code necessary to the platform localization layer.
*/
void _Locale_final(void);
/* Create a category of the locale with the given name.
*
* The char* argument is a simple (not a composite) locale name, which may
* neither be an empty string nor a null pointer.
*
* These functions return NULL to indicate failure. Failure reason should be reported
* using the __err_code pointer.
*/
struct _Locale_ctype* _Locale_ctype_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
struct _Locale_codecvt* _Locale_codecvt_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
struct _Locale_numeric* _Locale_numeric_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
struct _Locale_time* _Locale_time_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
struct _Locale_collate* _Locale_collate_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
struct _Locale_monetary* _Locale_monetary_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
struct _Locale_messages* _Locale_messages_create(const char *, struct _Locale_name_hint*, int * /* __err_code */);
/* Give error reason on failure of one of the _Locale_*_create functions. Available
* reasons are:
* 0: No specific error reason has been reported.
* 1: No platform support for the given facet.
* 2: Unknown locale name
* 3: No platform API for localization support.
* 4: No more memory
*/
#define _STLP_LOC_UNDEFINED 0
#define _STLP_LOC_UNSUPPORTED_FACET_CATEGORY 1
#define _STLP_LOC_UNKNOWN_NAME 2
#define _STLP_LOC_NO_PLATFORM_SUPPORT 3
#define _STLP_LOC_NO_MEMORY 4
/* Release a category of a locale
*
* These functions are used to release a category acquired with the
* according _Locale_*_create() functions.
*/
void _Locale_ctype_destroy(struct _Locale_ctype *);
void _Locale_codecvt_destroy(struct _Locale_codecvt *);
void _Locale_numeric_destroy(struct _Locale_numeric *);
void _Locale_time_destroy(struct _Locale_time *);
void _Locale_collate_destroy(struct _Locale_collate *);
void _Locale_monetary_destroy(struct _Locale_monetary *);
void _Locale_messages_destroy(struct _Locale_messages *);
/*
* Returns the name of the user's default locale in each
* category, as a null-terminated string. A NULL value
* means the default "C" locale.
*/
const char * _Locale_ctype_default(char * __buf);
const char * _Locale_numeric_default(char * __buf);
const char * _Locale_time_default(char * __buf);
const char * _Locale_collate_default(char * __buf);
const char * _Locale_monetary_default(char * __buf);
const char * _Locale_messages_default(char * __buf);
/* Retrieve the name of the given category
*
* __buf points to a buffer that can hold at least _Locale_MAX_SIMPLE_NAME
* characters. These functions store the name, as a null-terminated
* string, in __buf. This function can't fail, at worst name is truncated.
*/
char const* _Locale_ctype_name(const struct _Locale_ctype *, char* __buf);
char const* _Locale_codecvt_name(const struct _Locale_codecvt *, char* __buf);
char const* _Locale_numeric_name(const struct _Locale_numeric *, char* __buf);
char const* _Locale_time_name(const struct _Locale_time *, char* __buf);
char const* _Locale_collate_name(const struct _Locale_collate *, char* __buf);
char const* _Locale_monetary_name(const struct _Locale_monetary *, char* __buf);
char const* _Locale_messages_name(const struct _Locale_messages *, char* __buf);
/*
* cname is a (possibly composite) locale name---i.e. a name that can
* be passed to setlocale. __buf points to an array large enough to
* store at least _Locale_MAX_SIMPLE_NAME characters, and each of these
* functions extracts the name of a single category, stores it in buf
* as a null-terminated string, and returns buf.
*/
char const* _Locale_extract_ctype_name(const char *cname, char *__buf,
struct _Locale_name_hint* __hint, int *__err_code);
char const* _Locale_extract_numeric_name(const char *cname, char *__buf,
struct _Locale_name_hint* __hint, int *__err_code);
char const* _Locale_extract_time_name(const char *cname, char *__buf,
struct _Locale_name_hint* __hint, int *__err_code);
char const* _Locale_extract_collate_name(const char *cname, char *__buf,
struct _Locale_name_hint* __hint, int *__err_code);
char const* _Locale_extract_monetary_name(const char *cname, char *__buf,
struct _Locale_name_hint* __hint, int *__err_code);
char const* _Locale_extract_messages_name(const char *cname, char *__buf,
struct _Locale_name_hint* __hint, int *__err_code);
/* Functions to improve locale creation process. For some locale API (Win32)
* you need to find a locale identification from the name which can be a
* rather expensive operation especially if you do so for all facets of a
* locale. Those functions can be used to extract from a API dependent facet
* struct the information necessary to skip this lookup process for other
* facets creation. If not supported those function should return NULL.
*/
struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype*);
struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric*);
struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time*);
struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate*);
struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary*);
struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages*);
/*
* FUNCTIONS THAT USE CTYPE
*/
/*
* Narrow character functions:
*/
/*
* Returns a pointer to the beginning of the ctype table. The table is
* at least 257 bytes long; if p is the pointer returned by this
* function, then p[c] is valid if c is EOF or if p is any value of
* type unsigned char.
*/
const _Locale_mask_t * _Locale_ctype_table(struct _Locale_ctype *);
/*
* c is either EOF, or an unsigned char value.
*/
int _Locale_toupper(struct _Locale_ctype *, int /* c */);
int _Locale_tolower(struct _Locale_ctype *, int /* c */);
#ifndef _STLP_NO_WCHAR_T
/*
* Wide character functions:
*/
_Locale_mask_t _WLocale_ctype(struct _Locale_ctype *, wint_t, _Locale_mask_t);
wint_t _WLocale_tolower(struct _Locale_ctype *, wint_t);
wint_t _WLocale_toupper(struct _Locale_ctype *, wint_t);
/*
* Multibyte functions:
*/
/*
* Returns the number of bytes of the longest allowed multibyte
* character in the current encoding.
*/
int _WLocale_mb_cur_max(struct _Locale_codecvt *);
/*
* Returns the number of bytes of the shortest allowed multibyte
* character in the current encoding.
*/
int _WLocale_mb_cur_min(struct _Locale_codecvt *);
/*
* Returns 1 if the current multibyte encoding is stateless
* and does not require the use of an mbstate_t value.
*/
int _WLocale_is_stateless(struct _Locale_codecvt *);
/*
* Almost identical to mbrtowc, from 4.6.5.3.2 of NA1. The only
* important difference is that mbrtowc treats null wide characters
* as special, and we don't. Specifically: examines the characters
* in [from, from + n), extracts a single wide character, and stores
* it in *to. Modifies shift_state if appropriate. The return value,
* which is always positive, is the number of characters extracted from
* the input sequence. Return value is (size_t) -1 if there was an
* encoding error in the input sequence, and (size_t) -2 if
* [from, from + n) is correct but not complete. None of the pointer
* arguments may be null pointers.
*/
size_t _WLocale_mbtowc(struct _Locale_codecvt *,
wchar_t * /* to */,
const char * /* from */, size_t /* n */,
mbstate_t *);
/*
* Again, very similar to wcrtomb. The differences are that (1) it
* doesn't treat null characters as special; and (2) it stores at most
* n characters. Converts c to a multibyte sequence, stores that
* sequence in the array 'to', and returns the length of the sequence.
* Modifies shift_state if appropriate. The return value is (size_t) -1
* if c is not a valid wide character, and (size_t) -2 if the length of
* the multibyte character sequence is greater than n.
*/
size_t _WLocale_wctomb(struct _Locale_codecvt *,
char *, size_t,
const wchar_t,
mbstate_t *);
/*
* Inserts whatever characters are necessary to restore st to an
* initial shift state. Sets *next to buf + m, where m is the number
* of characters inserted. (0 <= m <= n.) Returns m to indicate
* success, (size_t) -1 to indicate error, (size_t) -2 to indicate
* partial success (more than n characters needed). For success or partial
* success, sets *next to buf + m.
*/
size_t _WLocale_unshift(struct _Locale_codecvt *,
mbstate_t *,
char *, size_t, char **);
#endif
/*
* FUNCTIONS THAT USE COLLATE
*/
/*
* Compares the two sequences [s1, s1 + n1) and [s2, s2 + n2). Neither
* sequence is assumed to be null-terminated, and null characters
* aren't special. If the two sequences are the same up through
* min(n1, n2), then the sequence that compares less is whichever one
* is shorter.
*/
int _Locale_strcmp(struct _Locale_collate *,
const char * /* s1 */, size_t /* n1 */,
const char * /* s2 */, size_t /* n2 */);
#ifndef _STLP_NO_WCHAR_T
int _WLocale_strcmp(struct _Locale_collate *,
const wchar_t * /* s1 */, size_t /* n1 */,
const wchar_t * /* s2 */, size_t /* n2 */);
#endif
/*
* Creates a transformed version of the string [s2, s2 + n2). The
* string may contain embedded null characters; nulls aren't special.
* The transformed string begins at s1, and contains at most n1
* characters. The return value is the length of the transformed
* string. If the return value is greater than n1 then this is an
* error condition: it indicates that there wasn't enough space. In
* that case, the contents of [s1, s1 + n1) is unspecified.
*/
size_t _Locale_strxfrm(struct _Locale_collate *,
char * /* s1 */, size_t /* n1 */,
const char * /* s2 */, size_t /* n2 */);
#ifndef _STLP_NO_WCHAR_T
size_t _WLocale_strxfrm(struct _Locale_collate *,
wchar_t * /* s1 */, size_t /* n1 */,
const wchar_t * /* s2 */, size_t /* n2 */);
#endif
/*
* FUNCTIONS THAT USE NUMERIC
*/
/*
* Equivalent to the first three fields in struct lconv. (C standard,
* section 7.4.)
*/
char _Locale_decimal_point(struct _Locale_numeric *);
char _Locale_thousands_sep(struct _Locale_numeric *);
const char * _Locale_grouping(struct _Locale_numeric *);
#ifndef _STLP_NO_WCHAR_T
wchar_t _WLocale_decimal_point(struct _Locale_numeric *);
wchar_t _WLocale_thousands_sep(struct _Locale_numeric *);
#endif
/*
* Return "true" and "false" in English locales, and something
* appropriate in non-English locales.
*/
const char * _Locale_true(struct _Locale_numeric *);
const char * _Locale_false(struct _Locale_numeric *);
#ifndef _STLP_NO_WCHAR_T
const wchar_t * _WLocale_true(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */);
const wchar_t * _WLocale_false(struct _Locale_numeric *, wchar_t* /* buf */, size_t /* bufSize */);
#endif
/*
* FUNCTIONS THAT USE MONETARY
*/
/*
* Return the obvious fields of struct lconv.
*/
const char * _Locale_int_curr_symbol(struct _Locale_monetary *);
const char * _Locale_currency_symbol(struct _Locale_monetary *);
char _Locale_mon_decimal_point(struct _Locale_monetary *);
char _Locale_mon_thousands_sep(struct _Locale_monetary *);
const char * _Locale_mon_grouping(struct _Locale_monetary *);
const char * _Locale_positive_sign(struct _Locale_monetary *);
const char * _Locale_negative_sign(struct _Locale_monetary *);
char _Locale_int_frac_digits(struct _Locale_monetary *);
char _Locale_frac_digits(struct _Locale_monetary *);
int _Locale_p_cs_precedes(struct _Locale_monetary *);
int _Locale_p_sep_by_space(struct _Locale_monetary *);
int _Locale_p_sign_posn(struct _Locale_monetary *);
int _Locale_n_cs_precedes(struct _Locale_monetary *);
int _Locale_n_sep_by_space(struct _Locale_monetary *);
int _Locale_n_sign_posn(struct _Locale_monetary *);
#ifndef _STLP_NO_WCHAR_T
const wchar_t * _WLocale_int_curr_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
const wchar_t * _WLocale_currency_symbol(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary *);
wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary *);
const wchar_t * _WLocale_positive_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
const wchar_t * _WLocale_negative_sign(struct _Locale_monetary *, wchar_t* /* buf */, size_t /* bufSize */);
#endif
/*
* FUNCTIONS THAT USE TIME
*/
/*
* month is in the range [0, 12).
*/
const char * _Locale_full_monthname(struct _Locale_time *, int /* month */);
const char * _Locale_abbrev_monthname(struct _Locale_time *, int /* month */);
#ifndef _STLP_NO_WCHAR_T
const wchar_t * _WLocale_full_monthname(struct _Locale_time *, int /* month */,
wchar_t* /* buf */, size_t /* bufSize */);
const wchar_t * _WLocale_abbrev_monthname(struct _Locale_time *, int /* month */,
wchar_t* /* buf */, size_t /* bufSize */);
#endif
/*
* day is in the range [0, 7). Sunday is 0.
*/
const char * _Locale_full_dayofweek(struct _Locale_time *, int /* day */);
const char * _Locale_abbrev_dayofweek(struct _Locale_time *, int /* day */);
#ifndef _STLP_NO_WCHAR_T
const wchar_t * _WLocale_full_dayofweek(struct _Locale_time *, int /* day */,
wchar_t* /* buf */, size_t /* bufSize */);
const wchar_t * _WLocale_abbrev_dayofweek(struct _Locale_time *, int /* day */,
wchar_t* /* buf */, size_t /* bufSize */);
#endif
const char * _Locale_d_t_fmt(struct _Locale_time *);
const char * _Locale_d_fmt(struct _Locale_time *);
const char * _Locale_t_fmt(struct _Locale_time *);
const char * _Locale_long_d_t_fmt(struct _Locale_time*);
const char * _Locale_long_d_fmt(struct _Locale_time*);
const char * _Locale_am_str(struct _Locale_time *);
const char * _Locale_pm_str(struct _Locale_time *);
#ifndef _STLP_NO_WCHAR_T
const wchar_t * _WLocale_am_str(struct _Locale_time *,
wchar_t* /* buf */, size_t /* bufSize */);
const wchar_t * _WLocale_pm_str(struct _Locale_time *,
wchar_t* /* buf */, size_t /* bufSize */);
#endif
/*
* FUNCTIONS THAT USE MESSAGES
*/
/*
* Very similar to catopen, except that it uses the given message
* category to determine which catalog to open.
*/
nl_catd_type _Locale_catopen(struct _Locale_messages*, const char*);
/* Complementary to _Locale_catopen.
* The catalog must be a value that was returned by a previous call
* to _Locale_catopen.
*/
void _Locale_catclose(struct _Locale_messages*, nl_catd_type);
/*
* Returns a string, identified by a set index and a message index,
* from an opened message catalog. Returns the supplied default if
* no such string exists.
*/
const char * _Locale_catgets(struct _Locale_messages *, nl_catd_type,
int, int,const char *);
#ifdef __cplusplus
}
#endif
#endif /* _STLP_C_LOCALE_IMPL_H */

View File

@@ -0,0 +1,485 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* This is a "stub" implementation of the "c_locale.h" interface,
intended for operating systems where we have not yet written
a real implementation. A C++ library using this stub implementation
is still standard-conforming, since the C++ standard does not require
that any locales other than "C" be supported.
*/
#include <string.h>
#include <wchar.h>
#include <ctype.h>
#include <wctype.h>
#include <limits.h>
#if defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
# define _STLP_STRNCPY(D, DS, S, C) strncpy_s(D, DS, S, C)
# if !defined (_STLP_NO_WCHAR_T)
# define _STLP_WCSNCPY(D, DS, S, C) wcsncpy_s(D, DS, S, C)
# endif
#else
# define _STLP_STRNCPY(D, DS, S, C) strncpy(D, S, C)
# if !defined (_STLP_NO_WCHAR_T)
# define _STLP_WCSNCPY(D, DS, S, C) wcsncpy(D, S, C)
# endif
#endif
static const char *_C_name = "C";
static const char *_empty_str = "";
#ifndef _STLP_NO_WCHAR_T
static const wchar_t *_empty_wstr = L"";
#endif
static _Locale_mask_t ctable[256];
/* Framework functions */
void _Locale_init(void) {
/* Ctype table for the ASCII character set. */
char c;
/* We might never reach 128 when char is signed. */
for (c = 0; /* c != 128 */; ++c) {
if (isalpha(c)) ctable[(unsigned char)c] |= _Locale_ALPHA;
if (iscntrl(c)) ctable[(unsigned char)c] |= _Locale_CNTRL;
if (isdigit(c)) ctable[(unsigned char)c] |= _Locale_DIGIT;
if (isprint(c)) ctable[(unsigned char)c] |= _Locale_PRINT;
if (ispunct(c)) ctable[(unsigned char)c] |= _Locale_PUNCT;
if (isspace(c)) ctable[(unsigned char)c] |= _Locale_SPACE;
if (isxdigit(c)) ctable[(unsigned char)c] |= _Locale_XDIGIT;
if (isupper(c)) ctable[(unsigned char)c] |= _Locale_UPPER;
if (islower(c)) ctable[(unsigned char)c] |= _Locale_LOWER;
if (c == 127) break;
}
/* ASCII is a 7-bit code, so everything else is non-ASCII. */
memset(&(ctable[128]), 0, 128 * sizeof(_Locale_mask_t));
}
void _Locale_final(void)
{}
void* _Locale_create(const char* name, int *__err_code) {
if (name[0] == 'C' && name[1] == 0)
{ return (void*)0x1; }
*__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;
}
struct _Locale_ctype* _Locale_ctype_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_ctype*)_Locale_create(name, __err_code); }
struct _Locale_codecvt* _Locale_codecvt_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_codecvt*)_Locale_create(name, __err_code); }
struct _Locale_numeric* _Locale_numeric_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_numeric*)_Locale_create(name, __err_code); }
struct _Locale_time* _Locale_time_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_time*)_Locale_create(name, __err_code); }
struct _Locale_collate* _Locale_collate_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_collate*)_Locale_create(name, __err_code); }
struct _Locale_monetary* _Locale_monetary_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_monetary*)_Locale_create(name, __err_code); }
struct _Locale_messages* _Locale_messages_create(const char *name,
struct _Locale_name_hint* hint, int *__err_code)
{ return (struct _Locale_messages*)_Locale_create(name, __err_code); }
const char *_Locale_ctype_default(char* buf) { return _C_name; }
const char *_Locale_numeric_default(char * buf) { return _C_name; }
const char *_Locale_time_default(char* buf) { return _C_name; }
const char *_Locale_collate_default(char* buf) { return _C_name; }
const char *_Locale_monetary_default(char* buf) { return _C_name; }
const char *_Locale_messages_default(char* buf) { return _C_name; }
char const* _Locale_ctype_name(const struct _Locale_ctype *lctype, char* buf)
{ return _C_name; }
char const* _Locale_codecvt_name(const struct _Locale_codecvt *lcodecvt, char* buf)
{ return _C_name; }
char const* _Locale_numeric_name(const struct _Locale_numeric *lnum, char* buf)
{ return _C_name; }
char const* _Locale_time_name(const struct _Locale_time *ltime, char* buf)
{ return _C_name; }
char const* _Locale_collate_name(const struct _Locale_collate *lcol, char* buf)
{ return _C_name; }
char const* _Locale_monetary_name(const struct _Locale_monetary *lmon, char* buf)
{ return _C_name; }
char const* _Locale_messages_name(const struct _Locale_messages *lmes, char* buf)
{ return _C_name; }
void _Locale_ctype_destroy(struct _Locale_ctype *lctype) {}
void _Locale_codecvt_destroy(struct _Locale_codecvt *lcodecvt) {}
void _Locale_numeric_destroy(struct _Locale_numeric *lnum) {}
void _Locale_time_destroy(struct _Locale_time *ltime) {}
void _Locale_collate_destroy(struct _Locale_collate *lcol) {}
void _Locale_monetary_destroy(struct _Locale_monetary *lmon) {}
void _Locale_messages_destroy(struct _Locale_messages *lmes) {}
static char const* _Locale_extract_name(const char* name, int *__err_code) {
// When the request is the default locale or the "C" locale we answer "C".
if (name[0] == 0 ||
(name[0] == 'C' && name[1] == 0))
{ return _C_name; }
*__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;
}
char const* _Locale_extract_ctype_name(const char *name, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return _Locale_extract_name(name, __err_code); }
char const* _Locale_extract_numeric_name(const char *name, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return _Locale_extract_name(name, __err_code); }
char const* _Locale_extract_time_name(const char*name, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return _Locale_extract_name(name, __err_code); }
char const* _Locale_extract_collate_name(const char *name, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return _Locale_extract_name(name, __err_code); }
char const* _Locale_extract_monetary_name(const char *name, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return _Locale_extract_name(name, __err_code); }
char const* _Locale_extract_messages_name(const char *name, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return _Locale_extract_name(name, __err_code); }
struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype* ctype)
{ return 0; }
struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric* numeric)
{ return 0; }
struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time* time)
{ return 0; }
struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate* collate)
{ return 0; }
struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary* monetary)
{ return 0; }
struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages* messages)
{ return 0; }
/* ctype */
const _Locale_mask_t* _Locale_ctype_table(struct _Locale_ctype* lctype) {
_STLP_MARK_PARAMETER_AS_UNUSED(lctype)
return ctable;
}
int _Locale_toupper(struct _Locale_ctype*lctype, int c)
{ return toupper(c); }
int _Locale_tolower(struct _Locale_ctype*lctype, int c)
{ return tolower(c); }
#ifndef _STLP_NO_WCHAR_T
_Locale_mask_t _WLocale_ctype(struct _Locale_ctype *lctype, wint_t wc, _Locale_mask_t mask) {
_Locale_mask_t ret = 0;
if ((mask & _Locale_ALPHA) != 0 && iswalpha(wc))
ret |= _Locale_ALPHA;
if ((mask & _Locale_CNTRL) != 0 && iswcntrl(wc))
ret |= _Locale_CNTRL;
if ((mask & _Locale_DIGIT) != 0 && iswdigit(wc))
ret |= _Locale_DIGIT;
if ((mask & _Locale_PRINT) != 0 && iswprint(wc))
ret |= _Locale_PRINT;
if ((mask & _Locale_PUNCT) != 0 && iswpunct(wc))
ret |= _Locale_PUNCT;
if ((mask & _Locale_SPACE) != 0 && iswspace(wc))
ret |= _Locale_SPACE;
if ((mask & _Locale_XDIGIT) != 0 && iswxdigit(wc))
ret |= _Locale_XDIGIT;
if ((mask & _Locale_UPPER) != 0 && iswupper(wc))
ret |= _Locale_UPPER;
if ((mask & _Locale_LOWER) != 0 && iswlower(wc))
ret |= _Locale_LOWER;
return ret;
}
wint_t _WLocale_tolower(struct _Locale_ctype *lctype, wint_t wc)
{ return towlower(wc); }
wint_t _WLocale_toupper(struct _Locale_ctype *lctype, wint_t wc)
{ return towupper(wc); }
int _WLocale_mb_cur_max (struct _Locale_codecvt *lcodecvt) { return 1; }
int _WLocale_mb_cur_min (struct _Locale_codecvt *lcodecvt) { return 1; }
int _WLocale_is_stateless (struct _Locale_codecvt *lcodecvt) { return 1; }
size_t _WLocale_mbtowc(struct _Locale_codecvt *lcodecvt,
wchar_t *to,
const char *from, size_t n,
mbstate_t *st)
{ *to = *from; return 1; }
size_t _WLocale_wctomb(struct _Locale_codecvt *lcodecvt,
char *to, size_t n,
const wchar_t c,
mbstate_t *st)
{ *to = (char)c; return 1; }
size_t _WLocale_unshift(struct _Locale_codecvt *lcodecvt,
mbstate_t *st,
char *buf, size_t n, char ** next)
{ *next = buf; return 0; }
#endif
/* Collate */
int _Locale_strcmp(struct _Locale_collate* lcol,
const char* s1, size_t n1, const char* s2, size_t n2) {
int ret = 0;
char buf1[64], buf2[64];
while (n1 > 0 || n2 > 0) {
size_t bufsize1 = n1 < 63 ? n1 : 63;
size_t bufsize2 = n2 < 63 ? n2 : 63;
_STLP_STRNCPY(buf1, 64, s1, bufsize1); buf1[bufsize1] = 0;
_STLP_STRNCPY(buf2, 64, s2, bufsize2); buf2[bufsize2] = 0;
ret = strcmp(buf1, buf2);
if (ret != 0) return ret < 0 ? -1 : 1;
s1 += bufsize1; n1 -= bufsize1;
s2 += bufsize2; n2 -= bufsize2;
}
return ret == 0 ? 0 : (ret < 0 ? -1 : 1);
}
#ifndef _STLP_NO_WCHAR_T
int _WLocale_strcmp(struct _Locale_collate* lcol,
const wchar_t* s1, size_t n1, const wchar_t* s2, size_t n2) {
int ret = 0;
wchar_t buf1[64], buf2[64];
while (n1 > 0 || n2 > 0) {
size_t bufsize1 = n1 < 63 ? n1 : 63;
size_t bufsize2 = n2 < 63 ? n2 : 63;
_STLP_WCSNCPY(buf1, 64, s1, bufsize1); buf1[bufsize1] = 0;
_STLP_WCSNCPY(buf2, 64, s2, bufsize2); buf2[bufsize2] = 0;
ret = wcscmp(buf1, buf2);
if (ret != 0) return ret < 0 ? -1 : 1;
s1 += bufsize1; n1 -= bufsize1;
s2 += bufsize2; n2 -= bufsize2;
}
return ret == 0 ? 0 : (ret < 0 ? -1 : 1);
}
#endif
size_t _Locale_strxfrm(struct _Locale_collate* lcol,
char* dest, size_t dest_n,
const char* src, size_t src_n) {
if (dest != 0) {
_STLP_STRNCPY(dest, dest_n, src, dest_n - 1); dest[dest_n - 1] = 0;
}
return src_n;
}
#ifndef _STLP_NO_WCHAR_T
size_t _WLocale_strxfrm(struct _Locale_collate* lcol,
wchar_t* dest, size_t dest_n,
const wchar_t* src, size_t src_n) {
if (dest != 0) {
_STLP_WCSNCPY(dest, dest_n, src, dest_n - 1); dest[dest_n - 1] = 0;
}
return src_n;
}
#endif
/* Numeric */
char _Locale_decimal_point(struct _Locale_numeric* lnum)
{ return '.'; }
char _Locale_thousands_sep(struct _Locale_numeric* lnum)
{ return ','; }
const char* _Locale_grouping(struct _Locale_numeric * lnum)
{ return _empty_str; }
const char * _Locale_true(struct _Locale_numeric * lnum)
{ return "true"; }
const char * _Locale_false(struct _Locale_numeric * lnum)
{ return "false"; }
#ifndef _STLP_NO_WCHAR_T
wchar_t _WLocale_decimal_point(struct _Locale_numeric* lnum)
{ return L'.'; }
wchar_t _WLocale_thousands_sep(struct _Locale_numeric* lnum)
{ return L','; }
const wchar_t * _WLocale_true(struct _Locale_numeric* lnum, wchar_t* buf, size_t bufSize)
{ return L"true"; }
const wchar_t * _WLocale_false(struct _Locale_numeric* lnum, wchar_t* buf, size_t bufSize)
{ return L"false"; }
#endif
/* Monetary */
const char* _Locale_int_curr_symbol(struct _Locale_monetary * lmon)
{ return _empty_str; }
const char* _Locale_currency_symbol(struct _Locale_monetary * lmon)
{ return _empty_str; }
char _Locale_mon_decimal_point(struct _Locale_monetary * lmon)
{ return '.'; }
char _Locale_mon_thousands_sep(struct _Locale_monetary * lmon)
{ return ','; }
const char* _Locale_mon_grouping(struct _Locale_monetary * lmon)
{ return _empty_str; }
const char* _Locale_positive_sign(struct _Locale_monetary * lmon)
{ return _empty_str; }
const char* _Locale_negative_sign(struct _Locale_monetary * lmon)
{ return _empty_str; }
char _Locale_int_frac_digits(struct _Locale_monetary * lmon)
{ return 0; }
char _Locale_frac_digits(struct _Locale_monetary * lmon)
{ return 0; }
int _Locale_p_cs_precedes(struct _Locale_monetary * lmon)
{ return CHAR_MAX; }
int _Locale_p_sep_by_space(struct _Locale_monetary * lmon)
{ return CHAR_MAX; }
int _Locale_p_sign_posn(struct _Locale_monetary * lmon)
{ return CHAR_MAX; }
int _Locale_n_cs_precedes(struct _Locale_monetary * lmon)
{ return CHAR_MAX; }
int _Locale_n_sep_by_space(struct _Locale_monetary * lmon)
{ return CHAR_MAX; }
int _Locale_n_sign_posn(struct _Locale_monetary * lmon)
{ return CHAR_MAX; }
#ifndef _STLP_NO_WCHAR_T
const wchar_t* _WLocale_int_curr_symbol(struct _Locale_monetary * lmon,
wchar_t* buf, size_t bufSize)
{ return _empty_wstr; }
const wchar_t* _WLocale_currency_symbol(struct _Locale_monetary * lmon,
wchar_t* buf, size_t bufSize)
{ return _empty_wstr; }
wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary * lmon)
{ return L'.'; }
wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary * lmon)
{ return L','; }
const wchar_t* _WLocale_positive_sign(struct _Locale_monetary * lmon,
wchar_t* buf, size_t bufSize)
{ return _empty_wstr; }
const wchar_t* _WLocale_negative_sign(struct _Locale_monetary * lmon,
wchar_t* buf, size_t bufSize)
{ return _empty_wstr; }
#endif
/* Time */
static const char* full_monthname[] =
{ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
const char * _Locale_full_monthname(struct _Locale_time * ltime, int n)
{ return full_monthname[n]; }
static const char* abbrev_monthname[] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
const char * _Locale_abbrev_monthname(struct _Locale_time * ltime, int n)
{ return abbrev_monthname[n]; }
static const char* full_dayname[] =
{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
const char * _Locale_full_dayofweek(struct _Locale_time * ltime, int n)
{ return full_dayname[n]; }
static const char* abbrev_dayname[] =
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
const char * _Locale_abbrev_dayofweek(struct _Locale_time * ltime, int n)
{ return abbrev_dayname[n]; }
const char* _Locale_d_t_fmt(struct _Locale_time* ltime)
{ return "%m/%d/%y"; }
const char* _Locale_d_fmt(struct _Locale_time* ltime)
{ return "%m/%d/%y"; }
const char* _Locale_t_fmt(struct _Locale_time* ltime)
{ return "%H:%M:%S"; }
const char* _Locale_long_d_t_fmt(struct _Locale_time* ltime)
{ return _empty_str; }
const char* _Locale_long_d_fmt(struct _Locale_time* ltime)
{ return _empty_str; }
const char* _Locale_am_str(struct _Locale_time* ltime)
{ return "AM"; }
const char* _Locale_pm_str(struct _Locale_time* ltime)
{ return "PM"; }
#ifndef _STLP_NO_WCHAR_T
static const wchar_t* full_wmonthname[] =
{ L"January", L"February", L"March", L"April", L"May", L"June",
L"July", L"August", L"September", L"October", L"November", L"December" };
const wchar_t * _WLocale_full_monthname(struct _Locale_time * ltime, int n,
wchar_t* buf, size_t bufSize)
{ return full_wmonthname[n]; }
static const wchar_t* abbrev_wmonthname[] =
{ L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" };
const wchar_t * _WLocale_abbrev_monthname(struct _Locale_time * ltime, int n,
wchar_t* buf, size_t bufSize)
{ return abbrev_wmonthname[n]; }
static const wchar_t* full_wdayname[] =
{ L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday", L"Friday", L"Saturday" };
const wchar_t * _WLocale_full_dayofweek(struct _Locale_time * ltime, int n,
wchar_t* buf, size_t bufSize)
{ return full_wdayname[n]; }
static const wchar_t* abbrev_wdayname[] =
{ L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" };
const wchar_t * _WLocale_abbrev_dayofweek(struct _Locale_time * ltime, int n,
wchar_t* buf, size_t bufSize)
{ return abbrev_wdayname[n]; }
const wchar_t* _WLocale_am_str(struct _Locale_time* ltime,
wchar_t* buf, size_t bufSize)
{ return L"AM"; }
const wchar_t* _WLocale_pm_str(struct _Locale_time* ltime,
wchar_t* buf, size_t bufSize)
{ return L"PM"; }
#endif
/* Messages */
nl_catd_type _Locale_catopen(struct _Locale_messages* lmes, const char* name)
{ return -1; }
void _Locale_catclose(struct _Locale_messages* lmes, nl_catd_type cat) {}
const char* _Locale_catgets(struct _Locale_messages* lmes, nl_catd_type cat,
int setid, int msgid, const char *dfault)
{ return dfault; }

View File

@@ -0,0 +1,705 @@
#include <locale.h>
#include <langinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <wctype.h>
#include <string.h>
#include <stdint.h>
static const char *_empty_str = "";
static const char *_C_name = "C";
static wchar_t* _ToWChar(const char* buf, wchar_t *wbuf, size_t wbufSize) {
wchar_t *wcur = wbuf;
wchar_t *wend = wbuf + wbufSize - 1;
for (; wcur != wend && *buf != 0; ++buf, ++wcur)
*wcur = *buf;
*wcur = 0;
return wbuf;
}
#if 0
struct _Locale_ctype
{
locale_t __cloc;
};
struct _Locale_numeric
{
locale_t __cloc;
};
struct _Locale_time
{
locale_t __cloc;
};
struct _Locale_collate
{
locale_t __cloc;
};
struct _Locale_monetary
{
locale_t __cloc;
};
struct _Locale_messages
{
locale_t __cloc;
};
#endif
void _Locale_init()
{}
void _Locale_final()
{}
struct _Locale_ctype *_Locale_ctype_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
*__err_code = _STLP_LOC_UNKNOWN_NAME;
return (struct _Locale_ctype*)newlocale(LC_CTYPE_MASK, nm, NULL);
}
struct _Locale_codecvt *_Locale_codecvt_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
// Glibc do not support multibyte manipulation for the moment, it simply implements "C".
if (nm[0] == 'C' && nm[1] == 0)
{ return (struct _Locale_codecvt*)0x01; }
*__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;
}
struct _Locale_numeric *_Locale_numeric_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
*__err_code = _STLP_LOC_UNKNOWN_NAME;
return (struct _Locale_numeric*)newlocale(LC_NUMERIC_MASK, nm, NULL);
}
struct _Locale_time *_Locale_time_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
*__err_code = _STLP_LOC_UNKNOWN_NAME;
return (struct _Locale_time*)newlocale(LC_TIME_MASK, nm, NULL);
}
struct _Locale_collate *_Locale_collate_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
*__err_code = _STLP_LOC_UNKNOWN_NAME;
return (struct _Locale_collate*)newlocale(LC_COLLATE_MASK, nm, NULL);
}
struct _Locale_monetary *_Locale_monetary_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
*__err_code = _STLP_LOC_UNKNOWN_NAME;
return (struct _Locale_monetary*)newlocale(LC_MONETARY_MASK, nm, NULL);
}
struct _Locale_messages *_Locale_messages_create(const char *nm, struct _Locale_name_hint* hint,
int *__err_code) {
*__err_code = _STLP_LOC_UNKNOWN_NAME;
return (struct _Locale_messages*)newlocale(LC_MESSAGES_MASK, nm, NULL);
}
/*
try to see locale category LC should be used from environment;
according POSIX, the order is
1. LC_ALL
2. category (LC_CTYPE, LC_NUMERIC, ... )
3. LANG
If set nothing, return "C" (this really implementation-specific).
*/
static const char *_Locale_aux_default( const char *LC, char *nm )
{
char *name = getenv( "LC_ALL" );
if ( name != NULL && *name != 0 ) {
return name;
}
name = getenv( LC );
if ( name != NULL && *name != 0 ) {
return name;
}
name = getenv( "LANG" );
if ( name != NULL && *name != 0 ) {
return name;
}
return _C_name;
}
const char *_Locale_ctype_default( char *nm )
{
return _Locale_aux_default( "LC_CTYPE", nm );
}
const char *_Locale_numeric_default( char *nm )
{
return _Locale_aux_default( "LC_NUMERIC", nm );
}
const char *_Locale_time_default( char *nm )
{
return _Locale_aux_default( "LC_TIME", nm );
}
const char *_Locale_collate_default( char *nm )
{
return _Locale_aux_default( "LC_COLLATE", nm );
}
const char *_Locale_monetary_default( char *nm )
{
return _Locale_aux_default( "LC_MONETARY", nm );
}
const char *_Locale_messages_default( char *nm )
{
return _Locale_aux_default( "LC_MESSAGES", nm );
}
char const*_Locale_ctype_name( const struct _Locale_ctype *__loc, char *buf )
{
return ((locale_t)__loc)->__names[LC_CTYPE];
}
char const*_Locale_codecvt_name( const struct _Locale_codecvt *__loc, char *buf )
{
return _C_name;
}
char const*_Locale_numeric_name( const struct _Locale_numeric *__loc, char *buf )
{
return ((locale_t)__loc)->__names[LC_NUMERIC];
}
char const*_Locale_time_name( const struct _Locale_time *__loc, char *buf )
{
return ((locale_t)__loc)->__names[LC_TIME];
}
char const*_Locale_collate_name( const struct _Locale_collate *__loc, char *buf )
{
return ((locale_t)__loc)->__names[LC_COLLATE];
}
char const*_Locale_monetary_name( const struct _Locale_monetary *__loc, char *buf )
{
return ((locale_t)__loc)->__names[LC_MONETARY];
}
char const*_Locale_messages_name( const struct _Locale_messages *__loc, char *buf )
{
return ((locale_t)__loc)->__names[LC_MESSAGES];
}
void _Locale_ctype_destroy( struct _Locale_ctype *__loc )
{ freelocale((locale_t)__loc); }
void _Locale_codecvt_destroy( struct _Locale_codecvt *__loc )
{}
void _Locale_numeric_destroy( struct _Locale_numeric *__loc )
{ freelocale((locale_t)__loc); }
void _Locale_time_destroy( struct _Locale_time *__loc )
{ freelocale((locale_t)__loc); }
void _Locale_collate_destroy( struct _Locale_collate *__loc )
{ freelocale((locale_t)__loc); }
void _Locale_monetary_destroy( struct _Locale_monetary *__loc )
{ freelocale((locale_t)__loc); }
void _Locale_messages_destroy( struct _Locale_messages* __loc )
{ freelocale((locale_t)__loc); }
/*
* locale loc expected either locale name indeed (platform-specific)
* or string like "LC_CTYPE=LocaleNameForCType;LC_NUMERIC=LocaleNameForNum;"
*
*/
static char const*__Extract_locale_name( const char *loc, const char *category, char *buf )
{
char *expr;
size_t len_name;
if( loc[0]=='L' && loc[1]=='C' && loc[2]=='_') {
expr = strstr( (char*)loc, category );
if ( expr == NULL )
return NULL; /* Category not found. */
++expr;
len_name = strcspn( expr, ";" );
len_name = len_name >= _Locale_MAX_SIMPLE_NAME ? _Locale_MAX_SIMPLE_NAME - 1 : len_name;
strncpy( buf, expr, len_name );
buf[len_name] = 0;
return buf;
}
return loc;
}
char const*_Locale_extract_ctype_name(const char *loc, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return __Extract_locale_name( loc, "LC_CTYPE=", buf ); }
char const*_Locale_extract_numeric_name(const char *loc, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return __Extract_locale_name( loc, "LC_NUMERIC=", buf ); }
char const*_Locale_extract_time_name(const char *loc, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return __Extract_locale_name( loc, "LC_TIME=", buf ); }
char const*_Locale_extract_collate_name(const char *loc, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return __Extract_locale_name( loc, "LC_COLLATE=", buf ); }
char const*_Locale_extract_monetary_name(const char *loc, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return __Extract_locale_name( loc, "LC_MONETARY=", buf ); }
char const*_Locale_extract_messages_name(const char *loc, char *buf,
struct _Locale_name_hint* hint, int *__err_code)
{ return __Extract_locale_name( loc, "LC_MESSAGES=", buf ); }
struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype* ctype)
{ return 0; }
struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric* numeric)
{ return 0; }
struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time* time)
{ return 0; }
struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate* collate)
{ return 0; }
struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary* monetary)
{ return 0; }
struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages* messages)
{ return 0; }
/* ctype */
const _Locale_mask_t *_Locale_ctype_table( struct _Locale_ctype *__loc )
{
/* return table with masks (upper, lower, alpha, etc.) */
_STLP_STATIC_ASSERT( sizeof(_Locale_mask_t) == sizeof(((locale_t)__loc)->__ctype_b[0]) )
return ((locale_t)__loc)->__ctype_b;
}
int _Locale_toupper( struct _Locale_ctype *__loc, int c )
{ return ((locale_t)__loc)->__ctype_toupper[c]; }
int _Locale_tolower( struct _Locale_ctype *__loc, int c )
{ return ((locale_t)__loc)->__ctype_tolower[c]; }
#if !defined (_STLP_NO_WCHAR_T)
_Locale_mask_t _WLocale_ctype( struct _Locale_ctype *__loc, wint_t wc, _Locale_mask_t __mask )
{
_Locale_mask_t ret = 0;
if ((__mask & _Locale_ALPHA) != 0 && iswalpha_l(wc, (locale_t)__loc))
ret |= _Locale_ALPHA;
if ((__mask & _Locale_CNTRL) != 0 && iswcntrl_l(wc, (locale_t)__loc))
ret |= _Locale_CNTRL;
if ((__mask & _Locale_DIGIT) != 0 && iswdigit_l(wc, (locale_t)__loc))
ret |= _Locale_DIGIT;
if ((__mask & _Locale_PRINT) != 0 && iswprint_l(wc, (locale_t)__loc))
ret |= _Locale_PRINT;
if ((__mask & _Locale_PUNCT) != 0 && iswpunct_l(wc, (locale_t)__loc))
ret |= _Locale_PUNCT;
if ((__mask & _Locale_SPACE) != 0 && iswspace_l(wc, (locale_t)__loc))
ret |= _Locale_SPACE;
if ((__mask & _Locale_XDIGIT) != 0 && iswxdigit_l(wc, (locale_t)__loc))
ret |= _Locale_XDIGIT;
if ((__mask & _Locale_UPPER) != 0 && iswupper_l(wc, (locale_t)__loc))
ret |= _Locale_UPPER;
if ((__mask & _Locale_LOWER) != 0 && iswlower_l(wc, (locale_t)__loc))
ret |= _Locale_LOWER;
return ret;
}
wint_t _WLocale_tolower( struct _Locale_ctype *__loc, wint_t c )
{
return towlower_l( c, ((locale_t)__loc) );
}
wint_t _WLocale_toupper( struct _Locale_ctype *__loc, wint_t c )
{
return towupper_l( c, ((locale_t)__loc) );
}
#endif
int _WLocale_mb_cur_max( struct _Locale_codecvt * lcodecvt) { return 1; }
int _WLocale_mb_cur_min( struct _Locale_codecvt * lcodecvt) { return 1; }
int _WLocale_is_stateless( struct _Locale_codecvt * lcodecvt) { return 1; }
#if !defined (_STLP_NO_WCHAR_T)
size_t _WLocale_mbtowc(struct _Locale_codecvt *lcodecvt,
wchar_t *to,
const char *from, size_t n,
mbstate_t *st)
{ *to = *from; return 1; }
size_t _WLocale_wctomb(struct _Locale_codecvt *lcodecvt,
char *to, size_t n,
const wchar_t c,
mbstate_t *st)
{ *to = (char)c; return 1; }
#endif
size_t _WLocale_unshift(struct _Locale_codecvt *lcodecvt,
mbstate_t *st,
char *buf, size_t n, char ** next)
{ *next = buf; return 0; }
/* Collate */
int _Locale_strcmp(struct _Locale_collate * __loc,
const char *s1, size_t n1,
const char *s2, size_t n2) {
int ret = 0;
char buf1[64], buf2[64];
while (n1 > 0 || n2 > 0) {
size_t bufsize1 = n1 < 63 ? n1 : 63;
size_t bufsize2 = n2 < 63 ? n2 : 63;
strncpy(buf1, s1, bufsize1); buf1[bufsize1] = 0;
strncpy(buf2, s2, bufsize2); buf2[bufsize2] = 0;
ret = strcoll_l(buf1, buf2, (locale_t)__loc);
if (ret != 0) return ret;
s1 += bufsize1; n1 -= bufsize1;
s2 += bufsize2; n2 -= bufsize2;
}
return ret;
}
#if !defined (_STLP_NO_WCHAR_T)
int _WLocale_strcmp(struct _Locale_collate *__loc,
const wchar_t *s1, size_t n1,
const wchar_t *s2, size_t n2) {
int ret = 0;
wchar_t buf1[64], buf2[64];
while (n1 > 0 || n2 > 0) {
size_t bufsize1 = n1 < 63 ? n1 : 63;
size_t bufsize2 = n2 < 63 ? n2 : 63;
wcsncpy(buf1, s1, bufsize1); buf1[bufsize1] = 0;
wcsncpy(buf2, s2, bufsize2); buf2[bufsize2] = 0;
ret = wcscoll_l(buf1, buf2, (locale_t)__loc);
if (ret != 0) return ret;
s1 += bufsize1; n1 -= bufsize1;
s2 += bufsize2; n2 -= bufsize2;
}
return ret;
}
#endif
size_t _Locale_strxfrm(struct _Locale_collate *__loc,
char *dest, size_t dest_n,
const char *src, size_t src_n )
{
const char *real_src;
char *buf = NULL;
size_t result;
if (src_n == 0)
{
if (dest != NULL) dest[0] = 0;
return 0;
}
if (src[src_n] != 0) {
buf = malloc(src_n + 1);
strncpy(buf, src, src_n);
buf[src_n] = 0;
real_src = buf;
}
else
real_src = src;
result = strxfrm_l(dest, real_src, dest_n, (locale_t)__loc);
if (buf != NULL) free(buf);
return result;
}
# ifndef _STLP_NO_WCHAR_T
size_t _WLocale_strxfrm( struct _Locale_collate *__loc,
wchar_t *dest, size_t dest_n,
const wchar_t *src, size_t src_n )
{
const wchar_t *real_src;
wchar_t *buf = NULL;
size_t result;
if (src_n == 0)
{
if (dest != NULL) dest[0] = 0;
return 0;
}
if (src[src_n] != 0) {
buf = malloc((src_n + 1) * sizeof(wchar_t));
wcsncpy(buf, src, src_n);
buf[src_n] = 0;
real_src = buf;
}
else
real_src = src;
result = wcsxfrm_l(dest, real_src, dest_n, (locale_t)__loc);
if (buf != NULL) free(buf);
return result;
}
# endif
/* Numeric */
char _Locale_decimal_point(struct _Locale_numeric *__loc)
{
return *(nl_langinfo_l(RADIXCHAR, (locale_t)__loc));
}
char _Locale_thousands_sep(struct _Locale_numeric *__loc)
{
return *(nl_langinfo_l(THOUSEP, (locale_t)__loc));
}
const char* _Locale_grouping(struct _Locale_numeric *__loc)
{
return (_Locale_thousands_sep(__loc) != 0 ) ? (nl_langinfo_l(GROUPING, (locale_t)__loc)) : _empty_str;
}
const char *_Locale_true(struct _Locale_numeric *__loc)
{
return nl_langinfo_l(YESSTR, (locale_t)__loc);
}
const char *_Locale_false(struct _Locale_numeric *__loc)
{
return nl_langinfo_l(NOSTR, (locale_t)__loc);
}
#ifndef _STLP_NO_WCHAR_T
wchar_t _WLocale_decimal_point(struct _Locale_numeric *__loc)
{ return (wchar_t)_Locale_decimal_point(__loc); }
wchar_t _WLocale_thousands_sep(struct _Locale_numeric *__loc)
{ return (wchar_t)_Locale_thousands_sep(__loc); }
const wchar_t *_WLocale_true(struct _Locale_numeric *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_true(__loc), buf, bufSize); }
const wchar_t *_WLocale_false(struct _Locale_numeric *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_false(__loc), buf, bufSize); }
#endif
/* Monetary */
const char *_Locale_int_curr_symbol(struct _Locale_monetary *__loc)
{
return nl_langinfo_l(INT_CURR_SYMBOL, (locale_t)__loc);
}
const char *_Locale_currency_symbol(struct _Locale_monetary *__loc)
{
return nl_langinfo_l(CURRENCY_SYMBOL, (locale_t)__loc);
}
char _Locale_mon_decimal_point(struct _Locale_monetary * __loc)
{
return *(nl_langinfo_l(MON_DECIMAL_POINT,(locale_t)__loc));
}
char _Locale_mon_thousands_sep(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(MON_THOUSANDS_SEP, (locale_t)__loc));
}
#ifndef _STLP_NO_WCHAR_T
const wchar_t *_WLocale_int_curr_symbol(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_int_curr_symbol(__loc), buf, bufSize); }
const wchar_t *_WLocale_currency_symbol(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_currency_symbol(__loc), buf, bufSize); }
wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary * __loc)
{ return (wchar_t)_Locale_mon_decimal_point(__loc); }
wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary * __loc)
{ return (wchar_t)_Locale_mon_thousands_sep(__loc); }
const wchar_t *_WLocale_positive_sign(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_positive_sign(__loc), buf, bufSize); }
const wchar_t *_WLocale_negative_sign(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_negative_sign(__loc), buf, bufSize); }
#endif
const char *_Locale_mon_grouping(struct _Locale_monetary *__loc)
{
return (_Locale_mon_thousands_sep( __loc ) != 0 ) ? nl_langinfo_l(MON_GROUPING, (locale_t)__loc) : _empty_str;
}
const char *_Locale_positive_sign(struct _Locale_monetary *__loc)
{
return nl_langinfo_l(POSITIVE_SIGN, (locale_t)__loc);
}
const char *_Locale_negative_sign(struct _Locale_monetary *__loc)
{
return nl_langinfo_l(NEGATIVE_SIGN, (locale_t)__loc);
}
char _Locale_int_frac_digits(struct _Locale_monetary *__loc)
{
/* We are forced to manually handled the "C" locale for consistency with
* the default implementation in STLport. */
const char* lname = ((locale_t)__loc)->__names[LC_MONETARY];
if (lname[0] == 'C' && lname[1] == 0)
return 0;
return *(nl_langinfo_l(INT_FRAC_DIGITS, (locale_t)__loc));
}
char _Locale_frac_digits(struct _Locale_monetary *__loc)
{
/* We are forced to manually handled the "C" locale for consistency with
* the default implementation in STLport. */
const char* lname = ((locale_t)__loc)->__names[LC_MONETARY];
if (lname[0] == 'C' && lname[1] == 0)
return 0;
return *(nl_langinfo_l(FRAC_DIGITS, (locale_t)__loc));
}
/* 1 if currency_symbol precedes a positive value, 0 if succeeds */
int _Locale_p_cs_precedes(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(P_CS_PRECEDES, (locale_t)__loc));
}
/* 1 if a space separates currency_symbol from a positive value. */
int _Locale_p_sep_by_space(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(P_SEP_BY_SPACE, (locale_t)__loc));
}
/*
* 0 Parentheses surround the quantity and currency_symbol
* 1 The sign string precedes the quantity and currency_symbol
* 2 The sign string succeeds the quantity and currency_symbol.
* 3 The sign string immediately precedes the currency_symbol.
* 4 The sign string immediately succeeds the currency_symbol.
*/
int _Locale_p_sign_posn(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(P_SIGN_POSN, (locale_t)__loc));
}
/* 1 if currency_symbol precedes a negative value, 0 if succeeds */
int _Locale_n_cs_precedes(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(N_CS_PRECEDES, (locale_t)__loc));
}
/* 1 if a space separates currency_symbol from a negative value. */
int _Locale_n_sep_by_space(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(N_SEP_BY_SPACE, (locale_t)__loc));
}
/*
* 0 Parentheses surround the quantity and currency_symbol
* 1 The sign string precedes the quantity and currency_symbol
* 2 The sign string succeeds the quantity and currency_symbol.
* 3 The sign string immediately precedes the currency_symbol.
* 4 The sign string immediately succeeds the currency_symbol.
*/
int _Locale_n_sign_posn(struct _Locale_monetary *__loc)
{
return *(nl_langinfo_l(N_SIGN_POSN, (locale_t)__loc));
}
/* Time */
const char *_Locale_full_monthname(struct _Locale_time *__loc, int _m )
{
return nl_langinfo_l(MON_1 + _m, (locale_t)__loc);
}
const char *_Locale_abbrev_monthname(struct _Locale_time *__loc, int _m )
{
return nl_langinfo_l(ABMON_1 + _m, (locale_t)__loc);
}
const char *_Locale_full_dayofweek(struct _Locale_time *__loc, int _d )
{
return nl_langinfo_l(DAY_1 + _d, (locale_t)__loc);
}
const char *_Locale_abbrev_dayofweek(struct _Locale_time *__loc, int _d )
{
return nl_langinfo_l(ABDAY_1 + _d, (locale_t)__loc);
}
const char *_Locale_d_t_fmt(struct _Locale_time *__loc)
{
return nl_langinfo_l(D_T_FMT, (locale_t)__loc);
}
const char *_Locale_d_fmt(struct _Locale_time *__loc )
{
return nl_langinfo_l(D_FMT, (locale_t)__loc);
}
const char *_Locale_t_fmt(struct _Locale_time *__loc )
{
return nl_langinfo_l(T_FMT, (locale_t)__loc);
}
const char *_Locale_long_d_t_fmt(struct _Locale_time *__loc )
{
return nl_langinfo_l(ERA_D_T_FMT, (locale_t)__loc);
}
const char *_Locale_long_d_fmt(struct _Locale_time *__loc )
{
return nl_langinfo_l(ERA_D_FMT, (locale_t)__loc);
}
const char *_Locale_am_str(struct _Locale_time *__loc )
{
return nl_langinfo_l(AM_STR, (locale_t)__loc);
}
const char *_Locale_pm_str(struct _Locale_time* __loc )
{
return nl_langinfo_l(PM_STR, (locale_t)__loc);
}
#ifndef _STLP_NO_WCHAR_T
const wchar_t *_WLocale_full_monthname(struct _Locale_time *__loc, int _m, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_full_monthname(__loc, _m), buf, bufSize); }
const wchar_t *_WLocale_abbrev_monthname(struct _Locale_time *__loc, int _m, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_abbrev_monthname(__loc, _m), buf, bufSize); }
const wchar_t *_WLocale_full_dayofweek(struct _Locale_time *__loc, int _d, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_full_dayofweek(__loc, _d), buf, bufSize); }
const wchar_t *_WLocale_abbrev_dayofweek(struct _Locale_time *__loc, int _d, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_abbrev_dayofweek(__loc, _d), buf, bufSize); }
const wchar_t *_WLocale_am_str(struct _Locale_time *__loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_am_str(__loc), buf, bufSize); }
const wchar_t *_WLocale_pm_str(struct _Locale_time* __loc, wchar_t *buf, size_t bufSize)
{ return _ToWChar(_Locale_pm_str(__loc), buf, bufSize); }
#endif
/* Messages */
nl_catd_type _Locale_catopen(struct _Locale_messages *__loc, const char *__cat_name )
{
return catopen( __cat_name, NL_CAT_LOCALE );
}
void _Locale_catclose(struct _Locale_messages *__loc, nl_catd_type __cat )
{
catclose( __cat );
}
const char *_Locale_catgets(struct _Locale_messages *__loc, nl_catd_type __cat,
int __setid, int __msgid, const char *dfault)
{
return catgets( __cat, __setid, __msgid, dfault );
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,314 @@
/*
* Copyright (c) 2007 2008
* Francois Dumont
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#if defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
# define _STLP_WCSNCPY(D, DS, S, C) wcsncpy_s(D, DS, S, C)
#else
# define _STLP_WCSNCPY(D, DS, S, C) wcsncpy(D, S, C)
#endif
static const wchar_t* __wtrue_name = L"true";
static const wchar_t* __wfalse_name = L"false";
typedef struct _Locale_codecvt {
_Locale_lcid_t lc;
UINT cp;
unsigned char cleads[256 / CHAR_BIT];
unsigned char max_char_size;
DWORD mbtowc_flags;
DWORD wctomb_flags;
} _Locale_codecvt_t;
/* Ctype */
_Locale_mask_t _WLocale_ctype(_Locale_ctype_t* ltype, wint_t c,
_Locale_mask_t which_bits) {
wchar_t buf[2];
WORD out[2];
buf[0] = c; buf[1] = 0;
GetStringTypeW(CT_CTYPE1, buf, -1, out);
_STLP_MARK_PARAMETER_AS_UNUSED(ltype)
return (_Locale_mask_t)(MapCtypeMask(out[0]) & which_bits);
}
wint_t _WLocale_tolower(_Locale_ctype_t* ltype, wint_t c) {
wchar_t in_c = c;
wchar_t res;
LCMapStringW(ltype->lc.id, LCMAP_LOWERCASE, &in_c, 1, &res, 1);
return res;
}
wint_t _WLocale_toupper(_Locale_ctype_t* ltype, wint_t c) {
wchar_t in_c = c;
wchar_t res;
LCMapStringW(ltype->lc.id, LCMAP_UPPERCASE, &in_c, 1, &res, 1);
return res;
}
_Locale_codecvt_t* _Locale_codecvt_create(const char * name, _Locale_lcid_t* lc_hint, int *__err_code) {
char cp_name[MAX_CP_LEN + 1];
unsigned char *ptr;
CPINFO CPInfo;
int i;
_Locale_codecvt_t *lcodecvt = (_Locale_codecvt_t*)malloc(sizeof(_Locale_codecvt_t));
if (!lcodecvt) { *__err_code = _STLP_LOC_NO_MEMORY; return lcodecvt; }
memset(lcodecvt, 0, sizeof(_Locale_codecvt_t));
if (__GetLCIDFromName(name, &lcodecvt->lc.id, cp_name, lc_hint) == -1)
{ free(lcodecvt); *__err_code = _STLP_LOC_UNKNOWN_NAME; return NULL; }
lcodecvt->cp = atoi(cp_name);
if (!GetCPInfo(lcodecvt->cp, &CPInfo)) { free(lcodecvt); return NULL; }
if (lcodecvt->cp != CP_UTF7 && lcodecvt->cp != CP_UTF8) {
lcodecvt->mbtowc_flags = MB_PRECOMPOSED;
lcodecvt->wctomb_flags = WC_COMPOSITECHECK | WC_SEPCHARS;
}
lcodecvt->max_char_size = CPInfo.MaxCharSize;
if (CPInfo.MaxCharSize > 1) {
for (ptr = (unsigned char*)CPInfo.LeadByte; *ptr && *(ptr + 1); ptr += 2)
for (i = *ptr; i <= *(ptr + 1); ++i) lcodecvt->cleads[i / CHAR_BIT] |= (0x01 << i % CHAR_BIT);
}
return lcodecvt;
}
char const* _Locale_codecvt_name(const _Locale_codecvt_t* lcodecvt, char* buf) {
char cp_buf[MAX_CP_LEN + 1];
my_ltoa(lcodecvt->cp, cp_buf);
return __GetLocaleName(lcodecvt->lc.id, cp_buf, buf);
}
void _Locale_codecvt_destroy(_Locale_codecvt_t* lcodecvt) {
if (!lcodecvt) return;
free(lcodecvt);
}
int _WLocale_mb_cur_max (_Locale_codecvt_t * lcodecvt)
{ return lcodecvt->max_char_size; }
int _WLocale_mb_cur_min (_Locale_codecvt_t *lcodecvt) {
_STLP_MARK_PARAMETER_AS_UNUSED(lcodecvt)
return 1;
}
int _WLocale_is_stateless (_Locale_codecvt_t * lcodecvt)
{ return (lcodecvt->max_char_size == 1) ? 1 : 0; }
static int __isleadbyte(int i, unsigned char *ctable) {
unsigned char c = (unsigned char)i;
return (ctable[c / CHAR_BIT] & (0x01 << c % CHAR_BIT));
}
static int __mbtowc(_Locale_codecvt_t *l, wchar_t *dst, const char *from, unsigned int count) {
int result;
if (l->cp == CP_UTF7 || l->cp == CP_UTF8) {
result = MultiByteToWideChar(l->cp, l->mbtowc_flags, from, count, dst, 1);
if (result == 0) {
switch (GetLastError()) {
case ERROR_NO_UNICODE_TRANSLATION:
return -2;
default:
return -1;
}
}
}
else {
if (count == 1 && __isleadbyte(*from, l->cleads)) return (size_t)-2;
result = MultiByteToWideChar(l->cp, l->mbtowc_flags, from, count, dst, 1);
if (result == 0) return -1;
}
return result;
}
size_t _WLocale_mbtowc(_Locale_codecvt_t *lcodecvt, wchar_t *to,
const char *from, size_t n, mbstate_t *shift_state) {
int result;
_STLP_MARK_PARAMETER_AS_UNUSED(shift_state)
if (lcodecvt->max_char_size == 1) { /* Single byte encoding. */
result = MultiByteToWideChar(lcodecvt->cp, lcodecvt->mbtowc_flags, from, 1, to, 1);
if (result == 0) return (size_t)-1;
return result;
}
else { /* Multi byte encoding. */
int retval;
unsigned int count = 1;
while (n--) {
retval = __mbtowc(lcodecvt, to, from, count);
if (retval == -2)
{ if (++count > ((unsigned int)lcodecvt->max_char_size)) return (size_t)-1; }
else if (retval == -1)
{ return (size_t)-1; }
else
{ return count; }
}
return (size_t)-2;
}
}
size_t _WLocale_wctomb(_Locale_codecvt_t *lcodecvt, char *to, size_t n,
const wchar_t c, mbstate_t *shift_state) {
int size = WideCharToMultiByte(lcodecvt->cp, lcodecvt->wctomb_flags, &c, 1, NULL, 0, NULL, NULL);
if (!size) return (size_t)-1;
if ((size_t)size > n) return (size_t)-2;
if (n > INT_MAX)
/* Limiting the output buf size to INT_MAX seems like reasonable to transform a single wchar_t. */
n = INT_MAX;
WideCharToMultiByte(lcodecvt->cp, lcodecvt->wctomb_flags, &c, 1, to, (int)n, NULL, NULL);
_STLP_MARK_PARAMETER_AS_UNUSED(shift_state)
return (size_t)size;
}
size_t _WLocale_unshift(_Locale_codecvt_t *lcodecvt, mbstate_t *st,
char *buf, size_t n, char **next) {
/* _WLocale_wctomb do not even touch to st, there is nothing to unshift in this localization implementation. */
_STLP_MARK_PARAMETER_AS_UNUSED(lcodecvt)
_STLP_MARK_PARAMETER_AS_UNUSED(st)
_STLP_MARK_PARAMETER_AS_UNUSED(&n)
*next = buf;
return 0;
}
/* Collate */
/* This function takes care of the potential size_t DWORD different size. */
static int _WLocale_strcmp_aux(_Locale_collate_t* lcol,
const wchar_t* s1, size_t n1,
const wchar_t* s2, size_t n2) {
int result = CSTR_EQUAL;
while (n1 > 0 || n2 > 0) {
DWORD size1 = trim_size_t_to_DWORD(n1);
DWORD size2 = trim_size_t_to_DWORD(n2);
result = CompareStringW(lcol->lc.id, 0, s1, size1, s2, size2);
if (result != CSTR_EQUAL)
break;
n1 -= size1;
n2 -= size2;
}
return result;
}
int _WLocale_strcmp(_Locale_collate_t* lcol,
const wchar_t* s1, size_t n1,
const wchar_t* s2, size_t n2) {
int result;
result = _WLocale_strcmp_aux(lcol, s1, n1, s2, n2);
return (result == CSTR_EQUAL) ? 0 : (result == CSTR_LESS_THAN) ? -1 : 1;
}
size_t _WLocale_strxfrm(_Locale_collate_t* lcol,
wchar_t* dst, size_t dst_size,
const wchar_t* src, size_t src_size) {
int result, i;
/* see _Locale_strxfrm: */
if (src_size > INT_MAX) {
if (dst != 0) {
_STLP_WCSNCPY(dst, dst_size, src, src_size);
}
return src_size;
}
if (dst_size > INT_MAX) {
dst_size = INT_MAX;
}
result = LCMapStringW(lcol->lc.id, LCMAP_SORTKEY, src, (int)src_size, dst, (int)dst_size);
if (result != 0 && dst != 0) {
for (i = result - 1; i >= 0; --i) {
dst[i] = ((unsigned char*)dst)[i];
}
}
return result != 0 ? result - 1 : 0;
}
/* Numeric */
wchar_t _WLocale_decimal_point(_Locale_numeric_t* lnum) {
wchar_t buf[4];
GetLocaleInfoW(lnum->lc.id, LOCALE_SDECIMAL, buf, 4);
return buf[0];
}
wchar_t _WLocale_thousands_sep(_Locale_numeric_t* lnum) {
wchar_t buf[4];
GetLocaleInfoW(lnum->lc.id, LOCALE_STHOUSAND, buf, 4);
return buf[0];
}
const wchar_t * _WLocale_true(_Locale_numeric_t* lnum, wchar_t* buf, size_t bufSize) {
_STLP_MARK_PARAMETER_AS_UNUSED(lnum)
_STLP_MARK_PARAMETER_AS_UNUSED(buf)
_STLP_MARK_PARAMETER_AS_UNUSED(&bufSize)
return __wtrue_name;
}
const wchar_t * _WLocale_false(_Locale_numeric_t* lnum, wchar_t* buf, size_t bufSize) {
_STLP_MARK_PARAMETER_AS_UNUSED(lnum)
_STLP_MARK_PARAMETER_AS_UNUSED(buf)
_STLP_MARK_PARAMETER_AS_UNUSED(&bufSize)
return __wfalse_name;
}
/* Monetary */
const wchar_t* _WLocale_int_curr_symbol(_Locale_monetary_t * lmon, wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(lmon->lc.id, LOCALE_SINTLSYMBOL, buf, (int)bufSize); return buf; }
const wchar_t* _WLocale_currency_symbol(_Locale_monetary_t * lmon, wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(lmon->lc.id, LOCALE_SCURRENCY, buf, (int)bufSize); return buf; }
wchar_t _WLocale_mon_decimal_point(_Locale_monetary_t * lmon)
{ return lmon->decimal_point[0]; }
wchar_t _WLocale_mon_thousands_sep(_Locale_monetary_t * lmon)
{ return lmon->thousands_sep[0]; }
const wchar_t* _WLocale_positive_sign(_Locale_monetary_t * lmon, wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(lmon->lc.id, LOCALE_SPOSITIVESIGN, buf, (int)bufSize); return buf; }
const wchar_t* _WLocale_negative_sign(_Locale_monetary_t * lmon, wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(lmon->lc.id, LOCALE_SNEGATIVESIGN, buf, (int)bufSize); return buf; }
/* Time */
const wchar_t * _WLocale_full_monthname(_Locale_time_t * ltime, int month,
wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(ltime->lc.id, LOCALE_SMONTHNAME1 + month, buf, (int)bufSize); return buf; }
const wchar_t * _WLocale_abbrev_monthname(_Locale_time_t * ltime, int month,
wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(ltime->lc.id, LOCALE_SABBREVMONTHNAME1 + month, buf, (int)bufSize); return buf; }
const wchar_t * _WLocale_full_dayofweek(_Locale_time_t * ltime, int day,
wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(ltime->lc.id, LOCALE_SDAYNAME1 + day, buf, (int)bufSize); return buf; }
const wchar_t * _WLocale_abbrev_dayofweek(_Locale_time_t * ltime, int day,
wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(ltime->lc.id, LOCALE_SABBREVDAYNAME1 + day, buf, (int)bufSize); return buf; }
const wchar_t* _WLocale_am_str(_Locale_time_t* ltime,
wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(ltime->lc.id, LOCALE_S1159, buf, (int)bufSize); return buf; }
const wchar_t* _WLocale_pm_str(_Locale_time_t* ltime,
wchar_t* buf, size_t bufSize)
{ GetLocaleInfoW(ltime->lc.id, LOCALE_S2359, buf, (int)bufSize); return buf; }

143
extern/STLport/5.2.1/src/codecvt.cpp vendored Normal file
View File

@@ -0,0 +1,143 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
#include <algorithm>
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// codecvt<char, char, mbstate_t>
codecvt<char, char, mbstate_t>::~codecvt() {}
int codecvt<char, char, mbstate_t>::do_length(state_type&,
const char* from,
const char* end,
size_t mx) const
{ return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }
int codecvt<char, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
{ return 1; }
bool
codecvt<char, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
{ return true; }
int
codecvt<char, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
{ return 1; }
codecvt_base::result
codecvt<char, char, mbstate_t>::do_unshift(state_type& /* __state */,
char* __to,
char* /* __to_limit */,
char*& __to_next) const
{ __to_next = __to; return noconv; }
codecvt_base::result
codecvt<char, char, mbstate_t>::do_in (state_type& /* __state */ ,
const char* __from,
const char* /* __from_end */,
const char*& __from_next,
char* __to,
char* /* __to_end */,
char*& __to_next) const
{ __from_next = __from; __to_next = __to; return noconv; }
codecvt_base::result
codecvt<char, char, mbstate_t>::do_out(state_type& /* __state */,
const char* __from,
const char* /* __from_end */,
const char*& __from_next,
char* __to,
char* /* __to_limit */,
char*& __to_next) const
{ __from_next = __from; __to_next = __to; return noconv; }
#if !defined (_STLP_NO_WCHAR_T)
//----------------------------------------------------------------------
// codecvt<wchar_t, char, mbstate_t>
codecvt<wchar_t, char, mbstate_t>::~codecvt() {}
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_out(state_type& /* state */,
const intern_type* from,
const intern_type* from_end,
const intern_type*& from_next,
extern_type* to,
extern_type* to_limit,
extern_type*& to_next) const {
ptrdiff_t len = (min) (from_end - from, to_limit - to);
copy(from, from + len, to);
from_next = from + len;
to_next = to + len;
return ok;
}
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_in (state_type& /* state */,
const extern_type* from,
const extern_type* from_end,
const extern_type*& from_next,
intern_type* to,
intern_type* to_limit,
intern_type*& to_next) const {
ptrdiff_t len = (min) (from_end - from, to_limit - to);
copy(__REINTERPRET_CAST(const unsigned char*, from),
__REINTERPRET_CAST(const unsigned char*, from) + len, to);
from_next = from + len;
to_next = to + len;
return ok;
}
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& /* state */,
extern_type* to,
extern_type* ,
extern_type*& to_next) const {
to_next = to;
return noconv;
}
int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
{ return 1; }
bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
{ return true; }
int codecvt<wchar_t, char, mbstate_t>::do_length(state_type&,
const extern_type* from,
const extern_type* end,
size_t mx) const
{ return (int)(min) ((size_t) (end - from), mx); }
int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
{ return 1; }
#endif /* wchar_t */
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

69
extern/STLport/5.2.1/src/collate.cpp vendored Normal file
View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
_STLP_BEGIN_NAMESPACE
// collate<char>
collate<char>::~collate() {}
int collate<char>::do_compare(const char* low1, const char* high1,
const char* low2, const char* high2) const
{ return _STLP_PRIV __lexicographical_compare_3way(low1, high1, low2, high2); }
string collate<char>::do_transform(const char* low, const char* high) const
{ return string(low, high); }
long collate<char>::do_hash(const char* low, const char* high) const {
unsigned long result = 0;
for ( ; low < high; ++low)
result = 5 * result + *low;
return result;
}
#if !defined (_STLP_NO_WCHAR_T)
// collate<wchar_t>
collate<wchar_t>::~collate() {}
int
collate<wchar_t>::do_compare(const wchar_t* low1, const wchar_t* high1,
const wchar_t* low2, const wchar_t* high2) const
{ return _STLP_PRIV __lexicographical_compare_3way(low1, high1, low2, high2); }
wstring collate<wchar_t>::do_transform(const wchar_t* low, const wchar_t* high) const
{ return wstring(low, high); }
long collate<wchar_t>::do_hash(const wchar_t* low, const wchar_t* high) const {
unsigned long result = 0;
for ( ; low < high; ++low)
result = 5 * result + *low;
return result;
}
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

347
extern/STLport/5.2.1/src/complex.cpp vendored Normal file
View File

@@ -0,0 +1,347 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <numeric>
#include <cmath>
#include <complex>
#if defined (_STLP_MSVC_LIB) && (_STLP_MSVC_LIB >= 1400)
// hypot is deprecated.
# if defined (_STLP_MSVC)
# pragma warning (disable : 4996)
# elif defined (__ICL)
# pragma warning (disable : 1478)
# endif
#endif
_STLP_BEGIN_NAMESPACE
// Complex division and square roots.
// Absolute value
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC float _STLP_CALL abs(const complex<float>& __z)
{ return ::hypot(__z._M_re, __z._M_im); }
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC double _STLP_CALL abs(const complex<double>& __z)
{ return ::hypot(__z._M_re, __z._M_im); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC long double _STLP_CALL abs(const complex<long double>& __z)
{ return ::hypot(__z._M_re, __z._M_im); }
#endif
// Phase
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC float _STLP_CALL arg(const complex<float>& __z)
{ return ::atan2(__z._M_im, __z._M_re); }
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC double _STLP_CALL arg(const complex<double>& __z)
{ return ::atan2(__z._M_im, __z._M_re); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC long double _STLP_CALL arg(const complex<long double>& __z)
{ return ::atan2(__z._M_im, __z._M_re); }
#endif
// Construct a complex number from polar representation
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC complex<float> _STLP_CALL polar(const float& __rho, const float& __phi)
{ return complex<float>(__rho * ::cos(__phi), __rho * ::sin(__phi)); }
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC complex<double> _STLP_CALL polar(const double& __rho, const double& __phi)
{ return complex<double>(__rho * ::cos(__phi), __rho * ::sin(__phi)); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC complex<long double> _STLP_CALL polar(const long double& __rho, const long double& __phi)
{ return complex<long double>(__rho * ::cos(__phi), __rho * ::sin(__phi)); }
#endif
// Division
template <class _Tp>
static void _divT(const _Tp& __z1_r, const _Tp& __z1_i,
const _Tp& __z2_r, const _Tp& __z2_i,
_Tp& __res_r, _Tp& __res_i) {
_Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
_Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
if (__ar <= __ai) {
_Tp __ratio = __z2_r / __z2_i;
_Tp __denom = __z2_i * (1 + __ratio * __ratio);
__res_r = (__z1_r * __ratio + __z1_i) / __denom;
__res_i = (__z1_i * __ratio - __z1_r) / __denom;
}
else {
_Tp __ratio = __z2_i / __z2_r;
_Tp __denom = __z2_r * (1 + __ratio * __ratio);
__res_r = (__z1_r + __z1_i * __ratio) / __denom;
__res_i = (__z1_i - __z1_r * __ratio) / __denom;
}
}
template <class _Tp>
static void _divT(const _Tp& __z1_r,
const _Tp& __z2_r, const _Tp& __z2_i,
_Tp& __res_r, _Tp& __res_i) {
_Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
_Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
if (__ar <= __ai) {
_Tp __ratio = __z2_r / __z2_i;
_Tp __denom = __z2_i * (1 + __ratio * __ratio);
__res_r = (__z1_r * __ratio) / __denom;
__res_i = - __z1_r / __denom;
}
else {
_Tp __ratio = __z2_i / __z2_r;
_Tp __denom = __z2_r * (1 + __ratio * __ratio);
__res_r = __z1_r / __denom;
__res_i = - (__z1_r * __ratio) / __denom;
}
}
void _STLP_CALL
complex<float>::_div(const float& __z1_r, const float& __z1_i,
const float& __z2_r, const float& __z2_i,
float& __res_r, float& __res_i)
{ _divT(__z1_r, __z1_i, __z2_r, __z2_i, __res_r, __res_i); }
void _STLP_CALL
complex<float>::_div(const float& __z1_r,
const float& __z2_r, const float& __z2_i,
float& __res_r, float& __res_i)
{ _divT(__z1_r, __z2_r, __z2_i, __res_r, __res_i); }
void _STLP_CALL
complex<double>::_div(const double& __z1_r, const double& __z1_i,
const double& __z2_r, const double& __z2_i,
double& __res_r, double& __res_i)
{ _divT(__z1_r, __z1_i, __z2_r, __z2_i, __res_r, __res_i); }
void _STLP_CALL
complex<double>::_div(const double& __z1_r,
const double& __z2_r, const double& __z2_i,
double& __res_r, double& __res_i)
{ _divT(__z1_r, __z2_r, __z2_i, __res_r, __res_i); }
#if !defined (_STLP_NO_LONG_DOUBLE)
void _STLP_CALL
complex<long double>::_div(const long double& __z1_r, const long double& __z1_i,
const long double& __z2_r, const long double& __z2_i,
long double& __res_r, long double& __res_i)
{ _divT(__z1_r, __z1_i, __z2_r, __z2_i, __res_r, __res_i); }
void _STLP_CALL
complex<long double>::_div(const long double& __z1_r,
const long double& __z2_r, const long double& __z2_i,
long double& __res_r, long double& __res_i)
{ _divT(__z1_r, __z2_r, __z2_i, __res_r, __res_i); }
#endif
//----------------------------------------------------------------------
// Square root
template <class _Tp>
static complex<_Tp> sqrtT(const complex<_Tp>& z) {
_Tp re = z._M_re;
_Tp im = z._M_im;
_Tp mag = ::hypot(re, im);
complex<_Tp> result;
if (mag == 0.f) {
result._M_re = result._M_im = 0.f;
} else if (re > 0.f) {
result._M_re = ::sqrt(0.5f * (mag + re));
result._M_im = im/result._M_re/2.f;
} else {
result._M_im = ::sqrt(0.5f * (mag - re));
if (im < 0.f)
result._M_im = - result._M_im;
result._M_re = im/result._M_im/2.f;
}
return result;
}
complex<float> _STLP_CALL
sqrt(const complex<float>& z) { return sqrtT(z); }
complex<double> _STLP_CALL
sqrt(const complex<double>& z) { return sqrtT(z); }
#if !defined (_STLP_NO_LONG_DOUBLE)
complex<long double> _STLP_CALL
sqrt(const complex<long double>& z) { return sqrtT(z); }
#endif
// exp, log, pow for complex<float>, complex<double>, and complex<long double>
//----------------------------------------------------------------------
// exp
template <class _Tp>
static complex<_Tp> expT(const complex<_Tp>& z) {
_Tp expx = ::exp(z._M_re);
return complex<_Tp>(expx * ::cos(z._M_im),
expx * ::sin(z._M_im));
}
_STLP_DECLSPEC complex<float> _STLP_CALL exp(const complex<float>& z)
{ return expT(z); }
_STLP_DECLSPEC complex<double> _STLP_CALL exp(const complex<double>& z)
{ return expT(z); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL exp(const complex<long double>& z)
{ return expT(z); }
#endif
//----------------------------------------------------------------------
// log10
template <class _Tp>
static complex<_Tp> log10T(const complex<_Tp>& z, const _Tp& ln10_inv) {
complex<_Tp> r;
r._M_im = ::atan2(z._M_im, z._M_re) * ln10_inv;
r._M_re = ::log10(::hypot(z._M_re, z._M_im));
return r;
}
static const float LN10_INVF = 1.f / ::log(10.f);
_STLP_DECLSPEC complex<float> _STLP_CALL log10(const complex<float>& z)
{ return log10T(z, LN10_INVF); }
static const double LN10_INV = 1. / ::log10(10.);
_STLP_DECLSPEC complex<double> _STLP_CALL log10(const complex<double>& z)
{ return log10T(z, LN10_INV); }
#if !defined (_STLP_NO_LONG_DOUBLE)
static const long double LN10_INVL = 1.l / ::log(10.l);
_STLP_DECLSPEC complex<long double> _STLP_CALL log10(const complex<long double>& z)
{ return log10T(z, LN10_INVL); }
#endif
//----------------------------------------------------------------------
// log
template <class _Tp>
static complex<_Tp> logT(const complex<_Tp>& z) {
complex<_Tp> r;
r._M_im = ::atan2(z._M_im, z._M_re);
r._M_re = ::log(::hypot(z._M_re, z._M_im));
return r;
}
_STLP_DECLSPEC complex<float> _STLP_CALL log(const complex<float>& z)
{ return logT(z); }
_STLP_DECLSPEC complex<double> _STLP_CALL log(const complex<double>& z)
{ return logT(z); }
#ifndef _STLP_NO_LONG_DOUBLE
_STLP_DECLSPEC complex<long double> _STLP_CALL log(const complex<long double>& z)
{ return logT(z); }
# endif
//----------------------------------------------------------------------
// pow
template <class _Tp>
static complex<_Tp> powT(const _Tp& a, const complex<_Tp>& b) {
_Tp logr = ::log(a);
_Tp x = ::exp(logr * b._M_re);
_Tp y = logr * b._M_im;
return complex<_Tp>(x * ::cos(y), x * ::sin(y));
}
template <class _Tp>
static complex<_Tp> powT(const complex<_Tp>& z_in, int n) {
complex<_Tp> z = z_in;
z = _STLP_PRIV __power(z, (n < 0 ? -n : n), multiplies< complex<_Tp> >());
if (n < 0)
return _Tp(1.0) / z;
else
return z;
}
template <class _Tp>
static complex<_Tp> powT(const complex<_Tp>& a, const _Tp& b) {
_Tp logr = ::log(::hypot(a._M_re,a._M_im));
_Tp logi = ::atan2(a._M_im, a._M_re);
_Tp x = ::exp(logr * b);
_Tp y = logi * b;
return complex<_Tp>(x * ::cos(y), x * ::sin(y));
}
template <class _Tp>
static complex<_Tp> powT(const complex<_Tp>& a, const complex<_Tp>& b) {
_Tp logr = ::log(::hypot(a._M_re,a._M_im));
_Tp logi = ::atan2(a._M_im, a._M_re);
_Tp x = ::exp(logr * b._M_re - logi * b._M_im);
_Tp y = logr * b._M_im + logi * b._M_re;
return complex<_Tp>(x * ::cos(y), x * ::sin(y));
}
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const float& a, const complex<float>& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& z_in, int n)
{ return powT(z_in, n); }
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& a, const float& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& a, const complex<float>& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const double& a, const complex<double>& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>& z_in, int n)
{ return powT(z_in, n); }
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>& a, const double& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>& a, const complex<double>& b)
{ return powT(a, b); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const long double& a,
const complex<long double>& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& z_in, int n)
{ return powT(z_in, n); }
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& a,
const long double& b)
{ return powT(a, b); }
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& a,
const complex<long double>& b)
{ return powT(a, b); }
#endif
_STLP_END_NAMESPACE

157
extern/STLport/5.2.1/src/complex_io.cpp vendored Normal file
View File

@@ -0,0 +1,157 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <complex>
#include <istream>
_STLP_BEGIN_NAMESPACE
// Specializations for narrow characters; lets us avoid the nuisance of
// widening.
_STLP_OPERATOR_SPEC
basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
{ return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }
_STLP_OPERATOR_SPEC
basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
{ return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
#ifndef _STLP_NO_LONG_DOUBLE
_STLP_OPERATOR_SPEC
basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
{ return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
#endif
// Specialization for narrow characters; lets us avoid widen.
_STLP_OPERATOR_SPEC
basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
float __re = 0;
float __im = 0;
char __c;
__is >> __c;
if (__c == '(') {
__is >> __re >> __c;
if (__c == ',')
__is >> __im >> __c;
if (__c != ')')
__is.setstate(ios_base::failbit);
}
else {
__is.putback(__c);
__is >> __re;
}
if (__is)
__z = complex<float>(__re, __im);
return __is;
}
_STLP_OPERATOR_SPEC
basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
double __re = 0;
double __im = 0;
char __c;
__is >> __c;
if (__c == '(') {
__is >> __re >> __c;
if (__c == ',')
__is >> __im >> __c;
if (__c != ')')
__is.setstate(ios_base::failbit);
}
else {
__is.putback(__c);
__is >> __re;
}
if (__is)
__z = complex<double>(__re, __im);
return __is;
}
#ifndef _STLP_NO_LONG_DOUBLE
_STLP_OPERATOR_SPEC
basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
long double __re = 0;
long double __im = 0;
char __c;
__is >> __c;
if (__c == '(') {
__is >> __re >> __c;
if (__c == ',')
__is >> __im >> __c;
if (__c != ')')
__is.setstate(ios_base::failbit);
}
else {
__is.putback(__c);
__is >> __re;
}
if (__is)
__z = complex<long double>(__re, __im);
return __is;
}
#endif
// Force instantiation of complex I/O functions
#if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
#ifndef _STLP_NO_LONG_DOUBLE
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
#endif
_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
#endif /* _STLP_NO_WCHAR_T */
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
// Trigonometric and hyperbolic functions for complex<float>,
// complex<double>, and complex<long double>
#include <complex>
#include <cfloat>
#include <cmath>
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// helpers
#if defined (__sgi)
static const union { unsigned int i; float f; } float_ulimit = { 0x42b2d4fc };
static const float float_limit = float_ulimit.f;
static union {
struct { unsigned int h; unsigned int l; } w;
double d;
} double_ulimit = { 0x408633ce, 0x8fb9f87d };
static const double double_limit = double_ulimit.d;
static union {
struct { unsigned int h[2]; unsigned int l[2]; } w;
long double ld;
} ldouble_ulimit = {0x408633ce, 0x8fb9f87e, 0xbd23b659, 0x4e9bd8b1};
# if !defined (_STLP_NO_LONG_DOUBLE)
static const long double ldouble_limit = ldouble_ulimit.ld;
# endif
#else
# if defined (M_LN2) && defined (FLT_MAX_EXP)
static const float float_limit = float(M_LN2 * FLT_MAX_EXP);
static const double double_limit = M_LN2 * DBL_MAX_EXP;
# else
static const float float_limit = ::log(FLT_MAX);
static const double double_limit = ::log(DBL_MAX);
# endif
# if !defined (_STLP_NO_LONG_DOUBLE)
# if defined (M_LN2l)
static const long double ldouble_limit = M_LN2l * LDBL_MAX_EXP;
# else
static const long double ldouble_limit = ::log(LDBL_MAX);
# endif
# endif
#endif
//----------------------------------------------------------------------
// sin
template <class _Tp>
static complex<_Tp> sinT(const complex<_Tp>& z) {
return complex<_Tp>(::sin(z._M_re) * ::cosh(z._M_im),
::cos(z._M_re) * ::sinh(z._M_im));
}
_STLP_DECLSPEC complex<float> _STLP_CALL sin(const complex<float>& z)
{ return sinT(z); }
_STLP_DECLSPEC complex<double> _STLP_CALL sin(const complex<double>& z)
{ return sinT(z); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL sin(const complex<long double>& z)
{ return sinT(z); }
#endif
//----------------------------------------------------------------------
// cos
template <class _Tp>
static complex<_Tp> cosT(const complex<_Tp>& z) {
return complex<_Tp>(::cos(z._M_re) * ::cosh(z._M_im),
-::sin(z._M_re) * ::sinh(z._M_im));
}
_STLP_DECLSPEC complex<float> _STLP_CALL cos(const complex<float>& z)
{ return cosT(z); }
_STLP_DECLSPEC complex<double> _STLP_CALL cos(const complex<double>& z)
{ return cosT(z); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL cos(const complex<long double>& z)
{ return cosT(z); }
#endif
//----------------------------------------------------------------------
// tan
template <class _Tp>
static complex<_Tp> tanT(const complex<_Tp>& z, const _Tp& Tp_limit) {
_Tp re2 = 2.f * z._M_re;
_Tp im2 = 2.f * z._M_im;
if (::abs(im2) > Tp_limit)
return complex<_Tp>(0.f, (im2 > 0 ? 1.f : -1.f));
else {
_Tp den = ::cos(re2) + ::cosh(im2);
return complex<_Tp>(::sin(re2) / den, ::sinh(im2) / den);
}
}
_STLP_DECLSPEC complex<float> _STLP_CALL tan(const complex<float>& z)
{ return tanT(z, float_limit); }
_STLP_DECLSPEC complex<double> _STLP_CALL tan(const complex<double>& z)
{ return tanT(z, double_limit); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL tan(const complex<long double>& z)
{ return tanT(z, ldouble_limit); }
#endif
//----------------------------------------------------------------------
// sinh
template <class _Tp>
static complex<_Tp> sinhT(const complex<_Tp>& z) {
return complex<_Tp>(::sinh(z._M_re) * ::cos(z._M_im),
::cosh(z._M_re) * ::sin(z._M_im));
}
_STLP_DECLSPEC complex<float> _STLP_CALL sinh(const complex<float>& z)
{ return sinhT(z); }
_STLP_DECLSPEC complex<double> _STLP_CALL sinh(const complex<double>& z)
{ return sinhT(z); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL sinh(const complex<long double>& z)
{ return sinhT(z); }
#endif
//----------------------------------------------------------------------
// cosh
template <class _Tp>
static complex<_Tp> coshT(const complex<_Tp>& z) {
return complex<_Tp>(::cosh(z._M_re) * ::cos(z._M_im),
::sinh(z._M_re) * ::sin(z._M_im));
}
_STLP_DECLSPEC complex<float> _STLP_CALL cosh(const complex<float>& z)
{ return coshT(z); }
_STLP_DECLSPEC complex<double> _STLP_CALL cosh(const complex<double>& z)
{ return coshT(z); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL cosh(const complex<long double>& z)
{ return coshT(z); }
#endif
//----------------------------------------------------------------------
// tanh
template <class _Tp>
static complex<_Tp> tanhT(const complex<_Tp>& z, const _Tp& Tp_limit) {
_Tp re2 = 2.f * z._M_re;
_Tp im2 = 2.f * z._M_im;
if (::abs(re2) > Tp_limit)
return complex<_Tp>((re2 > 0 ? 1.f : -1.f), 0.f);
else {
_Tp den = ::cosh(re2) + ::cos(im2);
return complex<_Tp>(::sinh(re2) / den, ::sin(im2) / den);
}
}
_STLP_DECLSPEC complex<float> _STLP_CALL tanh(const complex<float>& z)
{ return tanhT(z, float_limit); }
_STLP_DECLSPEC complex<double> _STLP_CALL tanh(const complex<double>& z)
{ return tanhT(z, double_limit); }
#if !defined (_STLP_NO_LONG_DOUBLE)
_STLP_DECLSPEC complex<long double> _STLP_CALL tanh(const complex<long double>& z)
{ return tanhT(z, ldouble_limit); }
#endif
_STLP_END_NAMESPACE

486
extern/STLport/5.2.1/src/ctype.cpp vendored Normal file
View File

@@ -0,0 +1,486 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <algorithm>
#include <locale>
#include <functional>
#include "c_locale.h"
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// ctype<char>
// The classic table: static data members.
#if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION)
//*TY 02/25/2000 - added workaround for MPW compilers; they confuse on in-class static const
const size_t ctype<char>::table_size;
#endif
// This macro is specifically for platforms where isprint() relies
// on separate flag
const ctype_base::mask*
ctype<char>::classic_table() _STLP_NOTHROW {
/* Ctype table for the ASCII character set. */
static const ctype_base::mask _S_classic_table[table_size] = {
cntrl /* null */,
cntrl /* ^A */,
cntrl /* ^B */,
cntrl /* ^C */,
cntrl /* ^D */,
cntrl /* ^E */,
cntrl /* ^F */,
cntrl /* ^G */,
cntrl /* ^H */,
ctype_base::mask(space | cntrl) /* tab */,
ctype_base::mask(space | cntrl) /* LF */,
ctype_base::mask(space | cntrl) /* ^K */,
ctype_base::mask(space | cntrl) /* FF */,
ctype_base::mask(space | cntrl) /* ^M */,
cntrl /* ^N */,
cntrl /* ^O */,
cntrl /* ^P */,
cntrl /* ^Q */,
cntrl /* ^R */,
cntrl /* ^S */,
cntrl /* ^T */,
cntrl /* ^U */,
cntrl /* ^V */,
cntrl /* ^W */,
cntrl /* ^X */,
cntrl /* ^Y */,
cntrl /* ^Z */,
cntrl /* esc */,
cntrl /* ^\ */,
cntrl /* ^] */,
cntrl /* ^^ */,
cntrl /* ^_ */,
ctype_base::mask(space | print) /* */,
ctype_base::mask(punct | print) /* ! */,
ctype_base::mask(punct | print) /* " */,
ctype_base::mask(punct | print) /* # */,
ctype_base::mask(punct | print) /* $ */,
ctype_base::mask(punct | print) /* % */,
ctype_base::mask(punct | print) /* & */,
ctype_base::mask(punct | print) /* ' */,
ctype_base::mask(punct | print) /* ( */,
ctype_base::mask(punct | print) /* ) */,
ctype_base::mask(punct | print) /* * */,
ctype_base::mask(punct | print) /* + */,
ctype_base::mask(punct | print) /* , */,
ctype_base::mask(punct | print) /* - */,
ctype_base::mask(punct | print) /* . */,
ctype_base::mask(punct | print) /* / */,
ctype_base::mask(digit | print | xdigit) /* 0 */,
ctype_base::mask(digit | print | xdigit) /* 1 */,
ctype_base::mask(digit | print | xdigit) /* 2 */,
ctype_base::mask(digit | print | xdigit) /* 3 */,
ctype_base::mask(digit | print | xdigit) /* 4 */,
ctype_base::mask(digit | print | xdigit) /* 5 */,
ctype_base::mask(digit | print | xdigit) /* 6 */,
ctype_base::mask(digit | print | xdigit) /* 7 */,
ctype_base::mask(digit | print | xdigit) /* 8 */,
ctype_base::mask(digit | print | xdigit) /* 9 */,
ctype_base::mask(punct | print) /* : */,
ctype_base::mask(punct | print) /* ; */,
ctype_base::mask(punct | print) /* < */,
ctype_base::mask(punct | print) /* = */,
ctype_base::mask(punct | print) /* > */,
ctype_base::mask(punct | print) /* ? */,
ctype_base::mask(punct | print) /* ! */,
ctype_base::mask(alpha | print | upper | xdigit) /* A */,
ctype_base::mask(alpha | print | upper | xdigit) /* B */,
ctype_base::mask(alpha | print | upper | xdigit) /* C */,
ctype_base::mask(alpha | print | upper | xdigit) /* D */,
ctype_base::mask(alpha | print | upper | xdigit) /* E */,
ctype_base::mask(alpha | print | upper | xdigit) /* F */,
ctype_base::mask(alpha | print | upper) /* G */,
ctype_base::mask(alpha | print | upper) /* H */,
ctype_base::mask(alpha | print | upper) /* I */,
ctype_base::mask(alpha | print | upper) /* J */,
ctype_base::mask(alpha | print | upper) /* K */,
ctype_base::mask(alpha | print | upper) /* L */,
ctype_base::mask(alpha | print | upper) /* M */,
ctype_base::mask(alpha | print | upper) /* N */,
ctype_base::mask(alpha | print | upper) /* O */,
ctype_base::mask(alpha | print | upper) /* P */,
ctype_base::mask(alpha | print | upper) /* Q */,
ctype_base::mask(alpha | print | upper) /* R */,
ctype_base::mask(alpha | print | upper) /* S */,
ctype_base::mask(alpha | print | upper) /* T */,
ctype_base::mask(alpha | print | upper) /* U */,
ctype_base::mask(alpha | print | upper) /* V */,
ctype_base::mask(alpha | print | upper) /* W */,
ctype_base::mask(alpha | print | upper) /* X */,
ctype_base::mask(alpha | print | upper) /* Y */,
ctype_base::mask(alpha | print | upper) /* Z */,
ctype_base::mask(punct | print) /* [ */,
ctype_base::mask(punct | print) /* \ */,
ctype_base::mask(punct | print) /* ] */,
ctype_base::mask(punct | print) /* ^ */,
ctype_base::mask(punct | print) /* _ */,
ctype_base::mask(punct | print) /* ` */,
ctype_base::mask(alpha | print | lower | xdigit) /* a */,
ctype_base::mask(alpha | print | lower | xdigit) /* b */,
ctype_base::mask(alpha | print | lower | xdigit) /* c */,
ctype_base::mask(alpha | print | lower | xdigit) /* d */,
ctype_base::mask(alpha | print | lower | xdigit) /* e */,
ctype_base::mask(alpha | print | lower | xdigit) /* f */,
ctype_base::mask(alpha | print | lower) /* g */,
ctype_base::mask(alpha | print | lower) /* h */,
ctype_base::mask(alpha | print | lower) /* i */,
ctype_base::mask(alpha | print | lower) /* j */,
ctype_base::mask(alpha | print | lower) /* k */,
ctype_base::mask(alpha | print | lower) /* l */,
ctype_base::mask(alpha | print | lower) /* m */,
ctype_base::mask(alpha | print | lower) /* n */,
ctype_base::mask(alpha | print | lower) /* o */,
ctype_base::mask(alpha | print | lower) /* p */,
ctype_base::mask(alpha | print | lower) /* q */,
ctype_base::mask(alpha | print | lower) /* r */,
ctype_base::mask(alpha | print | lower) /* s */,
ctype_base::mask(alpha | print | lower) /* t */,
ctype_base::mask(alpha | print | lower) /* u */,
ctype_base::mask(alpha | print | lower) /* v */,
ctype_base::mask(alpha | print | lower) /* w */,
ctype_base::mask(alpha | print | lower) /* x */,
ctype_base::mask(alpha | print | lower) /* y */,
ctype_base::mask(alpha | print | lower) /* z */,
ctype_base::mask(punct | print) /* { */,
ctype_base::mask(punct | print) /* | */,
ctype_base::mask(punct | print) /* } */,
ctype_base::mask(punct | print) /* ~ */,
cntrl /* del (0x7f)*/,
/* ASCII is a 7-bit code, so everything else is non-ASCII */
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0),
ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0), ctype_base::mask(0)
};
return _S_classic_table;
}
// For every c in the range 0 <= c < 256, _S_upper[c] is the
// uppercased version of c and _S_lower[c] is the lowercased
// version. As before, these two tables assume the ASCII character
// set.
const unsigned char _S_upper[ctype<char>::table_size] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
const unsigned char _S_lower[ctype<char>::table_size] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
//An helper struct to check wchar_t index without generating warnings
//under some compilers (gcc) because of a limited range of value
//(when wchar_t is unsigned)
template <bool _IsSigned>
struct _WCharIndexT;
#if !(defined (__BORLANDC__) && !defined(__linux__)) && \
!(defined (__GNUC__) && (defined (__MINGW32__) || defined (__CYGWIN__))) && \
!defined (__ICL)
_STLP_TEMPLATE_NULL
struct _WCharIndexT<true> {
static bool in_range(wchar_t c, size_t upperBound) {
return c >= 0 && size_t(c) < upperBound;
}
};
#endif
_STLP_TEMPLATE_NULL
struct _WCharIndexT<false> {
static bool in_range(wchar_t c, size_t upperBound) {
return size_t(c) < upperBound;
}
};
typedef _WCharIndexT<wchar_t(-1) < 0> _WCharIndex;
// Some helper functions used in ctype<>::scan_is and scan_is_not.
struct _Ctype_is_mask : public unary_function<char, bool> {
ctype_base::mask _Mask;
const ctype_base::mask* _M_table;
_Ctype_is_mask(ctype_base::mask __m, const ctype_base::mask* __t) : _Mask(__m), _M_table(__t) {}
bool operator()(char __c) const { return (_M_table[(unsigned char) __c] & _Mask) != 0; }
};
struct _Ctype_not_mask : public unary_function<char, bool> {
ctype_base::mask _Mask;
const ctype_base::mask* _M_table;
_Ctype_not_mask(ctype_base::mask __m, const ctype_base::mask* __t) : _Mask(__m), _M_table(__t) {}
bool operator()(char __c) const { return (_M_table[(unsigned char) __c] & _Mask) == 0; }
};
ctype<char>::ctype(const ctype_base::mask * __tab, bool __del, size_t __refs) :
locale::facet(__refs),
_M_ctype_table(__tab ? __tab : classic_table()),
_M_delete(__tab && __del)
{}
ctype<char>::~ctype() {
if (_M_delete)
delete[] __CONST_CAST(ctype_base::mask *, _M_ctype_table);
}
const char*
#if defined (__DMC__)
_STLP_DECLSPEC
#endif
ctype<char>::scan_is(ctype_base::mask __m, const char* __low, const char* __high) const
{ return _STLP_STD::find_if(__low, __high, _Ctype_is_mask(__m, _M_ctype_table)); }
const char*
#if defined (__DMC__)
_STLP_DECLSPEC
#endif
ctype<char>::scan_not(ctype_base::mask __m, const char* __low, const char* __high) const
{ return _STLP_STD::find_if(__low, __high, _Ctype_not_mask(__m, _M_ctype_table)); }
char ctype<char>::do_toupper(char __c) const
{ return (char) _S_upper[(unsigned char) __c]; }
char ctype<char>::do_tolower(char __c) const
{ return (char) _S_lower[(unsigned char) __c]; }
const char* ctype<char>::do_toupper(char* __low, const char* __high) const {
for ( ; __low < __high; ++__low)
*__low = (char) _S_upper[(unsigned char) *__low];
return __high;
}
const char* ctype<char>::do_tolower(char* __low, const char* __high) const {
for ( ; __low < __high; ++__low)
*__low = (char) _S_lower[(unsigned char) *__low];
return __high;
}
char
ctype<char>::do_widen(char __c) const { return __c; }
const char*
ctype<char>::do_widen(const char* __low, const char* __high,
char* __to) const {
_STLP_PRIV __copy_trivial(__low, __high, __to);
return __high;
}
char
ctype<char>::do_narrow(char __c, char /* dfault */ ) const { return __c; }
const char*
ctype<char>::do_narrow(const char* __low, const char* __high,
char /* dfault */, char* __to) const {
_STLP_PRIV __copy_trivial(__low, __high, __to);
return __high;
}
#if !defined (_STLP_NO_WCHAR_T)
struct _Ctype_w_is_mask : public unary_function<wchar_t, bool> {
ctype_base::mask M;
const ctype_base::mask* table;
_Ctype_w_is_mask(ctype_base::mask m, const ctype_base::mask* t)
: M(m), table(t) {}
bool operator()(wchar_t c) const
{ return _WCharIndex::in_range(c, ctype<char>::table_size) && (table[c] & M); }
};
//----------------------------------------------------------------------
// ctype<wchar_t>
ctype<wchar_t>::~ctype() {}
bool ctype<wchar_t>::do_is(ctype_base::mask m, wchar_t c) const {
const ctype_base::mask * table = ctype<char>::classic_table();
return _WCharIndex::in_range(c, ctype<char>::table_size) && (m & table[c]);
}
const wchar_t* ctype<wchar_t>::do_is(const wchar_t* low, const wchar_t* high,
ctype_base::mask * vec) const {
// boris : not clear if this is the right thing to do...
const ctype_base::mask * table = ctype<char>::classic_table();
wchar_t c;
for ( ; low < high; ++low, ++vec) {
c = *low;
*vec = _WCharIndex::in_range(c, ctype<char>::table_size) ? table[c] : ctype_base::mask(0);
}
return high;
}
const wchar_t*
ctype<wchar_t>::do_scan_is(ctype_base::mask m,
const wchar_t* low, const wchar_t* high) const {
return find_if(low, high, _Ctype_w_is_mask(m, ctype<char>::classic_table()));
}
const wchar_t*
ctype<wchar_t>::do_scan_not(ctype_base::mask m,
const wchar_t* low, const wchar_t* high) const {
return find_if(low, high, not1(_Ctype_w_is_mask(m, ctype<char>::classic_table())));
}
wchar_t ctype<wchar_t>::do_toupper(wchar_t c) const {
return _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_upper[c]
: c;
}
const wchar_t*
ctype<wchar_t>::do_toupper(wchar_t* low, const wchar_t* high) const {
for ( ; low < high; ++low) {
wchar_t c = *low;
*low = _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_upper[c]
: c;
}
return high;
}
wchar_t ctype<wchar_t>::do_tolower(wchar_t c) const {
return _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_lower[c]
: c;
}
const wchar_t*
ctype<wchar_t>::do_tolower(wchar_t* low, const wchar_t* high) const {
for ( ; low < high; ++low) {
wchar_t c = *low;
*low = _WCharIndex::in_range(c, ctype<char>::table_size) ? (wchar_t)_S_lower[c]
: c;
}
return high;
}
wchar_t ctype<wchar_t>::do_widen(char c) const {
return (wchar_t)(unsigned char)c;
}
const char*
ctype<wchar_t>::do_widen(const char* low, const char* high,
wchar_t* dest) const {
while (low != high)
*dest++ = (wchar_t)(unsigned char)*low++;
return high;
}
char ctype<wchar_t>::do_narrow(wchar_t c, char dfault) const
{ return (unsigned char)c == c ? (char)c : dfault; }
const wchar_t* ctype<wchar_t>::do_narrow(const wchar_t* low,
const wchar_t* high,
char dfault, char* dest) const {
while (low != high) {
wchar_t c = *low++;
*dest++ = (unsigned char)c == c ? (char)c : dfault;
}
return high;
}
# endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

198
extern/STLport/5.2.1/src/cxa.c vendored Normal file
View File

@@ -0,0 +1,198 @@
#include "stlport_prefix.h"
#if defined(__unix) && defined(__GNUC__)
#ifdef __FreeBSD__
# include <osreldate.h>
#endif
#if (defined(__FreeBSD__) && (__FreeBSD_version < 503001)) || defined(__sun) || defined (__hpux)
/* Note: __cxa_finalize and __cxa_atexit present in libc in FreeBSD 5.3 */
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
/* __asm__ (".symver " "__cxa_finalize" "," "__cxa_finalize" "@" "STLPORT_5_0_0"); */
/* __asm__ (".symver " "__cxa_finalize" "," "__cxa_finalize" "@@" "STLPORT_5_0_0"); */
/* Not atomic! */
/* But we can use static mutexes here: I hope that performance issue isn't very
significant on unloading (for only few calls, ~10) - ptr */
/*
#define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
({ __typeof (mem) __gmemp = (mem); \
__typeof (*mem) __gnewval = (newval); \
\
*__gmemp == (oldval) ? (*__gmemp = __gnewval, 0) : 1; })
*/
enum {
ef_free, /* `ef_free' MUST be zero! */
ef_us,
ef_on,
ef_at,
ef_cxa
};
struct exit_function
{
/* `flavour' should be of type of the `enum' above but since we need
this element in an atomic operation we have to use `long int'. */
long int flavor;
union {
void (*at)(void);
struct {
void (*fn)(int status, void *arg);
void *arg;
} on;
struct {
void (*fn)(void *arg, int status);
void *arg;
void *dso_handle;
} cxa;
} func;
};
struct exit_function_list
{
struct exit_function_list *next;
size_t idx;
struct exit_function fns[32];
};
struct exit_function *__new_exitfn (void);
/* Register a function to be called by exit or when a shared library
is unloaded. This function is only called from code generated by
the C++ compiler. */
int __cxa_atexit(void (*func)(void *), void *arg, void *d)
{
struct exit_function *new = __new_exitfn ();
if ( new == NULL )
return -1;
new->flavor = ef_cxa;
new->func.cxa.fn = (void (*) (void *, int)) func;
new->func.cxa.arg = arg;
new->func.cxa.dso_handle = d;
return 0;
}
/* We change global data, so we need locking. */
#ifdef __linux__
static pthread_mutex_t lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#endif
/* #ifdef __FreeBSD__ */
#if 0
static pthread_mutex_t lock =
{ PTHREAD_MUTEX_RECURSIVE /* PTHREAD_MUTEX_DEFAULT */, PTHREAD_PRIO_NONE, {NULL,NULL},
NULL, { NULL }, /* MUTEX_FLAGS_PRIVATE */ 0x1, 0, 0, 0, {NULL, NULL},
{ 0, 0, 0, 0 } };
#endif
#ifdef __sun
static pthread_mutex_t lock =
{{0, 0, 0, PTHREAD_MUTEX_RECURSIVE, _MUTEX_MAGIC}, {{{0}}}, 0};
#endif
#ifdef __hpux
static pthread_mutex_t lock = PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP;
# ifdef __ia64
void *__dso_handle = (void *) &__dso_handle;
# endif
#endif
static struct exit_function_list initial;
struct exit_function_list *__exit_funcs = &initial;
struct exit_function *__new_exitfn(void)
{
struct exit_function_list *l;
size_t i = 0;
#ifndef __FreeBSD__
pthread_mutex_lock( &lock );
#endif
for (l = __exit_funcs; l != NULL; l = l->next) {
for (i = 0; i < l->idx; ++i)
if (l->fns[i].flavor == ef_free)
break;
if ( i < l->idx )
break;
if (l->idx < sizeof (l->fns) / sizeof (l->fns[0])) {
i = l->idx++;
break;
}
}
if (l == NULL) {
l = (struct exit_function_list *)malloc( sizeof(struct exit_function_list) );
if (l != NULL) {
l->next = __exit_funcs;
__exit_funcs = l;
l->idx = 1;
i = 0;
}
}
/* Mark entry as used, but we don't know the flavor now. */
if ( l != NULL )
l->fns[i].flavor = ef_us;
#ifndef __FreeBSD__
pthread_mutex_unlock( &lock );
#endif
return l == NULL ? NULL : &l->fns[i];
}
/* If D is non-NULL, call all functions registered with `__cxa_atexit'
with the same dso handle. Otherwise, if D is NULL, call all of the
registered handlers. */
/*
* Note, that original __cxa_finalize don't use lock, but use __exit_funcs
* i.e. global data.
*/
void __cxa_finalize(void *d)
{
struct exit_function_list *funcs;
#ifndef __FreeBSD__
pthread_mutex_lock( &lock );
#endif
for (funcs = __exit_funcs; funcs; funcs = funcs->next) {
struct exit_function *f;
for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f) {
if ( (d == NULL || d == f->func.cxa.dso_handle) && (f->flavor == ef_cxa) ) {
f->flavor = ef_free;
(*f->func.cxa.fn) (f->func.cxa.arg, 0);
}
}
}
/* Remove the registered fork handlers. We do not have to
unregister anything if the program is going to terminate anyway. */
#ifdef UNREGISTER_ATFORK
if (d != NULL)
UNREGISTER_ATFORK (d);
#endif
#ifndef __FreeBSD__
pthread_mutex_unlock( &lock );
#endif
}
/* __asm__ (".symver " "__cxa_finalize" "," "__cxa_finalize" "@@" "STLPORT_5_0_0"); */
/* void __cxa_finalize(void *d) __attribute__ ((weak)); */
#endif /* OS name */
#endif /* __unix */

View File

@@ -0,0 +1,387 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#if defined (__SUNPPRO_CC) && !defined (_STLP_NO_NEW_C_HEADERS)
# include <time.h>
// For sunpro, it chokes if time.h is included through stat.h
#endif
#include <fstream>
#ifdef __CYGWIN__
# define __int64 long long
#endif
#include <cstdio>
#if !defined(__ISCPP__)
extern "C" {
# include <sys/stat.h>
}
#endif
#if defined( __MSL__ )
# include <unix.h>
#endif
#if defined(__ISCPP__)
# include <c_locale_is/filestat.h>
#endif
#if defined(__BEOS__) && defined(__INTEL__)
# include <fcntl.h>
# include <sys/stat.h> // For _fstat
#endif
#if defined (_STLP_MSVC) || defined (__MINGW32__)
# include <fcntl.h>
# define S_IREAD _S_IREAD
# define S_IWRITE _S_IWRITE
# define S_IFREG _S_IFREG
// map permission masks
# ifndef S_IRUSR
# define S_IRUSR _S_IREAD
# define S_IWUSR _S_IWRITE
# endif
# ifndef S_IRGRP
# define S_IRGRP _S_IREAD
# define S_IWGRP _S_IWRITE
# endif
# ifndef S_IROTH
# define S_IROTH _S_IREAD
# define S_IWOTH _S_IWRITE
# endif
# ifndef O_RDONLY
# define O_RDONLY _O_RDONLY
# define O_WRONLY _O_WRONLY
# define O_RDWR _O_RDWR
# define O_APPEND _O_APPEND
# define O_CREAT _O_CREAT
# define O_TRUNC _O_TRUNC
# define O_TEXT _O_TEXT
# define O_BINARY _O_BINARY
# endif
# ifndef O_ACCMODE
# define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
# endif
#endif
const _STLP_fd INVALID_STLP_FD = -1;
# ifdef __MSL__
# define _O_TEXT 0x0
# if !defined( O_TEXT )
# define O_TEXT _O_TEXT
# endif
# define _S_IFREG S_IFREG
# define S_IREAD S_IRUSR
# define S_IWRITE S_IWUSR
# define S_IEXEC S_IXUSR
# define _S_IWRITE S_IWRITE
# define _S_IREAD S_IREAD
# define _open open
# define _close close
# define _read read
# define _write write
# endif
_STLP_BEGIN_NAMESPACE
// Compare with streamoff definition in stl/char_traits.h!
#if defined (_STLP_USE_DEFAULT_FILE_OFFSET) || \
(!defined(_LARGEFILE_SOURCE) && !defined(_LARGEFILE64_SOURCE))
# define FOPEN fopen
# define FSEEK fseek
# define FSTAT fstat
# define STAT stat
# define FTELL ftell
#else
# define FOPEN fopen64
# define FSEEK fseeko64
# define FSTAT fstat64
# define STAT stat64
# define FTELL ftello64
#endif
_STLP_MOVE_TO_PRIV_NAMESPACE
// Helper functions for _Filebuf_base.
static bool __is_regular_file(_STLP_fd fd) {
struct STAT buf;
return FSTAT(fd, &buf) == 0 && (buf.st_mode & S_IFREG) != 0 ;
}
// Number of characters in the file.
static streamoff __file_size(_STLP_fd fd) {
streamoff ret = 0;
struct STAT buf;
if (FSTAT(fd, &buf) == 0 && (buf.st_mode & S_IFREG) != 0)
ret = buf.st_size > 0 ? buf.st_size : 0;
return ret;
}
_STLP_MOVE_TO_STD_NAMESPACE
// All version of Unix have mmap and lseek system calls. Some also have
// longer versions of those system calls to accommodate 64-bit offsets.
// If we're on a Unix system, define some macros to encapsulate those
// differences.
size_t _Filebuf_base::_M_page_size = 4096;
_Filebuf_base::_Filebuf_base()
: _M_file_id(INVALID_STLP_FD),
_M_openmode(0),
_M_is_open(false),
_M_should_close(false)
{}
void _Filebuf_base::_S_initialize()
{
}
// Return the size of the file. This is a wrapper for stat.
// Returns zero if the size cannot be determined or is ill-defined.
streamoff _Filebuf_base::_M_file_size()
{
return _STLP_PRIV __file_size(_M_file_id);
}
bool _Filebuf_base::_M_open(const char* name, ios_base::openmode openmode,
long permission)
{
_STLP_fd file_no;
if (_M_is_open)
return false;
// use FILE-based i/o
const char* flags;
switch (openmode & (~ios_base::ate)) {
case ios_base::out:
case ios_base::out | ios_base::trunc:
flags = "w";
break;
case ios_base::out | ios_base::binary:
case ios_base::out | ios_base::trunc | ios_base::binary:
flags = "wb";
break;
case ios_base::out | ios_base::app:
flags = "a";
break;
case ios_base::out | ios_base::app | ios_base::binary:
flags = "ab";
break;
case ios_base::in:
flags = "r";
break;
case ios_base::in | ios_base::binary:
flags = "rb";
break;
case ios_base::in | ios_base::out:
flags = "r+";
break;
case ios_base::in | ios_base::out | ios_base::binary:
flags = "r+b";
break;
case ios_base::in | ios_base::out | ios_base::trunc:
flags = "w+";
break;
case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
flags = "w+b";
break;
default: // The above are the only combinations of
return false; // flags allowed by the C++ standard.
}
// fbp : TODO : set permissions !
(void)permission; // currently unused //*TY 02/26/2000 - added to suppress warning message
_M_file = FOPEN(name, flags);
if (_M_file) {
file_no = fileno(_M_file);
} else {
return false;
}
// unset buffering immediately
setbuf(_M_file, 0);
_M_is_open = true;
if (openmode & ios_base::ate) {
if (FSEEK(_M_file, 0, SEEK_END) != 0)
_M_is_open = false;
}
_M_file_id = file_no;
_M_should_close = _M_is_open;
_M_openmode = openmode;
if (_M_is_open)
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return (_M_is_open != 0);
}
bool _Filebuf_base::_M_open(const char* name, ios_base::openmode openmode)
{
// This doesn't really grant everyone in the world read/write
// access. On Unix, file-creation system calls always clear
// bits that are set in the umask from the permissions flag.
return this->_M_open(name, openmode, S_IRUSR | S_IWUSR | S_IRGRP |
S_IWGRP | S_IROTH | S_IWOTH);
}
// Associated the filebuf with a file descriptor pointing to an already-
// open file. Mode is set to be consistent with the way that the file
// was opened.
bool _Filebuf_base::_M_open( int file_no, ios_base::openmode )
{
if (_M_is_open || file_no < 0)
return false;
struct STAT buf;
if (FSTAT(file_no, &buf) != 0)
return false;
int mode = buf.st_mode;
switch ( mode & (S_IWRITE | S_IREAD) ) {
case S_IREAD:
_M_openmode = ios_base::in;
break;
case S_IWRITE:
_M_openmode = ios_base::out;
break;
case (S_IWRITE | S_IREAD):
_M_openmode = ios_base::in | ios_base::out;
break;
default:
return false;
}
_M_file_id = file_no;
_M_is_open = true;
_M_should_close = false;
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return true;
}
bool _Filebuf_base::_M_close()
{
if (!_M_is_open)
return false;
bool ok = _M_should_close ? (fclose(_M_file) == 0) : true;
_M_is_open = _M_should_close = false;
_M_openmode = 0;
return ok;
}
// Read up to n characters into a buffer. Return value is number of
// characters read.
ptrdiff_t _Filebuf_base::_M_read(char* buf, ptrdiff_t n) {
return fread(buf, 1, n, _M_file);
}
// Write n characters from a buffer. Return value: true if we managed
// to write the entire buffer, false if we didn't.
bool _Filebuf_base::_M_write(char* buf, ptrdiff_t n)
{
for (;;) {
ptrdiff_t written = fwrite(buf, 1, n, _M_file);
if (n == written) {
return true;
}
if (written > 0 && written < n) {
n -= written;
buf += written;
} else {
return false;
}
}
}
// Wrapper for lseek or the like.
streamoff _Filebuf_base::_M_seek(streamoff offset, ios_base::seekdir dir)
{
int whence;
switch ( dir ) {
case ios_base::beg:
if (offset < 0 /* || offset > _M_file_size() */ )
return streamoff(-1);
whence = SEEK_SET;
break;
case ios_base::cur:
whence = SEEK_CUR;
break;
case ios_base::end:
if (/* offset > 0 || */ -offset > _M_file_size() )
return streamoff(-1);
whence = SEEK_END;
break;
default:
return streamoff(-1);
}
if ( FSEEK(_M_file, offset, whence) == 0 ) {
return FTELL(_M_file);
}
return streamoff(-1);
}
// Attempts to memory-map len bytes of the current file, starting
// at position offset. Precondition: offset is a multiple of the
// page size. Postcondition: return value is a null pointer if the
// memory mapping failed. Otherwise the return value is a pointer to
// the memory-mapped file and the file position is set to offset.
void *_Filebuf_base::_M_mmap(streamoff, streamoff )
{
return 0;
}
void _Filebuf_base::_M_unmap(void*, streamoff)
{
// precondition : there is a valid mapping at the moment
}
_STLP_END_NAMESPACE

View File

@@ -0,0 +1,347 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#if defined (__SUNPPRO_CC) && !defined (_STLP_NO_NEW_C_HEADERS)
# include <time.h>
// For sunpro, it chokes if time.h is included through stat.h
#endif
#include <fstream>
#ifdef __CYGWIN__
# define __int64 long long
#endif
extern "C" {
// open/close/read/write
#include <sys/stat.h> // For stat
#if !defined (_CRAY) && ! defined (__EMX__)
# include <sys/mman.h> // For mmap
#endif
// on HP-UX 11, this one contradicts with pthread.h on pthread_atfork, unless we unset this
#if defined (__hpux) && defined (__GNUC__)
# undef _INCLUDE_POSIX1C_SOURCE
#endif
#include <unistd.h>
#include <fcntl.h>
}
#ifdef __APPLE__
# include <sys/sysctl.h>
#endif
const _STLP_fd INVALID_STLP_FD = -1;
#ifndef O_ACCMODE
# define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
// Compare with streamoff definition in stl/char_traits.h!
#if defined (_STLP_USE_DEFAULT_FILE_OFFSET) || \
(!defined(_LARGEFILE_SOURCE) && !defined (_LARGEFILE64_SOURCE))
# define FSTAT fstat
# define STAT stat
# define LSEEK lseek
# define MMAP mmap
# define OPEN open
#else
# define FSTAT fstat64
# define STAT stat64
# define LSEEK lseek64
# define MMAP mmap64
# define OPEN open64
#endif
#ifndef MAP_FAILED /* MMAP failure return code */
# define MAP_FAILED -1
#endif
_STLP_BEGIN_NAMESPACE
static ios_base::openmode flag_to_openmode(int mode)
{
ios_base::openmode ret = ios_base::__default_mode;
switch ( mode & O_ACCMODE ) {
case O_RDONLY:
ret = ios_base::in;
break;
case O_WRONLY:
ret = ios_base::out;
break;
case O_RDWR:
ret = ios_base::in | ios_base::out;
break;
}
if ( mode & O_APPEND )
ret |= ios_base::app;
return ret;
}
_STLP_MOVE_TO_PRIV_NAMESPACE
// Helper functions for _Filebuf_base.
static bool __is_regular_file(_STLP_fd fd) {
struct STAT buf;
return FSTAT(fd, &buf) == 0 && S_ISREG(buf.st_mode);
}
// Number of characters in the file.
static streamoff __file_size(_STLP_fd fd) {
streamoff ret = 0;
struct STAT buf;
if (FSTAT(fd, &buf) == 0 && S_ISREG(buf.st_mode))
ret = buf.st_size > 0 ? buf.st_size : 0;
return ret;
}
_STLP_MOVE_TO_STD_NAMESPACE
size_t _Filebuf_base::_M_page_size = 4096;
_Filebuf_base::_Filebuf_base()
: _M_file_id(INVALID_STLP_FD),
_M_openmode(0),
_M_is_open(false),
_M_should_close(false)
{}
void _Filebuf_base::_S_initialize()
{
#if defined (__APPLE__)
int mib[2];
size_t pagesize, len;
mib[0] = CTL_HW;
mib[1] = HW_PAGESIZE;
len = sizeof(pagesize);
sysctl(mib, 2, &pagesize, &len, NULL, 0);
_M_page_size = pagesize;
#elif defined (__DJGPP) && defined (_CRAY)
_M_page_size = BUFSIZ;
#else
_M_page_size = sysconf(_SC_PAGESIZE);
#endif
}
// Return the size of the file. This is a wrapper for stat.
// Returns zero if the size cannot be determined or is ill-defined.
streamoff _Filebuf_base::_M_file_size()
{
return _STLP_PRIV __file_size(_M_file_id);
}
bool _Filebuf_base::_M_open(const char* name, ios_base::openmode openmode,
long permission)
{
_STLP_fd file_no;
if (_M_is_open)
return false;
int flags = 0;
// Unix makes no distinction between text and binary files.
switch ( openmode & (~ios_base::ate & ~ios_base::binary) ) {
case ios_base::out:
case ios_base::out | ios_base::trunc:
flags = O_WRONLY | O_CREAT | O_TRUNC;
break;
case ios_base::app:
case ios_base::out | ios_base::app:
flags = O_WRONLY | O_CREAT | O_APPEND;
break;
case ios_base::in:
flags = O_RDONLY;
permission = 0; // Irrelevant unless we're writing.
break;
case ios_base::in | ios_base::out:
flags = O_RDWR;
break;
case ios_base::in | ios_base::out | ios_base::trunc:
flags = O_RDWR | O_CREAT | O_TRUNC;
break;
case ios_base::in | ios_base::app:
case ios_base::in | ios_base::out | ios_base::app:
flags = O_RDWR | O_CREAT | O_APPEND;
break;
default: // The above are the only combinations of
return false; // flags allowed by the C++ standard.
}
file_no = OPEN(name, flags, permission);
if (file_no < 0)
return false;
_M_is_open = true;
if ((openmode & (ios_base::ate | ios_base::app)) && (LSEEK(file_no, 0, SEEK_END) == -1)) {
_M_is_open = false;
}
_M_file_id = file_no;
_M_should_close = _M_is_open;
_M_openmode = openmode;
if (_M_is_open)
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return (_M_is_open != 0);
}
bool _Filebuf_base::_M_open(const char* name, ios_base::openmode openmode)
{
// This doesn't really grant everyone in the world read/write
// access. On Unix, file-creation system calls always clear
// bits that are set in the umask from the permissions flag.
return this->_M_open(name, openmode, S_IRUSR | S_IWUSR | S_IRGRP |
S_IWGRP | S_IROTH | S_IWOTH);
}
// Associated the filebuf with a file descriptor pointing to an already-
// open file. Mode is set to be consistent with the way that the file
// was opened.
bool _Filebuf_base::_M_open(int file_no, ios_base::openmode)
{
if (_M_is_open || file_no < 0)
return false;
int mode = fcntl(file_no, F_GETFL);
if (mode == -1)
return false;
_M_openmode = flag_to_openmode(mode);
_M_file_id = file_no;
_M_is_open = true;
_M_should_close = false;
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return true;
}
bool _Filebuf_base::_M_close()
{
if (!_M_is_open)
return false;
bool ok = _M_should_close ? (close(_M_file_id) == 0) : true;
_M_is_open = _M_should_close = false;
_M_openmode = 0;
return ok;
}
// Read up to n characters into a buffer. Return value is number of
// characters read.
ptrdiff_t _Filebuf_base::_M_read(char* buf, ptrdiff_t n)
{
return read(_M_file_id, buf, n);
}
// Write n characters from a buffer. Return value: true if we managed
// to write the entire buffer, false if we didn't.
bool _Filebuf_base::_M_write(char* buf, ptrdiff_t n)
{
for (;;) {
ptrdiff_t written = write(_M_file_id, buf, n);
if (n == written) {
return true;
}
if (written > 0 && written < n) {
n -= written;
buf += written;
} else {
return false;
}
}
}
// Wrapper for lseek or the like.
streamoff _Filebuf_base::_M_seek(streamoff offset, ios_base::seekdir dir)
{
int whence;
switch ( dir ) {
case ios_base::beg:
if (offset < 0 /* || offset > _M_file_size() */ )
return streamoff(-1);
whence = SEEK_SET;
break;
case ios_base::cur:
whence = SEEK_CUR;
break;
case ios_base::end:
if (/* offset > 0 || */ -offset > _M_file_size() )
return streamoff(-1);
whence = SEEK_END;
break;
default:
return streamoff(-1);
}
return LSEEK(_M_file_id, offset, whence);
}
// Attempts to memory-map len bytes of the current file, starting
// at position offset. Precondition: offset is a multiple of the
// page size. Postcondition: return value is a null pointer if the
// memory mapping failed. Otherwise the return value is a pointer to
// the memory-mapped file and the file position is set to offset.
void* _Filebuf_base::_M_mmap(streamoff offset, streamoff len)
{
void* base;
#if !defined (__DJGPP) && !defined (_CRAY)
base = MMAP(0, len, PROT_READ, MAP_PRIVATE, _M_file_id, offset);
if (base != (void*)MAP_FAILED) {
if (LSEEK(_M_file_id, offset + len, SEEK_SET) < 0) {
this->_M_unmap(base, len);
base = 0;
}
} else
base =0;
#else
_STLP_MARK_PARAMETER_AS_UNUSED(&offset)
_STLP_MARK_PARAMETER_AS_UNUSED(&len)
base = 0;
#endif
return base;
}
void _Filebuf_base::_M_unmap(void* base, streamoff len)
{
// precondition : there is a valid mapping at the moment
#if !defined (__DJGPP) && !defined (_CRAY)
munmap((char*)base, len);
#else
_STLP_MARK_PARAMETER_AS_UNUSED(&len)
_STLP_MARK_PARAMETER_AS_UNUSED(base)
#endif
}
_STLP_END_NAMESPACE

View File

@@ -0,0 +1,629 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include <fstream>
#if !defined (_STLP_WCE)
# ifdef __BORLANDC__
# include <cfcntl.h> // For _O_RDONLY, etc
# else
# include <io.h> // For _get_osfhandle
# include <fcntl.h> // For _O_RDONLY, etc
# endif
# include <sys/stat.h> // For _fstat
#endif
#define _TEXTBUF_SIZE 0x1000
const _STLP_fd INVALID_STLP_FD = INVALID_HANDLE_VALUE;
#if !defined (INVALID_SET_FILE_POINTER)
# define INVALID_SET_FILE_POINTER 0xffffffff
#endif
#ifndef O_ACCMODE
# define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
_STLP_BEGIN_NAMESPACE
#if !defined(__MSL__) && !defined(_STLP_WCE)
static ios_base::openmode flag_to_openmode(int mode) {
ios_base::openmode ret = ios_base::__default_mode;
switch (mode & O_ACCMODE) {
case O_RDONLY:
ret = ios_base::in; break;
case O_WRONLY:
ret = ios_base::out; break;
case O_RDWR:
ret = ios_base::in | ios_base::out; break;
}
if (mode & O_APPEND)
ret |= ios_base::app;
if (mode & O_BINARY)
ret |= ios_base::binary;
return ret;
}
#endif
_STLP_MOVE_TO_PRIV_NAMESPACE
// Helper functions for _Filebuf_base.
static bool __is_regular_file(_STLP_fd fd) {
BY_HANDLE_FILE_INFORMATION info;
// Return true if the file handle isn't a directory.
return GetFileInformationByHandle(fd, &info) &&
((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
}
// Number of characters in the file.
static streamoff __file_size(_STLP_fd fd) {
streamoff ret = 0;
LARGE_INTEGER li;
li.LowPart = GetFileSize(fd, (unsigned long*) &li.HighPart);
if (li.LowPart != INVALID_FILE_SIZE || GetLastError() == NO_ERROR)
ret = li.QuadPart;
return ret;
}
_STLP_MOVE_TO_STD_NAMESPACE
// Visual C++ and Intel use this, but not Metrowerks
// Also MinGW, msvcrt.dll (but not crtdll.dll) dependent version
#if (defined (_STLP_MSVC_LIB) && !defined (_STLP_WCE)) || \
(defined (__MINGW32__) && defined (__MSVCRT__))
// fcntl(fileno, F_GETFL) for Microsoft library
// 'semi-documented' defines:
# define IOINFO_L2E 5
# define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
# define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + \
((i) & (IOINFO_ARRAY_ELTS - 1)) )
# define FAPPEND 0x20 // O_APPEND flag
# define FTEXT 0x80 // O_TEXT flag
// end of 'semi-documented' defines
// 'semi-documented' internal structure
extern "C" {
struct ioinfo {
long osfhnd; // the real os HANDLE
char osfile; // file handle flags
char pipech; // pipe buffer
# if defined (_MT)
// multi-threaded locking
int lockinitflag;
CRITICAL_SECTION lock;
# endif
};
# if defined (__MINGW32__)
__MINGW_IMPORT ioinfo * __pioinfo[];
# else
extern _CRTIMP ioinfo * __pioinfo[];
# endif
} // extern "C"
// end of 'semi-documented' declarations
static ios_base::openmode _get_osfflags(int fd, HANDLE oshandle) {
char dosflags = 0;
if (fd >= 0)
dosflags = _pioinfo(fd)->osfile;
//else
//the file will be considered as open in binary mode with no append attribute
// end of 'semi-documented' stuff
int mode = 0;
if (dosflags & FAPPEND)
mode |= O_APPEND;
if (dosflags & FTEXT)
mode |= O_TEXT;
else
mode |= O_BINARY;
// For Read/Write access we have to guess
DWORD dummy, dummy2;
BOOL writeOk = WriteFile(oshandle, &dummy2, 0, &dummy, 0);
BOOL readOk = ReadFile(oshandle, &dummy2, 0, &dummy, NULL);
if (writeOk && readOk)
mode |= O_RDWR;
else if (readOk)
mode |= O_RDONLY;
else
mode |= O_WRONLY;
return flag_to_openmode(mode);
}
#elif defined (__DMC__)
# define FHND_APPEND 0x04
# define FHND_DEVICE 0x08
# define FHND_TEXT 0x10
extern "C" unsigned char __fhnd_info[_NFILE];
static ios_base::openmode _get_osfflags(int fd, HANDLE oshandle) {
int mode = 0;
if (__fhnd_info[fd] & FHND_APPEND)
mode |= O_APPEND;
if (__fhnd_info[fd] & FHND_TEXT == 0)
mode |= O_BINARY;
for (FILE *fp = &_iob[0]; fp < &_iob[_NFILE]; fp++) {
if ((fileno(fp) == fd) && (fp->_flag & (_IOREAD | _IOWRT | _IORW))) {
const int osflags = fp->_flag;
if ((osflags & _IOREAD) && !(osflags & _IOWRT) && !(osflags & _IORW))
mode |= O_RDONLY;
else if ((osflags & _IOWRT) && !(osflags & _IOREAD) && !(osflags & _IORW))
mode |= O_WRONLY;
else
mode |= O_RDWR;
break;
}
}
return flag_to_openmode(mode);
}
#endif
size_t _Filebuf_base::_M_page_size = 4096;
_Filebuf_base::_Filebuf_base()
: _M_file_id(INVALID_STLP_FD),
_M_openmode(0),
_M_is_open(false),
_M_should_close(false),
_M_view_id(0)
{}
void _Filebuf_base::_S_initialize() {
SYSTEM_INFO SystemInfo;
GetSystemInfo(&SystemInfo);
_M_page_size = SystemInfo.dwPageSize;
// might be .dwAllocationGranularity
}
// Return the size of the file. This is a wrapper for stat.
// Returns zero if the size cannot be determined or is ill-defined.
streamoff _Filebuf_base::_M_file_size() {
return _STLP_PRIV __file_size(_M_file_id);
}
bool _Filebuf_base::_M_open(const char* name, ios_base::openmode openmode,
long permission) {
_STLP_fd file_no;
if (_M_is_open)
return false;
DWORD dwDesiredAccess, dwCreationDisposition;
bool doTruncate = false;
switch (openmode & (~ios_base::ate & ~ios_base::binary)) {
case ios_base::out:
case ios_base::out | ios_base::trunc:
dwDesiredAccess = GENERIC_WRITE;
dwCreationDisposition = OPEN_ALWAYS;
// boris : even though it is very non-intuitive, standard
// requires them both to behave same.
doTruncate = true;
break;
case ios_base::out | ios_base::app:
dwDesiredAccess = GENERIC_WRITE;
dwCreationDisposition = OPEN_ALWAYS;
break;
case ios_base::in:
dwDesiredAccess = GENERIC_READ;
dwCreationDisposition = OPEN_EXISTING;
permission = 0; // Irrelevant unless we're writing.
break;
case ios_base::in | ios_base::out:
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
dwCreationDisposition = OPEN_EXISTING;
break;
case ios_base::in | ios_base::out | ios_base::trunc:
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
dwCreationDisposition = OPEN_ALWAYS;
doTruncate = true;
break;
default: // The above are the only combinations of
return false; // flags allowed by the C++ standard.
}
DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
#if defined(_STLP_USE_WIDE_INTERFACE)
file_no = CreateFile (_STLP_PRIV __ASCIIToWide(name).c_str(),
#else
file_no = CreateFileA(name,
#endif
dwDesiredAccess, dwShareMode, 0,
dwCreationDisposition, permission, 0);
if (file_no == INVALID_STLP_FD)
return false;
if (
#if !defined (_STLP_WCE)
GetFileType(file_no) == FILE_TYPE_DISK &&
#endif
((doTruncate && SetEndOfFile(file_no) == 0) ||
(((openmode & ios_base::ate) != 0) &&
(SetFilePointer(file_no, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)))) {
CloseHandle(file_no);
return false;
}
_M_is_open = true;
_M_file_id = file_no;
_M_should_close = _M_is_open;
_M_openmode = openmode;
if (_M_is_open)
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return (_M_is_open != 0);
}
bool _Filebuf_base::_M_open(const char* name, ios_base::openmode openmode) {
// This doesn't really grant everyone in the world read/write
// access. On Unix, file-creation system calls always clear
// bits that are set in the umask from the permissions flag.
return this->_M_open(name, openmode, FILE_ATTRIBUTE_NORMAL);
}
bool _Filebuf_base::_M_open(_STLP_fd __id, ios_base::openmode init_mode) {
#if (defined (_STLP_MSVC_LIB) && !defined (_STLP_WCE)) || \
(defined (__MINGW32__) && defined (__MSVCRT__)) || defined (__DMC__)
if (_M_is_open || __id == INVALID_STLP_FD)
return false;
if (init_mode != ios_base::__default_mode)
_M_openmode = init_mode;
else
_M_openmode = _get_osfflags(-1, __id);
_M_is_open = true;
_M_file_id = __id;
_M_should_close = false;
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return true;
#else
(void)__id;
(void)init_mode; // dwa 4/27/00 - suppress unused parameter warning
// not available for the API
return false;
#endif
}
// Associated the filebuf with a file descriptor pointing to an already-
// open file. Mode is set to be consistent with the way that the file
// was opened.
bool _Filebuf_base::_M_open(int file_no, ios_base::openmode init_mode) {
if (_M_is_open || file_no < 0)
return false;
#if (defined (_STLP_MSVC_LIB) && !defined (_STLP_WCE)) || \
(defined (__MINGW32__) && defined (__MSVCRT__)) || defined (__DMC__)
HANDLE oshandle = (HANDLE)_get_osfhandle(file_no);
if (oshandle == INVALID_STLP_FD)
return false;
if (init_mode != ios_base::__default_mode)
_M_openmode = init_mode;
else
_M_openmode = _get_osfflags(file_no, oshandle);
_M_file_id = oshandle;
_M_is_open = true;
_M_should_close = false;
_M_regular_file = _STLP_PRIV __is_regular_file(_M_file_id);
return true;
#else
_STLP_MARK_PARAMETER_AS_UNUSED(&init_mode)
// not available for the API
return false;
#endif
}
bool _Filebuf_base::_M_close() {
if (!_M_is_open)
return false;
bool ok;
if (!_M_should_close)
ok = true;
else {
if (_M_file_id != INVALID_STLP_FD) {
ok = (CloseHandle(_M_file_id) != 0);
}
else {
ok = false;
}
}
_M_is_open = _M_should_close = false;
_M_openmode = 0;
return ok;
}
#define _STLP_LF 10
#define _STLP_CR 13
#define _STLP_CTRLZ 26
// Read up to n characters into a buffer. Return value is number of
// characters read.
ptrdiff_t _Filebuf_base::_M_read(char* buf, ptrdiff_t n) {
ptrdiff_t readen = 0;
//Here cast to size_t is safe as n cannot be negative.
size_t chunkSize = (min)(size_t(0xffffffff), __STATIC_CAST(size_t, n));
// The following, while validating that we are still able to extract chunkSize
// charaters to the buffer, avoids extraction of too small chunk of datas
// which would be counter performant.
while (__STATIC_CAST(size_t, (n - readen)) >= chunkSize) {
DWORD numberOfBytesRead;
ReadFile(_M_file_id, buf + readen, __STATIC_CAST(DWORD, chunkSize), &numberOfBytesRead, 0);
if (numberOfBytesRead == 0)
break;
if (!(_M_openmode & ios_base::binary)) {
// translate CR-LFs to LFs in the buffer
char *to = buf + readen;
char *from = to;
char *last = from + numberOfBytesRead - 1;
for (; from <= last && *from != _STLP_CTRLZ; ++from) {
if (*from != _STLP_CR)
*to++ = *from;
else { // found CR
if (from < last) { // not at buffer end
if (*(from + 1) != _STLP_LF)
*to++ = _STLP_CR;
}
else { // last char is CR, peek for LF
char peek = ' ';
DWORD NumberOfBytesPeeked;
ReadFile(_M_file_id, (LPVOID)&peek, 1, &NumberOfBytesPeeked, 0);
if (NumberOfBytesPeeked != 0) {
if (peek != _STLP_LF) { //not a <CR><LF> combination
*to++ = _STLP_CR;
if ((to < buf + n) && (peek != _STLP_CR))
//We have enough place to store peek and it is no a special
//_STLP_CR character, we can store it.
*to++ = peek;
else
SetFilePointer(_M_file_id, (LONG)-1, 0, FILE_CURRENT);
}
else {
// A <CR><LF> combination, we keep the <LF>:
*to++ = _STLP_LF;
}
}
else {
/* This case is tedious, we could
* - put peek back in the file but this would then generate an infinite loop
* - report an error as we don't know if in a future call to ReadFile we won't then
* get a <LF>. Doing so would make all files with a <CR> last an invalid file
* for STLport, a hard solution for STLport clients.
* - store the <CR> in the returned buffer, the chosen solution, even if in this
* case we could miss a <CR><LF> combination.
*/
*to++ = _STLP_CR;
}
}
} // found CR
} // for
readen = to - buf;
// seek back to TEXT end of file if hit CTRL-Z
if (from <= last) { // terminated due to CTRLZ
SetFilePointer(_M_file_id, -(LONG)((last + 1) - from), 0, FILE_CURRENT);
break;
}
}
else
readen += numberOfBytesRead;
}
return readen;
}
// Write n characters from a buffer. Return value: true if we managed
// to write the entire buffer, false if we didn't.
bool _Filebuf_base::_M_write(char* buf, ptrdiff_t n) {
for (;;) {
ptrdiff_t written;
//In the following implementation we are going to cast most of the ptrdiff_t
//values in size_t to work with coherent unsigned values. Doing so make code
//more simple especially in the min function call.
// In append mode, every write does an implicit seek to the end
// of the file.
if (_M_openmode & ios_base::app)
_M_seek(0, ios_base::end);
if (_M_openmode & ios_base::binary) {
// binary mode
size_t bytes_to_write = (size_t)n;
DWORD NumberOfBytesWritten;
written = 0;
for (; bytes_to_write != 0;) {
WriteFile(_M_file_id, buf + written,
__STATIC_CAST(DWORD, (min)(size_t(0xffffffff), bytes_to_write)),
&NumberOfBytesWritten, 0);
if (NumberOfBytesWritten == 0)
return false;
bytes_to_write -= NumberOfBytesWritten;
written += NumberOfBytesWritten;
}
}
else {
char textbuf[_TEXTBUF_SIZE + 1]; // extra 1 in case LF at end
char * nextblock = buf, * ptrtextbuf = textbuf;
char * endtextbuf = textbuf + _TEXTBUF_SIZE;
char * endblock = buf + n;
ptrdiff_t nextblocksize = (min) (n, (ptrdiff_t)_TEXTBUF_SIZE);
char * nextlf;
while ( (nextblocksize > 0) &&
(nextlf = (char *)memchr(nextblock, _STLP_LF, nextblocksize)) != 0) {
ptrdiff_t linelength = nextlf - nextblock;
memcpy(ptrtextbuf, nextblock, linelength);
ptrtextbuf += linelength;
nextblock += (linelength + 1);
* ptrtextbuf ++ = _STLP_CR;
* ptrtextbuf ++ = _STLP_LF;
nextblocksize = (min) (ptrdiff_t(endblock - nextblock),
(max) (ptrdiff_t(0), ptrdiff_t(endtextbuf - ptrtextbuf)));
}
// write out what's left, > condition is here since for LF at the end ,
// endtextbuf may get < ptrtextbuf ...
if (nextblocksize > 0) {
memcpy(ptrtextbuf, nextblock, nextblocksize);
ptrtextbuf += nextblocksize;
nextblock += nextblocksize;
}
// now write out the translated buffer
char * writetextbuf = textbuf;
for (size_t NumberOfBytesToWrite = (size_t)(ptrtextbuf - textbuf);
NumberOfBytesToWrite;) {
DWORD NumberOfBytesWritten;
WriteFile((HANDLE)_M_file_id, writetextbuf,
__STATIC_CAST(DWORD, (min)(size_t(0xffffffff), NumberOfBytesToWrite)),
&NumberOfBytesWritten, 0);
if (!NumberOfBytesWritten) // write shortfall
return false;
writetextbuf += NumberOfBytesWritten;
NumberOfBytesToWrite -= NumberOfBytesWritten;
}
// count non-translated characters
written = (nextblock - buf);
}
if (n == written)
return true;
else if (written > 0 && written < n) {
n -= written;
buf += written;
}
else
return false;
}
}
// Wrapper for lseek or the like.
streamoff _Filebuf_base::_M_seek(streamoff offset, ios_base::seekdir dir) {
streamoff result = -1;
int whence;
switch(dir) {
case ios_base::beg:
if (offset < 0 /* || offset > _M_file_size() */ )
return streamoff(-1);
whence = FILE_BEGIN;
break;
case ios_base::cur:
whence = FILE_CURRENT;
break;
case ios_base::end:
if (/* offset > 0 || */ -offset > _M_file_size() )
return streamoff(-1);
whence = FILE_END;
break;
default:
return streamoff(-1);
}
LARGE_INTEGER li;
li.QuadPart = offset;
li.LowPart = SetFilePointer(_M_file_id, li.LowPart, &li.HighPart, whence);
if (li.LowPart != INVALID_SET_FILE_POINTER || GetLastError() == NO_ERROR)
result = li.QuadPart;
return result;
}
// Attempts to memory-map len bytes of the current file, starting
// at position offset. Precondition: offset is a multiple of the
// page size. Postcondition: return value is a null pointer if the
// memory mapping failed. Otherwise the return value is a pointer to
// the memory-mapped file and the file position is set to offset.
void* _Filebuf_base::_M_mmap(streamoff offset, streamoff len) {
void* base;
_M_view_id = CreateFileMapping(_M_file_id, (PSECURITY_ATTRIBUTES)0 ,
PAGE_READONLY, 0 /* len >> 32 */ ,
0 /* len & 0xFFFFFFFF */ , // low-order DWORD of size
0);
if (_M_view_id) {
#if 0
/*
printf("view %x created from file %x, error = %d, size = %d, map_offset = %d map_len = %d\n",
_M_view_id, _M_file_id, GetLastError(),
(int)cur_filesize, ULL(offset) & 0xffffffff, len);
*/
#endif
LARGE_INTEGER li;
li.QuadPart = offset;
base = MapViewOfFile(_M_view_id, FILE_MAP_READ, li.HighPart, li.LowPart,
#if !defined (__DMC__)
__STATIC_CAST(SIZE_T, len));
#else
__STATIC_CAST(DWORD, len));
#endif
// check if mapping succeded and is usable
if (base == 0 || _M_seek(offset + len, ios_base::beg) < 0) {
this->_M_unmap(base, len);
base = 0;
}
} else
base = 0;
return base;
}
void _Filebuf_base::_M_unmap(void* base, streamoff len) {
// precondition : there is a valid mapping at the moment
if (base != NULL)
UnmapViewOfFile(base);
// destroy view handle as well
if (_M_view_id != NULL)
CloseHandle(_M_view_id);
_M_view_id = NULL;
(void)len; //unused variable
}
_STLP_END_NAMESPACE

262
extern/STLport/5.2.1/src/dll_main.cpp vendored Normal file
View File

@@ -0,0 +1,262 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#define _STLP_EXPOSE_GLOBALS_IMPLEMENTATION
#include "stlport_prefix.h"
#if !defined (_STLP_DEBUG) && ! defined (_STLP_ASSERTIONS)
# if !defined (__APPLE__) || !defined (__GNUC__) || (__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 3))
/* dums: Please if the following code was being uncommented please explain why
* as for the moment it only looks like a source of inconsistency in the way
* STLport different translation units are compiled.
*/
//# define _STLP_ASSERTIONS 1
# endif
#endif
#include <utility>
#include <memory>
#include <vector>
#include <set>
#include <list>
#include <slist>
#include <deque>
#include <hash_map>
#include <limits>
#include <string>
#include <stdexcept>
#include <bitset>
#include <locale>
#if defined (__DMC__)
// for rope static members
# include <rope>
#endif
#include <stl/_range_errors.c>
_STLP_BEGIN_NAMESPACE
#if defined (_STLP_NO_EXCEPTION_HEADER) || defined (_STLP_BROKEN_EXCEPTION_CLASS)
exception::exception() _STLP_NOTHROW {}
exception::~exception() _STLP_NOTHROW {}
bad_exception::bad_exception() _STLP_NOTHROW {}
bad_exception::~bad_exception() _STLP_NOTHROW {}
const char* exception::what() const _STLP_NOTHROW { return "class exception"; }
const char* bad_exception::what() const _STLP_NOTHROW { return "class bad_exception"; }
#endif
#if defined (_STLP_OWN_STDEXCEPT)
# include <stl/_stdexcept_base.c>
// boris : those are needed to force typeinfo nodes to be created in here only
logic_error::~logic_error() _STLP_NOTHROW_INHERENTLY {}
runtime_error::~runtime_error() _STLP_NOTHROW_INHERENTLY {}
domain_error::~domain_error() _STLP_NOTHROW_INHERENTLY {}
invalid_argument::~invalid_argument() _STLP_NOTHROW_INHERENTLY {}
length_error::~length_error() _STLP_NOTHROW_INHERENTLY {}
out_of_range::~out_of_range() _STLP_NOTHROW_INHERENTLY {}
range_error::~range_error() _STLP_NOTHROW_INHERENTLY {}
overflow_error::~overflow_error() _STLP_NOTHROW_INHERENTLY {}
underflow_error::~underflow_error() _STLP_NOTHROW_INHERENTLY {}
#endif
#if !defined(_STLP_WCE_EVC3)
# if defined (_STLP_NO_BAD_ALLOC)
const nothrow_t nothrow /* = {} */;
# endif
#endif
#if !defined (_STLP_NO_FORCE_INSTANTIATE)
# if defined (_STLP_DEBUG) || defined (_STLP_ASSERTIONS)
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC __stl_debug_engine<bool>;
_STLP_MOVE_TO_STD_NAMESPACE
# endif
template class _STLP_CLASS_DECLSPEC __debug_alloc<__node_alloc>;
template class _STLP_CLASS_DECLSPEC __debug_alloc<__new_alloc>;
//Export of the types used to represent buckets in the hashtable implementation.
/*
* For the vector class we do not use any MSVC6 workaround even if we export it from
* the STLport dynamic libraries because we know what methods are called and none is
* a template method. Moreover the exported class is an instanciation of vector with
* _Slist_node_base struct that is an internal STLport class that no user should ever
* use.
*/
# if !defined (_STLP_USE_PTR_SPECIALIZATIONS)
template class _STLP_CLASS_DECLSPEC allocator<_STLP_PRIV _Slist_node_base*>;
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<_Slist_node_base**, _Slist_node_base*,
allocator<_Slist_node_base*> >;
template class _STLP_CLASS_DECLSPEC _Vector_base<_Slist_node_base*,
allocator<_Slist_node_base*> >;
_STLP_MOVE_TO_STD_NAMESPACE
# endif
# if defined (_STLP_DEBUG)
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _STLP_NON_DBG_NAME(vector)<_Slist_node_base*,
allocator<_Slist_node_base*> >;
_STLP_MOVE_TO_STD_NAMESPACE
# endif
template class _STLP_CLASS_DECLSPEC vector<_STLP_PRIV _Slist_node_base*,
allocator<_STLP_PRIV _Slist_node_base*> >;
//End of hashtable bucket types export.
//Export of _Locale_impl facets container:
# if !defined (_STLP_USE_PTR_SPECIALIZATIONS)
template class _STLP_CLASS_DECLSPEC allocator<locale::facet*>;
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<locale::facet**, locale::facet*, allocator<locale::facet*> >;
template class _STLP_CLASS_DECLSPEC _Vector_base<locale::facet*, allocator<locale::facet*> >;
_STLP_MOVE_TO_STD_NAMESPACE
# endif
# if defined (_STLP_DEBUG)
_STLP_MOVE_TO_PRIV_NAMESPACE
# define _STLP_NON_DBG_VECTOR _STLP_NON_DBG_NAME(vector)
template class _STLP_CLASS_DECLSPEC __construct_checker<_STLP_PRIV _STLP_NON_DBG_VECTOR<locale::facet*, allocator<locale::facet*> > >;
template class _STLP_CLASS_DECLSPEC _STLP_NON_DBG_VECTOR<locale::facet*, allocator<locale::facet*> >;
# undef _STLP_NON_DBG_VECTOR
_STLP_MOVE_TO_STD_NAMESPACE
# endif
template class _STLP_CLASS_DECLSPEC vector<locale::facet*, allocator<locale::facet*> >;
//End of export of _Locale_impl facets container.
# if defined (_STLP_USE_PTR_SPECIALIZATIONS)
template class _STLP_CLASS_DECLSPEC allocator<void*>;
typedef _STLP_PRIV _List_node<void*> _VoidPtr_Node;
template class _STLP_CLASS_DECLSPEC allocator<_VoidPtr_Node>;
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<void**, void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _Vector_base<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _STLP_PTR_IMPL_NAME(vector)<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _List_node<void*>;
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<_List_node_base, _VoidPtr_Node, allocator<_VoidPtr_Node> >;
template class _STLP_CLASS_DECLSPEC _List_base<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _STLP_PTR_IMPL_NAME(list)<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _Slist_node<void*>;
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<_Slist_node_base, _Slist_node<void*>, allocator<_Slist_node<void*> > >;
template class _STLP_CLASS_DECLSPEC _Slist_base<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _STLP_PTR_IMPL_NAME(slist)<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<size_t, void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<void***, void**, allocator<void**> >;
template struct _STLP_CLASS_DECLSPEC _Deque_iterator<void*, _Nonconst_traits<void*> >;
template class _STLP_CLASS_DECLSPEC _Deque_base<void*, allocator<void*> >;
template class _STLP_CLASS_DECLSPEC _STLP_PTR_IMPL_NAME(deque)<void*, allocator<void*> >;
_STLP_MOVE_TO_STD_NAMESPACE
# endif /* _STLP_USE_PTR_SPECIALIZATIONS */
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _Rb_global<bool>;
template class _STLP_CLASS_DECLSPEC _List_global<bool>;
template class _STLP_CLASS_DECLSPEC _Sl_global<bool>;
template class _STLP_CLASS_DECLSPEC _Stl_prime<bool>;
template class _STLP_CLASS_DECLSPEC _LimG<bool>;
_STLP_MOVE_TO_STD_NAMESPACE
#endif /* _STLP_NO_FORCE_INSTANTIATE */
_STLP_END_NAMESPACE
#if defined (_STLP_SIGNAL_RUNTIME_COMPATIBILITY)
extern "C" void _STLP_DECLSPEC _STLP_CALL _STLP_SIGNAL_RUNTIME_COMPATIBILITY() {}
#endif
#define FORCE_SYMBOL extern
#if defined (_WIN32) && defined (_STLP_USE_DECLSPEC) && !defined (_STLP_USE_STATIC_LIB)
// stlportmt.cpp : Defines the entry point for the DLL application.
//
# undef FORCE_SYMBOL
# define FORCE_SYMBOL APIENTRY
extern "C" {
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls((HINSTANCE)hModule);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
} /* extern "C" */
#if !defined (_STLP_MSVC) && !defined (__MINGW32__)
_STLP_BEGIN_NAMESPACE
static void FORCE_SYMBOL
force_link() {
set<int>::iterator iter;
// _M_increment; _M_decrement instantiation
++iter;
--iter;
}
_STLP_END_NAMESPACE
#endif
#endif /* _WIN32 */
#if defined (__ICL) && (__ICL >= 900) && (_STLP_MSVC_LIB < 1300)
# undef std
namespace std
{
void _STLP_CALL unexpected() {
unexpected_handler hdl;
set_unexpected(hdl = set_unexpected((unexpected_handler)0));
hdl();
}
}
#endif

1057
extern/STLport/5.2.1/src/facets_byname.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

114
extern/STLport/5.2.1/src/fstream.cpp vendored Normal file
View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#ifdef _STLP_USE_UNIX_IO
# include "details/fstream_unistd.cpp"
#elif defined(_STLP_USE_STDIO_IO)
# include "details/fstream_stdio.cpp"
#elif defined(_STLP_USE_WIN32_IO)
# include "details/fstream_win32io.cpp"
#else
# error "Can't recognize IO scheme to use"
#endif
_STLP_BEGIN_NAMESPACE
// fbp : let us map 1 MB maximum, just be sure not to trash VM
#define MMAP_CHUNK 0x100000L
_Underflow< char, char_traits<char> >::int_type _STLP_CALL
_Underflow< char, char_traits<char> >::_M_doit(basic_filebuf<char, char_traits<char> >* __this)
{
typedef char_traits<char> traits_type;
typedef traits_type::int_type int_type;
if (!__this->_M_in_input_mode) {
if (!__this->_M_switch_to_input_mode())
return traits_type::eof();
}
else if (__this->_M_in_putback_mode) {
__this->_M_exit_putback_mode();
if (__this->gptr() != __this->egptr()) {
int_type __c = traits_type::to_int_type(*__this->gptr());
return __c;
}
}
// If it's a disk file, and if the internal and external character
// sequences are guaranteed to be identical, then try to use memory
// mapped I/O. Otherwise, revert to ordinary read.
if (__this->_M_base.__regular_file()
&& __this->_M_always_noconv
&& __this->_M_base._M_in_binary_mode()) {
// If we've mmapped part of the file already, then unmap it.
if (__this->_M_mmap_base)
__this->_M_base._M_unmap(__this->_M_mmap_base, __this->_M_mmap_len);
// Determine the position where we start mapping. It has to be
// a multiple of the page size.
streamoff __cur = __this->_M_base._M_seek(0, ios_base::cur);
streamoff __size = __this->_M_base._M_file_size();
if (__size > 0 && __cur >= 0 && __cur < __size) {
streamoff __offset = (__cur / __this->_M_base.__page_size()) * __this->_M_base.__page_size();
streamoff __remainder = __cur - __offset;
__this->_M_mmap_len = __size - __offset;
if (__this->_M_mmap_len > MMAP_CHUNK)
__this->_M_mmap_len = MMAP_CHUNK;
if ((__this->_M_mmap_base = __this->_M_base._M_mmap(__offset, __this->_M_mmap_len)) != 0) {
__this->setg(__STATIC_CAST(char*, __this->_M_mmap_base),
__STATIC_CAST(char*, __this->_M_mmap_base) + __STATIC_CAST(ptrdiff_t, __remainder),
__STATIC_CAST(char*, __this->_M_mmap_base) + __STATIC_CAST(ptrdiff_t, __this->_M_mmap_len));
return traits_type::to_int_type(*__this->gptr());
}
else
__this->_M_mmap_len = 0;
}
else {
__this->_M_mmap_base = 0;
__this->_M_mmap_len = 0;
}
}
return __this->_M_underflow_aux();
}
//----------------------------------------------------------------------
// Force instantiation of filebuf and fstream classes.
#if !defined(_STLP_NO_FORCE_INSTANTIATE)
template class basic_filebuf<char, char_traits<char> >;
template class basic_ifstream<char, char_traits<char> >;
template class basic_ofstream<char, char_traits<char> >;
template class basic_fstream<char, char_traits<char> >;
# if !defined (_STLP_NO_WCHAR_T)
template class _Underflow<wchar_t, char_traits<wchar_t> >;
template class basic_filebuf<wchar_t, char_traits<wchar_t> >;
template class basic_ifstream<wchar_t, char_traits<wchar_t> >;
template class basic_ofstream<wchar_t, char_traits<wchar_t> >;
template class basic_fstream<wchar_t, char_traits<wchar_t> >;
# endif /* _STLP_NO_WCHAR_T */
#endif
_STLP_END_NAMESPACE

318
extern/STLport/5.2.1/src/ios.cpp vendored Normal file
View File

@@ -0,0 +1,318 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <algorithm>
#include <ios>
#include <locale>
#include <ostream> // for __get_ostreambuf definition
#include "aligned_buffer.h"
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// ios_base members
// class ios_base::failure, a subclass of exception. It's used solely
// for reporting errors.
ios_base::failure::failure(const string& s)
: __Named_exception(s)
{}
ios_base::failure::~failure() _STLP_NOTHROW_INHERENTLY {}
#if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION)
// Definitions of ios_base's formatting flags.
const ios_base::fmtflags ios_base::left;
const ios_base::fmtflags ios_base::right;
const ios_base::fmtflags ios_base::internal;
const ios_base::fmtflags ios_base::dec;
const ios_base::fmtflags ios_base::hex;
const ios_base::fmtflags ios_base::oct;
const ios_base::fmtflags ios_base::fixed;
const ios_base::fmtflags ios_base::scientific;
const ios_base::fmtflags ios_base::boolalpha;
const ios_base::fmtflags ios_base::showbase;
const ios_base::fmtflags ios_base::showpoint;
const ios_base::fmtflags ios_base::showpos;
const ios_base::fmtflags ios_base::skipws;
const ios_base::fmtflags ios_base::unitbuf;
const ios_base::fmtflags ios_base::uppercase;
const ios_base::fmtflags ios_base::adjustfield;
const ios_base::fmtflags ios_base::basefield;
const ios_base::fmtflags ios_base::floatfield;
// Definitions of ios_base's state flags.
const ios_base::iostate ios_base::goodbit;
const ios_base::iostate ios_base::badbit;
const ios_base::iostate ios_base::eofbit;
const ios_base::iostate ios_base::failbit;
// Definitions of ios_base's openmode flags.
const ios_base::openmode ios_base::app;
const ios_base::openmode ios_base::ate;
const ios_base::openmode ios_base::binary;
const ios_base::openmode ios_base::in;
const ios_base::openmode ios_base::out;
const ios_base::openmode ios_base::trunc;
// Definitions of ios_base's seekdir flags.
const ios_base::seekdir ios_base::beg;
const ios_base::seekdir ios_base::cur;
const ios_base::seekdir ios_base::end;
#endif
// Internal functions used for managing exponentially-growing arrays of
// POD types.
// array is a pointer to N elements of type PODType. Expands the array,
// if necessary, so that array[index] is meaningful. All new elements are
// initialized to zero. Returns a pointer to the new array, and the new
// size.
template <class PODType>
static pair<PODType*, size_t>
_Stl_expand_array(PODType* __array, size_t N, int index) {
if ((int)N < index + 1) {
size_t new_N = (max)(2 * N, size_t(index + 1));
PODType* new_array
= __STATIC_CAST(PODType*,realloc(__array, new_N * sizeof(PODType)));
if (new_array) {
fill(new_array + N, new_array + new_N, PODType());
return pair<PODType*, size_t>(new_array, new_N);
}
else
return pair<PODType*, size_t>(__STATIC_CAST(PODType*,0), 0);
}
else
return pair<PODType*, size_t>(__array, N);
}
// array is a pointer to N elements of type PODType. Allocate a new
// array of N elements, copying the values from the old array to the new.
// Return a pointer to the new array. It is assumed that array is non-null
// and N is nonzero.
template <class PODType>
static PODType* _Stl_copy_array(const PODType* __array, size_t N) {
PODType* result = __STATIC_CAST(PODType*,malloc(N * sizeof(PODType)));
if (result)
copy(__array, __array + N, result);
return result;
}
locale ios_base::imbue(const locale& loc) {
if (loc != _M_locale) {
locale previous = _M_locale;
_M_locale = loc;
_M_invoke_callbacks(imbue_event);
return previous;
}
else {
_M_invoke_callbacks(imbue_event);
return _M_locale;
}
}
int _STLP_CALL ios_base::xalloc() {
#if defined (_STLP_THREADS) && \
defined (_STLP_WIN32THREADS) && defined (_STLP_NEW_PLATFORM_SDK)
static volatile __stl_atomic_t _S_index = 0;
return _STLP_ATOMIC_INCREMENT(&_S_index);
#else
static int _S_index = 0;
static _STLP_STATIC_MUTEX __lock _STLP_MUTEX_INITIALIZER;
_STLP_auto_lock sentry(__lock);
return _S_index++;
#endif
}
long& ios_base::iword(int index) {
static long dummy = 0;
pair<long*, size_t> tmp = _Stl_expand_array(_M_iwords, _M_num_iwords, index);
if (tmp.first) { // The allocation, if any, succeeded.
_M_iwords = tmp.first;
_M_num_iwords = tmp.second;
return _M_iwords[index];
}
else {
_M_setstate_nothrow(badbit);
_M_check_exception_mask();
return dummy;
}
}
void*& ios_base::pword(int index) {
static void* dummy = 0;
pair<void**, size_t> tmp = _Stl_expand_array(_M_pwords, _M_num_pwords, index);
if (tmp.first) { // The allocation, if any, succeeded.
_M_pwords = tmp.first;
_M_num_pwords = tmp.second;
return _M_pwords[index];
}
else {
_M_setstate_nothrow(badbit);
_M_check_exception_mask();
return dummy;
}
}
void ios_base::register_callback(event_callback __fn, int index) {
pair<pair<event_callback, int>*, size_t> tmp
= _Stl_expand_array(_M_callbacks, _M_num_callbacks, (int)_M_callback_index /* fbp: index ??? */ );
if (tmp.first) {
_M_callbacks = tmp.first;
_M_num_callbacks = tmp.second;
_M_callbacks[_M_callback_index++] = make_pair(__fn, index);
}
else {
_M_setstate_nothrow(badbit);
_M_check_exception_mask();
}
}
// Invokes all currently registered callbacks for a particular event.
// Behaves correctly even if one of the callbacks adds a new callback.
void ios_base::_M_invoke_callbacks(event E) {
for (size_t i = _M_callback_index; i > 0; --i) {
event_callback f = _M_callbacks[i-1].first;
int n = _M_callbacks[i-1].second;
f(E, *this, n);
}
}
// This function is called if the state, rdstate(), has a bit set
// that is also set in the exception mask exceptions().
void ios_base::_M_throw_failure() {
const char* arg ;
# if 0
char buffer[256];
char* ptr;
strcpy(buffer, "ios failure: rdstate = 0x");
ptr = __write_integer(buffer+strlen(buffer), ios_base::hex, __STATIC_CAST(unsigned long,_M_iostate));
strcpy(ptr, " mask = 0x");
ptr = __write_integer(buffer+strlen(buffer), ios_base::hex, __STATIC_CAST(unsigned long,_M_exception_mask));
*ptr = 0;
arg = buffer;
# else
arg = "ios failure";
# endif
# ifndef _STLP_USE_EXCEPTIONS
fputs(arg, stderr);
# else
throw failure(arg);
# endif
}
// Copy x's state to *this. This member function is used in the
// implementation of basic_ios::copyfmt. Does not copy _M_exception_mask
// or _M_iostate.
void ios_base::_M_copy_state(const ios_base& x) {
_M_fmtflags = x._M_fmtflags; // Copy the flags, except for _M_iostate
_M_openmode = x._M_openmode; // and _M_exception_mask.
_M_seekdir = x._M_seekdir;
_M_precision = x._M_precision;
_M_width = x._M_width;
_M_locale = x._M_locale;
if (x._M_callbacks) {
pair<event_callback, int>* tmp = _Stl_copy_array(x._M_callbacks, x._M_callback_index);
if (tmp) {
free(_M_callbacks);
_M_callbacks = tmp;
_M_num_callbacks = _M_callback_index = x._M_callback_index;
}
else {
_M_setstate_nothrow(badbit);
_M_check_exception_mask();
}
}
if (x._M_iwords) {
long* tmp = _Stl_copy_array(x._M_iwords, x._M_num_iwords);
if (tmp) {
free(_M_iwords);
_M_iwords = tmp;
_M_num_iwords = x._M_num_iwords;
}
else {
_M_setstate_nothrow(badbit);
_M_check_exception_mask();
}
}
if (x._M_pwords) {
void** tmp = _Stl_copy_array(x._M_pwords, x._M_num_pwords);
if (tmp) {
free(_M_pwords);
_M_pwords = tmp;
_M_num_pwords = x._M_num_pwords;
}
else {
_M_setstate_nothrow(badbit);
_M_check_exception_mask();
}
}
}
// ios's (protected) default constructor. The standard says that all
// fields have indeterminate values; we initialize them to zero for
// simplicity. The only thing that really matters is that the arrays
// are all initially null pointers, and the array element counts are all
// initially zero.
ios_base::ios_base()
: _M_fmtflags(0), _M_iostate(0), _M_openmode(0), _M_seekdir(0),
_M_exception_mask(0),
_M_precision(0), _M_width(0),
_M_locale(),
_M_callbacks(0), _M_num_callbacks(0), _M_callback_index(0),
_M_iwords(0), _M_num_iwords(0),
_M_pwords(0),
_M_num_pwords(0)
{}
// ios's destructor.
ios_base::~ios_base() {
_M_invoke_callbacks(erase_event);
free(_M_callbacks);
free(_M_iwords);
free(_M_pwords);
}
//----------------------------------------------------------------------
// Force instantiation of basic_ios
// For DLL exports, they are already instantiated.
#if !defined(_STLP_NO_FORCE_INSTANTIATE)
template class _STLP_CLASS_DECLSPEC basic_ios<char, char_traits<char> >;
# if !defined (_STLP_NO_WCHAR_T)
template class _STLP_CLASS_DECLSPEC basic_ios<wchar_t, char_traits<wchar_t> >;
# endif /* _STLP_NO_WCHAR_T */
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

354
extern/STLport/5.2.1/src/iostream.cpp vendored Normal file
View File

@@ -0,0 +1,354 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <memory>
#include <istream>
#include <fstream>
#if defined (_STLP_MSVC) || defined (__MWERKS__) || defined (__ICL) || defined (__ISCPP__)
# define _STLP_USE_NOT_INIT_SEGMENT
# include <iostream>
#endif
#include "stdio_streambuf.h"
#include "aligned_buffer.h"
#include "_stdio_file.h"
#include "c_locale.h"
// boris : note this is repeated in <iostream>
#ifndef _STLP_USE_NAMESPACES
// in case of SGI iostreams, we have to rename our streams not to clash with those
// provided in native lib
# define cin _STLP_cin
# define cout _STLP_cout
# define cerr _STLP_cerr
# define clog _STLP_clog
#endif
_STLP_BEGIN_NAMESPACE
// This file handles iostream initialization. It is inherently
// nonportable, since the C++ language definition provides no mechanism
// for controlling order of initialization of nonlocal objects.
// Initialization has three parts, which must be performed in the following
// order:
// (1) Initialize the locale system
// (2) Call the constructors for the eight global stream objects.
// (3) Create streambufs for the global stream objects, and initialize
// the stream objects by calling the init() member function.
#if defined (_STLP_USE_NOT_INIT_SEGMENT)
// Definitions of the eight global I/O objects that are declared in
// <iostream>. For some compilers we use pragmas to put the global I/O
// objects into an initialization segment that will not
// be executed. We then explicitly invoke the constructors
// with placement new in ios_base::_S_initialize()
# if defined (__MWERKS__)
# pragma suppress_init_code on
# else
# pragma init_seg("STLPORT_NO_INIT")
# endif
_STLP_DECLSPEC istream cin(0);
_STLP_DECLSPEC ostream cout(0);
_STLP_DECLSPEC ostream cerr(0);
_STLP_DECLSPEC ostream clog(0);
# ifndef _STLP_NO_WCHAR_T
_STLP_DECLSPEC wistream wcin(0);
_STLP_DECLSPEC wostream wcout(0);
_STLP_DECLSPEC wostream wcerr(0);
_STLP_DECLSPEC wostream wclog(0);
# endif
# if defined (__MWERKS__)
# pragma suppress_init_code off
# endif
#else
// Definitions of the eight global I/O objects that are declared in
// <iostream>. Disgusting hack: we deliberately define them with the
// wrong types so that the constructors don't get run automatically.
// We need special tricks to make sure that these objects are struct-
// aligned rather than byte-aligned.
// This is not portable. Declaring a variable with different types in
// two translations units is "undefined", according to the C++ standard.
// Most compilers, however, silently accept this instead of diagnosing
// it as an error.
# ifndef __DMC__
_STLP_DECLSPEC _Stl_aligned_buffer<istream> cin;
_STLP_DECLSPEC _Stl_aligned_buffer<ostream> cout;
_STLP_DECLSPEC _Stl_aligned_buffer<ostream> cerr;
_STLP_DECLSPEC _Stl_aligned_buffer<ostream> clog;
# else
_Stl_aligned_buffer<istream> cin;
_Stl_aligned_buffer<ostream> cout;
_Stl_aligned_buffer<ostream> cerr;
_Stl_aligned_buffer<ostream> clog;
# pragma alias("?cin@std@@3V?$basic_istream@std@DV?$char_traits@std@D@1@@1@A", "?cin@std@@3T?$_Stl_aligned_buffer@std@V?$basic_istream@std@DV?$char_traits@std@D@1@@1@@1@A")
# pragma alias("?cout@std@@3V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@A", "?cout@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@@1@A")
# pragma alias("?cerr@std@@3V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@A", "?cerr@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@@1@A")
# pragma alias("?clog@std@@3V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@A", "?clog@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@@1@A")
# endif
# ifndef _STLP_NO_WCHAR_T
# ifndef __DMC__
_STLP_DECLSPEC _Stl_aligned_buffer<wistream> wcin;
_STLP_DECLSPEC _Stl_aligned_buffer<wostream> wcout;
_STLP_DECLSPEC _Stl_aligned_buffer<wostream> wcerr;
_STLP_DECLSPEC _Stl_aligned_buffer<wostream> wclog;
# else
_Stl_aligned_buffer<wistream> wcin;
_Stl_aligned_buffer<wostream> wcout;
_Stl_aligned_buffer<wostream> wcerr;
_Stl_aligned_buffer<wostream> wclog;
# pragma alias("?wcin@std@@3V?$basic_istream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wcin@std@@3T?$_Stl_aligned_buffer@std@V?$basic_istream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
# pragma alias("?wcout@std@@3V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wcout@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
# pragma alias("?wcerr@std@@3V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wcerr@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
# pragma alias("?wclog@std@@3V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wclog@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
# endif
# endif
#endif /* STL_MSVC || __MWERKS__ */
// Member functions from class ios_base and ios_base::Init
long ios_base::Init::_S_count = 0;
// by default, those are synced
bool ios_base::_S_is_synced = true;
ios_base::Init::Init() {
if (_S_count++ == 0) {
_Locale_init();
ios_base::_S_initialize();
_Filebuf_base::_S_initialize();
}
}
ios_base::Init::~Init() {
if (--_S_count == 0) {
ios_base::_S_uninitialize();
_Locale_final();
}
}
static int _Stl_extract_open_param(FILE* f)
{ return _FILE_fd(f); }
#ifdef _STLP_REDIRECT_STDSTREAMS
static const char* _Stl_extract_open_param(const char* name)
{ return name; }
#endif
template <class _Tp>
static filebuf*
_Stl_create_filebuf(_Tp x, ios_base::openmode mode ) {
auto_ptr<filebuf> result(new basic_filebuf<char, char_traits<char> >());
result->open(_Stl_extract_open_param(x), mode);
if (result->is_open())
return result.release();
return 0;
}
#if !defined (_STLP_NO_WCHAR_T)
static wfilebuf*
_Stl_create_wfilebuf(FILE* f, ios_base::openmode mode) {
auto_ptr<wfilebuf> result(new basic_filebuf<wchar_t, char_traits<wchar_t> >());
result->_M_open(_FILE_fd(f), mode);
if (result->is_open())
return result.release();
return 0;
}
#endif
void _STLP_CALL ios_base::_S_initialize() {
#if !defined (_STLP_HAS_NO_NAMESPACES) && !defined (_STLP_DONT_USE_PRIV_NAMESPACE)
using _STLP_PRIV stdio_istreambuf;
using _STLP_PRIV stdio_ostreambuf;
#endif
auto_ptr<streambuf> cin_buf;
auto_ptr<streambuf> cout_buf;
auto_ptr<streambuf> cerr_buf;
auto_ptr<streambuf> clog_buf;
if (_S_is_synced)
cin_buf.reset(new stdio_istreambuf(stdin));
else
cin_buf.reset(_Stl_create_filebuf(stdin, ios_base::in));
if (_S_is_synced) {
#ifdef _STLP_REDIRECT_STDSTREAMS
cout_buf.reset(_Stl_create_filebuf("/stdout.txt", ios::out));
cerr_buf.reset(_Stl_create_filebuf("/stderr.txt", ios::out));
clog_buf.reset(_Stl_create_filebuf("/stdlog.txt", ios::out));
#else
cout_buf.reset(new stdio_ostreambuf(stdout));
cerr_buf.reset(new stdio_ostreambuf(stderr));
clog_buf.reset(new stdio_ostreambuf(stderr));
#endif
}
else {
cout_buf.reset(_Stl_create_filebuf(stdout, ios_base::out));
cerr_buf.reset(_Stl_create_filebuf(stderr, ios_base::out));
clog_buf.reset(_Stl_create_filebuf(stderr, ios_base::out));
}
istream* ptr_cin = new(&cin) istream(cin_buf.get()); cin_buf.release();
ostream* ptr_cout = new(&cout) ostream(cout_buf.get()); cout_buf.release();
ostream* ptr_cerr = new(&cerr) ostream(cerr_buf.get()); cerr_buf.release();
/*ostream* ptr_clog = */ new(&clog) ostream(clog_buf.get()); clog_buf.release();
ptr_cin->tie(ptr_cout);
ptr_cerr->setf(ios_base::unitbuf);
#ifndef _STLP_NO_WCHAR_T
auto_ptr<wfilebuf> win(_Stl_create_wfilebuf(stdin, ios_base::in));
auto_ptr<wfilebuf> wout(_Stl_create_wfilebuf(stdout, ios_base::out));
auto_ptr<wfilebuf> werr(_Stl_create_wfilebuf(stderr, ios_base::out));
auto_ptr<wfilebuf> wlog(_Stl_create_wfilebuf(stderr, ios_base::out));
// Run constructors for the four wide stream objects.
wistream* ptr_wcin = new(&wcin) wistream(win.get()); win.release();
wostream* ptr_wcout = new(&wcout) wostream(wout.get()); wout.release();
wostream* ptr_wcerr = new(&wcerr) wostream(werr.get()); werr.release();
/*wostream* ptr_wclog = */ new(&wclog) wostream(wlog.get()); wlog.release();
ptr_wcin->tie(ptr_wcout);
ptr_wcerr->setf(ios_base::unitbuf);
#endif
}
void _STLP_CALL ios_base::_S_uninitialize() {
// Note that destroying output streambufs flushes the buffers.
istream* ptr_cin = &cin;
ostream* ptr_cout = &cout;
ostream* ptr_cerr = &cerr;
ostream* ptr_clog = &clog;
// We don't want any exceptions being thrown here
ptr_cin->exceptions(0);
ptr_cout->exceptions(0);
ptr_cerr->exceptions(0);
ptr_clog->exceptions(0);
delete ptr_cin->rdbuf(0);
delete ptr_cout->rdbuf(0);
delete ptr_cerr->rdbuf(0);
delete ptr_clog->rdbuf(0);
_Destroy(ptr_cin);
_Destroy(ptr_cout);
_Destroy(ptr_cerr);
_Destroy(ptr_clog);
#ifndef _STLP_NO_WCHAR_T
wistream* ptr_wcin = &wcin;
wostream* ptr_wcout = &wcout;
wostream* ptr_wcerr = &wcerr;
wostream* ptr_wclog = &wclog;
// We don't want any exceptions being thrown here
ptr_wcin->exceptions(0);
ptr_wcout->exceptions(0);
ptr_wcerr->exceptions(0);
ptr_wclog->exceptions(0);
delete ptr_wcin->rdbuf(0);
delete ptr_wcout->rdbuf(0);
delete ptr_wcerr->rdbuf(0);
delete ptr_wclog->rdbuf(0);
_Destroy(ptr_wcin);
_Destroy(ptr_wcout);
_Destroy(ptr_wcerr);
_Destroy(ptr_wclog);
#endif
}
bool _STLP_CALL ios_base::sync_with_stdio(bool sync) {
# if !defined (_STLP_HAS_NO_NAMESPACES) && !defined (_STLP_DONT_USE_PRIV_NAMESPACE)
using _STLP_PRIV stdio_istreambuf;
using _STLP_PRIV stdio_ostreambuf;
# endif
if (sync == _S_is_synced) return sync;
// if by any chance we got there before std streams initialization,
// just set the sync flag and exit
if (Init::_S_count == 0) {
_S_is_synced = sync;
return sync;
}
auto_ptr<streambuf> cin_buf;
auto_ptr<streambuf> cout_buf;
auto_ptr<streambuf> cerr_buf;
auto_ptr<streambuf> clog_buf;
if (sync)
cin_buf.reset(new stdio_istreambuf(stdin));
else
cin_buf.reset(_Stl_create_filebuf(stdin, ios_base::in));
if (sync) {
#ifdef _STLP_REDIRECT_STDSTREAMS
cout_buf.reset(_Stl_create_filebuf("/stdout.txt", ios::out));
cerr_buf.reset(_Stl_create_filebuf("/stderr.txt", ios::out));
clog_buf.reset(_Stl_create_filebuf("/stdlog.txt", ios::out));
#else
cout_buf.reset(new stdio_ostreambuf(stdout));
cerr_buf.reset(new stdio_ostreambuf(stderr));
clog_buf.reset(new stdio_ostreambuf(stderr));
#endif
}
else {
cout_buf.reset(_Stl_create_filebuf(stdout, ios_base::out));
cerr_buf.reset(_Stl_create_filebuf(stderr, ios_base::out));
clog_buf.reset(_Stl_create_filebuf(stderr, ios_base::out));
}
if (cin_buf.get() != 0 && cout_buf.get() != 0 && cerr_buf.get() != 0 && clog_buf.get() != 0) {
// When streambuf passed to rdbuf is not null, rdbuf is exception safe:
delete (&cin)->rdbuf(cin_buf.release());
delete (&cout)->rdbuf(cout_buf.release());
delete (&cerr)->rdbuf(cerr_buf.release());
delete (&clog)->rdbuf(clog_buf.release());
_S_is_synced = sync;
}
return _S_is_synced;
}
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

48
extern/STLport/5.2.1/src/istream.cpp vendored Normal file
View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
# include "stlport_prefix.h"
#include <istream>
_STLP_BEGIN_NAMESPACE
#if !defined(_STLP_NO_FORCE_INSTANTIATE)
// instantiations
# if defined (_STLP_USE_TEMPLATE_EXPORT)
template class _STLP_CLASS_DECLSPEC _Isentry<char, char_traits<char> >;
# endif
template class _STLP_CLASS_DECLSPEC basic_iostream<char, char_traits<char> >;
template class _STLP_CLASS_DECLSPEC basic_istream<char, char_traits<char> >;
# if !defined (_STLP_NO_WCHAR_T)
# if defined (_STLP_USE_TEMPLATE_EXPORT)
template class _STLP_CLASS_DECLSPEC _Isentry<wchar_t, char_traits<wchar_t> >;
# endif
template class _STLP_CLASS_DECLSPEC basic_istream<wchar_t, char_traits<wchar_t> >;
template class _STLP_CLASS_DECLSPEC basic_iostream<wchar_t, char_traits<wchar_t> >;
# endif /* !_STLP_NO_WCHAR_T */
#endif /* _STLP_NO_FORCE_INSTANTIATE */
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

445
extern/STLport/5.2.1/src/locale.cpp vendored Normal file
View File

@@ -0,0 +1,445 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
#include <stdexcept>
#include "c_locale.h"
#include "locale_impl.h"
_STLP_BEGIN_NAMESPACE
static const string _Nameless("*");
static inline bool is_C_locale_name (const char* name)
{ return ((name[0] == 'C') && (name[1] == 0)); }
locale* _Stl_get_classic_locale();
locale* _Stl_get_global_locale();
#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) || \
defined (_STLP_SIGNAL_RUNTIME_COMPATIBILITY) || defined (_STLP_CHECK_RUNTIME_COMPATIBILITY)
# define locale _STLP_NO_MEM_T_NAME(loc)
#endif
locale::facet::~facet() {}
#if !defined (_STLP_MEMBER_TEMPLATES) || defined (_STLP_INLINE_MEMBER_TEMPLATES)
// members that fail to be templates
bool locale::operator()(const string& __x,
const string& __y) const
{ return __locale_do_operator_call(*this, __x, __y); }
# if !defined (_STLP_NO_WCHAR_T)
bool locale::operator()(const wstring& __x,
const wstring& __y) const
{ return __locale_do_operator_call(*this, __x, __y); }
# endif
#endif
void _STLP_CALL locale::_M_throw_on_null_name()
{ _STLP_THROW(runtime_error("Invalid null locale name")); }
void _STLP_CALL locale::_M_throw_on_combine_error(const string& name) {
string what = "Unable to find facet";
what += " in ";
what += name.empty() ? "system" : name.c_str();
what += " locale";
_STLP_THROW(runtime_error(what.c_str()));
}
void _STLP_CALL locale::_M_throw_on_creation_failure(int __err_code,
const char* name, const char* facet) {
string what;
switch (__err_code) {
case _STLP_LOC_UNSUPPORTED_FACET_CATEGORY:
what = "No platform localization support for ";
what += facet;
what += " facet category, unable to create facet for ";
what += name[0] == 0 ? "system" : name;
what += " locale";
break;
case _STLP_LOC_NO_PLATFORM_SUPPORT:
what = "No platform localization support, unable to create ";
what += name[0] == 0 ? "system" : name;
what += " locale";
break;
default:
case _STLP_LOC_UNKNOWN_NAME:
what = "Unable to create facet ";
what += facet;
what += " from name '";
what += name;
what += "'";
break;
case _STLP_LOC_NO_MEMORY:
_STLP_THROW_BAD_ALLOC;
break;
}
_STLP_THROW(runtime_error(what.c_str()));
}
// Takes a reference to a locale::id, assign a numeric index if not already
// affected and returns it. The returned index is always positive.
static const locale::id& _Stl_loc_get_index(locale::id& id) {
if (id._M_index == 0) {
#if defined (_STLP_ATOMIC_INCREMENT) && !defined (_STLP_WIN95_LIKE)
static _STLP_VOLATILE __stl_atomic_t _S_index = __STATIC_CAST(__stl_atomic_t, locale::id::_S_max);
id._M_index = _STLP_ATOMIC_INCREMENT(&_S_index);
#else
static _STLP_STATIC_MUTEX _Index_lock _STLP_MUTEX_INITIALIZER;
_STLP_auto_lock sentry(_Index_lock);
size_t new_index = locale::id::_S_max++;
id._M_index = new_index;
#endif
}
return id;
}
// Default constructor: create a copy of the global locale.
locale::locale() _STLP_NOTHROW
: _M_impl(_get_Locale_impl(_Stl_get_global_locale()->_M_impl))
{}
// Copy constructor
locale::locale(const locale& L) _STLP_NOTHROW
: _M_impl( _get_Locale_impl( L._M_impl ) )
{}
void locale::_M_insert(facet* f, locale::id& n) {
if (f)
_M_impl->insert(f, _Stl_loc_get_index(n));
}
locale::locale( _Locale_impl* impl ) :
_M_impl( _get_Locale_impl( impl ) )
{}
// Create a locale from a name.
locale::locale(const char* name)
: _M_impl(0) {
if (!name)
_M_throw_on_null_name();
if (is_C_locale_name(name)) {
_M_impl = _get_Locale_impl( locale::classic()._M_impl );
return;
}
_Locale_impl* impl = 0;
_STLP_TRY {
impl = new _Locale_impl(locale::id::_S_max, name);
// Insert categories one at a time.
_Locale_name_hint *hint = 0;
const char* ctype_name = name;
char ctype_buf[_Locale_MAX_SIMPLE_NAME];
const char* numeric_name = name;
char numeric_buf[_Locale_MAX_SIMPLE_NAME];
const char* time_name = name;
char time_buf[_Locale_MAX_SIMPLE_NAME];
const char* collate_name = name;
char collate_buf[_Locale_MAX_SIMPLE_NAME];
const char* monetary_name = name;
char monetary_buf[_Locale_MAX_SIMPLE_NAME];
const char* messages_name = name;
char messages_buf[_Locale_MAX_SIMPLE_NAME];
hint = impl->insert_ctype_facets(ctype_name, ctype_buf, hint);
hint = impl->insert_numeric_facets(numeric_name, numeric_buf, hint);
hint = impl->insert_time_facets(time_name, time_buf, hint);
hint = impl->insert_collate_facets(collate_name, collate_buf, hint);
hint = impl->insert_monetary_facets(monetary_name, monetary_buf, hint);
impl->insert_messages_facets(messages_name, messages_buf, hint);
// Try to use a normalize locale name in order to have the == operator
// to behave correctly:
if (strcmp(ctype_name, numeric_name) == 0 &&
strcmp(ctype_name, time_name) == 0 &&
strcmp(ctype_name, collate_name) == 0 &&
strcmp(ctype_name, monetary_name) == 0 &&
strcmp(ctype_name, messages_name) == 0) {
impl->name = ctype_name;
}
// else we keep current name.
// reassign impl
_M_impl = _get_Locale_impl( impl );
}
_STLP_UNWIND(delete impl);
}
static void _Stl_loc_combine_names_aux(_Locale_impl* L,
const char* name,
const char* ctype_name, const char* time_name, const char* numeric_name,
const char* collate_name, const char* monetary_name, const char* messages_name,
locale::category c) {
// This function is only called when names has been validated so using _Locale_extract_*_name
// can't fail.
int __err_code;
char buf[_Locale_MAX_SIMPLE_NAME];
L->name = string("LC_CTYPE=") + _Locale_extract_ctype_name((c & locale::ctype) ? ctype_name : name, buf, 0, &__err_code) + ";";
L->name += string("LC_TIME=") + _Locale_extract_time_name((c & locale::time) ? time_name : name, buf, 0, &__err_code) + ";";
L->name += string("LC_NUMERIC=") + _Locale_extract_numeric_name((c & locale::numeric) ? numeric_name : name, buf, 0, &__err_code) + ";";
L->name += string("LC_COLLATE=") + _Locale_extract_collate_name((c & locale::collate) ? collate_name : name, buf, 0, &__err_code) + ";";
L->name += string("LC_MONETARY=") + _Locale_extract_monetary_name((c & locale::monetary) ? monetary_name : name, buf, 0, &__err_code) + ";";
L->name += string("LC_MESSAGES=") + _Locale_extract_messages_name((c & locale::messages) ? messages_name : name, buf, 0, &__err_code);
}
// Give L a name where all facets except those in category c
// are taken from name1, and those in category c are taken from name2.
static void _Stl_loc_combine_names(_Locale_impl* L,
const char* name1, const char* name2,
locale::category c) {
if ((c & locale::all) == 0 || strcmp(name1, name1) == 0)
L->name = name1;
else if ((c & locale::all) == locale::all)
L->name = name2;
else {
_Stl_loc_combine_names_aux(L, name1, name2, name2, name2, name2, name2, name2, c);
}
}
static void _Stl_loc_combine_names(_Locale_impl* L,
const char* name,
const char* ctype_name, const char* time_name, const char* numeric_name,
const char* collate_name, const char* monetary_name, const char* messages_name,
locale::category c) {
if ((c & locale::all) == 0 || (strcmp(name, ctype_name) == 0 &&
strcmp(name, time_name) == 0 &&
strcmp(name, numeric_name) == 0 &&
strcmp(name, collate_name) == 0 &&
strcmp(name, monetary_name) == 0 &&
strcmp(name, messages_name) == 0))
L->name = name;
else if ((c & locale::all) == locale::all && strcmp(ctype_name, time_name) == 0 &&
strcmp(ctype_name, numeric_name) == 0 &&
strcmp(ctype_name, collate_name) == 0 &&
strcmp(ctype_name, monetary_name) == 0 &&
strcmp(ctype_name, messages_name) == 0)
L->name = ctype_name;
else {
_Stl_loc_combine_names_aux(L, name, ctype_name, time_name, numeric_name, collate_name, monetary_name, messages_name, c);
}
}
// Create a locale that's a copy of L, except that all of the facets
// in category c are instead constructed by name.
locale::locale(const locale& L, const char* name, locale::category c)
: _M_impl(0) {
if (!name)
_M_throw_on_null_name();
if (_Nameless == name)
_STLP_THROW(runtime_error((string("Invalid locale name '") + _Nameless + "'").c_str()));
_Locale_impl* impl = 0;
_STLP_TRY {
impl = new _Locale_impl(*L._M_impl);
_Locale_name_hint *hint = 0;
const char* ctype_name = name;
char ctype_buf[_Locale_MAX_SIMPLE_NAME];
const char* numeric_name = name;
char numeric_buf[_Locale_MAX_SIMPLE_NAME];
const char* time_name = name;
char time_buf[_Locale_MAX_SIMPLE_NAME];
const char* collate_name = name;
char collate_buf[_Locale_MAX_SIMPLE_NAME];
const char* monetary_name = name;
char monetary_buf[_Locale_MAX_SIMPLE_NAME];
const char* messages_name = name;
char messages_buf[_Locale_MAX_SIMPLE_NAME];
if (c & locale::ctype)
hint = impl->insert_ctype_facets(ctype_name, ctype_buf, hint);
if (c & locale::numeric)
hint = impl->insert_numeric_facets(numeric_name, numeric_buf, hint);
if (c & locale::time)
hint = impl->insert_time_facets(time_name, time_buf, hint);
if (c & locale::collate)
hint = impl->insert_collate_facets(collate_name, collate_buf, hint);
if (c & locale::monetary)
hint = impl->insert_monetary_facets(monetary_name, monetary_buf,hint);
if (c & locale::messages)
impl->insert_messages_facets(messages_name, messages_buf, hint);
_Stl_loc_combine_names(impl, L._M_impl->name.c_str(),
ctype_name, time_name, numeric_name,
collate_name, monetary_name, messages_name, c);
_M_impl = _get_Locale_impl( impl );
}
_STLP_UNWIND(delete impl)
}
// Contruct a new locale where all facets that aren't in category c
// come from L1, and all those that are in category c come from L2.
locale::locale(const locale& L1, const locale& L2, category c)
: _M_impl(0) {
_Locale_impl* impl = new _Locale_impl(*L1._M_impl);
_Locale_impl* i2 = L2._M_impl;
if (L1.name() != _Nameless && L2.name() != _Nameless)
_Stl_loc_combine_names(impl, L1._M_impl->name.c_str(), L2._M_impl->name.c_str(), c);
else {
impl->name = _Nameless;
}
if (c & collate) {
impl->insert( i2, _STLP_STD::collate<char>::id);
# ifndef _STLP_NO_WCHAR_T
impl->insert( i2, _STLP_STD::collate<wchar_t>::id);
# endif
}
if (c & ctype) {
impl->insert( i2, _STLP_STD::ctype<char>::id);
impl->insert( i2, _STLP_STD::codecvt<char, char, mbstate_t>::id);
# ifndef _STLP_NO_WCHAR_T
impl->insert( i2, _STLP_STD::ctype<wchar_t>::id);
impl->insert( i2, _STLP_STD::codecvt<wchar_t, char, mbstate_t>::id);
# endif
}
if (c & monetary) {
impl->insert( i2, _STLP_STD::moneypunct<char, true>::id);
impl->insert( i2, _STLP_STD::moneypunct<char, false>::id);
impl->insert( i2, _STLP_STD::money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
impl->insert( i2, _STLP_STD::money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
# ifndef _STLP_NO_WCHAR_T
impl->insert( i2, _STLP_STD::moneypunct<wchar_t, true>::id);
impl->insert( i2, _STLP_STD::moneypunct<wchar_t, false>::id);
impl->insert( i2, _STLP_STD::money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
impl->insert( i2, _STLP_STD::money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
# endif
}
if (c & numeric) {
impl->insert( i2, _STLP_STD::numpunct<char>::id);
impl->insert( i2, _STLP_STD::num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
impl->insert( i2, _STLP_STD::num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
# ifndef _STLP_NO_WCHAR_T
impl->insert( i2, _STLP_STD::numpunct<wchar_t>::id);
impl->insert( i2, _STLP_STD::num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
impl->insert( i2, _STLP_STD::num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
# endif
}
if (c & time) {
impl->insert( i2, _STLP_STD::time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
impl->insert( i2, _STLP_STD::time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
# ifndef _STLP_NO_WCHAR_T
impl->insert( i2, _STLP_STD::time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
impl->insert( i2, _STLP_STD::time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
# endif
}
if (c & messages) {
impl->insert( i2, _STLP_STD::messages<char>::id);
# ifndef _STLP_NO_WCHAR_T
impl->insert( i2, _STLP_STD::messages<wchar_t>::id);
# endif
}
_M_impl = _get_Locale_impl( impl );
}
// Destructor.
locale::~locale() _STLP_NOTHROW {
if (_M_impl)
_release_Locale_impl(_M_impl);
}
// Assignment operator. Much like the copy constructor: just a bit of
// pointer twiddling.
const locale& locale::operator=(const locale& L) _STLP_NOTHROW {
if (this->_M_impl != L._M_impl) {
if (this->_M_impl)
_release_Locale_impl(this->_M_impl);
this->_M_impl = _get_Locale_impl(L._M_impl);
}
return *this;
}
locale::facet* locale::_M_get_facet(const locale::id& n) const {
return n._M_index < _M_impl->size() ? _M_impl->facets_vec[n._M_index] : 0;
}
locale::facet* locale::_M_use_facet(const locale::id& n) const {
locale::facet* f = (n._M_index < _M_impl->size() ? _M_impl->facets_vec[n._M_index] : 0);
if (!f)
_M_impl->_M_throw_bad_cast();
return f;
}
string locale::name() const {
return _M_impl->name;
}
// Compare two locales for equality.
bool locale::operator==(const locale& L) const {
return this->_M_impl == L._M_impl ||
(this->name() == L.name() && this->name() != _Nameless);
}
bool locale::operator!=(const locale& L) const {
return !(*this == L);
}
// static data members.
const locale& _STLP_CALL locale::classic() {
return *_Stl_get_classic_locale();
}
#if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
locale _STLP_CALL locale::global(const locale& L) {
#else
_Locale_impl* _STLP_CALL locale::global(const locale& L) {
#endif
locale old(_Stl_get_global_locale()->_M_impl);
if (_Stl_get_global_locale()->_M_impl != L._M_impl) {
_release_Locale_impl(_Stl_get_global_locale()->_M_impl);
// this assign should be atomic, should be fixed here:
_Stl_get_global_locale()->_M_impl = _get_Locale_impl(L._M_impl);
// Set the global C locale, if appropriate.
#if !defined(_STLP_NO_LOCALE_SUPPORT)
if (L.name() != _Nameless)
setlocale(LC_ALL, L.name().c_str());
#endif
}
#if !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
return old;
#else
return old._M_impl;
#endif
}
#if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION)
const locale::category locale::none;
const locale::category locale::collate;
const locale::category locale::ctype;
const locale::category locale::monetary;
const locale::category locale::numeric;
const locale::category locale::time;
const locale::category locale::messages;
const locale::category locale::all;
#endif
_STLP_END_NAMESPACE

View File

@@ -0,0 +1,288 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <hash_map>
#include <string>
#include <locale>
#include <istream>
#include "c_locale.h"
#include "locale_impl.h"
#include "acquire_release.h"
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// Those wrappers are needed to use locale functions in __acquire_category,
// all functions have to present the same prototype.
static void* _Loc_ctype_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_ctype_create(s, hint, __err_code); }
static void* _Loc_codecvt_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_codecvt_create(s, hint, __err_code); }
static void* _Loc_numeric_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_numeric_create(s, hint, __err_code); }
static void* _Loc_time_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_time_create(s, hint, __err_code); }
static void* _Loc_collate_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_collate_create(s, hint, __err_code); }
static void* _Loc_monetary_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_monetary_create(s, hint, __err_code); }
static void* _Loc_messages_create(const char * s, _Locale_name_hint* hint, int *__err_code)
{ return _Locale_messages_create(s, hint, __err_code); }
static char const* _Loc_ctype_name(void* l, char* s)
{ return _Locale_ctype_name((_Locale_ctype*)l, s); }
static char const* _Loc_codecvt_name(void* l, char* s)
{ return _Locale_codecvt_name((_Locale_codecvt*)l, s); }
static char const* _Loc_numeric_name(void* l, char* s)
{ return _Locale_numeric_name((_Locale_numeric*)l, s); }
static char const* _Loc_time_name(void* l, char* s)
{ return _Locale_time_name((_Locale_time*)l, s); }
static char const* _Loc_collate_name(void* l, char* s)
{ return _Locale_collate_name((_Locale_collate*)l, s); }
static char const* _Loc_monetary_name(void* l, char* s)
{ return _Locale_monetary_name((_Locale_monetary*)l, s); }
static char const* _Loc_messages_name(void* l, char* s)
{ return _Locale_messages_name((_Locale_messages*)l, s); }
static const char* _Loc_ctype_default(char* p)
{ return _Locale_ctype_default(p); }
static const char* _Loc_numeric_default(char * p)
{ return _Locale_numeric_default(p); }
static const char* _Loc_time_default(char* p)
{ return _Locale_time_default(p); }
static const char* _Loc_collate_default(char* p)
{ return _Locale_collate_default(p); }
static const char* _Loc_monetary_default(char* p)
{ return _Locale_monetary_default(p); }
static const char* _Loc_messages_default(char* p)
{ return _Locale_messages_default(p); }
static void _Loc_ctype_destroy(void* p) {_Locale_ctype_destroy((_Locale_ctype*)p); }
static void _Loc_codecvt_destroy(void* p) {_Locale_codecvt_destroy((_Locale_codecvt*)p); }
static void _Loc_numeric_destroy(void* p) {_Locale_numeric_destroy((_Locale_numeric*)p); }
static void _Loc_time_destroy(void* p) {_Locale_time_destroy((_Locale_time*)p);}
static void _Loc_collate_destroy(void* p) {_Locale_collate_destroy((_Locale_collate*)p);}
static void _Loc_monetary_destroy(void* p) {_Locale_monetary_destroy((_Locale_monetary*)p);}
static void _Loc_messages_destroy(void* p) {_Locale_messages_destroy((_Locale_messages*)p);}
typedef void* (*loc_create_func_t)(const char *, _Locale_name_hint*, int *__err_code);
typedef char const* (*loc_name_func_t)(void* l, char* s);
typedef void (*loc_destroy_func_t)(void* l);
typedef const char* (*loc_default_name_func_t)(char* s);
typedef char const* (*loc_extract_name_func_t)(const char*, char*, _Locale_name_hint*, int *__err_code);
//----------------------------------------------------------------------
// Acquire and release low-level category objects. The whole point of
// this is so that we don't allocate (say) four different _Locale_ctype
// objects for a single locale.
// Global hash tables for category objects.
typedef hash_map<string, pair<void*, size_t>, hash<string>, equal_to<string> > Category_Map;
// Look up a category by name
static Category_Map** ctype_hash() {
static Category_Map *_S_ctype_hash = 0;
return &_S_ctype_hash;
}
static Category_Map** codecvt_hash() {
static Category_Map *_S_codecvt_hash = 0;
return &_S_codecvt_hash;
}
static Category_Map** numeric_hash() {
static Category_Map *_S_numeric_hash = 0;
return &_S_numeric_hash;
}
static Category_Map** time_hash() {
static Category_Map *_S_time_hash = 0;
return &_S_time_hash;
}
static Category_Map** collate_hash() {
static Category_Map *_S_collate_hash = 0;
return &_S_collate_hash;
}
static Category_Map** monetary_hash() {
static Category_Map *_S_monetary_hash = 0;
return &_S_monetary_hash;
}
static Category_Map** messages_hash() {
static Category_Map *_S_messages_hash;
return &_S_messages_hash;
}
// We have a single lock for all of the hash tables. We may wish to
// replace it with six different locks.
/* REFERENCED */
static _STLP_STATIC_MUTEX& category_hash_mutex() {
static _STLP_STATIC_MUTEX lock _STLP_MUTEX_INITIALIZER;
return lock;
}
static void*
__acquire_category(const char* &name, char *buf, _Locale_name_hint* hint,
loc_extract_name_func_t extract_name,
loc_create_func_t create_obj, loc_default_name_func_t default_name,
Category_Map ** M, int *__err_code) {
#if !defined (__BORLANDC__) || (__BORLANDC__ >= 0x564)
typedef Category_Map::iterator Category_iterator;
pair<Category_iterator, bool> result;
#else
# if !defined(_STLP_DEBUG)
pair<_Ht_iterator<_Slist_iterator<pair<const string,pair<void *,unsigned int> >,_Nonconst_traits<pair<const string,pair<void *,unsigned int> > > >,_NonLocalHashMapTraitsT<pair<const string,pair<void *,unsigned int> > > >, bool> result;
# else
pair<_DBG_iter<_NonDbg_hashtable<pair<const string,pair<void *,unsigned int> >,string,hash<string>,_HashMapTraitsT<pair<const string,pair<void *,unsigned int> > >,_Select1st<pair<const string,pair<void *,unsigned int> > >,_DbgEqual<string,equal_to<string> >,allocator<pair<const string,pair<void *,unsigned int> > > >,_DbgTraits<_NonLocalHashMapTraitsT<pair<const string,pair<void *,unsigned int> > > > >, bool> result;
# endif
#endif
*__err_code = _STLP_LOC_UNDEFINED;
// Find what name to look for. Be careful if user requests the default.
if (name[0] == 0) {
name = default_name(buf);
if (name == 0 || name[0] == 0)
name = "C";
}
else {
const char* cname = extract_name(name, buf, hint, __err_code);
if (cname == 0) {
return 0;
}
name = cname;
}
Category_Map::value_type __e(name, pair<void*,size_t>((void*)0,size_t(0)));
_STLP_auto_lock sentry(category_hash_mutex());
if (!*M)
*M = new Category_Map();
// Look for an existing entry with that name.
result = (*M)->insert_noresize(__e);
if (result.second) {
// There was no entry in the map already. Create the category.
(*result.first).second.first = create_obj(name, hint, __err_code);
if (!(*result.first).second.first) {
(*M)->erase(result.first);
#if defined (_STLP_LEAKS_PEDANTIC)
if ((*M)->empty()) {
delete *M;
*M = 0;
}
#endif
return 0;
}
}
// Increment the reference count.
++((*result.first).second.second);
return (*result.first).second.first;
}
static void
__release_category(void* cat,
loc_destroy_func_t destroy_fun,
loc_name_func_t get_name,
Category_Map** M) {
Category_Map *pM = *M;
if (cat && pM) {
// Find the name of the category object.
char buf[_Locale_MAX_SIMPLE_NAME + 1];
char const* name = get_name(cat, buf);
if (name != 0) {
_STLP_auto_lock sentry(category_hash_mutex());
Category_Map::iterator it = pM->find(name);
if (it != pM->end()) {
// Decrement the ref count. If it goes to zero, delete this category
// from the map.
if (--((*it).second.second) == 0) {
void* cat1 = (*it).second.first;
destroy_fun(cat1);
pM->erase(it);
#if defined (_STLP_LEAKS_PEDANTIC)
if (pM->empty()) {
delete pM;
*M = 0;
}
#endif
}
}
}
}
}
_Locale_ctype* _STLP_CALL __acquire_ctype(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_ctype*, __acquire_category(name, buf, hint,
_Locale_extract_ctype_name, _Loc_ctype_create, _Loc_ctype_default,
ctype_hash(), __err_code));
}
_Locale_codecvt* _STLP_CALL __acquire_codecvt(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_codecvt*, __acquire_category(name, buf, hint,
_Locale_extract_ctype_name, _Loc_codecvt_create, _Loc_ctype_default,
codecvt_hash(), __err_code));
}
_Locale_numeric* _STLP_CALL __acquire_numeric(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_numeric*, __acquire_category(name, buf, hint,
_Locale_extract_numeric_name, _Loc_numeric_create, _Loc_numeric_default,
numeric_hash(), __err_code));
}
_Locale_time* _STLP_CALL __acquire_time(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_time*, __acquire_category(name, buf, hint,
_Locale_extract_time_name, _Loc_time_create, _Loc_time_default,
time_hash(), __err_code));
}
_Locale_collate* _STLP_CALL __acquire_collate(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_collate*, __acquire_category(name, buf, hint,
_Locale_extract_collate_name, _Loc_collate_create, _Loc_collate_default,
collate_hash(), __err_code));
}
_Locale_monetary* _STLP_CALL __acquire_monetary(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_monetary*, __acquire_category(name, buf, hint,
_Locale_extract_monetary_name, _Loc_monetary_create, _Loc_monetary_default,
monetary_hash(), __err_code));
}
_Locale_messages* _STLP_CALL __acquire_messages(const char* &name, char *buf, _Locale_name_hint* hint, int *__err_code) {
return __REINTERPRET_CAST(_Locale_messages*, __acquire_category(name, buf, hint,
_Locale_extract_messages_name, _Loc_messages_create, _Loc_messages_default,
messages_hash(), __err_code));
}
void _STLP_CALL __release_ctype(_Locale_ctype* cat)
{ __release_category(cat, _Loc_ctype_destroy, _Loc_ctype_name, ctype_hash()); }
void _STLP_CALL __release_codecvt(_Locale_codecvt* cat)
{ __release_category(cat, _Loc_codecvt_destroy, _Loc_codecvt_name, codecvt_hash()); }
void _STLP_CALL __release_numeric(_Locale_numeric* cat)
{ __release_category(cat, _Loc_numeric_destroy, _Loc_numeric_name, numeric_hash()); }
void _STLP_CALL __release_time(_Locale_time* cat)
{ __release_category(cat, _Loc_time_destroy, _Loc_time_name, time_hash()); }
void _STLP_CALL __release_collate(_Locale_collate* cat)
{ __release_category(cat, _Loc_collate_destroy, _Loc_collate_name, collate_hash()); }
void _STLP_CALL __release_monetary(_Locale_monetary* cat)
{ __release_category(cat, _Loc_monetary_destroy, _Loc_monetary_name, monetary_hash()); }
void _STLP_CALL __release_messages(_Locale_messages* cat)
{ __release_category(cat, _Loc_messages_destroy, _Loc_messages_name, messages_hash()); }
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE

765
extern/STLport/5.2.1/src/locale_impl.cpp vendored Normal file
View File

@@ -0,0 +1,765 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
#include <algorithm>
#include <typeinfo>
#include "c_locale.h"
#include "aligned_buffer.h"
#include "acquire_release.h"
#include "locale_impl.h"
_STLP_BEGIN_NAMESPACE
static const string _Nameless("*");
static inline bool is_C_locale_name (const char* name)
{ return ((name[0] == 'C') && (name[1] == 0)); }
locale::facet * _STLP_CALL _get_facet(locale::facet *f)
{
if (f != 0)
f->_M_incr();
return f;
}
void _STLP_CALL _release_facet(locale::facet *&f)
{
if ((f != 0) && (f->_M_decr() == 0)) {
delete f;
f = 0;
}
}
size_t locale::id::_S_max = 27;
static void _Stl_loc_assign_ids();
static _Stl_aligned_buffer<_Locale_impl::Init> __Loc_init_buf;
_Locale_impl::Init::Init() {
if (_M_count()._M_incr() == 1) {
_Locale_impl::_S_initialize();
}
}
_Locale_impl::Init::~Init() {
if (_M_count()._M_decr() == 0) {
_Locale_impl::_S_uninitialize();
}
}
_Refcount_Base& _Locale_impl::Init::_M_count() const {
static _Refcount_Base _S_count(0);
return _S_count;
}
_Locale_impl::_Locale_impl(const char* s)
: _Refcount_Base(0), name(s), facets_vec() {
facets_vec.reserve( locale::id::_S_max );
new (&__Loc_init_buf) Init();
}
_Locale_impl::_Locale_impl( _Locale_impl const& locimpl )
: _Refcount_Base(0), name(locimpl.name), facets_vec() {
for_each( locimpl.facets_vec.begin(), locimpl.facets_vec.end(), _get_facet);
facets_vec = locimpl.facets_vec;
new (&__Loc_init_buf) Init();
}
_Locale_impl::_Locale_impl( size_t n, const char* s)
: _Refcount_Base(0), name(s), facets_vec(n, 0) {
new (&__Loc_init_buf) Init();
}
_Locale_impl::~_Locale_impl() {
(&__Loc_init_buf)->~Init();
for_each( facets_vec.begin(), facets_vec.end(), _release_facet);
}
// Initialization of the locale system. This must be called before
// any locales are constructed. (Meaning that it must be called when
// the I/O library itself is initialized.)
void _STLP_CALL _Locale_impl::_S_initialize() {
_Stl_loc_assign_ids();
make_classic_locale();
}
// Release of the classic locale ressources. Has to be called after the last
// locale destruction and not only after the classic locale destruction as
// the facets can be shared between different facets.
void _STLP_CALL _Locale_impl::_S_uninitialize() {
//Not necessary anymore as classic facets are now 'normal' dynamically allocated
//facets with a reference counter telling to _release_facet when the facet can be
//deleted.
//free_classic_locale();
}
// _Locale_impl non-inline member functions.
void _STLP_CALL _Locale_impl::_M_throw_bad_cast() {
_STLP_THROW(bad_cast());
}
void _Locale_impl::insert(_Locale_impl *from, const locale::id& n) {
if (n._M_index > 0 && n._M_index < from->size()) {
this->insert(from->facets_vec[n._M_index], n);
}
}
locale::facet* _Locale_impl::insert(locale::facet *f, const locale::id& n) {
if (f == 0 || n._M_index == 0)
return 0;
if (n._M_index >= facets_vec.size()) {
facets_vec.resize(n._M_index + 1);
}
if (f != facets_vec[n._M_index])
{
_release_facet(facets_vec[n._M_index]);
facets_vec[n._M_index] = _get_facet(f);
}
return f;
}
//
// <locale> content which is dependent on the name
//
/* Six functions, one for each category. Each of them takes a
* a name, constructs that appropriate category facets by name,
* and inserts them into the locale. */
_Locale_name_hint* _Locale_impl::insert_ctype_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
if (name[0] == 0)
name = _Locale_ctype_default(buf);
if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
_Locale_impl* i2 = locale::classic()._M_impl;
this->insert(i2, ctype<char>::id);
this->insert(i2, codecvt<char, char, mbstate_t>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2, ctype<wchar_t>::id);
this->insert(i2, codecvt<wchar_t, char, mbstate_t>::id);
#endif
} else {
locale::facet* ct = 0;
locale::facet* cvt = 0;
#ifndef _STLP_NO_WCHAR_T
locale::facet* wct = 0;
locale::facet* wcvt = 0;
#endif
int __err_code;
_Locale_ctype *__lct = _STLP_PRIV __acquire_ctype(name, buf, hint, &__err_code);
if (!__lct) {
locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
return hint;
}
if (hint == 0) hint = _Locale_get_ctype_hint(__lct);
_STLP_TRY {
ct = new ctype_byname<char>(__lct);
}
_STLP_UNWIND(_STLP_PRIV __release_ctype(__lct));
_STLP_TRY {
cvt = new codecvt_byname<char, char, mbstate_t>(name);
}
_STLP_UNWIND(delete ct);
#ifndef _STLP_NO_WCHAR_T
_STLP_TRY {
_Locale_ctype *__lwct = _STLP_PRIV __acquire_ctype(name, buf, hint, &__err_code);
if (!__lwct) {
locale::_M_throw_on_creation_failure(__err_code, name, "ctype");
return hint;
}
_STLP_TRY {
wct = new ctype_byname<wchar_t>(__lwct);
}
_STLP_UNWIND(_STLP_PRIV __release_ctype(__lwct));
_Locale_codecvt *__lwcvt = _STLP_PRIV __acquire_codecvt(name, buf, hint, &__err_code);
if (__lwcvt) {
_STLP_TRY {
wcvt = new codecvt_byname<wchar_t, char, mbstate_t>(__lwcvt);
}
_STLP_UNWIND(_STLP_PRIV __release_codecvt(__lwcvt); delete wct);
}
}
_STLP_UNWIND(delete cvt; delete ct);
#endif
this->insert(ct, ctype<char>::id);
this->insert(cvt, codecvt<char, char, mbstate_t>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(wct, ctype<wchar_t>::id);
if (wcvt) this->insert(wcvt, codecvt<wchar_t, char, mbstate_t>::id);
#endif
}
return hint;
}
_Locale_name_hint* _Locale_impl::insert_numeric_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
if (name[0] == 0)
name = _Locale_numeric_default(buf);
_Locale_impl* i2 = locale::classic()._M_impl;
// We first insert name independant facets taken from the classic locale instance:
this->insert(i2,
num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
this->insert(i2,
num_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2,
num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
this->insert(i2,
num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
#endif
if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
this->insert(i2, numpunct<char>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2, numpunct<wchar_t>::id);
#endif
}
else {
locale::facet* punct = 0;
#ifndef _STLP_NO_WCHAR_T
locale::facet* wpunct = 0;
#endif
int __err_code;
_Locale_numeric *__lpunct = _STLP_PRIV __acquire_numeric(name, buf, hint, &__err_code);
if (!__lpunct) {
locale::_M_throw_on_creation_failure(__err_code, name, "numpunct");
return hint;
}
if (hint == 0) hint = _Locale_get_numeric_hint(__lpunct);
_STLP_TRY {
punct = new numpunct_byname<char>(__lpunct);
}
_STLP_UNWIND(_STLP_PRIV __release_numeric(__lpunct));
#ifndef _STLP_NO_WCHAR_T
_Locale_numeric *__lwpunct = _STLP_PRIV __acquire_numeric(name, buf, hint, &__err_code);
if (!__lwpunct) {
delete punct;
locale::_M_throw_on_creation_failure(__err_code, name, "numpunct");
return hint;
}
if (__lwpunct) {
_STLP_TRY {
wpunct = new numpunct_byname<wchar_t>(__lwpunct);
}
_STLP_UNWIND(_STLP_PRIV __release_numeric(__lwpunct); delete punct);
}
#endif
this->insert(punct, numpunct<char>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(wpunct, numpunct<wchar_t>::id);
#endif
}
return hint;
}
_Locale_name_hint* _Locale_impl::insert_time_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
if (name[0] == 0)
name = _Locale_time_default(buf);
if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
_Locale_impl* i2 = locale::classic()._M_impl;
this->insert(i2,
time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
this->insert(i2,
time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2,
time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
this->insert(i2,
time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
#endif
} else {
locale::facet *get = 0;
locale::facet *put = 0;
#ifndef _STLP_NO_WCHAR_T
locale::facet *wget = 0;
locale::facet *wput = 0;
#endif
int __err_code;
_Locale_time *__time = _STLP_PRIV __acquire_time(name, buf, hint, &__err_code);
if (!__time) {
// time facets category is not mandatory for correct stream behavior so if platform
// do not support it we do not generate a runtime_error exception.
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
return hint;
}
if (!hint) hint = _Locale_get_time_hint(__time);
_STLP_TRY {
get = new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(__time);
put = new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(__time);
#ifndef _STLP_NO_WCHAR_T
wget = new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(__time);
wput = new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(__time);
#endif
}
#ifndef _STLP_NO_WCHAR_T
_STLP_UNWIND(delete wget; delete put; delete get; _STLP_PRIV __release_time(__time));
#else
_STLP_UNWIND(delete get; _STLP_PRIV __release_time(__time));
#endif
_STLP_PRIV __release_time(__time);
this->insert(get, time_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
this->insert(put, time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(wget, time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
this->insert(wput, time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
#endif
}
return hint;
}
_Locale_name_hint* _Locale_impl::insert_collate_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
if (name[0] == 0)
name = _Locale_collate_default(buf);
if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
_Locale_impl* i2 = locale::classic()._M_impl;
this->insert(i2, collate<char>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2, collate<wchar_t>::id);
#endif
}
else {
locale::facet *col = 0;
#ifndef _STLP_NO_WCHAR_T
locale::facet *wcol = 0;
#endif
int __err_code;
_Locale_collate *__coll = _STLP_PRIV __acquire_collate(name, buf, hint, &__err_code);
if (!__coll) {
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
return hint;
}
if (hint == 0) hint = _Locale_get_collate_hint(__coll);
_STLP_TRY {
col = new collate_byname<char>(__coll);
}
_STLP_UNWIND(_STLP_PRIV __release_collate(__coll));
#ifndef _STLP_NO_WCHAR_T
_Locale_collate *__wcoll = _STLP_PRIV __acquire_collate(name, buf, hint, &__err_code);
if (!__wcoll) {
if (__err_code == _STLP_LOC_NO_MEMORY) {
delete col;
_STLP_THROW_BAD_ALLOC;
}
}
if (__wcoll) {
_STLP_TRY {
wcol = new collate_byname<wchar_t>(__wcoll);
}
_STLP_UNWIND(_STLP_PRIV __release_collate(__wcoll); delete col);
}
#endif
this->insert(col, collate<char>::id);
#ifndef _STLP_NO_WCHAR_T
if (wcol) this->insert(wcol, collate<wchar_t>::id);
#endif
}
return hint;
}
_Locale_name_hint* _Locale_impl::insert_monetary_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
if (name[0] == 0)
name = _Locale_monetary_default(buf);
_Locale_impl* i2 = locale::classic()._M_impl;
// We first insert name independant facets taken from the classic locale instance:
this->insert(i2, money_get<char, istreambuf_iterator<char, char_traits<char> > >::id);
this->insert(i2, money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2, money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
this->insert(i2, money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id);
#endif
if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
this->insert(i2, moneypunct<char, false>::id);
this->insert(i2, moneypunct<char, true>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2, moneypunct<wchar_t, false>::id);
this->insert(i2, moneypunct<wchar_t, true>::id);
#endif
}
else {
locale::facet *punct = 0;
locale::facet *ipunct = 0;
#ifndef _STLP_NO_WCHAR_T
locale::facet* wpunct = 0;
locale::facet* wipunct = 0;
#endif
int __err_code;
_Locale_monetary *__mon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
if (!__mon) {
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
return hint;
}
if (hint == 0) hint = _Locale_get_monetary_hint(__mon);
_STLP_TRY {
punct = new moneypunct_byname<char, false>(__mon);
}
_STLP_UNWIND(_STLP_PRIV __release_monetary(__mon));
_Locale_monetary *__imon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
if (!__imon) {
delete punct;
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
return hint;
}
_STLP_TRY {
ipunct = new moneypunct_byname<char, true>(__imon);
}
_STLP_UNWIND(_STLP_PRIV __release_monetary(__imon); delete punct);
#ifndef _STLP_NO_WCHAR_T
_STLP_TRY {
_Locale_monetary *__wmon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
if (!__wmon) {
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
}
if (__wmon) {
_STLP_TRY {
wpunct = new moneypunct_byname<wchar_t, false>(__wmon);
}
_STLP_UNWIND(_STLP_PRIV __release_monetary(__wmon));
_Locale_monetary *__wimon = _STLP_PRIV __acquire_monetary(name, buf, hint, &__err_code);
if (!__wimon) {
delete wpunct;
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
wpunct = 0;
}
else {
_STLP_TRY {
wipunct = new moneypunct_byname<wchar_t, true>(__wimon);
}
_STLP_UNWIND(_STLP_PRIV __release_monetary(__wimon); delete wpunct);
}
}
}
_STLP_UNWIND(delete ipunct; delete punct);
#endif
this->insert(punct, moneypunct<char, false>::id);
this->insert(ipunct, moneypunct<char, true>::id);
#ifndef _STLP_NO_WCHAR_T
if (wpunct) this->insert(wpunct, moneypunct<wchar_t, false>::id);
if (wipunct) this->insert(wipunct, moneypunct<wchar_t, true>::id);
#endif
}
return hint;
}
_Locale_name_hint* _Locale_impl::insert_messages_facets(const char* &name, char *buf, _Locale_name_hint* hint) {
if (name[0] == 0)
name = _Locale_messages_default(buf);
if (name == 0 || name[0] == 0 || is_C_locale_name(name)) {
_Locale_impl* i2 = locale::classic()._M_impl;
this->insert(i2, messages<char>::id);
#ifndef _STLP_NO_WCHAR_T
this->insert(i2, messages<wchar_t>::id);
#endif
}
else {
locale::facet *msg = 0;
#ifndef _STLP_NO_WCHAR_T
locale::facet *wmsg = 0;
#endif
int __err_code;
_Locale_messages *__msg = _STLP_PRIV __acquire_messages(name, buf, hint, &__err_code);
if (!__msg) {
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
return hint;
}
_STLP_TRY {
msg = new messages_byname<char>(__msg);
}
_STLP_UNWIND(_STLP_PRIV __release_messages(__msg));
#ifndef _STLP_NO_WCHAR_T
_STLP_TRY {
_Locale_messages *__wmsg = _STLP_PRIV __acquire_messages(name, buf, hint, &__err_code);
if (!__wmsg) {
if (__err_code == _STLP_LOC_NO_MEMORY) {
_STLP_THROW_BAD_ALLOC;
}
}
if (__wmsg) {
_STLP_TRY {
wmsg = new messages_byname<wchar_t>(__wmsg);
}
_STLP_UNWIND(_STLP_PRIV __release_messages(__wmsg));
}
}
_STLP_UNWIND(delete msg);
#endif
this->insert(msg, messages<char>::id);
#ifndef _STLP_NO_WCHAR_T
if (wmsg) this->insert(wmsg, messages<wchar_t>::id);
#endif
}
return hint;
}
static void _Stl_loc_assign_ids() {
// This assigns ids to every facet that is a member of a category,
// and also to money_get/put, num_get/put, and time_get/put
// instantiated using ordinary pointers as the input/output
// iterators. (The default is [io]streambuf_iterator.)
money_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 8;
money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 9;
num_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 10;
num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 11;
time_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 12;
time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 13;
#ifndef _STLP_NO_WCHAR_T
money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 21;
money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 22;
num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 23;
num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id._M_index = 24;
time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 25;
time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 26;
#endif
// locale::id::_S_max = 27;
}
// To access those static instance use the getter below, they guaranty
// a correct initialization.
static locale *_Stl_classic_locale = 0;
static locale *_Stl_global_locale = 0;
locale* _Stl_get_classic_locale() {
static _Locale_impl::Init init;
return _Stl_classic_locale;
}
locale* _Stl_get_global_locale() {
static _Locale_impl::Init init;
return _Stl_global_locale;
}
#if defined (_STLP_MSVC) || defined (__ICL) || defined (__ISCPP__) || defined (__DMC__)
/*
* The following static variable needs to be initialized before STLport
* users static variable in order for him to be able to use Standard
* streams in its variable initialization.
* This variable is here because MSVC do not allow to change the initialization
* segment in a given translation unit, iostream.cpp already contains an
* initialization segment specification.
*/
# pragma warning (disable : 4073)
# pragma init_seg(lib)
#endif
static ios_base::Init _IosInit;
void _Locale_impl::make_classic_locale() {
// This funcion will be called once: during build classic _Locale_impl
// The classic locale contains every facet that belongs to a category.
static _Stl_aligned_buffer<_Locale_impl> _Locale_classic_impl_buf;
_Locale_impl *classic = new(&_Locale_classic_impl_buf) _Locale_impl("C");
locale::facet* classic_facets[] = {
0,
new collate<char>(1),
new ctype<char>(0, false, 1),
new codecvt<char, char, mbstate_t>(1),
new moneypunct<char, true>(1),
new moneypunct<char, false>(1),
new numpunct<char>(1),
new messages<char>(1),
new money_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
new money_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
new num_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
new num_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
new time_get<char, istreambuf_iterator<char, char_traits<char> > >(1),
new time_put<char, ostreambuf_iterator<char, char_traits<char> > >(1),
#ifndef _STLP_NO_WCHAR_T
new collate<wchar_t>(1),
new ctype<wchar_t>(1),
new codecvt<wchar_t, char, mbstate_t>(1),
new moneypunct<wchar_t, true>(1),
new moneypunct<wchar_t, false>(1),
new numpunct<wchar_t>(1),
new messages<wchar_t>(1),
new money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
new money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
new num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
new num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
new time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
new time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(1),
#endif
0
};
const size_t nb_classic_facets = sizeof(classic_facets) / sizeof(locale::facet *);
classic->facets_vec.reserve(nb_classic_facets);
classic->facets_vec.assign(&classic_facets[0], &classic_facets[0] + nb_classic_facets);
static locale _Locale_classic(classic);
_Stl_classic_locale = &_Locale_classic;
static locale _Locale_global(classic);
_Stl_global_locale = &_Locale_global;
}
// Declarations of (non-template) facets' static data members
// size_t locale::id::_S_max = 27; // made before
locale::id collate<char>::id = { 1 };
locale::id ctype<char>::id = { 2 };
locale::id codecvt<char, char, mbstate_t>::id = { 3 };
locale::id moneypunct<char, true>::id = { 4 };
locale::id moneypunct<char, false>::id = { 5 };
locale::id numpunct<char>::id = { 6 } ;
locale::id messages<char>::id = { 7 };
#ifndef _STLP_NO_WCHAR_T
locale::id collate<wchar_t>::id = { 14 };
locale::id ctype<wchar_t>::id = { 15 };
locale::id codecvt<wchar_t, char, mbstate_t>::id = { 16 };
locale::id moneypunct<wchar_t, true>::id = { 17 } ;
locale::id moneypunct<wchar_t, false>::id = { 18 } ;
locale::id numpunct<wchar_t>::id = { 19 };
locale::id messages<wchar_t>::id = { 20 };
#endif
_STLP_DECLSPEC _Locale_impl* _STLP_CALL _get_Locale_impl(_Locale_impl *loc)
{
_STLP_ASSERT( loc != 0 );
loc->_M_incr();
return loc;
}
void _STLP_CALL _release_Locale_impl(_Locale_impl *& loc)
{
_STLP_ASSERT( loc != 0 );
if (loc->_M_decr() == 0) {
if (*loc != *_Stl_classic_locale)
delete loc;
else
loc->~_Locale_impl();
loc = 0;
}
}
_STLP_DECLSPEC _Locale_impl* _STLP_CALL _copy_Nameless_Locale_impl(_Locale_impl *loc)
{
_STLP_ASSERT( loc != 0 );
_Locale_impl *loc_new = new _Locale_impl(*loc);
loc_new->name = _Nameless;
return loc_new;
}
/* _GetFacetId implementation have to be here in order to be in the same translation unit
* as where id are initialize (in _Stl_loc_assign_ids) */
_STLP_MOVE_TO_PRIV_NAMESPACE
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_get<char, istreambuf_iterator<char, char_traits<char> > >*)
{ return money_get<char, istreambuf_iterator<char, char_traits<char> > >::id; }
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_put<char, ostreambuf_iterator<char, char_traits<char> > >*)
{ return money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; }
#ifndef _STLP_NO_WCHAR_T
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
{ return money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
{ return money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
#endif
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_get<char, istreambuf_iterator<char, char_traits<char> > >*)
{ return num_get<char, istreambuf_iterator<char, char_traits<char> > >::id; }
#ifndef _STLP_NO_WCHAR_T
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
{ return num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
#endif
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_put<char, ostreambuf_iterator<char, char_traits<char> > >*)
{ return num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; }
#ifndef _STLP_NO_WCHAR_T
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
{ return num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
#endif
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_get<char, istreambuf_iterator<char, char_traits<char> > >*)
{ return time_get<char, istreambuf_iterator<char, char_traits<char> > >::id; }
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_put<char, ostreambuf_iterator<char, char_traits<char> > >*)
{ return time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id; }
#ifndef _STLP_NO_WCHAR_T
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
{ return time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
_STLP_DECLSPEC locale::id& _STLP_CALL _GetFacetId(const time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >*)
{ return time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id; }
#endif
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE

133
extern/STLport/5.2.1/src/locale_impl.h vendored Normal file
View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef LOCALE_IMPL_H
#define LOCALE_IMPL_H
#include <clocale> // C locale header file.
#include <vector>
#include <string>
#include <locale>
#include "c_locale.h"
_STLP_BEGIN_NAMESPACE
#if defined (_STLP_USE_TEMPLATE_EXPORT)
//Export of _Locale_impl facets container:
# if !defined (_STLP_USE_PTR_SPECIALIZATIONS)
//If we are using pointer specialization, vector<locale::facet*> will use
//the already exported vector<void*> implementation.
_STLP_EXPORT_TEMPLATE_CLASS allocator<locale::facet*>;
_STLP_MOVE_TO_PRIV_NAMESPACE
_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<locale::facet**, locale::facet*, allocator<locale::facet*> >;
_STLP_EXPORT_TEMPLATE_CLASS _Vector_base<locale::facet*, allocator<locale::facet*> >;
_STLP_MOVE_TO_STD_NAMESPACE
# endif
# if defined (_STLP_DEBUG)
_STLP_MOVE_TO_PRIV_NAMESPACE
# define _STLP_NON_DBG_VECTOR _STLP_NON_DBG_NAME(vector)
_STLP_EXPORT_TEMPLATE_CLASS __construct_checker<_STLP_NON_DBG_VECTOR<locale::facet*, allocator<locale::facet*> > >;
_STLP_EXPORT_TEMPLATE_CLASS _STLP_NON_DBG_VECTOR<locale::facet*, allocator<locale::facet*> >;
# undef _STLP_NON_DBG_VECTOR
_STLP_MOVE_TO_STD_NAMESPACE
# endif
_STLP_EXPORT_TEMPLATE_CLASS vector<locale::facet*, allocator<locale::facet*> >;
#endif
//----------------------------------------------------------------------
// Class _Locale_impl
// This is the base class which implements access only and is supposed to
// be used for classic locale only
class _STLP_CLASS_DECLSPEC _Locale_impl : public _Refcount_Base {
public:
_Locale_impl(const char* s);
_Locale_impl(const _Locale_impl&);
_Locale_impl(size_t n, const char* s);
private:
~_Locale_impl();
public:
size_t size() const { return facets_vec.size(); }
basic_string<char, char_traits<char>, allocator<char> > name;
static void _STLP_FUNCTION_THROWS _STLP_CALL _M_throw_bad_cast();
private:
void operator=(const _Locale_impl&);
public:
class _STLP_CLASS_DECLSPEC Init {
public:
Init();
~Init();
private:
_Refcount_Base& _M_count() const;
};
static void _STLP_CALL _S_initialize();
static void _STLP_CALL _S_uninitialize();
static void make_classic_locale();
static void free_classic_locale();
friend class Init;
public:
// void remove(size_t index);
locale::facet* insert(locale::facet*, const locale::id& n);
void insert(_Locale_impl* from, const locale::id& n);
// Helper functions for byname construction of locales.
_Locale_name_hint* insert_ctype_facets(const char* &name, char *buf, _Locale_name_hint* hint);
_Locale_name_hint* insert_numeric_facets(const char* &name, char *buf, _Locale_name_hint* hint);
_Locale_name_hint* insert_time_facets(const char* &name, char *buf, _Locale_name_hint* hint);
_Locale_name_hint* insert_collate_facets(const char* &name, char *buf, _Locale_name_hint* hint);
_Locale_name_hint* insert_monetary_facets(const char* &name, char *buf, _Locale_name_hint* hint);
_Locale_name_hint* insert_messages_facets(const char* &name, char *buf, _Locale_name_hint* hint);
bool operator != (const locale& __loc) const { return __loc._M_impl != this; }
private:
vector<locale::facet*> facets_vec;
private:
friend _Locale_impl * _STLP_CALL _copy_Nameless_Locale_impl( _Locale_impl * );
friend void _STLP_CALL _release_Locale_impl( _Locale_impl *& loc );
#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND) || \
defined (_STLP_SIGNAL_RUNTIME_COMPATIBILITY) || defined (_STLP_CHECK_RUNTIME_COMPATIBILITY)
friend class _STLP_NO_MEM_T_NAME(loc);
#else
friend class locale;
#endif
};
void _STLP_CALL _release_Locale_impl( _Locale_impl *& loc );
_STLP_END_NAMESPACE
#endif
// Local Variables:
// mode:C++
// End:

View File

@@ -0,0 +1,307 @@
/*
* Copyright (c) 1997-1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_LOCK_FREE_SLIST_H
#define _STLP_LOCK_FREE_SLIST_H
#if defined(_STLP_PTHREADS)
# include <pthread.h>
# if defined (__GNUC__) && defined (__i386__)
# define _STLP_HAS_ATOMIC_FREELIST
/**
* Class that implements a non-blocking and thread-safe freelist.
* It is used for the lock-free node allocation engine.
*
* @author felixw@inin.com
*/
class _STLP_atomic_freelist {
public:
/**
* Type representing items of the freelist
*/
struct item {
item* _M_next;
};
_STLP_atomic_freelist() {
// Statically assert layout of member is as expected by assembly code
_STLP_STATIC_ASSERT(sizeof(_M) == 8)
_M._M_data._M_top = 0;
_M._M_data._M_sequence = 0;
}
/**
* Atomically pushes the specified item onto the freelist.
*
* @param __item [in] Item to add to the front of the list
*/
void push(item* __item) {
// NOTE: GCC uses ebx as the PIC register for globals in shared libraries.
// The GCC version I'm using (3.4.1) won't temporarily spill it if it's
// used as input, output, or clobber. Instead, it complains with a
// "can't find a register in class `BREG' while reloading `asm'" error.
// This is probably a compiler bug, but as the cmpxchg8b instruction
// requires ebx, I work around this here by using ecx for the '__item'
// input and spilling ebx into edi. This also precludes us from using
// a "m" operand for the cmpxchg8b argument (GCC might think it can make
// it relative to ebx). Instead, we're using esi for the address of _M_data.
//
int __tmp1; // These dummy variables are used to tell GCC that the eax, ecx,
int __tmp2; // and edx registers will not have the same value as their input.
int __tmp3; // The optimizer will remove them as their values are not used.
__asm__ __volatile__
(" movl %%ebx, %%edi\n\t"
" movl %%ecx, %%ebx\n\t"
"L1_%=: movl %%eax, (%%ebx)\n\t" // __item._M_next = _M._M_data._M_top
" leal 1(%%edx),%%ecx\n\t" // new sequence = _M._M_data._M_sequence + 1
"lock; cmpxchg8b (%%esi)\n\t"
" jne L1_%=\n\t" // Failed, retry! (edx:eax now contain most recent _M_sequence:_M_top)
" movl %%edi, %%ebx"
:"=a" (__tmp1), "=d" (__tmp2), "=c" (__tmp3)
:"a" (_M._M_data._M_top), "d" (_M._M_data._M_sequence), "c" (__item), "S" (&_M._M_data)
:"edi", "memory", "cc");
}
/**
* Atomically removes the topmost item from the freelist and returns a
* pointer to it. Returns NULL if the list is empty.
*
* @return Item that was removed from front of list; NULL if list empty
*/
item* pop() {
item* __result;
int __tmp;
__asm__ __volatile__
(" movl %%ebx, %%edi\n\t"
"L1_%=: testl %%eax, %%eax\n\t" // _M_top == NULL?
" je L2_%=\n\t" // If yes, we're done
" movl (%%eax), %%ebx\n\t" // new top = _M._M_data._M_top->_M_next
" leal 1(%%edx),%%ecx\n\t" // new sequence = _M._M_data._M_sequence + 1
"lock; cmpxchg8b (%%esi)\n\t"
" jne L1_%=\n\t" // We failed, retry! (edx:eax now contain most recent _M_sequence:_M_top)
"L2_%=: movl %%edi, %%ebx"
:"=a" (__result), "=d" (__tmp)
:"a" (_M._M_data._M_top), "d" (_M._M_data._M_sequence), "S" (&_M._M_data)
:"edi", "ecx", "memory", "cc");
return __result;
}
/**
* Atomically detaches all items from the list and returns a pointer to the
* topmost item. The items are still chained and may be traversed safely as
* they're now "owned" by the calling thread.
*
* @return Pointer to topmost item in the list; NULL if list empty
*/
item* clear() {
item* __result;
int __tmp;
__asm__ __volatile__
(" movl %%ebx, %%edi\n\t"
"L1_%=: testl %%eax, %%eax\n\t" // _M_top == NULL?
" je L2_%=\n\t" // If yes, we're done
" xorl %%ebx, %%ebx\n\t" // We're attempting to set _M_top to NULL
" leal 1(%%edx),%%ecx\n\t" // new sequence = _M._M_data._M_sequence + 1
"lock; cmpxchg8b (%%esi)\n\t"
" jne L1_%=\n\t" // Failed, retry! (edx:eax now contain most recent _M_sequence:_M_top)
"L2_%=: movl %%edi, %%ebx"
:"=a" (__result), "=d" (__tmp)
:"a" (_M._M_data._M_top), "d" (_M._M_data._M_sequence), "S" (&_M._M_data)
:"edi", "ecx", "memory", "cc");
return __result;
}
private:
union {
long long _M_align;
struct {
item* _M_top; // Topmost element in the freelist
unsigned int _M_sequence; // Sequence counter to prevent "ABA problem"
} _M_data;
} _M;
_STLP_atomic_freelist(const _STLP_atomic_freelist&);
_STLP_atomic_freelist& operator=(const _STLP_atomic_freelist&);
};
# endif /* if defined(__GNUC__) && defined(__i386__) */
#elif defined (_STLP_WIN32THREADS)
# if !defined (_WIN64)
# define _STLP_USE_ASM_IMPLEMENTATION
# endif
// Here are the compiler/platform requirements for the thread safe and
// lock free singly linked list implementation:
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
// For the asm version:
# if defined (_STLP_MSVC) && defined (_M_IX86) && (_M_IX86 >= 500)
# define _STLP_HAS_ATOMIC_FREELIST
# endif
# else
// For the API based version:
# if defined (_STLP_NEW_PLATFORM_SDK) && (!defined (WINVER) || (WINVER >= 0x0501)) && \
(!defined (_WIN32_WINNT) || (_WIN32_WINNT >= 0x0501))
# define _STLP_HAS_ATOMIC_FREELIST
# endif
# endif
# if defined (_STLP_HAS_ATOMIC_FREELIST)
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
# if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) || defined (__ICL)
# pragma warning (push)
# pragma warning (disable : 4035) //function has no return value
# endif
# endif
/**
* Class that implements a non-blocking and thread-safe freelist.
* It is used for the lock-free node allocation engine.
*
* @author felixw@inin.com
*/
class _STLP_atomic_freelist {
public:
/**
* Type representing items of the freelist
*/
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
struct item {
item* _M_next;
};
# else
typedef SLIST_ENTRY item;
# endif
_STLP_atomic_freelist() {
// Statically assert layout of member is as expected by assembly code
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
_STLP_STATIC_ASSERT((sizeof(item) == sizeof(item*)) && (sizeof(_M) == 8))
_M._M_data._M_top = 0;
_M._M_data._M_sequence = 0;
# else
InitializeSListHead(&_M_head);
# endif
}
/**
* Atomically pushes the specified item onto the freelist.
*
* @param __item [in] Item to add to the front of the list
*/
void push(item* __item) {
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
__asm
{
mov esi, this
mov ebx, __item
mov eax, [esi] // _M._M_data._M_top
mov edx, [esi+4] // _M._M_data._M_sequence
L1: mov [ebx], eax // __item._M_next = _M._M_data._M_top
lea ecx, [edx+1] // new sequence = _M._M_data._M_sequence + 1
lock cmpxchg8b qword ptr [esi]
jne L1 // Failed, retry! (edx:eax now contain most recent _M_sequence:_M_top)
}
# else
InterlockedPushEntrySList(&_M_head, __item);
# endif
}
/**
* Atomically removes the topmost item from the freelist and returns a
* pointer to it. Returns NULL if the list is empty.
*
* @return Item that was removed from front of list; NULL if list empty
*/
item* pop() {
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
__asm
{
mov esi, this
mov eax, [esi] // _M._M_data._M_top
mov edx, [esi+4] // _M._M_data._M_sequence
L1: test eax, eax // _M_top == NULL?
je L2 // Yes, we're done
mov ebx, [eax] // new top = _M._M_data._M_top->_M_next
lea ecx, [edx+1] // new sequence = _M._M_data._M_sequence + 1
lock cmpxchg8b qword ptr [esi]
jne L1 // Failed, retry! (edx:eax now contain most recent _M_sequence:_M_top)
L2:
}
# else
return InterlockedPopEntrySList(&_M_head);
# endif
}
/**
* Atomically detaches all items from the list and returns pointer to the
* topmost. The items are still chained and may be traversed safely as
* they're now "owned" by the calling thread.
*
* @return Pointer to topmost item in the list; NULL if list empty
*/
item* clear() {
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
__asm
{
mov esi, this
mov eax, [esi] // _M._M_data._M_top
mov edx, [esi+4] // _M._M_data._M_sequence
L1: test eax, eax // _M_top == NULL?
je L2 // Yes, we're done
xor ebx,ebx // We're attempting to set _M._M_data._M_top to NULL
lea ecx, [edx+1] // new sequence = _M._M_data._M_sequence + 1
lock cmpxchg8b qword ptr [esi]
jne L1 // Failed, retry! (edx:eax now contain most recent _M_sequence:_M_top)
L2:
}
# else
return InterlockedFlushSList(&_M_head);
# endif
}
private:
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
union {
__int64 _M_align;
struct {
item* _M_top; // Topmost element in the freelist
unsigned int _M_sequence; // Sequence counter to prevent "ABA problem"
} _M_data;
} _M;
# else
SLIST_HEADER _M_head;
# endif
_STLP_atomic_freelist(const _STLP_atomic_freelist&);
_STLP_atomic_freelist& operator = (const _STLP_atomic_freelist&);
};
# if defined (_STLP_USE_ASM_IMPLEMENTATION)
# if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) || defined (__ICL)
# pragma warning (pop)
# endif
# endif
# endif /* _STLP_HAS_ATOMIC_FREELIST */
#endif
#endif /* _STLP_LOCK_FREE_SLIST_H */

View File

@@ -0,0 +1,152 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef MESSAGE_FACETS_H
#define MESSAGE_FACETS_H
#include <string>
#include <locale>
#include <hash_map>
#include "c_locale.h"
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// Class _Catalog_locale_map. The reason for this is that, internally,
// a message string is always a char*. We need a ctype facet to convert
// a string to and from wchar_t, and the user is permitted to provide such
// a facet when calling open().
struct _Catalog_locale_map {
_Catalog_locale_map() : M(0) {}
~_Catalog_locale_map() { if (M) delete M; }
void insert(nl_catd_type key, const locale& L);
locale lookup(nl_catd_type key) const;
void erase(nl_catd_type key);
typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type>,
allocator<pair<_STLP_CONST nl_catd_type, locale> > > map_type;
map_type *M;
private: // Invalidate copy constructor and assignment
_Catalog_locale_map(const _Catalog_locale_map&);
void operator=(const _Catalog_locale_map&);
};
/*
* In glibc nl_catd type is void *, but messages_base::catalog is defined as int
* by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms;
* Another problem, is that do_open() may return negative value to indicate that no
* catalog open---this case can't be represented with pointers.
* The class _Catalog_nl_catd_map intended to make relation between
* messages_base::catalog and nl_catd handler.
*
*/
#if defined (_STLP_USE_GLIBC2_LOCALIZATION)
# define _STLP_USE_NL_CATD_MAPPING
#else
/* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1,
* has to be large enough to contain a nl_catd_type value.
*/
_STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int))
#endif
class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map {
public:
_Catalog_nl_catd_map()
{}
~_Catalog_nl_catd_map()
{}
typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog>,
allocator<pair<_STLP_CONST messages_base::catalog, nl_catd_type> > > map_type;
typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type>,
allocator<pair<_STLP_CONST nl_catd_type, messages_base::catalog> > > rmap_type;
// typedef map<messages_base::catalog,nl_catd_type> map_type;
// typedef map<nl_catd_type,messages_base::catalog> rmap_type;
messages_base::catalog insert(nl_catd_type cat)
#if !defined (_STLP_USE_NL_CATD_MAPPING)
{ return (messages_base::catalog)cat; }
#else
;
#endif
void erase(messages_base::catalog)
#if !defined (_STLP_USE_NL_CATD_MAPPING)
{}
#else
;
#endif
nl_catd_type operator [] ( messages_base::catalog cat )
#if !defined (_STLP_USE_NL_CATD_MAPPING)
{ return cat; }
#else
{ return cat < 0 ? 0 : M[cat]; }
#endif
private:
_Catalog_nl_catd_map(const _Catalog_nl_catd_map&);
_Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&);
#if defined (_STLP_USE_NL_CATD_MAPPING)
map_type M;
rmap_type Mr;
static _STLP_VOLATILE __stl_atomic_t _count;
#endif
};
class _Messages {
public:
typedef messages_base::catalog catalog;
_Messages(bool, const char *name);
_Messages(bool, _Locale_messages*);
catalog do_open(const string& __fn, const locale& __loc) const;
string do_get(catalog __c, int __set, int __msgid,
const string& __dfault) const;
#if !defined (_STLP_NO_WCHAR_T)
wstring do_get(catalog __c, int __set, int __msgid,
const wstring& __dfault) const;
#endif
void do_close(catalog __c) const;
~_Messages();
private:
_Locale_messages* _M_message_obj;
_Catalog_locale_map* _M_map;
mutable _Catalog_nl_catd_map _M_cat;
//private definition to avoid warning (with ICL)
_Messages(const _Messages&);
_Messages& operator=(const _Messages&);
};
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE
#endif
// Local Variables:
// mode:C++
// End:

247
extern/STLport/5.2.1/src/messages.cpp vendored Normal file
View File

@@ -0,0 +1,247 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <typeinfo>
#include "message_facets.h"
#include "acquire_release.h"
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
void _Catalog_locale_map::insert(nl_catd_type key, const locale& L) {
_STLP_TRY {
#if !defined (_STLP_NO_TYPEINFO) && !defined (_STLP_NO_RTTI)
// Don't bother to do anything unless we're using a non-default ctype facet
# ifdef _STLP_NO_WCHAR_T
typedef char _Char;
# else
typedef wchar_t _Char;
# endif
typedef ctype<_Char> wctype;
wctype const& wct = use_facet<wctype>(L);
if (typeid(wct) != typeid(wctype)) {
#endif
if (!M)
M = new map_type;
M->insert(map_type::value_type(key, L));
#if !defined (_STLP_NO_TYPEINFO) && !defined (_STLP_NO_RTTI)
}
#endif
}
_STLP_CATCH_ALL {}
}
void _Catalog_locale_map::erase(nl_catd_type key) {
if (M)
M->erase(key);
}
locale _Catalog_locale_map::lookup(nl_catd_type key) const {
if (M) {
map_type::const_iterator i = M->find(key);
return i != M->end() ? (*i).second : locale::classic();
}
else
return locale::classic();
}
#if defined (_STLP_USE_NL_CATD_MAPPING)
_STLP_VOLATILE __stl_atomic_t _Catalog_nl_catd_map::_count = 0;
messages_base::catalog _Catalog_nl_catd_map::insert(nl_catd_type cat) {
messages_base::catalog &res = Mr[cat];
if ( res == 0 ) {
#if defined (_STLP_ATOMIC_INCREMENT)
res = __STATIC_CAST(int, _STLP_ATOMIC_INCREMENT(&_count));
#else
static _STLP_STATIC_MUTEX _Count_lock _STLP_MUTEX_INITIALIZER;
{
_STLP_auto_lock sentry(_Count_lock);
res = __STATIC_CAST(int, ++_count);
}
#endif
M[res] = cat;
}
return res;
}
void _Catalog_nl_catd_map::erase(messages_base::catalog cat) {
map_type::iterator mit(M.find(cat));
if (mit != M.end()) {
Mr.erase((*mit).second);
M.erase(mit);
}
}
#endif
//----------------------------------------------------------------------
//
_Messages::_Messages(bool is_wide, const char *name) :
_M_message_obj(0), _M_map(0) {
if (!name)
locale::_M_throw_on_null_name();
int __err_code;
char buf[_Locale_MAX_SIMPLE_NAME];
_M_message_obj = _STLP_PRIV __acquire_messages(name, buf, 0, &__err_code);
if (!_M_message_obj)
locale::_M_throw_on_creation_failure(__err_code, name, "messages");
if (is_wide)
_M_map = new _Catalog_locale_map;
}
_Messages::_Messages(bool is_wide, _Locale_messages* msg) :
_M_message_obj(msg), _M_map(is_wide ? new _Catalog_locale_map() : 0)
{}
_Messages::~_Messages() {
__release_messages(_M_message_obj);
delete _M_map;
}
_Messages::catalog _Messages::do_open(const string& filename, const locale& L) const {
nl_catd_type result = _M_message_obj ? _Locale_catopen(_M_message_obj, filename.c_str())
: (nl_catd_type)(-1);
if ( result != (nl_catd_type)(-1) ) {
if ( _M_map != 0 ) {
_M_map->insert(result, L);
}
return _STLP_MUTABLE(_Messages_impl, _M_cat).insert( result );
}
return -1;
}
string _Messages::do_get(catalog cat,
int set, int p_id, const string& dfault) const {
return _M_message_obj != 0 && cat >= 0
? string(_Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[cat],
set, p_id, dfault.c_str()))
: dfault;
}
#if !defined (_STLP_NO_WCHAR_T)
wstring
_Messages::do_get(catalog thecat,
int set, int p_id, const wstring& dfault) const {
typedef ctype<wchar_t> wctype;
const wctype& ct = use_facet<wctype>(_M_map->lookup(_STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]));
const char* str = _Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat], set, p_id, "");
// Verify that the lookup failed; an empty string might represent success.
if (!str)
return dfault;
else if (str[0] == '\0') {
const char* str2 = _Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat], set, p_id, "*");
if (!str2 || ((str2[0] == '*') && (str2[1] == '\0')))
return dfault;
}
// str is correct. Now we must widen it to get a wstring.
size_t n = strlen(str);
// NOT PORTABLE. What we're doing relies on internal details of the
// string implementation. (Contiguity of string elements.)
wstring result(n, wchar_t(0));
ct.widen(str, str + n, &*result.begin());
return result;
}
#endif
void _Messages::do_close(catalog thecat) const {
if (_M_message_obj)
_Locale_catclose(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]);
if (_M_map) _M_map->erase(_STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]);
_STLP_MUTABLE(_Messages_impl, _M_cat).erase( thecat );
}
_STLP_MOVE_TO_STD_NAMESPACE
//----------------------------------------------------------------------
// messages<char>
messages<char>::messages(size_t refs)
: locale::facet(refs) {}
messages_byname<char>::messages_byname(const char *name, size_t refs)
: messages<char>(refs), _M_impl(new _STLP_PRIV _Messages(false, name)) {}
messages_byname<char>::messages_byname(_Locale_messages* msg)
: messages<char>(0), _M_impl(new _STLP_PRIV _Messages(false, msg)) {}
messages_byname<char>::~messages_byname()
{ delete _M_impl; }
messages_byname<char>::catalog
messages_byname<char>::do_open(const string& filename, const locale& l) const
{ return _M_impl->do_open(filename, l); }
string
messages_byname<char>::do_get(catalog cat, int set, int p_id,
const string& dfault) const
{ return _M_impl->do_get(cat, set, p_id, dfault); }
void messages_byname<char>::do_close(catalog cat) const
{ _M_impl->do_close(cat); }
#if !defined (_STLP_NO_WCHAR_T)
//----------------------------------------------------------------------
// messages<wchar_t>
messages<wchar_t>::messages(size_t refs)
: locale::facet(refs) {}
messages_byname<wchar_t>::messages_byname(const char *name, size_t refs)
: messages<wchar_t>(refs), _M_impl(new _STLP_PRIV _Messages(true, name)) {}
messages_byname<wchar_t>::messages_byname(_Locale_messages* msg)
: messages<wchar_t>(0), _M_impl(new _STLP_PRIV _Messages(true, msg)) {}
messages_byname<wchar_t>::~messages_byname()
{ delete _M_impl; }
messages_byname<wchar_t>::catalog
messages_byname<wchar_t>::do_open(const string& filename, const locale& L) const
{ return _M_impl->do_open(filename, L); }
wstring
messages_byname<wchar_t>::do_get(catalog thecat,
int set, int p_id, const wstring& dfault) const
{ return _M_impl->do_get(thecat, set, p_id, dfault); }
void messages_byname<wchar_t>::do_close(catalog cat) const
{ _M_impl->do_close(cat); }
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

152
extern/STLport/5.2.1/src/monetary.cpp vendored Normal file
View File

@@ -0,0 +1,152 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
#include <istream>
_STLP_BEGIN_NAMESPACE
static void _Init_monetary_formats(money_base::pattern& pos_format,
money_base::pattern& neg_format) {
pos_format.field[0] = (char) money_base::symbol;
pos_format.field[1] = (char) money_base::sign;
pos_format.field[2] = (char) money_base::none;
pos_format.field[3] = (char) money_base::value;
neg_format.field[0] = (char) money_base::symbol;
neg_format.field[1] = (char) money_base::sign;
neg_format.field[2] = (char) money_base::none;
neg_format.field[3] = (char) money_base::value;
}
// This is being used throughout the library
static const string _S_empty_string;
#ifndef _STLP_NO_WCHAR_T
static const wstring _S_empty_wstring;
#endif
//
// moneypunct<>
//
moneypunct<char, true>::moneypunct(size_t __refs) : locale::facet(__refs)
{ _Init_monetary_formats(_M_pos_format, _M_neg_format); }
moneypunct<char, true>::~moneypunct() {}
char moneypunct<char, true>::do_decimal_point() const {return ' ';}
char moneypunct<char, true>::do_thousands_sep() const {return ' ';}
string moneypunct<char, true>::do_grouping() const { return _S_empty_string; }
string moneypunct<char, true>::do_curr_symbol() const { return _S_empty_string; }
string moneypunct<char, true>::do_positive_sign() const { return _S_empty_string; }
string moneypunct<char, true>::do_negative_sign() const { return _S_empty_string; }
money_base::pattern moneypunct<char, true>::do_pos_format() const {return _M_pos_format;}
money_base::pattern moneypunct<char, true>::do_neg_format() const {return _M_neg_format;}
int moneypunct<char, true>::do_frac_digits() const {return 0;}
moneypunct<char, false>::moneypunct(size_t __refs) : locale::facet(__refs)
{ _Init_monetary_formats(_M_pos_format, _M_neg_format); }
moneypunct<char, false>::~moneypunct() {}
char moneypunct<char, false>::do_decimal_point() const {return ' ';}
char moneypunct<char, false>::do_thousands_sep() const {return ' ';}
string moneypunct<char, false>::do_grouping() const { return _S_empty_string; }
string moneypunct<char, false>::do_curr_symbol() const { return _S_empty_string; }
string moneypunct<char, false>::do_positive_sign() const { return _S_empty_string; }
string moneypunct<char, false>::do_negative_sign() const { return _S_empty_string; }
money_base::pattern moneypunct<char, false>::do_pos_format() const {return _M_pos_format;}
money_base::pattern moneypunct<char, false>::do_neg_format() const {return _M_neg_format;}
int moneypunct<char, false>::do_frac_digits() const {return 0;}
#ifndef _STLP_NO_WCHAR_T
moneypunct<wchar_t, true>::moneypunct(size_t __refs) : locale::facet(__refs)
{ _Init_monetary_formats(_M_pos_format, _M_neg_format); }
moneypunct<wchar_t, true>::~moneypunct() {}
wchar_t moneypunct<wchar_t, true>::do_decimal_point() const {return L' ';}
wchar_t moneypunct<wchar_t, true>::do_thousands_sep() const {return L' ';}
string moneypunct<wchar_t, true>::do_grouping() const {return _S_empty_string;}
wstring moneypunct<wchar_t, true>::do_curr_symbol() const
{return _S_empty_wstring;}
wstring moneypunct<wchar_t, true>::do_positive_sign() const
{return _S_empty_wstring;}
wstring moneypunct<wchar_t, true>::do_negative_sign() const
{return _S_empty_wstring;}
int moneypunct<wchar_t, true>::do_frac_digits() const {return 0;}
money_base::pattern moneypunct<wchar_t, true>::do_pos_format() const
{return _M_pos_format;}
money_base::pattern moneypunct<wchar_t, true>::do_neg_format() const
{return _M_neg_format;}
moneypunct<wchar_t, false>::moneypunct(size_t __refs) : locale::facet(__refs)
{ _Init_monetary_formats(_M_pos_format, _M_neg_format); }
moneypunct<wchar_t, false>::~moneypunct() {}
wchar_t moneypunct<wchar_t, false>::do_decimal_point() const {return L' ';}
wchar_t moneypunct<wchar_t, false>::do_thousands_sep() const {return L' ';}
string moneypunct<wchar_t, false>::do_grouping() const { return _S_empty_string;}
wstring moneypunct<wchar_t, false>::do_curr_symbol() const
{return _S_empty_wstring;}
wstring moneypunct<wchar_t, false>::do_positive_sign() const
{return _S_empty_wstring;}
wstring moneypunct<wchar_t, false>::do_negative_sign() const
{return _S_empty_wstring;}
int moneypunct<wchar_t, false>::do_frac_digits() const {return 0;}
money_base::pattern moneypunct<wchar_t, false>::do_pos_format() const
{return _M_pos_format;}
money_base::pattern moneypunct<wchar_t, false>::do_neg_format() const
{return _M_neg_format;}
#endif /* WCHAR_T */
//
// Instantiations
//
#if !defined (_STLP_NO_FORCE_INSTANTIATE)
template class _STLP_CLASS_DECLSPEC money_get<char, istreambuf_iterator<char, char_traits<char> > >;
template class _STLP_CLASS_DECLSPEC money_put<char, ostreambuf_iterator<char, char_traits<char> > >;
// template class money_put<char, char*>;
# ifndef _STLP_NO_WCHAR_T
template class _STLP_CLASS_DECLSPEC money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
template class _STLP_CLASS_DECLSPEC money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
// template class money_put<wchar_t, wchar_t*>;
// template class money_get<wchar_t, const wchar_t*>;
# endif
#endif
#if !defined (_STLP_STATIC_CONST_INIT_BUG) && !defined (_STLP_NO_STATIC_CONST_DEFINITION)
const bool moneypunct<char, true>::intl;
const bool moneypunct<char, false>::intl;
# ifndef _STLP_NO_WCHAR_T
const bool moneypunct<wchar_t, true>::intl;
const bool moneypunct<wchar_t, false>::intl;
# endif
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

120
extern/STLport/5.2.1/src/num_get.cpp vendored Normal file
View File

@@ -0,0 +1,120 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
#include <istream>
#include <algorithm>
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// __valid_grouping compares two strings, one representing the
// group sizes encountered when reading an integer, and the other
// representing the valid group sizes as returned by the numpunct
// grouping() member function. Both are interpreted right-to-left.
// The grouping string is treated as if it were extended indefinitely
// with its last value. For a grouping to be valid, each term in
// the first string must be equal to the corresponding term in the
// second, except for the last, which must be less than or equal.
// boris : this takes reversed first string !
bool _STLP_CALL
__valid_grouping(const char * first1, const char * last1,
const char * first2, const char * last2) {
if (first1 == last1 || first2 == last2) return true;
--last1; --last2;
while (first1 != last1) {
if (*last1 != *first2)
return false;
--last1;
if (first2 != last2) ++first2;
}
return *last1 <= *first2;
}
_STLP_DECLSPEC unsigned char _STLP_CALL __digit_val_table(unsigned __index) {
static const unsigned char __val_table[128] = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,10,11,12,13,14,15,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
return __val_table[__index];
}
_STLP_DECLSPEC const char* _STLP_CALL __narrow_atoms()
{ return "+-0xX"; }
// index is actually a char
#if !defined (_STLP_NO_WCHAR_T)
// Similar, except return the character itself instead of the numeric
// value. Used for floating-point input.
bool _STLP_CALL __get_fdigit(wchar_t& c, const wchar_t* digits) {
const wchar_t* p = find(digits, digits + 10, c);
if (p != digits + 10) {
c = (char)('0' + (p - digits));
return true;
}
else
return false;
}
bool _STLP_CALL __get_fdigit_or_sep(wchar_t& c, wchar_t sep,
const wchar_t * digits) {
if (c == sep) {
c = (char)',';
return true;
}
else
return __get_fdigit(c, digits);
}
#endif
_STLP_MOVE_TO_STD_NAMESPACE
#if !defined(_STLP_NO_FORCE_INSTANTIATE)
//----------------------------------------------------------------------
// Force instantiation of num_get<>
template class _STLP_CLASS_DECLSPEC istreambuf_iterator<char, char_traits<char> >;
// template class num_get<char, const char*>;
template class num_get<char, istreambuf_iterator<char, char_traits<char> > >;
# if !defined (_STLP_NO_WCHAR_T)
template class _STLP_CLASS_DECLSPEC istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
template class num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
// template class num_get<wchar_t, const wchar_t*>;
# endif
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

View File

@@ -0,0 +1,883 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <limits>
#include <locale>
#include <istream>
#if (defined (__GNUC__) && !defined (__sun) && !defined (__hpux)) || \
defined (__DMC__)
# include <stdint.h>
#endif
#if defined (__linux__) || defined (__MINGW32__) || defined (__CYGWIN__) || \
defined (__BORLANDC__) || defined (__DMC__) || defined (__HP_aCC)
# if defined (__BORLANDC__)
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
# endif
union _ll {
uint64_t i64;
struct {
# if defined (_STLP_BIG_ENDIAN)
uint32_t hi;
uint32_t lo;
# elif defined (_STLP_LITTLE_ENDIAN)
uint32_t lo;
uint32_t hi;
# else
# error Unknown endianess
# endif
} i32;
};
# if defined (__linux__)
# include <ieee754.h>
# else
union ieee854_long_double {
long double d;
/* This is the IEEE 854 double-extended-precision format. */
struct {
unsigned int mantissa1:32;
unsigned int mantissa0:32;
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
} ieee;
};
# define IEEE854_LONG_DOUBLE_BIAS 0x3fff
# endif
#endif
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
//----------------------------------------------------------------------
// num_get
// Helper functions for _M_do_get_float.
#if !defined (_STLP_NO_WCHAR_T)
void _STLP_CALL
_Initialize_get_float( const ctype<wchar_t>& ct,
wchar_t& Plus, wchar_t& Minus,
wchar_t& pow_e, wchar_t& pow_E,
wchar_t* digits) {
char ndigits[11] = "0123456789";
Plus = ct.widen('+');
Minus = ct.widen('-');
pow_e = ct.widen('e');
pow_E = ct.widen('E');
ct.widen(ndigits + 0, ndigits + 10, digits);
}
#endif /* WCHAR_T */
/*
* __string_to_double is just lifted from atof, the difference being
* that we just use '.' for the decimal point, rather than let it
* be taken from the current C locale, which of course is not accessible
* to us.
*/
#if defined (_STLP_MSVC) || defined (__BORLANDC__) || defined (__ICL)
typedef unsigned long uint32;
typedef unsigned __int64 uint64;
# define ULL(x) x##Ui64
#elif defined (__unix) || defined (__MINGW32__) || \
(defined (__DMC__) && (__LONGLONG)) || defined (__WATCOMC__)
typedef uint32_t uint32;
typedef uint64_t uint64;
# define ULL(x) x##ULL
#else
# error There should be some unsigned 64-bit integer on the system!
#endif
// Multiplication of two 64-bit integers, giving a 128-bit result.
// Taken from Algorithm M in Knuth section 4.3.1, with the loop
// hand-unrolled.
static void _Stl_mult64(const uint64 u, const uint64 v,
uint64& high, uint64& low) {
const uint64 low_mask = ULL(0xffffffff);
const uint64 u0 = u & low_mask;
const uint64 u1 = u >> 32;
const uint64 v0 = v & low_mask;
const uint64 v1 = v >> 32;
uint64 t = u0 * v0;
low = t & low_mask;
t = u1 * v0 + (t >> 32);
uint64 w1 = t & low_mask;
uint64 w2 = t >> 32;
uint64 x = u0 * v1 + w1;
low += (x & low_mask) << 32;
high = u1 * v1 + w2 + (x >> 32);
}
#ifndef __linux__
# define bit11 ULL(0x7ff)
# define exponent_mask (bit11 << 52)
# if !defined (__GNUC__) || (__GNUC__ != 3) || (__GNUC_MINOR__ != 4) || \
(!defined (__CYGWIN__) && !defined (__MINGW32__))
//Generate bad code when compiled with -O2 option.
inline
# endif
void _Stl_set_exponent(uint64 &val, uint64 exp)
{ val = (val & ~exponent_mask) | ((exp & bit11) << 52); }
#endif // __linux__
/* Power of ten fractions for tenscale*/
/* The constants are factored so that at most two constants
* and two multiplies are needed. Furthermore, one of the constants
* is represented exactly - 10**n where 1<= n <= 27.
*/
static const uint64 _Stl_tenpow[80] = {
ULL(0xa000000000000000), /* _Stl_tenpow[0]=(10**1)/(2**4) */
ULL(0xc800000000000000), /* _Stl_tenpow[1]=(10**2)/(2**7) */
ULL(0xfa00000000000000), /* _Stl_tenpow[2]=(10**3)/(2**10) */
ULL(0x9c40000000000000), /* _Stl_tenpow[3]=(10**4)/(2**14) */
ULL(0xc350000000000000), /* _Stl_tenpow[4]=(10**5)/(2**17) */
ULL(0xf424000000000000), /* _Stl_tenpow[5]=(10**6)/(2**20) */
ULL(0x9896800000000000), /* _Stl_tenpow[6]=(10**7)/(2**24) */
ULL(0xbebc200000000000), /* _Stl_tenpow[7]=(10**8)/(2**27) */
ULL(0xee6b280000000000), /* _Stl_tenpow[8]=(10**9)/(2**30) */
ULL(0x9502f90000000000), /* _Stl_tenpow[9]=(10**10)/(2**34) */
ULL(0xba43b74000000000), /* _Stl_tenpow[10]=(10**11)/(2**37) */
ULL(0xe8d4a51000000000), /* _Stl_tenpow[11]=(10**12)/(2**40) */
ULL(0x9184e72a00000000), /* _Stl_tenpow[12]=(10**13)/(2**44) */
ULL(0xb5e620f480000000), /* _Stl_tenpow[13]=(10**14)/(2**47) */
ULL(0xe35fa931a0000000), /* _Stl_tenpow[14]=(10**15)/(2**50) */
ULL(0x8e1bc9bf04000000), /* _Stl_tenpow[15]=(10**16)/(2**54) */
ULL(0xb1a2bc2ec5000000), /* _Stl_tenpow[16]=(10**17)/(2**57) */
ULL(0xde0b6b3a76400000), /* _Stl_tenpow[17]=(10**18)/(2**60) */
ULL(0x8ac7230489e80000), /* _Stl_tenpow[18]=(10**19)/(2**64) */
ULL(0xad78ebc5ac620000), /* _Stl_tenpow[19]=(10**20)/(2**67) */
ULL(0xd8d726b7177a8000), /* _Stl_tenpow[20]=(10**21)/(2**70) */
ULL(0x878678326eac9000), /* _Stl_tenpow[21]=(10**22)/(2**74) */
ULL(0xa968163f0a57b400), /* _Stl_tenpow[22]=(10**23)/(2**77) */
ULL(0xd3c21bcecceda100), /* _Stl_tenpow[23]=(10**24)/(2**80) */
ULL(0x84595161401484a0), /* _Stl_tenpow[24]=(10**25)/(2**84) */
ULL(0xa56fa5b99019a5c8), /* _Stl_tenpow[25]=(10**26)/(2**87) */
ULL(0xcecb8f27f4200f3a), /* _Stl_tenpow[26]=(10**27)/(2**90) */
ULL(0xd0cf4b50cfe20766), /* _Stl_tenpow[27]=(10**55)/(2**183) */
ULL(0xd2d80db02aabd62c), /* _Stl_tenpow[28]=(10**83)/(2**276) */
ULL(0xd4e5e2cdc1d1ea96), /* _Stl_tenpow[29]=(10**111)/(2**369) */
ULL(0xd6f8d7509292d603), /* _Stl_tenpow[30]=(10**139)/(2**462) */
ULL(0xd910f7ff28069da4), /* _Stl_tenpow[31]=(10**167)/(2**555) */
ULL(0xdb2e51bfe9d0696a), /* _Stl_tenpow[32]=(10**195)/(2**648) */
ULL(0xdd50f1996b947519), /* _Stl_tenpow[33]=(10**223)/(2**741) */
ULL(0xdf78e4b2bd342cf7), /* _Stl_tenpow[34]=(10**251)/(2**834) */
ULL(0xe1a63853bbd26451), /* _Stl_tenpow[35]=(10**279)/(2**927) */
ULL(0xe3d8f9e563a198e5), /* _Stl_tenpow[36]=(10**307)/(2**1020) */
// /* _Stl_tenpow[36]=(10**335)/(2**) */
// /* _Stl_tenpow[36]=(10**335)/(2**) */
ULL(0xfd87b5f28300ca0e), /* _Stl_tenpow[37]=(10**-28)/(2**-93) */
ULL(0xfb158592be068d2f), /* _Stl_tenpow[38]=(10**-56)/(2**-186) */
ULL(0xf8a95fcf88747d94), /* _Stl_tenpow[39]=(10**-84)/(2**-279) */
ULL(0xf64335bcf065d37d), /* _Stl_tenpow[40]=(10**-112)/(2**-372) */
ULL(0xf3e2f893dec3f126), /* _Stl_tenpow[41]=(10**-140)/(2**-465) */
ULL(0xf18899b1bc3f8ca2), /* _Stl_tenpow[42]=(10**-168)/(2**-558) */
ULL(0xef340a98172aace5), /* _Stl_tenpow[43]=(10**-196)/(2**-651) */
ULL(0xece53cec4a314ebe), /* _Stl_tenpow[44]=(10**-224)/(2**-744) */
ULL(0xea9c227723ee8bcb), /* _Stl_tenpow[45]=(10**-252)/(2**-837) */
ULL(0xe858ad248f5c22ca), /* _Stl_tenpow[46]=(10**-280)/(2**-930) */
ULL(0xe61acf033d1a45df), /* _Stl_tenpow[47]=(10**-308)/(2**-1023) */
ULL(0xe3e27a444d8d98b8), /* _Stl_tenpow[48]=(10**-336)/(2**-1116) */
ULL(0xe1afa13afbd14d6e) /* _Stl_tenpow[49]=(10**-364)/(2**-1209) */
};
static const short _Stl_twoexp[80] = {
4,7,10,14,17,20,24,27,30,34,37,40,44,47,50,54,57,60,64,67,70,74,77,80,84,87,90,
183,276,369,462,555,648,741,834,927,1020,
-93,-186,-279,-372,-465,-558,-651,-744,-837,-930,-1023,-1116,-1209
};
#define TEN_1 0 /* offset to 10 ** 1 */
#define TEN_27 26 /* offset to 10 ** 27 */
#define TEN_M28 37 /* offset to 10 ** -28 */
#define NUM_HI_P 11
#define NUM_HI_N 13
#define _Stl_HIBITULL (ULL(1) << 63)
static void _Stl_norm_and_round(uint64& p, int& norm, uint64 prodhi, uint64 prodlo) {
norm = 0;
if ((prodhi & _Stl_HIBITULL) == 0) {
/* leading bit is a zero
* may have to normalize
*/
if ((prodhi == ~_Stl_HIBITULL) &&
((prodlo >> 62) == 0x3)) { /* normalization followed by round
* would cause carry to create
* extra bit, so don't normalize
*/
p = _Stl_HIBITULL;
return;
}
p = (prodhi << 1) | (prodlo >> 63); /* normalize */
norm = 1;
prodlo <<= 1;
}
else {
p = prodhi;
}
if ((prodlo & _Stl_HIBITULL) != 0) { /* first guard bit a one */
if (((p & 0x1) != 0) ||
prodlo != _Stl_HIBITULL ) { /* not borderline for round to even */
/* round */
++p;
if (p == 0)
++p;
}
}
}
// Convert a 64-bitb fraction * 10^exp to a 64-bit fraction * 2^bexp.
// p: 64-bit fraction
// exp: base-10 exponent
// bexp: base-2 exponent (output parameter)
static void _Stl_tenscale(uint64& p, int exp, int& bexp) {
bexp = 0;
if ( exp == 0 ) { /* no scaling needed */
return;
}
int exp_hi = 0, exp_lo = exp; /* exp = exp_hi*32 + exp_lo */
int tlo = TEN_1, thi; /* offsets in power of ten table */
int num_hi; /* number of high exponent powers */
if (exp > 0) { /* split exponent */
if (exp_lo > 27) {
exp_lo++;
while (exp_lo > 27) {
exp_hi++;
exp_lo -= 28;
}
}
thi = TEN_27;
num_hi = NUM_HI_P;
} else { // exp < 0
while (exp_lo < 0) {
exp_hi++;
exp_lo += 28;
}
thi = TEN_M28;
num_hi = NUM_HI_N;
}
uint64 prodhi, prodlo; /* 128b product */
int norm; /* number of bits of normalization */
int hi, lo; /* offsets in power of ten table */
while (exp_hi) { /* scale */
hi = (min) (exp_hi, num_hi); /* only a few large powers of 10 */
exp_hi -= hi; /* could iterate in extreme case */
hi += thi-1;
_Stl_mult64(p, _Stl_tenpow[hi], prodhi, prodlo);
_Stl_norm_and_round(p, norm, prodhi, prodlo);
bexp += _Stl_twoexp[hi] - norm;
}
if (exp_lo) {
lo = tlo + exp_lo -1;
_Stl_mult64(p, _Stl_tenpow[lo], prodhi, prodlo);
_Stl_norm_and_round(p, norm, prodhi, prodlo);
bexp += _Stl_twoexp[lo] - norm;
}
return;
}
// First argument is a buffer of values from 0 to 9, NOT ascii.
// Second argument is number of digits in buffer, 1 <= digits <= 17.
// Third argument is base-10 exponent.
/* IEEE representation */
#if !defined (__linux__)
union _Double_rep {
uint64 ival;
double val;
};
static double _Stl_atod(char *buffer, ptrdiff_t ndigit, int dexp) {
typedef numeric_limits<double> limits;
_Double_rep drep;
uint64 &value = drep.ival; /* Value develops as follows:
* 1) decimal digits as an integer
* 2) left adjusted fraction
* 3) right adjusted fraction
* 4) exponent and fraction
*/
uint32 guard; /* First guard bit */
uint64 rest; /* Remaining guard bits */
int bexp; /* binary exponent */
int nzero; /* number of non-zero bits */
int sexp; /* scaling exponent */
char *bufferend; /* pointer to char after last digit */
/* Convert the decimal digits to a binary integer. */
bufferend = buffer + ndigit;
value = 0;
while (buffer < bufferend) {
value *= 10;
value += *buffer++;
}
/* Check for zero and treat it as a special case */
if (value == 0) {
return 0.0;
}
/* Normalize value */
bexp = 64; /* convert from 64b int to fraction */
/* Count number of non-zeroes in value */
nzero = 0;
if ((value >> 32) != 0) { nzero = 32; } //*TY 03/25/2000 - added explicit comparison to zero to avoid uint64 to bool conversion operator
if ((value >> (16 + nzero)) != 0) { nzero += 16; }
if ((value >> ( 8 + nzero)) != 0) { nzero += 8; }
if ((value >> ( 4 + nzero)) != 0) { nzero += 4; }
if ((value >> ( 2 + nzero)) != 0) { nzero += 2; }
if ((value >> ( 1 + nzero)) != 0) { nzero += 1; }
if ((value >> ( nzero)) != 0) { nzero += 1; }
/* Normalize */
value <<= /*(uint64)*/ (64 - nzero); //*TY 03/25/2000 - removed extraneous cast to uint64
bexp -= 64 - nzero;
/* At this point we have a 64b fraction and a binary exponent
* but have yet to incorporate the decimal exponent.
*/
/* multiply by 10^dexp */
_Stl_tenscale(value, dexp, sexp);
bexp += sexp;
if (bexp <= -1022) { /* HI denorm or underflow */
bexp += 1022;
if (bexp < -53) { /* guaranteed underflow */
value = 0;
}
else { /* denorm or possible underflow */
int lead0 = 12 - bexp; /* 12 sign and exponent bits */
/* we must special case right shifts of more than 63 */
if (lead0 > 64) {
rest = value;
guard = 0;
value = 0;
}
else if (lead0 == 64) {
rest = value & ((ULL(1)<< 63)-1);
guard = (uint32) ((value>> 63) & 1 );
value = 0;
}
else {
rest = value & (((ULL(1) << lead0)-1)-1);
guard = (uint32) (((value>> lead0)-1) & 1);
value >>= /*(uint64)*/ lead0; /* exponent is zero */
}
/* Round */
if (guard && ((value & 1) || rest) ) {
++value;
if (value == (ULL(1) << (limits::digits - 1))) { /* carry created normal number */
value = 0;
_Stl_set_exponent(value, 1);
}
}
}
}
else { /* not zero or denorm */
/* Round to 53 bits */
rest = value & ((1 << 10) - 1);
value >>= 10;
guard = (uint32) value & 1;
value >>= 1;
/* value&1 guard rest Action
*
* dc 0 dc none
* 1 1 dc round
* 0 1 0 none
* 0 1 !=0 round
*/
if (guard) {
if (((value&1)!=0) || (rest!=0)) {
++value; /* round */
if ((value >> 53) != 0) { /* carry all the way across */
value >>= 1; /* renormalize */
++bexp;
}
}
}
/*
* Check for overflow
* IEEE Double Precision Format
* (From Table 7-8 of Kane and Heinrich)
*
* Fraction bits 52
* Emax +1023
* Emin -1022
* Exponent bias +1023
* Exponent bits 11
* Integer bit hidden
* Total width in bits 64
*/
if (bexp > limits::max_exponent) { /* overflow */
return limits::infinity();
}
else { /* value is normal */
value &= ~(ULL(1) << (limits::digits - 1)); /* hide hidden bit */
_Stl_set_exponent(value, bexp + 1022); /* add bias */
}
}
_STLP_STATIC_ASSERT(sizeof(uint64) >= sizeof(double))
return drep.val;
}
#endif
#if defined (__linux__) || defined (__MINGW32__) || defined (__CYGWIN__) || \
defined (__BORLANDC__) || defined (__DMC__) || defined (__HP_aCC)
template <class D, class IEEE, int M, int BIAS>
D _Stl_atodT(char *buffer, ptrdiff_t ndigit, int dexp)
{
typedef numeric_limits<D> limits;
/* Convert the decimal digits to a binary integer. */
char *bufferend = buffer + ndigit; /* pointer to char after last digit */
_ll vv;
vv.i64 = 0L;
while ( buffer < bufferend ) {
vv.i64 *= 10;
vv.i64 += *buffer++;
}
if ( vv.i64 == ULL(0) ) { /* Check for zero and treat it as a special case */
return D(0.0);
}
/* Normalize value */
int bexp = 64; /* convert from 64b int to fraction */
/* Count number of non-zeroes in value */
int nzero = 0;
if ((vv.i64 >> 32) != 0) { nzero = 32; }
if ((vv.i64 >> (16 + nzero)) != 0) { nzero += 16; }
if ((vv.i64 >> ( 8 + nzero)) != 0) { nzero += 8; }
if ((vv.i64 >> ( 4 + nzero)) != 0) { nzero += 4; }
if ((vv.i64 >> ( 2 + nzero)) != 0) { nzero += 2; }
if ((vv.i64 >> ( 1 + nzero)) != 0) { nzero += 1; }
if ((vv.i64 >> ( nzero)) != 0) { nzero += 1; }
/* Normalize */
nzero = 64 - nzero;
vv.i64 <<= nzero; // * TY 03/25/2000 - removed extraneous cast to uint64
bexp -= nzero;
/* At this point we have a 64b fraction and a binary exponent
* but have yet to incorporate the decimal exponent.
*/
/* multiply by 10^dexp */
int sexp;
_Stl_tenscale(vv.i64, dexp, sexp);
bexp += sexp;
if ( bexp >= limits::min_exponent ) { /* not zero or denorm */
if ( limits::digits < 64 ) {
/* Round to (64 - M + 1) bits */
uint64_t rest = vv.i64 & ((~ULL(0) / ULL(2)) >> (limits::digits - 1));
vv.i64 >>= M - 2;
uint32_t guard = (uint32) vv.i64 & 1;
vv.i64 >>= 1;
/* value&1 guard rest Action
*
* dc 0 dc none
* 1 1 dc round
* 0 1 0 none
* 0 1 !=0 round
*/
if (guard) {
if ( ((vv.i64 & 1) != 0) || (rest != 0) ) {
vv.i64++; /* round */
if ( (vv.i64 >> (limits::digits < 64 ? limits::digits : 0)) != 0 ) { /* carry all the way across */
vv.i64 >>= 1; /* renormalize */
++bexp;
}
}
}
vv.i64 &= ~(ULL(1) << (limits::digits - 1)); /* hide hidden bit */
}
/*
* Check for overflow
* IEEE Double Precision Format
* (From Table 7-8 of Kane and Heinrich)
*
* Fraction bits 52
* Emax +1023
* Emin -1022
* Exponent bias +1023
* Exponent bits 11
* Integer bit hidden
* Total width in bits 64
*/
if (bexp > limits::max_exponent) { /* overflow */
return limits::infinity();
}
/* value is normal */
IEEE v;
v.ieee.mantissa0 = vv.i32.hi;
v.ieee.mantissa1 = vv.i32.lo;
v.ieee.negative = 0;
v.ieee.exponent = bexp + BIAS - 1;
return v.d;
}
/* HI denorm or underflow */
bexp += BIAS - 1;
if (bexp < -limits::digits) { /* guaranteed underflow */
vv.i64 = 0;
} else { /* denorm or possible underflow */
/*
* Problem point for long double: looks like this code reflect shareing of mantissa
* and exponent in 64b int; not so for long double
*/
int lead0 = M - bexp; /* M = 12 sign and exponent bits */
uint64_t rest;
uint32_t guard;
/* we must special case right shifts of more than 63 */
if (lead0 > 64) {
rest = vv.i64;
guard = 0;
vv.i64 = 0;
} else if (lead0 == 64) {
rest = vv.i64 & ((ULL(1) << 63)-1);
guard = (uint32) ((vv.i64 >> 63) & 1 );
vv.i64 = 0;
} else {
rest = vv.i64 & (((ULL(1) << lead0)-1)-1);
guard = (uint32) (((vv.i64 >> lead0)-1) & 1);
vv.i64 >>= /*(uint64)*/ lead0; /* exponent is zero */
}
/* Round */
if (guard && ( (vv.i64 & 1) || rest)) {
vv.i64++;
if (vv.i64 == (ULL(1) << (limits::digits - 1))) { /* carry created normal number */
IEEE v;
v.ieee.mantissa0 = 0;
v.ieee.mantissa1 = 0;
v.ieee.negative = 0;
v.ieee.exponent = 1;
return v.d;
}
}
}
IEEE v;
v.ieee.mantissa0 = vv.i32.hi;
v.ieee.mantissa1 = vv.i32.lo;
v.ieee.negative = 0;
v.ieee.exponent = 0;
return v.d;
}
#endif // __linux__
#ifndef __linux__
static double _Stl_string_to_double(const char *s) {
typedef numeric_limits<double> limits;
const int max_digits = limits::digits10 + 2;
unsigned c;
unsigned Negate, decimal_point;
char *d;
int exp;
int dpchar;
char digits[max_digits];
c = *s++;
/* process sign */
Negate = 0;
if (c == '+') {
c = *s++;
} else if (c == '-') {
Negate = 1;
c = *s++;
}
d = digits;
dpchar = '.' - '0';
decimal_point = 0;
exp = 0;
for (;;) {
c -= '0';
if (c < 10) {
if (d == digits + max_digits) {
/* ignore more than max_digits digits, but adjust exponent */
exp += (decimal_point ^ 1);
} else {
if (c == 0 && d == digits) {
/* ignore leading zeros */
} else {
*d++ = (char) c;
}
exp -= decimal_point;
}
} else if (c == (unsigned int) dpchar && !decimal_point) { /* INTERNATIONAL */
decimal_point = 1;
} else {
break;
}
c = *s++;
}
/* strtod cant return until it finds the end of the exponent */
if (d == digits) {
return 0.0;
}
if (c == 'e' - '0' || c == 'E' - '0') {
register unsigned negate_exp = 0;
register int e = 0;
c = *s++;
if (c == '+' || c == ' ') {
c = *s++;
} else if (c == '-') {
negate_exp = 1;
c = *s++;
}
if (c -= '0', c < 10) {
do {
e = e * 10 + (int)c;
c = *s++;
} while (c -= '0', c < 10);
if (negate_exp) {
e = -e;
}
exp += e;
}
}
double x;
ptrdiff_t n = d - digits;
if ((exp + n - 1) < limits::min_exponent10) {
x = 0;
}
else if ((exp + n - 1) > limits::max_exponent10) {
x = limits::infinity();
}
else {
/* Let _Stl_atod diagnose under- and over-flows.
* If the input was == 0.0, we have already returned,
* so retval of +-Inf signals OVERFLOW, 0.0 UNDERFLOW */
x = _Stl_atod(digits, n, exp);
}
if (Negate) {
x = -x;
}
return x;
}
#endif
#if defined (__linux__) || defined (__MINGW32__) || defined (__CYGWIN__) || \
defined (__BORLANDC__) || defined (__DMC__) || defined (__HP_aCC)
template <class D, class IEEE, int M, int BIAS>
D _Stl_string_to_doubleT(const char *s)
{
typedef numeric_limits<D> limits;
const int max_digits = limits::digits10; /* + 2 17 */;
unsigned c;
unsigned decimal_point;
char *d;
int exp;
D x;
int dpchar;
char digits[max_digits];
c = *s++;
/* process sign */
bool Negate = false;
if (c == '+') {
c = *s++;
} else if (c == '-') {
Negate = true;
c = *s++;
}
d = digits;
dpchar = '.' - '0';
decimal_point = 0;
exp = 0;
for (;;) {
c -= '0';
if (c < 10) {
if (d == digits + max_digits) {
/* ignore more than max_digits digits, but adjust exponent */
exp += (decimal_point ^ 1);
} else {
if (c == 0 && d == digits) {
/* ignore leading zeros */
} else {
*d++ = (char) c;
}
exp -= decimal_point;
}
} else if (c == (unsigned int) dpchar && !decimal_point) { /* INTERNATIONAL */
decimal_point = 1;
} else {
break;
}
c = *s++;
}
/* strtod cant return until it finds the end of the exponent */
if (d == digits) {
return D(0.0);
}
if (c == 'e'-'0' || c == 'E'-'0') {
bool negate_exp = false;
register int e = 0;
c = *s++;
if (c == '+' || c == ' ') {
c = *s++;
} else if (c == '-') {
negate_exp = true;
c = *s++;
}
if (c -= '0', c < 10) {
do {
e = e * 10 + (int)c;
c = *s++;
} while (c -= '0', c < 10);
if (negate_exp) {
e = -e;
}
exp += e;
}
}
ptrdiff_t n = d - digits;
if ((exp + n - 1) < limits::min_exponent10) {
return D(0.0); // +0.0 is the same as -0.0
} else if ((exp + n - 1) > limits::max_exponent10 ) {
// not good, because of x = -x below; this may lead to portability problems
x = limits::infinity();
} else {
/* let _Stl_atod diagnose under- and over-flows */
/* if the input was == 0.0, we have already returned,
so retval of +-Inf signals OVERFLOW, 0.0 UNDERFLOW
*/
x = _Stl_atodT<D,IEEE,M,BIAS>(digits, n, exp);
}
return Negate ? -x : x;
}
#endif // __linux__
void _STLP_CALL
__string_to_float(const __iostring& v, float& val)
{
#if !defined (__linux__)
val = (float)_Stl_string_to_double(v.c_str());
#else
val = (float)_Stl_string_to_doubleT<double,ieee754_double,12,IEEE754_DOUBLE_BIAS>(v.c_str());
#endif
}
void _STLP_CALL
__string_to_float(const __iostring& v, double& val)
{
#if !defined (__linux__)
val = _Stl_string_to_double(v.c_str());
#else
val = _Stl_string_to_doubleT<double,ieee754_double,12,IEEE754_DOUBLE_BIAS>(v.c_str());
#endif
}
#if !defined (_STLP_NO_LONG_DOUBLE)
void _STLP_CALL
__string_to_float(const __iostring& v, long double& val) {
#if !defined (__linux__) && !defined (__MINGW32__) && !defined (__CYGWIN__) && \
!defined (__BORLANDC__) && !defined (__DMC__) && !defined (__HP_aCC)
//The following function is valid only if long double is an alias for double.
_STLP_STATIC_ASSERT( sizeof(long double) <= sizeof(double) )
val = _Stl_string_to_double(v.c_str());
#else
val = _Stl_string_to_doubleT<long double,ieee854_long_double,16,IEEE854_LONG_DOUBLE_BIAS>(v.c_str());
#endif
}
#endif
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

183
extern/STLport/5.2.1/src/num_put.cpp vendored Normal file
View File

@@ -0,0 +1,183 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
#include <ostream>
_STLP_BEGIN_NAMESPACE
// Note that grouping[0] is the number of digits in the *rightmost* group.
// We assume, without checking, that *last is null and that there is enough
// space in the buffer to extend the number past [first, last).
template <class Char>
static ptrdiff_t
__insert_grouping_aux(Char* first, Char* last, const string& grouping,
Char separator, Char Plus, Char Minus,
int basechars) {
typedef string::size_type str_size;
if (first == last)
return 0;
int sign = 0;
if (*first == Plus || *first == Minus) {
sign = 1;
++first;
}
first += basechars;
Char* cur_group = last; // Points immediately beyond the rightmost
// digit of the current group.
int groupsize = 0; // Size of the current group (if grouping.size() == 0, size
// of group unlimited: we force condition (groupsize <= 0))
for ( str_size n = 0; ; ) { // Index of the current group
if ( n < grouping.size() ) {
groupsize = __STATIC_CAST(int, grouping[n++] );
}
if ((groupsize <= 0) || (groupsize >= cur_group - first) || (groupsize == CHAR_MAX)) {
break;
}
// Insert a separator character just before position cur_group - groupsize
cur_group -= groupsize;
++last;
copy_backward(cur_group, last, last + 1);
*cur_group = separator;
}
return (last - first) + sign + basechars;
}
//Dynamic output buffer version.
template <class Char, class Str>
static void
__insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos,
const string& grouping,
Char separator, Char Plus, Char Minus,
int basechars) {
typedef string::size_type str_size;
if (iostr.size() < __group_pos)
return;
int __first_pos = 0;
Char __first = *iostr.begin();
if (__first == Plus || __first == Minus) {
++__first_pos;
}
__first_pos += basechars;
typename Str::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost
// digit of the current group.
int groupsize = 0; // Size of the current group (if grouping.size() == 0, size
// of group unlimited: we force condition (groupsize <= 0))
for ( str_size n = 0; ; ) { // Index of the current group
if ( n < grouping.size() ) {
groupsize = __STATIC_CAST( int, grouping[n++] );
}
if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) ||
(groupsize == CHAR_MAX)) {
break;
}
// Insert a separator character just before position cur_group - groupsize
cur_group -= groupsize;
cur_group = iostr.insert(cur_group, separator);
}
}
//----------------------------------------------------------------------
// num_put
_STLP_MOVE_TO_PRIV_NAMESPACE
_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo()
{ return "0123456789abcdefx"; }
_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi()
{ return "0123456789ABCDEFX"; }
char* _STLP_CALL
__write_integer(char* buf, ios_base::fmtflags flags, long x) {
char tmp[64];
char* bufend = tmp+64;
char* beg = __write_integer_backward(bufend, flags, x);
return copy(beg, bufend, buf);
}
///-------------------------------------
ptrdiff_t _STLP_CALL
__insert_grouping(char * first, char * last, const string& grouping,
char separator, char Plus, char Minus, int basechars) {
return __insert_grouping_aux(first, last, grouping,
separator, Plus, Minus, basechars);
}
void _STLP_CALL
__insert_grouping(__iostring &str, size_t group_pos, const string& grouping,
char separator, char Plus, char Minus, int basechars) {
__insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
}
#if !defined (_STLP_NO_WCHAR_T)
ptrdiff_t _STLP_CALL
__insert_grouping(wchar_t* first, wchar_t* last, const string& grouping,
wchar_t separator, wchar_t Plus, wchar_t Minus,
int basechars) {
return __insert_grouping_aux(first, last, grouping, separator,
Plus, Minus, basechars);
}
void _STLP_CALL
__insert_grouping(__iowstring &str, size_t group_pos, const string& grouping,
wchar_t separator, wchar_t Plus, wchar_t Minus,
int basechars) {
__insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
}
#endif
_STLP_MOVE_TO_STD_NAMESPACE
//----------------------------------------------------------------------
// Force instantiation of num_put<>
#if !defined(_STLP_NO_FORCE_INSTANTIATE)
template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >;
// template class num_put<char, char*>;
template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
# ifndef _STLP_NO_WCHAR_T
template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >;
template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
// template class num_put<wchar_t, wchar_t*>;
# endif /* INSTANTIATE_WIDE_STREAMS */
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

View File

@@ -0,0 +1,918 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <cmath>
#include <ios>
#include <locale>
#if defined (__DECCXX)
# define NDIG 400
#else
# define NDIG 82
#endif
#define todigit(x) ((x)+'0')
#if defined (_STLP_UNIX)
# if defined (__sun)
# include <floatingpoint.h>
# endif
# if defined (__sun) || defined (__digital__) || defined (__sgi) || defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR)
// DEC, SGI & Solaris need this
# include <values.h>
# include <nan.h>
# endif
# if defined (__QNXNTO__) || ( defined(__GNUC__) && defined(__APPLE__) ) || defined(_STLP_USE_UCLIBC) /* 0.9.26 */ || \
defined(__FreeBSD__)
# define USE_SPRINTF_INSTEAD
# endif
# if defined (_AIX) // JFA 3-Aug-2000
# include <math.h>
# include <float.h>
# endif
# include <math.h>
#endif
#include <cstdio>
#include <cstdlib>
#if defined (_STLP_MSVC_LIB) || defined (__MINGW32__) || defined (__BORLANDC__) || defined (__DJGPP) || \
defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR)
# include <float.h>
#endif
#if defined (__MRC__) || defined (__SC__) || defined (_CRAY) //*TY 02/24/2000 - added support for MPW
# include <fp.h>
#endif
#if defined (__CYGWIN__)
# include <ieeefp.h>
#endif
#if defined (__MSL__)
# include <cstdlib> // for atoi
# include <cstdio> // for snprintf
# include <algorithm>
# include <cassert>
#endif
#if defined (__ISCPP__)
# include <cfloat>
#endif
#include <algorithm>
#if defined (__DMC__)
# define snprintf _snprintf
#endif
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
#if defined (__MWERKS__) || defined(__BEOS__)
# define USE_SPRINTF_INSTEAD
#endif
template <int N>
struct _Dig
{
enum { dig = _Dig<N/10>::dig + 1 };
};
_STLP_TEMPLATE_NULL
struct _Dig<0>
{
enum { dig = 0 };
};
#ifdef _STLP_NO_LONG_DOUBLE
# define MAXEDIGITS int(_Dig<DBL_MAX_10_EXP>::dig)
# define MAXFSIG DBL_DIG
# define MAXFCVT (DBL_DIG + 1)
#else
# define MAXEDIGITS int(_Dig<LDBL_MAX_10_EXP>::dig)
# define MAXFSIG LDBL_DIG
# define MAXFCVT (LDBL_DIG + 1)
#endif
// Tests for infinity and NaN differ on different OSs. We encapsulate
// these differences here.
#if !defined (USE_SPRINTF_INSTEAD)
# if defined (__hpux) && defined (__GNUC__)
# define _STLP_USE_SIGN_HELPER
# elif defined (__DJGPP) || (defined (_STLP_USE_GLIBC) && ! defined (__MSL__)) || \
defined (__CYGWIN__) || \
defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || \
defined (__HP_aCC)
static inline bool _Stl_is_nan_or_inf(double x)
# if defined (isfinite)
{ return !isfinite(x); }
# else
{ return !finite(x); }
# endif
static inline bool _Stl_is_neg_nan(double x) { return isnan(x) && ( copysign(1., x) < 0 ); }
static inline bool _Stl_is_inf(double x) { return isinf(x); }
// inline bool _Stl_is_neg_inf(double x) { return isinf(x) < 0; }
static inline bool _Stl_is_neg_inf(double x) { return isinf(x) && x < 0; }
# elif (defined (__unix) || defined (__unix__)) && \
!defined (__APPLE__) && !defined (__DJGPP) && !defined(__osf__) && \
!defined (_CRAY)
static inline bool _Stl_is_nan_or_inf(double x) { return IsNANorINF(x); }
static inline bool _Stl_is_inf(double x) { return IsNANorINF(x) && IsINF(x); }
static inline bool _Stl_is_neg_inf(double x) { return (IsINF(x)) && (x < 0.0); }
static inline bool _Stl_is_neg_nan(double x) { return IsNegNAN(x); }
# elif defined (_STLP_MSVC_LIB) || defined (__MINGW32__) || defined (__BORLANDC__)
static inline bool _Stl_is_nan_or_inf(double x) { return !_finite(x); }
# if !defined (__BORLANDC__)
static inline bool _Stl_is_inf(double x) {
int fclass = _fpclass(x);
return fclass == _FPCLASS_NINF || fclass == _FPCLASS_PINF;
}
static inline bool _Stl_is_neg_inf(double x) { return _fpclass(x) == _FPCLASS_NINF; }
# else
static inline bool _Stl_is_inf(double x) { return _Stl_is_nan_or_inf(x) && !_isnan(x);}
static inline bool _Stl_is_neg_inf(double x) { return _Stl_is_inf(x) && x < 0 ; }
# endif
static inline bool _Stl_is_neg_nan(double x) { return _isnan(x) && _copysign(1., x) < 0 ; }
# if defined (__BORLANDC__)
static inline bool _Stl_is_nan_or_inf(long double x) { return !_finitel(x); }
static inline bool _Stl_is_inf(long double x) { return _Stl_is_nan_or_inf(x) && !_isnanl(x);}
static inline bool _Stl_is_neg_inf(long double x) { return _Stl_is_inf(x) && x < 0 ; }
static inline bool _Stl_is_neg_nan(long double x) { return _isnanl(x) && _copysignl(1.l, x) < 0 ; }
# elif !defined (_STLP_NO_LONG_DOUBLE)
// Simply there to avoid warning long double -> double implicit conversion:
static inline bool _Stl_is_nan_or_inf(long double x) { return _Stl_is_nan_or_inf(__STATIC_CAST(double, x)); }
static inline bool _Stl_is_inf(long double x) { return _Stl_is_inf(__STATIC_CAST(double, x));}
static inline bool _Stl_is_neg_inf(long double x) { return _Stl_is_neg_inf(__STATIC_CAST(double, x)); }
static inline bool _Stl_is_neg_nan(long double x) { return _Stl_is_neg_nan(__STATIC_CAST(double, x)); }
# endif
# elif defined (__MRC__) || defined (__SC__) || defined (__DMC__)
static bool _Stl_is_nan_or_inf(double x) { return isnan(x) || !isfinite(x); }
static bool _Stl_is_inf(double x) { return !isfinite(x); }
static bool _Stl_is_neg_inf(double x) { return !isfinite(x) && signbit(x); }
static bool _Stl_is_neg_nan(double x) { return isnan(x) && signbit(x); }
# elif /* defined(__FreeBSD__) || defined(__OpenBSD__) || */ (defined(__GNUC__) && defined(__APPLE__))
static inline bool _Stl_is_nan_or_inf(double x) { return !finite(x); }
static inline bool _Stl_is_inf(double x) { return _Stl_is_nan_or_inf(x) && ! isnan(x); }
static inline bool _Stl_is_neg_inf(double x) { return _Stl_is_inf(x) && x < 0 ; }
static inline bool _Stl_is_neg_nan(double x) { return isnan(x) && copysign(1., x) < 0 ; }
# elif defined( _AIX ) // JFA 11-Aug-2000
static bool _Stl_is_nan_or_inf(double x) { return isnan(x) || !finite(x); }
static bool _Stl_is_inf(double x) { return !finite(x); }
// bool _Stl_is_neg_inf(double x) { return _class(x) == FP_MINUS_INF; }
static bool _Stl_is_neg_inf(double x) { return _Stl_is_inf(x) && ( copysign(1., x) < 0 ); }
static bool _Stl_is_neg_nan(double x) { return isnan(x) && ( copysign(1., x) < 0 ); }
# elif defined (__ISCPP__)
static inline bool _Stl_is_nan_or_inf (double x) { return _fp_isINF(x) || _fp_isNAN(x); }
static inline bool _Stl_is_inf (double x) { return _fp_isINF(x); }
static inline bool _Stl_is_neg_inf (double x) { return _fp_isINF(x) && x < 0; }
static inline bool _Stl_is_neg_nan (double x) { return _fp_isNAN(x) && x < 0; }
# elif defined (_CRAY)
# if defined (_CRAYIEEE)
static inline bool _Stl_is_nan_or_inf(double x) { return isnan(x) || isinf(x); }
static inline bool _Stl_is_inf(double x) { return isinf(x); }
static inline bool _Stl_is_neg_inf(double x) { return isinf(x) && signbit(x); }
static inline bool _Stl_is_neg_nan(double x) { return isnan(x) && signbit(x); }
# else
static inline bool _Stl_is_nan_or_inf(double x) { return false; }
static inline bool _Stl_is_inf(double x) { return false; }
static inline bool _Stl_is_neg_inf(double x) { return false; }
static inline bool _Stl_is_neg_nan(double x) { return false; }
# endif
# else // nothing from above
# define USE_SPRINTF_INSTEAD
# endif
#endif // !USE_SPRINTF_INSTEAD
#if !defined (USE_SPRINTF_INSTEAD)
// Reentrant versions of floating-point conversion functions. The argument
// lists look slightly different on different operating systems, so we're
// encapsulating the differences here.
# if defined (__CYGWIN__) || defined(__DJGPP)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf)
{ return ecvtbuf(x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf)
{ return fcvtbuf(x, n, pt, sign, buf); }
# if !defined (_STLP_NO_LONG_DOUBLE)
# if defined (__CYGWIN__)
# define _STLP_EMULATE_LONG_DOUBLE_CVT
# else
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return ecvtbuf(x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return fcvtbuf(x, n, pt, sign, buf); }
# endif
# endif
# elif defined (_STLP_USE_GLIBC)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return ecvt_r(x, n, pt, sign, buf, bsize) == 0 ? buf : 0; }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return fcvt_r(x, n, pt, sign, buf, bsize) == 0 ? buf : 0; }
# ifndef _STLP_NO_LONG_DOUBLE
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return qecvt_r(x, n, pt, sign, buf, bsize) == 0 ? buf : 0; }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return qfcvt_r(x, n, pt, sign, buf, bsize) == 0 ? buf : 0; }
# endif
# define _STLP_NEED_CVT_BUFFER_SIZE
# elif defined (__sun)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf)
{ return econvert(x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf)
{ return fconvert(x, n, pt, sign, buf); }
# ifndef _STLP_NO_LONG_DOUBLE
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return qeconvert(&x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return qfconvert(&x, n, pt, sign, buf); }
# endif
# elif defined (__DECCXX)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return (ecvt_r(x, n, pt, sign, buf, bsize) == 0 ? buf : 0); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return (fcvt_r(x, n, pt, sign, buf, bsize) == 0 ? buf : 0); }
# ifndef _STLP_NO_LONG_DOUBLE
// fbp : no "long double" conversions !
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return (ecvt_r((double)x, n, pt, sign, buf, bsize) == 0 ? buf : 0) ; }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf, size_t bsize)
{ return (fcvt_r((double)x, n, pt, sign, buf, bsize) == 0 ? buf : 0); }
# endif
# define _STLP_NEED_CVT_BUFFER_SIZE
# elif defined (__hpux)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign)
{ return ecvt(x, n, pt, sign); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign)
{ return fcvt(x, n, pt, sign); }
# if !defined (_STLP_NO_LONG_DOUBLE)
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign)
{ return _ldecvt(*(long_double*)&x, n, pt, sign); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign)
{ return _ldfcvt(*(long_double*)&x, n, pt, sign); }
# endif
# define _STLP_CVT_NEED_SYNCHRONIZATION
# elif defined (__unix) && !defined (__APPLE__) && !defined (_CRAY)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf)
{ return ecvt_r(x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf)
{ return fcvt_r(x, n, pt, sign, buf); }
# if !defined (_STLP_NO_LONG_DOUBLE)
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return qecvt_r(x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return qfcvt_r(x, n, pt, sign, buf); }
# endif
# elif defined (_STLP_MSVC_LIB) || defined (__MINGW32__) || defined (__BORLANDC__)
# if defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
# define _STLP_APPEND(a, b) a##b
# define _STLP_BUF_PARAMS , char* buf, size_t bsize
# define _STLP_SECURE_FUN(F, X, N, PT, SIGN) _STLP_APPEND(F, _s)(buf, bsize, X, N, PT, SIGN); return buf
# else
# define _STLP_BUF_PARAMS
# define _STLP_SECURE_FUN(F, X, N, PT, SIGN) return F(X, N, PT, SIGN)
# define _STLP_CVT_NEED_SYNCHRONIZATION
# endif
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign _STLP_BUF_PARAMS)
{ _STLP_SECURE_FUN(_ecvt, x, n, pt, sign); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign _STLP_BUF_PARAMS)
{ _STLP_SECURE_FUN(_fcvt, x, n, pt, sign); }
# if !defined (_STLP_NO_LONG_DOUBLE)
# if defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
# define _STLP_PARAMS , buf, bsize
# else
# define _STLP_PARAMS
# endif
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign _STLP_BUF_PARAMS)
{ return _Stl_ecvtR(__STATIC_CAST(double, x), n, pt, sign _STLP_PARAMS); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign _STLP_BUF_PARAMS)
{ return _Stl_fcvtR(__STATIC_CAST(double, x), n, pt, sign _STLP_PARAMS); }
# undef _STLP_PARAMS
# endif
# undef _STLP_SECURE_FUN
# undef _STLP_BUF_PARAMS
# undef _STLP_APPEND
# if defined (__BORLANDC__) /* || defined (__GNUC__) MinGW do not support 'L' modifier so emulation do not work */
# define _STLP_EMULATE_LONG_DOUBLE_CVT
# endif
# elif defined (__ISCPP__)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf)
{ return _fp_ecvt( x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf)
{ return _fp_fcvt(x, n, pt, sign, buf); }
# if !defined (_STLP_NO_LONG_DOUBLE)
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return _fp_ecvt( x, n, pt, sign, buf); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf)
{ return _fp_fcvt(x, n, pt, sign, buf); }
# endif
# elif defined (_AIX) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || \
defined (__MRC__) || defined (__SC__) || defined (_CRAY) || \
defined (_STLP_SCO_OPENSERVER) || defined (__NCR_SVR) || \
defined (__DMC__)
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign)
{ return ecvt(x, n, pt, sign ); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign)
{ return fcvt(x, n, pt, sign); }
# if !defined (_STLP_NO_LONG_DOUBLE)
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign)
{ return ecvt(x, n, pt, sign ); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign)
{ return fcvt(x, n, pt, sign); }
# endif
# define _STLP_CVT_NEED_SYNCHRONIZATION
# else
# error Missing _Stl_ecvtR and _Stl_fcvtR implementations.
# endif
#if defined (_STLP_CVT_NEED_SYNCHRONIZATION)
/* STLport synchronize access to *cvt functions but those methods might
* be called from outside, in this case we will still have a race condition. */
# if defined (_STLP_THREADS)
static _STLP_STATIC_MUTEX& put_float_mutex() {
static _STLP_STATIC_MUTEX __put_float_mutex _STLP_MUTEX_INITIALIZER;
return __put_float_mutex;
}
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char* buf) {
_STLP_auto_lock lock(put_float_mutex());
strcpy(buf, _Stl_ecvtR(x, n, pt, sign)); return buf;
}
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char* buf) {
_STLP_auto_lock lock(put_float_mutex());
strcpy(buf, _Stl_fcvtR(x, n, pt, sign)); return buf;
}
# if !defined (_STLP_NO_LONG_DOUBLE) && !defined (_STLP_EMULATE_LONG_DOUBLE_CVT)
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf) {
_STLP_auto_lock lock(put_float_mutex());
strcpy(buf, _Stl_ecvtR(x, n, pt, sign)); return buf;
}
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf) {
_STLP_auto_lock lock(put_float_mutex());
strcpy(buf, _Stl_fcvtR(x, n, pt, sign)); return buf;
}
# endif
# else
static inline char* _Stl_ecvtR(double x, int n, int* pt, int* sign, char*)
{ return _Stl_ecvtR(x, n, pt, sign); }
static inline char* _Stl_fcvtR(double x, int n, int* pt, int* sign, char*)
{ return _Stl_fcvtR(x, n, pt, sign); }
# if !defined (_STLP_NO_LONG_DOUBLE) && !defined (_STLP_EMULATE_LONG_DOUBLE_CVT)
static inline char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char*)
{ return _Stl_ecvtR(x, n, pt, sign); }
static inline char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char*)
{ return _Stl_fcvtR(x, n, pt, sign); }
# endif
# endif
#endif
# if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS) && !defined (_STLP_NEED_CVT_BUFFER_SIZE)
# define _STLP_CVT_BUFFER(B) B
# else
# define _STLP_CVT_BUFFER(B) _STLP_ARRAY_AND_SIZE(B)
# endif
# if defined (_STLP_EMULATE_LONG_DOUBLE_CVT)
static void __fill_fmtbuf(char* fmtbuf, ios_base::fmtflags flags, char long_modifier);
// Emulation of ecvt/fcvt functions using sprintf:
static char* _Stl_ecvtR(long double x, int n, int* pt, int* sign, char* buf) {
// If long double value can be safely converted to double without losing precision
// we use the ecvt function for double:
double y = __STATIC_CAST(double, x);
if (x == y)
return _Stl_ecvtR(y, n, pt, sign, buf);
char fmtbuf[32];
__fill_fmtbuf(fmtbuf, 0, 'L');
sprintf(buf, fmtbuf, n, x < 0.0l ? -x : x);
/* We are waiting for something having the form x.xxxe+yyyy */
*pt = 0;
*sign = 0;
int i = -1;
int offset = 0;
while (buf[++i] != 0 && n != 0) {
if (buf[i] >= '0' && buf[i] <= '9') {
--n;
if (offset != 0)
buf[i - offset] = buf[i];
}
else {
if (offset != 0) break;
++offset;
*pt = i;
}
}
if (offset != 0)
buf[i - offset] = 0;
// Extract exponent part in point position:
int e = 0;
while (buf[++i] != 0) {
if (buf[i] >= '0' && buf[i] <= '9') {
e = e * 10 + (buf[i] - '0');
}
}
*pt += e;
return buf;
}
static char* _Stl_fcvtR(long double x, int n, int* pt, int* sign, char* buf) {
// If long double value can be safely converted to double without losing precision
// we use the fcvt function for double:
double y = __STATIC_CAST(double, x);
if (x == y)
return _Stl_fcvtR(y, n, pt, sign, buf);
char fmtbuf[32];
__fill_fmtbuf(fmtbuf, ios_base::fixed, 'L');
sprintf(buf, fmtbuf, n, x < 0.0l ? -x : x);
*pt = 0;
*sign = 0;
int i = -1;
int offset = 0;
while (buf[++i] != 0 && (offset == 0 || n != 0)) {
if (buf[i] >= '0' && buf[i] <= '9') {
if (offset != 0) {
--n;
buf[i - offset] = buf[i];
}
}
else {
++offset;
*pt = i;
}
}
if (offset != 0)
buf[i - offset] = 0;
else
*pt = i;
return buf;
}
#endif
//----------------------------------------------------------------------
// num_put
// __format_float formats a mantissa and exponent as returned by
// one of the conversion functions (ecvt_r, fcvt_r, qecvt_r, qfcvt_r)
// according to the specified precision and format flags. This is
// based on doprnt but is much simpler since it is concerned only
// with floating point input and does not consider all formats. It
// also does not deal with blank padding, which is handled by
// __copy_float_and_fill.
static size_t __format_float_scientific( __iostring& buf, const char *bp,
int decpt, int sign, bool is_zero,
ios_base::fmtflags flags,
int precision) {
// sign if required
if (sign)
buf += '-';
else if (flags & ios_base::showpos)
buf += '+';
// first digit of mantissa
buf += *bp++;
// start of grouping position, grouping won't occur in scientific notation
// as it is impossible to have something like 1234.0e04 but we return a correct
// group position for coherency with __format_float_fixed.
size_t __group_pos = buf.size();
// decimal point if required
if (precision != 0 || flags & ios_base::showpoint) {
buf += '.';
}
// rest of mantissa
while (*bp != 0 && precision--)
buf += *bp++;
// trailing 0 if needed
if (precision > 0)
buf.append(precision, '0');
// exponent size = number of digits + exponent sign + exponent symbol + trailing zero
char expbuf[MAXEDIGITS + 3];
//We start filling at the buffer end
char *suffix = expbuf + MAXEDIGITS + 2;
*suffix = 0;
if (!is_zero) {
int nn = decpt - 1;
if (nn < 0)
nn = -nn;
for (; nn > 9; nn /= 10)
*--suffix = (char) todigit(nn % 10);
*--suffix = (char) todigit(nn);
}
// prepend leading zeros to exponent
// C89 Standard says that it should be at least 2 digits, C99 Standard says that
// we stop prepend zeros if more than 3 digits. To repect both STLport prepend zeros
// until it is 2 digits.
while (suffix > &expbuf[MAXEDIGITS])
*--suffix = '0';
// put in the exponent sign
*--suffix = (char) ((decpt > 0 || is_zero ) ? '+' : '-');
// put in the e
*--suffix = flags & ios_base::uppercase ? 'E' : 'e';
// copy the suffix
buf += suffix;
return __group_pos;
}
static size_t __format_float_fixed( __iostring &buf, const char *bp,
int decpt, int sign,
ios_base::fmtflags flags,
int precision) {
if ( sign && (decpt > -precision) && (*bp != 0) )
buf += '-';
else if ( flags & ios_base::showpos )
buf += '+';
// digits before decimal point
int nnn = decpt;
do {
buf += (nnn <= 0 || *bp == 0) ? '0' : *bp++;
} while ( --nnn > 0 );
// start of grouping position
size_t __group_pos = buf.size();
// decimal point if needed
if ( flags & ios_base::showpoint || precision > 0 ) {
buf += '.';
}
// digits after decimal point if any
while ( *bp != 0 && --precision >= 0 ) {
buf += (++decpt <= 0) ? '0' : *bp++;
}
// trailing zeros if needed
if (precision > 0)
buf.append(precision, '0');
return __group_pos;
}
#if defined (_STLP_USE_SIGN_HELPER)
template<class _FloatT>
struct float_sign_helper {
float_sign_helper(_FloatT __x)
{ _M_number._num = __x; }
bool is_negative() const {
const unsigned short sign_mask(1 << (sizeof(unsigned short) * CHAR_BIT - 1));
return (get_sign_word() & sign_mask) != 0;
}
private:
union {
unsigned short _Words[8];
_FloatT _num;
} _M_number;
unsigned short get_word_higher() const _STLP_NOTHROW
{ return _M_number._Words[0]; }
unsigned short get_word_lower() const _STLP_NOTHROW
{ return _M_number._Words[(sizeof(_FloatT) >= 12 ? 10 : sizeof(_FloatT)) / sizeof(unsigned short) - 1]; }
unsigned short get_sign_word() const _STLP_NOTHROW
# if defined (_STLP_BIG_ENDIAN)
{ return get_word_higher(); }
# else /* _STLP_LITTLE_ENDIAN */
{ return get_word_lower(); }
# endif
};
#endif
template <class _FloatT>
static size_t __format_nan_or_inf(__iostring& buf, _FloatT x, ios_base::fmtflags flags) {
static const char* inf[2] = { "inf", "Inf" };
static const char* nan[2] = { "nan", "NaN" };
const char** inf_or_nan;
#if !defined (_STLP_USE_SIGN_HELPER)
if (_Stl_is_inf(x)) { // Infinity
inf_or_nan = inf;
if (_Stl_is_neg_inf(x))
buf += '-';
else if (flags & ios_base::showpos)
buf += '+';
} else { // NaN
inf_or_nan = nan;
if (_Stl_is_neg_nan(x))
buf += '-';
else if (flags & ios_base::showpos)
buf += '+';
}
#else
typedef numeric_limits<_FloatT> limits;
if (x == limits::infinity() || x == -limits::infinity()) {
inf_or_nan = inf;
} else { // NaN
inf_or_nan = nan;
}
float_sign_helper<_FloatT> helper(x);
if (helper.is_negative())
buf += '-';
else if (flags & ios_base::showpos)
buf += '+';
#endif
size_t ret = buf.size();
buf += inf_or_nan[flags & ios_base::uppercase ? 1 : 0];
return ret;
}
static inline size_t __format_float(__iostring &buf, const char * bp,
int decpt, int sign, bool is_zero,
ios_base::fmtflags flags,
int precision) {
size_t __group_pos = 0;
switch (flags & ios_base::floatfield) {
case ios_base::scientific:
__group_pos = __format_float_scientific( buf, bp, decpt, sign, is_zero,
flags, precision);
break;
case ios_base::fixed:
__group_pos = __format_float_fixed( buf, bp, decpt, sign,
flags, precision);
break;
default: // g format
// establish default precision
if (flags & ios_base::showpoint || precision > 0) {
if (precision == 0) precision = 1;
} else
precision = 6;
// reset exponent if value is zero
if (is_zero)
decpt = 1;
int kk = precision;
if (!(flags & ios_base::showpoint)) {
size_t n = strlen(bp);
if (n < (size_t)kk)
kk = (int)n;
while (kk >= 1 && bp[kk-1] == '0')
--kk;
}
if (decpt < -3 || decpt > precision) {
precision = kk - 1;
__group_pos = __format_float_scientific( buf, bp, decpt, sign, is_zero,
flags, precision);
} else {
precision = kk - decpt;
__group_pos = __format_float_fixed( buf, bp, decpt, sign,
flags, precision);
}
break;
} /* switch */
return __group_pos;
}
#endif
#if defined (USE_SPRINTF_INSTEAD) || defined (_STLP_EMULATE_LONG_DOUBLE_CVT)
struct GroupPos {
bool operator () (char __c) const {
return __c == '.' ||
__c == 'e' || __c == 'E';
}
};
// Creates a format string for sprintf()
static void __fill_fmtbuf(char* fmtbuf, ios_base::fmtflags flags, char long_modifier) {
fmtbuf[0] = '%';
int i = 1;
if (flags & ios_base::showpos)
fmtbuf[i++] = '+';
if (flags & ios_base::showpoint)
fmtbuf[i++] = '#';
fmtbuf[i++] = '.';
fmtbuf[i++] = '*';
if (long_modifier)
fmtbuf[i++] = long_modifier;
switch (flags & ios_base::floatfield)
{
case ios_base::scientific:
fmtbuf[i++] = (flags & ios_base::uppercase) ? 'E' : 'e';
break;
case ios_base::fixed:
# if defined (__FreeBSD__)
fmtbuf[i++] = 'f';
# else
fmtbuf[i++] = (flags & ios_base::uppercase) ? 'F' : 'f';
# endif
break;
default:
fmtbuf[i++] = (flags & ios_base::uppercase) ? 'G' : 'g';
break;
}
fmtbuf[i] = 0;
}
#endif /* USE_SPRINTF_INSTEAD */
template <class _FloatT>
static size_t __write_floatT(__iostring &buf, ios_base::fmtflags flags, int precision,
_FloatT x
#if defined (USE_SPRINTF_INSTEAD)
, char modifier) {
/* In theory, if we want 'arbitrary' precision, we should use 'arbitrary'
* buffer size below, but really we limited by exponent part in double.
* - ptr
*/
typedef numeric_limits<_FloatT> limits;
char static_buf[limits::max_exponent10 + 6]; // 6: -xxx.yyyE-zzz (sign, dot, E, exp sign, \0)
char fmtbuf[32];
__fill_fmtbuf(fmtbuf, flags, modifier);
snprintf(_STLP_ARRAY_AND_SIZE(static_buf), fmtbuf, precision, x);
buf = static_buf;
return find_if(buf.begin(), buf.end(), GroupPos()) - buf.begin();
#else
) {
typedef numeric_limits<_FloatT> limits;
//If numeric_limits support is correct we use the exposed values to detect NaN and infinity:
if (limits::has_infinity && limits::has_quiet_NaN) {
if (!(x == x) || // NaN check
(x == limits::infinity() || x == -limits::infinity())) {
return __format_nan_or_inf(buf, x, flags);
}
}
// numeric_limits support is not good enough, we rely on platform dependent function
// _Stl_is_nan_or_inf that do not support long double.
else if (_Stl_is_nan_or_inf(x)) {
return __format_nan_or_inf(buf, x, flags);
}
# if defined (__MINGW32__)
//For the moment MinGW is limited to display at most numeric_limits<double>::max()
if (x > numeric_limits<double>::max() ||
x < -numeric_limits<double>::max()) {
return __format_nan_or_inf(buf, x, flags);
}
# endif
/* Buffer size is max number of digits which is the addition of:
* - max_exponent10: max number of digits in fixed mode
* - digits10 + 2: max number of significant digits
* - trailing '\0'
*/
char cvtbuf[limits::max_exponent10 + limits::digits10 + 2 + 1];
char *bp;
int decpt, sign;
switch (flags & ios_base::floatfield) {
case ios_base::fixed:
{
/* Here, number of digits represents digits _after_ decimal point.
* In order to limit static buffer size we have to give 2 different values depending on x value.
* For small values (abs(x) < 1) we need as many digits as requested by precision limited by the maximum number of digits
* which is min_exponent10 + digits10 + 2
* For bigger values we won't have more than limits::digits10 + 2 digits after decimal point. */
int digits10 = (x > -1.0 && x < 1.0 ? -limits::min_exponent10 + limits::digits10 + 2
: limits::digits10 + 2);
bp = _Stl_fcvtR(x, (min) (precision, digits10), &decpt, &sign, _STLP_CVT_BUFFER(cvtbuf) );
}
break;
case ios_base::scientific:
default:
/* Here, number of digits is total number of digits which is limited to digits10 + 2. */
{
int digits10 = limits::digits10 + 2;
bp = _Stl_ecvtR(x, (min) (precision, digits10), &decpt, &sign, _STLP_CVT_BUFFER(cvtbuf) );
}
break;
}
return __format_float(buf, bp, decpt, sign, x == 0.0, flags, precision);
#endif
}
size_t _STLP_CALL
__write_float(__iostring &buf, ios_base::fmtflags flags, int precision,
double x) {
return __write_floatT(buf, flags, precision, x
#if defined (USE_SPRINTF_INSTEAD)
, 0
#endif
);
}
#if !defined (_STLP_NO_LONG_DOUBLE)
size_t _STLP_CALL
__write_float(__iostring &buf, ios_base::fmtflags flags, int precision,
long double x) {
return __write_floatT(buf, flags, precision, x
#if defined (USE_SPRINTF_INSTEAD)
, 'L'
#endif
);
}
#endif
void _STLP_CALL __get_floor_digits(__iostring &out, _STLP_LONGEST_FLOAT_TYPE __x) {
typedef numeric_limits<_STLP_LONGEST_FLOAT_TYPE> limits;
#if defined (USE_SPRINTF_INSTEAD)
char cvtbuf[limits::max_exponent10 + 6];
# if !defined (_STLP_NO_LONG_DOUBLE)
snprintf(_STLP_ARRAY_AND_SIZE(cvtbuf), "%Lf", __x); // check for 1234.56!
# else
snprintf(_STLP_ARRAY_AND_SIZE(cvtbuf), "%f", __x); // check for 1234.56!
# endif
char *p = strchr( cvtbuf, '.' );
if ( p == 0 ) {
out.append( cvtbuf );
} else {
out.append( cvtbuf, p );
}
#else
char cvtbuf[limits::max_exponent10 + 1];
char * bp;
int decpt, sign;
bp = _Stl_fcvtR(__x, 0, &decpt, &sign, _STLP_CVT_BUFFER(cvtbuf));
if (sign) {
out += '-';
}
out.append(bp, bp + decpt);
#endif
}
#if !defined (_STLP_NO_WCHAR_T)
void _STLP_CALL __convert_float_buffer( __iostring const& str, __iowstring &out,
const ctype<wchar_t>& ct, wchar_t dot, bool __check_dot) {
string::const_iterator str_ite(str.begin()), str_end(str.end());
//First loop, check the dot char
if (__check_dot) {
while (str_ite != str_end) {
if (*str_ite != '.') {
out += ct.widen(*str_ite++);
} else {
out += dot;
break;
}
}
} else {
if (str_ite != str_end) {
out += ct.widen(*str_ite);
}
}
if (str_ite != str_end) {
//Second loop, dot has been found, no check anymore
while (++str_ite != str_end) {
out += ct.widen(*str_ite);
}
}
}
#endif
void _STLP_CALL
__adjust_float_buffer(__iostring &str, char dot) {
if ('.' != dot) {
size_t __dot_pos = str.find('.');
if (__dot_pos != string::npos) {
str[__dot_pos] = dot;
}
}
}
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

46
extern/STLport/5.2.1/src/numpunct.cpp vendored Normal file
View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <locale>
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// numpunct<char>
char numpunct<char>::do_decimal_point() const {return '.';}
char numpunct<char>::do_thousands_sep() const { return ','; }
string numpunct<char>::do_grouping() const { return string();}
string numpunct<char>::do_truename() const { return "true";}
string numpunct<char>::do_falsename() const { return "false"; }
numpunct<char>::~numpunct() {}
#if !defined (_STLP_NO_WCHAR_T)
wchar_t numpunct<wchar_t>::do_decimal_point() const { return L'.'; }
wchar_t numpunct<wchar_t>::do_thousands_sep() const { return L','; }
string numpunct<wchar_t>::do_grouping() const { return string(); }
wstring numpunct<wchar_t>::do_truename() const { return L"true"; }
wstring numpunct<wchar_t>::do_falsename() const { return L"false"; }
numpunct<wchar_t>::~numpunct() {}
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

47
extern/STLport/5.2.1/src/ostream.cpp vendored Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <ostream>
_STLP_BEGIN_NAMESPACE
#if !defined(_STLP_NO_FORCE_INSTANTIATE)
// instantiations
template class _STLP_CLASS_DECLSPEC basic_ostream<char, char_traits<char> >;
# if defined (_STLP_USE_TEMPLATE_EXPORT)
template class _STLP_CLASS_DECLSPEC _Osentry<char, char_traits<char> >;
# endif
#ifndef _STLP_NO_WCHAR_T
# if defined (_STLP_USE_TEMPLATE_EXPORT)
template class _STLP_CLASS_DECLSPEC _Osentry<wchar_t, char_traits<wchar_t> >;
# endif
template class _STLP_CLASS_DECLSPEC basic_ostream<wchar_t, char_traits<wchar_t> >;
#endif
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

68
extern/STLport/5.2.1/src/sparc_atomic.s vendored Normal file
View File

@@ -0,0 +1,68 @@
.section ".text",#alloc,#execinstr
.align 8
.skip 16
/*
** int _STLP_atomic_exchange (void *pvalue, int value)
*/
.type _STLP_atomic_exchange,#function
.global _STLP_atomic_exchange
.align 8
_STLP_atomic_exchange:
0:
ld [%o0], %o2 ! Set the current value
mov %o1, %o3 ! Set the new value
! swap [%o0], %o3 ! Do the compare and swap
cas [%o0], %o2, %o3
cmp %o2, %o3 ! Check whether successful
bne 0b ! Retry upon failure
stbar
mov %o2, %o0 ! Set the new value
retl ! return
nop
.size _STLP_atomic_exchange,(.-_STLP_atomic_exchange)
/* int _STLP_atomic_increment (void *pvalue) */
.type _STLP_atomic_increment,#function
.global _STLP_atomic_increment
.align 8
_STLP_atomic_increment:
1:
ld [%o0], %o2 ! set the current
add %o2, 0x1, %o3 ! Increment and store current
! swap [%o0], %o3 ! Do the compare and swap
cas [%o0], %o2, %o3
cmp %o3, %o2 ! Check whether successful
bne 1b ! Retry if we failed.
membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
! returning
nop
retl ! return
nop
.size _STLP_atomic_increment,(.-_STLP_atomic_increment)
/* int _STLP_atomic_decrement (void *pvalue) */
.type _STLP_atomic_decrement,#function
.global _STLP_atomic_decrement
.align 8
_STLP_atomic_decrement:
2:
ld [%o0], %o2 ! set the current
sub %o2, 0x1, %o3 ! decrement and store current
! swap [%o0], %o3 ! Do the compare and swap
cas [%o0], %o2, %o3
cmp %o3, %o2 ! Check whether successful
bne 2b ! Retry if we failed.
membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
nop
! returning
retl ! return
nop
.size _STLP_atomic_decrement,(.-_STLP_atomic_decrement)

View File

@@ -0,0 +1,65 @@
.section ".text",#alloc,#execinstr
.align 8
.skip 16
! int _STLP_atomic_exchange (void *pvalue, int value)
!
.type _STLP_atomic_exchange,#function
.global _STLP_atomic_exchange
.align 8
_STLP_atomic_exchange:
1:
ldx [%o0], %o2 ! Set the current value
mov %o1, %o3 ! Set the new value
casx [%o0], %o2, %o3 ! Do the compare and swap
cmp %o2, %o3 ! Check whether successful
bne 1b ! Retry upon failure
membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
! returning
retl ! return
mov %o2, %o0 ! Set the new value
.size _STLP_atomic_exchange,(.-_STLP_atomic_exchange)
! int _STLP_atomic_increment (void *pvalue)
.type _STLP_atomic_increment,#function
.global _STLP_atomic_increment
.align 8
_STLP_atomic_increment:
0:
ldx [%o0], %o2 ! set the current
addx %o2, 0x1, %o3 ! Increment and store current
casx [%o0], %o2, %o3 ! Do the compare and swap
cmp %o3, %o2 ! Check whether successful
bne 0b
membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
! returning
retl ! return
mov %o1, %o0 ! Set the return value
.size _STLP_atomic_increment,(.-_STLP_atomic_increment)
! /* int _STLP_atomic_decrement (void *pvalue) */
.type _STLP_atomic_decrement,#function
.global _STLP_atomic_decrement
.align 8
_STLP_atomic_decrement:
0:
ldx [%o0], %o2 ! set the current
subx %o2, 0x1, %o3 ! decrement and store current
casx [%o0], %o2, %o3 ! Do the compare and swap
cmp %o3, %o2 ! Check whether successful
bne 0b
membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
! returning
retl ! return
nop
.size _STLP_atomic_decrement,(.-_STLP_atomic_decrement)

45
extern/STLport/5.2.1/src/sstream.cpp vendored Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <sstream>
_STLP_BEGIN_NAMESPACE
#if !defined (_STLP_NO_FORCE_INSTANTIATE)
// Force instantiation of stringstream classes.
template class _STLP_CLASS_DECLSPEC basic_stringbuf<char, char_traits<char>, allocator<char> >;
template class _STLP_CLASS_DECLSPEC basic_ostringstream<char, char_traits<char>, allocator<char> >;
template class _STLP_CLASS_DECLSPEC basic_istringstream<char, char_traits<char>, allocator<char> >;
template class _STLP_CLASS_DECLSPEC basic_stringstream<char, char_traits<char>, allocator<char> >;
# if !defined (_STLP_NO_WCHAR_T)
template class _STLP_CLASS_DECLSPEC basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
template class _STLP_CLASS_DECLSPEC basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
template class _STLP_CLASS_DECLSPEC basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
template class _STLP_CLASS_DECLSPEC basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
# endif
#endif
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

View File

@@ -0,0 +1,239 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include "stdio_streambuf.h"
#ifdef _STLP_UNIX
# include <sys/types.h>
# include <sys/stat.h>
#endif
#include <fstream>
#include <limits>
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// Compare with streamoff definition in stl/char_traits.h!
#if defined (_STLP_USE_DEFAULT_FILE_OFFSET) || \
(!defined(_LARGEFILE_SOURCE) && !defined(_LARGEFILE64_SOURCE))
# if !defined (_STLP_MSVC) || (_STLP_MSVC < 1400) || defined(_STLP_WCE)
# define FSEEK fseek
# else
# define FSEEK _fseeki64
# endif
# define FSETPOS fsetpos
# define FGETPOS fgetpos
# define FPOS_T fpos_t
#else
# define FSEEK fseeko64
# define FSETPOS fsetpos64
# define FGETPOS fgetpos64
# define FPOS_T fpos64_t
#endif
//----------------------------------------------------------------------
// Class stdio_streambuf_base
stdio_streambuf_base::stdio_streambuf_base(FILE* file)
: /* _STLP_STD::FILE_basic_streambuf(file, 0), */
_M_file(file)
{}
stdio_streambuf_base::~stdio_streambuf_base() {
_STLP_VENDOR_CSTD::fflush(_M_file);
}
_STLP_STD::streambuf* stdio_streambuf_base::setbuf(char* s, streamsize n) {
#ifdef _STLP_WCE
// no buffering in windows ce .NET
#else
size_t __n_size_t = (sizeof(streamsize) > sizeof(size_t)) ? __STATIC_CAST(size_t, (min)(__STATIC_CAST(streamsize, (numeric_limits<size_t>::max)()), n))
: __STATIC_CAST(size_t, n);
_STLP_VENDOR_CSTD::setvbuf(_M_file, s, (s == 0 && n == 0) ? _IONBF : _IOFBF, __n_size_t);
#endif
return this;
}
stdio_streambuf_base::pos_type
stdio_streambuf_base::seekoff(off_type off, ios_base::seekdir dir,
ios_base::openmode /* mode */) {
int whence;
switch (dir) {
case ios_base::beg:
whence = SEEK_SET;
break;
case ios_base::cur:
whence = SEEK_CUR;
break;
case ios_base::end:
whence = SEEK_END;
break;
default:
return pos_type(-1);
}
if (off <= numeric_limits<off_type>::max() && FSEEK(_M_file, off, whence) == 0) {
FPOS_T pos;
FGETPOS(_M_file, &pos);
// added 21 june 00 mdb,rjf,wjs: glibc 2.2 changed fpos_t to be a struct instead
// of a primitive type
#if (defined (__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 2))))
return pos_type((streamoff)pos.__pos);
#elif defined (__ISCPP__) || defined (__MVS__) || defined (__OS400__)
return pos_type(pos.__fpos_elem[ 0 ]);
#elif defined (__EMX__)
return pos_type((streamoff)pos._pos);
#else
return pos_type(pos);
#endif
}
else
return pos_type(-1);
}
stdio_streambuf_base::pos_type
stdio_streambuf_base::seekpos(pos_type pos, ios_base::openmode /* mode */) {
// added 21 june 00 mdb,rjf,wjs: glibc 2.2 changed fpos_t to be a struct instead
// of a primitive type
#if (defined(__GLIBC__) && ( (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 2) ) ) )
FPOS_T p;
p.__pos = pos;
# ifdef _STLP_USE_UCLIBC
# ifdef __STDIO_MBSTATE
memset( &(p.__mbstate), 0, sizeof(p.__mbstate) );
# endif
# ifdef __STDIO_WIDE
p.mblen_pending = 0;
# endif
# else
memset( &(p.__state), 0, sizeof(p.__state) );
# endif
#elif defined (__MVS__) || defined (__OS400__)
FPOS_T p;
p.__fpos_elem[0] = pos;
#elif defined (__EMX__)
FPOS_T p;
p._pos = pos;
memset( &(p._mbstate), 0, sizeof(p._mbstate) );
#else
FPOS_T p(pos);
#endif
return FSETPOS(_M_file, &p) == 0 ? pos : pos_type(-1);
}
int stdio_streambuf_base::sync() {
return _STLP_VENDOR_CSTD::fflush(_M_file) == 0 ? 0 : -1;
}
//----------------------------------------------------------------------
// Class stdio_istreambuf
stdio_istreambuf::~stdio_istreambuf() {}
streamsize stdio_istreambuf::showmanyc()
{ return 0; }
stdio_istreambuf::int_type stdio_istreambuf::underflow()
{
#ifdef _STLP_WCE
int c = fgetc(_M_file);
#else
int c = getc(_M_file);
#endif
if (c != EOF) {
_STLP_VENDOR_CSTD::ungetc(c, _M_file);
return c;
}
else
return traits_type::eof();
}
stdio_istreambuf::int_type stdio_istreambuf::uflow() {
#ifdef _STLP_WCE
int c = fgetc(_M_file);
#else
int c = getc(_M_file);
#endif
return c != EOF ? c : traits_type::eof();
}
stdio_istreambuf::int_type stdio_istreambuf::pbackfail(int_type c) {
if (c != traits_type::eof()) {
int result = _STLP_VENDOR_CSTD::ungetc(c, _M_file);
return result != EOF ? result : traits_type::eof();
}
else{
if (this->eback() < this->gptr()) {
this->gbump(-1);
return traits_type::not_eof(c);
}
else
return traits_type::eof();
}
}
//----------------------------------------------------------------------
// Class stdio_ostreambuf
stdio_ostreambuf::~stdio_ostreambuf() {}
streamsize stdio_ostreambuf::showmanyc()
{ return -1; }
stdio_ostreambuf::int_type stdio_ostreambuf::overflow(int_type c) {
// Write the existing buffer, without writing any additional character.
if (c == traits_type::eof()) {
// Do we have a buffer to write?
ptrdiff_t unwritten = this->pptr() - this->pbase();
if (unwritten != 0) {
_STLP_VENDOR_CSTD::fflush(_M_file);
// Test if the write succeeded.
if (this->pptr() - this->pbase() < unwritten)
return traits_type::not_eof(c);
else
return traits_type::eof();
}
// We always succeed if we don't have to do anything.
else
return traits_type::not_eof(c);
}
// Write the character c, and whatever else might be in the buffer.
else {
#ifdef _STLP_WCE
int result = fputc(c, _M_file);
#else
int result = putc(c, _M_file);
#endif
return result != EOF ? result : traits_type::eof();
}
}
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// This header defines two streambufs:
// stdio_istreambuf, a read-only streambuf synchronized with a C stdio
// FILE object
// stdio_ostreambuf, a write-only streambuf synchronized with a C stdio
// FILE object.
// Note that neither stdio_istreambuf nor stdio_ostreambuf is a template;
// both classes are derived from basic_streambuf<char, char_traits<char> >.
// Note: the imbue() member function is a no-op. In particular, these
// classes assume that codecvt<char, char, mbstate_t> is always an identity
// transformation. This is true of the default locale, and of all locales
// defined for the C I/O library. If you need to use a locale where
// the codecvt<char, char, mbstate_t> facet performs a nontrivial
// conversion, then you should use basic_filebuf<> instead of stdio_istreambuf
// or stdio_ostreambuf. (If you don't understand what any of this means,
// then it's not a feature you need to worry about. Locales where
// codecvt<char, char, mbstate_t> does something nontrivial are a rare
// corner case.)
#ifndef _STLP_STDIO_STREAMBUF
#define _STLP_STDIO_STREAMBUF
#include <streambuf>
#include <cstdio> // For FILE.
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// Base class for features common to stdio_istreambuf and stdio_ostreambuf
class stdio_streambuf_base :
public basic_streambuf<char, char_traits<char> > /* FILE_basic_streambuf */ {
public: // Constructor, destructor.
// The argument may not be null. It must be an open file pointer.
stdio_streambuf_base(FILE*);
// The destructor flushes the stream, but does not close it.
~stdio_streambuf_base();
protected: // Virtual functions from basic_streambuf.
streambuf* setbuf(char*, streamsize);
pos_type seekoff(off_type, ios_base::seekdir,
ios_base::openmode
= ios_base::in | ios_base::out);
pos_type seekpos(pos_type,
ios_base::openmode
= ios_base::in | ios_base::out);
int sync();
protected:
FILE* _M_file;
};
class stdio_istreambuf : public stdio_streambuf_base {
public: // Constructor, destructor.
stdio_istreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
~stdio_istreambuf();
protected: // Virtual functions from basic_streambuf.
streamsize showmanyc();
int_type underflow();
int_type uflow();
virtual int_type pbackfail(int_type c = traits_type::eof());
};
class stdio_ostreambuf : public stdio_streambuf_base {
public: // Constructor, destructor.
stdio_ostreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
~stdio_ostreambuf();
protected: // Virtual functions from basic_streambuf.
streamsize showmanyc();
int_type overflow(int_type c = traits_type::eof());
};
_STLP_MOVE_TO_STD_NAMESPACE
_STLP_END_NAMESPACE
#endif /* _STLP_STDIO_STREAMBUF */
// Local Variables:
// mode:C++
// End:

96
extern/STLport/5.2.1/src/stlport.rc vendored Normal file
View File

@@ -0,0 +1,96 @@
///////////////////////////
//
// Version
//
#include <windows.h>
#include <stl/_stlport_version.h>
/* On some evc3/evc4 targets the windows.h doesn't include winver.h or doesn't
* define needed file version flags, so we redefine them here.
*/
#ifndef VS_FF_DEBUG
# define VS_FF_DEBUG 0x00000001L
#endif
#ifndef VOS__WINDOWS32
# define VOS__WINDOWS32 0x00000004L
#endif
#ifndef VFT_DLL
# define VFT_DLL 0x00000002L
#endif
#ifndef VFT2_UNKNOWN
# define VFT2_UNKNOWN 0x00000000L
#endif
#define STRINGIZE(X) STRINGIZE_AUX(X)
#define STRINGIZE_AUX(X) #X
#define VERSION_ID _STLPORT_MAJOR, _STLPORT_MINOR, _STLPORT_PATCHLEVEL, 0
#if !defined (__BORLANDC__)
# define VERSION_STR STRINGIZE(_STLPORT_MAJOR._STLPORT_MINOR._STLPORT_PATCHLEVEL)
#else
/* Borland precompiler happen weird character when trying to transform a
* macro containing 0 in a character string so we use a workaround for this
* value. We do not check the major version that will never be 0 again.
*/
# if (_STLPORT_MINOR == 0)
# define _STLP_MINOR "0"
# else
# define _STLP_MINOR STRINGIZE(_STLPORT_MINOR)
# endif
# if (_STLPORT_PATCHLEVEL == 0)
# define _STLP_PATCH "0"
# else
# define _STLP_PATCH STRINGIZE(_STLPORT_PATCHLEVEL)
# endif
# define VERSION_STR STRINGIZE(_STLPORT_MAJOR) "." _STLP_MINOR "." _STLP_PATCH "\0"
#endif
#if defined (__GNUC__)
# define LIB_MOTIF "libstlport"
#else
# define LIB_MOTIF "stlport"
#endif
#define DLLNAME LIB_MOTIF "." STRINGIZE(_STLPORT_MAJOR) "." STRINGIZE(_STLPORT_MINOR) ".dll\0"
#define DLLNAME2(buildstr) LIB_MOTIF "" STRINGIZE(buildstr) "." STRINGIZE(_STLPORT_MAJOR) "." STRINGIZE(_STLPORT_MINOR) ".dll\0"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_ID
PRODUCTVERSION VERSION_ID
FILEFLAGSMASK 0x3fL
FILEFLAGS VS_FF_DEBUG
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "STLport Consulting, Inc.\0"
VALUE "FileDescription", "STLport\0"
VALUE "FileVersion", VERSION_STR
VALUE "InternalName", "STLPORT.DLL\0"
VALUE "LegalCopyright", "Copyright (C) Boris Fomitchev\0"
#if !defined (BUILD)
VALUE "OriginalFilename", DLLNAME
#else
VALUE "OriginalFilename", DLLNAME2(BUILD)
#endif
VALUE "ProductName", "STLport Standard ANSI C++ Library\0"
VALUE "ProductVersion", VERSION_STR
#if defined (BUILD_INFOS)
VALUE "SpecialBuild", STRINGIZE(COMP) " " STRINGIZE(BUILD_INFOS) "\0"
#endif
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

View File

@@ -0,0 +1,43 @@
#ifndef STLPORT_PREFIX_H
#define STLPORT_PREFIX_H
#define __BUILDING_STLPORT 1
#if defined (_WIN32) || defined (WIN32)
# ifdef __cplusplus
# define WIN32_LEAN_AND_MEAN
# define NOSERVICE
# endif
#endif
#undef _STLP_NO_FORCE_INSTANTIATE
/* Please add extra compilation switches for particular compilers here */
#if defined (_MSC_VER) && !defined (__COMO__) && !defined (__MWERKS__)
# include "warning_disable.h"
#endif
#include <stl/config/features.h>
#if defined (_STLP_USE_TEMPLATE_EXPORT) && defined (_STLP_USE_DECLSPEC) && !defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
# define _STLP_EXPOSE_GLOBALS_IMPLEMENTATION
#endif
#ifdef __cplusplus
# include <ctime>
# if defined (_STLP_USE_NAMESPACES) && !defined (_STLP_VENDOR_GLOBAL_CSTD)
using _STLP_VENDOR_CSTD::time_t;
# endif
# if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
# define _STLP_OPERATOR_SPEC _STLP_DECLSPEC
# else
# define _STLP_OPERATOR_SPEC _STLP_TEMPLATE_NULL _STLP_DECLSPEC
# endif
#endif /* __cplusplus */
#endif /* PREFIX */

93
extern/STLport/5.2.1/src/string.cpp vendored Normal file
View File

@@ -0,0 +1,93 @@
#include "stlport_prefix.h"
#include <string>
_STLP_BEGIN_NAMESPACE
#if defined(_STLP_USE_WIDE_INTERFACE)
_STLP_MOVE_TO_PRIV_NAMESPACE
wstring __ASCIIToWide(const char *ascii) {
size_t size = strlen(ascii);
wchar_t* buff = new wchar_t[size+1];
mbstowcs(buff, ascii, size);
buff[size] = 0x00;
wstring ret(buff);
delete[] buff;
return ret;
}
string __WideToASCII(const wchar_t *wide) {
size_t size = wcslen(wide);
char* buff = new char[size+1];
wcstombs(buff, wide, size);
buff[size] = 0;
string ret(buff);
delete[] buff;
return ret;
}
_STLP_MOVE_TO_STD_NAMESPACE
#endif
#if !defined (_STLP_NO_FORCE_INSTANTIATE)
template class _STLP_CLASS_DECLSPEC allocator<char>;
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _STLP_alloc_proxy<char*, char, allocator<char> >;
template class _STLP_CLASS_DECLSPEC _String_base<char, allocator<char> >;
# if defined (_STLP_DEBUG) && !defined (__SUNPRO_CC) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
# define basic_string _STLP_NON_DBG_NAME(str)
template class _STLP_CLASS_DECLSPEC basic_string<char, char_traits<char>, allocator<char> >;
template class _STLP_CLASS_DECLSPEC __construct_checker<basic_string<char, char_traits<char>, allocator<char> > >;
# undef basic_string
# endif
# if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
# define basic_string _STLP_NO_MEM_T_NAME(str)
# else
_STLP_MOVE_TO_STD_NAMESPACE
# endif
template class _STLP_CLASS_DECLSPEC basic_string<char, char_traits<char>, allocator<char> >;
# if defined (basic_string)
_STLP_MOVE_TO_STD_NAMESPACE
# undef basic_string
# endif
# if !defined (_STLP_NO_WCHAR_T)
template class _STLP_CLASS_DECLSPEC allocator<wchar_t>;
_STLP_MOVE_TO_PRIV_NAMESPACE
template class _STLP_CLASS_DECLSPEC _String_base<wchar_t, allocator<wchar_t> >;
# if defined (_STLP_DEBUG) && !defined (__SUNPRO_CC) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
# define basic_string _STLP_NON_DBG_NAME(str)
template class _STLP_CLASS_DECLSPEC basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
template class _STLP_CLASS_DECLSPEC __construct_checker<basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > >;
# undef basic_string
# endif
# if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
# define basic_string _STLP_NO_MEM_T_NAME(str)
# else
_STLP_MOVE_TO_STD_NAMESPACE
# endif
template class _STLP_CLASS_DECLSPEC basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
# if defined (basic_string)
_STLP_MOVE_TO_STD_NAMESPACE
# undef basic_string
# endif
# endif
#endif
_STLP_END_NAMESPACE

391
extern/STLport/5.2.1/src/strstream.cpp vendored Normal file
View File

@@ -0,0 +1,391 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// Implementation of the classes in header <strstream>.
// WARNING: The classes defined in <strstream> are DEPRECATED. This
// header is defined in section D.7.1 of the C++ standard, and it
// MAY BE REMOVED in a future standard revision. You should use the
// header <sstream> instead.
#include "stlport_prefix.h"
#include <strstream>
#include <algorithm>
#include <limits>
_STLP_BEGIN_NAMESPACE
// strstreambuf constructor, destructor.
strstreambuf::strstreambuf(streamsize initial_capacity)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(true), _M_frozen(false), _M_constant(false) {
size_t n = (sizeof(streamsize) > sizeof(size_t)) ? __STATIC_CAST(size_t, (min)(__STATIC_CAST(streamsize, (numeric_limits<size_t>::max)()),
(max)(initial_capacity, streamsize(16))))
: __STATIC_CAST(size_t, (max)(initial_capacity, streamsize(16)));
char* buf = _M_alloc(n);
if (buf) {
setp(buf, buf + n);
setg(buf, buf, buf);
}
}
strstreambuf::strstreambuf(__alloc_fn alloc_f, __free_fn free_f)
: _M_alloc_fun(alloc_f), _M_free_fun(free_f),
_M_dynamic(true), _M_frozen(false), _M_constant(false) {
size_t n = 16;
char* buf = _M_alloc(n);
if (buf) {
setp(buf, buf + n);
setg(buf, buf, buf);
}
}
strstreambuf::strstreambuf(char* get, streamsize n, char* put)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(false) {
_M_setup(get, put, n);
}
strstreambuf::strstreambuf(signed char* get, streamsize n, signed char* put)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(false) {
_M_setup(__REINTERPRET_CAST(char*,get), __REINTERPRET_CAST(char*,put), n);
}
strstreambuf::strstreambuf(unsigned char* get, streamsize n,
unsigned char* put)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(false) {
_M_setup(__REINTERPRET_CAST(char*,get), __REINTERPRET_CAST(char*,put), n);
}
strstreambuf::strstreambuf(const char* get, streamsize n)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(true) {
_M_setup(__CONST_CAST(char*,get), 0, n);
}
strstreambuf::strstreambuf(const signed char* get, streamsize n)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(true) {
_M_setup(__REINTERPRET_CAST(char*, __CONST_CAST(signed char*,get)), 0, n);
}
strstreambuf::strstreambuf(const unsigned char* get, streamsize n)
: _M_alloc_fun(0), _M_free_fun(0),
_M_dynamic(false), _M_frozen(false), _M_constant(true) {
_M_setup(__REINTERPRET_CAST(char*, __CONST_CAST(unsigned char*,get)), 0, n);
}
strstreambuf::~strstreambuf() {
if (_M_dynamic && !_M_frozen)
_M_free(eback());
}
void strstreambuf::freeze(bool frozenflag) {
if (_M_dynamic)
_M_frozen = frozenflag;
}
char* strstreambuf::str() {
freeze(true);
return eback();
}
int strstreambuf::pcount() const {
return int(pptr() ? pptr() - pbase() : 0);
}
strstreambuf::int_type strstreambuf::overflow(int_type c) {
if (c == traits_type::eof())
return traits_type::not_eof(c);
// Try to expand the buffer.
if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant) {
ptrdiff_t old_size = epptr() - pbase();
ptrdiff_t new_size = (max)(2 * old_size, ptrdiff_t(1));
char* buf = _M_alloc(new_size);
if (buf) {
memcpy(buf, pbase(), old_size);
char* old_buffer = pbase();
bool reposition_get = false;
ptrdiff_t old_get_offset;
if (gptr() != 0) {
reposition_get = true;
old_get_offset = gptr() - eback();
}
setp(buf, buf + new_size);
pbump((int)old_size);
if (reposition_get)
setg(buf, buf + old_get_offset, buf + (max)(old_get_offset, old_size));
_M_free(old_buffer);
}
}
if (pptr() != epptr()) {
*pptr() = traits_type::to_char_type(c);
pbump(1);
return c;
}
else
return traits_type::eof();
}
strstreambuf::int_type strstreambuf::pbackfail(int_type c) {
if (gptr() != eback()) {
if (c == traits_type::eof()) {
gbump(-1);
return traits_type::not_eof(c);
}
else if (c == gptr()[-1]) {
gbump(-1);
return c;
}
else if (!_M_constant) {
gbump(-1);
*gptr() = traits_type::to_char_type(c);
return c;
}
}
return traits_type::eof();
}
strstreambuf::int_type strstreambuf::underflow() {
if (gptr() == egptr() && pptr() && pptr() > egptr())
setg(eback(), gptr(), pptr());
if (gptr() != egptr())
return (unsigned char) *gptr();
else
return _Traits::eof();
}
basic_streambuf<char, char_traits<char> >*
strstreambuf::setbuf(char*, streamsize) {
return this;
}
strstreambuf::pos_type
strstreambuf::seekoff(off_type off,
ios_base::seekdir dir, ios_base::openmode mode) {
bool do_get = false;
bool do_put = false;
if ((mode & (ios_base::in | ios_base::out)) ==
(ios_base::in | ios_base::out) &&
(dir == ios_base::beg || dir == ios_base::end))
do_get = do_put = true;
else if (mode & ios_base::in)
do_get = true;
else if (mode & ios_base::out)
do_put = true;
// !gptr() is here because, according to D.7.1 paragraph 4, the seekable
// area is undefined if there is no get area.
if ((!do_get && !do_put) || (do_put && !pptr()) || !gptr())
return pos_type(off_type(-1));
char* seeklow = eback();
char* seekhigh = epptr() ? epptr() : egptr();
off_type newoff;
switch(dir) {
case ios_base::beg:
newoff = 0;
break;
case ios_base::end:
newoff = seekhigh - seeklow;
break;
case ios_base::cur:
newoff = do_put ? pptr() - seeklow : gptr() - seeklow;
break;
default:
return pos_type(off_type(-1));
}
off += newoff;
if (off < 0 || off > seekhigh - seeklow)
return pos_type(off_type(-1));
if (do_put) {
if (seeklow + __STATIC_CAST(ptrdiff_t, off) < pbase()) {
setp(seeklow, epptr());
pbump((int)off);
}
else {
setp(pbase(), epptr());
pbump((int)(off - (pbase() - seeklow)));
}
}
if (do_get) {
if (off <= egptr() - seeklow)
setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), egptr());
else if (off <= pptr() - seeklow)
setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), pptr());
else
setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), epptr());
}
return pos_type(newoff);
}
strstreambuf::pos_type
strstreambuf::seekpos(pos_type pos, ios_base::openmode mode) {
return seekoff(pos - pos_type(off_type(0)), ios_base::beg, mode);
}
char* strstreambuf::_M_alloc(size_t n) {
if (_M_alloc_fun)
return __STATIC_CAST(char*,_M_alloc_fun(n));
else
return new char[n];
}
void strstreambuf::_M_free(char* p) {
if (p) {
if (_M_free_fun)
_M_free_fun(p);
else
delete[] p;
}
}
void strstreambuf::_M_setup(char* get, char* put, streamsize n) {
if (get) {
size_t N = n > 0 ? size_t(n) : n == 0 ? strlen(get) : size_t(INT_MAX);
if (put) {
setg(get, get, get + N);
setp(put, put + N);
}
else {
setg(get, get, get + N);
}
}
}
//----------------------------------------------------------------------
// Class istrstream
istrstream::istrstream(char* s)
: basic_istream<char, char_traits<char> >(0), _M_buf(s, 0) {
this->init(&_M_buf);
}
istrstream::istrstream(const char* s)
: basic_istream<char, char_traits<char> >(0), _M_buf(s, 0) {
this->init(&_M_buf);
}
istrstream::istrstream(char* s, streamsize n)
: basic_istream<char, char_traits<char> >(0), _M_buf(s, n) {
this->init(&_M_buf);
}
istrstream::istrstream(const char* s, streamsize n)
: basic_istream<char, char_traits<char> >(0), _M_buf(s, n) {
this->init(&_M_buf);
}
istrstream::~istrstream() {}
strstreambuf* istrstream::rdbuf() const {
return __CONST_CAST(strstreambuf*,&_M_buf);
}
char* istrstream::str() { return _M_buf.str(); }
//----------------------------------------------------------------------
// Class ostrstream
ostrstream::ostrstream()
: basic_ostream<char, char_traits<char> >(0), _M_buf() {
basic_ios<char, char_traits<char> >::init(&_M_buf);
}
ostrstream::ostrstream(char* s, int n, ios_base::openmode mode)
: basic_ostream<char, char_traits<char> >(0),
_M_buf(s, n, mode & ios_base::app ? s + strlen(s) : s) {
basic_ios<char, char_traits<char> >::init(&_M_buf);
}
ostrstream::~ostrstream() {}
strstreambuf* ostrstream::rdbuf() const {
return __CONST_CAST(strstreambuf*,&_M_buf);
}
void ostrstream::freeze(bool freezeflag) {
_M_buf.freeze(freezeflag);
}
char* ostrstream::str() {
return _M_buf.str();
}
int ostrstream::pcount() const {
return _M_buf.pcount();
}
//----------------------------------------------------------------------
// Class strstream
strstream::strstream()
: basic_iostream<char, char_traits<char> >(0), _M_buf() {
basic_ios<char, char_traits<char> >::init(&_M_buf);
}
strstream::strstream(char* s, int n, ios_base::openmode mode)
: basic_iostream<char, char_traits<char> >(0),
_M_buf(s, n, mode & ios_base::app ? s + strlen(s) : s) {
basic_ios<char, char_traits<char> >::init(&_M_buf);
}
strstream::~strstream() {}
strstreambuf* strstream::rdbuf() const {
return __CONST_CAST(strstreambuf*,&_M_buf);
}
void strstream::freeze(bool freezeflag) {
_M_buf.freeze(freezeflag);
}
int strstream::pcount() const {
return _M_buf.pcount();
}
char* strstream::str() {
return _M_buf.str();
}
_STLP_END_NAMESPACE
// Local Variables:
// mode:C++
// End:

565
extern/STLport/5.2.1/src/time_facets.cpp vendored Normal file
View File

@@ -0,0 +1,565 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#include "stlport_prefix.h"
#include <cstdio>
#include <locale>
#include <istream>
#include "c_locale.h"
#include "acquire_release.h"
_STLP_BEGIN_NAMESPACE
_STLP_MOVE_TO_PRIV_NAMESPACE
// default "C" values for month and day names
const char default_dayname[][14] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"};
const char default_monthname[][24] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
#ifndef _STLP_NO_WCHAR_T
const wchar_t default_wdayname[][14] = {
L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat",
L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday",
L"Friday", L"Saturday"};
const wchar_t default_wmonthname[][24] = {
L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec",
L"January", L"February", L"March", L"April", L"May", L"June",
L"July", L"August", L"September", L"October", L"November", L"December"};
#endif
#if defined (__BORLANDC__)
_Time_Info time_init<char>::_M_timeinfo;
# ifndef _STLP_NO_WCHAR_T
_WTime_Info time_init<wchar_t>::_M_timeinfo;
# endif
#endif
// _Init_time_info: initialize table with
// "C" values (note these are not defined in the C standard, so this
// is somewhat arbitrary).
static void _Init_timeinfo_base(_Time_Info_Base& table) {
table._M_time_format = "%H:%M:%S";
table._M_date_format = "%m/%d/%y";
table._M_date_time_format = "%m/%d/%y";
}
static void _Init_timeinfo(_Time_Info& table) {
int i;
for (i = 0; i < 14; ++i)
table._M_dayname[i] = default_dayname[i];
for (i = 0; i < 24; ++i)
table._M_monthname[i] = default_monthname[i];
table._M_am_pm[0] = "AM";
table._M_am_pm[1] = "PM";
_Init_timeinfo_base(table);
}
#ifndef _STLP_NO_WCHAR_T
static void _Init_timeinfo(_WTime_Info& table) {
int i;
for (i = 0; i < 14; ++i)
table._M_dayname[i] = default_wdayname[i];
for (i = 0; i < 24; ++i)
table._M_monthname[i] = default_wmonthname[i];
table._M_am_pm[0] = L"AM";
table._M_am_pm[1] = L"PM";
_Init_timeinfo_base(table);
}
#endif
static void _Init_timeinfo_base(_Time_Info_Base& table, _Locale_time * time) {
table._M_time_format = _Locale_t_fmt(time);
if ( table._M_time_format == "%T" ) {
table._M_time_format = "%H:%M:%S";
} else if ( table._M_time_format == "%r" ) {
table._M_time_format = "%I:%M:%S %p";
} else if ( table._M_time_format == "%R" ) {
table._M_time_format = "%H:%M";
}
table._M_date_format = _Locale_d_fmt(time);
table._M_date_time_format = _Locale_d_t_fmt(time);
table._M_long_date_format = _Locale_long_d_fmt(time);
table._M_long_date_time_format = _Locale_long_d_t_fmt(time);
}
static void _Init_timeinfo(_Time_Info& table, _Locale_time * time) {
int i;
for (i = 0; i < 7; ++i)
table._M_dayname[i] = _Locale_abbrev_dayofweek(time, i);
for (i = 0; i < 7; ++i)
table._M_dayname[i+7] = _Locale_full_dayofweek(time, i);
for (i = 0; i < 12; ++i)
table._M_monthname[i] = _Locale_abbrev_monthname(time, i);
for (i = 0; i < 12; ++i)
table._M_monthname[i+12] = _Locale_full_monthname(time, i);
table._M_am_pm[0] = _Locale_am_str(time);
table._M_am_pm[1] = _Locale_pm_str(time);
_Init_timeinfo_base(table, time);
}
#ifndef _STLP_NO_WCHAR_T
static void _Init_timeinfo(_WTime_Info& table, _Locale_time * time) {
wchar_t buf[128];
int i;
for (i = 0; i < 7; ++i)
table._M_dayname[i] = _WLocale_abbrev_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
for (i = 0; i < 7; ++i)
table._M_dayname[i+7] = _WLocale_full_dayofweek(time, i, _STLP_ARRAY_AND_SIZE(buf));
for (i = 0; i < 12; ++i)
table._M_monthname[i] = _WLocale_abbrev_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
for (i = 0; i < 12; ++i)
table._M_monthname[i+12] = _WLocale_full_monthname(time, i, _STLP_ARRAY_AND_SIZE(buf));
table._M_am_pm[0] = _WLocale_am_str(time, _STLP_ARRAY_AND_SIZE(buf));
table._M_am_pm[1] = _WLocale_pm_str(time, _STLP_ARRAY_AND_SIZE(buf));
_Init_timeinfo_base(table, time);
}
#endif
template <class _Ch, class _TimeInfo>
void __subformat(_STLP_BASIC_IOSTRING(_Ch) &buf, const ctype<_Ch>& ct,
const string& format, const _TimeInfo& table, const tm* t) {
const char * cp = format.data();
const char * cp_end = cp + format.size();
while (cp != cp_end) {
if (*cp == '%') {
char mod = 0;
++cp;
if (*cp == '#') {
mod = *cp; ++cp;
}
__write_formatted_timeT(buf, ct, *cp++, mod, table, t);
} else
buf.append(1, *cp++);
}
}
static void __append(__iostring &buf, const string& name)
{ buf.append(name.data(), name.data() + name.size()); }
static void __append(__iowstring &buf, const wstring& name)
{ buf.append(name.data(), name.data() + name.size()); }
static void __append(__iostring &buf, char *first, char *last, const ctype<char>& /* ct */)
{ buf.append(first, last); }
static void __append(__iowstring &buf, char *first, char *last, const ctype<wchar_t>& ct) {
wchar_t _wbuf[64];
ct.widen(first, last, _wbuf);
buf.append(_wbuf, _wbuf + (last - first));
}
#if defined (__GNUC__)
/* The number of days from the first day of the first ISO week of this
year to the year day YDAY with week day WDAY. ISO weeks start on
Monday; the first ISO week has the year's first Thursday. YDAY may
be as small as YDAY_MINIMUM. */
# define __ISO_WEEK_START_WDAY 1 /* Monday */
# define __ISO_WEEK1_WDAY 4 /* Thursday */
# define __YDAY_MINIMUM (-366)
# define __TM_YEAR_BASE 1900
static int
__iso_week_days(int yday, int wday) {
/* Add enough to the first operand of % to make it nonnegative. */
int big_enough_multiple_of_7 = (-__YDAY_MINIMUM / 7 + 2) * 7;
return (yday
- (yday - wday + __ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
+ __ISO_WEEK1_WDAY - __ISO_WEEK_START_WDAY);
}
# define __is_leap(year)\
((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
#endif
#define __hour12(hour) \
(((hour) % 12 == 0) ? (12) : (hour) % 12)
#if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
# define _STLP_SPRINTF sprintf
#else
# define _STLP_SPRINTF sprintf_s
#endif
template <class _Ch, class _TimeInfo>
void _STLP_CALL __write_formatted_timeT(_STLP_BASIC_IOSTRING(_Ch) &buf,
const ctype<_Ch>& ct,
char format, char modifier,
const _TimeInfo& table, const tm* t) {
char _buf[64];
char *_bend;
switch (format) {
case 'a':
__append(buf, table._M_dayname[t->tm_wday]);
break;
case 'A':
__append(buf, table._M_dayname[t->tm_wday + 7]);
break;
case 'b':
__append(buf, table._M_monthname[t->tm_mon]);
break;
case 'B':
__append(buf, table._M_monthname[t->tm_mon + 12]);
break;
case 'c':
__subformat(buf, ct, (modifier != '#') ? table._M_date_time_format
: table._M_long_date_time_format, table, t);
break;
case 'd':
_STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_mday);
__append(buf, _buf, ((long)t->tm_mday < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
break;
case 'e':
_STLP_SPRINTF(_buf, "%2ld", (long)t->tm_mday);
__append(buf, _buf, _buf + 2, ct);
break;
case 'H':
_STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_hour);
__append(buf, _buf, ((long)t->tm_hour < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
break;
case 'I':
_STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)__hour12(t->tm_hour));
__append(buf, _buf, ((long)__hour12(t->tm_hour) < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
break;
case 'j':
_bend = __write_integer(_buf, 0, (long)((long)t->tm_yday + 1));
__append(buf, _buf, _bend, ct);
break;
case 'm':
_STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_mon + 1);
__append(buf, _buf, ((long)(t->tm_mon + 1) < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
break;
case 'M':
_STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_min);
__append(buf, _buf, ((long)t->tm_min < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
break;
case 'p':
__append(buf, table._M_am_pm[t->tm_hour / 12]);
break;
case 'S': // pad with zeros
_STLP_SPRINTF(_buf, (modifier != '#') ? "%.2ld" : "%ld", (long)t->tm_sec);
__append(buf, _buf, ((long)t->tm_sec < 10L && modifier == '#') ? _buf + 1 : _buf + 2, ct);
break;
case 'U':
_bend = __write_integer(_buf, 0, long((t->tm_yday - t->tm_wday + 7) / 7));
__append(buf, _buf, _bend, ct);
break;
case 'w':
_bend = __write_integer(_buf, 0, (long)t->tm_wday);
__append(buf, _buf, _bend, ct);
break;
case 'W':
_bend = __write_integer(_buf, 0,
(long)(t->tm_wday == 0 ? (t->tm_yday + 1) / 7 :
(t->tm_yday + 8 - t->tm_wday) / 7));
__append(buf, _buf, _bend, ct);
break;
case'x':
__subformat(buf, ct, (modifier != '#') ? table._M_date_format
: table._M_long_date_format, table, t);
break;
case 'X':
__subformat(buf, ct, table._M_time_format, table, t);
break;
case 'y':
_bend = __write_integer(_buf, 0, (long)((long)(t->tm_year + 1900) % 100));
__append(buf, _buf, _bend, ct);
break;
case 'Y':
_bend = __write_integer(_buf, 0, (long)((long)t->tm_year + 1900));
__append(buf, _buf, _bend, ct);
break;
case '%':
buf.append(1, ct.widen('%'));
break;
#if defined (__GNUC__)
// fbp : at least on SUN
# if defined (_STLP_UNIX) && !defined (__linux__)
# define __USE_BSD 1
# endif
/*********************************************
* JGS, handle various extensions *
*********************************************/
case 'h': /* POSIX.2 extension */
// same as 'b', abbrev month name
__append(buf, table._M_monthname[t->tm_mon]);
break;
case 'C': /* POSIX.2 extension */
// same as 'd', the day
_STLP_SPRINTF(_buf, "%2ld", (long)t->tm_mday);
__append(buf, _buf, _buf + 2, ct);
break;
case 'D': /* POSIX.2 extension */
// same as 'x'
__subformat(buf, ct, table._M_date_format, table, t);
break;
case 'k': /* GNU extension */
_STLP_SPRINTF(_buf, "%2ld", (long)t->tm_hour);
__append(buf, _buf, _buf + 2, ct);
break;
case 'l': /* GNU extension */
_STLP_SPRINTF(_buf, "%2ld", (long)t->tm_hour % 12);
__append(buf, _buf, _buf + 2, ct);
break;
case 'n': /* POSIX.2 extension */
buf.append(1, ct.widen('\n'));
break;
case 'R': /* GNU extension */
__subformat(buf, ct, "%H:%M", table, t);
break;
case 'r': /* POSIX.2 extension */
__subformat(buf, ct, "%I:%M:%S %p", table, t);
break;
case 'T': /* POSIX.2 extension. */
__subformat(buf, ct, "%H:%M:%S", table, t);
break;
case 't': /* POSIX.2 extension. */
buf.append(1, ct.widen('\t'));
case 'u': /* POSIX.2 extension. */
_bend = __write_integer(_buf, 0, long((t->tm_wday - 1 + 7)) % 7 + 1);
__append(buf, _buf, _bend, ct);
break;
case 's': {
time_t __t = mktime(__CONST_CAST(tm*, t));
_bend = __write_integer(_buf, 0, (long)__t );
__append(buf, _buf, _bend, ct);
break;
}
case 'g': /* GNU extension */
case 'G': {
int year = t->tm_year + __TM_YEAR_BASE;
int days = __iso_week_days (t->tm_yday, t->tm_wday);
if (days < 0) {
/* This ISO week belongs to the previous year. */
year--;
days = __iso_week_days (t->tm_yday + (365 + __is_leap (year)), t->tm_wday);
}
else {
int d = __iso_week_days (t->tm_yday - (365 + __is_leap (year)), t->tm_wday);
if (0 <= d) {
/* This ISO week belongs to the next year. */
++year;
days = d;
}
}
long val;
switch (format) {
case 'g':
val = (long)(year % 100 + 100) % 100;
break;
case 'G':
val = (long)year;
break;
default:
val = (long)days / 7 + 1;
break;
}
_bend = __write_integer(_buf, 0, val);
__append(buf, _buf, _bend, ct);
break;
}
# if defined (_STLP_USE_GLIBC)
case 'z': /* GNU extension. */
if (t->tm_isdst < 0)
break;
{
int diff;
# if defined (__USE_BSD) || defined (__BEOS__)
diff = t->tm_gmtoff;
# else
diff = t->__tm_gmtoff;
# endif
if (diff < 0) {
buf.append(1, ct.widen('-'));
diff = -diff;
} else
buf.append(1, ct.widen('+'));
diff /= 60;
_STLP_SPRINTF(_buf, "%.4d", (diff / 60) * 100 + diff % 60);
__append(buf, _buf, _buf + 4, ct);
break;
}
# endif /* __GLIBC__ */
#endif /* __GNUC__ */
default:
break;
}
}
void _STLP_CALL __write_formatted_time(__iostring &buf, const ctype<char>& ct,
char format, char modifier,
const _Time_Info& table, const tm* t)
{ __write_formatted_timeT(buf, ct, format, modifier, table, t); }
void _STLP_CALL __write_formatted_time(__iowstring &buf, const ctype<wchar_t>& ct,
char format, char modifier,
const _WTime_Info& table, const tm* t)
{ __write_formatted_timeT(buf, ct, format, modifier, table, t); }
static time_base::dateorder __get_date_order(_Locale_time* time) {
const char * fmt = _Locale_d_fmt(time);
char first, second, third;
while (*fmt != 0 && *fmt != '%') ++fmt;
if (*fmt == 0)
return time_base::no_order;
first = *++fmt;
while (*fmt != 0 && *fmt != '%') ++fmt;
if (*fmt == 0)
return time_base::no_order;
second = *++fmt;
while (*fmt != 0 && *fmt != '%') ++fmt;
if (*fmt == 0)
return time_base::no_order;
third = *++fmt;
switch (first) {
case 'd':
return (second == 'm' && third == 'y') ? time_base::dmy
: time_base::no_order;
case 'm':
return (second == 'd' && third == 'y') ? time_base::mdy
: time_base::no_order;
case 'y':
switch (second) {
case 'd':
return third == 'm' ? time_base::ydm : time_base::no_order;
case 'm':
return third == 'd' ? time_base::ymd : time_base::no_order;
default:
return time_base::no_order;
}
default:
return time_base::no_order;
}
}
time_init<char>::time_init()
: _M_dateorder(time_base::no_order)
{ _Init_timeinfo(_M_timeinfo); }
time_init<char>::time_init(const char* __name) {
if (!__name)
locale::_M_throw_on_null_name();
int __err_code;
char buf[_Locale_MAX_SIMPLE_NAME];
_Locale_time *__time = __acquire_time(__name, buf, 0, &__err_code);
if (!__time)
locale::_M_throw_on_creation_failure(__err_code, __name, "time");
_Init_timeinfo(this->_M_timeinfo, __time);
_M_dateorder = __get_date_order(__time);
__release_time(__time);
}
time_init<char>::time_init(_Locale_time *__time) {
_Init_timeinfo(this->_M_timeinfo, __time);
_M_dateorder = __get_date_order(__time);
}
#ifndef _STLP_NO_WCHAR_T
time_init<wchar_t>::time_init()
: _M_dateorder(time_base::no_order)
{ _Init_timeinfo(_M_timeinfo); }
time_init<wchar_t>::time_init(const char* __name) {
if (!__name)
locale::_M_throw_on_null_name();
int __err_code;
char buf[_Locale_MAX_SIMPLE_NAME];
_Locale_time *__time = __acquire_time(__name, buf, 0, &__err_code);
if (!__time)
locale::_M_throw_on_creation_failure(__err_code, __name, "time");
_Init_timeinfo(this->_M_timeinfo, __time);
_M_dateorder = __get_date_order(__time);
__release_time(__time);
}
time_init<wchar_t>::time_init(_Locale_time *__time) {
_Init_timeinfo(this->_M_timeinfo, __time);
_M_dateorder = __get_date_order(__time);
}
#endif
_STLP_MOVE_TO_STD_NAMESPACE
#if !defined (_STLP_NO_FORCE_INSTANTIATE)
template class time_get<char, istreambuf_iterator<char, char_traits<char> > >;
template class time_put<char, ostreambuf_iterator<char, char_traits<char> > >;
# ifndef _STLP_NO_WCHAR_T
template class time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
template class time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
# endif
#endif
_STLP_END_NAMESPACE

View File

@@ -0,0 +1,61 @@
#if !defined (__ICL)
/* This header is used to turn off warnings of Microsoft compilers generated.
* while building STLport.
* For compiling user code, see stlport/config/_msvc_warnings_off.h.
*/
# if (_MSC_VER < 1300) /* VC6/eVC4 */
# pragma warning( disable : 4097 ) /* typedef-name used as based class of (...) */
# pragma warning( disable : 4251 ) /* DLL interface needed */
# pragma warning( disable : 4284 ) /* for -> operator */
# pragma warning( disable : 4503 ) /* decorated name length exceeded, name was truncated */
# pragma warning( disable : 4514 ) /* unreferenced inline function has been removed */
# pragma warning( disable : 4660 ) /* template-class specialization '...' is already instantiated */
# pragma warning( disable : 4701 ) /* local variable 'base' may be used without having been initialized */
# pragma warning( disable : 4710 ) /* function (...) not inlined */
# pragma warning( disable : 4786 ) /* identifier truncated to 255 characters */
# endif
# if (_MSC_VER <= 1310)
# pragma warning( disable : 4511 ) /* copy constructor cannot be generated */
# endif
# if (_MSC_VER < 1300) && defined (UNDER_CE)
# pragma warning( disable : 4201 ) /* nonstandard extension used : nameless struct/union */
# pragma warning( disable : 4214 ) /* nonstandard extension used : bit field types other than int */
# endif
/* Suppress warnings emitted from Windows CE SDK headers. */
# if (_MSC_VER >= 1400) && defined (UNDER_CE)
# pragma warning( disable : 4115 ) /* Named type definition in parentheses. */
# pragma warning( disable : 4201 ) /* Nameless struct/union. */
# pragma warning( disable : 4214 ) /* Bit field types other than int. */
# pragma warning( disable : 4290 ) /* C++ exception specification ignored. */
# pragma warning( disable : 4430 ) /* Missing type specifier, int assumed. */
# pragma warning( disable : 4431 ) /* Missing type specifier, int assumed. */
# endif
# pragma warning( disable : 4075 ) /* initializers put in unrecognized initialization area */
/* This warning is disable only for the c_locale_win32.c file compilation: */
# pragma warning( disable : 4100 ) /* unreferenced formal parameter */
# pragma warning( disable : 4127 ) /* conditional expression is constant */
# pragma warning( disable : 4146 ) /* unary minus applied to unsigned type */
# pragma warning( disable : 4245 ) /* conversion from 'enum ' to 'unsigned int', signed/unsigned mismatch */
# pragma warning( disable : 4244 ) /* implicit conversion: possible loss of data */
# pragma warning( disable : 4512 ) /* assignment operator could not be generated */
# pragma warning( disable : 4571 ) /* catch(...) blocks compiled with /EHs do not catch or re-throw Structured Exceptions */
# pragma warning( disable : 4702 ) /* unreachable code (appears in release with warning level4) */
#else
# pragma warning( disable : 69 ) /* integer conversion resulted in truncation */
# pragma warning( disable : 174 ) /* expression has no effect */
# pragma warning( disable : 279 ) /* controling expression is constant */
# pragma warning( disable : 383 ) /* reference to temporary used */
# pragma warning( disable : 444 ) /* destructor for base class "..." is not virtual*/
# pragma warning( disable : 810 ) /* conversion from "int" to "char" may lose significant bits */
# pragma warning( disable : 981 ) /* operands are evaluated in unspecified order */
# pragma warning( disable : 1418 ) /* external definition with no prior declaration */
# pragma warning( disable : 1419 ) /* external declaration in primary source file */
# pragma warning( disable : 1572 ) /* floating-point equality and inequality comparisons are unreliable */
# pragma warning( disable : 1682 ) /* implicit conversion of a 64-bit integral type to a smaller integral type */
# pragma warning( disable : 1683 ) /* explicit conversion of a 64-bit integral type to a smaller integral type */
#endif