From ec423de877f30e6a9dae7d3bcf164e33558ce244 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 19 Oct 2007 14:16:35 +0000 Subject: [PATCH] 2007-10-19 16:16 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapicdp.h * harbour/source/rtl/cdpapi.c + added hb_cdpGetChar() + harbour/tests/wcecon.prg + added demonstration console program for WinCE, compile it using: hbmk -n -w -es2 -gtwvt wcecon * harbour/include/hbwince.h * harbour/source/common/hbwince.c * harbour/contrib/win32/w32_ole.c * harbour/contrib/odbc/odbc.c * use UNICODE macro instead of HB_WINCE to allow using Unicode WINAPI also in other MS-Windows versions * harbour/source/rtl/gtwvt/gtwvt.h * harbour/source/rtl/gtwvt/gtwvt.c + added support for Unicode IO * harbour/source/rtl/diskspac.c * harbour/source/rtl/disksphb.c ! fixed wrongly set error code ! fixed possible access to uninitialized memory * use GetDiskFreeSpaceEx() on WinCE instead of GetDiskFreeSpace() for disk larger then 4GB - I do not know if PocketPC have such large devices now or if WinCE can support it but for sure it will somewhere in the future --- harbour/ChangeLog | 30 ++++++ harbour/contrib/odbc/odbc.c | 21 +++-- harbour/contrib/win32/w32_ole.c | 2 +- harbour/include/hbapicdp.h | 1 + harbour/include/hbwince.h | 41 ++++---- harbour/source/common/hbwince.c | 19 ++-- harbour/source/rtl/cdpapi.c | 18 ++++ harbour/source/rtl/diskspac.c | 144 +++++++++++++--------------- harbour/source/rtl/disksphb.c | 157 +++++++++++++++---------------- harbour/source/rtl/gtwvt/gtwvt.c | 82 +++++++++++++++- harbour/source/rtl/gtwvt/gtwvt.h | 4 + harbour/tests/wcecon.prg | 74 +++++++++++++++ 12 files changed, 399 insertions(+), 194 deletions(-) create mode 100644 harbour/tests/wcecon.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b807d2ee42..4ef5e4f3c6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,36 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-10-19 16:16 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapicdp.h + * harbour/source/rtl/cdpapi.c + + added hb_cdpGetChar() + + + harbour/tests/wcecon.prg + + added demonstration console program for WinCE, + compile it using: + hbmk -n -w -es2 -gtwvt wcecon + + * harbour/include/hbwince.h + * harbour/source/common/hbwince.c + * harbour/contrib/win32/w32_ole.c + * harbour/contrib/odbc/odbc.c + * use UNICODE macro instead of HB_WINCE to allow using Unicode + WINAPI also in other MS-Windows versions + + * harbour/source/rtl/gtwvt/gtwvt.h + * harbour/source/rtl/gtwvt/gtwvt.c + + added support for Unicode IO + + * harbour/source/rtl/diskspac.c + * harbour/source/rtl/disksphb.c + ! fixed wrongly set error code + ! fixed possible access to uninitialized memory + * use GetDiskFreeSpaceEx() on WinCE instead of GetDiskFreeSpace() + for disk larger then 4GB - I do not know if PocketPC have such + large devices now or if WinCE can support it but for sure it will + somewhere in the future + 2007-10-19 01:09 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/runjava - Obsolete contrib removed. (Thanks Petr) diff --git a/harbour/contrib/odbc/odbc.c b/harbour/contrib/odbc/odbc.c index 4859b1e7c6..d112e6ece3 100644 --- a/harbour/contrib/odbc/odbc.c +++ b/harbour/contrib/odbc/odbc.c @@ -143,7 +143,8 @@ HB_FUNC( SQLDRIVERC ) /* HB_SQLDRIVERCONNECT( hDbc, @ cConnectString ) --> nRetC SWORD wLen; RETCODE ret; -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) + LPTSTR lpStr = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); TCHAR buffer[ 1024 ]; buffer[ 0 ] = '\0'; @@ -173,7 +174,7 @@ HB_FUNC( SQLDRIVERC ) /* HB_SQLDRIVERCONNECT( hDbc, @ cConnectString ) --> nRetC HB_FUNC( SQLCONNECT ) /* HB_SQLCONNECT( hDbc, cDSN, cUseName, cPassword ) --> nRetCode */ { RETCODE ret; -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) LPTSTR lpDSN = HB_TCHAR_CONVTO( hb_parcx( 2 ) ), lpUseName = HB_TCHAR_CONVTO( hb_parcx( 3 ) ), lpPassword = HB_TCHAR_CONVTO( hb_parcx( 4 ) ); @@ -231,7 +232,7 @@ HB_FUNC( SQLFREESTM ) /* HB_SQLFREESTMT( hStmt, nType ) --> nRetCode */ HB_FUNC( SQLEXECDIR ) /* HB_SQLEXECDIRECT( hStmt, cStatement ) --> nRetCode */ { -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) LPTSTR lpStr = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); hb_retni( SQLExecDirect( ( HSTMT ) hb_parnl( 1 ), lpStr, hb_parclen( 2 ) ) ); HB_TCHAR_FREE( lpStr ); @@ -326,7 +327,7 @@ HB_FUNC( SQLDESCRIB ) SQLUINTEGER wColSize = hb_parni( 7 ); SQLSMALLINT wDecimals = hb_parni( 8 ); SQLSMALLINT wNullable = hb_parni( 9 ); -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) LPTSTR buffer = ( LPTSTR ) hb_xgrab( lLen * sizeof( TCHAR ) ); #else SQLCHAR * buffer = ( SQLCHAR * ) hb_xgrab( lLen * sizeof( SQLCHAR ) ); @@ -342,7 +343,7 @@ HB_FUNC( SQLDESCRIB ) { if( ISBYREF( 3 ) ) { -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) char * szStr = HB_TCHAR_CONVFROM( buffer ); hb_storc( szStr, 3 ); HB_TCHAR_FREE( szStr ); @@ -418,7 +419,7 @@ HB_FUNC( SQLERROR ) // hEnv, hDbc, hStmt, @ cErrorClass, @ nType, @ cErrorMsg { SQLINTEGER lError; SWORD wLen; -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) TCHAR buffer[ 256 ], szErrorMsg[ 256 ]; #else BYTE buffer[ 256 ], szErrorMsg[ 256 ]; @@ -429,7 +430,7 @@ HB_FUNC( SQLERROR ) // hEnv, hDbc, hStmt, @ cErrorClass, @ nType, @ cErrorMsg if( ISBYREF( 4 ) ) { -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) char * szStr = HB_TCHAR_CONVFROM( buffer ); hb_storc( szStr, 4 ); HB_TCHAR_FREE( szStr ); @@ -440,7 +441,7 @@ HB_FUNC( SQLERROR ) // hEnv, hDbc, hStmt, @ cErrorClass, @ nType, @ cErrorMsg hb_stornl( ( LONG ) lError, 5 ); if( ISBYREF( 6 ) ) { -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) char * szStr = HB_TCHAR_CONVFROM( szErrorMsg ); hb_storc( szStr, 6 ); HB_TCHAR_FREE( szStr ); @@ -524,7 +525,7 @@ HB_FUNC( SETNUMLEN ) /* SETNUMLEN( nValue, nSize, nDecimals ) ==> nValue (nSize HB_FUNC( SQLPREPARE ) /* HB_SQLPREPARE( hStmt, cStatement ) --> nRetCode */ { -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) LPTSTR lpStr = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); hb_retni( SQLPrepare( ( HSTMT ) hb_parnl( 1 ), lpStr, SQL_NTS ) ); HB_TCHAR_FREE( lpStr ); @@ -549,7 +550,7 @@ HB_FUNC( SQLEXECUTESCALAR ) if( wResult == SQL_SUCCESS || wResult == SQL_SUCCESS_WITH_INFO ) { -#if defined( HB_WINCE ) +#if defined( HB_OS_WIN_32 ) && defined( UNICODE ) LPTSTR lpStr = HB_TCHAR_CONVTO( hb_parcx( 1 ) ); wResult = SQLExecDirect( ( HSTMT ) hStmt, lpStr, SQL_NTS ); HB_TCHAR_FREE( lpStr ); diff --git a/harbour/contrib/win32/w32_ole.c b/harbour/contrib/win32/w32_ole.c index a10c3ad19d..bc0e9929bf 100644 --- a/harbour/contrib/win32/w32_ole.c +++ b/harbour/contrib/win32/w32_ole.c @@ -1398,7 +1398,7 @@ static void TraceLog( const char * sFile, const char * sTraceMsg, ... ) { if( (LONG) s_nOleError == DISP_E_EXCEPTION ) { -#if defined( HB_WINCE ) +#if defined( UNICODE ) MessageBox( NULL, excep.bstrDescription, excep.bstrSource, MB_ICONHAND ); #else LPSTR source, description; diff --git a/harbour/include/hbapicdp.h b/harbour/include/hbapicdp.h index 14e5d9a43c..e1b9243524 100644 --- a/harbour/include/hbapicdp.h +++ b/harbour/include/hbapicdp.h @@ -188,6 +188,7 @@ extern HB_EXPORT int hb_cdpchrcmp( char, char, PHB_CODEPAGE ); extern HB_EXPORT void hb_cdpReleaseAll( void ); extern HB_EXPORT USHORT hb_cdpGetU16( PHB_CODEPAGE, BOOL, BYTE ); +extern HB_EXPORT UCHAR hb_cdpGetChar( PHB_CODEPAGE, BOOL, USHORT ); extern HB_EXPORT BOOL hb_cdpGetFromUTF8( PHB_CODEPAGE, BOOL, BYTE, int *, USHORT * ); extern HB_EXPORT ULONG hb_cdpStrnToUTF8( PHB_CODEPAGE, BOOL, const BYTE *, ULONG, BYTE * ); extern HB_EXPORT ULONG hb_cdpStrnToU16( PHB_CODEPAGE, BOOL, const BYTE *, ULONG, BYTE * ); diff --git a/harbour/include/hbwince.h b/harbour/include/hbwince.h index 5a249f3adb..80e8722668 100644 --- a/harbour/include/hbwince.h +++ b/harbour/include/hbwince.h @@ -54,21 +54,7 @@ #define HB_WINCE_H_ #if defined(HB_WINCE) - -#undef OS_HAS_DRIVE_LETTER - -extern wchar_t * hb_mbtowc( const char *srcA ); -extern char * hb_wctomb( const wchar_t *srcW ); -extern void hb_mbtowccpy( wchar_t *dstW, const char *srcA, unsigned long ulLen ); -extern void hb_mbtowcset( wchar_t *dstW, const char *srcA, unsigned long ulLen ); -extern void hb_wctombget( char *dstA, const wchar_t *srcW, unsigned long ulLen ); - -#define HB_TCHAR_CPTO(d,s,l) hb_mbtowccpy(d,s,l) -#define HB_TCHAR_GETFROM(d,s,l) hb_wctombget(d,s,l) -#define HB_TCHAR_SETTO(d,s,l) hb_mbtowcset(d,s,l) -#define HB_TCHAR_CONVTO(s) hb_mbtowc(s) -#define HB_TCHAR_CONVFROM(s) hb_wctomb(s) -#define HB_TCHAR_FREE(s) hb_xfree(s) +# undef OS_HAS_DRIVE_LETTER /* defined(__CEGCC__) || defined(__MINGW32CE__) */ @@ -79,8 +65,27 @@ extern clock_t clock( void ); extern int remove( const char *filename ); extern int access( const char *pathname, int mode ); -extern char *strerror( int errnum ); extern int system( const char *string ); +extern char *strerror( int errnum ); + +#endif /* HB_WINCE */ + +#if defined(HB_OS_WIN_32) + +extern wchar_t * hb_mbtowc( const char *srcA ); +extern char * hb_wctomb( const wchar_t *srcW ); +extern void hb_mbtowccpy( wchar_t *dstW, const char *srcA, unsigned long ulLen ); +extern void hb_mbtowcset( wchar_t *dstW, const char *srcA, unsigned long ulLen ); +extern void hb_wctombget( char *dstA, const wchar_t *srcW, unsigned long ulLen ); + +#if defined(UNICODE) + +#define HB_TCHAR_CPTO(d,s,l) hb_mbtowccpy(d,s,l) +#define HB_TCHAR_GETFROM(d,s,l) hb_wctombget(d,s,l) +#define HB_TCHAR_SETTO(d,s,l) hb_mbtowcset(d,s,l) +#define HB_TCHAR_CONVTO(s) hb_mbtowc(s) +#define HB_TCHAR_CONVFROM(s) hb_wctomb(s) +#define HB_TCHAR_FREE(s) hb_xfree(s) #else @@ -91,6 +96,8 @@ extern int system( const char *string ); #define HB_TCHAR_CONVFROM(s) (s) #define HB_TCHAR_FREE(s) HB_SYMBOL_UNUSED(s) -#endif /* HB_WINCE */ +#endif /* UNICODE */ + +#endif /* HB_OS_WIN_32 */ #endif /* HB_WINCE_H_ */ diff --git a/harbour/source/common/hbwince.c b/harbour/source/common/hbwince.c index cca2ee0229..3df23dee97 100644 --- a/harbour/source/common/hbwince.c +++ b/harbour/source/common/hbwince.c @@ -63,11 +63,9 @@ #include "hbapi.h" #include "hbdate.h" -#if defined(HB_OS_WIN_32) && \ - ( defined(_WINCE) || defined(HB_WINCE) || \ - defined(__CEGCC__) || defined(__MINGW32CE__) ) - +#if defined(HB_WINCE) +#if defined(__MINGW32CE__) clock_t clock( void ) { SYSTEMTIME st; @@ -77,6 +75,7 @@ clock_t clock( void ) return ( ( clock_t ) hb_dateEncode( st.wYear, st.wMonth, st.wDay ) - 2451545 ) * 86400000 + ( ( st.wHour * 60 + st.wMinute ) * 60 + st.wSecond ) * 1000 + st.wMilliseconds; } +#endif int remove( const char *filename ) { @@ -145,6 +144,10 @@ char *strerror( int errnum ) return ( char * ) ""; } +#endif /* HB_WINCE */ + +#if defined(HB_OS_WIN_32) + void hb_mbtowccpy( wchar_t * dstW, const char *srcA, ULONG ulLen ) { MultiByteToWideChar( CP_ACP, 0, srcA, -1, dstW, ulLen / sizeof( wchar_t ) ); @@ -184,6 +187,8 @@ void hb_wctombget( char *dstA, const wchar_t *srcW, unsigned long ulLen ) WideCharToMultiByte( CP_ACP, 0, srcW, ulLen, dstA, ulLen, NULL, NULL ); } +#if defined(UNICODE) + DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size ) { /* use registry instead of "environment valuable". */ @@ -195,7 +200,7 @@ DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size ) LPWSTR wname; LPSTR avalue; - lret = RegOpenKeyEx( HKEY_LOCAL_MACHINE, L"Software\\harbour_mswince", 0, KEY_QUERY_VALUE, &hk ); + lret = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "Software\\harbour_mswince" ), 0, KEY_QUERY_VALUE, &hk ); if( lret != ERROR_SUCCESS ) { @@ -624,4 +629,6 @@ BOOL WINAPI LocalUnlock( HLOCAL h ) return FALSE; } -#endif +#endif /* UNICODE */ + +#endif /* HB_OS_WIN_32 */ diff --git a/harbour/source/rtl/cdpapi.c b/harbour/source/rtl/cdpapi.c index aea28f3817..24e22d8298 100644 --- a/harbour/source/rtl/cdpapi.c +++ b/harbour/source/rtl/cdpapi.c @@ -543,6 +543,24 @@ HB_EXPORT USHORT hb_cdpGetU16( PHB_CODEPAGE cdp, BOOL fCtrl, BYTE ch ) return u; } +HB_EXPORT UCHAR hb_cdpGetChar( PHB_CODEPAGE cdp, BOOL fCtrl, USHORT uc ) +{ + if( ( fCtrl || uc >= 32 ) && cdp && + cdp->uniTable && cdp->uniTable->uniCodes ) + { + int i; + for( i = fCtrl ? 0 : 32; i < cdp->uniTable->nChars; i++ ) + { + if( cdp->uniTable->uniCodes[ i ] == uc ) + { + uc = ( USHORT ) i; + break; + } + } + } + return uc >= 0x100 ? '?' : ( UCHAR ) uc; +} + HB_EXPORT BYTE * hb_cdpUTF8StringSubstr( const BYTE * pSrc, ULONG ulLen, ULONG ulFrom, ULONG ulCount, ULONG * pulDest ) diff --git a/harbour/source/rtl/diskspac.c b/harbour/source/rtl/diskspac.c index e6ebac9ccf..0960890fcb 100644 --- a/harbour/source/rtl/diskspac.c +++ b/harbour/source/rtl/diskspac.c @@ -77,7 +77,7 @@ HB_FUNC( DISKSPACE ) { double dSpace = 0.0; - BOOL bError = FALSE; + BOOL bError; #if defined(HB_OS_DOS) { @@ -88,76 +88,69 @@ HB_FUNC( DISKSPACE ) regs.h.ah = 0x36; HB_DOS_INT86( 0x21, ®s, ®s ); - if( regs.HB_XREGS.ax != 0xFFFF ) + bError = regs.HB_XREGS.ax == 0xFFFF + if( !bError ) dSpace = ( double ) regs.HB_XREGS.bx * ( double ) regs.HB_XREGS.ax * ( double ) regs.HB_XREGS.cx; - else - bError = TRUE; } #elif defined(HB_OS_WIN_32) { - USHORT uiDrive = ISNUM( 1 ) ? hb_parni( 1 ) : 0; +#if defined(_MSC_VER) || defined(__LCC__) || \ + ( defined(__GNUC__) && !defined(__RSXNT__) ) + +# define HB_GET_LARGE_UINT( v ) ( ( double ) (v).LowPart + \ + ( double ) (v).HighPart * \ + ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) + +#else + /* NOTE: Borland doesn't seem to deal with the un-named + struct that is part of ULARGE_INTEGER + [pt] */ +# define HB_GET_LARGE_UINT( v ) ( ( double ) (v).u.LowPart + \ + ( double ) (v).u.HighPart * \ + ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) +#endif + typedef BOOL ( WINAPI * P_GDFSE )( LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER ); - char szPath[ 4 ]; - P_GDFSE pGetDiskFreeSpaceEx; - UINT uiErrMode; - - /* Get the default drive */ - if( uiDrive == 0 ) - uiDrive = hb_fsCurDrv() + 1; - - szPath[ 0 ] = uiDrive + 'A' - 1; - szPath[ 1 ] = ':'; - szPath[ 2 ] = '\\'; - szPath[ 3 ] = '\0'; - - uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); - - SetLastError( 0 ); + ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; + USHORT uiParam = hb_parni( 1 ); + USHORT uiDrive = uiParam == 0 ? hb_fsCurDrv() + 1 : uiParam; + UINT uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); #if defined(HB_WINCE) - pGetDiskFreeSpaceEx = NULL; -#else - pGetDiskFreeSpaceEx = ( P_GDFSE ) GetProcAddress( GetModuleHandleA( "kernel32.dll" ), - "GetDiskFreeSpaceExA" ); + TCHAR lpPath[4]; + + lpPath[0] = uiDrive + 'A' - 1; + lpPath[1] = ':'; + lpPath[2] = '\\'; + lpPath[3] = '\0'; + + bError = !GetDiskFreeSpaceEx( lpPath, + ( PULARGE_INTEGER ) &i64FreeBytesToCaller, + ( PULARGE_INTEGER ) &i64TotalBytes, + ( PULARGE_INTEGER ) &i64FreeBytes ); + if( !bError ) + dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); +#else + char szPath[4]; + P_GDFSE pGetDiskFreeSpaceEx = ( P_GDFSE ) + GetProcAddress( GetModuleHandleA( "kernel32.dll" ), + "GetDiskFreeSpaceExA" ); + szPath[0] = uiDrive + 'A' - 1; + szPath[1] = ':'; + szPath[2] = '\\'; + szPath[3] = '\0'; -#endif if( pGetDiskFreeSpaceEx ) { - ULARGE_INTEGER i64FreeBytesToCaller, - i64TotalBytes, - i64FreeBytes, - i64RetVal; - - if( pGetDiskFreeSpaceEx( szPath, - ( PULARGE_INTEGER ) &i64FreeBytesToCaller, - ( PULARGE_INTEGER ) &i64TotalBytes, - ( PULARGE_INTEGER ) &i64FreeBytes ) ) - { - memcpy( &i64RetVal, &i64FreeBytesToCaller, sizeof( ULARGE_INTEGER ) ); - - #if ( defined(__GNUC__) || defined(_MSC_VER) || defined(__LCC__) ) && !defined(__RSXNT__) - - dSpace = ( double ) i64RetVal.LowPart + - ( double ) i64RetVal.HighPart + - ( double ) i64RetVal.HighPart * - ( double ) 0xFFFFFFFF; - - #else - - /* NOTE: Borland doesn't seem to deal with the un-named - struct that is part of ULARGE_INTEGER - [pt] */ - - dSpace = ( double ) i64RetVal.u.LowPart + - ( double ) i64RetVal.u.HighPart + - ( double ) i64RetVal.u.HighPart * - ( double ) 0xFFFFFFFF; - - #endif - } + bError = !pGetDiskFreeSpaceEx( szPath, + ( PULARGE_INTEGER ) &i64FreeBytesToCaller, + ( PULARGE_INTEGER ) &i64TotalBytes, + ( PULARGE_INTEGER ) &i64FreeBytes ); + if( !bError ) + dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); } else { @@ -166,22 +159,18 @@ HB_FUNC( DISKSPACE ) DWORD dwNumberOfFreeClusters; DWORD dwTotalNumberOfClusters; - SetLastError( 0 ); - - if( GetDiskFreeSpaceA( szPath, - &dwSectorsPerCluster, - &dwBytesPerSector, - &dwNumberOfFreeClusters, - &dwTotalNumberOfClusters ) ) + bError = !GetDiskFreeSpaceA( szPath, + &dwSectorsPerCluster, + &dwBytesPerSector, + &dwNumberOfFreeClusters, + &dwTotalNumberOfClusters ); + if( !bError ) dSpace = ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; } - +#endif SetErrorMode( uiErrMode ); - - if( GetLastError() != 0 ) - bError = TRUE; } #elif defined(HB_OS_OS2) { @@ -189,12 +178,11 @@ HB_FUNC( DISKSPACE ) struct _FSALLOCATE fsa; /* Query level 1 info from filesystem */ - if( DosQueryFSInfo( uiDrive, 1, &fsa, sizeof( fsa ) ) == 0 ) + bError = DosQueryFSInfo( uiDrive, 1, &fsa, sizeof( fsa ) ) != 0; + if( !bError ) dSpace = ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; - else - bError = TRUE; } #elif defined(HB_OS_UNIX) { @@ -209,27 +197,27 @@ HB_FUNC( DISKSPACE ) { #if defined(__WATCOMC__) || defined(__CEGCC__) struct stat st; - if( stat( szName, &st) == 0 ) + bError = stat( szName, &st) != 0; + if( !bError ) dSpace = ( double ) st.st_blocks * ( double ) st.st_blksize; - else - bError = TRUE; #else struct statvfs st; - if( statvfs( szName, &st ) == 0 ) + bError = statvfs( szName, &st ) != 0; + if( !bError ) { if( getuid() == 0 ) dSpace = ( double ) st.f_bfree * ( double ) st.f_bsize; else dSpace = ( double ) st.f_bavail * ( double ) st.f_bsize; } - else - bError = TRUE; #endif } if( fFree ) hb_xfree( szName ); } +#else + bError = FALSE; #endif if( bError ) diff --git a/harbour/source/rtl/disksphb.c b/harbour/source/rtl/disksphb.c index 4b642bcc81..7d10b8ab59 100644 --- a/harbour/source/rtl/disksphb.c +++ b/harbour/source/rtl/disksphb.c @@ -149,86 +149,94 @@ HB_FUNC( HB_DISKSPACE ) } #elif defined(HB_OS_WIN_32) { +#if defined(_MSC_VER) || defined(__LCC__) || \ + ( defined(__GNUC__) && !defined(__RSXNT__) ) + +# define HB_GET_LARGE_UINT( v ) ( ( double ) (v).LowPart + \ + ( double ) (v).HighPart * \ + ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) + +#else + /* NOTE: Borland doesn't seem to deal with the un-named + struct that is part of ULARGE_INTEGER + [pt] */ +# define HB_GET_LARGE_UINT( v ) ( ( double ) (v).u.LowPart + \ + ( double ) (v).u.HighPart * \ + ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) +#endif + + typedef BOOL ( WINAPI * P_GDFSE )( LPCSTR, PULARGE_INTEGER, + PULARGE_INTEGER, PULARGE_INTEGER ); + while( TRUE ) { - typedef BOOL ( WINAPI * P_GDFSE )( LPCSTR, PULARGE_INTEGER, - PULARGE_INTEGER, PULARGE_INTEGER ); - - P_GDFSE pGetDiskFreeSpaceEx; - UINT uiErrMode; - - uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); - - SetLastError( 0 ); + ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; + UINT uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); + BOOL fResult; #if defined(HB_WINCE) - pGetDiskFreeSpaceEx = NULL; + LPTSTR lpPath = HB_TCHAR_CONVTO( szPath ); + + fResult = GetDiskFreeSpaceEx( lpPath, + ( PULARGE_INTEGER ) &i64FreeBytesToCaller, + ( PULARGE_INTEGER ) &i64TotalBytes, + ( PULARGE_INTEGER ) &i64FreeBytes ); + hb_fsSetIOError( fResult, 0 ); + HB_TCHAR_FREE( lpPath ); + if( fResult ) + { + switch( uiType ) + { + case HB_DISK_AVAIL: + dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); + break; + + case HB_DISK_FREE: + dSpace = HB_GET_LARGE_UINT( i64FreeBytes ); + break; + + case HB_DISK_TOTAL: + dSpace = HB_GET_LARGE_UINT( i64TotalBytes ); + break; + + case HB_DISK_USED: + dSpace = HB_GET_LARGE_UINT( i64TotalBytes ) - + HB_GET_LARGE_UINT( i64FreeBytes ); + break; + } + } #else - pGetDiskFreeSpaceEx = ( P_GDFSE ) GetProcAddress( GetModuleHandleA( "kernel32.dll" ), - "GetDiskFreeSpaceExA" ); -#endif + P_GDFSE pGetDiskFreeSpaceEx = ( P_GDFSE ) + GetProcAddress( GetModuleHandleA( "kernel32.dll" ), + "GetDiskFreeSpaceExA" ); if( pGetDiskFreeSpaceEx ) { - ULARGE_INTEGER i64FreeBytesToCaller, - i64TotalBytes, - i64FreeBytes, - i64RetVal; - - if( pGetDiskFreeSpaceEx( szPath, - ( PULARGE_INTEGER ) &i64FreeBytesToCaller, - ( PULARGE_INTEGER ) &i64TotalBytes, - ( PULARGE_INTEGER ) &i64FreeBytes ) ) + fResult = pGetDiskFreeSpaceEx( szPath, + ( PULARGE_INTEGER ) &i64FreeBytesToCaller, + ( PULARGE_INTEGER ) &i64TotalBytes, + ( PULARGE_INTEGER ) &i64FreeBytes ); + hb_fsSetIOError( fResult, 0 ); + if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: - memcpy( &i64RetVal, &i64FreeBytesToCaller, sizeof( ULARGE_INTEGER ) ); + dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); break; case HB_DISK_FREE: - memcpy( &i64RetVal, &i64FreeBytes, sizeof( ULARGE_INTEGER ) ); + dSpace = HB_GET_LARGE_UINT( i64FreeBytes ); + break; + + case HB_DISK_TOTAL: + dSpace = HB_GET_LARGE_UINT( i64TotalBytes ); break; case HB_DISK_USED: - case HB_DISK_TOTAL: - memcpy( &i64RetVal, &i64TotalBytes, sizeof( ULARGE_INTEGER ) ); + dSpace = HB_GET_LARGE_UINT( i64TotalBytes ) - + HB_GET_LARGE_UINT( i64FreeBytes ); + break; } - - #if (defined(__GNUC__) || defined(_MSC_VER)) && !defined(__RSXNT__) - - dSpace = ( double ) i64RetVal.LowPart + - ( double ) i64RetVal.HighPart + - ( double ) i64RetVal.HighPart * - ( double ) 0xFFFFFFFF; - - if( uiType == HB_DISK_USED ) - { - dSpace -= ( double ) i64FreeBytes.LowPart + - ( double ) i64FreeBytes.HighPart + - ( double ) i64FreeBytes.HighPart * - ( double ) 0xFFFFFFFF; - } - - #else - - /* NOTE: Borland doesn't seem to deal with the un-named - struct that is part of ULARGE_INTEGER - [pt] */ - - dSpace = ( double ) i64RetVal.u.LowPart + - ( double ) i64RetVal.u.HighPart + - ( double ) i64RetVal.u.HighPart * - ( double ) 0xFFFFFFFF; - - if( uiType == HB_DISK_USED ) - { - dSpace -= ( double ) i64FreeBytes.u.LowPart + - ( double ) i64FreeBytes.u.HighPart + - ( double ) i64FreeBytes.u.HighPart * - ( double ) 0xFFFFFFFF; - } - - #endif } } else @@ -238,13 +246,13 @@ HB_FUNC( HB_DISKSPACE ) DWORD dwNumberOfFreeClusters; DWORD dwTotalNumberOfClusters; - SetLastError( 0 ); - - if( GetDiskFreeSpaceA( szPath, - &dwSectorsPerCluster, - &dwBytesPerSector, - &dwNumberOfFreeClusters, - &dwTotalNumberOfClusters ) ) + fResult = GetDiskFreeSpaceA( szPath, + &dwSectorsPerCluster, + &dwBytesPerSector, + &dwNumberOfFreeClusters, + &dwTotalNumberOfClusters ); + hb_fsSetIOError( fResult, 0 ); + if( fResult ) { switch( uiType ) { @@ -266,20 +274,11 @@ HB_FUNC( HB_DISKSPACE ) ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; - } } } - +#endif SetErrorMode( uiErrMode ); - - if( GetLastError() != 0 ) - { - hb_fsSetIOError( FALSE, 0 ); - dSpace = 0.0; - } - else - hb_fsSetIOError( TRUE, 0 ); break; } } diff --git a/harbour/source/rtl/gtwvt/gtwvt.c b/harbour/source/rtl/gtwvt/gtwvt.c index b071c84f2c..7904a0b8db 100644 --- a/harbour/source/rtl/gtwvt/gtwvt.c +++ b/harbour/source/rtl/gtwvt/gtwvt.c @@ -258,6 +258,9 @@ static void hb_gt_wvt_ResetWindowSize( HWND hWnd ) tm.tmAveCharWidth; /* For fixed FONT should == tm.tmMaxCharWidth */ _s.PTEXTSIZE.y = tm.tmHeight; /* but seems to be a problem on Win9X so */ /* assume proportional fonts always for Win9X */ +#if defined(HB_WINCE) + _s.FixedFont = FALSE; +#else if ( _s.fontWidth < 0 || _s.Win9X || ( tm.tmPitchAndFamily & TMPF_FIXED_PITCH ) || ( _s.PTEXTSIZE.x != tm.tmMaxCharWidth ) ) { _s.FixedFont = FALSE; @@ -266,6 +269,7 @@ static void hb_gt_wvt_ResetWindowSize( HWND hWnd ) { _s.FixedFont = TRUE ; } +#endif for( n = 0 ; n < _s.COLS ; n++ ) /* _s.FixedSize[] is used by ExtTextOut() to emulate */ { /* fixed font when a proportional font is used */ @@ -726,7 +730,7 @@ static BOOL hb_gt_wvt_KeyEvent( HWND hWnd, UINT message, WPARAM wParam, LPARAM l } else if ( bCtrl && ( c >= 1 && c <= 26 ) ) /* K_CTRL_A - Z */ { - hb_gt_wvt_AddCharToInputQueue( K_Ctrl[c-1] ); + hb_gt_wvt_AddCharToInputQueue( K_Ctrl[c - 1] ); } else { @@ -746,10 +750,13 @@ static BOOL hb_gt_wvt_KeyEvent( HWND hWnd, UINT message, WPARAM wParam, LPARAM l hb_gt_wvt_AddCharToInputQueue( K_ESC ); break; default: +#if defined(UNICODE) + if( _s.inCDP ) + c = hb_cdpGetChar( _s.inCDP, FALSE, ( USHORT ) c ); + else +#endif if( _s.CodePage == OEM_CHARSET ) - { c = hb_gt_wvt_key_ansi_to_oem( c ); - } hb_gt_wvt_AddCharToInputQueue( c ); break; } @@ -949,6 +956,9 @@ static void hb_gt_wvt_PaintText( HWND hWnd, RECT rcRect ) { break; } +#if defined(UNICODE) + usChar = hb_cdpGetU16( _s.hostCDP, TRUE, ( BYTE ) usChar ); +#endif if ( len == 0 ) { bOldColor = bColor; @@ -1283,6 +1293,10 @@ static void hb_gt_wvt_Init( FHANDLE hFilenoStdin, FHANDLE hFilenoStdout, FHANDLE hb_errInternal( 10001, "WINAPI CreateWindow() failed", "", "" ); } _s.hdc = GetDC( _s.hWnd ); +#ifndef HB_CDP_SUPPORT_OFF + _s.hostCDP = hb_cdp_page; + _s.inCDP = hb_cdp_page; +#endif /* Set default window title */ { @@ -1784,6 +1798,66 @@ static void hb_gt_wvt_Refresh( void ) } } +/* *********************************************************************** */ + +static BOOL hb_gt_wvt_SetDispCP( char * pszTermCDP, char * pszHostCDP, BOOL fBox ) +{ + + HB_GTSUPER_SETDISPCP( pszTermCDP, pszHostCDP, fBox ); + +#ifndef HB_CDP_SUPPORT_OFF + /* + * We are displaying text in U16 so pszTermCDP is unimportant. + * We only have to know what is the internal application codepage + * to make proper translation + */ + if( !pszHostCDP || !*pszHostCDP ) + { + if( hb_cdp_page ) + pszHostCDP = hb_cdp_page->id; + else if( pszTermCDP && *pszTermCDP ) + pszHostCDP = pszTermCDP; + } + if( pszHostCDP && *pszHostCDP ) + { + PHB_CODEPAGE cdpHost = hb_cdpFind( pszHostCDP ); + if( cdpHost ) + _s.hostCDP = cdpHost; + } +#endif + + return TRUE; +} + +static BOOL hb_gt_wvt_SetKeyCP( char * pszTermCDP, char * pszHostCDP ) +{ + HB_GTSUPER_SETKEYCP( pszTermCDP, pszHostCDP ); + +#ifndef HB_CDP_SUPPORT_OFF + /* + * We are receiving WM_CHAR events in U16 so pszTermCDP is unimportant. + * We only have to know what is the internal application codepage + * to make proper translation + */ + if( !pszHostCDP || !*pszHostCDP ) + { + if( hb_cdp_page ) + pszHostCDP = hb_cdp_page->id; + else if( pszTermCDP && *pszTermCDP ) + pszHostCDP = pszTermCDP; + } + if( pszHostCDP && *pszHostCDP ) + { + PHB_CODEPAGE cdpHost = hb_cdpFind( pszHostCDP ); + if( cdpHost ) + _s.inCDP = cdpHost; + } +#endif + + return TRUE; +} + + /* *********************************************************************** */ static BOOL hb_gt_FuncInit( PHB_GT_FUNCS pFuncTable ) @@ -1798,6 +1872,8 @@ static BOOL hb_gt_FuncInit( PHB_GT_FUNCS pFuncTable ) pFuncTable->Version = hb_gt_wvt_Version; pFuncTable->Tone = hb_gt_wvt_Tone; pFuncTable->Info = hb_gt_wvt_Info; + pFuncTable->SetDispCP = hb_gt_wvt_SetDispCP; + pFuncTable->SetKeyCP = hb_gt_wvt_SetKeyCP; pFuncTable->ReadKey = hb_gt_wvt_ReadKey; diff --git a/harbour/source/rtl/gtwvt/gtwvt.h b/harbour/source/rtl/gtwvt/gtwvt.h index 8997c58eaf..dd11bcac26 100644 --- a/harbour/source/rtl/gtwvt/gtwvt.h +++ b/harbour/source/rtl/gtwvt/gtwvt.h @@ -65,6 +65,7 @@ #include "hbset.h" #include "hbgtcore.h" #include "hbinit.h" +#include "hbapicdp.h" #include "hbapierr.h" #include "hbapiitm.h" #include "inkey.ch" @@ -131,6 +132,9 @@ typedef struct global_data HDC hdc; /* Handle to Windows Device Context */ + PHB_CODEPAGE hostCDP; /* Host/HVM CodePage for unicode output translations */ + PHB_CODEPAGE inCDP; /* Host/HVM CodePage for unicode input translations */ + int CodePage; /* Code page to use for display characters */ BOOL Win9X; /* Flag to say if running on Win9X not NT/2000/XP */ BOOL AltF4Close; /* Can use Alt+F4 to close application */ diff --git a/harbour/tests/wcecon.prg b/harbour/tests/wcecon.prg new file mode 100644 index 0000000000..98e2012326 --- /dev/null +++ b/harbour/tests/wcecon.prg @@ -0,0 +1,74 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * demonstration/test code for WinCE console program + * + * Copyright 2007 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + */ + +#include "hbgtinfo.ch" + +proc main() + + local nMaxScrRow, nMaxScrCol + local i, j, k + + /* set OEM font encoding for non unicode modes */ + hb_gtInfo( GTI_CODEPAGE, 255 ) + + /* Set EN CP-437 encoding */ + HB_SETCODEPAGE( "EN" ) + HB_SETTERMCP( "EN" ) + + /* Set font size */ + hb_gtInfo( GTI_FONTSIZE, 12 ) + hb_gtInfo( GTI_FONTWIDTH, 6 ) + + /* resize console window using new font size */ + SetMode( MaxRow() + 1, MaxCol() + 1 ) + + /* get screen dimensions */ + nMaxScrRow = hb_gtInfo( GTI_DESKTOPROWS ) + nMaxScrCol = hb_gtInfo( GTI_DESKTOPCOLS ) + + /* resize console window to the screen size */ + SetMode( nMaxScrRow, nMaxScrCol ) + + /* display console window size */ + ? "rows =", ltrim( str( maxrow() + 1 ) ) + ? "cols =", ltrim( str( maxcol() + 1 ) ) + inkey( 0 ) + + /* display infomration aboout used OS, harbour version and GT driver */ + alert( OS() + ";" + VERSION() + ";" + HB_GTVERSION() ) + + /* display all characters */ + ? + for i := 0 to 15 + for j := 0 to 15 + dispout( " " + chr( i * 16 + j ) ) + next + ? + next + inkey( 0 ) + + /* display boxes */ + ?; devout( "ÚÄÂÄ¿ ÉÍËÍ» ÕÍÑ͸ ÖÄÒÄ· ÜÜÜ" ) + ?; devout( "³ ³ ³ º º º ÃÄÅÄ´ ÇÄ×Ķ ÝþÞ" ) + ?; devout( "ÃÄÅÄ´ ÌÍÎ͹ ³ ³ ³ º º º ÝÛÞ" ) + ?; devout( "³ ³ ³ º º º ÆÍØÍµ ÌÍÎ͹ ÝþÞ" ) + ?; devout( "ÀÄÁÄÙ ÈÍÊͼ ÔÍÏ; ÓÄÐĽ ßßß" ) + inkey( 0 ) + + ? + ? "@ - interrupt, keycodes test " + while ( k := inkey( 0 ) ) != 64 + ? ; devout( "key=" + str( k, 4 ) + ", char='" + chr( k ) + "'" ) + enddo + +return