From e853a90f084e6f8de0111d32515dedb31a40ee3a Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 1 Oct 2012 21:48:26 +0000 Subject: [PATCH] 2012-10-01 23:48 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/src/pp/ppcore.c ! fixed possible GPF when some broken expressions are used as part of extended expression match marker * harbour/src/rtl/padr.c * harbour/src/rtl/padc.c * harbour/src/rtl/padl.c ! fixed PADR(), PADL() and PADC() to accept pad mulibyte characters when CPs with such encoding is used, i.e. CP950 or UTF8EX * harbour/contrib/xhb/xhb.hbx * updated to follow recent modifications --- harbour/ChangeLog | 14 ++++++++++ harbour/contrib/xhb/xhb.hbx | 2 +- harbour/src/pp/ppcore.c | 10 ++----- harbour/src/rtl/padc.c | 54 +++++++++++++++++++++++++++++++------ harbour/src/rtl/padl.c | 42 +++++++++++++++++++++++++---- harbour/src/rtl/padr.c | 41 ++++++++++++++++++++++++---- 6 files changed, 136 insertions(+), 27 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bcb05b8b18..c5e2834b54 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,20 @@ The license applies to all entries newer than 2009-04-28. */ +2012-10-01 23:48 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/src/pp/ppcore.c + ! fixed possible GPF when some broken expressions are used as + part of extended expression match marker + + * harbour/src/rtl/padr.c + * harbour/src/rtl/padc.c + * harbour/src/rtl/padl.c + ! fixed PADR(), PADL() and PADC() to accept pad mulibyte characters + when CPs with such encoding is used, i.e. CP950 or UTF8EX + + * harbour/contrib/xhb/xhb.hbx + * updated to follow recent modifications + 2012-10-01 22:23 UTC+0200 Viktor Szakats (harbour syenar.net) * include/box.ch * include/button.ch diff --git a/harbour/contrib/xhb/xhb.hbx b/harbour/contrib/xhb/xhb.hbx index 45c8ab5a47..1cba4b6951 100644 --- a/harbour/contrib/xhb/xhb.hbx +++ b/harbour/contrib/xhb/xhb.hbx @@ -112,7 +112,7 @@ DYNAMIC HB_BACKGROUNDRESET DYNAMIC HB_BACKGROUNDRUN DYNAMIC HB_BACKGROUNDRUNFORCED DYNAMIC HB_BACKGROUNDTIME -DYNAMIC HB_BITTEST +DYNAMIC HB_BITISSET DYNAMIC HB_BLDLOGMSG DYNAMIC HB_BUILDINFO DYNAMIC HB_CHECKSUM diff --git a/harbour/src/pp/ppcore.c b/harbour/src/pp/ppcore.c index 910f39ef83..054c31fb3a 100644 --- a/harbour/src/pp/ppcore.c +++ b/harbour/src/pp/ppcore.c @@ -3664,8 +3664,8 @@ static HB_BOOL hb_pp_tokenSkipExp( PHB_PP_TOKEN * pTokenPtr, PHB_PP_TOKEN pStop, pToken = pPrev; } - if( HB_PP_TOKEN_ISEOC( pToken ) && - ( mode != HB_PP_CMP_ADDR || pToken == pStop ) ) + if( mode == HB_PP_CMP_ADDR ? pToken == pStop : + HB_PP_TOKEN_ISEOC( pToken ) ) { if( pfStop ) * pfStop = HB_TRUE; @@ -3679,12 +3679,6 @@ static HB_BOOL hb_pp_tokenSkipExp( PHB_PP_TOKEN * pTokenPtr, PHB_PP_TOKEN pStop, else if( curtype == rbrtype ) --iBraces; } - else if( mode == HB_PP_CMP_ADDR && pToken == pStop ) - { - if( pfStop ) - * pfStop = HB_TRUE; - break; - } else if( curtype == HB_PP_TOKEN_COMMA ) { if( pfStop ) diff --git a/harbour/src/rtl/padc.c b/harbour/src/rtl/padc.c index 2c844302f1..c552f5ad17 100644 --- a/harbour/src/rtl/padc.c +++ b/harbour/src/rtl/padc.c @@ -63,6 +63,22 @@ static HB_SIZE hb_cdpItemLen( PHB_CODEPAGE cdp, PHB_ITEM pItem ) hb_cdpTextLen( cdp, hb_itemGetCPtr( pItem ), nLen ) : nLen; } +static const char * s_hb_padGet( PHB_CODEPAGE cdp, HB_SIZE * pnPad ) +{ + const char * szPad = hb_parc( 3 ); + + *pnPad = 1; + if( szPad == NULL ) + szPad = " "; + else if( HB_CDP_ISCHARIDX( cdp ) ) + { + *pnPad = hb_cdpTextPos( cdp, szPad, hb_parclen( 3 ), 1 ); + if( *pnPad == 0 ) + szPad = ""; + } + return szPad; +} + /* centre-pads a date, number, or string with spaces or supplied character */ HB_FUNC( PADC ) { @@ -95,15 +111,37 @@ HB_FUNC( PADC ) if( ( HB_SIZE ) nLen > nSize ) { - char * szResult = ( char * ) hb_xgrab( nLen + 1 ); - char cPad; - HB_ISIZ nPad = ( ( HB_SIZE ) nLen - nSize ) >> 1; + HB_SIZE nPad = 0; + const char * szPad = s_hb_padGet( cdp, &nPad ); + char * szResult; - cPad = ( HB_ISCHAR( 3 ) ? *( hb_parc( 3 ) ) : ' ' ); - hb_xmemset( szResult, cPad, nPad ); - hb_xmemcpy( szResult + nPad, szText, nSize ); - hb_xmemset( szResult + nPad + nSize, cPad, - ( HB_SIZE ) nLen - nSize - nPad ); + if( nPad > 1 ) + { + HB_SIZE nRep = ( ( HB_SIZE ) nLen - nSize ) >> 1, nPos = 0; + nLen += ( nLen - nSize ) * ( nPad - 1 ); + szResult = ( char * ) hb_xgrab( nLen + 1 ); + while( nRep-- ) + { + hb_xmemcpy( szResult + nPos, szPad, nPad ); + nPos += nPad; + } + hb_xmemcpy( szResult + nPos, szText, nSize ); + nSize += nPos; + while( nSize < ( HB_SIZE ) nLen ) + { + hb_xmemcpy( szResult + nSize, szPad, nPad ); + nSize += nPad; + } + } + else + { + szResult = ( char * ) hb_xgrab( nLen + 1 ); + nPad = ( ( HB_SIZE ) nLen - nSize ) >> 1; + hb_xmemset( szResult, szPad[ 0 ], nPad ); + hb_xmemcpy( szResult + nPad, szText, nSize ); + hb_xmemset( szResult + nPad + nSize, szPad[ 0 ], + ( HB_SIZE ) nLen - nSize - nPad ); + } hb_retclen_buffer( szResult, ( HB_SIZE ) nLen ); if( bFreeReq ) diff --git a/harbour/src/rtl/padl.c b/harbour/src/rtl/padl.c index f16606d303..c27b7a5bce 100644 --- a/harbour/src/rtl/padl.c +++ b/harbour/src/rtl/padl.c @@ -63,6 +63,22 @@ static HB_SIZE hb_cdpItemLen( PHB_CODEPAGE cdp, PHB_ITEM pItem ) hb_cdpTextLen( cdp, hb_itemGetCPtr( pItem ), nLen ) : nLen; } +static const char * s_hb_padGet( PHB_CODEPAGE cdp, HB_SIZE * pnPad ) +{ + const char * szPad = hb_parc( 3 ); + + *pnPad = 1; + if( szPad == NULL ) + szPad = " "; + else if( HB_CDP_ISCHARIDX( cdp ) ) + { + *pnPad = hb_cdpTextPos( cdp, szPad, hb_parclen( 3 ), 1 ); + if( *pnPad == 0 ) + szPad = ""; + } + return szPad; +} + /* left-pads a date, number, or string with spaces or supplied character */ HB_FUNC( PADL ) { @@ -95,12 +111,28 @@ HB_FUNC( PADL ) if( ( HB_SIZE ) nLen > nSize ) { - char * szResult = ( char * ) hb_xgrab( nLen + 1 ); - char cPad; + HB_SIZE nPad = 0; + const char * szPad = s_hb_padGet( cdp, &nPad ); + char * szResult; - cPad = ( HB_ISCHAR( 3 ) ? *( hb_parc( 3 ) ) : ' ' ); - hb_xmemset( szResult, cPad, ( HB_SIZE ) nLen - nSize ); - hb_xmemcpy( szResult + ( HB_SIZE ) nLen - nSize, szText, nSize ); + if( nPad > 1 ) + { + HB_SIZE nRep = ( ( HB_SIZE ) nLen - nSize ), nPos = 0; + nLen += nRep * ( nPad - 1 ); + szResult = ( char * ) hb_xgrab( nLen + 1 ); + while( nRep-- ) + { + hb_xmemcpy( szResult + nPos, szPad, nPad ); + nPos += nPad; + } + hb_xmemcpy( szResult + nPos, szText, nSize ); + } + else + { + szResult = ( char * ) hb_xgrab( nLen + 1 ); + hb_xmemset( szResult, szPad[ 0 ], ( HB_SIZE ) nLen - nSize ); + hb_xmemcpy( szResult + ( HB_SIZE ) nLen - nSize, szText, nSize ); + } hb_retclen_buffer( szResult, ( HB_SIZE ) nLen ); if( bFreeReq ) diff --git a/harbour/src/rtl/padr.c b/harbour/src/rtl/padr.c index 670afabf62..b6569540f6 100644 --- a/harbour/src/rtl/padr.c +++ b/harbour/src/rtl/padr.c @@ -63,6 +63,22 @@ static HB_SIZE hb_cdpItemLen( PHB_CODEPAGE cdp, PHB_ITEM pItem ) hb_cdpTextLen( cdp, hb_itemGetCPtr( pItem ), nLen ) : nLen; } +static const char * s_hb_padGet( PHB_CODEPAGE cdp, HB_SIZE * pnPad ) +{ + const char * szPad = hb_parc( 3 ); + + *pnPad = 1; + if( szPad == NULL ) + szPad = " "; + else if( HB_CDP_ISCHARIDX( cdp ) ) + { + *pnPad = hb_cdpTextPos( cdp, szPad, hb_parclen( 3 ), 1 ); + if( *pnPad == 0 ) + szPad = ""; + } + return szPad; +} + /* right-pads a date, number, or string with spaces or supplied character */ HB_FUNC( PADR ) { @@ -95,12 +111,27 @@ HB_FUNC( PADR ) if( ( HB_SIZE ) nLen > nSize ) { - char * szResult = ( char * ) hb_xgrab( nLen + 1 ); - char cPad; + HB_SIZE nPad = 0; + const char * szPad = s_hb_padGet( cdp, &nPad ); + char * szResult; - cPad = ( HB_ISCHAR( 3 ) ? *( hb_parc( 3 ) ) : ' ' ); - hb_xmemcpy( szResult, szText, nSize ); - hb_xmemset( szResult + nSize, cPad, ( HB_SIZE ) nLen - nSize ); + if( nPad > 1 ) + { + nLen += ( nLen - nSize ) * ( nPad - 1 ); + szResult = ( char * ) hb_xgrab( nLen + 1 ); + hb_xmemcpy( szResult, szText, nSize ); + while( nSize < ( HB_SIZE ) nLen ) + { + hb_xmemcpy( szResult + nSize, szPad, nPad ); + nSize += nPad; + } + } + else + { + szResult = ( char * ) hb_xgrab( nLen + 1 ); + hb_xmemcpy( szResult, szText, nSize ); + hb_xmemset( szResult + nSize, szPad[ 0 ], ( HB_SIZE ) nLen - nSize ); + } hb_retclen_buffer( szResult, ( HB_SIZE ) nLen ); if( bFreeReq )