LCOV - code coverage report
Current view: top level - basic/source/runtime - methods1.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 1490 2.3 %
Date: 2012-08-25 Functions: 8 104 7.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 20 2741 0.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <stdlib.h> // getenv
      22                 :            : #include <vcl/svapp.hxx>
      23                 :            : #include <vcl/mapmod.hxx>
      24                 :            : #include <vcl/wrkwin.hxx>
      25                 :            : #include <vcl/timer.hxx>
      26                 :            : #include <basic/sbxvar.hxx>
      27                 :            : #include <basic/sbx.hxx>
      28                 :            : #include <svl/zforlist.hxx>
      29                 :            : #include <tools/fsys.hxx>
      30                 :            : #include <tools/urlobj.hxx>
      31                 :            : #include <osl/file.hxx>
      32                 :            : #include <vcl/jobset.hxx>
      33                 :            : #include <basic/sbobjmod.hxx>
      34                 :            : 
      35                 :            : #include "sbintern.hxx"
      36                 :            : #include "runtime.hxx"
      37                 :            : #include "stdobj.hxx"
      38                 :            : #include "rtlproto.hxx"
      39                 :            : #include "dllmgr.hxx"
      40                 :            : #include <iosys.hxx>
      41                 :            : #include "sbunoobj.hxx"
      42                 :            : #include "propacc.hxx"
      43                 :            : 
      44                 :            : 
      45                 :            : #include <comphelper/processfactory.hxx>
      46                 :            : #include <comphelper/string.hxx>
      47                 :            : 
      48                 :            : #include <com/sun/star/uno/Sequence.hxx>
      49                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      50                 :            : #include <com/sun/star/i18n/XCalendar3.hpp>
      51                 :            : #include <com/sun/star/sheet/XFunctionAccess.hpp>
      52                 :            : 
      53                 :            : using namespace comphelper;
      54                 :            : using namespace com::sun::star::sheet;
      55                 :            : using namespace com::sun::star::uno;
      56                 :            : using namespace com::sun::star::i18n;
      57                 :            : 
      58                 :            : void unoToSbxValue( SbxVariable* pVar, const Any& aValue );
      59                 :            : Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, com::sun::star::beans::Property* pUnoProperty = NULL );
      60                 :            : sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam = false, sal_Int16 nFirstDay = 0 );
      61                 :            : 
      62                 :          0 : static Reference< XCalendar3 > getLocaleCalendar( void )
      63                 :            : {
      64 [ #  # ][ #  # ]:          0 :     static Reference< XCalendar3 > xCalendar;
      65         [ #  # ]:          0 :     if( !xCalendar.is() )
      66                 :            :     {
      67         [ #  # ]:          0 :         Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
      68         [ #  # ]:          0 :         if( xSMgr.is() )
      69                 :            :         {
      70         [ #  # ]:          0 :             xCalendar = Reference< XCalendar3 >( xSMgr->createInstance
      71 [ #  # ][ #  # ]:          0 :                 ( ::rtl::OUString("com.sun.star.i18n.LocaleCalendar" ) ), UNO_QUERY );
                 [ #  # ]
      72                 :          0 :         }
      73                 :            :     }
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 :     static com::sun::star::lang::Locale aLastLocale;
      76                 :            :     static bool bNeedsInit = true;
      77                 :            : 
      78 [ #  # ][ #  # ]:          0 :     com::sun::star::lang::Locale aLocale = Application::GetSettings().GetLocale();
      79                 :          0 :     bool bNeedsReload = false;
      80         [ #  # ]:          0 :     if( bNeedsInit )
      81                 :            :     {
      82                 :          0 :         bNeedsInit = false;
      83                 :          0 :         bNeedsReload = true;
      84                 :            :     }
      85   [ #  #  #  # ]:          0 :     else if( aLocale.Language != aLastLocale.Language ||
                 [ #  # ]
      86                 :          0 :              aLocale.Country  != aLastLocale.Country )
      87                 :            :     {
      88                 :          0 :         bNeedsReload = true;
      89                 :            :     }
      90         [ #  # ]:          0 :     if( bNeedsReload )
      91                 :            :     {
      92                 :          0 :         aLastLocale = aLocale;
      93 [ #  # ][ #  # ]:          0 :         xCalendar->loadDefaultCalendar( aLocale );
      94                 :            :     }
      95                 :          0 :     return xCalendar;
      96                 :            : }
      97                 :            : 
      98                 :            : #ifndef DISABLE_SCRIPTING
      99                 :            : 
     100                 :          0 : RTLFUNC(CallByName)
     101                 :            : {
     102                 :            :     (void)pBasic;
     103                 :            :     (void)bWrite;
     104                 :            : 
     105                 :          0 :     const sal_Int16 vbGet       = 2;
     106                 :          0 :     const sal_Int16 vbLet       = 4;
     107                 :          0 :     const sal_Int16 vbMethod    = 1;
     108                 :          0 :     const sal_Int16 vbSet       = 8;
     109                 :            : 
     110                 :            :     // At least 3 parameter needed plus function itself -> 4
     111         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
     112         [ #  # ]:          0 :     if ( nParCount < 4 )
     113                 :            :     {
     114         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     115                 :            :         return;
     116                 :            :     }
     117                 :            : 
     118                 :            :     // 1. parameter is object
     119 [ #  # ][ #  # ]:          0 :     SbxBase* pObjVar = (SbxObject*)rPar.Get(1)->GetObject();
     120                 :          0 :     SbxObject* pObj = NULL;
     121         [ #  # ]:          0 :     if( pObjVar )
     122 [ #  # ][ #  # ]:          0 :         pObj = PTR_CAST(SbxObject,pObjVar);
         [ #  # ][ #  # ]
     123 [ #  # ][ #  # ]:          0 :     if( !pObj && pObjVar && pObjVar->ISA(SbxVariable) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     124                 :            :     {
     125         [ #  # ]:          0 :         SbxBase* pObjVarObj = ((SbxVariable*)pObjVar)->GetObject();
     126 [ #  # ][ #  # ]:          0 :         pObj = PTR_CAST(SbxObject,pObjVarObj);
         [ #  # ][ #  # ]
     127                 :            :     }
     128         [ #  # ]:          0 :     if( !pObj )
     129                 :            :     {
     130         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_PARAMETER );
     131                 :            :         return;
     132                 :            :     }
     133                 :            : 
     134                 :            :     // 2. parameter is ProcedureName
     135 [ #  # ][ #  # ]:          0 :     String aNameStr = rPar.Get(2)->GetString();
                 [ #  # ]
     136                 :            : 
     137                 :            :     // 3. parameter is CallType
     138 [ #  # ][ #  # ]:          0 :     sal_Int16 nCallType = rPar.Get(3)->GetInteger();
     139                 :            : 
     140                 :            :     //SbxObject* pFindObj = NULL;
     141 [ #  # ][ #  # ]:          0 :     SbxVariable* pFindVar = pObj->Find( aNameStr, SbxCLASS_DONTCARE );
     142         [ #  # ]:          0 :     if( pFindVar == NULL )
     143                 :            :     {
     144         [ #  # ]:          0 :         StarBASIC::Error( SbERR_PROC_UNDEFINED );
     145                 :            :         return;
     146                 :            :     }
     147                 :            : 
     148   [ #  #  #  # ]:          0 :     switch( nCallType )
     149                 :            :     {
     150                 :            :         case vbGet:
     151                 :            :             {
     152                 :          0 :                 SbxValues aVals;
     153                 :          0 :                 aVals.eType = SbxVARIANT;
     154         [ #  # ]:          0 :                 pFindVar->Get( aVals );
     155                 :            : 
     156         [ #  # ]:          0 :                 SbxVariableRef refVar = rPar.Get(0);
     157 [ #  # ][ #  # ]:          0 :                 refVar->Put( aVals );
     158                 :            :             }
     159                 :          0 :             break;
     160                 :            :         case vbLet:
     161                 :            :         case vbSet:
     162                 :            :             {
     163         [ #  # ]:          0 :                 if ( nParCount != 5 )
     164                 :            :                 {
     165         [ #  # ]:          0 :                     StarBASIC::Error( SbERR_BAD_ARGUMENT );
     166                 :            :                     return;
     167                 :            :                 }
     168         [ #  # ]:          0 :                 SbxVariableRef pValVar = rPar.Get(4);
     169         [ #  # ]:          0 :                 if( nCallType == vbLet )
     170                 :            :                 {
     171                 :          0 :                     SbxValues aVals;
     172                 :          0 :                     aVals.eType = SbxVARIANT;
     173         [ #  # ]:          0 :                     pValVar->Get( aVals );
     174         [ #  # ]:          0 :                     pFindVar->Put( aVals );
     175                 :            :                 }
     176                 :            :                 else
     177                 :            :                 {
     178                 :          0 :                     SbxVariableRef rFindVar = pFindVar;
     179         [ #  # ]:          0 :                     SbiInstance* pInst = GetSbData()->pInst;
     180         [ #  # ]:          0 :                     SbiRuntime* pRT = pInst ? pInst->pRun : NULL;
     181         [ #  # ]:          0 :                     if( pRT != NULL )
     182 [ #  # ][ #  # ]:          0 :                         pRT->StepSET_Impl( pValVar, rFindVar, false );
     183         [ #  # ]:          0 :                 }
     184                 :            :             }
     185                 :          0 :             break;
     186                 :            :         case vbMethod:
     187                 :            :             {
     188 [ #  # ][ #  # ]:          0 :                 SbMethod* pMeth = PTR_CAST(SbMethod,pFindVar);
         [ #  # ][ #  # ]
     189         [ #  # ]:          0 :                 if( pMeth == NULL )
     190                 :            :                 {
     191         [ #  # ]:          0 :                     StarBASIC::Error( SbERR_PROC_UNDEFINED );
     192                 :            :                     return;
     193                 :            :                 }
     194                 :            : 
     195                 :            :                 // Setup parameters
     196                 :          0 :                 SbxArrayRef xArray;
     197                 :          0 :                 sal_uInt16 nMethParamCount = nParCount - 4;
     198         [ #  # ]:          0 :                 if( nMethParamCount > 0 )
     199                 :            :                 {
     200 [ #  # ][ #  # ]:          0 :                     xArray = new SbxArray;
                 [ #  # ]
     201         [ #  # ]:          0 :                     for( sal_uInt16 i = 0 ; i < nMethParamCount ; i++ )
     202                 :            :                     {
     203         [ #  # ]:          0 :                         SbxVariable* pPar = rPar.Get( i + 4 );
     204         [ #  # ]:          0 :                         xArray->Put( pPar, i + 1 );
     205                 :            :                     }
     206                 :            :                 }
     207                 :            : 
     208                 :            :                 // Call method
     209         [ #  # ]:          0 :                 SbxVariableRef refVar = rPar.Get(0);
     210         [ #  # ]:          0 :                 if( xArray.Is() )
     211         [ #  # ]:          0 :                     pMeth->SetParameters( xArray );
     212         [ #  # ]:          0 :                 pMeth->Call( refVar );
     213 [ #  # ][ #  # ]:          0 :                 pMeth->SetParameters( NULL );
                 [ #  # ]
     214                 :            :             }
     215                 :          0 :             break;
     216                 :            :         default:
     217         [ #  # ]:          0 :             StarBASIC::Error( SbERR_PROC_UNDEFINED );
     218 [ #  # ][ #  # ]:          0 :     }
     219                 :            : }
     220                 :            : 
     221                 :          0 : RTLFUNC(CBool) // JSM
     222                 :            : {
     223                 :            :     (void)pBasic;
     224                 :            :     (void)bWrite;
     225                 :            : 
     226                 :          0 :     sal_Bool bVal = sal_False;
     227         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     228                 :            :     {
     229                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     230                 :          0 :         bVal = pSbxVariable->GetBool();
     231                 :            :     }
     232                 :            :     else
     233                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     234                 :            : 
     235                 :          0 :     rPar.Get(0)->PutBool(bVal);
     236                 :          0 : }
     237                 :            : 
     238                 :          0 : RTLFUNC(CByte) // JSM
     239                 :            : {
     240                 :            :     (void)pBasic;
     241                 :            :     (void)bWrite;
     242                 :            : 
     243                 :          0 :     sal_uInt8 nByte = 0;
     244         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     245                 :            :     {
     246                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     247                 :          0 :         nByte = pSbxVariable->GetByte();
     248                 :            :     }
     249                 :            :     else
     250                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     251                 :            : 
     252                 :          0 :     rPar.Get(0)->PutByte(nByte);
     253                 :          0 : }
     254                 :            : 
     255                 :          0 : RTLFUNC(CCur)
     256                 :            : {
     257                 :            :     (void)pBasic;
     258                 :            :     (void)bWrite;
     259                 :            : 
     260                 :          0 :     sal_Int64 nCur = 0;
     261 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() == 2 )
     262                 :            :     {
     263         [ #  # ]:          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     264         [ #  # ]:          0 :         nCur = pSbxVariable->GetCurrency();
     265                 :            :     }
     266                 :            :     else
     267         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     268                 :            : 
     269 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutCurrency( nCur );
     270                 :          0 : }
     271                 :            : 
     272                 :          0 : RTLFUNC(CDec)
     273                 :            : {
     274                 :            :     (void)pBasic;
     275                 :            :     (void)bWrite;
     276                 :            : 
     277                 :            : #ifdef WNT
     278                 :            :     SbxDecimal* pDec = NULL;
     279                 :            :     if ( rPar.Count() == 2 )
     280                 :            :     {
     281                 :            :         SbxVariable *pSbxVariable = rPar.Get(1);
     282                 :            :         pDec = pSbxVariable->GetDecimal();
     283                 :            :     }
     284                 :            :     else
     285                 :            :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     286                 :            : 
     287                 :            :     rPar.Get(0)->PutDecimal( pDec );
     288                 :            : #else
     289                 :          0 :     rPar.Get(0)->PutEmpty();
     290                 :          0 :     StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
     291                 :            : #endif
     292                 :          0 : }
     293                 :            : 
     294                 :          0 : RTLFUNC(CDate) // JSM
     295                 :            : {
     296                 :            :     (void)pBasic;
     297                 :            :     (void)bWrite;
     298                 :            : 
     299                 :          0 :     double nVal = 0.0;
     300         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     301                 :            :     {
     302                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     303                 :          0 :         nVal = pSbxVariable->GetDate();
     304                 :            :     }
     305                 :            :     else
     306                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     307                 :            : 
     308                 :          0 :     rPar.Get(0)->PutDate(nVal);
     309                 :          0 : }
     310                 :            : 
     311                 :          0 : RTLFUNC(CDbl)  // JSM
     312                 :            : {
     313                 :            :     (void)pBasic;
     314                 :            :     (void)bWrite;
     315                 :            : 
     316                 :          0 :     double nVal = 0.0;
     317 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() == 2 )
     318                 :            :     {
     319         [ #  # ]:          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     320 [ #  # ][ #  # ]:          0 :         if( pSbxVariable->GetType() == SbxSTRING )
     321                 :            :         {
     322                 :            :             // #41690
     323 [ #  # ][ #  # ]:          0 :             String aScanStr = pSbxVariable->GetString();
     324         [ #  # ]:          0 :             SbError Error = SbxValue::ScanNumIntnl( aScanStr, nVal );
     325         [ #  # ]:          0 :             if( Error != SbxERR_OK )
     326 [ #  # ][ #  # ]:          0 :                 StarBASIC::Error( Error );
     327                 :            :         }
     328                 :            :         else
     329                 :            :         {
     330         [ #  # ]:          0 :             nVal = pSbxVariable->GetDouble();
     331                 :            :         }
     332                 :            :     }
     333                 :            :     else
     334         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     335                 :            : 
     336 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutDouble(nVal);
     337                 :          0 : }
     338                 :            : 
     339                 :          0 : RTLFUNC(CInt)  // JSM
     340                 :            : {
     341                 :            :     (void)pBasic;
     342                 :            :     (void)bWrite;
     343                 :            : 
     344                 :          0 :     sal_Int16 nVal = 0;
     345         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     346                 :            :     {
     347                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     348                 :          0 :         nVal = pSbxVariable->GetInteger();
     349                 :            :     }
     350                 :            :     else
     351                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     352                 :            : 
     353                 :          0 :     rPar.Get(0)->PutInteger(nVal);
     354                 :          0 : }
     355                 :            : 
     356                 :          0 : RTLFUNC(CLng)  // JSM
     357                 :            : {
     358                 :            :     (void)pBasic;
     359                 :            :     (void)bWrite;
     360                 :            : 
     361                 :          0 :     sal_Int32 nVal = 0;
     362         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     363                 :            :     {
     364                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     365                 :          0 :         nVal = pSbxVariable->GetLong();
     366                 :            :     }
     367                 :            :     else
     368                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     369                 :            : 
     370                 :          0 :     rPar.Get(0)->PutLong(nVal);
     371                 :          0 : }
     372                 :            : 
     373                 :          0 : RTLFUNC(CSng)  // JSM
     374                 :            : {
     375                 :            :     (void)pBasic;
     376                 :            :     (void)bWrite;
     377                 :            : 
     378                 :          0 :     float nVal = (float)0.0;
     379         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     380                 :            :     {
     381                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     382         [ #  # ]:          0 :         if( pSbxVariable->GetType() == SbxSTRING )
     383                 :            :         {
     384                 :            :             // #41690
     385                 :          0 :             double dVal = 0.0;
     386 [ #  # ][ #  # ]:          0 :             String aScanStr = pSbxVariable->GetString();
     387         [ #  # ]:          0 :             SbError Error = SbxValue::ScanNumIntnl( aScanStr, dVal, /*bSingle=*/sal_True );
     388 [ #  # ][ #  # ]:          0 :             if( SbxBase::GetError() == SbxERR_OK && Error != SbxERR_OK )
         [ #  # ][ #  # ]
     389         [ #  # ]:          0 :                 StarBASIC::Error( Error );
     390         [ #  # ]:          0 :             nVal = (float)dVal;
     391                 :            :         }
     392                 :            :         else
     393                 :            :         {
     394                 :          0 :             nVal = pSbxVariable->GetSingle();
     395                 :            :         }
     396                 :            :     }
     397                 :            :     else
     398                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     399                 :            : 
     400                 :          0 :     rPar.Get(0)->PutSingle(nVal);
     401                 :          0 : }
     402                 :            : 
     403                 :          0 : RTLFUNC(CStr)  // JSM
     404                 :            : {
     405                 :            :     (void)pBasic;
     406                 :            :     (void)bWrite;
     407                 :            : 
     408         [ #  # ]:          0 :     String aString;
     409 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() == 2 )
     410                 :            :     {
     411         [ #  # ]:          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     412 [ #  # ][ #  # ]:          0 :         aString = pSbxVariable->GetString();
     413                 :            :     }
     414                 :            :     else
     415         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     416                 :            : 
     417 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString(aString);
         [ #  # ][ #  # ]
     418                 :          0 : }
     419                 :            : 
     420                 :          0 : RTLFUNC(CVar)  // JSM
     421                 :            : {
     422                 :            :     (void)pBasic;
     423                 :            :     (void)bWrite;
     424                 :            : 
     425                 :          0 :     SbxValues aVals( SbxVARIANT );
     426 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() == 2 )
     427                 :            :     {
     428         [ #  # ]:          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     429         [ #  # ]:          0 :         pSbxVariable->Get( aVals );
     430                 :            :     }
     431                 :            :     else
     432         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     433                 :            : 
     434 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->Put( aVals );
     435                 :          0 : }
     436                 :            : 
     437                 :          0 : RTLFUNC(CVErr)
     438                 :            : {
     439                 :            :     (void)pBasic;
     440                 :            :     (void)bWrite;
     441                 :            : 
     442                 :          0 :     sal_Int16 nErrCode = 0;
     443         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
     444                 :            :     {
     445                 :          0 :         SbxVariable *pSbxVariable = rPar.Get(1);
     446                 :          0 :         nErrCode = pSbxVariable->GetInteger();
     447                 :            :     }
     448                 :            :     else
     449                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     450                 :            : 
     451                 :          0 :     rPar.Get(0)->PutErr( nErrCode );
     452                 :          0 : }
     453                 :            : 
     454                 :          0 : RTLFUNC(Iif) // JSM
     455                 :            : {
     456                 :            :     (void)pBasic;
     457                 :            :     (void)bWrite;
     458                 :            : 
     459         [ #  # ]:          0 :     if ( rPar.Count() == 4 )
     460                 :            :     {
     461         [ #  # ]:          0 :         if (rPar.Get(1)->GetBool())
     462                 :          0 :             *rPar.Get(0) = *rPar.Get(2);
     463                 :            :         else
     464                 :          0 :             *rPar.Get(0) = *rPar.Get(3);
     465                 :            :     }
     466                 :            :     else
     467                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     468                 :          0 : }
     469                 :            : 
     470                 :          0 : RTLFUNC(GetSystemType)
     471                 :            : {
     472                 :            :     (void)pBasic;
     473                 :            :     (void)bWrite;
     474                 :            : 
     475         [ #  # ]:          0 :     if ( rPar.Count() != 1 )
     476                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     477                 :            :     else
     478                 :            :         // Removed for SRC595
     479                 :          0 :         rPar.Get(0)->PutInteger( -1 );
     480                 :          0 : }
     481                 :            : 
     482                 :          0 : RTLFUNC(GetGUIType)
     483                 :            : {
     484                 :            :     (void)pBasic;
     485                 :            :     (void)bWrite;
     486                 :            : 
     487         [ #  # ]:          0 :     if ( rPar.Count() != 1 )
     488                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     489                 :            :     else
     490                 :            :     {
     491                 :            :         // 17.7.2000 Make simple solution for testtool / fat office
     492                 :            : #if defined (WNT)
     493                 :            :         rPar.Get(0)->PutInteger( 1 );
     494                 :            : #elif defined UNX
     495                 :          0 :         rPar.Get(0)->PutInteger( 4 );
     496                 :            : #else
     497                 :            :         rPar.Get(0)->PutInteger( -1 );
     498                 :            : #endif
     499                 :            :     }
     500                 :          0 : }
     501                 :            : 
     502                 :          0 : RTLFUNC(Red)
     503                 :            : {
     504                 :            :     (void)pBasic;
     505                 :            :     (void)bWrite;
     506                 :            : 
     507         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
     508                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     509                 :            :     else
     510                 :            :     {
     511                 :          0 :         sal_uIntPtr nRGB = (sal_uIntPtr)rPar.Get(1)->GetLong();
     512                 :          0 :         nRGB &= 0x00FF0000;
     513                 :          0 :         nRGB >>= 16;
     514                 :          0 :         rPar.Get(0)->PutInteger( (sal_Int16)nRGB );
     515                 :            :     }
     516                 :          0 : }
     517                 :            : 
     518                 :          0 : RTLFUNC(Green)
     519                 :            : {
     520                 :            :     (void)pBasic;
     521                 :            :     (void)bWrite;
     522                 :            : 
     523         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
     524                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     525                 :            :     else
     526                 :            :     {
     527                 :          0 :         sal_uIntPtr nRGB = (sal_uIntPtr)rPar.Get(1)->GetLong();
     528                 :          0 :         nRGB &= 0x0000FF00;
     529                 :          0 :         nRGB >>= 8;
     530                 :          0 :         rPar.Get(0)->PutInteger( (sal_Int16)nRGB );
     531                 :            :     }
     532                 :          0 : }
     533                 :            : 
     534                 :          0 : RTLFUNC(Blue)
     535                 :            : {
     536                 :            :     (void)pBasic;
     537                 :            :     (void)bWrite;
     538                 :            : 
     539         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
     540                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     541                 :            :     else
     542                 :            :     {
     543                 :          0 :         sal_uIntPtr nRGB = (sal_uIntPtr)rPar.Get(1)->GetLong();
     544                 :          0 :         nRGB &= 0x000000FF;
     545                 :          0 :         rPar.Get(0)->PutInteger( (sal_Int16)nRGB );
     546                 :            :     }
     547                 :          0 : }
     548                 :            : 
     549                 :            : 
     550                 :          0 : RTLFUNC(Switch)
     551                 :            : {
     552                 :            :     (void)pBasic;
     553                 :            :     (void)bWrite;
     554                 :            : 
     555                 :          0 :     sal_uInt16 nCount = rPar.Count();
     556         [ #  # ]:          0 :     if( !(nCount & 0x0001 ))
     557                 :            :         // number of arguments must be odd
     558                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     559                 :          0 :     sal_uInt16 nCurExpr = 1;
     560         [ #  # ]:          0 :     while( nCurExpr < (nCount-1) )
     561                 :            :     {
     562         [ #  # ]:          0 :         if( rPar.Get( nCurExpr )->GetBool())
     563                 :            :         {
     564                 :          0 :             (*rPar.Get(0)) = *(rPar.Get(nCurExpr+1));
     565                 :          0 :             return;
     566                 :            :         }
     567                 :          0 :         nCurExpr += 2;
     568                 :            :     }
     569                 :          0 :     rPar.Get(0)->PutNull();
     570                 :            : }
     571                 :            : 
     572                 :            : //i#64882# Common wait impl for existing Wait and new WaitUntil
     573                 :            : // rtl functions
     574                 :          0 : void Wait_Impl( bool bDurationBased, SbxArray& rPar )
     575                 :            : {
     576 [ #  # ][ #  # ]:          0 :     if( rPar.Count() != 2 )
     577                 :            :     {
     578         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     579                 :            :         return;
     580                 :            :     }
     581                 :          0 :     long nWait = 0;
     582         [ #  # ]:          0 :     if ( bDurationBased )
     583                 :            :     {
     584 [ #  # ][ #  # ]:          0 :         double dWait = rPar.Get(1)->GetDouble();
     585         [ #  # ]:          0 :         double dNow = Now_Impl();
     586                 :          0 :          double dSecs = (double)( ( dWait - dNow ) * (double)( 24.0*3600.0) );
     587                 :          0 :         nWait = (long)( dSecs * 1000 ); // wait in thousands of sec
     588                 :            :     }
     589                 :            :     else
     590 [ #  # ][ #  # ]:          0 :         nWait = rPar.Get(1)->GetLong();
     591         [ #  # ]:          0 :     if( nWait < 0 )
     592                 :            :     {
     593         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     594                 :            :         return;
     595                 :            :     }
     596                 :            : 
     597         [ #  # ]:          0 :     Timer aTimer;
     598         [ #  # ]:          0 :     aTimer.SetTimeout( nWait );
     599         [ #  # ]:          0 :     aTimer.Start();
     600         [ #  # ]:          0 :     while ( aTimer.IsActive() )
     601 [ #  # ][ #  # ]:          0 :         Application::Yield();
     602                 :            : }
     603                 :            : 
     604                 :            : //i#64882#
     605                 :          0 : RTLFUNC(Wait)
     606                 :            : {
     607                 :            :     (void)pBasic;
     608                 :            :     (void)bWrite;
     609                 :          0 :     Wait_Impl( false, rPar );
     610                 :          0 : }
     611                 :            : 
     612                 :            : //i#64882# add new WaitUntil ( for application.wait )
     613                 :            : // share wait_impl with 'normal' oobasic wait
     614                 :          0 : RTLFUNC(WaitUntil)
     615                 :            : {
     616                 :            :     (void)pBasic;
     617                 :            :     (void)bWrite;
     618                 :          0 :     Wait_Impl( true, rPar );
     619                 :          0 : }
     620                 :            : 
     621                 :          0 : RTLFUNC(DoEvents)
     622                 :            : {
     623                 :            :     (void)pBasic;
     624                 :            :     (void)bWrite;
     625                 :            :     (void)rPar;
     626                 :            : // don't undstand what upstream are up to
     627                 :            : // we already process application events etc. in between
     628                 :            : // basic runtime pcode ( on a timed basis )
     629                 :            :     // always return 0
     630                 :          0 :     rPar.Get(0)->PutInteger( 0 );
     631                 :          0 :     Application::Reschedule( true );
     632                 :          0 : }
     633                 :            : 
     634                 :          0 : RTLFUNC(GetGUIVersion)
     635                 :            : {
     636                 :            :     (void)pBasic;
     637                 :            :     (void)bWrite;
     638                 :            : 
     639         [ #  # ]:          0 :     if ( rPar.Count() != 1 )
     640                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     641                 :            :     else
     642                 :            :     {
     643                 :            :         // Removed for SRC595
     644                 :          0 :         rPar.Get(0)->PutLong( -1 );
     645                 :            :     }
     646                 :          0 : }
     647                 :            : 
     648                 :          0 : RTLFUNC(Choose)
     649                 :            : {
     650                 :            :     (void)pBasic;
     651                 :            :     (void)bWrite;
     652                 :            : 
     653         [ #  # ]:          0 :     if ( rPar.Count() < 2 )
     654                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     655                 :          0 :     sal_Int16 nIndex = rPar.Get(1)->GetInteger();
     656                 :          0 :     sal_uInt16 nCount = rPar.Count();
     657                 :          0 :     nCount--;
     658 [ #  # ][ #  # ]:          0 :     if( nCount == 1 || nIndex > (nCount-1) || nIndex < 1 )
                 [ #  # ]
     659                 :            :     {
     660                 :          0 :         rPar.Get(0)->PutNull();
     661                 :          0 :         return;
     662                 :            :     }
     663                 :          0 :     (*rPar.Get(0)) = *(rPar.Get(nIndex+1));
     664                 :            : }
     665                 :            : 
     666                 :            : 
     667                 :          0 : RTLFUNC(Trim)
     668                 :            : {
     669                 :            :     (void)pBasic;
     670                 :            :     (void)bWrite;
     671                 :            : 
     672         [ #  # ]:          0 :     if ( rPar.Count() < 2 )
     673                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     674                 :            :     else
     675                 :            :     {
     676 [ #  # ][ #  # ]:          0 :         rtl::OUString aStr(comphelper::string::strip(rPar.Get(1)->GetString(), ' '));
         [ #  # ][ #  # ]
     677 [ #  # ][ #  # ]:          0 :         rPar.Get(0)->PutString(aStr);
     678                 :            :     }
     679                 :          0 : }
     680                 :            : 
     681                 :          0 : RTLFUNC(GetSolarVersion)
     682                 :            : {
     683                 :            :     (void)pBasic;
     684                 :            :     (void)bWrite;
     685                 :            : 
     686                 :          0 :     rPar.Get(0)->PutLong( (sal_Int32)SUPD );
     687                 :          0 : }
     688                 :            : 
     689                 :          0 : RTLFUNC(TwipsPerPixelX)
     690                 :            : {
     691                 :            :     (void)pBasic;
     692                 :            :     (void)bWrite;
     693                 :            : 
     694                 :          0 :     sal_Int32 nResult = 0;
     695                 :          0 :     Size aSize( 100,0 );
     696         [ #  # ]:          0 :     MapMode aMap( MAP_TWIP );
     697         [ #  # ]:          0 :     OutputDevice* pDevice = Application::GetDefaultDevice();
     698         [ #  # ]:          0 :     if( pDevice )
     699                 :            :     {
     700         [ #  # ]:          0 :         aSize = pDevice->PixelToLogic( aSize, aMap );
     701                 :          0 :         nResult = aSize.Width() / 100;
     702                 :            :     }
     703 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutLong( nResult );
                 [ #  # ]
     704                 :          0 : }
     705                 :            : 
     706                 :          0 : RTLFUNC(TwipsPerPixelY)
     707                 :            : {
     708                 :            :     (void)pBasic;
     709                 :            :     (void)bWrite;
     710                 :            : 
     711                 :          0 :     sal_Int32 nResult = 0;
     712                 :          0 :     Size aSize( 0,100 );
     713         [ #  # ]:          0 :     MapMode aMap( MAP_TWIP );
     714         [ #  # ]:          0 :     OutputDevice* pDevice = Application::GetDefaultDevice();
     715         [ #  # ]:          0 :     if( pDevice )
     716                 :            :     {
     717         [ #  # ]:          0 :         aSize = pDevice->PixelToLogic( aSize, aMap );
     718                 :          0 :         nResult = aSize.Height() / 100;
     719                 :            :     }
     720 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutLong( nResult );
                 [ #  # ]
     721                 :          0 : }
     722                 :            : 
     723                 :            : 
     724                 :          0 : RTLFUNC(FreeLibrary)
     725                 :            : {
     726                 :            :     (void)pBasic;
     727                 :            :     (void)bWrite;
     728                 :            : 
     729         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
     730                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     731 [ #  # ][ #  # ]:          0 :     GetSbData()->pInst->GetDllMgr()->FreeDll( rPar.Get(1)->GetString() );
                 [ #  # ]
     732                 :          0 : }
     733                 :          0 : bool IsBaseIndexOne()
     734                 :            : {
     735                 :          0 :     bool result = false;
     736 [ #  # ][ #  # ]:          0 :     if ( GetSbData()->pInst && GetSbData()->pInst->pRun )
                 [ #  # ]
     737                 :            :     {
     738                 :          0 :         sal_uInt16 res = GetSbData()->pInst->pRun->GetBase();
     739         [ #  # ]:          0 :         if ( res )
     740                 :          0 :             result = true;
     741                 :            :     }
     742                 :          0 :     return result;
     743                 :            : }
     744                 :            : 
     745                 :          0 : RTLFUNC(Array)
     746                 :            : {
     747                 :            :     (void)pBasic;
     748                 :            :     (void)bWrite;
     749                 :            : 
     750 [ #  # ][ #  # ]:          0 :     SbxDimArray* pArray = new SbxDimArray( SbxVARIANT );
     751         [ #  # ]:          0 :     sal_uInt16 nArraySize = rPar.Count() - 1;
     752                 :            : 
     753                 :            :     // ignore Option Base so far (unfortunately only known by the compiler)
     754 [ #  # ][ #  # ]:          0 :     bool bIncIndex = (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() );
         [ #  # ][ #  # ]
     755         [ #  # ]:          0 :     if( nArraySize )
     756                 :            :     {
     757         [ #  # ]:          0 :         if ( bIncIndex )
     758         [ #  # ]:          0 :             pArray->AddDim( 1, nArraySize );
     759                 :            :         else
     760         [ #  # ]:          0 :             pArray->AddDim( 0, nArraySize-1 );
     761                 :            :     }
     762                 :            :     else
     763                 :            :     {
     764         [ #  # ]:          0 :         pArray->unoAddDim( 0, -1 );
     765                 :            :     }
     766                 :            : 
     767                 :            :     // insert parameters into the array
     768                 :            :     // ATTENTION: Using type sal_uInt16 for loop variable is
     769                 :            :     // mandatory to workaround a problem with the
     770                 :            :     // Solaris Intel compiler optimizer! See i104354
     771         [ #  # ]:          0 :     for( sal_uInt16 i = 0 ; i < nArraySize ; i++ )
     772                 :            :     {
     773         [ #  # ]:          0 :         SbxVariable* pVar = rPar.Get(i+1);
     774 [ #  # ][ #  # ]:          0 :         SbxVariable* pNew = new SbxVariable( *pVar );
     775                 :          0 :         pNew->SetFlag( SBX_WRITE );
     776                 :          0 :         short index = static_cast< short >(i);
     777         [ #  # ]:          0 :         if ( bIncIndex )
     778                 :          0 :             ++index;
     779         [ #  # ]:          0 :         pArray->Put( pNew, &index );
     780                 :            :     }
     781                 :            : 
     782                 :            :     // return array
     783         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
     784                 :          0 :     sal_uInt16 nFlags = refVar->GetFlags();
     785                 :          0 :     refVar->ResetFlag( SBX_FIXED );
     786         [ #  # ]:          0 :     refVar->PutObject( pArray );
     787                 :          0 :     refVar->SetFlags( nFlags );
     788 [ #  # ][ #  # ]:          0 :     refVar->SetParameters( NULL );
     789                 :          0 : }
     790                 :            : 
     791                 :            : 
     792                 :            : // Featurewish #57868
     793                 :            : // The function returns a variant-array; if there are no parameters passed,
     794                 :            : // an empty array is created (according to dim a(); equal to a sequence of
     795                 :            : // the length 0 in Uno).
     796                 :            : // If there are parameters passed, there's a dimension created for each of
     797                 :            : // them; DimArray( 2, 2, 4 ) is equal to DIM a( 2, 2, 4 )
     798                 :            : // the array is always of the type variant
     799                 :          0 : RTLFUNC(DimArray)
     800                 :            : {
     801                 :            :     (void)pBasic;
     802                 :            :     (void)bWrite;
     803                 :            : 
     804 [ #  # ][ #  # ]:          0 :     SbxDimArray * pArray = new SbxDimArray( SbxVARIANT );
     805         [ #  # ]:          0 :     sal_uInt16 nArrayDims = rPar.Count() - 1;
     806         [ #  # ]:          0 :     if( nArrayDims > 0 )
     807                 :            :     {
     808         [ #  # ]:          0 :         for( sal_uInt16 i = 0; i < nArrayDims ; i++ )
     809                 :            :         {
     810 [ #  # ][ #  # ]:          0 :             sal_Int32 ub = rPar.Get(i+1)->GetLong();
     811         [ #  # ]:          0 :             if( ub < 0 )
     812                 :            :             {
     813         [ #  # ]:          0 :                 StarBASIC::Error( SbERR_OUT_OF_RANGE );
     814                 :          0 :                 ub = 0;
     815                 :            :             }
     816         [ #  # ]:          0 :             pArray->AddDim32( 0, ub );
     817                 :            :         }
     818                 :            :     }
     819                 :            :     else
     820         [ #  # ]:          0 :         pArray->unoAddDim( 0, -1 );
     821                 :            : 
     822         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
     823                 :          0 :     sal_uInt16 nFlags = refVar->GetFlags();
     824                 :          0 :     refVar->ResetFlag( SBX_FIXED );
     825         [ #  # ]:          0 :     refVar->PutObject( pArray );
     826                 :          0 :     refVar->SetFlags( nFlags );
     827 [ #  # ][ #  # ]:          0 :     refVar->SetParameters( NULL );
     828                 :          0 : }
     829                 :            : 
     830                 :            : /*
     831                 :            :  * FindObject and FindPropertyObject make it possible to
     832                 :            :  * address objects and properties of the type Object with
     833                 :            :  * their name as string-pararmeters at the runtime.
     834                 :            :  *
     835                 :            :  * Example:
     836                 :            :  * MyObj.Prop1.Bla = 5
     837                 :            :  *
     838                 :            :  * is equal to:
     839                 :            :  * dim ObjVar as Object
     840                 :            :  * dim ObjProp as Object
     841                 :            :  * ObjName$ = "MyObj"
     842                 :            :  * ObjVar = FindObject( ObjName$ )
     843                 :            :  * PropName$ = "Prop1"
     844                 :            :  * ObjProp = FindPropertyObject( ObjVar, PropName$ )
     845                 :            :  * ObjProp.Bla = 5
     846                 :            :  *
     847                 :            :  * The names can be created dynamically at the runtime
     848                 :            :  * so that e. g. via controls "TextEdit1" to "TextEdit5"
     849                 :            :  * can be iterated in a dialog in a loop.
     850                 :            :  */
     851                 :            : 
     852                 :            : 
     853                 :            : // 1st parameter = the object's name as string
     854                 :          0 : RTLFUNC(FindObject)
     855                 :            : {
     856                 :            :     (void)pBasic;
     857                 :            :     (void)bWrite;
     858                 :            : 
     859 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() < 2 )
     860                 :            :     {
     861         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     862                 :          0 :         return;
     863                 :            :     }
     864                 :            : 
     865 [ #  # ][ #  # ]:          0 :     String aNameStr = rPar.Get(1)->GetString();
                 [ #  # ]
     866                 :            : 
     867         [ #  # ]:          0 :     SbxBase* pFind =  StarBASIC::FindSBXInCurrentScope( aNameStr );
     868                 :          0 :     SbxObject* pFindObj = NULL;
     869         [ #  # ]:          0 :     if( pFind )
     870 [ #  # ][ #  # ]:          0 :         pFindObj = PTR_CAST(SbxObject,pFind);
         [ #  # ][ #  # ]
     871                 :            : 
     872         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
     873 [ #  # ][ #  # ]:          0 :     refVar->PutObject( pFindObj );
                 [ #  # ]
     874                 :            : }
     875                 :            : 
     876                 :            : // address object-property in an object
     877                 :            : // 1st parameter = object
     878                 :            : // 2nd parameter = the property's name as string
     879                 :          0 : RTLFUNC(FindPropertyObject)
     880                 :            : {
     881                 :            :     (void)pBasic;
     882                 :            :     (void)bWrite;
     883                 :            : 
     884 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() < 3 )
     885                 :            :     {
     886         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     887                 :          0 :         return;
     888                 :            :     }
     889                 :            : 
     890 [ #  # ][ #  # ]:          0 :     SbxBase* pObjVar = (SbxObject*)rPar.Get(1)->GetObject();
     891                 :          0 :     SbxObject* pObj = NULL;
     892         [ #  # ]:          0 :     if( pObjVar )
     893 [ #  # ][ #  # ]:          0 :         pObj = PTR_CAST(SbxObject,pObjVar);
         [ #  # ][ #  # ]
     894 [ #  # ][ #  # ]:          0 :     if( !pObj && pObjVar && pObjVar->ISA(SbxVariable) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     895                 :            :     {
     896         [ #  # ]:          0 :         SbxBase* pObjVarObj = ((SbxVariable*)pObjVar)->GetObject();
     897 [ #  # ][ #  # ]:          0 :         pObj = PTR_CAST(SbxObject,pObjVarObj);
         [ #  # ][ #  # ]
     898                 :            :     }
     899                 :            : 
     900 [ #  # ][ #  # ]:          0 :     String aNameStr = rPar.Get(2)->GetString();
                 [ #  # ]
     901                 :            : 
     902                 :          0 :     SbxObject* pFindObj = NULL;
     903         [ #  # ]:          0 :     if( pObj )
     904                 :            :     {
     905 [ #  # ][ #  # ]:          0 :         SbxVariable* pFindVar = pObj->Find( aNameStr, SbxCLASS_OBJECT );
     906 [ #  # ][ #  # ]:          0 :         pFindObj = PTR_CAST(SbxObject,pFindVar);
         [ #  # ][ #  # ]
     907                 :            :     }
     908                 :            :     else
     909         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_PARAMETER );
     910                 :            : 
     911                 :            : 
     912         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
     913 [ #  # ][ #  # ]:          0 :     refVar->PutObject( pFindObj );
                 [ #  # ]
     914                 :            : }
     915                 :            : 
     916                 :            : 
     917                 :            : 
     918                 :          0 : sal_Bool lcl_WriteSbxVariable( const SbxVariable& rVar, SvStream* pStrm,
     919                 :            :     sal_Bool bBinary, short nBlockLen, sal_Bool bIsArray )
     920                 :            : {
     921                 :          0 :     sal_uIntPtr nFPos = pStrm->Tell();
     922                 :            : 
     923                 :          0 :     sal_Bool bIsVariant = !rVar.IsFixed();
     924                 :          0 :     SbxDataType eType = rVar.GetType();
     925                 :            : 
     926   [ #  #  #  #  :          0 :     switch( eType )
             #  #  #  # ]
     927                 :            :     {
     928                 :            :         case SbxBOOL:
     929                 :            :         case SbxCHAR:
     930                 :            :         case SbxBYTE:
     931         [ #  # ]:          0 :                 if( bIsVariant )
     932                 :          0 :                     *pStrm << (sal_uInt16)SbxBYTE; // VarType Id
     933                 :          0 :                 *pStrm << rVar.GetByte();
     934                 :          0 :                 break;
     935                 :            : 
     936                 :            :         case SbxEMPTY:
     937                 :            :         case SbxNULL:
     938                 :            :         case SbxVOID:
     939                 :            :         case SbxINTEGER:
     940                 :            :         case SbxUSHORT:
     941                 :            :         case SbxINT:
     942                 :            :         case SbxUINT:
     943         [ #  # ]:          0 :                 if( bIsVariant )
     944                 :          0 :                     *pStrm << (sal_uInt16)SbxINTEGER; // VarType Id
     945                 :          0 :                 *pStrm << rVar.GetInteger();
     946                 :          0 :                 break;
     947                 :            : 
     948                 :            :         case SbxLONG:
     949                 :            :         case SbxULONG:
     950         [ #  # ]:          0 :                 if( bIsVariant )
     951                 :          0 :                     *pStrm << (sal_uInt16)SbxLONG; // VarType Id
     952                 :          0 :                 *pStrm << rVar.GetLong();
     953                 :          0 :                 break;
     954                 :            :         case SbxSALINT64:
     955                 :            :         case SbxSALUINT64:
     956         [ #  # ]:          0 :                 if( bIsVariant )
     957                 :          0 :                     *pStrm << (sal_uInt16)SbxSALINT64; // VarType Id
     958                 :          0 :                 *pStrm << (sal_uInt64)rVar.GetInt64();
     959                 :          0 :                 break;
     960                 :            :         case SbxSINGLE:
     961         [ #  # ]:          0 :                 if( bIsVariant )
     962                 :          0 :                     *pStrm << (sal_uInt16)eType; // VarType Id
     963                 :          0 :                 *pStrm << rVar.GetSingle();
     964                 :          0 :                 break;
     965                 :            : 
     966                 :            :         case SbxDOUBLE:
     967                 :            :         case SbxCURRENCY:
     968                 :            :         case SbxDATE:
     969         [ #  # ]:          0 :                 if( bIsVariant )
     970                 :          0 :                     *pStrm << (sal_uInt16)eType; // VarType Id
     971         [ #  # ]:          0 :                 *pStrm << rVar.GetDouble();
     972                 :          0 :                 break;
     973                 :            : 
     974                 :            :         case SbxSTRING:
     975                 :            :         case SbxLPSTR:
     976                 :            :                 {
     977                 :          0 :                 const String& rStr = rVar.GetString();
     978 [ #  # ][ #  # ]:          0 :                 if( !bBinary || bIsArray )
     979                 :            :                 {
     980         [ #  # ]:          0 :                     if( bIsVariant )
     981                 :          0 :                         *pStrm << (sal_uInt16)SbxSTRING;
     982         [ #  # ]:          0 :                     pStrm->WriteUniOrByteString( rStr, osl_getThreadTextEncoding() );
     983                 :            :                 }
     984                 :            :                 else
     985                 :            :                 {
     986                 :            :                     // without any length information! without end-identifier!
     987                 :            :                     // What does that mean for Unicode?! Choosing conversion to ByteString...
     988 [ #  # ][ #  # ]:          0 :                     rtl::OString aByteStr(rtl::OUStringToOString(rStr, osl_getThreadTextEncoding()));
                 [ #  # ]
     989         [ #  # ]:          0 :                     *pStrm << (const char*)aByteStr.getStr();
     990                 :            :                 }
     991                 :            :                 }
     992                 :          0 :                 break;
     993                 :            : 
     994                 :            :         default:
     995                 :          0 :                 StarBASIC::Error( SbERR_BAD_ARGUMENT );
     996                 :          0 :                 return sal_False;
     997                 :            :     }
     998                 :            : 
     999         [ #  # ]:          0 :     if( nBlockLen )
    1000                 :          0 :         pStrm->Seek( nFPos + nBlockLen );
    1001                 :          0 :     return pStrm->GetErrorCode() ? sal_False : sal_True;
    1002                 :            : }
    1003                 :            : 
    1004                 :          0 : sal_Bool lcl_ReadSbxVariable( SbxVariable& rVar, SvStream* pStrm,
    1005                 :            :     sal_Bool bBinary, short nBlockLen, sal_Bool bIsArray )
    1006                 :            : {
    1007                 :            :     (void)bBinary;
    1008                 :            :     (void)bIsArray;
    1009                 :            : 
    1010                 :            :     double aDouble;
    1011                 :            : 
    1012                 :          0 :     sal_uIntPtr nFPos = pStrm->Tell();
    1013                 :            : 
    1014         [ #  # ]:          0 :     sal_Bool bIsVariant = !rVar.IsFixed();
    1015         [ #  # ]:          0 :     SbxDataType eVarType = rVar.GetType();
    1016                 :            : 
    1017                 :          0 :     SbxDataType eSrcType = eVarType;
    1018         [ #  # ]:          0 :     if( bIsVariant )
    1019                 :            :     {
    1020                 :            :         sal_uInt16 nTemp;
    1021         [ #  # ]:          0 :         *pStrm >> nTemp;
    1022                 :          0 :         eSrcType = (SbxDataType)nTemp;
    1023                 :            :     }
    1024                 :            : 
    1025   [ #  #  #  #  :          0 :     switch( eSrcType )
             #  #  #  #  
                      # ]
    1026                 :            :     {
    1027                 :            :         case SbxBOOL:
    1028                 :            :         case SbxCHAR:
    1029                 :            :         case SbxBYTE:
    1030                 :            :                 {
    1031                 :            :                 sal_uInt8 aByte;
    1032         [ #  # ]:          0 :                 *pStrm >> aByte;
    1033                 :            : 
    1034 [ #  # ][ #  # ]:          0 :                 if( bBinary && SbiRuntime::isVBAEnabled() && aByte == 1 && pStrm->IsEof() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1035                 :          0 :                     aByte = 0;
    1036                 :            : 
    1037         [ #  # ]:          0 :                 rVar.PutByte( aByte );
    1038                 :            :                 }
    1039                 :          0 :                 break;
    1040                 :            : 
    1041                 :            :         case SbxEMPTY:
    1042                 :            :         case SbxNULL:
    1043                 :            :         case SbxVOID:
    1044                 :            :         case SbxINTEGER:
    1045                 :            :         case SbxUSHORT:
    1046                 :            :         case SbxINT:
    1047                 :            :         case SbxUINT:
    1048                 :            :                 {
    1049                 :            :                 sal_Int16 aInt;
    1050         [ #  # ]:          0 :                 *pStrm >> aInt;
    1051         [ #  # ]:          0 :                 rVar.PutInteger( aInt );
    1052                 :            :                 }
    1053                 :          0 :                 break;
    1054                 :            : 
    1055                 :            :         case SbxLONG:
    1056                 :            :         case SbxULONG:
    1057                 :            :                 {
    1058                 :            :                 sal_Int32 aInt;
    1059         [ #  # ]:          0 :                 *pStrm >> aInt;
    1060         [ #  # ]:          0 :                 rVar.PutLong( aInt );
    1061                 :            :                 }
    1062                 :          0 :                 break;
    1063                 :            :         case SbxSALINT64:
    1064                 :            :         case SbxSALUINT64:
    1065                 :            :                 {
    1066                 :            :                 sal_uInt32 aInt;
    1067         [ #  # ]:          0 :                 *pStrm >> aInt;
    1068         [ #  # ]:          0 :                 rVar.PutInt64( (sal_Int64)aInt );
    1069                 :            :                 }
    1070                 :          0 :                 break;
    1071                 :            :         case SbxSINGLE:
    1072                 :            :                 {
    1073                 :            :                 float nS;
    1074         [ #  # ]:          0 :                 *pStrm >> nS;
    1075         [ #  # ]:          0 :                 rVar.PutSingle( nS );
    1076                 :            :                 }
    1077                 :          0 :                 break;
    1078                 :            : 
    1079                 :            :         case SbxDOUBLE:
    1080                 :            :         case SbxCURRENCY:
    1081                 :            :                 {
    1082         [ #  # ]:          0 :                 *pStrm >> aDouble;
    1083         [ #  # ]:          0 :                 rVar.PutDouble( aDouble );
    1084                 :            :                 }
    1085                 :          0 :                 break;
    1086                 :            : 
    1087                 :            :         case SbxDATE:
    1088                 :            :                 {
    1089         [ #  # ]:          0 :                 *pStrm >> aDouble;
    1090         [ #  # ]:          0 :                 rVar.PutDate( aDouble );
    1091                 :            :                 }
    1092                 :          0 :                 break;
    1093                 :            : 
    1094                 :            :         case SbxSTRING:
    1095                 :            :         case SbxLPSTR:
    1096                 :            :                 {
    1097 [ #  # ][ #  # ]:          0 :                 String aStr = pStrm->ReadUniOrByteString(osl_getThreadTextEncoding());
                 [ #  # ]
    1098 [ #  # ][ #  # ]:          0 :                 rVar.PutString( aStr );
                 [ #  # ]
    1099                 :            :                 }
    1100                 :          0 :                 break;
    1101                 :            : 
    1102                 :            :         default:
    1103         [ #  # ]:          0 :                 StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1104                 :          0 :                 return sal_False;
    1105                 :            :     }
    1106                 :            : 
    1107         [ #  # ]:          0 :     if( nBlockLen )
    1108         [ #  # ]:          0 :         pStrm->Seek( nFPos + nBlockLen );
    1109                 :          0 :     return pStrm->GetErrorCode() ? sal_False : sal_True;
    1110                 :            : }
    1111                 :            : 
    1112                 :            : 
    1113                 :            : // nCurDim = 1...n
    1114                 :          0 : sal_Bool lcl_WriteReadSbxArray( SbxDimArray& rArr, SvStream* pStrm,
    1115                 :            :     sal_Bool bBinary, short nCurDim, short* pOtherDims, sal_Bool bWrite )
    1116                 :            : {
    1117                 :            :     DBG_ASSERT( nCurDim > 0,"Bad Dim");
    1118                 :            :     short nLower, nUpper;
    1119 [ #  # ][ #  # ]:          0 :     if( !rArr.GetDim( nCurDim, nLower, nUpper ) )
    1120                 :          0 :         return sal_False;
    1121         [ #  # ]:          0 :     for( short nCur = nLower; nCur <= nUpper; nCur++ )
    1122                 :            :     {
    1123                 :          0 :         pOtherDims[ nCurDim-1 ] = nCur;
    1124         [ #  # ]:          0 :         if( nCurDim != 1 )
    1125         [ #  # ]:          0 :             lcl_WriteReadSbxArray(rArr, pStrm, bBinary, nCurDim-1, pOtherDims, bWrite);
    1126                 :            :         else
    1127                 :            :         {
    1128         [ #  # ]:          0 :             SbxVariable* pVar = rArr.Get( (const short*)pOtherDims );
    1129                 :            :             sal_Bool bRet;
    1130         [ #  # ]:          0 :             if( bWrite )
    1131         [ #  # ]:          0 :                 bRet = lcl_WriteSbxVariable(*pVar, pStrm, bBinary, 0, sal_True );
    1132                 :            :             else
    1133         [ #  # ]:          0 :                 bRet = lcl_ReadSbxVariable(*pVar, pStrm, bBinary, 0, sal_True );
    1134         [ #  # ]:          0 :             if( !bRet )
    1135                 :          0 :                 return sal_False;
    1136                 :            :         }
    1137                 :            :     }
    1138                 :          0 :     return sal_True;
    1139                 :            : }
    1140                 :            : 
    1141                 :          0 : void PutGet( SbxArray& rPar, sal_Bool bPut )
    1142                 :            : {
    1143         [ #  # ]:          0 :     if ( rPar.Count() != 4 )
    1144                 :            :     {
    1145                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1146                 :          0 :         return;
    1147                 :            :     }
    1148                 :          0 :     sal_Int16 nFileNo = rPar.Get(1)->GetInteger();
    1149                 :          0 :     SbxVariable* pVar2 = rPar.Get(2);
    1150                 :          0 :     SbxDataType eType2 = pVar2->GetType();
    1151 [ #  # ][ #  # ]:          0 :     bool bHasRecordNo = (eType2 != SbxEMPTY && eType2 != SbxERROR);
    1152                 :          0 :     long nRecordNo = pVar2->GetLong();
    1153 [ #  # ][ #  # ]:          0 :     if ( nFileNo < 1 || ( bHasRecordNo && nRecordNo < 1 ) )
                 [ #  # ]
    1154                 :            :     {
    1155                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1156                 :          0 :         return;
    1157                 :            :     }
    1158                 :          0 :     nRecordNo--;
    1159                 :          0 :     SbiIoSystem* pIO = GetSbData()->pInst->GetIoSystem();
    1160                 :          0 :     SbiStream* pSbStrm = pIO->GetStream( nFileNo );
    1161                 :            : 
    1162 [ #  # ][ #  # ]:          0 :     if ( !pSbStrm || !(pSbStrm->GetMode() & (SBSTRM_BINARY | SBSTRM_RANDOM)) )
                 [ #  # ]
    1163                 :            :     {
    1164                 :          0 :         StarBASIC::Error( SbERR_BAD_CHANNEL );
    1165                 :          0 :         return;
    1166                 :            :     }
    1167                 :            : 
    1168                 :          0 :     SvStream* pStrm = pSbStrm->GetStrm();
    1169                 :          0 :     bool bRandom = pSbStrm->IsRandom();
    1170         [ #  # ]:          0 :     short nBlockLen = bRandom ? pSbStrm->GetBlockLen() : 0;
    1171                 :            : 
    1172         [ #  # ]:          0 :     if( bPut )
    1173                 :            :     {
    1174                 :          0 :         pSbStrm->ExpandFile();
    1175                 :            :     }
    1176                 :            : 
    1177         [ #  # ]:          0 :     if( bHasRecordNo )
    1178                 :            :     {
    1179         [ #  # ]:          0 :         sal_uIntPtr nFilePos = bRandom ? (sal_uIntPtr)(nBlockLen*nRecordNo) : (sal_uIntPtr)nRecordNo;
    1180                 :          0 :         pStrm->Seek( nFilePos );
    1181                 :            :     }
    1182                 :            : 
    1183                 :          0 :     SbxDimArray* pArr = 0;
    1184                 :          0 :     SbxVariable* pVar = rPar.Get(3);
    1185         [ #  # ]:          0 :     if( pVar->GetType() & SbxARRAY )
    1186                 :            :     {
    1187                 :          0 :         SbxBase* pParObj = pVar->GetObject();
    1188 [ #  # ][ #  # ]:          0 :         pArr = PTR_CAST(SbxDimArray,pParObj);
    1189                 :            :     }
    1190                 :            : 
    1191                 :            :     sal_Bool bRet;
    1192                 :            : 
    1193         [ #  # ]:          0 :     if( pArr )
    1194                 :            :     {
    1195                 :          0 :         sal_uIntPtr nFPos = pStrm->Tell();
    1196                 :          0 :         short nDims = pArr->GetDims();
    1197                 :          0 :         short* pDims = new short[ nDims ];
    1198                 :          0 :         bRet = lcl_WriteReadSbxArray(*pArr,pStrm,!bRandom,nDims,pDims,bPut);
    1199         [ #  # ]:          0 :         delete [] pDims;
    1200         [ #  # ]:          0 :         if( nBlockLen )
    1201                 :          0 :             pStrm->Seek( nFPos + nBlockLen );
    1202                 :            :     }
    1203                 :            :     else
    1204                 :            :     {
    1205         [ #  # ]:          0 :         if( bPut )
    1206                 :          0 :             bRet = lcl_WriteSbxVariable(*pVar, pStrm, !bRandom, nBlockLen, sal_False);
    1207                 :            :         else
    1208                 :          0 :             bRet = lcl_ReadSbxVariable(*pVar, pStrm, !bRandom, nBlockLen, sal_False);
    1209                 :            :     }
    1210 [ #  # ][ #  # ]:          0 :     if( !bRet || pStrm->GetErrorCode() )
                 [ #  # ]
    1211                 :          0 :         StarBASIC::Error( SbERR_IO_ERROR );
    1212                 :            : }
    1213                 :            : 
    1214                 :          0 : RTLFUNC(Put)
    1215                 :            : {
    1216                 :            :     (void)pBasic;
    1217                 :            :     (void)bWrite;
    1218                 :            : 
    1219                 :          0 :     PutGet( rPar, sal_True );
    1220                 :          0 : }
    1221                 :            : 
    1222                 :          0 : RTLFUNC(Get)
    1223                 :            : {
    1224                 :            :     (void)pBasic;
    1225                 :            :     (void)bWrite;
    1226                 :            : 
    1227                 :          0 :     PutGet( rPar, sal_False );
    1228                 :          0 : }
    1229                 :            : 
    1230                 :          4 : RTLFUNC(Environ)
    1231                 :            : {
    1232                 :            :     (void)pBasic;
    1233                 :            :     (void)bWrite;
    1234                 :            : 
    1235 [ +  - ][ -  + ]:          4 :     if ( rPar.Count() != 2 )
    1236                 :            :     {
    1237         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1238                 :          4 :         return;
    1239                 :            :     }
    1240         [ +  - ]:          4 :     String aResult;
    1241                 :            :     // should be ANSI but that's not possible under Win16 in the DLL
    1242 [ +  - ][ +  - ]:          4 :     rtl::OString aByteStr(rtl::OUStringToOString(rPar.Get(1)->GetString(),
    1243 [ +  - ][ +  - ]:          8 :         osl_getThreadTextEncoding()));
                 [ +  - ]
    1244                 :          4 :     const char* pEnvStr = getenv(aByteStr.getStr());
    1245         [ +  - ]:          4 :     if ( pEnvStr )
    1246         [ +  - ]:          4 :         aResult = rtl::OUString::createFromAscii( pEnvStr );
    1247 [ +  - ][ +  - ]:          4 :     rPar.Get(0)->PutString( aResult );
         [ +  - ][ +  - ]
    1248                 :            : }
    1249                 :            : 
    1250                 :          0 : static double GetDialogZoomFactor( bool bX, long nValue )
    1251                 :            : {
    1252                 :          0 :     OutputDevice* pDevice = Application::GetDefaultDevice();
    1253                 :          0 :     double nResult = 0;
    1254         [ #  # ]:          0 :     if( pDevice )
    1255                 :            :     {
    1256                 :          0 :         Size aRefSize( nValue, nValue );
    1257         [ #  # ]:          0 :         Fraction aFracX( 1, 26 );
    1258         [ #  # ]:          0 :         Fraction aFracY( 1, 24 );
    1259         [ #  # ]:          0 :         MapMode aMap( MAP_APPFONT, Point(), aFracX, aFracY );
    1260         [ #  # ]:          0 :         Size aScaledSize = pDevice->LogicToPixel( aRefSize, aMap );
    1261 [ #  # ][ #  # ]:          0 :         aRefSize = pDevice->LogicToPixel( aRefSize, MapMode(MAP_TWIP) );
                 [ #  # ]
    1262                 :            : 
    1263                 :            :         double nRef, nScaled;
    1264         [ #  # ]:          0 :         if( bX )
    1265                 :            :         {
    1266                 :          0 :             nRef = aRefSize.Width();
    1267                 :          0 :             nScaled = aScaledSize.Width();
    1268                 :            :         }
    1269                 :            :         else
    1270                 :            :         {
    1271                 :          0 :             nRef = aRefSize.Height();
    1272                 :          0 :             nScaled = aScaledSize.Height();
    1273                 :            :         }
    1274         [ #  # ]:          0 :         nResult = nScaled / nRef;
    1275                 :            :     }
    1276                 :          0 :     return nResult;
    1277                 :            : }
    1278                 :            : 
    1279                 :            : 
    1280                 :          0 : RTLFUNC(GetDialogZoomFactorX)
    1281                 :            : {
    1282                 :            :     (void)pBasic;
    1283                 :            :     (void)bWrite;
    1284                 :            : 
    1285         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
    1286                 :            :     {
    1287                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1288                 :          0 :         return;
    1289                 :            :     }
    1290                 :          0 :     rPar.Get(0)->PutDouble( GetDialogZoomFactor( true, rPar.Get(1)->GetLong() ));
    1291                 :            : }
    1292                 :            : 
    1293                 :          0 : RTLFUNC(GetDialogZoomFactorY)
    1294                 :            : {
    1295                 :            :     (void)pBasic;
    1296                 :            :     (void)bWrite;
    1297                 :            : 
    1298         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
    1299                 :            :     {
    1300                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1301                 :          0 :         return;
    1302                 :            :     }
    1303                 :          0 :     rPar.Get(0)->PutDouble( GetDialogZoomFactor( false, rPar.Get(1)->GetLong()));
    1304                 :            : }
    1305                 :            : 
    1306                 :            : 
    1307                 :          0 : RTLFUNC(EnableReschedule)
    1308                 :            : {
    1309                 :            :     (void)pBasic;
    1310                 :            :     (void)bWrite;
    1311                 :            : 
    1312                 :          0 :     rPar.Get(0)->PutEmpty();
    1313         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
    1314                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1315         [ #  # ]:          0 :     if( GetSbData()->pInst )
    1316                 :          0 :         GetSbData()->pInst->EnableReschedule( rPar.Get(1)->GetBool() );
    1317                 :          0 : }
    1318                 :            : 
    1319                 :          0 : RTLFUNC(GetSystemTicks)
    1320                 :            : {
    1321                 :            :     (void)pBasic;
    1322                 :            :     (void)bWrite;
    1323                 :            : 
    1324         [ #  # ]:          0 :     if ( rPar.Count() != 1 )
    1325                 :            :     {
    1326                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1327                 :          0 :         return;
    1328                 :            :     }
    1329                 :          0 :     rPar.Get(0)->PutLong( Time::GetSystemTicks() );
    1330                 :            : }
    1331                 :            : 
    1332                 :          0 : RTLFUNC(GetPathSeparator)
    1333                 :            : {
    1334                 :            :     (void)pBasic;
    1335                 :            :     (void)bWrite;
    1336                 :            : 
    1337         [ #  # ]:          0 :     if ( rPar.Count() != 1 )
    1338                 :            :     {
    1339                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1340                 :          0 :         return;
    1341                 :            :     }
    1342 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString( DirEntry::GetAccessDelimiter() );
                 [ #  # ]
    1343                 :            : }
    1344                 :            : 
    1345                 :          0 : RTLFUNC(ResolvePath)
    1346                 :            : {
    1347                 :            :     (void)pBasic;
    1348                 :            :     (void)bWrite;
    1349                 :            : 
    1350         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
    1351                 :            :     {
    1352 [ #  # ][ #  # ]:          0 :         String aStr = rPar.Get(1)->GetString();
                 [ #  # ]
    1353         [ #  # ]:          0 :         DirEntry aEntry( aStr );
    1354 [ #  # ][ #  # ]:          0 :         rPar.Get(0)->PutString( aStr );
         [ #  # ][ #  # ]
                 [ #  # ]
    1355                 :            :     }
    1356                 :            :     else
    1357                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1358                 :          0 : }
    1359                 :            : 
    1360                 :          0 : RTLFUNC(TypeLen)
    1361                 :            : {
    1362                 :            :     (void)pBasic;
    1363                 :            :     (void)bWrite;
    1364                 :            : 
    1365         [ #  # ]:          0 :     if ( rPar.Count() != 2 )
    1366                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1367                 :            :     else
    1368                 :            :     {
    1369                 :          0 :         SbxDataType eType = rPar.Get(1)->GetType();
    1370                 :          0 :         sal_Int16 nLen = 0;
    1371   [ #  #  #  #  :          0 :         switch( eType )
             #  #  #  # ]
    1372                 :            :         {
    1373                 :            :             case SbxEMPTY:
    1374                 :            :             case SbxNULL:
    1375                 :            :             case SbxVECTOR:
    1376                 :            :             case SbxARRAY:
    1377                 :            :             case SbxBYREF:
    1378                 :            :             case SbxVOID:
    1379                 :            :             case SbxHRESULT:
    1380                 :            :             case SbxPOINTER:
    1381                 :            :             case SbxDIMARRAY:
    1382                 :            :             case SbxCARRAY:
    1383                 :            :             case SbxUSERDEF:
    1384                 :          0 :                 nLen = 0;
    1385                 :          0 :                 break;
    1386                 :            : 
    1387                 :            :             case SbxINTEGER:
    1388                 :            :             case SbxERROR:
    1389                 :            :             case SbxUSHORT:
    1390                 :            :             case SbxINT:
    1391                 :            :             case SbxUINT:
    1392                 :          0 :                 nLen = 2;
    1393                 :          0 :                 break;
    1394                 :            : 
    1395                 :            :             case SbxLONG:
    1396                 :            :             case SbxSINGLE:
    1397                 :            :             case SbxULONG:
    1398                 :          0 :                 nLen = 4;
    1399                 :          0 :                 break;
    1400                 :            : 
    1401                 :            :             case SbxDOUBLE:
    1402                 :            :             case SbxCURRENCY:
    1403                 :            :             case SbxDATE:
    1404                 :            :             case SbxSALINT64:
    1405                 :            :             case SbxSALUINT64:
    1406                 :          0 :                 nLen = 8;
    1407                 :          0 :                 break;
    1408                 :            : 
    1409                 :            :             case SbxOBJECT:
    1410                 :            :             case SbxVARIANT:
    1411                 :            :             case SbxDATAOBJECT:
    1412                 :          0 :                 nLen = 0;
    1413                 :          0 :                 break;
    1414                 :            : 
    1415                 :            :             case SbxCHAR:
    1416                 :            :             case SbxBYTE:
    1417                 :            :             case SbxBOOL:
    1418                 :          0 :                 nLen = 1;
    1419                 :          0 :                 break;
    1420                 :            : 
    1421                 :            :             case SbxLPSTR:
    1422                 :            :             case SbxLPWSTR:
    1423                 :            :             case SbxCoreSTRING:
    1424                 :            :             case SbxSTRING:
    1425                 :          0 :                 nLen = (sal_Int16)rPar.Get(1)->GetString().Len();
    1426                 :          0 :                 break;
    1427                 :            : 
    1428                 :            :             default:
    1429                 :          0 :                 nLen = 0;
    1430                 :            :         }
    1431                 :          0 :         rPar.Get(0)->PutInteger( nLen );
    1432                 :            :     }
    1433                 :          0 : }
    1434                 :            : 
    1435                 :            : 
    1436                 :            : // 1st parameter == class name, other parameters for initialisation
    1437                 :        104 : RTLFUNC(CreateUnoStruct)
    1438                 :            : {
    1439                 :            :     (void)pBasic;
    1440                 :            :     (void)bWrite;
    1441                 :            : 
    1442                 :        104 :     RTL_Impl_CreateUnoStruct( pBasic, rPar, bWrite );
    1443                 :        104 : }
    1444                 :            : 
    1445                 :            : 
    1446                 :            : // 1st parameter == service-name
    1447                 :         78 : RTLFUNC(CreateUnoService)
    1448                 :            : {
    1449                 :            :     (void)pBasic;
    1450                 :            :     (void)bWrite;
    1451                 :            : 
    1452                 :         78 :     RTL_Impl_CreateUnoService( pBasic, rPar, bWrite );
    1453                 :         78 : }
    1454                 :            : 
    1455                 :          0 : RTLFUNC(CreateUnoServiceWithArguments)
    1456                 :            : {
    1457                 :            :     (void)pBasic;
    1458                 :            :     (void)bWrite;
    1459                 :            : 
    1460                 :          0 :     RTL_Impl_CreateUnoServiceWithArguments( pBasic, rPar, bWrite );
    1461                 :          0 : }
    1462                 :            : 
    1463                 :            : 
    1464                 :          0 : RTLFUNC(CreateUnoValue)
    1465                 :            : {
    1466                 :            :     (void)pBasic;
    1467                 :            :     (void)bWrite;
    1468                 :            : 
    1469                 :          0 :     RTL_Impl_CreateUnoValue( pBasic, rPar, bWrite );
    1470                 :          0 : }
    1471                 :            : 
    1472                 :            : 
    1473                 :            : // no parameters
    1474                 :          0 : RTLFUNC(GetProcessServiceManager)
    1475                 :            : {
    1476                 :            :     (void)pBasic;
    1477                 :            :     (void)bWrite;
    1478                 :            : 
    1479                 :          0 :     RTL_Impl_GetProcessServiceManager( pBasic, rPar, bWrite );
    1480                 :          0 : }
    1481                 :            : 
    1482                 :            : 
    1483                 :            : // 1st parameter == Sequence<PropertyValue>
    1484                 :          0 : RTLFUNC(CreatePropertySet)
    1485                 :            : {
    1486                 :            :     (void)pBasic;
    1487                 :            :     (void)bWrite;
    1488                 :            : 
    1489                 :          0 :     RTL_Impl_CreatePropertySet( pBasic, rPar, bWrite );
    1490                 :          0 : }
    1491                 :            : 
    1492                 :            : 
    1493                 :            : // multiple interface-names as parameters
    1494                 :          0 : RTLFUNC(HasUnoInterfaces)
    1495                 :            : {
    1496                 :            :     (void)pBasic;
    1497                 :            :     (void)bWrite;
    1498                 :            : 
    1499                 :          0 :     RTL_Impl_HasInterfaces( pBasic, rPar, bWrite );
    1500                 :          0 : }
    1501                 :            : 
    1502                 :            : 
    1503                 :          0 : RTLFUNC(IsUnoStruct)
    1504                 :            : {
    1505                 :            :     (void)pBasic;
    1506                 :            :     (void)bWrite;
    1507                 :            : 
    1508                 :          0 :     RTL_Impl_IsUnoStruct( pBasic, rPar, bWrite );
    1509                 :          0 : }
    1510                 :            : 
    1511                 :            : 
    1512                 :          0 : RTLFUNC(EqualUnoObjects)
    1513                 :            : {
    1514                 :            :     (void)pBasic;
    1515                 :            :     (void)bWrite;
    1516                 :            : 
    1517                 :          0 :     RTL_Impl_EqualUnoObjects( pBasic, rPar, bWrite );
    1518                 :          0 : }
    1519                 :            : 
    1520                 :            : // Instanciate "com.sun.star.awt.UnoControlDialog" on basis
    1521                 :            : // of a DialogLibrary entry: Convert from XML-ByteSequence
    1522                 :            : // and attach events. Implemented in classes\eventatt.cxx
    1523                 :            : void RTL_Impl_CreateUnoDialog( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite );
    1524                 :            : 
    1525                 :          0 : RTLFUNC(CreateUnoDialog)
    1526                 :            : {
    1527                 :            :     (void)pBasic;
    1528                 :            :     (void)bWrite;
    1529                 :            : 
    1530                 :          0 :     RTL_Impl_CreateUnoDialog( pBasic, rPar, bWrite );
    1531                 :          0 : }
    1532                 :            : 
    1533                 :            : // Return the application standard lib as root scope
    1534                 :          0 : RTLFUNC(GlobalScope)
    1535                 :            : {
    1536                 :            :     (void)pBasic;
    1537                 :            :     (void)bWrite;
    1538                 :            : 
    1539                 :          0 :     SbxObject* p = pBasic;
    1540 [ #  # ][ #  # ]:          0 :     while( p->GetParent() )
    1541         [ #  # ]:          0 :         p = p->GetParent();
    1542                 :            : 
    1543         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
    1544 [ #  # ][ #  # ]:          0 :     refVar->PutObject( p );
    1545                 :          0 : }
    1546                 :            : 
    1547                 :            : // Helper functions to convert Url from/to system paths
    1548                 :          0 : RTLFUNC(ConvertToUrl)
    1549                 :            : {
    1550                 :            :     (void)pBasic;
    1551                 :            :     (void)bWrite;
    1552                 :            : 
    1553         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
    1554                 :            :     {
    1555 [ #  # ][ #  # ]:          0 :         String aStr = rPar.Get(1)->GetString();
                 [ #  # ]
    1556 [ #  # ][ #  # ]:          0 :         INetURLObject aURLObj( aStr, INET_PROT_FILE );
    1557         [ #  # ]:          0 :         ::rtl::OUString aFileURL = aURLObj.GetMainURL( INetURLObject::NO_DECODE );
    1558         [ #  # ]:          0 :         if( aFileURL.isEmpty() )
    1559         [ #  # ]:          0 :             ::osl::File::getFileURLFromSystemPath( aFileURL, aFileURL );
    1560         [ #  # ]:          0 :         if( aFileURL.isEmpty() )
    1561         [ #  # ]:          0 :             aFileURL = aStr;
    1562 [ #  # ][ #  # ]:          0 :         rPar.Get(0)->PutString( String(aFileURL) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1563                 :            :     }
    1564                 :            :     else
    1565                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1566                 :          0 : }
    1567                 :            : 
    1568                 :          0 : RTLFUNC(ConvertFromUrl)
    1569                 :            : {
    1570                 :            :     (void)pBasic;
    1571                 :            :     (void)bWrite;
    1572                 :            : 
    1573         [ #  # ]:          0 :     if ( rPar.Count() == 2 )
    1574                 :            :     {
    1575 [ #  # ][ #  # ]:          0 :         String aStr = rPar.Get(1)->GetString();
                 [ #  # ]
    1576                 :          0 :         ::rtl::OUString aSysPath;
    1577 [ #  # ][ #  # ]:          0 :         ::osl::File::getSystemPathFromFileURL( aStr, aSysPath );
    1578         [ #  # ]:          0 :         if( aSysPath.isEmpty() )
    1579         [ #  # ]:          0 :             aSysPath = aStr;
    1580 [ #  # ][ #  # ]:          0 :         rPar.Get(0)->PutString( String(aSysPath) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1581                 :            :     }
    1582                 :            :     else
    1583                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1584                 :          0 : }
    1585                 :            : 
    1586                 :            : 
    1587                 :            : // Provide DefaultContext
    1588                 :          2 : RTLFUNC(GetDefaultContext)
    1589                 :            : {
    1590                 :            :     (void)pBasic;
    1591                 :            :     (void)bWrite;
    1592                 :            : 
    1593                 :          2 :     RTL_Impl_GetDefaultContext( pBasic, rPar, bWrite );
    1594                 :          2 : }
    1595                 :            : 
    1596                 :            : #ifdef DBG_TRACE_BASIC
    1597                 :            : RTLFUNC(TraceCommand)
    1598                 :            : {
    1599                 :            :     RTL_Impl_TraceCommand( pBasic, rPar, bWrite );
    1600                 :            : }
    1601                 :            : #endif
    1602                 :            : 
    1603                 :          0 : RTLFUNC(Join)
    1604                 :            : {
    1605                 :            :     (void)pBasic;
    1606                 :            :     (void)bWrite;
    1607                 :            : 
    1608                 :          0 :     sal_uInt16 nParCount = rPar.Count();
    1609 [ #  # ][ #  # ]:          0 :     if ( nParCount != 3 && nParCount != 2 )
    1610                 :            :     {
    1611                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1612                 :          0 :         return;
    1613                 :            :     }
    1614                 :          0 :     SbxBase* pParObj = rPar.Get(1)->GetObject();
    1615 [ #  # ][ #  # ]:          0 :     SbxDimArray* pArr = PTR_CAST(SbxDimArray,pParObj);
    1616         [ #  # ]:          0 :     if( pArr )
    1617                 :            :     {
    1618 [ #  # ][ #  # ]:          0 :         if( pArr->GetDims() != 1 )
    1619         [ #  # ]:          0 :             StarBASIC::Error( SbERR_WRONG_DIMS );   // Syntax Error?!
    1620                 :            : 
    1621         [ #  # ]:          0 :         String aDelim;
    1622         [ #  # ]:          0 :         if( nParCount == 3 )
    1623 [ #  # ][ #  # ]:          0 :             aDelim = rPar.Get(2)->GetString();
                 [ #  # ]
    1624                 :            :         else
    1625         [ #  # ]:          0 :             aDelim = rtl::OUString(" ");
    1626                 :            : 
    1627         [ #  # ]:          0 :         String aRetStr;
    1628                 :            :         short nLower, nUpper;
    1629         [ #  # ]:          0 :         pArr->GetDim( 1, nLower, nUpper );
    1630         [ #  # ]:          0 :         for( short i = nLower ; i <= nUpper ; ++i )
    1631                 :            :         {
    1632 [ #  # ][ #  # ]:          0 :             String aStr = pArr->Get( &i )->GetString();
                 [ #  # ]
    1633         [ #  # ]:          0 :             aRetStr += aStr;
    1634         [ #  # ]:          0 :             if( i != nUpper )
    1635         [ #  # ]:          0 :                 aRetStr += aDelim;
    1636         [ #  # ]:          0 :         }
    1637 [ #  # ][ #  # ]:          0 :         rPar.Get(0)->PutString( aRetStr );
         [ #  # ][ #  # ]
                 [ #  # ]
    1638                 :            :     }
    1639                 :            :     else
    1640                 :          0 :         StarBASIC::Error( SbERR_MUST_HAVE_DIMS );
    1641                 :            : }
    1642                 :            : 
    1643                 :            : 
    1644                 :          0 : RTLFUNC(Split)
    1645                 :            : {
    1646                 :            :     (void)pBasic;
    1647                 :            :     (void)bWrite;
    1648                 :            : 
    1649         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    1650         [ #  # ]:          0 :     if ( nParCount < 2 )
    1651                 :            :     {
    1652         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1653                 :          0 :         return;
    1654                 :            :     }
    1655                 :            : 
    1656 [ #  # ][ #  # ]:          0 :     String aExpression = rPar.Get(1)->GetString();
                 [ #  # ]
    1657                 :          0 :     short nArraySize = 0;
    1658         [ #  # ]:          0 :     StringVector vRet;
    1659         [ #  # ]:          0 :     if( aExpression.Len() )
    1660                 :            :     {
    1661         [ #  # ]:          0 :         String aDelim;
    1662         [ #  # ]:          0 :         if( nParCount >= 3 )
    1663 [ #  # ][ #  # ]:          0 :             aDelim = rPar.Get(2)->GetString();
                 [ #  # ]
    1664                 :            :         else
    1665         [ #  # ]:          0 :             aDelim = rtl::OUString(" ");
    1666                 :            : 
    1667                 :          0 :         sal_Int32 nCount = -1;
    1668         [ #  # ]:          0 :         if( nParCount == 4 )
    1669 [ #  # ][ #  # ]:          0 :             nCount = rPar.Get(3)->GetLong();
    1670                 :            : 
    1671                 :          0 :         xub_StrLen nDelimLen = aDelim.Len();
    1672         [ #  # ]:          0 :         if( nDelimLen )
    1673                 :            :         {
    1674                 :          0 :             xub_StrLen iSearch = STRING_NOTFOUND;
    1675                 :          0 :             xub_StrLen iStart = 0;
    1676         [ #  # ]:          0 :             do
    1677                 :            :             {
    1678                 :          0 :                 bool bBreak = false;
    1679 [ #  # ][ #  # ]:          0 :                 if( nCount >= 0 && nArraySize == nCount - 1 )
    1680                 :          0 :                     bBreak = true;
    1681                 :            : 
    1682         [ #  # ]:          0 :                 iSearch = aExpression.Search( aDelim, iStart );
    1683         [ #  # ]:          0 :                 String aSubStr;
    1684 [ #  # ][ #  # ]:          0 :                 if( iSearch != STRING_NOTFOUND && !bBreak )
    1685                 :            :                 {
    1686 [ #  # ][ #  # ]:          0 :                     aSubStr = aExpression.Copy( iStart, iSearch - iStart );
                 [ #  # ]
    1687                 :          0 :                     iStart = iSearch + nDelimLen;
    1688                 :            :                 }
    1689                 :            :                 else
    1690                 :            :                 {
    1691 [ #  # ][ #  # ]:          0 :                     aSubStr = aExpression.Copy( iStart );
                 [ #  # ]
    1692                 :            :                 }
    1693         [ #  # ]:          0 :                 vRet.push_back( aSubStr );
    1694                 :          0 :                 nArraySize++;
    1695                 :            : 
    1696         [ #  # ]:          0 :                 if( bBreak )
    1697 [ #  # ][ #  # ]:          0 :                     break;
    1698                 :            :             }
    1699                 :            :             while( iSearch != STRING_NOTFOUND );
    1700                 :            :         }
    1701                 :            :         else
    1702                 :            :         {
    1703         [ #  # ]:          0 :             vRet.push_back( aExpression );
    1704                 :          0 :             nArraySize = 1;
    1705         [ #  # ]:          0 :         }
    1706                 :            :     }
    1707                 :            : 
    1708 [ #  # ][ #  # ]:          0 :     SbxDimArray* pArray = new SbxDimArray( SbxVARIANT );
    1709         [ #  # ]:          0 :     pArray->unoAddDim( 0, nArraySize-1 );
    1710                 :            : 
    1711                 :            :     // insert parameter(s) into the array
    1712         [ #  # ]:          0 :     for( short i = 0 ; i < nArraySize ; i++ )
    1713                 :            :     {
    1714 [ #  # ][ #  # ]:          0 :         SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
    1715 [ #  # ][ #  # ]:          0 :         xVar->PutString( vRet[i] );
                 [ #  # ]
    1716         [ #  # ]:          0 :         pArray->Put( (SbxVariable*)xVar, &i );
    1717         [ #  # ]:          0 :     }
    1718                 :            : 
    1719                 :            :     // return array
    1720         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
    1721                 :          0 :     sal_uInt16 nFlags = refVar->GetFlags();
    1722                 :          0 :     refVar->ResetFlag( SBX_FIXED );
    1723         [ #  # ]:          0 :     refVar->PutObject( pArray );
    1724                 :          0 :     refVar->SetFlags( nFlags );
    1725 [ #  # ][ #  # ]:          0 :     refVar->SetParameters( NULL );
                 [ #  # ]
    1726                 :            : }
    1727                 :            : 
    1728                 :            : // MonthName(month[, abbreviate])
    1729                 :          0 : RTLFUNC(MonthName)
    1730                 :            : {
    1731                 :            :     (void)pBasic;
    1732                 :            :     (void)bWrite;
    1733                 :            : 
    1734         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    1735 [ #  # ][ #  # ]:          0 :     if( nParCount != 2 && nParCount != 3 )
    1736                 :            :     {
    1737         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1738                 :            :         return;
    1739                 :            :     }
    1740                 :            : 
    1741         [ #  # ]:          0 :     Reference< XCalendar3 > xCalendar = getLocaleCalendar();
    1742         [ #  # ]:          0 :     if( !xCalendar.is() )
    1743                 :            :     {
    1744         [ #  # ]:          0 :         StarBASIC::Error( SbERR_INTERNAL_ERROR );
    1745                 :            :         return;
    1746                 :            :     }
    1747 [ #  # ][ #  # ]:          0 :     Sequence< CalendarItem2 > aMonthSeq = xCalendar->getMonths2();
    1748                 :          0 :     sal_Int32 nMonthCount = aMonthSeq.getLength();
    1749                 :            : 
    1750 [ #  # ][ #  # ]:          0 :     sal_Int16 nVal = rPar.Get(1)->GetInteger();
    1751 [ #  # ][ #  # ]:          0 :     if( nVal < 1 || nVal > nMonthCount )
    1752                 :            :     {
    1753         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1754                 :            :         return;
    1755                 :            :     }
    1756                 :            : 
    1757                 :          0 :     sal_Bool bAbbreviate = false;
    1758         [ #  # ]:          0 :     if( nParCount == 3 )
    1759 [ #  # ][ #  # ]:          0 :         bAbbreviate = rPar.Get(2)->GetBool();
    1760                 :            : 
    1761                 :          0 :     const CalendarItem2* pCalendarItems = aMonthSeq.getConstArray();
    1762                 :          0 :     const CalendarItem2& rItem = pCalendarItems[nVal - 1];
    1763                 :            : 
    1764         [ #  # ]:          0 :     ::rtl::OUString aRetStr = ( bAbbreviate ? rItem.AbbrevName : rItem.FullName );
    1765 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString( String(aRetStr) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1766                 :            : }
    1767                 :            : 
    1768                 :            : // WeekdayName(weekday, abbreviate, firstdayofweek)
    1769                 :          0 : RTLFUNC(WeekdayName)
    1770                 :            : {
    1771                 :            :     (void)pBasic;
    1772                 :            :     (void)bWrite;
    1773                 :            : 
    1774         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    1775 [ #  # ][ #  # ]:          0 :     if( nParCount < 2 || nParCount > 4 )
    1776                 :            :     {
    1777         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1778                 :            :         return;
    1779                 :            :     }
    1780                 :            : 
    1781         [ #  # ]:          0 :     Reference< XCalendar3 > xCalendar = getLocaleCalendar();
    1782         [ #  # ]:          0 :     if( !xCalendar.is() )
    1783                 :            :     {
    1784         [ #  # ]:          0 :         StarBASIC::Error( SbERR_INTERNAL_ERROR );
    1785                 :            :         return;
    1786                 :            :     }
    1787                 :            : 
    1788 [ #  # ][ #  # ]:          0 :     Sequence< CalendarItem2 > aDaySeq = xCalendar->getDays2();
    1789                 :          0 :     sal_Int16 nDayCount = (sal_Int16)aDaySeq.getLength();
    1790 [ #  # ][ #  # ]:          0 :     sal_Int16 nDay = rPar.Get(1)->GetInteger();
    1791                 :          0 :     sal_Int16 nFirstDay = 0;
    1792         [ #  # ]:          0 :     if( nParCount == 4 )
    1793                 :            :     {
    1794 [ #  # ][ #  # ]:          0 :         nFirstDay = rPar.Get(3)->GetInteger();
    1795 [ #  # ][ #  # ]:          0 :         if( nFirstDay < 0 || nFirstDay > 7 )
    1796                 :            :         {
    1797         [ #  # ]:          0 :             StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1798                 :            :             return;
    1799                 :            :         }
    1800                 :            :     }
    1801         [ #  # ]:          0 :     if( nFirstDay == 0 )
    1802 [ #  # ][ #  # ]:          0 :         nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 );
    1803                 :            : 
    1804                 :          0 :     nDay = 1 + (nDay + nDayCount + nFirstDay - 2) % nDayCount;
    1805 [ #  # ][ #  # ]:          0 :     if( nDay < 1 || nDay > nDayCount )
    1806                 :            :     {
    1807         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1808                 :            :         return;
    1809                 :            :     }
    1810                 :            : 
    1811                 :          0 :     sal_Bool bAbbreviate = false;
    1812         [ #  # ]:          0 :     if( nParCount >= 3 )
    1813                 :            :     {
    1814         [ #  # ]:          0 :         SbxVariable* pPar2 = rPar.Get(2);
    1815 [ #  # ][ #  # ]:          0 :         if( !pPar2->IsErr() )
    1816         [ #  # ]:          0 :             bAbbreviate = pPar2->GetBool();
    1817                 :            :     }
    1818                 :            : 
    1819                 :          0 :     const CalendarItem2* pCalendarItems = aDaySeq.getConstArray();
    1820                 :          0 :     const CalendarItem2& rItem = pCalendarItems[nDay - 1];
    1821                 :            : 
    1822         [ #  # ]:          0 :     ::rtl::OUString aRetStr = ( bAbbreviate ? rItem.AbbrevName : rItem.FullName );
    1823 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString( String(aRetStr) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1824                 :            : }
    1825                 :            : 
    1826                 :          0 : RTLFUNC(Weekday)
    1827                 :            : {
    1828                 :            :     (void)pBasic;
    1829                 :            :     (void)bWrite;
    1830                 :            : 
    1831                 :          0 :     sal_uInt16 nParCount = rPar.Count();
    1832         [ #  # ]:          0 :     if ( nParCount < 2 )
    1833                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1834                 :            :     else
    1835                 :            :     {
    1836                 :          0 :         double aDate = rPar.Get(1)->GetDate();
    1837                 :            : 
    1838                 :          0 :         bool bFirstDay = false;
    1839                 :          0 :         sal_Int16 nFirstDay = 0;
    1840         [ #  # ]:          0 :         if ( nParCount > 2 )
    1841                 :            :         {
    1842                 :          0 :             nFirstDay = rPar.Get(2)->GetInteger();
    1843                 :          0 :             bFirstDay = true;
    1844                 :            :         }
    1845                 :          0 :         sal_Int16 nDay = implGetWeekDay( aDate, bFirstDay, nFirstDay );
    1846                 :          0 :         rPar.Get(0)->PutInteger( nDay );
    1847                 :            :     }
    1848                 :          0 : }
    1849                 :            : 
    1850                 :            : 
    1851                 :            : enum Interval
    1852                 :            : {
    1853                 :            :     INTERVAL_NONE,
    1854                 :            :     INTERVAL_YYYY,
    1855                 :            :     INTERVAL_Q,
    1856                 :            :     INTERVAL_M,
    1857                 :            :     INTERVAL_Y,
    1858                 :            :     INTERVAL_D,
    1859                 :            :     INTERVAL_W,
    1860                 :            :     INTERVAL_WW,
    1861                 :            :     INTERVAL_H,
    1862                 :            :     INTERVAL_N,
    1863                 :            :     INTERVAL_S
    1864                 :            : };
    1865                 :            : 
    1866                 :            : struct IntervalInfo
    1867                 :            : {
    1868                 :            :     Interval    meInterval;
    1869                 :            :     const char* mpStringCode;
    1870                 :            :     double      mdValue;
    1871                 :            :     bool        mbSimple;
    1872                 :            : 
    1873                 :       2827 :     IntervalInfo( Interval eInterval, const char* pStringCode, double dValue, bool bSimple )
    1874                 :            :         : meInterval( eInterval )
    1875                 :            :         , mpStringCode( pStringCode )
    1876                 :            :         , mdValue( dValue )
    1877                 :       2827 :         , mbSimple( bSimple )
    1878                 :       2827 :     {}
    1879                 :            : };
    1880                 :            : 
    1881                 :            : static IntervalInfo pIntervalTable[] =
    1882                 :            : {
    1883                 :            :     IntervalInfo( INTERVAL_YYYY,    "yyyy",      0.0,               false ),    // Year
    1884                 :            :     IntervalInfo( INTERVAL_Q,       "q",         0.0,               false ),    // Quarter
    1885                 :            :     IntervalInfo( INTERVAL_M,       "m",         0.0,               false ),    // Month
    1886                 :            :     IntervalInfo( INTERVAL_Y,       "y",         1.0,               true ),     // Day of year
    1887                 :            :     IntervalInfo( INTERVAL_D,       "d",         1.0,               true ),     // Day
    1888                 :            :     IntervalInfo( INTERVAL_W,       "w",         1.0,               true ),     // Weekday
    1889                 :            :     IntervalInfo( INTERVAL_WW,      "ww",        7.0,               true ),     // Week
    1890                 :            :     IntervalInfo( INTERVAL_H,       "h",        (1.0 /    24.0),    true ),     // Hour
    1891                 :            :     IntervalInfo( INTERVAL_N,       "n",        (1.0 /  1440.0),    true),      // Minute
    1892                 :            :     IntervalInfo( INTERVAL_S,       "s",        (1.0 / 86400.0),    true ),     // Second
    1893                 :            :     IntervalInfo( INTERVAL_NONE, NULL, 0.0, false )
    1894                 :        257 : };
    1895                 :            : 
    1896                 :          0 : IntervalInfo* getIntervalInfo( const String& rStringCode )
    1897                 :            : {
    1898                 :          0 :     IntervalInfo* pInfo = NULL;
    1899                 :          0 :     sal_Int16 i = 0;
    1900         [ #  # ]:          0 :     while( (pInfo = pIntervalTable + i)->mpStringCode != NULL )
    1901                 :            :     {
    1902         [ #  # ]:          0 :         if( rStringCode.EqualsIgnoreCaseAscii( pInfo->mpStringCode ) )
    1903                 :          0 :             break;
    1904                 :          0 :         i++;
    1905                 :            :     }
    1906                 :          0 :     return pInfo;
    1907                 :            : }
    1908                 :            : 
    1909                 :            : // From methods.cxx
    1910                 :            : bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, double& rdRet );
    1911                 :            : sal_Int16 implGetDateDay( double aDate );
    1912                 :            : sal_Int16 implGetDateMonth( double aDate );
    1913                 :            : sal_Int16 implGetDateYear( double aDate );
    1914                 :            : 
    1915                 :            : sal_Int16 implGetHour( double dDate );
    1916                 :            : sal_Int16 implGetMinute( double dDate );
    1917                 :            : sal_Int16 implGetSecond( double dDate );
    1918                 :            : 
    1919                 :            : 
    1920                 :          0 : inline void implGetDayMonthYear( sal_Int16& rnYear, sal_Int16& rnMonth, sal_Int16& rnDay, double dDate )
    1921                 :            : {
    1922                 :          0 :     rnDay   = implGetDateDay( dDate );
    1923                 :          0 :     rnMonth = implGetDateMonth( dDate );
    1924                 :          0 :     rnYear  = implGetDateYear( dDate );
    1925                 :          0 : }
    1926                 :            : 
    1927                 :          0 : inline sal_Int16 limitToINT16( sal_Int32 n32 )
    1928                 :            : {
    1929         [ #  # ]:          0 :     if( n32 > 32767 )
    1930                 :          0 :         n32 = 32767;
    1931         [ #  # ]:          0 :     else if( n32 < -32768 )
    1932                 :          0 :         n32 = -32768;
    1933                 :          0 :     return (sal_Int16)n32;
    1934                 :            : }
    1935                 :            : 
    1936                 :          0 : RTLFUNC(DateAdd)
    1937                 :            : {
    1938                 :            :     (void)pBasic;
    1939                 :            :     (void)bWrite;
    1940                 :            : 
    1941         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    1942         [ #  # ]:          0 :     if( nParCount != 4 )
    1943                 :            :     {
    1944         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1945                 :            :         return;
    1946                 :            :     }
    1947                 :            : 
    1948 [ #  # ][ #  # ]:          0 :     String aStringCode = rPar.Get(1)->GetString();
                 [ #  # ]
    1949         [ #  # ]:          0 :     IntervalInfo* pInfo = getIntervalInfo( aStringCode );
    1950         [ #  # ]:          0 :     if( !pInfo )
    1951                 :            :     {
    1952         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    1953                 :            :         return;
    1954                 :            :     }
    1955                 :            : 
    1956 [ #  # ][ #  # ]:          0 :     sal_Int32 lNumber = rPar.Get(2)->GetLong();
    1957 [ #  # ][ #  # ]:          0 :     double dDate = rPar.Get(3)->GetDate();
    1958                 :          0 :     double dNewDate = 0;
    1959         [ #  # ]:          0 :     if( pInfo->mbSimple )
    1960                 :            :     {
    1961                 :          0 :         double dAdd = pInfo->mdValue * lNumber;
    1962                 :          0 :         dNewDate = dDate + dAdd;
    1963                 :            :     }
    1964                 :            :     else
    1965                 :            :     {
    1966                 :            :         // Keep hours, minutes, seconds
    1967                 :          0 :         double dHoursMinutesSeconds = dDate - floor( dDate );
    1968                 :            : 
    1969                 :          0 :         bool bOk = true;
    1970                 :            :         sal_Int16 nYear, nMonth, nDay;
    1971                 :          0 :         sal_Int16 nTargetYear16 = 0, nTargetMonth = 0;
    1972         [ #  # ]:          0 :         implGetDayMonthYear( nYear, nMonth, nDay, dDate );
    1973      [ #  #  # ]:          0 :         switch( pInfo->meInterval )
    1974                 :            :         {
    1975                 :            :             case INTERVAL_YYYY:
    1976                 :            :             {
    1977                 :          0 :                 sal_Int32 nTargetYear = lNumber + nYear;
    1978                 :          0 :                 nTargetYear16 = limitToINT16( nTargetYear );
    1979                 :          0 :                 nTargetMonth = nMonth;
    1980         [ #  # ]:          0 :                 bOk = implDateSerial( nTargetYear16, nTargetMonth, nDay, dNewDate );
    1981                 :          0 :                 break;
    1982                 :            :             }
    1983                 :            :             case INTERVAL_Q:
    1984                 :            :             case INTERVAL_M:
    1985                 :            :             {
    1986                 :          0 :                 bool bNeg = (lNumber < 0);
    1987         [ #  # ]:          0 :                 if( bNeg )
    1988                 :          0 :                     lNumber = -lNumber;
    1989                 :            :                 sal_Int32 nYearsAdd;
    1990                 :            :                 sal_Int16 nMonthAdd;
    1991         [ #  # ]:          0 :                 if( pInfo->meInterval == INTERVAL_Q )
    1992                 :            :                 {
    1993                 :          0 :                     nYearsAdd = lNumber / 4;
    1994                 :          0 :                     nMonthAdd = (sal_Int16)( 3 * (lNumber % 4) );
    1995                 :            :                 }
    1996                 :            :                 else
    1997                 :            :                 {
    1998                 :          0 :                     nYearsAdd = lNumber / 12;
    1999                 :          0 :                     nMonthAdd = (sal_Int16)( lNumber % 12 );
    2000                 :            :                 }
    2001                 :            : 
    2002                 :            :                 sal_Int32 nTargetYear;
    2003         [ #  # ]:          0 :                 if( bNeg )
    2004                 :            :                 {
    2005                 :          0 :                     nTargetMonth = nMonth - nMonthAdd;
    2006         [ #  # ]:          0 :                     if( nTargetMonth <= 0 )
    2007                 :            :                     {
    2008                 :          0 :                         nTargetMonth += 12;
    2009                 :          0 :                         nYearsAdd++;
    2010                 :            :                     }
    2011                 :          0 :                     nTargetYear = (sal_Int32)nYear - nYearsAdd;
    2012                 :            :                 }
    2013                 :            :                 else
    2014                 :            :                 {
    2015                 :          0 :                     nTargetMonth = nMonth + nMonthAdd;
    2016         [ #  # ]:          0 :                     if( nTargetMonth > 12 )
    2017                 :            :                     {
    2018                 :          0 :                         nTargetMonth -= 12;
    2019                 :          0 :                         nYearsAdd++;
    2020                 :            :                     }
    2021                 :          0 :                     nTargetYear = (sal_Int32)nYear + nYearsAdd;
    2022                 :            :                 }
    2023                 :          0 :                 nTargetYear16 = limitToINT16( nTargetYear );
    2024         [ #  # ]:          0 :                 bOk = implDateSerial( nTargetYear16, nTargetMonth, nDay, dNewDate );
    2025                 :          0 :                 break;
    2026                 :            :             }
    2027                 :          0 :             default: break;
    2028                 :            :         }
    2029                 :            : 
    2030         [ #  # ]:          0 :         if( bOk )
    2031                 :            :         {
    2032                 :            :             // Overflow?
    2033                 :            :             sal_Int16 nNewYear, nNewMonth, nNewDay;
    2034         [ #  # ]:          0 :             implGetDayMonthYear( nNewYear, nNewMonth, nNewDay, dNewDate );
    2035 [ #  # ][ #  # ]:          0 :             if( nNewYear > 9999 || nNewYear < 100 )
    2036                 :            :             {
    2037         [ #  # ]:          0 :                 StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2038                 :            :                 return;
    2039                 :            :             }
    2040                 :          0 :             sal_Int16 nCorrectionDay = nDay;
    2041         [ #  # ]:          0 :             while( nNewMonth > nTargetMonth )
    2042                 :            :             {
    2043                 :          0 :                 nCorrectionDay--;
    2044         [ #  # ]:          0 :                 implDateSerial( nTargetYear16, nTargetMonth, nCorrectionDay, dNewDate );
    2045         [ #  # ]:          0 :                 implGetDayMonthYear( nNewYear, nNewMonth, nNewDay, dNewDate );
    2046                 :            :             }
    2047                 :          0 :             dNewDate += dHoursMinutesSeconds;
    2048                 :            :         }
    2049                 :            :     }
    2050                 :            : 
    2051 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutDate( dNewDate );
         [ #  # ][ #  # ]
    2052                 :            : }
    2053                 :            : 
    2054                 :          0 : inline double RoundImpl( double d )
    2055                 :            : {
    2056         [ #  # ]:          0 :     return ( d >= 0 ) ? floor( d + 0.5 ) : -floor( -d + 0.5 );
    2057                 :            : }
    2058                 :            : 
    2059                 :          0 : RTLFUNC(DateDiff)
    2060                 :            : {
    2061                 :            :     (void)pBasic;
    2062                 :            :     (void)bWrite;
    2063                 :            : 
    2064                 :            :     // DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
    2065                 :            : 
    2066         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    2067 [ #  # ][ #  # ]:          0 :     if( nParCount < 4 || nParCount > 6 )
    2068                 :            :     {
    2069         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2070                 :            :         return;
    2071                 :            :     }
    2072                 :            : 
    2073 [ #  # ][ #  # ]:          0 :     String aStringCode = rPar.Get(1)->GetString();
                 [ #  # ]
    2074         [ #  # ]:          0 :     IntervalInfo* pInfo = getIntervalInfo( aStringCode );
    2075         [ #  # ]:          0 :     if( !pInfo )
    2076                 :            :     {
    2077         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2078                 :            :         return;
    2079                 :            :     }
    2080                 :            : 
    2081 [ #  # ][ #  # ]:          0 :     double dDate1 = rPar.Get(2)->GetDate();
    2082 [ #  # ][ #  # ]:          0 :     double dDate2 = rPar.Get(3)->GetDate();
    2083                 :            : 
    2084                 :          0 :     double dRet = 0.0;
    2085   [ #  #  #  #  :          0 :     switch( pInfo->meInterval )
          #  #  #  #  #  
                      # ]
    2086                 :            :     {
    2087                 :            :         case INTERVAL_YYYY:
    2088                 :            :         {
    2089         [ #  # ]:          0 :             sal_Int16 nYear1 = implGetDateYear( dDate1 );
    2090         [ #  # ]:          0 :             sal_Int16 nYear2 = implGetDateYear( dDate2 );
    2091                 :          0 :             dRet = nYear2 - nYear1;
    2092                 :          0 :             break;
    2093                 :            :         }
    2094                 :            :         case INTERVAL_Q:
    2095                 :            :         {
    2096         [ #  # ]:          0 :             sal_Int16 nYear1 = implGetDateYear( dDate1 );
    2097         [ #  # ]:          0 :             sal_Int16 nYear2 = implGetDateYear( dDate2 );
    2098         [ #  # ]:          0 :             sal_Int16 nQ1 = 1 + (implGetDateMonth( dDate1 ) - 1) / 3;
    2099         [ #  # ]:          0 :             sal_Int16 nQ2 = 1 + (implGetDateMonth( dDate2 ) - 1) / 3;
    2100                 :          0 :             sal_Int16 nQGes1 = 4 * nYear1 + nQ1;
    2101                 :          0 :             sal_Int16 nQGes2 = 4 * nYear2 + nQ2;
    2102                 :          0 :             dRet = nQGes2 - nQGes1;
    2103                 :          0 :             break;
    2104                 :            :         }
    2105                 :            :         case INTERVAL_M:
    2106                 :            :         {
    2107         [ #  # ]:          0 :             sal_Int16 nYear1 = implGetDateYear( dDate1 );
    2108         [ #  # ]:          0 :             sal_Int16 nYear2 = implGetDateYear( dDate2 );
    2109         [ #  # ]:          0 :             sal_Int16 nMonth1 = implGetDateMonth( dDate1 );
    2110         [ #  # ]:          0 :             sal_Int16 nMonth2 = implGetDateMonth( dDate2 );
    2111                 :          0 :             sal_Int16 nMonthGes1 = 12 * nYear1 + nMonth1;
    2112                 :          0 :             sal_Int16 nMonthGes2 = 12 * nYear2 + nMonth2;
    2113                 :          0 :             dRet = nMonthGes2 - nMonthGes1;
    2114                 :          0 :             break;
    2115                 :            :         }
    2116                 :            :         case INTERVAL_Y:
    2117                 :            :         case INTERVAL_D:
    2118                 :            :         {
    2119                 :          0 :             double dDays1 = floor( dDate1 );
    2120                 :          0 :             double dDays2 = floor( dDate2 );
    2121                 :          0 :             dRet = dDays2 - dDays1;
    2122                 :          0 :             break;
    2123                 :            :         }
    2124                 :            :         case INTERVAL_W:
    2125                 :            :         case INTERVAL_WW:
    2126                 :            :         {
    2127                 :          0 :             double dDays1 = floor( dDate1 );
    2128                 :          0 :             double dDays2 = floor( dDate2 );
    2129         [ #  # ]:          0 :             if( pInfo->meInterval == INTERVAL_WW )
    2130                 :            :             {
    2131                 :          0 :                 sal_Int16 nFirstDay = 1;    // Default
    2132         [ #  # ]:          0 :                 if( nParCount >= 5 )
    2133                 :            :                 {
    2134 [ #  # ][ #  # ]:          0 :                     nFirstDay = rPar.Get(4)->GetInteger();
    2135 [ #  # ][ #  # ]:          0 :                     if( nFirstDay < 0 || nFirstDay > 7 )
    2136                 :            :                     {
    2137         [ #  # ]:          0 :                         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2138                 :            :                         return;
    2139                 :            :                     }
    2140         [ #  # ]:          0 :                     if( nFirstDay == 0 )
    2141                 :            :                     {
    2142         [ #  # ]:          0 :                         Reference< XCalendar3 > xCalendar = getLocaleCalendar();
    2143         [ #  # ]:          0 :                         if( !xCalendar.is() )
    2144                 :            :                         {
    2145         [ #  # ]:          0 :                             StarBASIC::Error( SbERR_INTERNAL_ERROR );
    2146                 :            :                             return;
    2147                 :            :                         }
    2148 [ #  # ][ #  # ]:          0 :                         nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 );
                 [ #  # ]
    2149                 :            :                     }
    2150                 :            :                 }
    2151         [ #  # ]:          0 :                 sal_Int16 nDay1 = implGetWeekDay( dDate1 );
    2152                 :          0 :                 sal_Int16 nDay1_Diff = nDay1 - nFirstDay;
    2153         [ #  # ]:          0 :                 if( nDay1_Diff < 0 )
    2154                 :          0 :                     nDay1_Diff += 7;
    2155                 :          0 :                 dDays1 -= nDay1_Diff;
    2156                 :            : 
    2157         [ #  # ]:          0 :                 sal_Int16 nDay2 = implGetWeekDay( dDate2 );
    2158                 :          0 :                 sal_Int16 nDay2_Diff = nDay2 - nFirstDay;
    2159         [ #  # ]:          0 :                 if( nDay2_Diff < 0 )
    2160                 :          0 :                     nDay2_Diff += 7;
    2161                 :          0 :                 dDays2 -= nDay2_Diff;
    2162                 :            :             }
    2163                 :            : 
    2164                 :          0 :             double dDiff = dDays2 - dDays1;
    2165         [ #  # ]:          0 :             dRet = ( dDiff >= 0 ) ? floor( dDiff / 7.0 ) : -floor( -dDiff / 7.0 );
    2166                 :          0 :             break;
    2167                 :            :         }
    2168                 :            :         case INTERVAL_H:
    2169                 :            :         {
    2170                 :          0 :             double dFactor = 24.0;
    2171                 :          0 :             dRet = RoundImpl( dFactor * (dDate2 - dDate1) );
    2172                 :          0 :             break;
    2173                 :            :         }
    2174                 :            :         case INTERVAL_N:
    2175                 :            :         {
    2176                 :          0 :             double dFactor =1440.0;
    2177                 :          0 :             dRet = RoundImpl( dFactor * (dDate2 - dDate1) );
    2178                 :          0 :             break;
    2179                 :            :         }
    2180                 :            :         case INTERVAL_S:
    2181                 :            :         {
    2182                 :          0 :             double dFactor = 86400.0;
    2183                 :          0 :             dRet = RoundImpl( dFactor * (dDate2 - dDate1) );
    2184                 :          0 :             break;
    2185                 :            :         }
    2186                 :            :         case INTERVAL_NONE:
    2187                 :          0 :             break;
    2188                 :            :     }
    2189 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutDouble( dRet );
         [ #  # ][ #  # ]
    2190                 :            : }
    2191                 :            : 
    2192                 :          0 : double implGetDateOfFirstDayInFirstWeek
    2193                 :            :     ( sal_Int16 nYear, sal_Int16& nFirstDay, sal_Int16& nFirstWeek, bool* pbError = NULL )
    2194                 :            : {
    2195                 :          0 :     SbError nError = 0;
    2196 [ #  # ][ #  # ]:          0 :     if( nFirstDay < 0 || nFirstDay > 7 )
    2197                 :          0 :         nError = SbERR_BAD_ARGUMENT;
    2198                 :            : 
    2199 [ #  # ][ #  # ]:          0 :     if( nFirstWeek < 0 || nFirstWeek > 3 )
    2200                 :          0 :         nError = SbERR_BAD_ARGUMENT;
    2201                 :            : 
    2202                 :          0 :     Reference< XCalendar3 > xCalendar;
    2203 [ #  # ][ #  # ]:          0 :     if( nFirstDay == 0 || nFirstWeek == 0 )
    2204                 :            :     {
    2205 [ #  # ][ #  # ]:          0 :         xCalendar = getLocaleCalendar();
    2206         [ #  # ]:          0 :         if( !xCalendar.is() )
    2207                 :          0 :             nError = SbERR_BAD_ARGUMENT;
    2208                 :            :     }
    2209                 :            : 
    2210         [ #  # ]:          0 :     if( nError != 0 )
    2211                 :            :     {
    2212         [ #  # ]:          0 :         StarBASIC::Error( nError );
    2213         [ #  # ]:          0 :         if( pbError )
    2214                 :          0 :             *pbError = true;
    2215                 :          0 :         return 0.0;
    2216                 :            :     }
    2217                 :            : 
    2218         [ #  # ]:          0 :     if( nFirstDay == 0 )
    2219 [ #  # ][ #  # ]:          0 :         nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 );
    2220                 :            : 
    2221                 :          0 :     sal_Int16 nFirstWeekMinDays = 0;    // Not used for vbFirstJan1 = default
    2222         [ #  # ]:          0 :     if( nFirstWeek == 0 )
    2223                 :            :     {
    2224 [ #  # ][ #  # ]:          0 :         nFirstWeekMinDays = xCalendar->getMinimumNumberOfDaysForFirstWeek();
    2225         [ #  # ]:          0 :         if( nFirstWeekMinDays == 1 )
    2226                 :            :         {
    2227                 :          0 :             nFirstWeekMinDays = 0;
    2228                 :          0 :             nFirstWeek = 1;
    2229                 :            :         }
    2230         [ #  # ]:          0 :         else if( nFirstWeekMinDays == 4 )
    2231                 :          0 :             nFirstWeek = 2;
    2232         [ #  # ]:          0 :         else if( nFirstWeekMinDays == 7 )
    2233                 :          0 :             nFirstWeek = 3;
    2234                 :            :     }
    2235         [ #  # ]:          0 :     else if( nFirstWeek == 2 )
    2236                 :          0 :         nFirstWeekMinDays = 4;      // vbFirstFourDays
    2237         [ #  # ]:          0 :     else if( nFirstWeek == 3 )
    2238                 :          0 :         nFirstWeekMinDays = 7;      // vbFirstFourDays
    2239                 :            : 
    2240                 :            :     double dBaseDate;
    2241         [ #  # ]:          0 :     implDateSerial( nYear, 1, 1, dBaseDate );
    2242                 :          0 :     double dRetDate = dBaseDate;
    2243                 :            : 
    2244         [ #  # ]:          0 :     sal_Int16 nWeekDay0101 = implGetWeekDay( dBaseDate );
    2245                 :          0 :     sal_Int16 nDayDiff = nWeekDay0101 - nFirstDay;
    2246         [ #  # ]:          0 :     if( nDayDiff < 0 )
    2247                 :          0 :         nDayDiff += 7;
    2248                 :            : 
    2249         [ #  # ]:          0 :     if( nFirstWeekMinDays )
    2250                 :            :     {
    2251                 :          0 :         sal_Int16 nThisWeeksDaysInYearCount = 7 - nDayDiff;
    2252         [ #  # ]:          0 :         if( nThisWeeksDaysInYearCount < nFirstWeekMinDays )
    2253                 :          0 :             nDayDiff -= 7;
    2254                 :            :     }
    2255                 :          0 :     dRetDate = dBaseDate - nDayDiff;
    2256                 :          0 :     return dRetDate;
    2257                 :            : }
    2258                 :            : 
    2259                 :          0 : RTLFUNC(DatePart)
    2260                 :            : {
    2261                 :            :     (void)pBasic;
    2262                 :            :     (void)bWrite;
    2263                 :            : 
    2264                 :            :     // DatePart(interval, date[,firstdayofweek[, firstweekofyear]])
    2265                 :            : 
    2266         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    2267 [ #  # ][ #  # ]:          0 :     if( nParCount < 3 || nParCount > 5 )
    2268                 :            :     {
    2269         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2270                 :            :         return;
    2271                 :            :     }
    2272                 :            : 
    2273 [ #  # ][ #  # ]:          0 :     String aStringCode = rPar.Get(1)->GetString();
                 [ #  # ]
    2274         [ #  # ]:          0 :     IntervalInfo* pInfo = getIntervalInfo( aStringCode );
    2275         [ #  # ]:          0 :     if( !pInfo )
    2276                 :            :     {
    2277         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2278                 :            :         return;
    2279                 :            :     }
    2280                 :            : 
    2281 [ #  # ][ #  # ]:          0 :     double dDate = rPar.Get(2)->GetDate();
    2282                 :            : 
    2283                 :          0 :     sal_Int32 nRet = 0;
    2284   [ #  #  #  #  :          0 :     switch( pInfo->meInterval )
          #  #  #  #  #  
                #  #  # ]
    2285                 :            :     {
    2286                 :            :         case INTERVAL_YYYY:
    2287                 :            :         {
    2288         [ #  # ]:          0 :             nRet = implGetDateYear( dDate );
    2289                 :          0 :             break;
    2290                 :            :         }
    2291                 :            :         case INTERVAL_Q:
    2292                 :            :         {
    2293         [ #  # ]:          0 :             nRet = 1 + (implGetDateMonth( dDate ) - 1) / 3;
    2294                 :          0 :             break;
    2295                 :            :         }
    2296                 :            :         case INTERVAL_M:
    2297                 :            :         {
    2298         [ #  # ]:          0 :             nRet = implGetDateMonth( dDate );
    2299                 :          0 :             break;
    2300                 :            :         }
    2301                 :            :         case INTERVAL_Y:
    2302                 :            :         {
    2303         [ #  # ]:          0 :             sal_Int16 nYear = implGetDateYear( dDate );
    2304                 :            :             double dBaseDate;
    2305         [ #  # ]:          0 :             implDateSerial( nYear, 1, 1, dBaseDate );
    2306                 :          0 :             nRet = 1 + sal_Int32( dDate - dBaseDate );
    2307                 :            :             break;
    2308                 :            :         }
    2309                 :            :         case INTERVAL_D:
    2310                 :            :         {
    2311         [ #  # ]:          0 :             nRet = implGetDateDay( dDate );
    2312                 :          0 :             break;
    2313                 :            :         }
    2314                 :            :         case INTERVAL_W:
    2315                 :            :         {
    2316                 :          0 :             bool bFirstDay = false;
    2317                 :          0 :             sal_Int16 nFirstDay = 1;    // Default
    2318         [ #  # ]:          0 :             if( nParCount >= 4 )
    2319                 :            :             {
    2320 [ #  # ][ #  # ]:          0 :                 nFirstDay = rPar.Get(3)->GetInteger();
    2321                 :          0 :                 bFirstDay = true;
    2322                 :            :             }
    2323         [ #  # ]:          0 :             nRet = implGetWeekDay( dDate, bFirstDay, nFirstDay );
    2324                 :          0 :             break;
    2325                 :            :         }
    2326                 :            :         case INTERVAL_WW:
    2327                 :            :         {
    2328                 :          0 :             sal_Int16 nFirstDay = 1;    // Default
    2329         [ #  # ]:          0 :             if( nParCount >= 4 )
    2330 [ #  # ][ #  # ]:          0 :                 nFirstDay = rPar.Get(3)->GetInteger();
    2331                 :            : 
    2332                 :          0 :             sal_Int16 nFirstWeek = 1;   // Default
    2333         [ #  # ]:          0 :             if( nParCount == 5 )
    2334 [ #  # ][ #  # ]:          0 :                 nFirstWeek = rPar.Get(4)->GetInteger();
    2335                 :            : 
    2336         [ #  # ]:          0 :             sal_Int16 nYear = implGetDateYear( dDate );
    2337                 :          0 :             bool bError = false;
    2338         [ #  # ]:          0 :             double dYearFirstDay = implGetDateOfFirstDayInFirstWeek( nYear, nFirstDay, nFirstWeek, &bError );
    2339         [ #  # ]:          0 :             if( !bError )
    2340                 :            :             {
    2341         [ #  # ]:          0 :                 if( dYearFirstDay > dDate )
    2342                 :            :                 {
    2343                 :            :                     // Date belongs to last year's week
    2344         [ #  # ]:          0 :                     dYearFirstDay = implGetDateOfFirstDayInFirstWeek( nYear - 1, nFirstDay, nFirstWeek );
    2345                 :            :                 }
    2346         [ #  # ]:          0 :                 else if( nFirstWeek != 1 )
    2347                 :            :                 {
    2348                 :            :                     // Check if date belongs to next year
    2349         [ #  # ]:          0 :                     double dNextYearFirstDay = implGetDateOfFirstDayInFirstWeek( nYear + 1, nFirstDay, nFirstWeek );
    2350         [ #  # ]:          0 :                     if( dDate >= dNextYearFirstDay )
    2351                 :          0 :                         dYearFirstDay = dNextYearFirstDay;
    2352                 :            :                 }
    2353                 :            : 
    2354                 :            :                 // Calculate week
    2355                 :          0 :                 double dDiff = dDate - dYearFirstDay;
    2356                 :          0 :                 nRet = 1 + sal_Int32( dDiff / 7 );
    2357                 :            :             }
    2358                 :            :             break;
    2359                 :            :         }
    2360                 :            :         case INTERVAL_H:
    2361                 :            :         {
    2362         [ #  # ]:          0 :             nRet = implGetHour( dDate );
    2363                 :          0 :             break;
    2364                 :            :         }
    2365                 :            :         case INTERVAL_N:
    2366                 :            :         {
    2367         [ #  # ]:          0 :             nRet = implGetMinute( dDate );
    2368                 :          0 :             break;
    2369                 :            :         }
    2370                 :            :         case INTERVAL_S:
    2371                 :            :         {
    2372         [ #  # ]:          0 :             nRet = implGetSecond( dDate );
    2373                 :          0 :             break;
    2374                 :            :         }
    2375                 :            :         case INTERVAL_NONE:
    2376                 :          0 :             break;
    2377                 :            :     }
    2378 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutLong( nRet );
         [ #  # ][ #  # ]
    2379                 :            : }
    2380                 :            : 
    2381                 :            : // FormatDateTime(Date[,NamedFormat])
    2382                 :          0 : RTLFUNC(FormatDateTime)
    2383                 :            : {
    2384                 :            :     (void)pBasic;
    2385                 :            :     (void)bWrite;
    2386                 :            : 
    2387         [ #  # ]:          0 :     sal_uInt16 nParCount = rPar.Count();
    2388 [ #  # ][ #  # ]:          0 :     if( nParCount < 2 || nParCount > 3 )
    2389                 :            :     {
    2390         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2391                 :            :         return;
    2392                 :            :     }
    2393                 :            : 
    2394 [ #  # ][ #  # ]:          0 :     double dDate = rPar.Get(1)->GetDate();
    2395                 :          0 :     sal_Int16 nNamedFormat = 0;
    2396         [ #  # ]:          0 :     if( nParCount > 2 )
    2397                 :            :     {
    2398 [ #  # ][ #  # ]:          0 :         nNamedFormat = rPar.Get(2)->GetInteger();
    2399 [ #  # ][ #  # ]:          0 :         if( nNamedFormat < 0 || nNamedFormat > 4 )
    2400                 :            :         {
    2401         [ #  # ]:          0 :             StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2402                 :            :             return;
    2403                 :            :         }
    2404                 :            :     }
    2405                 :            : 
    2406         [ #  # ]:          0 :     Reference< XCalendar3 > xCalendar = getLocaleCalendar();
    2407         [ #  # ]:          0 :     if( !xCalendar.is() )
    2408                 :            :     {
    2409         [ #  # ]:          0 :         StarBASIC::Error( SbERR_INTERNAL_ERROR );
    2410                 :            :         return;
    2411                 :            :     }
    2412                 :            : 
    2413         [ #  # ]:          0 :     String aRetStr;
    2414 [ #  # ][ #  # ]:          0 :     SbxVariableRef pSbxVar = new SbxVariable( SbxSTRING );
    2415   [ #  #  #  #  :          0 :     switch( nNamedFormat )
                      # ]
    2416                 :            :     {
    2417                 :            :         // GeneralDate:
    2418                 :            :         // Display a date and/or time. If there is a date part,
    2419                 :            :         // display it as a short date. If there is a time part,
    2420                 :            :         // display it as a long time. If present, both parts are displayed.
    2421                 :            : 
    2422                 :            :         // 12/21/2004 11:24:50 AM
    2423                 :            :         // 21.12.2004 12:13:51
    2424                 :            :         case 0:
    2425         [ #  # ]:          0 :             pSbxVar->PutDate( dDate );
    2426 [ #  # ][ #  # ]:          0 :             aRetStr = pSbxVar->GetString();
    2427                 :            :             break;
    2428                 :            : 
    2429                 :            :         // LongDate: Display a date using the long date format specified
    2430                 :            :         // in your computer's regional settings.
    2431                 :            :         // Tuesday, December 21, 2004
    2432                 :            :         // Dienstag, 21. December 2004
    2433                 :            :         case 1:
    2434                 :            :         {
    2435                 :          0 :             SvNumberFormatter* pFormatter = NULL;
    2436 [ #  # ][ #  # ]:          0 :             if( GetSbData()->pInst )
    2437 [ #  # ][ #  # ]:          0 :                 pFormatter = GetSbData()->pInst->GetNumberFormatter();
    2438                 :            :             else
    2439                 :            :             {
    2440                 :            :                 sal_uInt32 n;   // Dummy
    2441         [ #  # ]:          0 :                 SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n );
    2442                 :            :             }
    2443                 :            : 
    2444 [ #  # ][ #  # ]:          0 :             LanguageType eLangType = GetpApp()->GetSettings().GetLanguage();
                 [ #  # ]
    2445         [ #  # ]:          0 :             sal_uIntPtr nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_LONG, eLangType );
    2446                 :            :             Color* pCol;
    2447         [ #  # ]:          0 :             pFormatter->GetOutputString( dDate, nIndex, aRetStr, &pCol );
    2448                 :            : 
    2449 [ #  # ][ #  # ]:          0 :             if( !GetSbData()->pInst )
    2450 [ #  # ][ #  # ]:          0 :                 delete pFormatter;
    2451                 :            : 
    2452                 :            :             break;
    2453                 :            :         }
    2454                 :            : 
    2455                 :            :         // ShortDate: Display a date using the short date format specified
    2456                 :            :         // in your computer's regional settings.
    2457                 :            :         // 21.12.2004
    2458                 :            :         case 2:
    2459         [ #  # ]:          0 :             pSbxVar->PutDate( floor(dDate) );
    2460 [ #  # ][ #  # ]:          0 :             aRetStr = pSbxVar->GetString();
    2461                 :            :             break;
    2462                 :            : 
    2463                 :            :         // LongTime: Display a time using the time format specified
    2464                 :            :         // in your computer's regional settings.
    2465                 :            :         // 11:24:50 AM
    2466                 :            :         // 12:13:51
    2467                 :            :         case 3:
    2468                 :            :         // ShortTime: Display a time using the 24-hour format (hh:mm).
    2469                 :            :         // 11:24
    2470                 :            :         case 4:
    2471                 :            :             double n;
    2472                 :          0 :             double dTime = modf( dDate, &n );
    2473         [ #  # ]:          0 :             pSbxVar->PutDate( dTime );
    2474         [ #  # ]:          0 :             if( nNamedFormat == 3 )
    2475 [ #  # ][ #  # ]:          0 :                 aRetStr = pSbxVar->GetString();
    2476                 :            :             else
    2477 [ #  # ][ #  # ]:          0 :                 aRetStr = pSbxVar->GetString().Copy( 0, 5 );
         [ #  # ][ #  # ]
    2478                 :            :             break;
    2479                 :            :     }
    2480                 :            : 
    2481 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString( aRetStr );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2482                 :            : }
    2483                 :            : 
    2484                 :          0 : RTLFUNC(Frac)
    2485                 :            : {
    2486                 :            :     (void)pBasic;
    2487                 :            :     (void)bWrite;
    2488                 :            : 
    2489                 :          0 :     sal_uInt16 nParCount = rPar.Count();
    2490         [ #  # ]:          0 :     if( nParCount != 2)
    2491                 :            :     {
    2492                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2493                 :          0 :         return;
    2494                 :            :     }
    2495                 :            : 
    2496                 :          0 :     SbxVariable *pSbxVariable = rPar.Get(1);
    2497                 :          0 :     double dVal = pSbxVariable->GetDouble();
    2498         [ #  # ]:          0 :     if(dVal >= 0)
    2499                 :          0 :         rPar.Get(0)->PutDouble(dVal - ::rtl::math::approxFloor(dVal));
    2500                 :            :     else
    2501                 :          0 :         rPar.Get(0)->PutDouble(dVal - ::rtl::math::approxCeil(dVal));
    2502                 :            : }
    2503                 :            : 
    2504                 :          0 : RTLFUNC(Round)
    2505                 :            : {
    2506                 :            :     (void)pBasic;
    2507                 :            :     (void)bWrite;
    2508                 :            : 
    2509                 :          0 :     sal_uInt16 nParCount = rPar.Count();
    2510 [ #  # ][ #  # ]:          0 :     if( nParCount != 2 && nParCount != 3 )
    2511                 :            :     {
    2512                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2513                 :          0 :         return;
    2514                 :            :     }
    2515                 :            : 
    2516                 :          0 :     SbxVariable *pSbxVariable = rPar.Get(1);
    2517                 :          0 :     double dVal = pSbxVariable->GetDouble();
    2518                 :          0 :     double dRes = 0.0;
    2519         [ #  # ]:          0 :     if( dVal != 0.0 )
    2520                 :            :     {
    2521                 :          0 :         bool bNeg = false;
    2522         [ #  # ]:          0 :         if( dVal < 0.0 )
    2523                 :            :         {
    2524                 :          0 :             bNeg = true;
    2525                 :          0 :             dVal = -dVal;
    2526                 :            :         }
    2527                 :            : 
    2528                 :          0 :         sal_Int16 numdecimalplaces = 0;
    2529         [ #  # ]:          0 :         if( nParCount == 3 )
    2530                 :            :         {
    2531                 :          0 :             numdecimalplaces = rPar.Get(2)->GetInteger();
    2532 [ #  # ][ #  # ]:          0 :             if( numdecimalplaces < 0 || numdecimalplaces > 22 )
    2533                 :            :             {
    2534                 :          0 :                 StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2535                 :          0 :                 return;
    2536                 :            :             }
    2537                 :            :         }
    2538                 :            : 
    2539         [ #  # ]:          0 :         if( numdecimalplaces == 0 )
    2540                 :            :         {
    2541                 :          0 :             dRes = floor( dVal + 0.5 );
    2542                 :            :         }
    2543                 :            :         else
    2544                 :            :         {
    2545                 :          0 :             double dFactor = pow( 10.0, numdecimalplaces );
    2546                 :          0 :             dVal *= dFactor;
    2547                 :          0 :             dRes = floor( dVal + 0.5 );
    2548                 :          0 :             dRes /= dFactor;
    2549                 :            :         }
    2550                 :            : 
    2551         [ #  # ]:          0 :         if( bNeg )
    2552                 :          0 :             dRes = -dRes;
    2553                 :            :     }
    2554                 :          0 :     rPar.Get(0)->PutDouble( dRes );
    2555                 :            : }
    2556                 :            : 
    2557                 :          0 : void CallFunctionAccessFunction( const Sequence< Any >& aArgs, const rtl::OUString& sFuncName, SbxVariable* pRet )
    2558                 :            : {
    2559 [ #  # ][ #  # ]:          0 :     static Reference< XFunctionAccess > xFunc;
    2560                 :          0 :     Any aRes;
    2561                 :            :     try
    2562                 :            :     {
    2563         [ #  # ]:          0 :         if ( !xFunc.is() )
    2564                 :            :         {
    2565         [ #  # ]:          0 :             Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
    2566         [ #  # ]:          0 :             if( xFactory.is() )
    2567                 :            :             {
    2568 [ #  # ][ #  # ]:          0 :                 xFunc.set( xFactory->createInstance(::rtl::OUString("com.sun.star.sheet.FunctionAccess")), UNO_QUERY_THROW);
                 [ #  # ]
    2569                 :          0 :             }
    2570                 :            :         }
    2571 [ #  # ][ #  # ]:          0 :         Any aRet = xFunc->callFunction( sFuncName, aArgs );
    2572                 :            : 
    2573         [ #  # ]:          0 :         unoToSbxValue( pRet, aRet );
    2574                 :            : 
    2575                 :            :     }
    2576   [ #  #  #  # ]:          0 :     catch(const Exception& )
    2577                 :            :     {
    2578         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2579                 :          0 :     }
    2580                 :          0 : }
    2581                 :            : 
    2582                 :          0 : RTLFUNC(SYD)
    2583                 :            : {
    2584                 :            :     (void)pBasic;
    2585                 :            :     (void)bWrite;
    2586                 :            : 
    2587         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2588                 :            : 
    2589         [ #  # ]:          0 :     if ( nArgCount < 4 )
    2590                 :            :     {
    2591         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2592                 :          0 :         return;
    2593                 :            :     }
    2594                 :            : 
    2595                 :            :     // retrieve non-optional params
    2596                 :            : 
    2597         [ #  # ]:          0 :     Sequence< Any > aParams( 4 );
    2598 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= makeAny( rPar.Get(1)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2599 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= makeAny( rPar.Get(2)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2600 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= makeAny( rPar.Get(3)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2601 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= makeAny( rPar.Get(4)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2602                 :            : 
    2603 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "SYD" ), rPar.Get( 0 ) );
                 [ #  # ]
    2604                 :            : }
    2605                 :            : 
    2606                 :          0 : RTLFUNC(SLN)
    2607                 :            : {
    2608                 :            :     (void)pBasic;
    2609                 :            :     (void)bWrite;
    2610                 :            : 
    2611         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2612                 :            : 
    2613         [ #  # ]:          0 :     if ( nArgCount < 3 )
    2614                 :            :     {
    2615         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2616                 :          0 :         return;
    2617                 :            :     }
    2618                 :            : 
    2619                 :            :     // retrieve non-optional params
    2620                 :            : 
    2621         [ #  # ]:          0 :     Sequence< Any > aParams( 3 );
    2622 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= makeAny( rPar.Get(1)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2623 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= makeAny( rPar.Get(2)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2624 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= makeAny( rPar.Get(3)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2625                 :            : 
    2626 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "SLN" ), rPar.Get( 0 ) );
                 [ #  # ]
    2627                 :            : }
    2628                 :            : 
    2629                 :          0 : RTLFUNC(Pmt)
    2630                 :            : {
    2631                 :            :     (void)pBasic;
    2632                 :            :     (void)bWrite;
    2633                 :            : 
    2634         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2635                 :            : 
    2636 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 3 || nArgCount > 5 )
    2637                 :            :     {
    2638         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2639                 :          0 :         return;
    2640                 :            :     }
    2641                 :            :     // retrieve non-optional params
    2642                 :            : 
    2643 [ #  # ][ #  # ]:          0 :     double rate = rPar.Get(1)->GetDouble();
    2644 [ #  # ][ #  # ]:          0 :     double nper = rPar.Get(2)->GetDouble();
    2645 [ #  # ][ #  # ]:          0 :     double pmt = rPar.Get(3)->GetDouble();
    2646                 :            : 
    2647                 :            :     // set default values for Optional args
    2648                 :          0 :     double fv = 0;
    2649                 :          0 :     double type = 0;
    2650                 :            : 
    2651                 :            :     // fv
    2652         [ #  # ]:          0 :     if ( nArgCount >= 4 )
    2653                 :            :     {
    2654 [ #  # ][ #  # ]:          0 :         if( rPar.Get(4)->GetType() != SbxEMPTY )
                 [ #  # ]
    2655 [ #  # ][ #  # ]:          0 :             fv = rPar.Get(4)->GetDouble();
    2656                 :            :     }
    2657                 :            :     // type
    2658         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    2659                 :            :     {
    2660 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    2661 [ #  # ][ #  # ]:          0 :             type = rPar.Get(5)->GetDouble();
    2662                 :            :     }
    2663                 :            : 
    2664         [ #  # ]:          0 :     Sequence< Any > aParams( 5 );
    2665 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= rate;
    2666 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= nper;
    2667 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= pmt;
    2668 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= fv;
    2669 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= type;
    2670                 :            : 
    2671 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "Pmt" ), rPar.Get( 0 ) );
                 [ #  # ]
    2672                 :            : }
    2673                 :            : 
    2674                 :          0 : RTLFUNC(PPmt)
    2675                 :            : {
    2676                 :            :     (void)pBasic;
    2677                 :            :     (void)bWrite;
    2678                 :            : 
    2679         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2680                 :            : 
    2681 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 4 || nArgCount > 6 )
    2682                 :            :     {
    2683         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2684                 :          0 :         return;
    2685                 :            :     }
    2686                 :            :     // retrieve non-optional params
    2687                 :            : 
    2688 [ #  # ][ #  # ]:          0 :     double rate = rPar.Get(1)->GetDouble();
    2689 [ #  # ][ #  # ]:          0 :     double per = rPar.Get(2)->GetDouble();
    2690 [ #  # ][ #  # ]:          0 :     double nper = rPar.Get(3)->GetDouble();
    2691 [ #  # ][ #  # ]:          0 :     double pv = rPar.Get(4)->GetDouble();
    2692                 :            : 
    2693                 :            :     // set default values for Optional args
    2694                 :          0 :     double fv = 0;
    2695                 :          0 :     double type = 0;
    2696                 :            : 
    2697                 :            :     // fv
    2698         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    2699                 :            :     {
    2700 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    2701 [ #  # ][ #  # ]:          0 :             fv = rPar.Get(5)->GetDouble();
    2702                 :            :     }
    2703                 :            :     // type
    2704         [ #  # ]:          0 :     if ( nArgCount >= 6 )
    2705                 :            :     {
    2706 [ #  # ][ #  # ]:          0 :         if( rPar.Get(6)->GetType() != SbxEMPTY )
                 [ #  # ]
    2707 [ #  # ][ #  # ]:          0 :             type = rPar.Get(6)->GetDouble();
    2708                 :            :     }
    2709                 :            : 
    2710         [ #  # ]:          0 :     Sequence< Any > aParams( 6 );
    2711 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= rate;
    2712 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= per;
    2713 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= nper;
    2714 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= pv;
    2715 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= fv;
    2716 [ #  # ][ #  # ]:          0 :     aParams[ 5 ] <<= type;
    2717                 :            : 
    2718 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "PPmt" ), rPar.Get( 0 ) );
                 [ #  # ]
    2719                 :            : }
    2720                 :            : 
    2721                 :          0 : RTLFUNC(PV)
    2722                 :            : {
    2723                 :            :     (void)pBasic;
    2724                 :            :     (void)bWrite;
    2725                 :            : 
    2726         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2727                 :            : 
    2728 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 3 || nArgCount > 5 )
    2729                 :            :     {
    2730         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2731                 :          0 :         return;
    2732                 :            :     }
    2733                 :            :     // retrieve non-optional params
    2734                 :            : 
    2735 [ #  # ][ #  # ]:          0 :     double rate = rPar.Get(1)->GetDouble();
    2736 [ #  # ][ #  # ]:          0 :     double nper = rPar.Get(2)->GetDouble();
    2737 [ #  # ][ #  # ]:          0 :     double pmt = rPar.Get(3)->GetDouble();
    2738                 :            : 
    2739                 :            :     // set default values for Optional args
    2740                 :          0 :     double fv = 0;
    2741                 :          0 :     double type = 0;
    2742                 :            : 
    2743                 :            :     // fv
    2744         [ #  # ]:          0 :     if ( nArgCount >= 4 )
    2745                 :            :     {
    2746 [ #  # ][ #  # ]:          0 :         if( rPar.Get(4)->GetType() != SbxEMPTY )
                 [ #  # ]
    2747 [ #  # ][ #  # ]:          0 :             fv = rPar.Get(4)->GetDouble();
    2748                 :            :     }
    2749                 :            :     // type
    2750         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    2751                 :            :     {
    2752 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    2753 [ #  # ][ #  # ]:          0 :             type = rPar.Get(5)->GetDouble();
    2754                 :            :     }
    2755                 :            : 
    2756         [ #  # ]:          0 :     Sequence< Any > aParams( 5 );
    2757 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= rate;
    2758 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= nper;
    2759 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= pmt;
    2760 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= fv;
    2761 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= type;
    2762                 :            : 
    2763 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "PV" ), rPar.Get( 0 ) );
                 [ #  # ]
    2764                 :            : }
    2765                 :            : 
    2766                 :          0 : RTLFUNC(NPV)
    2767                 :            : {
    2768                 :            :     (void)pBasic;
    2769                 :            :     (void)bWrite;
    2770                 :            : 
    2771         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2772                 :            : 
    2773 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 1 || nArgCount > 2 )
    2774                 :            :     {
    2775         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2776                 :          0 :         return;
    2777                 :            :     }
    2778                 :            : 
    2779         [ #  # ]:          0 :     Sequence< Any > aParams( 2 );
    2780 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= makeAny( rPar.Get(1)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2781                 :            :     Any aValues = sbxToUnoValue( rPar.Get(2),
    2782 [ #  # ][ #  # ]:          0 :                 getCppuType( (Sequence<double>*)0 ) );
                 [ #  # ]
    2783                 :            : 
    2784                 :            :     // convert for calc functions
    2785         [ #  # ]:          0 :     Sequence< Sequence< double > > sValues(1);
    2786 [ #  # ][ #  # ]:          0 :     aValues >>= sValues[ 0 ];
    2787         [ #  # ]:          0 :     aValues <<= sValues;
    2788                 :            : 
    2789 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= aValues;
    2790                 :            : 
    2791 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "NPV" ), rPar.Get( 0 ) );
         [ #  # ][ #  # ]
    2792                 :            : }
    2793                 :            : 
    2794                 :          0 : RTLFUNC(NPer)
    2795                 :            : {
    2796                 :            :     (void)pBasic;
    2797                 :            :     (void)bWrite;
    2798                 :            : 
    2799         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2800                 :            : 
    2801 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 3 || nArgCount > 5 )
    2802                 :            :     {
    2803         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2804                 :          0 :         return;
    2805                 :            :     }
    2806                 :            :     // retrieve non-optional params
    2807                 :            : 
    2808 [ #  # ][ #  # ]:          0 :     double rate = rPar.Get(1)->GetDouble();
    2809 [ #  # ][ #  # ]:          0 :     double pmt = rPar.Get(2)->GetDouble();
    2810 [ #  # ][ #  # ]:          0 :     double pv = rPar.Get(3)->GetDouble();
    2811                 :            : 
    2812                 :            :     // set default values for Optional args
    2813                 :          0 :     double fv = 0;
    2814                 :          0 :     double type = 0;
    2815                 :            : 
    2816                 :            :     // fv
    2817         [ #  # ]:          0 :     if ( nArgCount >= 4 )
    2818                 :            :     {
    2819 [ #  # ][ #  # ]:          0 :         if( rPar.Get(4)->GetType() != SbxEMPTY )
                 [ #  # ]
    2820 [ #  # ][ #  # ]:          0 :             fv = rPar.Get(4)->GetDouble();
    2821                 :            :     }
    2822                 :            :     // type
    2823         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    2824                 :            :     {
    2825 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    2826 [ #  # ][ #  # ]:          0 :             type = rPar.Get(5)->GetDouble();
    2827                 :            :     }
    2828                 :            : 
    2829         [ #  # ]:          0 :     Sequence< Any > aParams( 5 );
    2830 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= rate;
    2831 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= pmt;
    2832 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= pv;
    2833 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= fv;
    2834 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= type;
    2835                 :            : 
    2836 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "NPer" ), rPar.Get( 0 ) );
                 [ #  # ]
    2837                 :            : }
    2838                 :            : 
    2839                 :          0 : RTLFUNC(MIRR)
    2840                 :            : {
    2841                 :            :     (void)pBasic;
    2842                 :            :     (void)bWrite;
    2843                 :            : 
    2844         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2845                 :            : 
    2846         [ #  # ]:          0 :     if ( nArgCount < 3 )
    2847                 :            :     {
    2848         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2849                 :          0 :         return;
    2850                 :            :     }
    2851                 :            : 
    2852                 :            :     // retrieve non-optional params
    2853                 :            : 
    2854         [ #  # ]:          0 :     Sequence< Any > aParams( 3 );
    2855                 :            :     Any aValues = sbxToUnoValue( rPar.Get(1),
    2856 [ #  # ][ #  # ]:          0 :                 getCppuType( (Sequence<double>*)0 ) );
                 [ #  # ]
    2857                 :            : 
    2858                 :            :     // convert for calc functions
    2859         [ #  # ]:          0 :     Sequence< Sequence< double > > sValues(1);
    2860 [ #  # ][ #  # ]:          0 :     aValues >>= sValues[ 0 ];
    2861         [ #  # ]:          0 :     aValues <<= sValues;
    2862                 :            : 
    2863 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= aValues;
    2864 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= makeAny( rPar.Get(2)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2865 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= makeAny( rPar.Get(3)->GetDouble() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2866                 :            : 
    2867 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "MIRR" ), rPar.Get( 0 ) );
         [ #  # ][ #  # ]
    2868                 :            : }
    2869                 :            : 
    2870                 :          0 : RTLFUNC(IRR)
    2871                 :            : {
    2872                 :            :     (void)pBasic;
    2873                 :            :     (void)bWrite;
    2874                 :            : 
    2875         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2876                 :            : 
    2877 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 1 || nArgCount > 2 )
    2878                 :            :     {
    2879         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2880                 :          0 :         return;
    2881                 :            :     }
    2882                 :            :     // retrieve non-optional params
    2883                 :            :     Any aValues = sbxToUnoValue( rPar.Get(1),
    2884 [ #  # ][ #  # ]:          0 :                 getCppuType( (Sequence<double>*)0 ) );
                 [ #  # ]
    2885                 :            : 
    2886                 :            :     // convert for calc functions
    2887         [ #  # ]:          0 :     Sequence< Sequence< double > > sValues(1);
    2888 [ #  # ][ #  # ]:          0 :     aValues >>= sValues[ 0 ];
    2889         [ #  # ]:          0 :     aValues <<= sValues;
    2890                 :            : 
    2891                 :            :     // set default values for Optional args
    2892                 :          0 :     double guess = 0.1;
    2893                 :            :     // guess
    2894         [ #  # ]:          0 :     if ( nArgCount >= 2 )
    2895                 :            :     {
    2896 [ #  # ][ #  # ]:          0 :         if( rPar.Get(2)->GetType() != SbxEMPTY )
                 [ #  # ]
    2897 [ #  # ][ #  # ]:          0 :             guess = rPar.Get(2)->GetDouble();
    2898                 :            :     }
    2899                 :            : 
    2900         [ #  # ]:          0 :     Sequence< Any > aParams( 2 );
    2901 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= aValues;
    2902 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= guess;
    2903                 :            : 
    2904 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "IRR" ), rPar.Get( 0 ) );
         [ #  # ][ #  # ]
    2905                 :            : }
    2906                 :            : 
    2907                 :          0 : RTLFUNC(IPmt)
    2908                 :            : {
    2909                 :            :     (void)pBasic;
    2910                 :            :     (void)bWrite;
    2911                 :            : 
    2912         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2913                 :            : 
    2914 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 4 || nArgCount > 6 )
    2915                 :            :     {
    2916         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2917                 :          0 :         return;
    2918                 :            :     }
    2919                 :            :     // retrieve non-optional params
    2920                 :            : 
    2921 [ #  # ][ #  # ]:          0 :     double rate = rPar.Get(1)->GetDouble();
    2922 [ #  # ][ #  # ]:          0 :     double per = rPar.Get(2)->GetInteger();
    2923 [ #  # ][ #  # ]:          0 :     double nper = rPar.Get(3)->GetDouble();
    2924 [ #  # ][ #  # ]:          0 :     double pv = rPar.Get(4)->GetDouble();
    2925                 :            : 
    2926                 :            :     // set default values for Optional args
    2927                 :          0 :     double fv = 0;
    2928                 :          0 :     double type = 0;
    2929                 :            : 
    2930                 :            :     // fv
    2931         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    2932                 :            :     {
    2933 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    2934 [ #  # ][ #  # ]:          0 :             fv = rPar.Get(5)->GetDouble();
    2935                 :            :     }
    2936                 :            :     // type
    2937         [ #  # ]:          0 :     if ( nArgCount >= 6 )
    2938                 :            :     {
    2939 [ #  # ][ #  # ]:          0 :         if( rPar.Get(6)->GetType() != SbxEMPTY )
                 [ #  # ]
    2940 [ #  # ][ #  # ]:          0 :             type = rPar.Get(6)->GetDouble();
    2941                 :            :     }
    2942                 :            : 
    2943         [ #  # ]:          0 :     Sequence< Any > aParams( 6 );
    2944 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= rate;
    2945 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= per;
    2946 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= nper;
    2947 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= pv;
    2948 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= fv;
    2949 [ #  # ][ #  # ]:          0 :     aParams[ 5 ] <<= type;
    2950                 :            : 
    2951 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "IPmt" ), rPar.Get( 0 ) );
                 [ #  # ]
    2952                 :            : }
    2953                 :            : 
    2954                 :          0 : RTLFUNC(FV)
    2955                 :            : {
    2956                 :            :     (void)pBasic;
    2957                 :            :     (void)bWrite;
    2958                 :            : 
    2959         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    2960                 :            : 
    2961 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 3 || nArgCount > 5 )
    2962                 :            :     {
    2963         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    2964                 :          0 :         return;
    2965                 :            :     }
    2966                 :            :     // retrieve non-optional params
    2967                 :            : 
    2968 [ #  # ][ #  # ]:          0 :     double rate = rPar.Get(1)->GetDouble();
    2969 [ #  # ][ #  # ]:          0 :     double nper = rPar.Get(2)->GetDouble();
    2970 [ #  # ][ #  # ]:          0 :     double pmt = rPar.Get(3)->GetDouble();
    2971                 :            : 
    2972                 :            :     // set default values for Optional args
    2973                 :          0 :     double pv = 0;
    2974                 :          0 :     double type = 0;
    2975                 :            : 
    2976                 :            :     // pv
    2977         [ #  # ]:          0 :     if ( nArgCount >= 4 )
    2978                 :            :     {
    2979 [ #  # ][ #  # ]:          0 :         if( rPar.Get(4)->GetType() != SbxEMPTY )
                 [ #  # ]
    2980 [ #  # ][ #  # ]:          0 :             pv = rPar.Get(4)->GetDouble();
    2981                 :            :     }
    2982                 :            :     // type
    2983         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    2984                 :            :     {
    2985 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    2986 [ #  # ][ #  # ]:          0 :             type = rPar.Get(5)->GetDouble();
    2987                 :            :     }
    2988                 :            : 
    2989         [ #  # ]:          0 :     Sequence< Any > aParams( 5 );
    2990 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= rate;
    2991 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= nper;
    2992 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= pmt;
    2993 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= pv;
    2994 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= type;
    2995                 :            : 
    2996 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "FV" ), rPar.Get( 0 ) );
                 [ #  # ]
    2997                 :            : }
    2998                 :            : 
    2999                 :          0 : RTLFUNC(DDB)
    3000                 :            : {
    3001                 :            :     (void)pBasic;
    3002                 :            :     (void)bWrite;
    3003                 :            : 
    3004         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    3005                 :            : 
    3006 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 4 || nArgCount > 5 )
    3007                 :            :     {
    3008         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3009                 :          0 :         return;
    3010                 :            :     }
    3011                 :            :     // retrieve non-optional params
    3012                 :            : 
    3013 [ #  # ][ #  # ]:          0 :     double cost = rPar.Get(1)->GetDouble();
    3014 [ #  # ][ #  # ]:          0 :     double salvage = rPar.Get(2)->GetDouble();
    3015 [ #  # ][ #  # ]:          0 :     double life = rPar.Get(3)->GetDouble();
    3016 [ #  # ][ #  # ]:          0 :     double period = rPar.Get(4)->GetDouble();
    3017                 :            : 
    3018                 :            :     // set default values for Optional args
    3019                 :          0 :     double factor = 2;
    3020                 :            : 
    3021                 :            :     // factor
    3022         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    3023                 :            :     {
    3024 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    3025 [ #  # ][ #  # ]:          0 :             factor = rPar.Get(5)->GetDouble();
    3026                 :            :     }
    3027                 :            : 
    3028         [ #  # ]:          0 :     Sequence< Any > aParams( 5 );
    3029 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= cost;
    3030 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= salvage;
    3031 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= life;
    3032 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= period;
    3033 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= factor;
    3034                 :            : 
    3035 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "DDB" ), rPar.Get( 0 ) );
                 [ #  # ]
    3036                 :            : }
    3037                 :            : 
    3038                 :          0 : RTLFUNC(Rate)
    3039                 :            : {
    3040                 :            :     (void)pBasic;
    3041                 :            :     (void)bWrite;
    3042                 :            : 
    3043         [ #  # ]:          0 :     sal_uLong nArgCount = rPar.Count()-1;
    3044                 :            : 
    3045 [ #  # ][ #  # ]:          0 :     if ( nArgCount < 3 || nArgCount > 6 )
    3046                 :            :     {
    3047         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3048                 :          0 :         return;
    3049                 :            :     }
    3050                 :            :     // retrieve non-optional params
    3051                 :            : 
    3052                 :          0 :     double nper = 0;
    3053                 :          0 :     double pmt = 0;
    3054                 :          0 :     double pv = 0;
    3055                 :            : 
    3056 [ #  # ][ #  # ]:          0 :     nper = rPar.Get(1)->GetDouble();
    3057 [ #  # ][ #  # ]:          0 :     pmt = rPar.Get(2)->GetDouble();
    3058 [ #  # ][ #  # ]:          0 :     pv = rPar.Get(3)->GetDouble();
    3059                 :            : 
    3060                 :            :     // set default values for Optional args
    3061                 :          0 :     double fv = 0;
    3062                 :          0 :     double type = 0;
    3063                 :          0 :     double guess = 0.1;
    3064                 :            : 
    3065                 :            :     // fv
    3066         [ #  # ]:          0 :     if ( nArgCount >= 4 )
    3067                 :            :     {
    3068 [ #  # ][ #  # ]:          0 :         if( rPar.Get(4)->GetType() != SbxEMPTY )
                 [ #  # ]
    3069 [ #  # ][ #  # ]:          0 :             fv = rPar.Get(4)->GetDouble();
    3070                 :            :     }
    3071                 :            : 
    3072                 :            :     // type
    3073         [ #  # ]:          0 :     if ( nArgCount >= 5 )
    3074                 :            :     {
    3075 [ #  # ][ #  # ]:          0 :         if( rPar.Get(5)->GetType() != SbxEMPTY )
                 [ #  # ]
    3076 [ #  # ][ #  # ]:          0 :             type = rPar.Get(5)->GetDouble();
    3077                 :            :     }
    3078                 :            : 
    3079                 :            :     // guess
    3080         [ #  # ]:          0 :     if ( nArgCount >= 6 )
    3081                 :            :     {
    3082 [ #  # ][ #  # ]:          0 :         if( rPar.Get(6)->GetType() != SbxEMPTY )
                 [ #  # ]
    3083 [ #  # ][ #  # ]:          0 :             type = rPar.Get(6)->GetDouble();
    3084                 :            :     }
    3085                 :            : 
    3086         [ #  # ]:          0 :     Sequence< Any > aParams( 6 );
    3087 [ #  # ][ #  # ]:          0 :     aParams[ 0 ] <<= nper;
    3088 [ #  # ][ #  # ]:          0 :     aParams[ 1 ] <<= pmt;
    3089 [ #  # ][ #  # ]:          0 :     aParams[ 2 ] <<= pv;
    3090 [ #  # ][ #  # ]:          0 :     aParams[ 3 ] <<= fv;
    3091 [ #  # ][ #  # ]:          0 :     aParams[ 4 ] <<= type;
    3092 [ #  # ][ #  # ]:          0 :     aParams[ 5 ] <<= guess;
    3093                 :            : 
    3094 [ #  # ][ #  # ]:          0 :     CallFunctionAccessFunction( aParams, rtl::OUString( "Rate" ), rPar.Get( 0 ) );
                 [ #  # ]
    3095                 :            : }
    3096                 :            : 
    3097                 :          0 : RTLFUNC(StrReverse)
    3098                 :            : {
    3099                 :            :     (void)pBasic;
    3100                 :            :     (void)bWrite;
    3101                 :            : 
    3102 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() != 2 )
    3103                 :            :     {
    3104         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3105                 :            :         return;
    3106                 :            :     }
    3107                 :            : 
    3108         [ #  # ]:          0 :     SbxVariable *pSbxVariable = rPar.Get(1);
    3109 [ #  # ][ #  # ]:          0 :     if( pSbxVariable->IsNull() )
    3110                 :            :     {
    3111         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3112                 :            :         return;
    3113                 :            :     }
    3114                 :            : 
    3115 [ #  # ][ #  # ]:          0 :     rtl::OUString aStr = comphelper::string::reverseString(pSbxVariable->GetString());
                 [ #  # ]
    3116 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString( aStr );
    3117                 :            : }
    3118                 :            : 
    3119                 :          4 : RTLFUNC(CompatibilityMode)
    3120                 :            : {
    3121                 :            :     (void)pBasic;
    3122                 :            :     (void)bWrite;
    3123                 :            : 
    3124                 :          4 :     bool bEnabled = false;
    3125                 :          4 :     sal_uInt16 nCount = rPar.Count();
    3126 [ -  + ][ +  - ]:          4 :     if ( nCount != 1 && nCount != 2 )
    3127                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3128                 :            : 
    3129                 :          4 :     SbiInstance* pInst = GetSbData()->pInst;
    3130         [ +  - ]:          4 :     if( pInst )
    3131                 :            :     {
    3132         [ +  - ]:          4 :         if ( nCount == 2 )
    3133                 :          4 :             pInst->EnableCompatibility( rPar.Get(1)->GetBool() );
    3134                 :            : 
    3135                 :          4 :         bEnabled = pInst->IsCompatibility();
    3136                 :            :     }
    3137                 :          4 :     rPar.Get(0)->PutBool( bEnabled );
    3138                 :          4 : }
    3139                 :            : 
    3140                 :          0 : RTLFUNC(Input)
    3141                 :            : {
    3142                 :            :     (void)pBasic;
    3143                 :            :     (void)bWrite;
    3144                 :            : 
    3145                 :            :     // 2 parameters needed
    3146 [ #  # ][ #  # ]:          0 :     if ( rPar.Count() < 3 )
    3147                 :            :     {
    3148         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3149                 :            :         return;
    3150                 :            :     }
    3151                 :            : 
    3152 [ #  # ][ #  # ]:          0 :     sal_uInt16 nByteCount  = rPar.Get(1)->GetUShort();
    3153 [ #  # ][ #  # ]:          0 :     sal_Int16  nFileNumber = rPar.Get(2)->GetInteger();
    3154                 :            : 
    3155         [ #  # ]:          0 :     SbiIoSystem* pIosys = GetSbData()->pInst->GetIoSystem();
    3156         [ #  # ]:          0 :     SbiStream* pSbStrm = pIosys->GetStream( nFileNumber );
    3157 [ #  # ][ #  # ]:          0 :     if ( !pSbStrm || !(pSbStrm->GetMode() & (SBSTRM_BINARY | SBSTRM_INPUT)) )
                 [ #  # ]
    3158                 :            :     {
    3159         [ #  # ]:          0 :         StarBASIC::Error( SbERR_BAD_CHANNEL );
    3160                 :            :         return;
    3161                 :            :     }
    3162                 :            : 
    3163                 :          0 :     rtl::OString aByteBuffer;
    3164         [ #  # ]:          0 :     SbError err = pSbStrm->Read( aByteBuffer, nByteCount, true );
    3165         [ #  # ]:          0 :     if( !err )
    3166         [ #  # ]:          0 :         err = pIosys->GetError();
    3167                 :            : 
    3168         [ #  # ]:          0 :     if( err )
    3169                 :            :     {
    3170         [ #  # ]:          0 :         StarBASIC::Error( err );
    3171                 :            :         return;
    3172                 :            :     }
    3173 [ #  # ][ #  # ]:          0 :     rPar.Get(0)->PutString(rtl::OStringToOUString(aByteBuffer, osl_getThreadTextEncoding()));
         [ #  # ][ #  # ]
                 [ #  # ]
    3174                 :            : }
    3175                 :            : 
    3176                 :          0 : RTLFUNC(Me)
    3177                 :            : {
    3178                 :            :     (void)pBasic;
    3179                 :            :     (void)bWrite;
    3180                 :            : 
    3181 [ #  # ][ #  # ]:          0 :     SbModule* pActiveModule = GetSbData()->pInst->GetActiveModule();
    3182 [ #  # ][ #  # ]:          0 :     SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
         [ #  # ][ #  # ]
    3183         [ #  # ]:          0 :     SbxVariableRef refVar = rPar.Get(0);
    3184         [ #  # ]:          0 :     if( pClassModuleObject == NULL )
    3185                 :            :     {
    3186 [ #  # ][ #  # ]:          0 :         SbObjModule* pMod = PTR_CAST(SbObjModule,pActiveModule);
         [ #  # ][ #  # ]
    3187         [ #  # ]:          0 :         if ( pMod )
    3188         [ #  # ]:          0 :             refVar->PutObject( pMod );
    3189                 :            :         else
    3190         [ #  # ]:          0 :             StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT );
    3191                 :            :     }
    3192                 :            :     else
    3193 [ #  # ][ #  # ]:          0 :         refVar->PutObject( pClassModuleObject );
    3194                 :          0 : }
    3195                 :            : 
    3196                 :            : #endif
    3197                 :            : 
    3198                 :          0 : sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam, sal_Int16 nFirstDay )
    3199                 :            : {
    3200                 :          0 :     Date aRefDate( 1,1,1900 );
    3201                 :          0 :     long nDays = (long) aDate;
    3202                 :          0 :     nDays -= 2; // normieren: 1.1.1900 => 0
    3203         [ #  # ]:          0 :     aRefDate += nDays;
    3204         [ #  # ]:          0 :     DayOfWeek aDay = aRefDate.GetDayOfWeek();
    3205                 :            :     sal_Int16 nDay;
    3206         [ #  # ]:          0 :     if ( aDay != SUNDAY )
    3207                 :          0 :         nDay = (sal_Int16)aDay + 2;
    3208                 :            :     else
    3209                 :          0 :         nDay = 1;   // 1 == Sunday
    3210                 :            : 
    3211                 :            :     // #117253 optional 2nd parameter "firstdayofweek"
    3212         [ #  # ]:          0 :     if( bFirstDayParam )
    3213                 :            :     {
    3214 [ #  # ][ #  # ]:          0 :         if( nFirstDay < 0 || nFirstDay > 7 )
    3215                 :            :         {
    3216                 :            : #ifndef DISABLE_SCRIPTING
    3217         [ #  # ]:          0 :             StarBASIC::Error( SbERR_BAD_ARGUMENT );
    3218                 :            : #endif
    3219                 :          0 :             return 0;
    3220                 :            :         }
    3221         [ #  # ]:          0 :         if( nFirstDay == 0 )
    3222                 :            :         {
    3223         [ #  # ]:          0 :             Reference< XCalendar3 > xCalendar = getLocaleCalendar();
    3224         [ #  # ]:          0 :             if( !xCalendar.is() )
    3225                 :            :             {
    3226                 :            : #ifndef DISABLE_SCRIPTING
    3227         [ #  # ]:          0 :                 StarBASIC::Error( SbERR_INTERNAL_ERROR );
    3228                 :            : #endif
    3229                 :          0 :                 return 0;
    3230                 :            :             }
    3231 [ #  # ][ #  # ]:          0 :             nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 );
                 [ #  # ]
    3232                 :            :         }
    3233                 :          0 :         nDay = 1 + (nDay + 7 - nFirstDay) % 7;
    3234                 :            :     }
    3235                 :          0 :     return nDay;
    3236 [ +  - ][ +  - ]:        771 : }
    3237                 :            : 
    3238                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10