From 2975eadbba937ba901241f2dca3c62f5b411da42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Sun, 15 Jan 2023 11:17:33 +0100 Subject: [PATCH] 2023-01-15 11:17 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbwin/win_prn1.c ! fixed parameter type in font enum callback * include/harbour.hbx * src/harbour.def * src/rtl/hbgtcore.c + added two new PRG functions: hb_gtExists( ) -> hb_gtList() -> * src/rtl/hbgtcore.c * changed the order of defualt GT initialization. Now GT specified by -gt* hbmk2 option has higher priority then GT chosen by request HB_GT__DEFAULT * include/hbapi.h * src/vm/set.c + added two C functions for OS codepage translations: char * hb_osStrEncode2( const char * pszName, char * pszBuffer, HB_SIZE nSize ); HB_WCHAR * hb_osStrU16Encode2( const char * pszName, HB_WCHAR * pszBufferW, HB_SIZE nSize ); * include/hbwinuni.h + added HB_CHARDUP2() macro for UNICODE/ANSI OS codepage translation * src/common/hbgete.c ! fixed memory allocation in MS-Windows version of hb_getenv_buffer() * src/pp/hbpp.c ! added integer range to HB_VER_REVID definition to pacify warning * src/rtl/cdpapi.c * minor simplification --- ChangeLog.txt | 36 ++++++++++++++++++++++++++++++++++++ contrib/hbwin/win_prn1.c | 2 +- include/harbour.hbx | 2 ++ include/hbapi.h | 2 ++ include/hbwinuni.h | 2 ++ src/common/hbgete.c | 19 +++++++++++++------ src/harbour.def | 2 ++ src/pp/hbpp.c | 2 +- src/rtl/cdpapi.c | 11 +++-------- src/rtl/hbgtcore.c | 26 ++++++++++++++++++++++++-- src/vm/set.c | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 123 insertions(+), 18 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 179749ac31..f56935782a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,42 @@ Entries may not always be in chronological/commit order. See license at the end of file. */ +2023-01-15 11:17 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbwin/win_prn1.c + ! fixed parameter type in font enum callback + + * include/harbour.hbx + * src/harbour.def + * src/rtl/hbgtcore.c + + added two new PRG functions: + hb_gtExists( ) -> + hb_gtList() -> + + * src/rtl/hbgtcore.c + * changed the order of defualt GT initialization. Now GT specified by -gt* + hbmk2 option has higher priority then GT chosen by + request HB_GT__DEFAULT + + * include/hbapi.h + * src/vm/set.c + + added two C functions for OS codepage translations: + char * hb_osStrEncode2( const char * pszName, + char * pszBuffer, HB_SIZE nSize ); + HB_WCHAR * hb_osStrU16Encode2( const char * pszName, + HB_WCHAR * pszBufferW, HB_SIZE nSize ); + + * include/hbwinuni.h + + added HB_CHARDUP2() macro for UNICODE/ANSI OS codepage translation + + * src/common/hbgete.c + ! fixed memory allocation in MS-Windows version of hb_getenv_buffer() + + * src/pp/hbpp.c + ! added integer range to HB_VER_REVID definition to pacify warning + + * src/rtl/cdpapi.c + * minor simplification + 2022-11-25 18:14 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbapi.h * src/vm/cmdarg.c diff --git a/contrib/hbwin/win_prn1.c b/contrib/hbwin/win_prn1.c index 59f2cc608e..b1f1aef3e9 100644 --- a/contrib/hbwin/win_prn1.c +++ b/contrib/hbwin/win_prn1.c @@ -522,7 +522,7 @@ HB_FUNC( WIN_GETDOCUMENTPROPERTIES ) } static int CALLBACK FontEnumCallBack( LOGFONT * lplf, TEXTMETRIC * lpntm, - DWORD dwFontType, LPVOID pArray ) + DWORD dwFontType, LPARAM pArray ) { PHB_ITEM pSubItems = hb_itemArrayNew( 4 ); diff --git a/include/harbour.hbx b/include/harbour.hbx index 8abaada73b..764d17495e 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -479,7 +479,9 @@ DYNAMIC hb_gfxPrimitive DYNAMIC hb_gfxText DYNAMIC hb_gtAlert DYNAMIC hb_gtCreate +DYNAMIC hb_gtExists DYNAMIC hb_gtInfo +DYNAMIC hb_gtList DYNAMIC hb_gtLock DYNAMIC hb_gtReload DYNAMIC hb_gtSelect diff --git a/include/hbapi.h b/include/hbapi.h index 08da334e8a..63b45e69e6 100644 --- a/include/hbapi.h +++ b/include/hbapi.h @@ -1226,11 +1226,13 @@ extern HB_EXPORT const char * hb_osDecodeCP( const char * szName, char ** pszFre extern HB_EXPORT char * hb_osStrEncode( const char * pszName ); extern HB_EXPORT char * hb_osStrEncodeN( const char * pszName, HB_SIZE nLen ); +extern HB_EXPORT char * hb_osStrEncode2( const char * pszName, char * pszBuffer, HB_SIZE nSize ); extern HB_EXPORT char * hb_osStrDecode( const char * pszName ); extern HB_EXPORT char * hb_osStrDecode2( const char * pszName, char * pszBuffer, HB_SIZE nSize ); #if defined( HB_OS_WIN ) extern HB_EXPORT HB_WCHAR * hb_osStrU16Encode( const char * pszName ); extern HB_EXPORT HB_WCHAR * hb_osStrU16EncodeN( const char * pszName, HB_SIZE nLen ); +extern HB_EXPORT HB_WCHAR * hb_osStrU16Encode2( const char * pszName, HB_WCHAR * pszBufferW, HB_SIZE nSize ); extern HB_EXPORT char * hb_osStrU16Decode( const HB_WCHAR * pszNameW ); extern HB_EXPORT char * hb_osStrU16Decode2( const HB_WCHAR * pszNameW, char * pszBuffer, HB_SIZE nSize ); #endif diff --git a/include/hbwinuni.h b/include/hbwinuni.h index 9ae753e78e..da79a87fa1 100644 --- a/include/hbwinuni.h +++ b/include/hbwinuni.h @@ -81,6 +81,7 @@ #define HB_FSNAMECONV( fname, pfree ) ( ( LPCTSTR ) ( *( pfree ) = hb_fsNameConvU16( fname ) ) ) #define HB_CHARDUP( str ) hb_osStrU16Encode( str ) #define HB_CHARDUPN( str, len ) hb_osStrU16EncodeN( str, len ) + #define HB_CHARDUP2( str, buf, len ) hb_osStrU16Encode2( str, buf, len ) #define HB_OSSTRDUP( str ) hb_osStrU16Decode( str ) #define HB_OSSTRDUP2( str, buf, len ) hb_osStrU16Decode2( str, buf, len ) #define HB_WINAPI_SYSTEM( cmd ) _wsystem( cmd ) @@ -120,6 +121,7 @@ #define HB_FSNAMECONV( fname, pfree ) hb_fsNameConv( fname, pfree ) #define HB_CHARDUP( str ) hb_osStrEncode( str ) #define HB_CHARDUPN( str, len ) hb_osStrEncodeN( str, len ) + #define HB_CHARDUP2( str, buf, len ) hb_osStrEncode2( str, buf, len ) #define HB_OSSTRDUP( str ) hb_osStrDecode( str ) #define HB_OSSTRDUP2( str, buf, len ) hb_osStrDecode2( str, buf, len ) #define HB_WINAPI_SYSTEM( cmd ) system( cmd ) diff --git a/src/common/hbgete.c b/src/common/hbgete.c index 895965875d..ba41d1d0d8 100644 --- a/src/common/hbgete.c +++ b/src/common/hbgete.c @@ -121,15 +121,22 @@ HB_BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize ) #if defined( HB_OS_WIN ) { - LPTSTR lpName = HB_CHARDUP( szName ), lpBuffer; + TCHAR lpNameBuffer[ 64 ], lpDestBuffer[ HB_PATH_MAX ]; + LPTSTR lpName = lpNameBuffer, lpBuffer = lpDestBuffer; - if( szBuffer != NULL || nSize > 0 ) - lpBuffer = ( LPTSTR ) hb_xgrab( nSize * sizeof( TCHAR ) ); - else + if( szBuffer == NULL || nSize == 0 ) lpBuffer = NULL; + else if( ( HB_SIZE ) nSize > HB_SIZEOFARRAY( lpDestBuffer ) ) + lpBuffer = ( LPTSTR ) hb_xgrab( nSize * sizeof( TCHAR ) ); + + if( strlen( szName ) >= HB_SIZEOFARRAY( lpNameBuffer ) ) + lpName = HB_CHARDUP( szName ); fRetVal = GetEnvironmentVariable( lpName, lpBuffer, nSize ) != 0; + if( lpName != lpNameBuffer ) + hb_xfree( lpName ); + if( lpBuffer ) { if( fRetVal ) @@ -137,9 +144,9 @@ HB_BOOL hb_getenv_buffer( const char * szName, char * szBuffer, int nSize ) lpBuffer[ nSize - 1 ] = TEXT( '\0' ); HB_OSSTRDUP2( lpBuffer, szBuffer, nSize - 1 ); } - hb_xfree( lpBuffer ); + if( lpBuffer != lpDestBuffer ) + hb_xfree( lpBuffer ); } - hb_xfree( lpName ); } #elif defined( HB_OS_OS2 ) { diff --git a/src/harbour.def b/src/harbour.def index 2c5f63232a..967c081fea 100644 --- a/src/harbour.def +++ b/src/harbour.def @@ -566,7 +566,9 @@ HB_FUN_HB_GFXPRIMITIVE HB_FUN_HB_GFXTEXT HB_FUN_HB_GTALERT HB_FUN_HB_GTCREATE +HB_FUN_HB_GTEXISTS HB_FUN_HB_GTINFO +HB_FUN_HB_GTLIST HB_FUN_HB_GTLOCK HB_FUN_HB_GTRELOAD HB_FUN_HB_GTSELECT diff --git a/src/pp/hbpp.c b/src/pp/hbpp.c index 62e5d899ce..39fbd98290 100644 --- a/src/pp/hbpp.c +++ b/src/pp/hbpp.c @@ -350,7 +350,7 @@ static int hb_pp_generateVerInfo( char * szVerFile, " * and is covered by the same license as Harbour PP\n" " */\n\n" ); - fprintf( fout, "#define HB_VER_REVID %" PFHL "u\n", nRevID ); + fprintf( fout, "#define HB_VER_REVID %" PFHL "u" PFHL "u\n", nRevID ); if( szChangeLogID ) { diff --git a/src/rtl/cdpapi.c b/src/rtl/cdpapi.c index 8397ab9210..c1d646cc74 100644 --- a/src/rtl/cdpapi.c +++ b/src/rtl/cdpapi.c @@ -1999,8 +1999,6 @@ HB_SIZE hb_cdpU16ToStr( PHB_CODEPAGE cdp, int iEndian, HB_SIZE hb_cdpTransLen( const char * pSrc, HB_SIZE nSrc, HB_SIZE nMax, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut ) { - HB_SIZE nSize; - if( cdpIn && cdpOut && cdpIn != cdpOut && ( cdpIn->uniTable != cdpOut->uniTable || HB_CDP_ISCUSTOM( cdpIn ) || HB_CDP_ISCUSTOM( cdpOut ) ) ) @@ -2011,7 +2009,7 @@ HB_SIZE hb_cdpTransLen( const char * pSrc, HB_SIZE nSrc, HB_SIZE nMax, return hb_cdpStrAsUTF8Len( cdpIn, pSrc, nSrc, nMax ); else if( HB_CDP_ISCUSTOM( cdpIn ) || HB_CDP_ISCUSTOM( cdpOut ) ) { - HB_SIZE nPosS; + HB_SIZE nPosS, nSize; HB_WCHAR wc; nPosS = nSize = 0; @@ -2022,14 +2020,11 @@ HB_SIZE hb_cdpTransLen( const char * pSrc, HB_SIZE nSrc, HB_SIZE nMax, break; nSize += i; } + return nSize; } - else - nSize = ( nMax && nSrc > nMax ) ? nMax : nSrc; } - else - nSize = ( nMax && nSrc > nMax ) ? nMax : nSrc; - return nSize; + return ( nMax && nSrc > nMax ) ? nMax : nSrc; } HB_SIZE hb_cdpTransTo( const char * pSrc, HB_SIZE nSrc, diff --git a/src/rtl/hbgtcore.c b/src/rtl/hbgtcore.c index b7b1f164bc..415c3dc67a 100644 --- a/src/rtl/hbgtcore.c +++ b/src/rtl/hbgtcore.c @@ -3935,7 +3935,8 @@ static HB_BOOL hb_gtTryInit( const char * szGtName, HB_BOOL fFree ) * pszStr = '\0'; } - hb_stackSetGT( hb_gtLoad( szGtName, NULL, NULL ) ); + if( * szGtName ) + hb_stackSetGT( hb_gtLoad( szGtName, NULL, NULL ) ); } if( fFree ) @@ -3951,9 +3952,13 @@ void hb_gtStartupInit( void ) return; if( hb_gtTryInit( hb_getenv( "HB_GT" ), HB_TRUE ) ) return; + if( s_szNameDefault == s_gtNameBuf && + hb_gtTryInit( s_szNameDefault, HB_FALSE ) ) + return; if( hb_gtTryInit( hb_gt_FindDefault(), HB_FALSE ) ) return; - if( hb_gtTryInit( s_szNameDefault, HB_FALSE ) ) + if( s_szNameDefault != s_gtNameBuf && + hb_gtTryInit( s_szNameDefault, HB_FALSE ) ) return; if( hb_dynsymFind( "HB_GT_NUL" ) ) /* GTNUL was explicitly REQUESTed */ @@ -4068,3 +4073,20 @@ HB_FUNC( HB_GTSELECT ) hb_retptrGC( gtHolder ); } } + +HB_FUNC( HB_GTEXISTS ) +{ + const char * pszGtName = hb_parc( 1 ); + + hb_retl( pszGtName && hb_gt_FindEntry( pszGtName ) >= -1 ); +} + +HB_FUNC( HB_GTLIST ) +{ + int iPos; + + hb_reta( s_iGtCount + 1 ); + hb_storvc( "NUL", -1, 1 ); + for( iPos = 0; iPos < s_iGtCount; ++iPos ) + hb_storvc( s_gtInit[ iPos ]->id, -1, iPos + 2 ); +} diff --git a/src/vm/set.c b/src/vm/set.c index c2b7708815..920f7eb25a 100644 --- a/src/vm/set.c +++ b/src/vm/set.c @@ -2867,6 +2867,27 @@ char * hb_osStrEncodeN( const char * pszName, HB_SIZE nLen ) return hb_strndup( pszName, nLen ); } +char * hb_osStrEncode2( const char * pszName, char * pszBuffer, HB_SIZE nSize ) +{ + if( hb_vmIsReady() ) + { + HB_STACK_TLS_PRELOAD + PHB_CODEPAGE cdpOS = ( PHB_CODEPAGE ) hb_stackSetStruct()->hb_set_oscp; + if( cdpOS ) + { + PHB_CODEPAGE cdpHost = hb_vmCDP(); + if( cdpHost && cdpHost != cdpOS ) + { + pszBuffer[ nSize ] = 0; + hb_cdpnDup2( pszName, strlen( pszName ), pszBuffer, &nSize, cdpHost, cdpOS ); + return pszBuffer; + } + } + } + + return hb_strncpy( pszBuffer, pszName, nSize ); +} + char * hb_osStrDecode( const char * pszName ) { if( hb_vmIsReady() ) @@ -2948,6 +2969,22 @@ HB_WCHAR * hb_osStrU16EncodeN( const char * pszName, HB_SIZE nLen ) return hb_mbntowc( pszName, nLen ); /* No HVM stack */ } +HB_WCHAR * hb_osStrU16Encode2( const char * pszName, HB_WCHAR * pszBufferW, HB_SIZE nSize ) +{ + if( hb_vmIsReady() ) + { + PHB_CODEPAGE cdp = hb_vmCDP(); + if( cdp ) + { + hb_cdpStrToU16( cdp, HB_CDP_ENDIAN_NATIVE, pszName, strlen( pszName ), pszBufferW, nSize + 1 ); + pszBufferW[ nSize ] = 0; + return pszBufferW; + } + } + hb_mbntowccpy( pszBufferW, pszName, nSize ); /* No HVM stack */ + return pszBufferW; +} + char * hb_osStrU16Decode( const HB_WCHAR * pszNameW ) { if( hb_vmIsReady() )