From 3fddd75f6bc45a08b68601eeea72b75f8db0ea84 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Thu, 5 Nov 2009 23:16:00 +0000 Subject: [PATCH] 2009-11-06 00:15 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/strcase.c * harbour/src/rtl/cdpapi.c * moved some CP dependent functions from strcase.c to cdpapi.c They will be reimplemented in new CDP code. * harbour/src/rtl/cdpapi.c * harbour/include/hbapicdp.h + added new C functions to eliminate direct access to HB_CODEPAGE structure by non core code * harbour/src/rtl/gtcgi/gtcgi.c * harbour/src/rtl/gtpca/gtpca.c * harbour/src/rtl/gtstd/gtstd.c * harbour/src/rtl/gtcrs/gtcrs.c * harbour/src/rtl/gtsln/gtsln.c * harbour/src/rtl/gttrm/gttrm.c * harbour/src/rtl/gtxwc/gtxwc.c * harbour/src/rtl/gtdos/gtdos.c * harbour/src/rtl/gtwin/gtwin.c * harbour/src/rtl/gtwvt/gtwvt.c * harbour/contrib/gtwvg/gtwvg.c * harbour/contrib/gtqtc/gtqtc.cpp * updated to eliminate direct access to HB_CODEPAGE structure --- harbour/ChangeLog | 25 ++++++ harbour/contrib/gtqtc/gtqtc.cpp | 78 ++++++++++------- harbour/contrib/gtwvg/gtwvg.c | 99 +++++++++------------- harbour/include/hbapicdp.h | 9 ++ harbour/src/rtl/cdpapi.c | 144 +++++++++++++++++++++++++++++++- harbour/src/rtl/gtcgi/gtcgi.c | 3 +- harbour/src/rtl/gtcrs/gtcrs.c | 131 +++++++++-------------------- harbour/src/rtl/gtdos/gtdos.c | 73 ++++++++-------- harbour/src/rtl/gtpca/gtpca.c | 62 +++++--------- harbour/src/rtl/gtsln/gtsln.c | 85 +++++++------------ harbour/src/rtl/gtstd/gtstd.c | 66 +++++---------- harbour/src/rtl/gttrm/gttrm.c | 114 +++++++------------------ harbour/src/rtl/gtwin/gtwin.c | 109 ++++++++++-------------- harbour/src/rtl/gtwvt/gtwvt.c | 99 +++++++++------------- harbour/src/rtl/gtxwc/gtxwc.c | 36 ++++---- harbour/src/rtl/strcase.c | 67 --------------- 16 files changed, 542 insertions(+), 658 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7308fd2d85..9b51500d54 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,31 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-11-06 00:15 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rtl/strcase.c + * harbour/src/rtl/cdpapi.c + * moved some CP dependent functions from strcase.c to cdpapi.c + They will be reimplemented in new CDP code. + + * harbour/src/rtl/cdpapi.c + * harbour/include/hbapicdp.h + + added new C functions to eliminate direct access to HB_CODEPAGE + structure by non core code + + * harbour/src/rtl/gtcgi/gtcgi.c + * harbour/src/rtl/gtpca/gtpca.c + * harbour/src/rtl/gtstd/gtstd.c + * harbour/src/rtl/gtcrs/gtcrs.c + * harbour/src/rtl/gtsln/gtsln.c + * harbour/src/rtl/gttrm/gttrm.c + * harbour/src/rtl/gtxwc/gtxwc.c + * harbour/src/rtl/gtdos/gtdos.c + * harbour/src/rtl/gtwin/gtwin.c + * harbour/src/rtl/gtwvt/gtwvt.c + * harbour/contrib/gtwvg/gtwvg.c + * harbour/contrib/gtqtc/gtqtc.cpp + * updated to eliminate direct access to HB_CODEPAGE structure + 2009-11-05 19:25 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.prg ! Deleted 'lib' prefix for os2/gcc targets to sync it diff --git a/harbour/contrib/gtqtc/gtqtc.cpp b/harbour/contrib/gtqtc/gtqtc.cpp index 31bb473991..dbc97fbe8d 100644 --- a/harbour/contrib/gtqtc/gtqtc.cpp +++ b/harbour/contrib/gtqtc/gtqtc.cpp @@ -770,8 +770,7 @@ static BOOL hb_gt_wvt_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * We are displaying text in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -784,40 +783,35 @@ static BOOL hb_gt_wvt_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char { PHB_CODEPAGE cdpHost = hb_cdpFind( pszHostCDP ); if( cdpHost ) - HB_GTWVT_GET( pGT )->hostCDP = cdpHost; - } - -#else - if( !pszHostCDP ) - pszHostCDP = hb_cdpID(); - if( !pszTermCDP ) - pszTermCDP = pszHostCDP; - - if( pszTermCDP && pszHostCDP ) - { - PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - int i; - - for( i = 0; i < 256; ++i ) - pWVT->chrTransTbl[ i ] = ( BYTE ) i; - - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) { - for( i = 0; i < cdpHost->nChars; ++i ) - { - pWVT->chrTransTbl[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - pWVT->chrTransTbl[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + + pWVT->hostCDP = cdpHost; + pWVT->boxCDP = fBox ? cdpHost : hb_cdpFind( "EN" ); } } +# else + { + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + PHB_CODEPAGE cdpTerm, cdpHost; + int i; -#endif + if( !pszHostCDP ) + pszHostCDP = hb_cdpID(); + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + { + pWVT->chrTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); + } + } +# endif #endif return TRUE; @@ -828,6 +822,7 @@ static BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); #ifndef HB_CDP_SUPPORT_OFF +# if defined( UNICODE ) /* * We are receiving WM_CHAR events in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -842,6 +837,27 @@ static BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char if( cdpHost ) HB_GTWVT_GET( pGT )->inCDP = cdpHost; } +# else + { + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + PHB_CODEPAGE cdpTerm, cdpHost; + int i; + + if( !pszHostCDP ) + pszHostCDP = hb_cdpID(); + + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + pWVT->keyTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); + pWVT->inCDP = cdpTerm; + } +# endif #endif return TRUE; diff --git a/harbour/contrib/gtwvg/gtwvg.c b/harbour/contrib/gtwvg/gtwvg.c index 5ec7002656..f1628836c5 100644 --- a/harbour/contrib/gtwvg/gtwvg.c +++ b/harbour/contrib/gtwvg/gtwvg.c @@ -4033,8 +4033,7 @@ static BOOL hb_gt_wvt_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * We are displaying text in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -4047,41 +4046,35 @@ static BOOL hb_gt_wvt_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char { PHB_CODEPAGE cdpHost = hb_cdpFind( pszHostCDP ); if( cdpHost ) - HB_GTWVT_GET( pGT )->hostCDP = cdpHost; - } - -#else - - if( !pszHostCDP ) - pszHostCDP = hb_cdpID(); - if( !pszTermCDP ) - pszTermCDP = pszHostCDP; - - if( pszTermCDP && pszHostCDP ) - { - PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - int i; - - for( i = 0; i < 256; ++i ) - pWVT->chrTransTbl[ i ] = ( BYTE ) i; - - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) { - for( i = 0; i < cdpHost->nChars; ++i ) - { - pWVT->chrTransTbl[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - pWVT->chrTransTbl[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + + pWVT->hostCDP = cdpHost; + pWVT->boxCDP = fBox ? cdpHost : hb_cdpFind( "EN" ); } } +# else + { + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + PHB_CODEPAGE cdpTerm, cdpHost; + int i; -#endif + if( !pszHostCDP ) + pszHostCDP = hb_cdpID(); + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + { + pWVT->chrTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); + } + } +# endif #endif return TRUE; @@ -4092,8 +4085,7 @@ static BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * We are receiving WM_CHAR events in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -4108,40 +4100,27 @@ static BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char if( cdpHost ) HB_GTWVT_GET( pGT )->inCDP = cdpHost; } - -#else - - if( !pszHostCDP ) - pszHostCDP = hb_cdpID(); - if( !pszTermCDP ) - pszTermCDP = pszHostCDP; - - if( pszTermCDP && pszHostCDP ) +# else { PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); + PHB_CODEPAGE cdpTerm, cdpHost; int i; - for( i = 0; i < 256; ++i ) - pWVT->keyTransTbl[ i ] = ( BYTE ) i; + if( !pszHostCDP ) + pszHostCDP = hb_cdpID(); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - for( i = 0; i < cdpHost->nChars; ++i ) - { - pWVT->keyTransTbl[ ( BYTE ) cdpTerm->CharsUpper[ i ] ] = - ( BYTE ) cdpHost->CharsUpper[ i ]; - pWVT->keyTransTbl[ ( BYTE ) cdpTerm->CharsLower[ i ] ] = - ( BYTE ) cdpHost->CharsLower[ i ]; - } - } + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + pWVT->keyTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); pWVT->inCDP = cdpTerm; } -#endif - +# endif #endif return TRUE; diff --git a/harbour/include/hbapicdp.h b/harbour/include/hbapicdp.h index 43faaba831..7f3b297cd8 100644 --- a/harbour/include/hbapicdp.h +++ b/harbour/include/hbapicdp.h @@ -315,6 +315,10 @@ extern HB_EXPORT const char * hb_cdpID( void ); extern HB_EXPORT PHB_CODEPAGE hb_cdpSelect( PHB_CODEPAGE ); extern HB_EXPORT PHB_CODEPAGE hb_cdpFind( const char * ); extern HB_EXPORT PHB_CODEPAGE hb_cdpFindExt( const char * ); +extern HB_EXPORT BOOL hb_cdpIsDigit( PHB_CODEPAGE, int ); +extern HB_EXPORT BOOL hb_cdpIsAlpha( PHB_CODEPAGE, int ); +extern HB_EXPORT BOOL hb_cdpIsLower( PHB_CODEPAGE, int ); +extern HB_EXPORT BOOL hb_cdpIsUpper( PHB_CODEPAGE, int ); extern HB_EXPORT int hb_cdpcmp( const char *, ULONG, const char *, ULONG, PHB_CODEPAGE, BOOL ); extern HB_EXPORT int hb_cdpicmp( const char *, ULONG, const char *, ULONG, PHB_CODEPAGE, BOOL ); extern HB_EXPORT int hb_cdpchrcmp( char, char, PHB_CODEPAGE ); @@ -328,6 +332,8 @@ extern HB_EXPORT ULONG hb_cdpnDup2Len( const char *, ULONG, ULONG, PHB_C extern HB_EXPORT void hb_cdpTranslate( char *, PHB_CODEPAGE, PHB_CODEPAGE ); extern HB_EXPORT void hb_cdpnTranslate( char *, PHB_CODEPAGE, PHB_CODEPAGE, ULONG ); +extern HB_EXPORT int hb_cdpTranslateChar( int iChar, BOOL fCtrl, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut ); + extern HB_EXPORT HB_WCHAR hb_cdpGetU16( PHB_CODEPAGE, BOOL, UCHAR ); extern HB_EXPORT UCHAR hb_cdpGetChar( PHB_CODEPAGE, BOOL, HB_WCHAR ); extern HB_EXPORT BOOL hb_cdpGetFromUTF8( PHB_CODEPAGE, BOOL, UCHAR, int *, HB_WCHAR * ); @@ -355,6 +361,9 @@ extern HB_EXPORT ULONG hb_cdpUTF8StringPeek( const char *, ULONG, ULONG extern HB_EXPORT PHB_ITEM hb_itemDeserializeCP( const char ** pBufferPtr, ULONG * pulSize, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut ); extern HB_EXPORT char * hb_itemSerializeCP( PHB_ITEM pItem, BOOL fNumSize, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut, ULONG *pulSize ); +#define hb_cdpStrToUTF8( cdp, ctrl, src, slen, dst, dlen ) \ + hb_cdpStrnToUTF8( cdp, ctrl, src, slen, dst ) + HB_EXTERN_END #else diff --git a/harbour/src/rtl/cdpapi.c b/harbour/src/rtl/cdpapi.c index 2aa770c641..94b473f6ad 100644 --- a/harbour/src/rtl/cdpapi.c +++ b/harbour/src/rtl/cdpapi.c @@ -517,6 +517,59 @@ BOOL hb_charIsUpper( int iChar ) return FALSE; } +BOOL hb_cdpIsDigit( PHB_CODEPAGE cdp, int iChar ) +{ + HB_SYMBOL_UNUSED( cdp ); + + return HB_ISDIGIT( ( unsigned char ) iChar ); +} + +BOOL hb_cdpIsAlpha( PHB_CODEPAGE cdp, int iChar ) +{ + if( HB_ISALPHA( ( unsigned char ) iChar ) ) + return TRUE; + else + { + /* ( char * ) casting for MSVC */ + if( cdp && cdp->nChars && iChar && + ( strchr( ( char * ) cdp->CharsUpper, iChar ) || + strchr( ( char * ) cdp->CharsLower, iChar ) ) ) + return TRUE; + } + + return FALSE; +} + +BOOL hb_cdpIsLower( PHB_CODEPAGE cdp, int iChar ) +{ + if( HB_ISLOWER( ( unsigned char ) iChar ) ) + return TRUE; + else + { + /* ( char * ) casting for MSVC */ + if( cdp && cdp->nChars && iChar && + strchr( ( char * ) cdp->CharsLower, iChar ) ) + return TRUE; + } + + return FALSE; +} + +BOOL hb_cdpIsUpper( PHB_CODEPAGE cdp, int iChar ) +{ + if( HB_ISUPPER( ( unsigned char ) iChar ) ) + return TRUE; + else + { + /* ( char * ) casting for MSVC */ + if( cdp && cdp->nChars && iChar && + strchr( ( char * ) cdp->CharsUpper, iChar ) ) + return TRUE; + } + + return FALSE; +} + PHB_CODEPAGE hb_cdpFind( const char *pszID ) { int iPos; @@ -666,6 +719,27 @@ void hb_cdpnTranslate( char *psz, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut, ULONG } } +int hb_cdpTranslateChar( int iChar, BOOL fCtrl, PHB_CODEPAGE cdpIn, PHB_CODEPAGE cdpOut ) +{ + if( cdpIn && cdpOut && cdpIn != cdpOut && cdpIn->nChars == cdpOut->nChars && + iChar >= ( fCtrl ? 32 : 0 ) && iChar < 256 ) + { + /* ( char * ) casting for MSVC */ + char * ptr = strchr( ( char * ) cdpIn->CharsUpper, iChar ); + if( ptr ) + iChar = ( unsigned char ) cdpOut->CharsUpper[ ptr - cdpIn->CharsUpper ]; + else + { + /* ( char * ) casting for MSVC */ + ptr = strchr( ( char * ) cdpIn->CharsLower, iChar ); + if( ptr ) + iChar = ( unsigned char ) cdpOut->CharsLower[ ptr - cdpIn->CharsLower ]; + } + } + + return iChar; +} + HB_WCHAR hb_cdpGetU16( PHB_CODEPAGE cdp, BOOL fCtrl, UCHAR ch ) { if( ( fCtrl || ch >= 32 ) && cdp && cdp->uniTable && @@ -1490,12 +1564,12 @@ const char * hb_cdpnDup3( const char * pszSrc, ULONG ulSrc, } if( pszPrev ) hb_xfree( pszPrev ); - if( *pulDst ) + if( pulDst ) *pulDst = ulDst; return pszDst; } - if( *pulDst ) + if( pulDst ) *pulDst = ulSrc; return pszSrc; } @@ -2175,3 +2249,69 @@ BOOL hb_charIsUpper( int iChar ) } #endif /* HB_CDP_SUPPORT_OFF */ + +/* converts szText to lower case. Does not create a new string! */ +char * hb_strLower( char * szText, ULONG ulLen ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_strLower(%s, %lu)", szText, ulLen)); + + { + ULONG i; +#ifndef HB_CDP_SUPPORT_OFF + PHB_CODEPAGE cdp = hb_vmCDP(); + if( cdp && cdp->nChars ) + for( i = 0; i < ulLen; i++ ) + szText[ i ] = ( char ) cdp->s_lower[ ( UCHAR ) szText[ i ] ]; + else +#endif + for( i = 0; i < ulLen; i++ ) + szText[ i ] = HB_TOLOWER( szText[ i ] ); + } + + return szText; +} + +/* converts szText to upper case. Does not create a new string! */ +char * hb_strUpper( char * szText, ULONG ulLen ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_strUpper(%s, %lu)", szText, ulLen)); + + { + ULONG i; +#ifndef HB_CDP_SUPPORT_OFF + PHB_CODEPAGE cdp = hb_vmCDP(); + if( cdp && cdp->nChars ) + for( i = 0; i < ulLen; i++ ) + szText[ i ] = ( char ) cdp->s_upper[ ( UCHAR ) szText[ i ] ]; + else +#endif + for( i = 0; i < ulLen; i++ ) + szText[ i ] = HB_TOUPPER( szText[ i ] ); + } + + return szText; +} + +/* converts iChar to lower case */ +int hb_charLower( int iChar ) +{ +#ifndef HB_CDP_SUPPORT_OFF + PHB_CODEPAGE cdp = hb_vmCDP(); + if( cdp && cdp->nChars ) + return ( unsigned char ) cdp->s_lower[ (unsigned char) iChar ]; + else +#endif + return HB_TOLOWER( iChar ); +} + +/* converts iChar to upper case */ +int hb_charUpper( int iChar ) +{ +#ifndef HB_CDP_SUPPORT_OFF + PHB_CODEPAGE cdp = hb_vmCDP(); + if( cdp && cdp->nChars ) + return ( unsigned char ) cdp->s_upper[ (unsigned char) iChar ]; + else +#endif + return HB_TOUPPER( iChar ); +} diff --git a/harbour/src/rtl/gtcgi/gtcgi.c b/harbour/src/rtl/gtcgi/gtcgi.c index 4314db73ff..da9325a937 100644 --- a/harbour/src/rtl/gtcgi/gtcgi.c +++ b/harbour/src/rtl/gtcgi/gtcgi.c @@ -245,11 +245,10 @@ static BOOL hb_gt_cgi_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char pGTCGI->cdpHost = hb_cdpFindExt( pszHostCDP ); pGTCGI->fDispTrans = pGTCGI->cdpTerm && pGTCGI->cdpHost && pGTCGI->cdpTerm != pGTCGI->cdpHost; - return TRUE; } #endif - return FALSE; + return TRUE; } #ifdef HB_GT_CGI_RAWOUTPUT diff --git a/harbour/src/rtl/gtcrs/gtcrs.c b/harbour/src/rtl/gtcrs/gtcrs.c index 46da3e9ec5..1dc1ce8276 100644 --- a/harbour/src/rtl/gtcrs/gtcrs.c +++ b/harbour/src/rtl/gtcrs/gtcrs.c @@ -1844,21 +1844,17 @@ static int gt_setsize( InOutBase * ioBase, int rows, int cols ) return ret; } -static void setKeyTrans( InOutBase * ioBase, unsigned char *ksrc, unsigned char *kdst ) +static void setKeyTrans( InOutBase * ioBase, PHB_CODEPAGE cdpTerm, PHB_CODEPAGE cdpHost ) { - unsigned char c; - int n; + int i; - if ( ksrc && kdst ) + if ( cdpTerm && cdpHost && cdpTerm != cdpHost ) { if ( ioBase->in_transtbl == NULL ) ioBase->in_transtbl = ( unsigned char * ) hb_xgrab( 256 ); - memset( ioBase->in_transtbl, 0, 256 ); - - for ( n = 0; n < 256 && ( c = ksrc[n] ); n++ ) - ioBase->in_transtbl[c] = kdst[n]; - + for ( i = 0; i < 256; ++i ) + ioBase->in_transtbl[i] = hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); } else if ( ioBase->in_transtbl != NULL ) { @@ -1867,14 +1863,12 @@ static void setKeyTrans( InOutBase * ioBase, unsigned char *ksrc, unsigned char } } -static void setDispTrans( InOutBase * ioBase, const char *src, const char *dst, int box ) +static void setDispTrans( InOutBase * ioBase, PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, int box ) { - unsigned char c, d; - int i, aSet = 0; + int i, aSet; chtype ch; - if ( src && dst ) - aSet = 1; + aSet = ( cdpHost && cdpTerm ); for ( i = 0; i < 256; i++ ) { @@ -1920,20 +1914,25 @@ static void setDispTrans( InOutBase * ioBase, const char *src, const char *dst, } if ( aSet ) { - for( i = 0; i < 256 && ( c = ( unsigned char ) src[i] ); i++ ) + for( i = 0; i < 256; ++i ) { - d = ( unsigned char ) dst[i]; - ioBase->std_chmap[c] = d | A_NORMAL; - if( box ) - ioBase->box_chmap[c] = d | A_NORMAL; - if( c != d ) + if( hb_cdpIsAlpha( cdpHost, i ) ) { - if( ioBase->out_transtbl == NULL ) + unsigned char uc = ( unsigned char ) + hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); + + ioBase->std_chmap[i] = uc | A_NORMAL; + if( box ) + ioBase->box_chmap[i] = uc | A_NORMAL; + if( i != ( int ) uc ) { - ioBase->out_transtbl = ( unsigned char * )hb_xgrab( 256 ); - memset( ioBase->out_transtbl, 0, 256 ); + if( ioBase->out_transtbl == NULL ) + { + ioBase->out_transtbl = ( unsigned char * ) hb_xgrab( 256 ); + memset( ioBase->out_transtbl, 0, 256 ); + } + ioBase->out_transtbl[i] = uc; } - ioBase->out_transtbl[c] = d; } } } @@ -2422,11 +2421,6 @@ int HB_GT_FUNC( gt_WaitKey( double dTimeOut ) ) return wait_key( s_ioBase, ( int ) ( dTimeOut * 1000.0 ) ); } -void HB_GT_FUNC( gt_SetKeyTrans( unsigned char *szSrc, unsigned char *szDst ) ) -{ - setKeyTrans( s_ioBase, szSrc, szDst ); -} - int HB_GT_FUNC( gt_AddKeyMap( int iKey, char *szSequence ) ) { return addKeyMap( s_ioBase, SET_CLIPKEY( iKey ), szSequence ); @@ -2833,47 +2827,20 @@ static BOOL hb_gt_crs_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char { HB_TRACE( HB_TR_DEBUG, ( "hb_gt_crs_SetDispCP(%p,%s,%s,%d)", pGT, pszTermCDP, pszHostCDP, (int) fBox ) ); +#ifndef HB_CDP_SUPPORT_OFF HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); -#ifndef HB_CDP_SUPPORT_OFF - if( !pszHostCDP || !*pszHostCDP ) - { + if( !pszHostCDP ) pszHostCDP = hb_cdpID(); - if ( !pszHostCDP ) - pszHostCDP = pszTermCDP; - } - if( !pszTermCDP || !*pszTermCDP ) + if( !pszTermCDP ) pszTermCDP = pszHostCDP; - if( pszTermCDP && pszHostCDP && *pszTermCDP && *pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost ) - { - if( cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - char *pszHostLetters = ( char * ) hb_xgrab( cdpHost->nChars * 2 + 1 ); - char *pszTermLetters = ( char * ) hb_xgrab( cdpTerm->nChars * 2 + 1 ); - - hb_strncpy( pszHostLetters, cdpHost->CharsUpper, cdpHost->nChars * 2 ); - hb_strncat( pszHostLetters, cdpHost->CharsLower, cdpHost->nChars * 2 ); - hb_strncpy( pszTermLetters, cdpTerm->CharsUpper, cdpTerm->nChars * 2 ); - hb_strncat( pszTermLetters, cdpTerm->CharsLower, cdpTerm->nChars * 2 ); - - setDispTrans( s_ioBase, pszHostLetters, pszTermLetters, fBox ? 1 : 0 ); - - hb_xfree( pszHostLetters ); - hb_xfree( pszTermLetters ); - return TRUE; - } - else - setDispTrans( s_ioBase, "", "", fBox ? 1 : 0 ); - } - } + setDispTrans( s_ioBase, hb_cdpFind( pszHostCDP ), + hb_cdpFind( pszTermCDP ), fBox ? 1 : 0 ); + return TRUE; +#else + return HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); #endif - - return FALSE; } /* *********************************************************************** */ @@ -2882,40 +2849,20 @@ static BOOL hb_gt_crs_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char * { HB_TRACE( HB_TR_DEBUG, ( "hb_gt_crs_SetKeyCP(%p,%s,%s)", pGT, pszTermCDP, pszHostCDP ) ); +#ifndef HB_CDP_SUPPORT_OFF HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); -#ifndef HB_CDP_SUPPORT_OFF - if( !pszHostCDP || !*pszHostCDP ) - { + if( !pszHostCDP ) pszHostCDP = hb_cdpID(); - } + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; - if( pszTermCDP && pszHostCDP && *pszTermCDP && *pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - char *pszHostLetters = ( char * ) hb_xgrab( cdpHost->nChars * 2 + 1 ); - char *pszTermLetters = ( char * ) hb_xgrab( cdpTerm->nChars * 2 + 1 ); + setKeyTrans( s_ioBase, hb_cdpFind( pszTermCDP ), hb_cdpFind( pszHostCDP ) ); - hb_strncpy( pszHostLetters, cdpHost->CharsUpper, cdpHost->nChars * 2 ); - hb_strncat( pszHostLetters, cdpHost->CharsLower, cdpHost->nChars * 2 ); - hb_strncpy( pszTermLetters, cdpTerm->CharsUpper, cdpTerm->nChars * 2 ); - hb_strncat( pszTermLetters, cdpTerm->CharsLower, cdpTerm->nChars * 2 ); - - setKeyTrans( s_ioBase, ( unsigned char * ) pszTermLetters, - ( unsigned char * ) pszHostLetters ); - - hb_xfree( pszHostLetters ); - hb_xfree( pszTermLetters ); - return TRUE; - } - } + return TRUE; +#else + return HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); #endif - - return FALSE; } /* *********************************************************************** */ diff --git a/harbour/src/rtl/gtdos/gtdos.c b/harbour/src/rtl/gtdos/gtdos.c index 9000e0cb6c..d2f2653203 100644 --- a/harbour/src/rtl/gtdos/gtdos.c +++ b/harbour/src/rtl/gtdos/gtdos.c @@ -1241,39 +1241,36 @@ static BOOL hb_gt_dos_Resume( PHB_GT pGT ) static BOOL hb_gt_dos_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char *pszHostCDP, BOOL fBox ) { + PHB_CODEPAGE cdpTerm, cdpHost; int i; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_SetDispCP(%p,%s,%s,%d)", pGT, pszTermCDP, pszHostCDP, (int) fBox ) ); HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); - for( i = 0; i < 256; i++ ) - s_charTrans[ i ] = ( BYTE ) i; - #ifndef HB_CDP_SUPPORT_OFF if( !pszHostCDP ) pszHostCDP = hb_cdpID(); - if( pszTermCDP && pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - for( i = 0; i < cdpHost->nChars; ++i ) - { - s_charTrans[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - s_charTrans[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } - } - } -#endif + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); for( i = 0; i < 256; i++ ) - s_charTransRev[ s_charTrans[ i ] ] = ( BYTE ) i; + { + s_charTrans[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpHost, cdpTerm ); + s_charTransRev[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); + } +#else + HB_SYMBOL_UNUSED( cdpTerm ); + HB_SYMBOL_UNUSED( cdpHost ); + for( i = 0; i < 256; i++ ) + s_charTransRev[ i ] = s_charTrans[ i ] = ( BYTE ) i; +#endif return TRUE; } @@ -1282,37 +1279,33 @@ static BOOL hb_gt_dos_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char static BOOL hb_gt_dos_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char *pszHostCDP ) { + PHB_CODEPAGE cdpTerm, cdpHost; int i; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_SetKeyCP(%p,%s,%s)", pGT, pszTermCDP, pszHostCDP ) ); HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); - for( i = 0; i < 256; i++ ) - s_keyTrans[ i ] = ( BYTE ) i; - #ifndef HB_CDP_SUPPORT_OFF if( !pszHostCDP ) - { pszHostCDP = hb_cdpID(); - } - if( pszTermCDP && pszHostCDP ) + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - for( i = 0; i < cdpHost->nChars; ++i ) - { - s_keyTrans[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - s_keyTrans[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } - } + s_keyTrans[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); } +#else + HB_SYMBOL_UNUSED( cdpTerm ); + HB_SYMBOL_UNUSED( cdpHost ); + for( i = 0; i < 256; i++ ) + s_keyTrans[ i ] = ( BYTE ) i; #endif return TRUE; diff --git a/harbour/src/rtl/gtpca/gtpca.c b/harbour/src/rtl/gtpca/gtpca.c index 68f1604067..465d3b8fed 100644 --- a/harbour/src/rtl/gtpca/gtpca.c +++ b/harbour/src/rtl/gtpca/gtpca.c @@ -103,6 +103,8 @@ static int s_iRow; static int s_iCol; static int s_iLineBufSize = 0; static char * s_sLineBuf; +static ULONG s_ulTransBufSize = 0; +static char * s_sTransBuf; static const char * s_szCrLf; static ULONG s_ulCrLf; static int s_iCurrentSGR, s_iFgColor, s_iBgColor, s_iBold, s_iBlink, s_iAM; @@ -436,7 +438,7 @@ static void hb_gt_pca_AnsiInit( void ) s_iCurrentSGR = s_iRow = s_iCol = s_iCursorStyle = s_iAM = -1; } -static void hb_gt_pca_AnsiPutStr( int iRow, int iCol, int iColor, char * szStr, int iLen ) +static void hb_gt_pca_AnsiPutStr( int iRow, int iCol, int iColor, const char * szStr, int iLen ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_pca_AnsiPutStr(%d,%d,%d,%p,%d)", iRow, iCol, iColor, szStr, iLen)); @@ -447,19 +449,13 @@ static void hb_gt_pca_AnsiPutStr( int iRow, int iCol, int iColor, char * szStr, s_iCol += iLen; } -static void hb_gt_pca_setKeyTrans( char * pSrcChars, char * pDstChars ) +static void hb_gt_pca_setKeyTrans( PHB_CODEPAGE cdpTerm, PHB_CODEPAGE cdpHost ) { int i; for( i = 0; i < 256; ++i ) - s_keyTransTbl[ i ] = ( BYTE ) i; - - if( pSrcChars && pDstChars ) - { - BYTE c; - for( i = 0; i < 256 && ( c = ( BYTE ) pSrcChars[ i ] ) != 0; ++i ) - s_keyTransTbl[ c ] = ( BYTE ) pDstChars[ i ]; - } + s_keyTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); } static void hb_gt_pca_Init( PHB_GT pGT, HB_FHANDLE hFilenoStdin, HB_FHANDLE hFilenoStdout, HB_FHANDLE hFilenoStderr ) @@ -579,6 +575,11 @@ static void hb_gt_pca_Exit( PHB_GT pGT ) hb_xfree( s_sLineBuf ); s_iLineBufSize = 0; } + if( s_ulTransBufSize > 0 ) + { + hb_xfree( s_sTransBuf ); + s_ulTransBufSize = 0; + } if( s_iOutBufSize > 0 ) { hb_xfree( s_sOutBuf ); @@ -789,11 +790,10 @@ static BOOL hb_gt_pca_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char s_cdpTerm = hb_cdpFind( pszTermCDP ); s_cdpHost = hb_cdpFind( pszHostCDP ); s_fDispTrans = s_cdpTerm && s_cdpHost && s_cdpTerm != s_cdpHost; - return TRUE; } #endif - return FALSE; + return TRUE; } static BOOL hb_gt_pca_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char *pszHostCDP ) @@ -808,31 +808,7 @@ static BOOL hb_gt_pca_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char * if( !pszTermCDP ) pszTermCDP = pszHostCDP; - if( pszTermCDP && pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - char *pszHostLetters = ( char * ) hb_xgrab( cdpHost->nChars * 2 + 1 ); - char *pszTermLetters = ( char * ) hb_xgrab( cdpTerm->nChars * 2 + 1 ); - - hb_strncpy( pszHostLetters, cdpHost->CharsUpper, cdpHost->nChars * 2 ); - hb_strncat( pszHostLetters, cdpHost->CharsLower, cdpHost->nChars * 2 ); - hb_strncpy( pszTermLetters, cdpTerm->CharsUpper, cdpTerm->nChars * 2 ); - hb_strncat( pszTermLetters, cdpTerm->CharsLower, cdpTerm->nChars * 2 ); - - hb_gt_pca_setKeyTrans( pszTermLetters, pszHostLetters ); - - hb_xfree( pszHostLetters ); - hb_xfree( pszTermLetters ); - } - else - hb_gt_pca_setKeyTrans( NULL, NULL ); - - return TRUE; - } + hb_gt_pca_setKeyTrans( hb_cdpFind( pszTermCDP ), hb_cdpFind( pszHostCDP ) ); #endif return TRUE; @@ -860,9 +836,11 @@ static void hb_gt_pca_Redraw( PHB_GT pGT, int iRow, int iCol, int iSize ) if( s_fDispTrans ) { ULONG ulLen = iLen; - char * buffer = hb_cdpnDup( s_sLineBuf, &ulLen, s_cdpHost, s_cdpTerm ); + const char * buffer = hb_cdpnDup3( s_sLineBuf, ulLen, + s_sTransBuf, &ulLen, + &s_sTransBuf, &s_ulTransBufSize, + s_cdpHost, s_cdpTerm ); hb_gt_pca_AnsiPutStr( iRow, iCol, iColor2, buffer, ulLen ); - hb_xfree( buffer ); } else #endif @@ -882,9 +860,11 @@ static void hb_gt_pca_Redraw( PHB_GT pGT, int iRow, int iCol, int iSize ) if( s_fDispTrans ) { ULONG ulLen = iLen; - char * buffer = hb_cdpnDup( s_sLineBuf, &ulLen, s_cdpHost, s_cdpTerm ); + const char * buffer = hb_cdpnDup3( s_sLineBuf, ulLen, + s_sTransBuf, &ulLen, + &s_sTransBuf, &s_ulTransBufSize, + s_cdpHost, s_cdpTerm ); hb_gt_pca_AnsiPutStr( iRow, iCol, iColor2, buffer, ulLen ); - hb_xfree( buffer ); } else #endif diff --git a/harbour/src/rtl/gtsln/gtsln.c b/harbour/src/rtl/gtsln/gtsln.c index 2e00a8736f..ed444b312d 100644 --- a/harbour/src/rtl/gtsln/gtsln.c +++ b/harbour/src/rtl/gtsln/gtsln.c @@ -348,13 +348,14 @@ static void hb_sln_setACSCtrans( void ) static void hb_sln_setCharTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, BOOL fBox ) { - int i, iSrc, iDst; + int i, iDst; -#ifdef HB_CDP_SUPPORT_OFF +#if defined( HB_CDP_SUPPORT_OFF ) HB_SYMBOL_UNUSED( cdpHost ); HB_SYMBOL_UNUSED( cdpTerm ); HB_SYMBOL_UNUSED( fBox ); - HB_SYMBOL_UNUSED( iSrc ); +#elif !defined( HB_SLN_UNICODE ) + HB_SYMBOL_UNUSED( cdpTerm ); #endif /* build a conversion chars table */ @@ -392,35 +393,24 @@ static void hb_sln_setCharTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, BOO memcpy( s_outboxTab, s_outputTab, sizeof( s_outputTab ) ); #ifndef HB_CDP_SUPPORT_OFF - if( cdpHost && cdpHost->nChars ) + if( cdpHost ) { -#ifdef HB_SLN_UNICODE - HB_SYMBOL_UNUSED( cdpTerm ); -#else - BOOL fTrans = cdpTerm && cdpTerm->nChars == cdpHost->nChars; -#endif - - for( i = 0; i < cdpHost->nChars; i++ ) + for( i = 0; i < 256; ++i ) { - iSrc = ( unsigned char ) cdpHost->CharsUpper[ i ]; + if( hb_cdpIsAlpha( cdpHost, i ) ) + { #ifdef HB_SLN_UNICODE - iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) iSrc ); + iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) i ); #else - iDst = fTrans ? ( unsigned char ) cdpTerm->CharsUpper[ i ] : iSrc; + if( hb_sln_Is_Unicode ) + iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) i ); + else + iDst = hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); #endif - HB_SLN_BUILD_RAWCHAR( s_outputTab[ iSrc ], iDst, 0 ); - if( fBox ) - s_outboxTab[ iSrc ] = s_outputTab[ iSrc ]; - - iSrc = ( unsigned char ) cdpHost->CharsLower[ i ]; -#ifdef HB_SLN_UNICODE - iDst = hb_cdpGetU16( cdpHost, TRUE, ( BYTE ) iSrc ); -#else - iDst = fTrans ? ( unsigned char ) cdpTerm->CharsLower[ i ] : iSrc; -#endif - HB_SLN_BUILD_RAWCHAR( s_outputTab[ iSrc ], iDst, 0 ); - if( fBox ) - s_outboxTab[ iSrc ] = s_outputTab[ iSrc ]; + HB_SLN_BUILD_RAWCHAR( s_outputTab[ i ], iDst, 0 ); + if( fBox ) + s_outboxTab[ i ] = s_outputTab[ i ]; + } } } #endif @@ -433,29 +423,16 @@ static void hb_sln_setKeyTrans( PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm ) char *p; int i; - for ( i = 0; i < 256; i++ ) - hb_sln_inputTab[ i ] = ( unsigned char ) i; - #ifndef HB_CDP_SUPPORT_OFF - if ( cdpHost && cdpTerm && cdpTerm->nChars == cdpHost->nChars ) - { - int iSrc, iDst; - - for ( i = 0; i < cdpHost->nChars; i++ ) - { - iSrc = ( unsigned char ) cdpTerm->CharsUpper[ i ]; - iDst = ( unsigned char ) cdpHost->CharsUpper[ i ]; - hb_sln_inputTab[ iSrc ] = iDst; - - iSrc = ( unsigned char ) cdpTerm->CharsLower[ i ]; - iDst = ( unsigned char ) cdpHost->CharsLower[ i ]; - hb_sln_inputTab[ iSrc ] = iDst; - } - } + for ( i = 0; i < 256; i++ ) + hb_sln_inputTab[ i ] = ( unsigned char ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); hb_sln_cdpIN = cdpTerm ? cdpTerm : cdpHost; #else HB_SYMBOL_UNUSED( cdpHost ); HB_SYMBOL_UNUSED( cdpTerm ); + for ( i = 0; i < 256; i++ ) + hb_sln_inputTab[ i ] = ( unsigned char ) i; #endif /* init national chars */ @@ -976,23 +953,22 @@ static BOOL hb_gt_sln_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) static BOOL hb_gt_sln_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char * pszHostCDP, BOOL fBox ) { + HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); + #ifndef HB_CDP_SUPPORT_OFF PHB_CODEPAGE cdpTerm = NULL, cdpHost = NULL; - cdpHost = hb_cdpFind( pszHostCDP ); - if ( pszHostCDP && *pszHostCDP ) + if ( pszHostCDP ) cdpHost = hb_cdpFind( pszHostCDP ); if ( ! cdpHost ) cdpHost = hb_vmCDP(); - if ( pszTermCDP && *pszTermCDP ) + if ( pszTermCDP ) cdpTerm = hb_cdpFind( pszTermCDP ); hb_sln_setCharTrans( cdpHost, cdpTerm, fBox ); #endif - HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); - return TRUE; } @@ -1000,23 +976,22 @@ static BOOL hb_gt_sln_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char static BOOL hb_gt_sln_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char * pszHostCDP ) { + HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); + #ifndef HB_CDP_SUPPORT_OFF PHB_CODEPAGE cdpTerm = NULL, cdpHost = NULL; - cdpHost = hb_cdpFind( pszHostCDP ); - if ( pszHostCDP && *pszHostCDP ) + if ( pszHostCDP ) cdpHost = hb_cdpFind( pszHostCDP ); if ( ! cdpHost ) cdpHost = hb_vmCDP(); - if ( pszTermCDP && *pszTermCDP ) + if ( pszTermCDP ) cdpTerm = hb_cdpFind( pszTermCDP ); hb_sln_setKeyTrans( cdpHost, cdpTerm ); #endif - HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); - return TRUE; } diff --git a/harbour/src/rtl/gtstd/gtstd.c b/harbour/src/rtl/gtstd/gtstd.c index 5891635ef9..1afcdc7af6 100644 --- a/harbour/src/rtl/gtstd/gtstd.c +++ b/harbour/src/rtl/gtstd/gtstd.c @@ -104,6 +104,8 @@ typedef struct _HB_GTSTD int iLineBufSize; char * sLineBuf; + ULONG ulTransBufSize; + char * sTransBuf; BOOL fFullRedraw; char * szCrLf; ULONG ulCrLf; @@ -174,19 +176,13 @@ static void sig_handler( int iSigNo ) #endif -static void hb_gt_std_setKeyTrans( PHB_GTSTD pGTSTD, char * pSrcChars, char * pDstChars ) +static void hb_gt_std_setKeyTrans( PHB_GTSTD pGTSTD, PHB_CODEPAGE cdpTerm, PHB_CODEPAGE cdpHost ) { int i; for( i = 0; i < 256; ++i ) - pGTSTD->keyTransTbl[ i ] = ( BYTE ) i; - - if( pSrcChars && pDstChars ) - { - BYTE c; - for( i = 0; i < 256 && ( c = ( BYTE ) pSrcChars[ i ] ) != 0; ++i ) - pGTSTD->keyTransTbl[ c ] = ( BYTE ) pDstChars[ i ]; - } + pGTSTD->keyTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); } static void hb_gt_std_termOut( PHB_GTSTD pGTSTD, const char * szStr, ULONG ulLen ) @@ -321,6 +317,8 @@ static void hb_gt_std_Exit( PHB_GT pGT ) #endif if( pGTSTD->iLineBufSize > 0 ) hb_xfree( pGTSTD->sLineBuf ); + if( pGTSTD->ulTransBufSize > 0 ) + hb_xfree( pGTSTD->sTransBuf ); if( pGTSTD->szCrLf ) hb_xfree( pGTSTD->szCrLf ); hb_xfree( pGTSTD ); @@ -547,11 +545,9 @@ static BOOL hb_gt_std_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char pGTSTD->cdpHost = hb_cdpFindExt( pszHostCDP ); pGTSTD->fDispTrans = pGTSTD->cdpTerm && pGTSTD->cdpHost && pGTSTD->cdpTerm != pGTSTD->cdpHost; - return TRUE; } #endif - - return FALSE; + return TRUE; } static BOOL hb_gt_std_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char *pszHostCDP ) @@ -566,34 +562,10 @@ static BOOL hb_gt_std_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char * if( !pszTermCDP ) pszTermCDP = pszHostCDP; - if( pszTermCDP && pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - char *pszHostLetters = ( char * ) hb_xgrab( cdpHost->nChars * 2 + 1 ); - char *pszTermLetters = ( char * ) hb_xgrab( cdpTerm->nChars * 2 + 1 ); - - hb_strncpy( pszHostLetters, cdpHost->CharsUpper, cdpHost->nChars * 2 ); - hb_strncat( pszHostLetters, cdpHost->CharsLower, cdpHost->nChars * 2 ); - hb_strncpy( pszTermLetters, cdpTerm->CharsUpper, cdpTerm->nChars * 2 ); - hb_strncat( pszTermLetters, cdpTerm->CharsLower, cdpTerm->nChars * 2 ); - - hb_gt_std_setKeyTrans( HB_GTSTD_GET( pGT ), pszTermLetters, pszHostLetters ); - - hb_xfree( pszHostLetters ); - hb_xfree( pszTermLetters ); - } - else - hb_gt_std_setKeyTrans( HB_GTSTD_GET( pGT ), NULL, NULL ); - - return TRUE; - } + hb_gt_std_setKeyTrans( HB_GTSTD_GET( pGT ), hb_cdpFind( pszTermCDP ), + hb_cdpFind( pszHostCDP ) ); #endif - - return FALSE; + return TRUE; } static void hb_gt_std_DispLine( PHB_GT pGT, int iRow ) @@ -616,7 +588,14 @@ static void hb_gt_std_DispLine( PHB_GT pGT, int iRow ) } hb_gt_std_newLine( pGTSTD ); if( iMin > 0 ) - hb_gt_std_termOut( pGTSTD, pGTSTD->sLineBuf, iMin ); + { + ULONG ulLen = iMin; + const char * buffer = hb_cdpnDup3( pGTSTD->sLineBuf, ulLen, + pGTSTD->sTransBuf, &ulLen, + &pGTSTD->sTransBuf, &pGTSTD->ulTransBufSize, + pGTSTD->cdpHost, pGTSTD->cdpTerm ); + hb_gt_std_termOut( pGTSTD, buffer, ulLen ); + } pGTSTD->iLastCol = pGTSTD->iCol = iMin; pGTSTD->iRow = iRow; } @@ -720,10 +699,11 @@ static void hb_gt_std_Redraw( PHB_GT pGT, int iRow, int iCol, int iSize ) if( pGTSTD->fDispTrans ) { ULONG ulLen = iLen; - char * buffer = hb_cdpnDup( pGTSTD->sLineBuf, &ulLen, - pGTSTD->cdpHost, pGTSTD->cdpTerm ); + const char * buffer = hb_cdpnDup3( pGTSTD->sLineBuf, ulLen, + pGTSTD->sTransBuf, &ulLen, + &pGTSTD->sTransBuf, &pGTSTD->ulTransBufSize, + pGTSTD->cdpHost, pGTSTD->cdpTerm ); hb_gt_std_termOut( pGTSTD, buffer, ulLen ); - hb_xfree( buffer ); } else #endif diff --git a/harbour/src/rtl/gttrm/gttrm.c b/harbour/src/rtl/gttrm/gttrm.c index c5b5718076..16dcacbac0 100644 --- a/harbour/src/rtl/gttrm/gttrm.c +++ b/harbour/src/rtl/gttrm/gttrm.c @@ -324,7 +324,6 @@ typedef struct _HB_GTTRM #ifndef HB_CDP_SUPPORT_OFF PHB_CODEPAGE cdpHost; - PHB_CODEPAGE cdpOut; PHB_CODEPAGE cdpBox; PHB_CODEPAGE cdpIn; #endif @@ -754,8 +753,9 @@ static void hb_gt_trm_termOutTrans( PHB_GTTRM pTerm, const char * pStr, int iLen } if( i > iLen ) i = iLen; - pTerm->iOutBufIndex += hb_cdpStrnToUTF8( cdp, TRUE, pStr, i, - pTerm->pOutBuf + pTerm->iOutBufIndex ); + pTerm->iOutBufIndex += hb_cdpStrToUTF8( cdp, TRUE, pStr, i, + pTerm->pOutBuf + pTerm->iOutBufIndex, + pTerm->iOutBufSize - pTerm->iOutBufIndex ); pStr += i; iLen -= i; } @@ -2229,26 +2229,21 @@ static void hb_gt_trm_ResetPalette( PHB_GTTRM pTerm ) } } -static void hb_gt_trm_SetKeyTrans( PHB_GTTRM pTerm, char * pSrcChars, char * pDstChars ) +static void hb_gt_trm_SetKeyTrans( PHB_GTTRM pTerm, PHB_CODEPAGE cdpTerm, PHB_CODEPAGE cdpHost ) { int i; - HB_TRACE(HB_TR_DEBUG, ("hb_gt_trm_SetKeyTrans(%p,%s,%s)", pTerm, pSrcChars, pDstChars)); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_trm_SetKeyTrans(%p,%p,%p)", pTerm, cdpTerm, cdpHost)); for( i = 0; i < 256; ++i ) - pTerm->keyTransTbl[ i ] = ( UCHAR ) i; + pTerm->keyTransTbl[ i ] = ( unsigned char ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); - if( pSrcChars && pDstChars ) - { - UCHAR c; - for( i = 0; i < 256 && ( c = ( UCHAR ) pSrcChars[ i ] ) != 0; ++i ) - pTerm->keyTransTbl[ c ] = ( UCHAR ) pDstChars[ i ]; - } + pTerm->cdpIn = cdpTerm; } -static void hb_gt_trm_SetDispTrans( PHB_GTTRM pTerm, char * src, char * dst, int box ) +static void hb_gt_trm_SetDispTrans( PHB_GTTRM pTerm, PHB_CODEPAGE cdpHost, PHB_CODEPAGE cdpTerm, int box ) { - unsigned char c, d; int i, ch, mode; memset( pTerm->chrattr, 0, sizeof( pTerm->chrattr ) ); @@ -2287,16 +2282,23 @@ static void hb_gt_trm_SetDispTrans( PHB_GTTRM pTerm, char * src, char * dst, int pTerm->boxattr[i] |= ch; } - if( src && dst ) + if( cdpHost && cdpTerm ) { - for( i = 0; i < 256 && ( c = ( unsigned char ) src[i] ) != 0; i++ ) + for( i = 0; i < 256; ++i ) { - d = ( unsigned char ) dst[i]; - pTerm->chrattr[c] = d | HB_GTTRM_ATTR_STD; - if( box ) - pTerm->boxattr[c] = d | HB_GTTRM_ATTR_STD; + if( hb_cdpIsAlpha( cdpHost, i ) ) + { + unsigned char uc = ( unsigned char ) + hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); + + pTerm->chrattr[i] = uc | HB_GTTRM_ATTR_STD; + if( box ) + pTerm->boxattr[i] = uc | HB_GTTRM_ATTR_STD; + } } } + pTerm->cdpHost = cdpHost; + pTerm->cdpBox = box ? cdpHost : hb_cdpFind( "EN" ); } static int addKeyMap( PHB_GTTRM pTerm, int nKey, const char *cdesc ) @@ -3051,7 +3053,7 @@ static void hb_gt_trm_SetTerm( PHB_GTTRM pTerm ) hb_gt_chrmapinit( pTerm->charmap, szTerm, pTerm->terminal_type == TERM_XTERM ); #ifndef HB_CDP_SUPPORT_OFF - pTerm->cdpHost = pTerm->cdpOut = pTerm->cdpIn = NULL; + pTerm->cdpHost = pTerm->cdpIn = NULL; pTerm->cdpBox = hb_cdpFind( "EN" ); #endif add_efds( pTerm, pTerm->hFilenoStdin, O_RDONLY, NULL, NULL ); @@ -3465,38 +3467,11 @@ static BOOL hb_gt_trm_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char if( !pszTermCDP ) pszTermCDP = pszHostCDP; - if( pszTermCDP && pszHostCDP ) - { - PHB_GTTRM pTerm = HB_GTTRM_GET( pGT ); - - pTerm->cdpOut = hb_cdpFind( pszTermCDP ); - pTerm->cdpHost = hb_cdpFind( pszHostCDP ); - if( fBox && pTerm->cdpHost ) - pTerm->cdpBox = pTerm->cdpHost; - - if( pTerm->cdpOut && pTerm->cdpHost && - pTerm->cdpHost->nChars && - pTerm->cdpHost->nChars == pTerm->cdpOut->nChars ) - { - int iChars = pTerm->cdpHost->nChars; - char *pszHostLetters = ( char * ) hb_xgrab( iChars * 2 + 1 ); - char *pszTermLetters = ( char * ) hb_xgrab( iChars * 2 + 1 ); - - memcpy( pszHostLetters, pTerm->cdpHost->CharsUpper, iChars ); - memcpy( pszHostLetters + iChars, pTerm->cdpHost->CharsLower, iChars + 1 ); - memcpy( pszTermLetters, pTerm->cdpOut->CharsUpper, iChars ); - memcpy( pszTermLetters + iChars, pTerm->cdpOut->CharsLower, iChars + 1 ); - - hb_gt_trm_SetDispTrans( pTerm, pszHostLetters, pszTermLetters, fBox ? 1 : 0 ); - - hb_xfree( pszHostLetters ); - hb_xfree( pszTermLetters ); - } - return TRUE; - } + hb_gt_trm_SetDispTrans( HB_GTTRM_GET( pGT ), hb_cdpFind( pszHostCDP ), + hb_cdpFind( pszTermCDP ), + fBox ? 1 : 0 ); #endif - - return FALSE; + return TRUE; } static BOOL hb_gt_trm_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char *pszHostCDP ) @@ -3511,39 +3486,10 @@ static BOOL hb_gt_trm_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char * if( !pszTermCDP ) pszTermCDP = pszHostCDP; - if( pszTermCDP && pszHostCDP ) - { - PHB_GTTRM pTerm = HB_GTTRM_GET( pGT ); - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - char *pszHostLetters = ( char * ) hb_xgrab( ( cdpHost->nChars << 1 ) + 1 ); - char *pszTermLetters = ( char * ) hb_xgrab( ( cdpTerm->nChars << 1 ) + 1 ); - - memcpy( pszHostLetters, cdpHost->CharsUpper, cdpHost->nChars ); - memcpy( pszHostLetters + cdpHost->nChars, cdpHost->CharsLower, cdpHost->nChars ); - pszHostLetters[ cdpHost->nChars << 1 ] = '\0'; - memcpy( pszTermLetters, cdpTerm->CharsUpper, cdpTerm->nChars ); - memcpy( pszTermLetters + cdpTerm->nChars, cdpTerm->CharsLower, cdpTerm->nChars ); - pszTermLetters[ cdpTerm->nChars << 1 ] = '\0'; - - hb_gt_trm_SetKeyTrans( pTerm, pszTermLetters, pszHostLetters ); - - hb_xfree( pszHostLetters ); - hb_xfree( pszTermLetters ); - } - else - hb_gt_trm_SetKeyTrans( pTerm, NULL, NULL ); - - pTerm->cdpIn = cdpTerm; - - return TRUE; - } + hb_gt_trm_SetKeyTrans( HB_GTTRM_GET( pGT ), hb_cdpFind( pszTermCDP ), + hb_cdpFind( pszHostCDP ) ); #endif - - return FALSE; + return TRUE; } static void hb_gt_trm_Redraw( PHB_GT pGT, int iRow, int iCol, int iSize ) diff --git a/harbour/src/rtl/gtwin/gtwin.c b/harbour/src/rtl/gtwin/gtwin.c index 6ffd1212fa..b548f5ca42 100644 --- a/harbour/src/rtl/gtwin/gtwin.c +++ b/harbour/src/rtl/gtwin/gtwin.c @@ -591,28 +591,29 @@ static void hb_gt_win_xGetScreenContents( PHB_GT pGT, SMALL_RECT * psrWin ) for( iCol = psrWin->Left; iCol <= psrWin->Right; ++iCol ) { #if defined( HB_CDP_SUPPORT_OFF ) - HB_GTSELF_PUTSCRCHAR( pGT, iRow, iCol, ( BYTE ) s_pCharInfoScreen[ i ].Attributes, 0, - ( BYTE ) s_pCharInfoScreen[ i ].Char.AsciiChar ); + HB_GTSELF_PUTSCRCHAR( pGT, iRow, iCol, ( UCHAR ) s_pCharInfoScreen[ i ].Attributes, 0, + ( UCHAR ) s_pCharInfoScreen[ i ].Char.AsciiChar ); #elif defined( UNICODE ) - USHORT uc = s_pCharInfoScreen[ i ].Char.UnicodeChar, u2; + HB_WCHAR wc = s_pCharInfoScreen[ i ].Char.UnicodeChar; + unsigned char uc; BYTE bAttr = 0; /* TODO: optimize it by creating conversion table - it can be * very slow in some cases */ - u2 = hb_cdpGetChar( s_cdpHost, FALSE, uc ); - if( u2 == '?' && uc >= 0x100 && s_cdpHost != s_cdpBox ) + uc = hb_cdpGetChar( s_cdpHost, FALSE, wc ); + if( uc == '?' && wc >= 0x100 && s_cdpHost != s_cdpBox ) { - u2 = hb_cdpGetChar( s_cdpBox, FALSE, uc ); - if( u2 != '?' ) + uc = hb_cdpGetChar( s_cdpBox, FALSE, wc ); + if( uc != '?' ) bAttr |= HB_GT_ATTR_BOX; } - HB_GTSELF_PUTSCRCHAR( pGT, iRow, iCol, ( BYTE ) s_pCharInfoScreen[ i ].Attributes, - bAttr, u2 ); + HB_GTSELF_PUTSCRCHAR( pGT, iRow, iCol, ( UCHAR ) s_pCharInfoScreen[ i ].Attributes, + bAttr, uc ); #else - HB_GTSELF_PUTSCRCHAR( pGT, iRow, iCol, ( BYTE ) s_pCharInfoScreen[ i ].Attributes, 0, - s_charTransRev[ ( BYTE ) s_pCharInfoScreen[ i ].Char.AsciiChar ] ); + HB_GTSELF_PUTSCRCHAR( pGT, iRow, iCol, ( UCHAR ) s_pCharInfoScreen[ i ].Attributes, 0, + s_charTransRev[ ( UCHAR ) s_pCharInfoScreen[ i ].Char.AsciiChar ] ); #endif ++i; } @@ -1488,56 +1489,47 @@ static BOOL hb_gt_win_SetDispCP( PHB_GT pGT, const char *pszTermCDP, const char HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * 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( !pszHostCDP ) pszHostCDP = hb_cdpID(); - if( pszHostCDP && *pszHostCDP ) + if( pszHostCDP ) { PHB_CODEPAGE cdpHost = hb_cdpFind( pszHostCDP ); if( cdpHost ) + { s_cdpHost = cdpHost; + s_cdpBox = fBox ? cdpHost : hb_cdpFind( "EN" ); + } } - -#else +# else { + PHB_CODEPAGE cdpTerm, cdpHost; int i; - for( i = 0; i < 256; i++ ) - s_charTrans[ i ] = ( BYTE ) i; - if( !pszHostCDP ) pszHostCDP = hb_cdpID(); - if( pszTermCDP && pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - for( i = 0; i < cdpHost->nChars; ++i ) - { - s_charTrans[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - s_charTrans[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } - } - } + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); for( i = 0; i < 256; i++ ) - s_charTransRev[ s_charTrans[ i ] ] = ( BYTE ) i; - + { + s_charTrans[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); + s_charTransRev[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, TRUE, cdpTerm, cdpHost ); + } } -#endif - +# endif #endif return TRUE; @@ -1553,8 +1545,7 @@ static BOOL hb_gt_win_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char * HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * We are receiving WM_CHAR events in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -1570,35 +1561,25 @@ static BOOL hb_gt_win_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char * s_cdpIn = cdpHost; } -#else +# else { + PHB_CODEPAGE cdpTerm, cdpHost; int i; - for( i = 0; i < 256; i++ ) - s_keyTrans[ i ] = ( BYTE ) i; - if( !pszHostCDP ) pszHostCDP = hb_cdpID(); - if( pszTermCDP && pszHostCDP ) - { - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - for( i = 0; i < cdpHost->nChars; ++i ) - { - s_keyTrans[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - s_keyTrans[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } - } - } - } -#endif + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + s_keyTrans[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); + } +# endif #endif return TRUE; diff --git a/harbour/src/rtl/gtwvt/gtwvt.c b/harbour/src/rtl/gtwvt/gtwvt.c index bafdc80a49..3904ce8b59 100644 --- a/harbour/src/rtl/gtwvt/gtwvt.c +++ b/harbour/src/rtl/gtwvt/gtwvt.c @@ -2958,8 +2958,7 @@ static BOOL hb_gt_wvt_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char HB_GTSUPER_SETDISPCP( pGT, pszTermCDP, pszHostCDP, fBox ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * We are displaying text in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -2972,41 +2971,35 @@ static BOOL hb_gt_wvt_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char { PHB_CODEPAGE cdpHost = hb_cdpFind( pszHostCDP ); if( cdpHost ) - HB_GTWVT_GET( pGT )->hostCDP = cdpHost; - } - -#else - - if( !pszHostCDP ) - pszHostCDP = hb_cdpID(); - if( !pszTermCDP ) - pszTermCDP = pszHostCDP; - - if( pszTermCDP && pszHostCDP ) - { - PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); - int i; - - for( i = 0; i < 256; ++i ) - pWVT->chrTransTbl[ i ] = ( BYTE ) i; - - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) { - for( i = 0; i < cdpHost->nChars; ++i ) - { - pWVT->chrTransTbl[ ( BYTE ) cdpHost->CharsUpper[ i ] ] = - ( BYTE ) cdpTerm->CharsUpper[ i ]; - pWVT->chrTransTbl[ ( BYTE ) cdpHost->CharsLower[ i ] ] = - ( BYTE ) cdpTerm->CharsLower[ i ]; - } + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + + pWVT->hostCDP = cdpHost; + pWVT->boxCDP = fBox ? cdpHost : hb_cdpFind( "EN" ); } } +# else + { + PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); + PHB_CODEPAGE cdpTerm, cdpHost; + int i; -#endif + if( !pszHostCDP ) + pszHostCDP = hb_cdpID(); + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + { + pWVT->chrTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, TRUE, cdpHost, cdpTerm ); + } + } +# endif #endif return TRUE; @@ -3017,8 +3010,7 @@ static BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); #ifndef HB_CDP_SUPPORT_OFF - -#if defined( UNICODE ) +# if defined( UNICODE ) /* * We are receiving WM_CHAR events in U16 so pszTermCDP is unimportant. * We only have to know what is the internal application codepage @@ -3033,40 +3025,27 @@ static BOOL hb_gt_wvt_SetKeyCP( PHB_GT pGT, const char * pszTermCDP, const char if( cdpHost ) HB_GTWVT_GET( pGT )->inCDP = cdpHost; } - -#else - - if( !pszHostCDP ) - pszHostCDP = hb_cdpID(); - if( !pszTermCDP ) - pszTermCDP = pszHostCDP; - - if( pszTermCDP && pszHostCDP ) +# else { PHB_GTWVT pWVT = HB_GTWVT_GET( pGT ); - PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), - cdpHost = hb_cdpFind( pszHostCDP ); + PHB_CODEPAGE cdpTerm, cdpHost; int i; - for( i = 0; i < 256; ++i ) - pWVT->keyTransTbl[ i ] = ( BYTE ) i; + if( !pszHostCDP ) + pszHostCDP = hb_cdpID(); - if( cdpTerm && cdpHost && cdpTerm != cdpHost && - cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) - { - for( i = 0; i < cdpHost->nChars; ++i ) - { - pWVT->keyTransTbl[ ( BYTE ) cdpTerm->CharsUpper[ i ] ] = - ( BYTE ) cdpHost->CharsUpper[ i ]; - pWVT->keyTransTbl[ ( BYTE ) cdpTerm->CharsLower[ i ] ] = - ( BYTE ) cdpHost->CharsLower[ i ]; - } - } + if( !pszTermCDP ) + pszTermCDP = pszHostCDP; + cdpTerm = hb_cdpFind( pszTermCDP ); + cdpHost = hb_cdpFind( pszHostCDP ); + + for( i = 0; i < 256; i++ ) + pWVT->keyTransTbl[ i ] = ( BYTE ) + hb_cdpTranslateChar( i, FALSE, cdpTerm, cdpHost ); pWVT->inCDP = cdpTerm; } -#endif - +# endif #endif return TRUE; diff --git a/harbour/src/rtl/gtxwc/gtxwc.c b/harbour/src/rtl/gtxwc/gtxwc.c index 155197b8ba..8e87732dd4 100644 --- a/harbour/src/rtl/gtxwc/gtxwc.c +++ b/harbour/src/rtl/gtxwc/gtxwc.c @@ -402,6 +402,8 @@ typedef struct tag_x_wnddef /* CodePage support */ PHB_CODEPAGE hostCDP; /* PHB_CODEPAGE outCDP; */ + PHB_CODEPAGE utf8CDP; + PHB_CODEPAGE boxCDP; PHB_CODEPAGE inCDP; /* current cursor and color settings */ @@ -2179,13 +2181,10 @@ static void hb_gt_xwc_WndProc( PXWND_DEF wnd, XEvent *evt ) #ifdef XWC_DEBUG printf( "UTF8String='%s'\r\n", text.value ); fflush(stdout); #endif - nItem = hb_cdpUTF8StringLength( ( const char * ) text.value, text.nitems ); - if( wnd->ClipboardData != NULL ) - hb_xfree( wnd->ClipboardData ); - wnd->ClipboardData = ( unsigned char * ) hb_xgrab( nItem + 1 ); - wnd->ClipboardSize = nItem; - hb_cdpUTF8ToStrn( wnd->hostCDP, FALSE, ( const char * ) text.value, text.nitems, - ( char * ) wnd->ClipboardData, nItem + 1 ); + wnd->ClipboardSize = text.nitems; + wnd->ClipboardData = ( unsigned char * ) + hb_cdpnDup( ( const char * ) text.value, &wnd->ClipboardSize, + wnd->utf8CDP, wnd->hostCDP ); wnd->ClipboardTime = evt->xselection.time; wnd->ClipboardRcvd = TRUE; } @@ -2202,8 +2201,8 @@ static void hb_gt_xwc_WndProc( PXWND_DEF wnd, XEvent *evt ) wnd->ClipboardSize = text.nitems; #ifndef HB_CDP_SUPPORT_OFF wnd->ClipboardData = ( unsigned char * ) - hb_cdpnDup( ( const char * ) text.value, &wnd->ClipboardSize, - wnd->inCDP, wnd->hostCDP ); + hb_cdpnDup( ( const char * ) text.value, &wnd->ClipboardSize, + wnd->inCDP, wnd->hostCDP ); #else wnd->ClipboardData = ( unsigned char * ) hb_xgrab( text.nitems + 1 ); memcpy( wnd->ClipboardData, text.value, text.nitems ); @@ -2281,7 +2280,9 @@ static void hb_gt_xwc_WndProc( PXWND_DEF wnd, XEvent *evt ) if( wnd->inCDP && wnd->hostCDP && wnd->inCDP != wnd->hostCDP ) { ULONG ulLen = wnd->ClipboardSize; - unsigned char * pBuffer = ( unsigned char * ) hb_cdpnDup( ( const char * ) wnd->ClipboardData, &ulLen, wnd->hostCDP, wnd->inCDP ); + unsigned char * pBuffer = ( unsigned char * ) + hb_cdpnDup( ( const char * ) wnd->ClipboardData, &ulLen, + wnd->hostCDP, wnd->inCDP ); XChangeProperty( wnd->dpy, req->requestor, req->property, s_atomString, 8, PropModeReplace, @@ -2299,10 +2300,11 @@ static void hb_gt_xwc_WndProc( PXWND_DEF wnd, XEvent *evt ) #ifndef HB_CDP_SUPPORT_OFF else if( req->target == s_atomUTF8String ) { - ULONG ulLen = hb_cdpStringInUTF8Length( wnd->hostCDP, FALSE, ( const char * ) wnd->ClipboardData, wnd->ClipboardSize ); - unsigned char * pBuffer = ( unsigned char * ) hb_xgrab( ulLen + 1 ); + ULONG ulLen = wnd->ClipboardSize; + unsigned char * pBuffer = ( unsigned char * ) + hb_cdpnDup( ( const char * ) wnd->ClipboardData, &ulLen, + wnd->hostCDP, wnd->utf8CDP ); - hb_cdpStrnToUTF8( wnd->hostCDP, FALSE, ( const char * ) wnd->ClipboardData, wnd->ClipboardSize, ( char * ) pBuffer ); #ifdef XWC_DEBUG printf( "SelectionRequest: (%s)->(%s) [%s]\r\n", wnd->ClipboardData, pBuffer, wnd->hostCDP->id ); fflush(stdout); #endif @@ -2967,11 +2969,8 @@ static void hb_gt_xwc_ProcessMessages( PXWND_DEF wnd ) { XTextProperty text; char * pBuffer; - ULONG ulLen; - ulLen = hb_cdpStringInUTF8Length( wnd->hostCDP, FALSE, wnd->szTitle, strlen( wnd->szTitle ) ); - pBuffer = ( char * ) hb_xgrab( ulLen + 1 ); - hb_cdpStrnToUTF8( wnd->hostCDP, FALSE, wnd->szTitle, strlen( wnd->szTitle ), pBuffer ); + pBuffer = hb_cdpDup( wnd->szTitle, wnd->hostCDP, wnd->utf8CDP ); text.value = ( unsigned char * ) pBuffer; text.encoding = s_atomUTF8String; text.format = 8; @@ -3137,6 +3136,8 @@ static PXWND_DEF hb_gt_xwc_CreateWndDef( PHB_GT pGT ) wnd->fWinResize = FALSE; #ifndef HB_CDP_SUPPORT_OFF wnd->hostCDP = hb_vmCDP(); + wnd->utf8CDP = hb_cdpFind( "UTF8" ); + wnd->boxCDP = hb_cdpFind( "EN" ); #endif wnd->cursorType = SC_NORMAL; @@ -3803,6 +3804,7 @@ static BOOL hb_gt_xwc_SetDispCP( PHB_GT pGT, const char * pszTermCDP, const char if( cdpHost && cdpHost != wnd->hostCDP ) { wnd->hostCDP = cdpHost; + wnd->boxCDP = fBox ? cdpHost : hb_cdpFind( "EN" ); if( wnd->fInit ) { HB_XWC_XLIB_LOCK diff --git a/harbour/src/rtl/strcase.c b/harbour/src/rtl/strcase.c index 7b551a9062..783805455a 100644 --- a/harbour/src/rtl/strcase.c +++ b/harbour/src/rtl/strcase.c @@ -53,73 +53,6 @@ #include "hbapi.h" #include "hbapiitm.h" #include "hbapierr.h" -#include "hbapicdp.h" - -/* converts szText to lower case. Does not create a new string! */ -char * hb_strLower( char * szText, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_strLower(%s, %lu)", szText, ulLen)); - - { - ULONG i; -#ifndef HB_CDP_SUPPORT_OFF - PHB_CODEPAGE cdp = hb_vmCDP(); - if( cdp && cdp->nChars ) - for( i = 0; i < ulLen; i++ ) - szText[ i ] = ( char ) cdp->s_lower[ ( UCHAR ) szText[ i ] ]; - else -#endif - for( i = 0; i < ulLen; i++ ) - szText[ i ] = HB_TOLOWER( szText[ i ] ); - } - - return szText; -} - -/* converts szText to upper case. Does not create a new string! */ -char * hb_strUpper( char * szText, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_strUpper(%s, %lu)", szText, ulLen)); - - { - ULONG i; -#ifndef HB_CDP_SUPPORT_OFF - PHB_CODEPAGE cdp = hb_vmCDP(); - if( cdp && cdp->nChars ) - for( i = 0; i < ulLen; i++ ) - szText[ i ] = ( char ) cdp->s_upper[ ( UCHAR ) szText[ i ] ]; - else -#endif - for( i = 0; i < ulLen; i++ ) - szText[ i ] = HB_TOUPPER( szText[ i ] ); - } - - return szText; -} - -/* converts iChar to lower case */ -int hb_charLower( int iChar ) -{ -#ifndef HB_CDP_SUPPORT_OFF - PHB_CODEPAGE cdp = hb_vmCDP(); - if( cdp && cdp->nChars ) - return ( unsigned char ) cdp->s_lower[ (unsigned char) iChar ]; - else -#endif - return HB_TOLOWER( iChar ); -} - -/* converts iChar to upper case */ -int hb_charUpper( int iChar ) -{ -#ifndef HB_CDP_SUPPORT_OFF - PHB_CODEPAGE cdp = hb_vmCDP(); - if( cdp && cdp->nChars ) - return ( unsigned char ) cdp->s_upper[ (unsigned char) iChar ]; - else -#endif - return HB_TOUPPER( iChar ); -} /* converts string to lower case */ HB_FUNC( LOWER )