diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5680b1c6d9..62c88a1627 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,28 @@ +20000321-15:08 GMT+1 Victor Szakats + + * source/rtl/diskspac.c + + Supports larger disks than 2GB by design. + + Support added for Win95B, Win98, WinNT, Win2K to return the correct + free space for >2GB disks. (Wewwh, Win32 API *is* a strange beast ;) + + * source/rtl/seconds.c + include/hbdate.h + * hb_secondsToday() -> hb_seconds() Hack to avoid name collision removed. + + * include/hbdefs.h + pp/pplib.c + rtl/gtdos/gtdos.c + rtl/gtos2/gtos2.c + rtl/gtwin/gtwin.c + rtl/ampm.c + rtl/gtapi.c + rtl/memoline.c + rtl/round.c + vm/arrayshb.c + vm/fm.c + * HB_MIN_() -> HB_MIN() + HB_MAX_() -> HB_MAX() + 20000321-12:32 GMT+1 Victor Szakats * include/hbdefs.h diff --git a/harbour/include/hbdate.h b/harbour/include/hbdate.h index 9991500009..2dfc0159f6 100644 --- a/harbour/include/hbdate.h +++ b/harbour/include/hbdate.h @@ -40,7 +40,7 @@ extern char * hb_monthsname []; extern char * hb_daysname []; -extern double hb_secondsToday( void ); +extern double hb_seconds( void ); extern char * hb_cmonth( int iMonth ); extern char * hb_cdow( int iDay ); extern long hb_dow( long lDay, long lMonth, long lYear ); diff --git a/harbour/include/hbdefs.h b/harbour/include/hbdefs.h index 3cd13039aa..6138ad941b 100644 --- a/harbour/include/hbdefs.h +++ b/harbour/include/hbdefs.h @@ -102,10 +102,8 @@ #endif /* HB_DONT_DEFINE_BASIC_TYPES */ -/* NOTE: Underscore postfix needed to avoid conflict with the functions - named HB_MIN() and HB_MAX() [vszakats] */ -#define HB_MAX_( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) ) -#define HB_MIN_( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) +#define HB_MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) ) +#define HB_MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) #define HB_LOBYTE( w ) ( ( BYTE ) ( w ) ) #define HB_HIBYTE( w ) ( ( BYTE ) ( ( ( USHORT ) ( w ) >> 8 ) & 0xFF ) ) @@ -145,10 +143,18 @@ typedef BYTE HB_ATTR; typedef HARBOUR ( * PHB_FUNC )( void ); typedef PHB_FUNC HB_FUNC_PTR; -/* Function declaration macro */ +/* Function declaration macros */ + +/* NOTE: The prefix is "HB_FUN_" currently, this is needed to + avoid collision with any other declared symbol. + Note that "HB_" is not enough, since the Harbour internals + are also prefixed with HB_. [vszakats] */ + #define HB_FUNCNAME( funcname ) HB_FUN_##funcname #define HB_FUNC( funcname ) HARBOUR HB_FUN_##funcname ( void ) +/* */ + typedef ULONG HB_HANDLE; /* handle to memvar value */ typedef char HB_SYMBOLSCOPE; /* stores symbol's scope */ diff --git a/harbour/source/pp/pplib.c b/harbour/source/pp/pplib.c index aa6d9c3f6f..fccbcf06f3 100644 --- a/harbour/source/pp/pplib.c +++ b/harbour/source/pp/pplib.c @@ -86,7 +86,7 @@ HB_FUNC( __PREPROCESS ) hb_pp_Init(); - slen = HB_MIN_( hb_parclen( 1 ), HB_PP_STR_SIZE - 1 ); + slen = HB_MIN( hb_parclen( 1 ), HB_PP_STR_SIZE - 1 ); memcpy( pText, hb_parc( 1 ), slen ); pText[ slen ] = 0; /* Preprocessor expects null-terminated string */ memset( pOut, 0, HB_PP_STR_SIZE ); diff --git a/harbour/source/rtl/ampm.c b/harbour/source/rtl/ampm.c index 36e2bade71..4beb6d1a79 100644 --- a/harbour/source/rtl/ampm.c +++ b/harbour/source/rtl/ampm.c @@ -39,7 +39,7 @@ HB_FUNC( AMPM ) { char * pszTime = hb_parc( 1 ); ULONG ulTimeLen = hb_parclen( 1 ); - char * pszResult = ( char * ) hb_xgrab( HB_MAX_( ulTimeLen, 2 ) + 3 + 1 ); + char * pszResult = ( char * ) hb_xgrab( HB_MAX( ulTimeLen, 2 ) + 3 + 1 ); USHORT uiHour = ( USHORT ) hb_strVal( pszTime ); BOOL bAM; diff --git a/harbour/source/rtl/diskspac.c b/harbour/source/rtl/diskspac.c index b49089c9ce..4c40b8c387 100644 --- a/harbour/source/rtl/diskspac.c +++ b/harbour/source/rtl/diskspac.c @@ -44,11 +44,16 @@ * */ +/* NOTE: DISKSPACE() supports larger disks than 2GB. CA-Cl*pper will always + return a (long) value, Harbour may return a (double) for large + values, the decimal places are always set to zero, though. */ + #define HB_OS_WIN_32_USED #include "hbapi.h" #include "hbapierr.h" #include "hbapifs.h" +#include "hbapiitm.h" #if defined(HB_OS_DOS) || defined(__WATCOMC__) #include @@ -56,7 +61,7 @@ HB_FUNC( DISKSPACE ) { - ULONG ulSpaceFree = 0; + double dSpaceFree = 0.0; USHORT uiDrive = ISNUM( 1 ) ? hb_parni( 1 ) : 0; #if defined(HB_OS_DOS) || defined(__WATCOMC__) @@ -73,19 +78,19 @@ HB_FUNC( DISKSPACE ) } if( uiResult != 0 ) - ulSpaceFree = ( ULONG ) disk.avail_clusters * - ( ULONG ) disk.sectors_per_cluster * - ( ULONG ) disk.bytes_per_sector; + dSpaceFree = ( double ) disk.avail_clusters * + ( double ) disk.sectors_per_cluster * + ( double ) disk.bytes_per_sector; #elif defined(HB_OS_WIN_32) - + { - char szPath[ 4 ]; - DWORD dwSectorsPerCluster; - DWORD dwBytesPerSector; - DWORD dwNumberOfFreeClusters; - DWORD dwTotalNumberOfClusters; + typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER, + PULARGE_INTEGER, PULARGE_INTEGER); + + char szPath[ 4 ]; + P_GDFSE pGetDiskFreeSpaceEx; /* Get the default drive */ @@ -103,15 +108,39 @@ HB_FUNC( DISKSPACE ) szPath[ 2 ] = '\\'; szPath[ 3 ] = '\0'; - if( GetDiskFreeSpace( szPath, - &dwSectorsPerCluster, - &dwBytesPerSector, - &dwNumberOfFreeClusters, - &dwTotalNumberOfClusters ) ) + pGetDiskFreeSpaceEx = ( P_GDFSE ) GetProcAddress( GetModuleHandle( "kernel32.dll" ), + "GetDiskFreeSpaceExA"); + + if( pGetDiskFreeSpaceEx ) { - ulSpaceFree = dwNumberOfFreeClusters * - dwSectorsPerCluster * - dwBytesPerSector; + ULARGE_INTEGER i64FreeBytesToCaller; + ULARGE_INTEGER i64TotalBytes; + ULARGE_INTEGER i64FreeBytes; + + if( pGetDiskFreeSpaceEx( szPath, + ( PULARGE_INTEGER ) &i64FreeBytesToCaller, + ( PULARGE_INTEGER ) &i64TotalBytes, + ( PULARGE_INTEGER ) &i64FreeBytes ) ) + + dSpaceFree = ( double ) i64FreeBytesToCaller.QuadPart ; + } + else + { + DWORD dwSectorsPerCluster; + DWORD dwBytesPerSector; + DWORD dwNumberOfFreeClusters; + DWORD dwTotalNumberOfClusters; + + if( GetDiskFreeSpace( szPath, + &dwSectorsPerCluster, + &dwBytesPerSector, + &dwNumberOfFreeClusters, + &dwTotalNumberOfClusters ) ) + { + dSpaceFree = ( double ) dwNumberOfFreeClusters * + ( double ) dwSectorsPerCluster * + ( double ) dwBytesPerSector; + } } } @@ -121,6 +150,13 @@ HB_FUNC( DISKSPACE ) #endif - hb_retnl( ( long ) ulSpaceFree ); + { + PHB_ITEM pRetVal; + + pRetVal = hb_itemNew( NULL ); + hb_itemPutNLen( pRetVal, dSpaceFree, -1, 0 ); + hb_itemReturn( pRetVal ); + hb_itemRelease( pRetVal ); + } } diff --git a/harbour/source/rtl/gtapi.c b/harbour/source/rtl/gtapi.c index 9d69ed1f43..b3c105f92f 100644 --- a/harbour/source/rtl/gtapi.c +++ b/harbour/source/rtl/gtapi.c @@ -964,7 +964,7 @@ USHORT hb_gtDrawShadow( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiR /* Draw the bottom edge */ if( uiBottom <= uiMaxRow && uiLeft <= uiMaxCol ) - hb_gt_SetAttribute( uiBottom, uiLeft, uiBottom, HB_MIN_( uiRight, uiMaxCol ), byAttr ); + hb_gt_SetAttribute( uiBottom, uiLeft, uiBottom, HB_MIN( uiRight, uiMaxCol ), byAttr ); uiRight++; uiTop++; @@ -972,7 +972,7 @@ USHORT hb_gtDrawShadow( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiR /* Draw the right edge */ if( uiTop <= uiMaxRow && uiRight <= uiMaxCol ) - hb_gt_SetAttribute( uiTop, uiRight, uiBottom, HB_MIN_( uiRight + 1, uiMaxCol ), byAttr ); + hb_gt_SetAttribute( uiTop, uiRight, uiBottom, HB_MIN( uiRight + 1, uiMaxCol ), byAttr ); return 0; } diff --git a/harbour/source/rtl/gtdos/gtdos.c b/harbour/source/rtl/gtdos/gtdos.c index 59de209cf4..1257a113d1 100644 --- a/harbour/source/rtl/gtdos/gtdos.c +++ b/harbour/source/rtl/gtdos/gtdos.c @@ -1029,7 +1029,7 @@ void hb_gt_Tone( double dFrequency, double dDuration ) /* The conversion from Clipper timer tick units to milliseconds is * 1000.0 / 18.2. */ - dFrequency = HB_MIN_( HB_MAX_( 0.0, dFrequency ), 32767.0 ); + dFrequency = HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 ); dDuration = dDuration * CLOCKS_PER_SEC / 18.2 ; /* clocks */ #if defined(__BORLANDC__) || defined(__WATCOMC__) @@ -1042,7 +1042,7 @@ void hb_gt_Tone( double dFrequency, double dDuration ) { /* Use USHORT, because this variable gets added to clock() to form end_clock and we want to minimize overflow risk */ - USHORT temp = ( USHORT ) HB_MIN_( HB_MAX_( 0, dDuration ), USHRT_MAX ); + USHORT temp = ( USHORT ) HB_MIN( HB_MAX( 0, dDuration ), USHRT_MAX ); clock_t end_clock; dDuration -= temp; diff --git a/harbour/source/rtl/gtos2/gtos2.c b/harbour/source/rtl/gtos2/gtos2.c index 8f32245211..d27de697ec 100644 --- a/harbour/source/rtl/gtos2/gtos2.c +++ b/harbour/source/rtl/gtos2/gtos2.c @@ -584,12 +584,12 @@ void hb_gt_Tone( double dFrequency, double dDuration ) /* The conversion from Clipper timer tick units to milliseconds is * 1000.0 / 18.2. */ - dFrequency = HB_MIN_( HB_MAX_( 0.0, dFrequency ), 32767.0 ); + dFrequency = HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 ); dDuration = dDuration * 1000.0 / 18.2; /* milliseconds */ while( dDuration > 0.0 ) { - USHORT temp = ( USHORT ) HB_MIN_( HB_MAX_( 0, dDuration ), USHRT_MAX ); + USHORT temp = ( USHORT ) HB_MIN( HB_MAX( 0, dDuration ), USHRT_MAX ); dDuration -= temp; if( temp <= 0 ) diff --git a/harbour/source/rtl/gtwin/gtwin.c b/harbour/source/rtl/gtwin/gtwin.c index a93f310709..c092089d11 100644 --- a/harbour/source/rtl/gtwin/gtwin.c +++ b/harbour/source/rtl/gtwin/gtwin.c @@ -1146,10 +1146,10 @@ void hb_gt_Tone( double dFrequency, double dDuration ) milliseconds is * 1000.0 / 18.2. */ dDuration = dDuration * 1000.0 / 18.2; /* milliseconds */ - dDuration = HB_MIN_( HB_MAX_( 0, dDuration ), ULONG_MAX ); + dDuration = HB_MIN( HB_MAX( 0, dDuration ), ULONG_MAX ); if( dDuration > 0.0 ) - Beep( ( ULONG ) HB_MIN_( HB_MAX_( 0.0, dFrequency ), 32767.0 ), + Beep( ( ULONG ) HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 ), ( ULONG ) dDuration ); } diff --git a/harbour/source/rtl/memoline.c b/harbour/source/rtl/memoline.c index d8c0a9618b..333c636d46 100644 --- a/harbour/source/rtl/memoline.c +++ b/harbour/source/rtl/memoline.c @@ -70,7 +70,7 @@ HB_FUNC( MEMOLINE ) case HB_CHAR_LF: ulCurLength = 0; ulLastSpace = 0; - ulLineEnd = HB_MAX_( ulPos - 2, ulLineBegin ); + ulLineEnd = HB_MAX( ulPos - 2, ulLineBegin ); ulLines++; if( ulLines < ulLineNumber ) { diff --git a/harbour/source/rtl/round.c b/harbour/source/rtl/round.c index 3480ef6caa..b57ec5a31a 100644 --- a/harbour/source/rtl/round.c +++ b/harbour/source/rtl/round.c @@ -121,7 +121,7 @@ HB_FUNC( ROUND ) { int iDec = hb_parni( 2 ); - hb_retndlen( hb_numRound( hb_parnd( 1 ), iDec ), 0, HB_MAX_( iDec, 0 ) ); + hb_retndlen( hb_numRound( hb_parnd( 1 ), iDec ), 0, HB_MAX( iDec, 0 ) ); } else { diff --git a/harbour/source/rtl/seconds.c b/harbour/source/rtl/seconds.c index a74001cd8d..32cacd733c 100644 --- a/harbour/source/rtl/seconds.c +++ b/harbour/source/rtl/seconds.c @@ -42,7 +42,7 @@ #include #endif -double hb_secondsToday( void ) +double hb_seconds( void ) { #if defined(_MSC_VER) #define timeb _timeb @@ -51,7 +51,7 @@ double hb_secondsToday( void ) struct timeb tb; struct tm * oTime; - HB_TRACE(HB_TR_DEBUG, ("hb_secondsToday()")); + HB_TRACE(HB_TR_DEBUG, ("hb_seconds()")); ftime( &tb ); oTime = localtime( &tb.time ); @@ -64,6 +64,6 @@ double hb_secondsToday( void ) HB_FUNC( SECONDS ) { - hb_retnd( hb_secondsToday() ); + hb_retnd( hb_seconds() ); } diff --git a/harbour/source/vm/arrayshb.c b/harbour/source/vm/arrayshb.c index 1219ffae19..37d0f70f28 100644 --- a/harbour/source/vm/arrayshb.c +++ b/harbour/source/vm/arrayshb.c @@ -127,7 +127,7 @@ HB_FUNC( ASIZE ) { long lSize = hb_parnl( 2 ); - hb_arraySize( pArray, HB_MAX_( lSize, 0 ) ); + hb_arraySize( pArray, HB_MAX( lSize, 0 ) ); hb_itemReturn( pArray ); /* ASize() returns the array itself */ } diff --git a/harbour/source/vm/fm.c b/harbour/source/vm/fm.c index 0db47f510c..91a9b718f3 100644 --- a/harbour/source/vm/fm.c +++ b/harbour/source/vm/fm.c @@ -507,7 +507,7 @@ ULONG hb_xquery( USHORT uiMode ) { MEMORYSTATUS memorystatus; GlobalMemoryStatus( &memorystatus ); - ulResult = HB_MIN_( memorystatus.dwAvailPhys, ULONG_MAX ) / 1024; + ulResult = HB_MIN( memorystatus.dwAvailPhys, ULONG_MAX ) / 1024; } #else ulResult = 9999;