2009-01-27 04:30 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbdefs.h
* added some C compilers which supports stdint.h
* harbour/source/common/hbprintf.c
* eliminated non portable GCC only C syntax.
* updated to compile with other C compilers.
Now only GNUC with C99 support and BORLAND C gives all
+inf/-inf/NaN values for [long] double conversions.
Other compilers uses NaN also for infinite numbers or nothing.
Please add full support for them. See TODO notes I left.
For compilers which supports C99 floating point macros should
be enough to enable the same macros used for GNUC && _ISOC99_SOURCE.
* harbour/contrib/hbcrypt/sha2.h
* harbour/contrib/hbcrypt/sha2.c
! fixed BCC5.5 compilation
TOFIX: harbour/contrib/hbssl/ssl.c[631], sslctx.c[268], sslctx.c[281]
error: invalid conversion from ‘void*’ to ‘const char*’
I do not know if SSL_get_ex_data()/SSL_CTX_get_app_data()
returns valid ASCIIZ string so I cannot decide if simple casting
is safe and to pacify above errors.
Viktor, can you look at it?
This commit is contained in:
@@ -8,6 +8,31 @@
|
||||
2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
|
||||
*/
|
||||
|
||||
2009-01-27 04:30 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/include/hbdefs.h
|
||||
* added some C compilers which supports stdint.h
|
||||
|
||||
* harbour/source/common/hbprintf.c
|
||||
* eliminated non portable GCC only C syntax.
|
||||
* updated to compile with other C compilers.
|
||||
Now only GNUC with C99 support and BORLAND C gives all
|
||||
+inf/-inf/NaN values for [long] double conversions.
|
||||
Other compilers uses NaN also for infinite numbers or nothing.
|
||||
Please add full support for them. See TODO notes I left.
|
||||
For compilers which supports C99 floating point macros should
|
||||
be enough to enable the same macros used for GNUC && _ISOC99_SOURCE.
|
||||
|
||||
* harbour/contrib/hbcrypt/sha2.h
|
||||
* harbour/contrib/hbcrypt/sha2.c
|
||||
! fixed BCC5.5 compilation
|
||||
|
||||
TOFIX: harbour/contrib/hbssl/ssl.c[631], sslctx.c[268], sslctx.c[281]
|
||||
error: invalid conversion from ‘void*’ to ‘const char*’
|
||||
I do not know if SSL_get_ex_data()/SSL_CTX_get_app_data()
|
||||
returns valid ASCIIZ string so I cannot decide if simple casting
|
||||
is safe and to pacify above errors.
|
||||
Viktor, can you look at it?
|
||||
|
||||
2009-01-27 02:22 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
|
||||
* source/rtl/version.c
|
||||
! Fixed hb_version( HB_VERSION_BUILD_DATE ).
|
||||
|
||||
@@ -131,6 +131,18 @@
|
||||
wv[h] = t1 + t2; \
|
||||
}
|
||||
|
||||
#if defined( __BORLANDC__ )
|
||||
# if __BORLANDC__ >= 1328
|
||||
# define _ULL( num ) num##ui64
|
||||
# else
|
||||
# define _ULL( num ) num
|
||||
# endif
|
||||
#elif defined( _MSC_VER )
|
||||
# define _ULL( num ) num
|
||||
#else
|
||||
# define _ULL( num ) num##ULL
|
||||
#endif
|
||||
|
||||
uint32 sha224_h0[8] =
|
||||
{0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
||||
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4};
|
||||
@@ -140,16 +152,16 @@ uint32 sha256_h0[8] =
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
|
||||
|
||||
uint64 sha384_h0[8] =
|
||||
{0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL,
|
||||
0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL,
|
||||
0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL,
|
||||
0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL};
|
||||
{_ULL( 0xcbbb9d5dc1059ed8 ), _ULL( 0x629a292a367cd507 ),
|
||||
_ULL( 0x9159015a3070dd17 ), _ULL( 0x152fecd8f70e5939 ),
|
||||
_ULL( 0x67332667ffc00b31 ), _ULL( 0x8eb44a8768581511 ),
|
||||
_ULL( 0xdb0c2e0d64f98fa7 ), _ULL( 0x47b5481dbefa4fa4 )};
|
||||
|
||||
uint64 sha512_h0[8] =
|
||||
{0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};
|
||||
{_ULL( 0x6a09e667f3bcc908 ), _ULL( 0xbb67ae8584caa73b ) ,
|
||||
_ULL( 0x3c6ef372fe94f82b ), _ULL( 0xa54ff53a5f1d36f1 ) ,
|
||||
_ULL( 0x510e527fade682d1 ), _ULL( 0x9b05688c2b3e6c1f ) ,
|
||||
_ULL( 0x1f83d9abfb41bd6b ), _ULL( 0x5be0cd19137e2179 ) };
|
||||
|
||||
uint32 sha256_k[64] =
|
||||
{0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
@@ -170,46 +182,46 @@ uint32 sha256_k[64] =
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
|
||||
|
||||
uint64 sha512_k[80] =
|
||||
{0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
|
||||
0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
|
||||
0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
|
||||
0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
|
||||
0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
|
||||
0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
|
||||
0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
|
||||
0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
|
||||
0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
|
||||
0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
|
||||
0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
|
||||
0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
|
||||
0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
|
||||
0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
|
||||
0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
|
||||
0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
|
||||
0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
|
||||
0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
|
||||
0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
|
||||
0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
|
||||
0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
|
||||
0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
|
||||
0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
|
||||
0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
|
||||
0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
|
||||
0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
|
||||
0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
|
||||
0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
|
||||
0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
|
||||
0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
|
||||
0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
|
||||
0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
|
||||
0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
|
||||
0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
|
||||
0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
|
||||
0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
|
||||
0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
|
||||
0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
|
||||
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
|
||||
0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL};
|
||||
{_ULL( 0x428a2f98d728ae22 ), _ULL( 0x7137449123ef65cd ),
|
||||
_ULL( 0xb5c0fbcfec4d3b2f ), _ULL( 0xe9b5dba58189dbbc ),
|
||||
_ULL( 0x3956c25bf348b538 ), _ULL( 0x59f111f1b605d019 ),
|
||||
_ULL( 0x923f82a4af194f9b ), _ULL( 0xab1c5ed5da6d8118 ),
|
||||
_ULL( 0xd807aa98a3030242 ), _ULL( 0x12835b0145706fbe ),
|
||||
_ULL( 0x243185be4ee4b28c ), _ULL( 0x550c7dc3d5ffb4e2 ),
|
||||
_ULL( 0x72be5d74f27b896f ), _ULL( 0x80deb1fe3b1696b1 ),
|
||||
_ULL( 0x9bdc06a725c71235 ), _ULL( 0xc19bf174cf692694 ),
|
||||
_ULL( 0xe49b69c19ef14ad2 ), _ULL( 0xefbe4786384f25e3 ),
|
||||
_ULL( 0x0fc19dc68b8cd5b5 ), _ULL( 0x240ca1cc77ac9c65 ),
|
||||
_ULL( 0x2de92c6f592b0275 ), _ULL( 0x4a7484aa6ea6e483 ),
|
||||
_ULL( 0x5cb0a9dcbd41fbd4 ), _ULL( 0x76f988da831153b5 ),
|
||||
_ULL( 0x983e5152ee66dfab ), _ULL( 0xa831c66d2db43210 ),
|
||||
_ULL( 0xb00327c898fb213f ), _ULL( 0xbf597fc7beef0ee4 ),
|
||||
_ULL( 0xc6e00bf33da88fc2 ), _ULL( 0xd5a79147930aa725 ),
|
||||
_ULL( 0x06ca6351e003826f ), _ULL( 0x142929670a0e6e70 ),
|
||||
_ULL( 0x27b70a8546d22ffc ), _ULL( 0x2e1b21385c26c926 ),
|
||||
_ULL( 0x4d2c6dfc5ac42aed ), _ULL( 0x53380d139d95b3df ),
|
||||
_ULL( 0x650a73548baf63de ), _ULL( 0x766a0abb3c77b2a8 ),
|
||||
_ULL( 0x81c2c92e47edaee6 ), _ULL( 0x92722c851482353b ),
|
||||
_ULL( 0xa2bfe8a14cf10364 ), _ULL( 0xa81a664bbc423001 ),
|
||||
_ULL( 0xc24b8b70d0f89791 ), _ULL( 0xc76c51a30654be30 ),
|
||||
_ULL( 0xd192e819d6ef5218 ), _ULL( 0xd69906245565a910 ),
|
||||
_ULL( 0xf40e35855771202a ), _ULL( 0x106aa07032bbd1b8 ),
|
||||
_ULL( 0x19a4c116b8d2d0c8 ), _ULL( 0x1e376c085141ab53 ),
|
||||
_ULL( 0x2748774cdf8eeb99 ), _ULL( 0x34b0bcb5e19b48a8 ),
|
||||
_ULL( 0x391c0cb3c5c95a63 ), _ULL( 0x4ed8aa4ae3418acb ),
|
||||
_ULL( 0x5b9cca4f7763e373 ), _ULL( 0x682e6ff3d6b2b8a3 ),
|
||||
_ULL( 0x748f82ee5defb2fc ), _ULL( 0x78a5636f43172f60 ),
|
||||
_ULL( 0x84c87814a1f0ab72 ), _ULL( 0x8cc702081a6439ec ),
|
||||
_ULL( 0x90befffa23631e28 ), _ULL( 0xa4506cebde82bde9 ),
|
||||
_ULL( 0xbef9a3f7b2c67915 ), _ULL( 0xc67178f2e372532b ),
|
||||
_ULL( 0xca273eceea26619c ), _ULL( 0xd186b8c721c0c207 ),
|
||||
_ULL( 0xeada7dd6cde0eb1e ), _ULL( 0xf57d4f7fee6ed178 ),
|
||||
_ULL( 0x06f067aa72176fba ), _ULL( 0x0a637dc5a2c898a6 ),
|
||||
_ULL( 0x113f9804bef90dae ), _ULL( 0x1b710b35131c471b ),
|
||||
_ULL( 0x28db77f523047d84 ), _ULL( 0x32caab7b40c72493 ),
|
||||
_ULL( 0x3c9ebe0a15c9bebc ), _ULL( 0x431d67c49c100d4c ),
|
||||
_ULL( 0x4cc5d4becb3e42b6 ), _ULL( 0x597f299cfc657e2a ),
|
||||
_ULL( 0x5fcb6fab3ad6faec ), _ULL( 0x6c44198c4a475817 )};
|
||||
|
||||
/* SHA-256 functions */
|
||||
|
||||
|
||||
@@ -52,8 +52,12 @@
|
||||
#define SHA2_TYPES
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned int uint32;
|
||||
#if defined( __BORLANDC__ )
|
||||
typedef unsigned __int64 uint64;
|
||||
#else
|
||||
typedef unsigned long long uint64;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -63,10 +63,13 @@
|
||||
#include "hbtrace.h"
|
||||
#include "hbver.h"
|
||||
|
||||
#if defined( __XCC__ ) || defined( __MINGW32__ ) || \
|
||||
#if defined( __XCC__ ) || defined( __POCC__ ) || defined( __LCC__ ) || \
|
||||
defined( __MINGW32__ ) || defined(__DMC__) || \
|
||||
( defined( __BORLANDC__ ) && __BORLANDC__ >= 1410 ) || \
|
||||
( defined( __WATCOMC__ ) && __WATCOMC__ >= 1270 ) || \
|
||||
( defined( __GNUC__ ) && \
|
||||
( defined( HB_OS_LINUX ) || defined( HB_OS_DARWIN ) ) )
|
||||
( defined( _ISOC99_SOURCE ) || \
|
||||
defined( HB_OS_LINUX ) || defined( HB_OS_DARWIN ) ) )
|
||||
#include <stdint.h>
|
||||
/* workaround for BCC 5.8 bug */
|
||||
#if ( defined( __BORLANDC__ ) && __BORLANDC__ >= 1410 )
|
||||
@@ -454,13 +457,17 @@
|
||||
#if defined( __BORLANDC__ )
|
||||
# if __BORLANDC__ >= 1328
|
||||
# define HB_LL( num ) num##i64
|
||||
# define HB_ULL( num ) num##ui64
|
||||
# else
|
||||
# define HB_LL( num ) num
|
||||
# define HB_ULL( num ) num
|
||||
# endif
|
||||
#elif defined( _MSC_VER )
|
||||
# define HB_LL( num ) num
|
||||
# define HB_ULL( num ) num
|
||||
#else
|
||||
# define HB_LL( num ) num##LL
|
||||
# define HB_ULL( num ) num##ULL
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
|
||||
/*
|
||||
patterm format:
|
||||
@@ -90,60 +90,151 @@ optimized.
|
||||
|
||||
/* #define __NO_DOUBLE__ */
|
||||
/* #define __NO_LONGDOUBLE__ */
|
||||
/* #define __NO_ARGPOS__ */
|
||||
/* #define __NO_LONGLONG__ */
|
||||
/* #define __NO_ARGPOS__ */
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(__DJGPP__)
|
||||
# include <libm/math.h>
|
||||
_LIB_VERSION_TYPE _LIB_VERSION = _XOPEN_;
|
||||
#else
|
||||
# include <math.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include "hbapi.h"
|
||||
#include "hbmath.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#if defined( __GNUC__ )
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#ifndef __NO_ARGPOS__
|
||||
# include <stdlib.h> /* malloc()/realloc()/free() */
|
||||
#if defined( __BORLANDC__ ) || defined( __WATCOMC__ )
|
||||
# include <float.h>
|
||||
#elif defined(__DJGPP__)
|
||||
_LIB_VERSION_TYPE _LIB_VERSION = _XOPEN_;
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# define _EXTERN_C extern "C"
|
||||
#else
|
||||
# define _EXTERN_C extern
|
||||
HB_EXTERN_BEGIN
|
||||
|
||||
int hb_snprintf_c( char *buffer, size_t bufsize, const char *format, ... )
|
||||
HB_PRINTF_FORMAT( 3, 4 );
|
||||
|
||||
HB_EXTERN_END
|
||||
|
||||
#if defined( HB_LONG_DOUBLE_OFF ) && !defined( __NO_LONGDOUBLE__ )
|
||||
# define __NO_LONGDOUBLE__
|
||||
#endif
|
||||
|
||||
#if defined( __GNUC__ )
|
||||
_EXTERN_C int hb_snprintf_c( char *buffer, size_t bufsize, const char *format, ... )
|
||||
__attribute__ (( format (printf, 3, 4)));
|
||||
#if defined( HB_LONG_LONG_OFF ) && !defined( __NO_LONGLONG__ )
|
||||
# define __NO_LONGLONG__
|
||||
#endif
|
||||
|
||||
/* few macros for some platform dependent floating point functions/macros */
|
||||
|
||||
#define _HB_NUM_NAN 1
|
||||
#define _HB_NUM_PINF 2
|
||||
#define _HB_NUM_NINF 4
|
||||
|
||||
#if defined( __BORLANDC__ )
|
||||
/* use Borland C _fpclass[l]() function */
|
||||
# ifdef __NO_LONGDOUBLE__
|
||||
# define hb_fpclassify( d ) _fpclass( d )
|
||||
# else
|
||||
# define hb_fpclassify( d ) _fpclassl( d )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if ( defined( __BORLANDC__ ) && __BORLANDC__ < 1410 ) || \
|
||||
( defined( __WATCOMC__ ) && __WATCOMC__ < 1270 )
|
||||
# define intmax_t _x_longlong
|
||||
# define uintmax_t _x_ulonglong
|
||||
#endif
|
||||
|
||||
/* signbit() needs _GNU_SOURCE defined. If it's not available on given
|
||||
* platform then it can be replaced by 'value < 0' but in such case
|
||||
* -0.0 will be shown as 0.0
|
||||
*/
|
||||
#if defined( __GNUC__ ) && defined( _ISOC99_SOURCE )
|
||||
/* use C99 macros */
|
||||
# define hb_signbit( d ) signbit( d )
|
||||
|
||||
#elif defined( __BORLANDC__ )
|
||||
|
||||
# define hb_signbit( d ) ( ( hb_fpclassify( d ) & ( _FPCLASS_NINF | _FPCLASS_NZ ) ) != 0 )
|
||||
|
||||
#elif 0 /* TODO: add other C compilers here (check their version number) */
|
||||
#else
|
||||
|
||||
#define strnlen( s, maxlen ) \
|
||||
( { size_t n = maxlen, size = 0; \
|
||||
while( n < maxlen && s[ size ] ) \
|
||||
++size; \
|
||||
size; \
|
||||
} )
|
||||
# define hb_signbit( d ) ( d < 0 )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined( __GNUC__ ) && defined( _ISOC99_SOURCE )
|
||||
|
||||
/* use C99 macros */
|
||||
# define HB_NUMTYPE( v, d ) do { \
|
||||
v = ( isfinite( d ) ? 0 : \
|
||||
( isnan( d ) ? _HB_NUM_NAN : \
|
||||
( isinf( d ) < 0 ? _HB_NUM_NINF : \
|
||||
_HB_NUM_PINF ) ) ); \
|
||||
} while( 0 )
|
||||
|
||||
#elif defined( __GNUC__ ) && \
|
||||
( defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) || \
|
||||
defined( _XOPEN_SOURCE ) )
|
||||
|
||||
/* use BSD floating point functions */
|
||||
# ifdef __NO_LONGDOUBLE__
|
||||
# define HB_NUMTYPE( v, d ) do { \
|
||||
v = ( finite( d ) ? 0 : \
|
||||
( isnan( d ) ? _HB_NUM_NAN : \
|
||||
( isinf( d ) < 0 ? _HB_NUM_NINF : \
|
||||
_HB_NUM_PINF ) ) ); \
|
||||
} while( 0 )
|
||||
# else
|
||||
# define HB_NUMTYPE( v, d ) do { \
|
||||
v = ( finitel( d ) ? 0 : \
|
||||
( isnanl( d ) ? _HB_NUM_NAN : \
|
||||
( isinfl( d ) < 0 ? _HB_NUM_NINF : \
|
||||
_HB_NUM_PINF ) ) ); \
|
||||
} while( 0 )
|
||||
# endif
|
||||
|
||||
#elif defined( __BORLANDC__ )
|
||||
|
||||
# define HB_NUMTYPE( v, d ) do { \
|
||||
int t = hb_fpclassify( d ); \
|
||||
v = ( ( t & ( _FPCLASS_UNSUP | _FPCLASS_SNAN | _FPCLASS_QNAN ) ) ? _HB_NUM_NAN : \
|
||||
( ( t & _FPCLASS_NINF ) ? _HB_NUM_NINF : \
|
||||
( ( t & _FPCLASS_PINF ) ? _HB_NUM_PINF : 0 ) ) ); \
|
||||
} while( 0 )
|
||||
#elif 0 /* TODO: add other C compilers here (check their version number) */
|
||||
#else
|
||||
|
||||
# if defined(__RSXNT__) || defined(__EMX__) || \
|
||||
defined(__XCC__) || defined(__POCC__) || \
|
||||
defined(HB_OS_HPUX)
|
||||
# define hb_isfinite( d ) isfinite( d )
|
||||
# elif defined(__WATCOMC__) || defined(__BORLANDC__) || defined(_MSC_VER)
|
||||
# define hb_isfinite( d ) _finite( d )
|
||||
# elif defined(__GNUC__) || defined(__DJGPP__) || defined(__MINGW32__) || \
|
||||
defined(__LCC__)
|
||||
# define hb_isfinite( d ) finite( d )
|
||||
# else
|
||||
# define hb_isfinite( d ) FALSE
|
||||
# endif
|
||||
|
||||
# define HB_NUMTYPE( v, d ) do { \
|
||||
v = hb_isfinite( d ) ? 0 : _HB_NUM_NAN ; \
|
||||
} while( 0 )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define _ARGBUF_SIZE 16
|
||||
#define _ARGBUF_ALLOC 16
|
||||
|
||||
#define _F_ALTERNATE 0x01 /* only for: o xX aA eE fF gG */
|
||||
#define _F_ZEROPADED 0x02 /* only for: d i o u xX aA eE fF gG */
|
||||
#define _F_LEFTADJUSTED 0x04 /* clears _F_ZEROPADED */
|
||||
#define _F_SPACE 0x08 /* only for signed num conversions: d i fF aA eE gG */
|
||||
#define _F_SIGN 0x10 /* only for signed num conversions: d i fF aA eE gG, clears _F_SPACE */
|
||||
|
||||
#define _ARGBUF_SIZE 16
|
||||
|
||||
#define _L_UNDEF_ 0
|
||||
#define _L_CHAR_ 1
|
||||
#define _L_SHORT_ 2
|
||||
@@ -156,14 +247,17 @@ _EXTERN_C int hb_snprintf_c( char *buffer, size_t bufsize, const char *format, .
|
||||
#define _L_LONGDOUBLE_ 9
|
||||
|
||||
#ifndef __NO_DOUBLE__
|
||||
# ifndef __NO_LONGDOUBLE__
|
||||
# define _x_long_dbl long double
|
||||
# define _POWD( x, y ) powl( x, y )
|
||||
# define _MODFD( x, p ) modfl( x, p )
|
||||
# else
|
||||
# ifdef __NO_LONGDOUBLE__
|
||||
# define _x_long_dbl double
|
||||
# define _POWD( x, y ) pow( x, y )
|
||||
# define _MODFD( x, p ) modf( x, p )
|
||||
# else
|
||||
# define _x_long_dbl long double
|
||||
# if defined( __WATCOMC__ ) || defined( __MINGW32CE__ )
|
||||
# define _HB_WRAP_MODFL_
|
||||
# define _MODFD( x, p ) _hb_modfl( x, p )
|
||||
# else
|
||||
# define _MODFD( x, p ) modfl( x, p )
|
||||
# endif
|
||||
# endif
|
||||
# define _x_double double
|
||||
#else
|
||||
@@ -171,8 +265,8 @@ _EXTERN_C int hb_snprintf_c( char *buffer, size_t bufsize, const char *format, .
|
||||
# define _x_double int
|
||||
#endif
|
||||
#ifndef __NO_LONGLONG__
|
||||
# define _x_longlong long long
|
||||
# define _x_ulonglong unsigned long long
|
||||
# define _x_longlong LONGLONG
|
||||
# define _x_ulonglong ULONGLONG
|
||||
#else
|
||||
# define _x_longlong long
|
||||
# define _x_ulonglong unsigned long
|
||||
@@ -228,6 +322,13 @@ typedef struct {
|
||||
x_type value;
|
||||
} v_param;
|
||||
|
||||
typedef struct {
|
||||
int maxarg;
|
||||
int size;
|
||||
BOOL repeat;
|
||||
v_param * arglst;
|
||||
} v_paramlst;
|
||||
|
||||
#ifdef __NO_ARGPOS__
|
||||
|
||||
/* this version does not support positional parameters (f.e. '%1$d')
|
||||
@@ -267,105 +368,103 @@ typedef struct {
|
||||
#else
|
||||
|
||||
#define va_arg_n( va, type, n ) \
|
||||
( { \
|
||||
type result; \
|
||||
if( n == 0 ) \
|
||||
{ \
|
||||
result = va_arg( va, type ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if( maxarg == 0 ) \
|
||||
{ \
|
||||
repeat = 1; \
|
||||
memset( argbuf, 0, sizeof( argbuf ) ); \
|
||||
} \
|
||||
if( repeat ) \
|
||||
{ \
|
||||
if( n > maxarg ) \
|
||||
maxarg = n; \
|
||||
if( n > argbuf_size ) \
|
||||
{ \
|
||||
int prev_size = argbuf_size; \
|
||||
argbuf_size = n + _ARGBUF_SIZE; \
|
||||
if( argbuf_size == _ARGBUF_SIZE ) \
|
||||
arglst = memcpy( malloc( argbuf_size * sizeof( v_param ) ), \
|
||||
argbuf, sizeof( argbuf ) ); \
|
||||
else \
|
||||
arglst = realloc( arglst, argbuf_size * sizeof( v_param ) ); \
|
||||
memset( &arglst[ prev_size ], 0, ( argbuf_size - prev_size ) * \
|
||||
sizeof( v_param ) ); \
|
||||
argbuf_size += _ARGBUF_SIZE; \
|
||||
} \
|
||||
arglst[ n - 1 ].id = (v##type); \
|
||||
result = ( type ) 0; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
result = arglst[ n - 1 ].value.as##type; \
|
||||
} \
|
||||
} \
|
||||
result; \
|
||||
} )
|
||||
( n == 0 ? va_arg( va, type ) : \
|
||||
va_arg_get( n, ¶ms, v##type )->value.as##type )
|
||||
|
||||
#define va_arg_fill( va ) \
|
||||
do { \
|
||||
int iArg; \
|
||||
va_start( va, format ); \
|
||||
for( iArg = 0; iArg < maxarg; ++iArg ) \
|
||||
{ \
|
||||
switch( arglst[ iArg ].id ) \
|
||||
{ \
|
||||
case v_x_uint: \
|
||||
arglst[ iArg ].value.as_x_uint = va_arg( va, _x_uint ); \
|
||||
break; \
|
||||
case v_x_long: \
|
||||
arglst[ iArg ].value.as_x_long = va_arg( va, _x_long ); \
|
||||
break; \
|
||||
case v_x_ulong: \
|
||||
arglst[ iArg ].value.as_x_ulong = va_arg( va, _x_ulong ); \
|
||||
break; \
|
||||
case v_x_longlong: \
|
||||
arglst[ iArg ].value.as_x_longlong = va_arg( va, _x_longlong ); \
|
||||
break; \
|
||||
case v_x_ulonglong: \
|
||||
arglst[ iArg ].value.as_x_ulonglong = va_arg( va, _x_ulonglong ); \
|
||||
break; \
|
||||
case v_x_intmax_t: \
|
||||
arglst[ iArg ].value.as_x_intmax_t = va_arg( va, _x_intmax_t ); \
|
||||
break; \
|
||||
case v_x_uintmax_t: \
|
||||
arglst[ iArg ].value.as_x_uintmax_t = va_arg( va, _x_uintmax_t ); \
|
||||
break; \
|
||||
case v_x_size_t: \
|
||||
arglst[ iArg ].value.as_x_size_t = va_arg( va, _x_size_t ); \
|
||||
break; \
|
||||
case v_x_ptrdiff_t: \
|
||||
arglst[ iArg ].value.as_x_ptrdiff_t = va_arg( va, _x_ptrdiff_t ); \
|
||||
break; \
|
||||
case v_x_ptr: \
|
||||
arglst[ iArg ].value.as_x_ptr = va_arg( va, _x_ptr ); \
|
||||
break; \
|
||||
case v_x_str: \
|
||||
arglst[ iArg ].value.as_x_str = va_arg( va, _x_str ); \
|
||||
break; \
|
||||
case v_x_intptr: \
|
||||
arglst[ iArg ].value.as_x_intptr = va_arg( va, _x_intptr ); \
|
||||
break; \
|
||||
case v_x_double: \
|
||||
arglst[ iArg ].value.as_x_double = va_arg( va, _x_double ); \
|
||||
break; \
|
||||
case v_x_long_dbl: \
|
||||
arglst[ iArg ].value.as_x_long_dbl = va_arg( va, _x_long_dbl ); \
|
||||
break; \
|
||||
default: \
|
||||
arglst[ iArg ].value.as_x_int = va_arg( va, _x_int ); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
va_end( va ); \
|
||||
} while( 0 )
|
||||
static v_param * va_arg_get( int iArg, v_paramlst * plst, int iType )
|
||||
{
|
||||
if( plst->maxarg == 0 )
|
||||
{
|
||||
plst->repeat = TRUE;
|
||||
memset( plst->arglst, 0, plst->size * sizeof( v_param ) );
|
||||
}
|
||||
if( plst->repeat )
|
||||
{
|
||||
if( iArg > plst->maxarg )
|
||||
plst->maxarg = iArg;
|
||||
if( iArg > plst->size )
|
||||
{
|
||||
int prev_size = plst->size;
|
||||
|
||||
plst->size = iArg + _ARGBUF_ALLOC;
|
||||
if( prev_size == _ARGBUF_SIZE )
|
||||
plst->arglst = ( v_param * ) memcpy( hb_xgrab( plst->size * sizeof( v_param ) ),
|
||||
plst->arglst, _ARGBUF_SIZE * sizeof( v_param ) );
|
||||
else
|
||||
plst->arglst = ( v_param * ) hb_xrealloc( plst->arglst, plst->size * sizeof( v_param ) );
|
||||
memset( &plst->arglst[ prev_size ], 0, ( plst->size - prev_size ) *
|
||||
sizeof( v_param ) );
|
||||
}
|
||||
plst->arglst[ iArg - 1 ].id = iType;
|
||||
}
|
||||
return &plst->arglst[ iArg - 1 ];
|
||||
}
|
||||
|
||||
static void va_arg_fill( v_paramlst * plst, va_list va )
|
||||
{
|
||||
int iArg;
|
||||
for( iArg = 0; iArg < plst->maxarg; ++iArg )
|
||||
{
|
||||
switch( plst->arglst[ iArg ].id )
|
||||
{
|
||||
case v_x_uint:
|
||||
plst->arglst[ iArg ].value.as_x_uint = va_arg( va, _x_uint );
|
||||
break;
|
||||
case v_x_long:
|
||||
plst->arglst[ iArg ].value.as_x_long = va_arg( va, _x_long );
|
||||
break;
|
||||
case v_x_ulong:
|
||||
plst->arglst[ iArg ].value.as_x_ulong = va_arg( va, _x_ulong );
|
||||
break;
|
||||
case v_x_longlong:
|
||||
plst->arglst[ iArg ].value.as_x_longlong = va_arg( va, _x_longlong );
|
||||
break;
|
||||
case v_x_ulonglong:
|
||||
plst->arglst[ iArg ].value.as_x_ulonglong = va_arg( va, _x_ulonglong );
|
||||
break;
|
||||
case v_x_intmax_t:
|
||||
plst->arglst[ iArg ].value.as_x_intmax_t = va_arg( va, _x_intmax_t );
|
||||
break;
|
||||
case v_x_uintmax_t:
|
||||
plst->arglst[ iArg ].value.as_x_uintmax_t = va_arg( va, _x_uintmax_t );
|
||||
break;
|
||||
case v_x_size_t:
|
||||
plst->arglst[ iArg ].value.as_x_size_t = va_arg( va, _x_size_t );
|
||||
break;
|
||||
case v_x_ptrdiff_t:
|
||||
plst->arglst[ iArg ].value.as_x_ptrdiff_t = va_arg( va, _x_ptrdiff_t );
|
||||
break;
|
||||
case v_x_ptr:
|
||||
plst->arglst[ iArg ].value.as_x_ptr = va_arg( va, _x_ptr );
|
||||
break;
|
||||
case v_x_str:
|
||||
plst->arglst[ iArg ].value.as_x_str = va_arg( va, _x_str );
|
||||
break;
|
||||
case v_x_intptr:
|
||||
plst->arglst[ iArg ].value.as_x_intptr = va_arg( va, _x_intptr );
|
||||
break;
|
||||
case v_x_double:
|
||||
plst->arglst[ iArg ].value.as_x_double = va_arg( va, _x_double );
|
||||
break;
|
||||
case v_x_long_dbl:
|
||||
plst->arglst[ iArg ].value.as_x_long_dbl = va_arg( va, _x_long_dbl );
|
||||
break;
|
||||
default:
|
||||
plst->arglst[ iArg ].value.as_x_int = va_arg( va, _x_int );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _HB_WRAP_MODFL_
|
||||
_x_long_dbl _hb_modfl( _x_long_dbl x, _x_long_dbl * p )
|
||||
{
|
||||
_x_double pd = *p;
|
||||
_x_long_dbl r = modf( x, &pd );
|
||||
*p = pd;
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char get_decimal( char c, const char **format, int *result )
|
||||
@@ -507,15 +606,7 @@ static size_t put_dbl( char *buffer, size_t bufsize, size_t size,
|
||||
|
||||
if( precision < 0 )
|
||||
precision = 6;
|
||||
/* signbit() needs _GNU_SOURCE defined. If it's not available on given
|
||||
* platform then it can be replaced by 'value < 0' but in such case
|
||||
* -0.0 will be shown as 0.0
|
||||
*/
|
||||
#if defined( __GNUC__ )
|
||||
sign = signbit( value );
|
||||
#else
|
||||
sign = value < 0;
|
||||
#endif
|
||||
sign = hb_signbit( value );
|
||||
if( sign )
|
||||
value = - value;
|
||||
|
||||
@@ -688,18 +779,7 @@ static size_t put_str( char *buffer, size_t bufsize, size_t size,
|
||||
if( precision < 0 )
|
||||
precision = ( int ) strlen( str );
|
||||
else if( precision > 0 )
|
||||
/* strnlen() is GNU extension. It needs _GNU_SOURCE
|
||||
* macro defined before including header files. If this
|
||||
* function does not exist on some platform then can be
|
||||
* easy replaced by this macro:
|
||||
* #define strnlen( s, maxlen ) \
|
||||
* ( { size_t n = maxlen, size = 0; \
|
||||
* while( n < maxlen && s[ size ] ) \
|
||||
* ++size; \
|
||||
* size; \
|
||||
* } )
|
||||
*/
|
||||
precision = ( int ) strnlen( str, precision );
|
||||
precision = ( int ) hb_strnlen( str, precision );
|
||||
|
||||
width -= precision;
|
||||
if( ( flags & _F_LEFTADJUSTED ) == 0 ) while( width > 0 )
|
||||
@@ -735,19 +815,25 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... )
|
||||
#ifndef __NO_ARGPOS__
|
||||
const char * fmt_start = format;
|
||||
v_param argbuf[ _ARGBUF_SIZE ];
|
||||
v_param * arglst = argbuf;
|
||||
int argbuf_size = _ARGBUF_SIZE;
|
||||
int repeat = 1;
|
||||
int maxarg = 0;
|
||||
v_paramlst params;
|
||||
|
||||
params.size = _ARGBUF_SIZE;
|
||||
params.maxarg = 0;
|
||||
params.arglst = argbuf;
|
||||
params.repeat = TRUE;
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef __NO_ARGPOS__
|
||||
while( repeat )
|
||||
while( params.repeat )
|
||||
{
|
||||
repeat = 0;
|
||||
if( maxarg > 0 )
|
||||
va_arg_fill( args );
|
||||
params.repeat = 0;
|
||||
if( params.maxarg > 0 )
|
||||
{
|
||||
va_start( args, format );
|
||||
va_arg_fill( ¶ms, args );
|
||||
va_end( args );
|
||||
}
|
||||
format = fmt_start;
|
||||
#endif
|
||||
va_start( args, format );
|
||||
@@ -764,22 +850,24 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... )
|
||||
if( c != 0 && c != '%' )
|
||||
{
|
||||
/* decode pattern */
|
||||
int param = 0, flags = 0, width = -1, precision = -1, length,
|
||||
value = 0, stop = 0;
|
||||
v_param argval;
|
||||
int param = 0, flags = 0, width = -1, precision = -1, length,
|
||||
value, stop = 0;
|
||||
|
||||
/* parameter position */
|
||||
if( c >= '1' && c <= '9' )
|
||||
if( c >= '0' && c <= '9' )
|
||||
{
|
||||
c = get_decimal( c, &format, &value );
|
||||
if( c == '$' )
|
||||
{
|
||||
param = value;
|
||||
value = 0;
|
||||
c = *format++;
|
||||
}
|
||||
else
|
||||
stop = 1;
|
||||
{
|
||||
format = pattern;
|
||||
c = *format++;
|
||||
}
|
||||
}
|
||||
|
||||
/* flags */
|
||||
@@ -816,9 +904,7 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... )
|
||||
}
|
||||
|
||||
/* field width */
|
||||
if( value != 0 )
|
||||
width = value;
|
||||
else if( c == '*' )
|
||||
if( c == '*' )
|
||||
{
|
||||
c = *format++;
|
||||
if( c >= '0' && c <= '9' )
|
||||
@@ -928,19 +1014,20 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... )
|
||||
argval.value.as_x_long_dbl = va_arg_n( args, _x_long_dbl, param );
|
||||
else
|
||||
argval.value.as_x_long_dbl = va_arg_n( args, _x_double, param );
|
||||
if( isnan( argval.value.as_x_long_dbl ) )
|
||||
HB_NUMTYPE( value, argval.value.as_x_long_dbl );
|
||||
if( value & _HB_NUM_NAN )
|
||||
size = put_str( buffer, bufsize, size,
|
||||
c == 'f' ?
|
||||
( flags & _F_SIGN ? "+nan": "nan" ) :
|
||||
( flags & _F_SIGN ? "+NAN": "NAN" ) ,
|
||||
flags, width, -1 );
|
||||
else if( isinf( argval.value.as_x_long_dbl ) > 0 )
|
||||
else if( value & _HB_NUM_PINF )
|
||||
size = put_str( buffer, bufsize, size,
|
||||
c == 'f' ?
|
||||
( flags & _F_SIGN ? "+inf": "inf" ) :
|
||||
( flags & _F_SIGN ? "+INF": "INF" ),
|
||||
flags, width, -1 );
|
||||
else if( isinf( argval.value.as_x_long_dbl ) < 0 )
|
||||
else if( value & _HB_NUM_NINF )
|
||||
size = put_str( buffer, bufsize, size,
|
||||
c == 'f' ? "-inf" : "-INF",
|
||||
flags, width, -1 );
|
||||
@@ -1073,8 +1160,8 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... )
|
||||
|
||||
#ifndef __NO_ARGPOS__
|
||||
}
|
||||
if( arglst != argbuf )
|
||||
free( argbuf );
|
||||
if( params.arglst != argbuf )
|
||||
hb_xfree( params.arglst );
|
||||
#endif
|
||||
|
||||
/* always set trailing \0 !!! */
|
||||
|
||||
@@ -991,7 +991,9 @@ PHB_ITEM hb_itemPutNDLen( PHB_ITEM pItem, double dNumber, int iWidth, int iDec )
|
||||
if( iWidth <= 0 || iWidth > 99 )
|
||||
{
|
||||
#if (__BORLANDC__ > 1040) /* Use this only above Borland C++ 3.1 */
|
||||
/* Borland C compiled app crashes if a "NaN" double is compared with another double [martin vogel] */
|
||||
/* Borland C compiled app crashes if a "NaN" double is compared
|
||||
* with another double [martin vogel]
|
||||
*/
|
||||
if( _isnan( dNumber ) )
|
||||
{
|
||||
iWidth = 20;
|
||||
|
||||
Reference in New Issue
Block a user