From 46d64612b53626ad5f31a2f30e1091265eddca4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Thu, 22 Aug 2013 19:06:06 +0200 Subject: [PATCH] 2013-08-22 19:06 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbct/getsecrt.prg ! applied Clipper compatibility fix to GetSecret() by Pavel Tsarenko * src/common/hbdate.c * removed explicit _BSD_SOURCE definition - it was confusing our code used to detect localtime_r() support and is not necessary if we do not use extended fields of tm structure * src/rtl/mtran.c * updated to show strict Clipper compatible behavior - Clipper ignores 3-rd cSoftCR parameter if 2-nd one cHardCR is not given (strict compatibility is covered by HB_CLP_STRICT macro and disabled by default - undocumented feature which may confuse users) % minor optimization --- ChangeLog.txt | 17 +++++++++++++++++ contrib/hbct/getsecrt.prg | 11 ++++++++++- src/common/hbdate.c | 2 -- src/rtl/mtran.c | 40 ++++++++++++++++++++++++++------------- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 8a1d3efaa4..c6df70b73e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,23 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-08-22 19:06 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbct/getsecrt.prg + ! applied Clipper compatibility fix to GetSecret() by Pavel Tsarenko + + * src/common/hbdate.c + * removed explicit _BSD_SOURCE definition - it was confusing our + code used to detect localtime_r() support and is not necessary + if we do not use extended fields of tm structure + + * src/rtl/mtran.c + * updated to show strict Clipper compatible behavior - Clipper + ignores 3-rd cSoftCR parameter if 2-nd one cHardCR is not given + (strict compatibility is covered by HB_CLP_STRICT macro and + disabled by default - undocumented feature which may confuse + users) + % minor optimization + 2013-08-20 17:32 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/gtqtc/gtqtc1.cpp * accept META key as CTRL key in MacOSX builds. diff --git a/contrib/hbct/getsecrt.prg b/contrib/hbct/getsecrt.prg index 68ec258c5e..7397d195d4 100644 --- a/contrib/hbct/getsecrt.prg +++ b/contrib/hbct/getsecrt.prg @@ -51,6 +51,7 @@ #include "getexit.ch" #include "setcurs.ch" +#include "inkey.ch" FUNCTION GetSecret( cVar, nRow, nCol, lSay, xPrompt ) @@ -136,10 +137,18 @@ STATIC PROCEDURE _SECRET( _cGetSecret, lHide, oGet, oGetList ) oGetList:ReadVar() ) lHide := .T. LOOP + ELSEIF nKey == K_BS + IF oGet:pos > 1 + _cGetSecret := Padr( Left( _cGetSecret, oGet:pos - 2 ) + ; + Substr( _cGetSecret, oGet:pos ), nLen ) + ENDIF + ELSEIF nKey == K_DEL + _cGetSecret := Padr( Left( _cGetSecret, oGet:pos - 1 ) + ; + Substr( _cGetSecret, oGet:pos + 1 ), nLen ) ELSEIF ! ( cKey := hb_keyChar( nKey ) ) == "" IF Set( _SET_INSERT ) _cGetSecret := Stuff( Left( _cGetSecret, nLen - 1 ), ; - oGet:pos, 0, cKey ) + oGet:pos, 0, cKey ) ELSE _cGetSecret := Stuff( _cGetSecret, oGet:pos, 1, cKey ) ENDIF diff --git a/src/common/hbdate.c b/src/common/hbdate.c index f333625107..ed00c4c0e8 100644 --- a/src/common/hbdate.c +++ b/src/common/hbdate.c @@ -66,8 +66,6 @@ * */ -#define _BSD_SOURCE - #include "hbapi.h" #include "hbdate.h" #if defined( HB_LONG_LONG_OFF ) diff --git a/src/rtl/mtran.c b/src/rtl/mtran.c index 5043845015..0b1263749e 100644 --- a/src/rtl/mtran.c +++ b/src/rtl/mtran.c @@ -51,25 +51,25 @@ /* NOTE: pszResult must have an allocated buffer of at least nStringLen */ -static char * hb_strMemotran( char * pszResult, HB_SIZE * pnResultLen, const char * pszString, HB_SIZE nStringLen, char cHardcr, char cSoftcr ) +HB_SIZE hb_strMemotran( char * pszResult, const char * pszString, HB_SIZE nStringLen, char cHardCR, char cSoftCR ) { HB_SIZE nStringPos = 0; HB_SIZE nResultPos = 0; - HB_TRACE( HB_TR_DEBUG, ( "hb_strMemotran(%p, %p, %s, %" HB_PFS "u, %x, %x)", pszResult, pnResultLen, pszString, nStringLen, cHardcr, cSoftcr ) ); + HB_TRACE( HB_TR_DEBUG, ( "hb_strMemotran(%p, %p, %s, %" HB_PFS "u, %x, %x)", pszResult, pnResultLen, pszString, nStringLen, cHardCR, cSoftCR ) ); while( nStringPos < nStringLen ) { if( pszString[ nStringPos ] == HB_CHAR_HARD1 && pszString[ nStringPos + 1 ] == HB_CHAR_HARD2 ) { - pszResult[ nResultPos++ ] = cHardcr; + pszResult[ nResultPos++ ] = cHardCR; nStringPos += 2; } else if( pszString[ nStringPos ] == HB_CHAR_SOFT1 && pszString[ nStringPos + 1 ] == HB_CHAR_SOFT2 ) { - pszResult[ nResultPos++ ] = cSoftcr; + pszResult[ nResultPos++ ] = cSoftCR; nStringPos += 2; } else @@ -78,9 +78,7 @@ static char * hb_strMemotran( char * pszResult, HB_SIZE * pnResultLen, const cha pszResult[ nResultPos ] = '\0'; - *pnResultLen = nResultPos; - - return pszResult; + return nResultPos; } HB_FUNC( MEMOTRAN ) @@ -89,13 +87,29 @@ HB_FUNC( MEMOTRAN ) if( pString ) { - char * pszResult = ( char * ) hb_xgrab( hb_itemGetCLen( pString ) + 1 ); - char cHardcr = HB_ISCHAR( 2 ) ? *hb_parc( 2 ) : ';'; - char cSoftcr = HB_ISCHAR( 3 ) ? *hb_parc( 3 ) : ' '; - HB_SIZE nResultLen; + HB_SIZE nLen = hb_itemGetCLen( pString ); + char * pszResult = ( char * ) hb_xgrab( nLen + 1 ); + const char * pszRepl; + char cHardCR = ';'; + char cSoftCR = ' '; - hb_strMemotran( pszResult, &nResultLen, hb_itemGetCPtr( pString ), hb_itemGetCLen( pString ), cHardcr, cSoftcr ); - hb_retclen_buffer( pszResult, nResultLen ); + pszRepl = hb_parc( 2 ); + if( pszRepl ) + cHardCR = *pszRepl; + + /* CA-Cl*pper checks 3-rd cSoftCR parameter only + * if 2-nd one cHardCR is specified [druzus] + */ +#ifdef HB_CLP_STRICT + if( pszRepl ) +#endif + pszRepl = hb_parc( 3 ); + if( pszRepl ) + cSoftCR = *pszRepl; + + nLen = hb_strMemotran( pszResult, hb_itemGetCPtr( pString ), nLen, + cHardCR, cSoftCR ); + hb_retclen_buffer( pszResult, nLen ); } else hb_retc_null();