diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a6ea102fc1..cf29df8d3a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,25 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-12 13:52 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbwinuni.h + + added new macro HB_ITEMGETSTR() + + * harbour/src/rtl/gtwin/gtwin.c + * modified to use new UNICODE API instead of HB_TCHAR_*() + + * harbour/contrib/hbwin/win_misc.c + * rewritten WIN_GETCOMMANDLINEPARAM() + New version does not use old HB_TCHAR_*() API and respect multiple + quoting by "" (i.e. .\"myapp"li"cation".exe) + + TOFIX: WIN_ANSITOWIDE() and WIN_WIDETOANSI() are wrong and have + to be fixed. Please remember that number of character + after conversion to/from UNICODE can be different then + original number of chars, i.e. multibyte characters + can be replaced by single Unicode character or one Unicode + character may use few bytes representation. + 2009-12-12 12:48 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/hbqt_hbqmainwindow.cpp * Temporarily disabled mutex for HBMainWindow. diff --git a/harbour/contrib/hbwin/win_misc.c b/harbour/contrib/hbwin/win_misc.c index a0050b5787..490b0cda4e 100644 --- a/harbour/contrib/hbwin/win_misc.c +++ b/harbour/contrib/hbwin/win_misc.c @@ -165,45 +165,22 @@ HB_FUNC( WIN_LOADRESOURCE ) HB_FUNC( WIN_GETCOMMANDLINEPARAM ) { - char * buffer = HB_TCHAR_CONVFROM( GetCommandLine() ); + LPCTSTR lpCmdLine = GetCommandLine(); + HB_BOOL fQuote = HB_FALSE; long pos; /* Skip application path */ pos = 0; - if( buffer[ pos ] == '"' ) + while( lpCmdLine[ pos ] && ( fQuote || !HB_ISSPACE( lpCmdLine[ pos ] ) ) ) { - /* If it contains spaces, it will be enclosed in quote chars, - skip this to get to the command line. */ + if( lpCmdLine[ pos ] == '"' ) + fQuote = !fQuote; pos++; - while( buffer[ pos ] && buffer[ pos ] != '"' ) - pos++; - - if( buffer[ pos ] == '"' ) - pos++; } - else - { - /* If not, look for the next space for the beginning of the - command line. */ - while( buffer[ pos ] && buffer[ pos ] != ' ' ) - pos++; - } - - if( buffer[ pos ] == ' ' ) + while( HB_ISSPACE( lpCmdLine[ pos ] ) ) pos++; - { - /* Convert from OS codepage */ - char * pszFree = NULL; - const char * pszResult = hb_osDecodeCP( buffer + pos, &pszFree, NULL ); - - if( pszFree ) - hb_retc_buffer( pszFree ); - else - hb_retc( pszResult ); - } - - HB_TCHAR_FREE( buffer ); + HB_RETSTR( lpCmdLine + pos ); } HB_FUNC( WIN_ANSITOWIDE ) diff --git a/harbour/include/hbwinuni.h b/harbour/include/hbwinuni.h index 07f595be57..f7a6174e54 100644 --- a/harbour/include/hbwinuni.h +++ b/harbour/include/hbwinuni.h @@ -68,8 +68,9 @@ #define HB_STORSTRLEN( str, len, n ) hb_storstrlen_u16( HB_CDP_ENDIAN_NATIVE, str, len, n ) #define HB_ARRAYSETSTR( arr, n, str ) hb_arraySetStrU16( arr, n, HB_CDP_ENDIAN_NATIVE, str ) #define HB_ARRAYSETSTRLEN( arr, n, str, len ) hb_arraySetStrLenU16( arr, n, HB_CDP_ENDIAN_NATIVE, str, len ) - #define HB_ITEMPUTSTR( p, str ) hb_itemPutStrU16( p, HB_CDP_ENDIAN_NATIVE, str ) - #define HB_ITEMPUTSTRLEN( p, str, len ) hb_itemPutStrLenU16( p, HB_CDP_ENDIAN_NATIVE, str, len ) + #define HB_ITEMGETSTR( itm, phstr, plen ) hb_itemGetStrU16( itm, HB_CDP_ENDIAN_NATIVE, phstr, plen ) + #define HB_ITEMPUTSTR( itm, str ) hb_itemPutStrU16( itm, HB_CDP_ENDIAN_NATIVE, str ) + #define HB_ITEMPUTSTRLEN( itm, str, len ) hb_itemPutStrLenU16( itm, HB_CDP_ENDIAN_NATIVE, str, len ) #define HB_STRUNSHARE( h, str, len ) hb_wstrunshare( h, str, len ) #else #define HB_PARSTR( n, h, len ) hb_parstr( n, hb_setGetOSCP(), h, len ) @@ -80,8 +81,9 @@ #define HB_STORSTRLEN( str, len, n ) hb_storstrlen( hb_setGetOSCP(), str, len, n ) #define HB_ARRAYSETSTR( arr, n, str ) hb_arraySetStr( arr, n, hb_setGetOSCP(), str ) #define HB_ARRAYSETSTRLEN( arr, n, str, len ) hb_arraySetStrLen( arr, n, hb_setGetOSCP(), str, len ) - #define HB_ITEMPUTSTR( p, str ) hb_itemPutStr( p, hb_setGetOSCP(), str ) - #define HB_ITEMPUTSTRLEN( p, str, len ) hb_itemPutStrLen( p, hb_setGetOSCP(), str, len ) + #define HB_ITEMGETSTR( itm, phstr, plen ) hb_itemGetStr( itm, hb_setGetOSCP(), phstr, plen ) + #define HB_ITEMPUTSTR( p, str ) hb_itemPutStr( itm, hb_setGetOSCP(), str ) + #define HB_ITEMPUTSTRLEN( p, str, len ) hb_itemPutStrLen( itm, hb_setGetOSCP(), str, len ) #define HB_STRUNSHARE( h, str, len ) hb_strunshare( h, str, len ) #endif diff --git a/harbour/src/rtl/gtwin/gtwin.c b/harbour/src/rtl/gtwin/gtwin.c index 9c1f90ad8c..7111537445 100644 --- a/harbour/src/rtl/gtwin/gtwin.c +++ b/harbour/src/rtl/gtwin/gtwin.c @@ -83,6 +83,7 @@ #include "hbinit.h" #include "hbapiitm.h" #include "hbapierr.h" +#include "hbwinuni.h" #include "hbapicdp.h" @@ -1611,18 +1612,16 @@ static BOOL hb_gt_win_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) case HB_GTI_WINTITLE: { TCHAR buff[ 256 ]; - char * szTitle; DWORD dwLen; dwLen = GetConsoleTitle( buff, sizeof( buff ) / sizeof( TCHAR ) ); - szTitle = ( char * ) hb_xgrab( dwLen + 1 ); - HB_TCHAR_GETFROM( szTitle, buff, dwLen ); - pInfo->pResult = hb_itemPutCLPtr( pInfo->pResult, szTitle, dwLen ); + pInfo->pResult = HB_ITEMPUTSTRLEN( pInfo->pResult, buff, dwLen ); if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { - LPTSTR lpTitle = HB_TCHAR_CONVTO( hb_itemGetCPtr( pInfo->pNewVal ) ); - SetConsoleTitle( lpTitle ); - HB_TCHAR_FREE( lpTitle ); + void * hTitle; + + SetConsoleTitle( HB_ITEMGETSTR( pInfo->pNewVal, &hTitle, NULL ) ); + hb_strfree( hTitle ); } break; }