diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e89b8914a1..ade161ca17 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,17 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-01-28 22:28 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/vm/itemapi.c + % eliminated hb_snpritf() from HB_IT_POINTER conversion in + hb_itemString() + + * harbour/source/common/hbprintf.c + ! fixed return value - it should be one less. Thanks to Xavi. + + added support for I64, I32 and I16 length specifiers - it's + MS-Windows only extension but it should help in replacing + native C *printf() calls with Harbour version. + 2009-01-28 19:03 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/common/hbprintf.c * disabled _finitel() in MSVC builds, added casting to double instead diff --git a/harbour/source/common/hbprintf.c b/harbour/source/common/hbprintf.c index d94f74b5f7..6b953155e5 100644 --- a/harbour/source/common/hbprintf.c +++ b/harbour/source/common/hbprintf.c @@ -1012,6 +1012,27 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... ) length = _L_PTRDIFF_; c = *format++; break; + case 'I': /* MS-Windows extension */ + if( format[ 0 ] == '6' && format[ 1 ] == '4' ) + { + length = _L_LONGLONG_; + format += 2; + c = *format++; + break; + } + else if( format[ 0 ] == '1' && format[ 1 ] == '6' ) + { + length = _L_SHORT_; + format += 2; + c = *format++; + break; + } + else if( format[ 0 ] == '3' && format[ 1 ] == '2' ) + { + format += 2; + c = *format++; + } + /* no break; */ default: length = _L_UNDEF_; break; @@ -1196,7 +1217,7 @@ int hb_snprintf_c( char * buffer, size_t bufsize, const char * format, ... ) if( bufsize ) buffer[ bufsize - 1 ] = 0; - return ( int ) size; + return ( int ) ( size - 1 ); } #endif diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index d412644780..9570f6375f 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -2496,29 +2496,21 @@ char * hb_itemString( PHB_ITEM pItem, ULONG * ulLen, BOOL * bFreeReq ) case HB_IT_POINTER: { int size = ( sizeof( void * ) << 1 ) + 3; /* n bytes for address + 0x + \0 */ - int n; - BOOL bFail = TRUE; + HB_PTRDIFF addr = ( HB_PTRDIFF ) hb_itemGetPtr( pItem ); + * ulLen = size - 1; + * bFreeReq = TRUE; buffer = ( char * ) hb_xgrab( size ); + buffer[ 0 ] = '0'; + buffer[ 1 ] = 'x'; + buffer[ --size ] = '\0'; do { - n = hb_snprintf( buffer, size, "%p", hb_itemGetPtr( pItem ) ); - if( (n > -1) && (n < size) ) - { - bFail = FALSE; - } - else - { - if( n > -1 ) - size = n + 1; - else - size *= 2; - buffer = ( char * ) hb_xrealloc( buffer, size ); - } + UCHAR uc = ( UCHAR ) ( addr & 0xf ); + buffer[ --size ] = ( char ) ( uc + ( uc < 10 ? '0' : 'A' - 10 ) ); + addr >>= 4; } - while( bFail ); - * ulLen = strlen( buffer ); - * bFreeReq = TRUE; + while( size > 2 ); break; } default: