Files
harbour-core/src/rtl/hbdef.c
Przemysław Czerpak bcfb15e873 2014-01-07 13:01 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* include/harbour.hbx
  * src/rtl/hbdef.c
    + added new PRG function hb_defaultValue(). It's similar to hb_default()
      but it returns expected value instead of setting 1-st parameter.
      New function can be used to replace code like:
         hb_default( @lParam, .T. )
         IF lParam
            [...]
         ENDIF
      with:
         IF hb_defaultValue( lParam, .T. )
            [...]
         ENDIF
      It's useful for two main reasons:
      1) we do not damage original parameter value
      2) if parameter is used only once then it's a little bit faster

  * contrib/hbfship/stroccur.prg
    ! do not generate error when wrong parameters are passed to StrOccurs()
      function (FS compatible behavior)
    ! set default value of 3-rd parameter in StrOccurs() to .T. only if it's not
      passed at all, otherwise set it to .F. (FS compatible behavior)
    % small simplification

  * src/compiler/hbmain.c
    ! extended code which resolves conflicts with multiple static
      functions with the same name compiled from different PRG modules
      into single object file to resolve conflicts also with external
      function calls. It should fix problem reported by Viktor.
2014-01-07 13:01:03 +01:00

135 lines
3.8 KiB
C

/*
* Harbour Project source code:
* hb_default() and __defaultNIL() functions
*
* Copyright 2012 Viktor Szakats (vszakats.net/harbour)
* 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.txt. 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, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour 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 Harbour 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 by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the 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 Harbour, 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"
typedef enum
{
HB_IT_U,
HB_IT_N,
HB_IT_C,
HB_IT_L,
HB_IT_T,
HB_IT_B,
HB_IT_H,
HB_IT_A,
HB_IT_O,
HB_IT_P,
HB_IT_S
} HB_IT_BASIC;
static HB_IT_BASIC s_hb_itemTypeBasic( PHB_ITEM pItem )
{
switch( HB_ITEM_TYPE( pItem ) )
{
case HB_IT_ARRAY:
return hb_arrayIsObject( pItem ) ? HB_IT_O : HB_IT_A;
case HB_IT_BLOCK:
return HB_IT_B;
case HB_IT_DATE:
case HB_IT_TIMESTAMP:
return HB_IT_T;
case HB_IT_LOGICAL:
return HB_IT_L;
case HB_IT_INTEGER:
case HB_IT_LONG:
case HB_IT_DOUBLE:
return HB_IT_N;
case HB_IT_STRING:
case HB_IT_MEMO:
return HB_IT_C;
case HB_IT_HASH:
return HB_IT_H;
case HB_IT_POINTER:
return HB_IT_P;
case HB_IT_SYMBOL:
return HB_IT_S;
}
return HB_IT_U;
}
HB_FUNC( HB_DEFAULT )
{
PHB_ITEM pDefault = hb_param( 2, HB_IT_ANY );
if( pDefault &&
s_hb_itemTypeBasic( hb_param( 1, HB_IT_ANY ) ) !=
s_hb_itemTypeBasic( pDefault ) )
hb_itemParamStore( 1, pDefault );
}
HB_FUNC( HB_DEFAULTVALUE )
{
PHB_ITEM pParam = hb_param( 1, HB_IT_ANY );
PHB_ITEM pDefault = hb_param( 2, HB_IT_ANY );
if( pDefault &&
s_hb_itemTypeBasic( pParam ) != s_hb_itemTypeBasic( pDefault ) )
pParam = pDefault;
hb_itemReturn( pParam );
}
/* For compatibility with legacy DEFAULT ... TO ... command.
Not recommended for new code. */
HB_FUNC( __DEFAULTNIL )
{
if( hb_pcount() >= 2 && HB_IS_NIL( hb_param( 1, HB_IT_ANY ) ) )
hb_itemParamStore( 1, hb_param( 2, HB_IT_ANY ) );
}