From fa7562e9920f8bb51d7f64d0f4b6eded781d86a6 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 27 Oct 2009 10:51:37 +0000 Subject: [PATCH] 2009-10-27 11:51 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/xhb/xhbarr.c + added XHB_AINS(), XHB_ADEL() functions which accept negative indexes. Warning I haven't replicated xHarbour bugs in AINS() so it's not exactly the same. Sooner or later someone will fix AINS() code in xHarbour CVS. This code illustrates the problem and also incompatibilities with Clipper: #ifdef __HARBOUR__ #ifndef __XHARBOUR__ #xtranslate adel() => xhb_adel() #xtranslate ains() => xhb_ains() #endif #endif proc main() local a := { 100, 200, 300 } ? ; aeval( a, { |x| qout( x ) } ) adel( a, -1, .t. ) ? ; aeval( a, { |x| qout( x ) } ) ains( a, -1, 400, .t. ) ? ; aeval( a, { |x| qout( x ) } ) ains( a ) ? ; aeval( a, { |x| qout( x ) } ) return --- harbour/ChangeLog | 24 +++++++++++++++ harbour/contrib/xhb/xhbarr.c | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e68706f7c2..d450caec3f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,30 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-10-27 11:51 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/xhb/xhbarr.c + + added XHB_AINS(), XHB_ADEL() functions which accept negative indexes. + Warning I haven't replicated xHarbour bugs in AINS() so it's not + exactly the same. Sooner or later someone will fix AINS() code in + xHarbour CVS. This code illustrates the problem and also + incompatibilities with Clipper: + #ifdef __HARBOUR__ + #ifndef __XHARBOUR__ + #xtranslate adel() => xhb_adel() + #xtranslate ains() => xhb_ains() + #endif + #endif + proc main() + local a := { 100, 200, 300 } + ? ; aeval( a, { |x| qout( x ) } ) + adel( a, -1, .t. ) + ? ; aeval( a, { |x| qout( x ) } ) + ains( a, -1, 400, .t. ) + ? ; aeval( a, { |x| qout( x ) } ) + ains( a ) + ? ; aeval( a, { |x| qout( x ) } ) + return + 2009-10-27 10:34 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapi.h * harbour/src/vm/garbage.c diff --git a/harbour/contrib/xhb/xhbarr.c b/harbour/contrib/xhb/xhbarr.c index 516bf9685c..7babd9e745 100644 --- a/harbour/contrib/xhb/xhbarr.c +++ b/harbour/contrib/xhb/xhbarr.c @@ -231,3 +231,60 @@ HB_FUNC( AMERGE ) hb_errRT_BASE( EG_ARG, 1003, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } } + +HB_FUNC( XHB_ADEL ) +{ + PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY ); + + if( pArray ) + { + long lPos = hb_parnl( 2 ); + + if( lPos == 0 ) + lPos = 1; + else if( lPos < 0 ) + lPos += hb_arrayLen( pArray ) + 1; + + if( hb_arrayDel( pArray, lPos ) ) + { + if( hb_parl( 3 ) ) + hb_arraySize( pArray, hb_arrayLen( pArray ) - 1 ); + } + + hb_itemReturn( pArray ); /* ADel() returns the array itself */ + } +} + +HB_FUNC( XHB_AINS ) +{ + PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY ); + + if( pArray ) + { + long lPos = hb_parnl( 2 ); + + + if( hb_parl( 4 ) ) + { + ULONG ulLen = hb_arrayLen( pArray ) + 1; + if( lPos == 0 ) + lPos = 1; + else if( lPos < 0 ) + lPos += ulLen + 1; + if( lPos >= 1 && ( ULONG ) lPos <= ulLen ) + hb_arraySize( pArray, ulLen ); + } + else if( lPos == 0 ) + lPos = 1; + else if( lPos < 0 ) + lPos += hb_arrayLen( pArray ) + 1; + + if( hb_arrayIns( pArray, lPos ) ) + { + if( ! HB_ISNIL( 3 ) ) + hb_arraySet( pArray, lPos, hb_param( 3, HB_IT_ANY ) ); + } + + hb_itemReturn( pArray ); /* AIns() returns the array itself */ + } +}