From a73bbdb1e3b4c61978afd2ab199de6ab0c689b4a Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 8 Nov 2010 11:21:00 +0000 Subject: [PATCH] 2010-11-08 12:20 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/xhb/xhb.hbp * harbour/contrib/xhb/xhb.hbx + harbour/contrib/xhb/xhbarrex.c + added ASIZEALLOC(), ALENALLOC() xHarbour functions In Harbour they are in practice useless because we are using dynamic array preallocation not static one as in xHarbour. * harbour/doc/xhb-diff.txt + added information about HB_ARRAYTOPARAMS() function --- harbour/ChangeLog | 11 +++++ harbour/contrib/xhb/xhb.hbp | 1 + harbour/contrib/xhb/xhb.hbx | 2 + harbour/contrib/xhb/xhbarrex.c | 82 ++++++++++++++++++++++++++++++++++ harbour/doc/xhb-diff.txt | 39 +++++++++++++--- 5 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 harbour/contrib/xhb/xhbarrex.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7e8cd2552a..bc760d5fb0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,17 @@ The license applies to all entries newer than 2009-04-28. */ +2010-11-08 12:20 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/xhb/xhb.hbp + * harbour/contrib/xhb/xhb.hbx + + harbour/contrib/xhb/xhbarrex.c + + added ASIZEALLOC(), ALENALLOC() xHarbour functions + In Harbour they are in practice useless because we are using + dynamic array preallocation not static one as in xHarbour. + + * harbour/doc/xhb-diff.txt + + added information about HB_ARRAYTOPARAMS() function + 2010-11-08 11:17 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/hbqt_hbmk2_plugin.hbs ! Do not apply HB_QTPOSTFIX to rcc tool. diff --git a/harbour/contrib/xhb/xhb.hbp b/harbour/contrib/xhb/xhb.hbp index f1f4e22c4c..d33220bc7b 100644 --- a/harbour/contrib/xhb/xhb.hbp +++ b/harbour/contrib/xhb/xhb.hbp @@ -36,6 +36,7 @@ hbsyslog.c hbxml.c txtline.c xhbarr.c +xhbarrex.c xhbat.c xhbcopyf.c xhbdate.c diff --git a/harbour/contrib/xhb/xhb.hbx b/harbour/contrib/xhb/xhb.hbx index 731ff3744d..a7a227b3ca 100644 --- a/harbour/contrib/xhb/xhb.hbx +++ b/harbour/contrib/xhb/xhb.hbx @@ -26,9 +26,11 @@ #command DYNAMIC => EXTERNAL #endif +DYNAMIC ALENALLOC DYNAMIC AMERGE DYNAMIC ANY2STR DYNAMIC AREMOVE +DYNAMIC ASIZEALLOC DYNAMIC ASPLICE DYNAMIC ATI DYNAMIC ATSKIPSTRINGS diff --git a/harbour/contrib/xhb/xhbarrex.c b/harbour/contrib/xhb/xhbarrex.c new file mode 100644 index 0000000000..56c95ea73c --- /dev/null +++ b/harbour/contrib/xhb/xhbarrex.c @@ -0,0 +1,82 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * xHarbour compatible ASIZEALLOC(), ALENALLOC() function + * + * Copyright 2010 Przemyslaw Czerpak + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, xHarbour license gives permission for + * additional uses of the text contained in its release of xHarbour. + * + * The exception is that, if you link the xHarbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the xHarbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released with this xHarbour + * explicit exception. If you add/copy code from other sources, + * as the General Public License permits, the above exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for xHarbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" + +/* ASIZEALLOC( , ) -> - Set the pre-alloc step. */ +HB_FUNC( ASIZEALLOC ) +{ + PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY ); + PHB_ITEM pPreAlloc = hb_param( 2, HB_IT_NUMERIC ); + + if( pArray && pPreAlloc ) + { + /* do nothing Harbour uses dynamically updated preallocation size */ + hb_itemReturn( pArray ); + } +} + +/* ALENALLOC( ) -> - Get the pre-alloc step. */ +HB_FUNC( ALENALLOC ) +{ + PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY ); + + if( pArray ) + { + /* Harbour uses dynamically updated preallocation size + * let's approximate some value + */ + HB_SIZE nLen = hb_arrayLen( pArray ); + nLen = ( nLen >> 1 ) + 1; + hb_retns( nLen ); + } +} diff --git a/harbour/doc/xhb-diff.txt b/harbour/doc/xhb-diff.txt index 34e671c3d5..77774f3aff 100644 --- a/harbour/doc/xhb-diff.txt +++ b/harbour/doc/xhb-diff.txt @@ -314,7 +314,7 @@ In xHarbour the behavior of references stored in array is reverted in comparison to Clipper or Harbour. In Clipper and Harbour VM executing code like: aVal[ 1 ] := 100 -clears unconditionally 1-st item in aVal array and assign to it value 100. +clears unconditionally 1-st item in aVal array and assigns to it value 100. xHarbour checks if aVal[ 1 ] is an reference and in such case it resolves the reference and then assign 100 to the destination item. On access Clipper and Harbour VM executing code like: @@ -337,12 +337,12 @@ It can be seen in code like: x3 := aParams[ 3 ] x1 := lower( x1 ) + "1" - x2 := lower( x1 ) + "2" - x3 := lower( x1 ) + "3" + x2 := lower( x2 ) + "2" + x3 := lower( x3 ) + "3" Harbour and Clipper shows: A B C - a1 B a13 + a1 B c3 but xHarbour: A B C A B C @@ -391,7 +391,7 @@ Compiled by Harbour above code shows: abc klm xyz 123 456 789 abc [1] xyz 123 [2] 789 -In xHarbour only passing array items by reference work but do not work +In xHarbour only passing array items by reference works but does not work passing hash items by reference though it does not generate either compile time or run time errors so the above code can be compiled and executed but it shows: @@ -598,6 +598,35 @@ Harbour where item references stored in arrays work like in Clipper. +### HB_ARRAYTOPARAMS() FUNCTION ### +========================================= +Harbour has special function which allows to convert array into +list of items which can be used as function parameters, array +values or array indexes in the same way as '...' operator: + hb_arrayToParams( ) -> [ 1 ] [, [ N ] ] +i.e.: + proc main( ... ) + local aParams := hb_aParams(), n + /* remove parameters starting with "--" */ + n := 1 + while n < len( aParams ) + if left( aParams[ n ], 2 ) == "--" + hb_adel( aParams, n, .t. ) + else + ++n + endif + enddo + ? "Public parameters:", hb_arrayToParams( aParams ) + return + +Note for Clipper users: 'hb_adel( aParams, n, .t. )' in above example +works like 'adel( aParams, n ); asize( aParams, len( aParams ) - 1 )'. + +This functionality is unique to Harbour and xHarbour does not supports +hb_arrayToParams() or similar function. + + + ### MACRO MESSAGES ### ============================ Both compilers Harbour and xHarbour supports macros as messages.