1*e1f63238SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e1f63238SAndrew Rist * distributed with this work for additional information 6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance 9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at 10*e1f63238SAndrew Rist * 11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e1f63238SAndrew Rist * 13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e1f63238SAndrew Rist * software distributed under the License is distributed on an 15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the 17*e1f63238SAndrew Rist * specific language governing permissions and limitations 18*e1f63238SAndrew Rist * under the License. 19*e1f63238SAndrew Rist * 20*e1f63238SAndrew Rist *************************************************************/ 21*e1f63238SAndrew Rist 22*e1f63238SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basic.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <tools/date.hxx> 29cdf0e10cSrcweir #include <basic/sbxvar.hxx> 30cdf0e10cSrcweir #ifndef _VOS_PROCESS_HXX 31cdf0e10cSrcweir #include <vos/process.hxx> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #include <vcl/svapp.hxx> 34cdf0e10cSrcweir #include <vcl/settings.hxx> 35cdf0e10cSrcweir #include <vcl/sound.hxx> 36cdf0e10cSrcweir #include <tools/wintypes.hxx> 37cdf0e10cSrcweir #include <vcl/msgbox.hxx> 38cdf0e10cSrcweir #include <basic/sbx.hxx> 39cdf0e10cSrcweir #include <svl/zforlist.hxx> 40cdf0e10cSrcweir #include <rtl/math.hxx> 41cdf0e10cSrcweir #include <tools/urlobj.hxx> 42cdf0e10cSrcweir #include <osl/time.h> 43cdf0e10cSrcweir #include <unotools/charclass.hxx> 44cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 45cdf0e10cSrcweir #include <tools/wldcrd.hxx> 46cdf0e10cSrcweir #include <i18npool/lang.h> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include "runtime.hxx" 49cdf0e10cSrcweir #include "sbunoobj.hxx" 50cdf0e10cSrcweir #ifdef WNT 51cdf0e10cSrcweir #include <tools/prewin.h> 52cdf0e10cSrcweir #include "winbase.h" 53cdf0e10cSrcweir #include <tools/postwin.h> 54cdf0e10cSrcweir #ifndef _FSYS_HXX //autogen 55cdf0e10cSrcweir #include <tools/fsys.hxx> 56cdf0e10cSrcweir #endif 57cdf0e10cSrcweir #else 58cdf0e10cSrcweir #include <osl/file.hxx> 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir #include "errobject.hxx" 61cdf0e10cSrcweir 62cdf0e10cSrcweir #ifdef _USE_UNO 63cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 64cdf0e10cSrcweir 65cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 66cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 67cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 68cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp> 69cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess3.hpp> 70cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 71cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 72cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp> 73cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 74cdf0e10cSrcweir 75cdf0e10cSrcweir using namespace comphelper; 76cdf0e10cSrcweir using namespace osl; 77cdf0e10cSrcweir using namespace com::sun::star::uno; 78cdf0e10cSrcweir using namespace com::sun::star::lang; 79cdf0e10cSrcweir using namespace com::sun::star::ucb; 80cdf0e10cSrcweir using namespace com::sun::star::io; 81cdf0e10cSrcweir using namespace com::sun::star::frame; 82cdf0e10cSrcweir 83cdf0e10cSrcweir #endif /* _USE_UNO */ 84cdf0e10cSrcweir 85cdf0e10cSrcweir //#define _ENABLE_CUR_DIR 86cdf0e10cSrcweir 87cdf0e10cSrcweir #include "stdobj.hxx" 88cdf0e10cSrcweir #include <basic/sbstdobj.hxx> 89cdf0e10cSrcweir #include "rtlproto.hxx" 90cdf0e10cSrcweir #include "basrid.hxx" 91cdf0e10cSrcweir #include "image.hxx" 92cdf0e10cSrcweir #include "sb.hrc" 93cdf0e10cSrcweir #include "iosys.hxx" 94cdf0e10cSrcweir #include "ddectrl.hxx" 95cdf0e10cSrcweir #include <sbintern.hxx> 96cdf0e10cSrcweir #include <basic/vbahelper.hxx> 97cdf0e10cSrcweir 98cdf0e10cSrcweir #include <list> 99cdf0e10cSrcweir #include <math.h> 100cdf0e10cSrcweir #include <stdio.h> 101cdf0e10cSrcweir #include <stdlib.h> 102cdf0e10cSrcweir #include <ctype.h> 103cdf0e10cSrcweir 104cdf0e10cSrcweir #if defined (WNT) || defined (OS2) 105cdf0e10cSrcweir #include <direct.h> // _getdcwd get current work directory, _chdrive 106cdf0e10cSrcweir #endif 107cdf0e10cSrcweir 108cdf0e10cSrcweir #ifdef UNX 109cdf0e10cSrcweir #include <errno.h> 110cdf0e10cSrcweir #include <unistd.h> 111cdf0e10cSrcweir #endif 112cdf0e10cSrcweir 113cdf0e10cSrcweir #ifdef WNT 114cdf0e10cSrcweir #include <io.h> 115cdf0e10cSrcweir #endif 116cdf0e10cSrcweir 117cdf0e10cSrcweir #include <basic/sbobjmod.hxx> 118cdf0e10cSrcweir 119cdf0e10cSrcweir // from source/classes/sbxmod.cxx 120cdf0e10cSrcweir Reference< XModel > getDocumentModel( StarBASIC* ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir static void FilterWhiteSpace( String& rStr ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir rStr.EraseAllChars( ' ' ); 125cdf0e10cSrcweir rStr.EraseAllChars( '\t' ); 126cdf0e10cSrcweir rStr.EraseAllChars( '\n' ); 127cdf0e10cSrcweir rStr.EraseAllChars( '\r' ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir static long GetDayDiff( const Date& rDate ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir Date aRefDate( 1,1,1900 ); 133cdf0e10cSrcweir long nDiffDays; 134cdf0e10cSrcweir if ( aRefDate > rDate ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir nDiffDays = (long)(aRefDate - rDate); 137cdf0e10cSrcweir nDiffDays *= -1; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir else 140cdf0e10cSrcweir nDiffDays = (long)(rDate - aRefDate); 141cdf0e10cSrcweir nDiffDays += 2; // Anpassung VisualBasic: 1.Jan.1900 == 2 142cdf0e10cSrcweir return nDiffDays; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir static CharClass& GetCharClass( void ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir static sal_Bool bNeedsInit = sal_True; 148cdf0e10cSrcweir static ::com::sun::star::lang::Locale aLocale; 149cdf0e10cSrcweir if( bNeedsInit ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir bNeedsInit = sal_False; 152cdf0e10cSrcweir aLocale = Application::GetSettings().GetLocale(); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir static CharClass aCharClass( aLocale ); 155cdf0e10cSrcweir return aCharClass; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir static inline sal_Bool isFolder( FileStatus::Type aType ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir return ( aType == FileStatus::Directory || aType == FileStatus::Volume ); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir 164cdf0e10cSrcweir //*** UCB file access *** 165cdf0e10cSrcweir 166cdf0e10cSrcweir // Converts possibly relative paths to absolute paths 167cdf0e10cSrcweir // according to the setting done by ChDir/ChDrive 168cdf0e10cSrcweir String getFullPath( const String& aRelPath ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir ::rtl::OUString aFileURL; 171cdf0e10cSrcweir 172cdf0e10cSrcweir // #80204 Try first if it already is a valid URL 173cdf0e10cSrcweir INetURLObject aURLObj( aRelPath ); 174cdf0e10cSrcweir aFileURL = aURLObj.GetMainURL( INetURLObject::NO_DECODE ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir if( !aFileURL.getLength() ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir File::getFileURLFromSystemPath( aRelPath, aFileURL ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir return aFileURL; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir // Sets (virtual) current path for UCB file access 185cdf0e10cSrcweir void implChDir( const String& aDir ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir (void)aDir; 188cdf0e10cSrcweir // TODO 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir // Sets (virtual) current drive for UCB file access 192cdf0e10cSrcweir void implChDrive( const String& aDrive ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir (void)aDrive; 195cdf0e10cSrcweir // TODO 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir // Returns (virtual) current path for UCB file access 199cdf0e10cSrcweir String implGetCurDir( void ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir String aRetStr; 202cdf0e10cSrcweir 203cdf0e10cSrcweir return aRetStr; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // TODO: -> SbiGlobals 207cdf0e10cSrcweir static com::sun::star::uno::Reference< XSimpleFileAccess3 > getFileAccess( void ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir static com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI; 210cdf0e10cSrcweir if( !xSFI.is() ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir com::sun::star::uno::Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory(); 213cdf0e10cSrcweir if( xSMgr.is() ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir xSFI = com::sun::star::uno::Reference< XSimpleFileAccess3 >( xSMgr->createInstance 216cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir return xSFI; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir // Properties und Methoden legen beim Get (bPut = sal_False) den Returnwert 225cdf0e10cSrcweir // im Element 0 des Argv ab; beim Put (bPut = sal_True) wird der Wert aus 226cdf0e10cSrcweir // Element 0 gespeichert. 227cdf0e10cSrcweir 228cdf0e10cSrcweir // CreateObject( class ) 229cdf0e10cSrcweir 230cdf0e10cSrcweir RTLFUNC(CreateObject) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir (void)bWrite; 233cdf0e10cSrcweir 234cdf0e10cSrcweir String aClass( rPar.Get( 1 )->GetString() ); 235cdf0e10cSrcweir SbxObjectRef p = SbxBase::CreateObject( aClass ); 236cdf0e10cSrcweir if( !p ) 237cdf0e10cSrcweir StarBASIC::Error( SbERR_CANNOT_LOAD ); 238cdf0e10cSrcweir else 239cdf0e10cSrcweir { 240cdf0e10cSrcweir // Convenience: BASIC als Parent eintragen 241cdf0e10cSrcweir p->SetParent( pBasic ); 242cdf0e10cSrcweir rPar.Get( 0 )->PutObject( p ); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir // Error( n ) 247cdf0e10cSrcweir 248cdf0e10cSrcweir RTLFUNC(Error) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir (void)bWrite; 251cdf0e10cSrcweir 252cdf0e10cSrcweir if( !pBasic ) 253cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 254cdf0e10cSrcweir else 255cdf0e10cSrcweir { 256cdf0e10cSrcweir String aErrorMsg; 257cdf0e10cSrcweir SbError nErr = 0L; 258cdf0e10cSrcweir sal_Int32 nCode = 0; 259cdf0e10cSrcweir if( rPar.Count() == 1 ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir nErr = StarBASIC::GetErrBasic(); 262cdf0e10cSrcweir aErrorMsg = StarBASIC::GetErrorMsg(); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir else 265cdf0e10cSrcweir { 266cdf0e10cSrcweir nCode = rPar.Get( 1 )->GetLong(); 267cdf0e10cSrcweir if( nCode > 65535L ) 268cdf0e10cSrcweir StarBASIC::Error( SbERR_CONVERSION ); 269cdf0e10cSrcweir else 270cdf0e10cSrcweir nErr = StarBASIC::GetSfxFromVBError( (sal_uInt16)nCode ); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir bool bVBA = SbiRuntime::isVBAEnabled(); 274cdf0e10cSrcweir String tmpErrMsg; 275cdf0e10cSrcweir if( bVBA && aErrorMsg.Len() > 0 ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir tmpErrMsg = aErrorMsg; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir else 280cdf0e10cSrcweir { 281cdf0e10cSrcweir pBasic->MakeErrorText( nErr, aErrorMsg ); 282cdf0e10cSrcweir tmpErrMsg = pBasic->GetErrorText(); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir // If this rtlfunc 'Error' passed a errcode the same as the active Err Objects's 285cdf0e10cSrcweir // current err then return the description for the error message if it is set 286cdf0e10cSrcweir // ( complicated isn't it ? ) 287cdf0e10cSrcweir if ( bVBA && rPar.Count() > 1 ) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir com::sun::star::uno::Reference< ooo::vba::XErrObject > xErrObj( SbxErrObject::getUnoErrObject() ); 290cdf0e10cSrcweir if ( xErrObj.is() && xErrObj->getNumber() == nCode && xErrObj->getDescription().getLength() ) 291cdf0e10cSrcweir tmpErrMsg = xErrObj->getDescription(); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir rPar.Get( 0 )->PutString( tmpErrMsg ); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir // Sinus 298cdf0e10cSrcweir 299cdf0e10cSrcweir RTLFUNC(Sin) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir (void)pBasic; 302cdf0e10cSrcweir (void)bWrite; 303cdf0e10cSrcweir 304cdf0e10cSrcweir if ( rPar.Count() < 2 ) 305cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 306cdf0e10cSrcweir else 307cdf0e10cSrcweir { 308cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 309cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( sin( pArg->GetDouble() ) ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir // Cosinus 314cdf0e10cSrcweir 315cdf0e10cSrcweir RTLFUNC(Cos) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir (void)pBasic; 318cdf0e10cSrcweir (void)bWrite; 319cdf0e10cSrcweir 320cdf0e10cSrcweir if ( rPar.Count() < 2 ) 321cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 322cdf0e10cSrcweir else 323cdf0e10cSrcweir { 324cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 325cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( cos( pArg->GetDouble() ) ); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir // Atn 330cdf0e10cSrcweir 331cdf0e10cSrcweir RTLFUNC(Atn) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir (void)pBasic; 334cdf0e10cSrcweir (void)bWrite; 335cdf0e10cSrcweir 336cdf0e10cSrcweir if ( rPar.Count() < 2 ) 337cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 338cdf0e10cSrcweir else 339cdf0e10cSrcweir { 340cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 341cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( atan( pArg->GetDouble() ) ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir 346cdf0e10cSrcweir 347cdf0e10cSrcweir RTLFUNC(Abs) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir (void)pBasic; 350cdf0e10cSrcweir (void)bWrite; 351cdf0e10cSrcweir 352cdf0e10cSrcweir if ( rPar.Count() < 2 ) 353cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 354cdf0e10cSrcweir else 355cdf0e10cSrcweir { 356cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 357cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( fabs( pArg->GetDouble() ) ); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir 362cdf0e10cSrcweir RTLFUNC(Asc) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir (void)pBasic; 365cdf0e10cSrcweir (void)bWrite; 366cdf0e10cSrcweir 367cdf0e10cSrcweir if ( rPar.Count() < 2 ) 368cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 369cdf0e10cSrcweir else 370cdf0e10cSrcweir { 371cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 372cdf0e10cSrcweir String aStr( pArg->GetString() ); 373cdf0e10cSrcweir if ( aStr.Len() == 0 ) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 376cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir else 379cdf0e10cSrcweir { 380cdf0e10cSrcweir sal_Unicode aCh = aStr.GetBuffer()[0]; 381cdf0e10cSrcweir rPar.Get(0)->PutLong( aCh ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir } 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir void implChr( SbxArray& rPar, bool bChrW ) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir if ( rPar.Count() < 2 ) 389cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 390cdf0e10cSrcweir else 391cdf0e10cSrcweir { 392cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 393cdf0e10cSrcweir 394cdf0e10cSrcweir String aStr; 395cdf0e10cSrcweir if( !bChrW && SbiRuntime::isVBAEnabled() ) 396cdf0e10cSrcweir { 397cdf0e10cSrcweir sal_Char c = (sal_Char)pArg->GetByte(); 398cdf0e10cSrcweir ByteString s( c ); 399cdf0e10cSrcweir aStr = String( s, gsl_getSystemTextEncoding() ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir else 402cdf0e10cSrcweir { 403cdf0e10cSrcweir sal_Unicode aCh = (sal_Unicode)pArg->GetUShort(); 404cdf0e10cSrcweir aStr = String( aCh ); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 407cdf0e10cSrcweir } 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir RTLFUNC(Chr) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir (void)pBasic; 413cdf0e10cSrcweir (void)bWrite; 414cdf0e10cSrcweir 415cdf0e10cSrcweir bool bChrW = false; 416cdf0e10cSrcweir implChr( rPar, bChrW ); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir RTLFUNC(ChrW) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir (void)pBasic; 422cdf0e10cSrcweir (void)bWrite; 423cdf0e10cSrcweir 424cdf0e10cSrcweir bool bChrW = true; 425cdf0e10cSrcweir implChr( rPar, bChrW ); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir 429cdf0e10cSrcweir #ifdef UNX 430cdf0e10cSrcweir #define _MAX_PATH 260 431cdf0e10cSrcweir #define _PATH_INCR 250 432cdf0e10cSrcweir #endif 433cdf0e10cSrcweir 434cdf0e10cSrcweir RTLFUNC(CurDir) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir (void)pBasic; 437cdf0e10cSrcweir (void)bWrite; 438cdf0e10cSrcweir 439cdf0e10cSrcweir // #57064 Obwohl diese Funktion nicht mit DirEntry arbeitet, ist sie von 440cdf0e10cSrcweir // der Anpassung an virtuelle URLs nich betroffen, da bei Nutzung der 441cdf0e10cSrcweir // DirEntry-Funktionalitaet keine Moeglichkeit besteht, das aktuelle so 442cdf0e10cSrcweir // zu ermitteln, dass eine virtuelle URL geliefert werden koennte. 443cdf0e10cSrcweir 444cdf0e10cSrcweir // rPar.Get(0)->PutEmpty(); 445cdf0e10cSrcweir #if defined (WNT) || defined (OS2) 446cdf0e10cSrcweir int nCurDir = 0; // Current dir // JSM 447cdf0e10cSrcweir if ( rPar.Count() == 2 ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir String aDrive = rPar.Get(1)->GetString(); 450cdf0e10cSrcweir if ( aDrive.Len() != 1 ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 453cdf0e10cSrcweir return; 454cdf0e10cSrcweir } 455cdf0e10cSrcweir else 456cdf0e10cSrcweir { 457cdf0e10cSrcweir nCurDir = (int)aDrive.GetBuffer()[0]; 458cdf0e10cSrcweir if ( !isalpha( nCurDir ) ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 461cdf0e10cSrcweir return; 462cdf0e10cSrcweir } 463cdf0e10cSrcweir else 464cdf0e10cSrcweir nCurDir -= ( 'A' - 1 ); 465cdf0e10cSrcweir } 466cdf0e10cSrcweir } 467cdf0e10cSrcweir char* pBuffer = new char[ _MAX_PATH ]; 468cdf0e10cSrcweir #ifdef OS2 469cdf0e10cSrcweir if( !nCurDir ) 470cdf0e10cSrcweir nCurDir = _getdrive(); 471cdf0e10cSrcweir #endif 472cdf0e10cSrcweir if ( _getdcwd( nCurDir, pBuffer, _MAX_PATH ) != 0 ) 473cdf0e10cSrcweir rPar.Get(0)->PutString( String::CreateFromAscii( pBuffer ) ); 474cdf0e10cSrcweir else 475cdf0e10cSrcweir StarBASIC::Error( SbERR_NO_DEVICE ); 476cdf0e10cSrcweir delete [] pBuffer; 477cdf0e10cSrcweir 478cdf0e10cSrcweir #elif defined( UNX ) 479cdf0e10cSrcweir 480cdf0e10cSrcweir int nSize = _PATH_INCR; 481cdf0e10cSrcweir char* pMem; 482cdf0e10cSrcweir while( sal_True ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir pMem = new char[nSize]; 485cdf0e10cSrcweir if( !pMem ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir StarBASIC::Error( SbERR_NO_MEMORY ); 488cdf0e10cSrcweir return; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir if( getcwd( pMem, nSize-1 ) != NULL ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir rPar.Get(0)->PutString( String::CreateFromAscii(pMem) ); 493cdf0e10cSrcweir delete [] pMem; 494cdf0e10cSrcweir return; 495cdf0e10cSrcweir } 496cdf0e10cSrcweir if( errno != ERANGE ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 499cdf0e10cSrcweir delete [] pMem; 500cdf0e10cSrcweir return; 501cdf0e10cSrcweir } 502cdf0e10cSrcweir delete [] pMem; 503cdf0e10cSrcweir nSize += _PATH_INCR; 504cdf0e10cSrcweir }; 505cdf0e10cSrcweir 506cdf0e10cSrcweir #endif 507cdf0e10cSrcweir } 508cdf0e10cSrcweir 509cdf0e10cSrcweir RTLFUNC(ChDir) // JSM 510cdf0e10cSrcweir { 511cdf0e10cSrcweir (void)bWrite; 512cdf0e10cSrcweir 513cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 514cdf0e10cSrcweir if (rPar.Count() == 2) 515cdf0e10cSrcweir { 516cdf0e10cSrcweir #ifdef _ENABLE_CUR_DIR 517cdf0e10cSrcweir String aPath = rPar.Get(1)->GetString(); 518cdf0e10cSrcweir sal_Bool bError = sal_False; 519cdf0e10cSrcweir #ifdef WNT 520cdf0e10cSrcweir // #55997 Laut MI hilft es bei File-URLs einen DirEntry zwischenzuschalten 521cdf0e10cSrcweir // #40996 Harmoniert bei Verwendung der WIN32-Funktion nicht mit getdir 522cdf0e10cSrcweir DirEntry aEntry( aPath ); 523cdf0e10cSrcweir ByteString aFullPath( aEntry.GetFull(), gsl_getSystemTextEncoding() ); 524cdf0e10cSrcweir if( chdir( aFullPath.GetBuffer()) ) 525cdf0e10cSrcweir bError = sal_True; 526cdf0e10cSrcweir #else 527cdf0e10cSrcweir if (!DirEntry(aPath).SetCWD()) 528cdf0e10cSrcweir bError = sal_True; 529cdf0e10cSrcweir #endif 530cdf0e10cSrcweir if( bError ) 531cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 532cdf0e10cSrcweir #endif 533cdf0e10cSrcweir // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.) 534cdf0e10cSrcweir if( SbiRuntime::isVBAEnabled() ) 535cdf0e10cSrcweir ::basic::vba::registerCurrentDirectory( getDocumentModel( pBasic ), rPar.Get(1)->GetString() ); 536cdf0e10cSrcweir } 537cdf0e10cSrcweir else 538cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir RTLFUNC(ChDrive) // JSM 542cdf0e10cSrcweir { 543cdf0e10cSrcweir (void)pBasic; 544cdf0e10cSrcweir (void)bWrite; 545cdf0e10cSrcweir 546cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 547cdf0e10cSrcweir if (rPar.Count() == 2) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir #ifdef _ENABLE_CUR_DIR 550cdf0e10cSrcweir // Keine Laufwerke in Unix 551cdf0e10cSrcweir #ifndef UNX 552cdf0e10cSrcweir String aPar1 = rPar.Get(1)->GetString(); 553cdf0e10cSrcweir 554cdf0e10cSrcweir #if defined (WNT) || defined (OS2) 555cdf0e10cSrcweir if (aPar1.Len() > 0) 556cdf0e10cSrcweir { 557cdf0e10cSrcweir int nCurDrive = (int)aPar1.GetBuffer()[0]; ; 558cdf0e10cSrcweir if ( !isalpha( nCurDrive ) ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 561cdf0e10cSrcweir return; 562cdf0e10cSrcweir } 563cdf0e10cSrcweir else 564cdf0e10cSrcweir nCurDrive -= ( 'A' - 1 ); 565cdf0e10cSrcweir if (_chdrive(nCurDrive)) 566cdf0e10cSrcweir StarBASIC::Error( SbERR_NO_DEVICE ); 567cdf0e10cSrcweir } 568cdf0e10cSrcweir #endif 569cdf0e10cSrcweir 570cdf0e10cSrcweir #endif 571cdf0e10cSrcweir // #ifndef UNX 572cdf0e10cSrcweir #endif 573cdf0e10cSrcweir } 574cdf0e10cSrcweir else 575cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 576cdf0e10cSrcweir } 577cdf0e10cSrcweir 578cdf0e10cSrcweir 579cdf0e10cSrcweir // Implementation of StepRENAME with UCB 580cdf0e10cSrcweir void implStepRenameUCB( const String& aSource, const String& aDest ) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 583cdf0e10cSrcweir if( xSFI.is() ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir try 586cdf0e10cSrcweir { 587cdf0e10cSrcweir String aSourceFullPath = getFullPath( aSource ); 588cdf0e10cSrcweir if( !xSFI->exists( aSourceFullPath ) ) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 591cdf0e10cSrcweir return; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir 594cdf0e10cSrcweir String aDestFullPath = getFullPath( aDest ); 595cdf0e10cSrcweir if( xSFI->exists( aDestFullPath ) ) 596cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_EXISTS ); 597cdf0e10cSrcweir else 598cdf0e10cSrcweir xSFI->move( aSourceFullPath, aDestFullPath ); 599cdf0e10cSrcweir } 600cdf0e10cSrcweir catch( Exception & ) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 603cdf0e10cSrcweir } 604cdf0e10cSrcweir } 605cdf0e10cSrcweir } 606cdf0e10cSrcweir 607cdf0e10cSrcweir // Implementation of StepRENAME with OSL 608cdf0e10cSrcweir void implStepRenameOSL( const String& aSource, const String& aDest ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir FileBase::RC nRet = File::move( getFullPathUNC( aSource ), getFullPathUNC( aDest ) ); 611cdf0e10cSrcweir if( nRet != FileBase::E_None ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir } 616cdf0e10cSrcweir 617cdf0e10cSrcweir RTLFUNC(FileCopy) // JSM 618cdf0e10cSrcweir { 619cdf0e10cSrcweir (void)pBasic; 620cdf0e10cSrcweir (void)bWrite; 621cdf0e10cSrcweir 622cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 623cdf0e10cSrcweir if (rPar.Count() == 3) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir String aSource = rPar.Get(1)->GetString(); 626cdf0e10cSrcweir String aDest = rPar.Get(2)->GetString(); 627cdf0e10cSrcweir // <-- UCB 628cdf0e10cSrcweir if( hasUno() ) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 631cdf0e10cSrcweir if( xSFI.is() ) 632cdf0e10cSrcweir { 633cdf0e10cSrcweir try 634cdf0e10cSrcweir { 635cdf0e10cSrcweir xSFI->copy( getFullPath( aSource ), getFullPath( aDest ) ); 636cdf0e10cSrcweir } 637cdf0e10cSrcweir catch( Exception & ) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 640cdf0e10cSrcweir } 641cdf0e10cSrcweir } 642cdf0e10cSrcweir } 643cdf0e10cSrcweir else 644cdf0e10cSrcweir // --> UCB 645cdf0e10cSrcweir { 646cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 647cdf0e10cSrcweir DirEntry aSourceDirEntry(aSource); 648cdf0e10cSrcweir if (aSourceDirEntry.Exists()) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir if (aSourceDirEntry.CopyTo(DirEntry(aDest),FSYS_ACTION_COPYFILE) != FSYS_ERR_OK) 651cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir else 654cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 655cdf0e10cSrcweir #else 656cdf0e10cSrcweir FileBase::RC nRet = File::copy( getFullPathUNC( aSource ), getFullPathUNC( aDest ) ); 657cdf0e10cSrcweir if( nRet != FileBase::E_None ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 660cdf0e10cSrcweir } 661cdf0e10cSrcweir #endif 662cdf0e10cSrcweir } 663cdf0e10cSrcweir } 664cdf0e10cSrcweir else 665cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir RTLFUNC(Kill) // JSM 669cdf0e10cSrcweir { 670cdf0e10cSrcweir (void)pBasic; 671cdf0e10cSrcweir (void)bWrite; 672cdf0e10cSrcweir 673cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 674cdf0e10cSrcweir if (rPar.Count() == 2) 675cdf0e10cSrcweir { 676cdf0e10cSrcweir String aFileSpec = rPar.Get(1)->GetString(); 677cdf0e10cSrcweir 678cdf0e10cSrcweir // <-- UCB 679cdf0e10cSrcweir if( hasUno() ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 682cdf0e10cSrcweir if( xSFI.is() ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir String aFullPath = getFullPath( aFileSpec ); 685cdf0e10cSrcweir if( !xSFI->exists( aFullPath ) || xSFI->isFolder( aFullPath ) ) 686cdf0e10cSrcweir { 687cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 688cdf0e10cSrcweir return; 689cdf0e10cSrcweir } 690cdf0e10cSrcweir try 691cdf0e10cSrcweir { 692cdf0e10cSrcweir xSFI->kill( aFullPath ); 693cdf0e10cSrcweir } 694cdf0e10cSrcweir catch( Exception & ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 697cdf0e10cSrcweir } 698cdf0e10cSrcweir } 699cdf0e10cSrcweir } 700cdf0e10cSrcweir else 701cdf0e10cSrcweir // --> UCB 702cdf0e10cSrcweir { 703cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 704cdf0e10cSrcweir if(DirEntry(aFileSpec).Kill() != FSYS_ERR_OK) 705cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 706cdf0e10cSrcweir #else 707cdf0e10cSrcweir File::remove( getFullPathUNC( aFileSpec ) ); 708cdf0e10cSrcweir #endif 709cdf0e10cSrcweir } 710cdf0e10cSrcweir } 711cdf0e10cSrcweir else 712cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715cdf0e10cSrcweir RTLFUNC(MkDir) // JSM 716cdf0e10cSrcweir { 717cdf0e10cSrcweir (void)pBasic; 718cdf0e10cSrcweir (void)bWrite; 719cdf0e10cSrcweir 720cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 721cdf0e10cSrcweir if (rPar.Count() == 2) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir String aPath = rPar.Get(1)->GetString(); 724cdf0e10cSrcweir 725cdf0e10cSrcweir // <-- UCB 726cdf0e10cSrcweir if( hasUno() ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 729cdf0e10cSrcweir if( xSFI.is() ) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir try 732cdf0e10cSrcweir { 733cdf0e10cSrcweir xSFI->createFolder( getFullPath( aPath ) ); 734cdf0e10cSrcweir } 735cdf0e10cSrcweir catch( Exception & ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 738cdf0e10cSrcweir } 739cdf0e10cSrcweir } 740cdf0e10cSrcweir } 741cdf0e10cSrcweir else 742cdf0e10cSrcweir // --> UCB 743cdf0e10cSrcweir { 744cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 745cdf0e10cSrcweir if (!DirEntry(aPath).MakeDir()) 746cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 747cdf0e10cSrcweir #else 748cdf0e10cSrcweir Directory::create( getFullPathUNC( aPath ) ); 749cdf0e10cSrcweir #endif 750cdf0e10cSrcweir } 751cdf0e10cSrcweir } 752cdf0e10cSrcweir else 753cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 754cdf0e10cSrcweir } 755cdf0e10cSrcweir 756cdf0e10cSrcweir 757cdf0e10cSrcweir #ifndef _OLD_FILE_IMPL 758cdf0e10cSrcweir 759cdf0e10cSrcweir // In OSL only empty directories can be deleted 760cdf0e10cSrcweir // so we have to delete all files recursively 761cdf0e10cSrcweir void implRemoveDirRecursive( const String& aDirPath ) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir DirectoryItem aItem; 764cdf0e10cSrcweir FileBase::RC nRet = DirectoryItem::get( aDirPath, aItem ); 765cdf0e10cSrcweir sal_Bool bExists = (nRet == FileBase::E_None); 766cdf0e10cSrcweir 767cdf0e10cSrcweir FileStatus aFileStatus( FileStatusMask_Type ); 768cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus ); 769cdf0e10cSrcweir FileStatus::Type aType = aFileStatus.getFileType(); 770cdf0e10cSrcweir sal_Bool bFolder = isFolder( aType ); 771cdf0e10cSrcweir 772cdf0e10cSrcweir if( !bExists || !bFolder ) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 775cdf0e10cSrcweir return; 776cdf0e10cSrcweir } 777cdf0e10cSrcweir 778cdf0e10cSrcweir Directory aDir( aDirPath ); 779cdf0e10cSrcweir nRet = aDir.open(); 780cdf0e10cSrcweir if( nRet != FileBase::E_None ) 781cdf0e10cSrcweir { 782cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 783cdf0e10cSrcweir return; 784cdf0e10cSrcweir } 785cdf0e10cSrcweir 786cdf0e10cSrcweir for( ;; ) 787cdf0e10cSrcweir { 788cdf0e10cSrcweir DirectoryItem aItem2; 789cdf0e10cSrcweir nRet = aDir.getNextItem( aItem2 ); 790cdf0e10cSrcweir if( nRet != FileBase::E_None ) 791cdf0e10cSrcweir break; 792cdf0e10cSrcweir 793cdf0e10cSrcweir // Handle flags 794cdf0e10cSrcweir FileStatus aFileStatus2( FileStatusMask_Type | FileStatusMask_FileURL ); 795cdf0e10cSrcweir nRet = aItem2.getFileStatus( aFileStatus2 ); 796cdf0e10cSrcweir ::rtl::OUString aPath = aFileStatus2.getFileURL(); 797cdf0e10cSrcweir 798cdf0e10cSrcweir // Directory? 799cdf0e10cSrcweir FileStatus::Type aType2 = aFileStatus2.getFileType(); 800cdf0e10cSrcweir sal_Bool bFolder2 = isFolder( aType2 ); 801cdf0e10cSrcweir if( bFolder2 ) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir implRemoveDirRecursive( aPath ); 804cdf0e10cSrcweir } 805cdf0e10cSrcweir else 806cdf0e10cSrcweir { 807cdf0e10cSrcweir File::remove( aPath ); 808cdf0e10cSrcweir } 809cdf0e10cSrcweir } 810cdf0e10cSrcweir nRet = aDir.close(); 811cdf0e10cSrcweir 812cdf0e10cSrcweir nRet = Directory::remove( aDirPath ); 813cdf0e10cSrcweir } 814cdf0e10cSrcweir #endif 815cdf0e10cSrcweir 816cdf0e10cSrcweir 817cdf0e10cSrcweir RTLFUNC(RmDir) // JSM 818cdf0e10cSrcweir { 819cdf0e10cSrcweir (void)pBasic; 820cdf0e10cSrcweir (void)bWrite; 821cdf0e10cSrcweir 822cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 823cdf0e10cSrcweir if (rPar.Count() == 2) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir String aPath = rPar.Get(1)->GetString(); 826cdf0e10cSrcweir // <-- UCB 827cdf0e10cSrcweir if( hasUno() ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 830cdf0e10cSrcweir if( xSFI.is() ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir try 833cdf0e10cSrcweir { 834cdf0e10cSrcweir if( !xSFI->isFolder( aPath ) ) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 837cdf0e10cSrcweir return; 838cdf0e10cSrcweir } 839cdf0e10cSrcweir SbiInstance* pInst = pINST; 840cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 841cdf0e10cSrcweir if( bCompatibility ) 842cdf0e10cSrcweir { 843cdf0e10cSrcweir Sequence< ::rtl::OUString > aContent = xSFI->getFolderContents( aPath, true ); 844cdf0e10cSrcweir sal_Int32 nCount = aContent.getLength(); 845cdf0e10cSrcweir if( nCount > 0 ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir StarBASIC::Error( SbERR_ACCESS_ERROR ); 848cdf0e10cSrcweir return; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir } 851cdf0e10cSrcweir 852cdf0e10cSrcweir xSFI->kill( getFullPath( aPath ) ); 853cdf0e10cSrcweir } 854cdf0e10cSrcweir catch( Exception & ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 857cdf0e10cSrcweir } 858cdf0e10cSrcweir } 859cdf0e10cSrcweir } 860cdf0e10cSrcweir else 861cdf0e10cSrcweir // --> UCB 862cdf0e10cSrcweir { 863cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 864cdf0e10cSrcweir DirEntry aDirEntry(aPath); 865cdf0e10cSrcweir if (aDirEntry.Kill() != FSYS_ERR_OK) 866cdf0e10cSrcweir StarBASIC::Error( SbERR_PATH_NOT_FOUND ); 867cdf0e10cSrcweir #else 868cdf0e10cSrcweir implRemoveDirRecursive( getFullPathUNC( aPath ) ); 869cdf0e10cSrcweir #endif 870cdf0e10cSrcweir } 871cdf0e10cSrcweir } 872cdf0e10cSrcweir else 873cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir RTLFUNC(SendKeys) // JSM 877cdf0e10cSrcweir { 878cdf0e10cSrcweir (void)pBasic; 879cdf0e10cSrcweir (void)bWrite; 880cdf0e10cSrcweir 881cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 882cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir 885cdf0e10cSrcweir RTLFUNC(Exp) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir (void)pBasic; 888cdf0e10cSrcweir (void)bWrite; 889cdf0e10cSrcweir 890cdf0e10cSrcweir if( rPar.Count() < 2 ) 891cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 892cdf0e10cSrcweir else 893cdf0e10cSrcweir { 894cdf0e10cSrcweir double aDouble = rPar.Get( 1 )->GetDouble(); 895cdf0e10cSrcweir aDouble = exp( aDouble ); 896cdf0e10cSrcweir checkArithmeticOverflow( aDouble ); 897cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( aDouble ); 898cdf0e10cSrcweir } 899cdf0e10cSrcweir } 900cdf0e10cSrcweir 901cdf0e10cSrcweir RTLFUNC(FileLen) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir (void)pBasic; 904cdf0e10cSrcweir (void)bWrite; 905cdf0e10cSrcweir 906cdf0e10cSrcweir if ( rPar.Count() < 2 ) 907cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 908cdf0e10cSrcweir else 909cdf0e10cSrcweir { 910cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 911cdf0e10cSrcweir String aStr( pArg->GetString() ); 912cdf0e10cSrcweir sal_Int32 nLen = 0; 913cdf0e10cSrcweir // <-- UCB 914cdf0e10cSrcweir if( hasUno() ) 915cdf0e10cSrcweir { 916cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 917cdf0e10cSrcweir if( xSFI.is() ) 918cdf0e10cSrcweir { 919cdf0e10cSrcweir try 920cdf0e10cSrcweir { 921cdf0e10cSrcweir nLen = xSFI->getSize( getFullPath( aStr ) ); 922cdf0e10cSrcweir } 923cdf0e10cSrcweir catch( Exception & ) 924cdf0e10cSrcweir { 925cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 926cdf0e10cSrcweir } 927cdf0e10cSrcweir } 928cdf0e10cSrcweir } 929cdf0e10cSrcweir else 930cdf0e10cSrcweir // --> UCB 931cdf0e10cSrcweir { 932cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 933cdf0e10cSrcweir FileStat aStat = DirEntry( aStr ); 934cdf0e10cSrcweir nLen = aStat.GetSize(); 935cdf0e10cSrcweir #else 936cdf0e10cSrcweir DirectoryItem aItem; 937cdf0e10cSrcweir FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( aStr ), aItem ); 938cdf0e10cSrcweir FileStatus aFileStatus( FileStatusMask_FileSize ); 939cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus ); 940cdf0e10cSrcweir nLen = (sal_Int32)aFileStatus.getFileSize(); 941cdf0e10cSrcweir #endif 942cdf0e10cSrcweir } 943cdf0e10cSrcweir rPar.Get(0)->PutLong( (long)nLen ); 944cdf0e10cSrcweir } 945cdf0e10cSrcweir } 946cdf0e10cSrcweir 947cdf0e10cSrcweir 948cdf0e10cSrcweir RTLFUNC(Hex) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir (void)pBasic; 951cdf0e10cSrcweir (void)bWrite; 952cdf0e10cSrcweir 953cdf0e10cSrcweir if ( rPar.Count() < 2 ) 954cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 955cdf0e10cSrcweir else 956cdf0e10cSrcweir { 957cdf0e10cSrcweir char aBuffer[16]; 958cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 959cdf0e10cSrcweir if ( pArg->IsInteger() ) 960cdf0e10cSrcweir snprintf( aBuffer, sizeof(aBuffer), "%X", pArg->GetInteger() ); 961cdf0e10cSrcweir else 962cdf0e10cSrcweir snprintf( aBuffer, sizeof(aBuffer), "%lX", static_cast<long unsigned int>(pArg->GetLong()) ); 963cdf0e10cSrcweir rPar.Get(0)->PutString( String::CreateFromAscii( aBuffer ) ); 964cdf0e10cSrcweir } 965cdf0e10cSrcweir } 966cdf0e10cSrcweir 967cdf0e10cSrcweir // InStr( [start],string,string,[compare] ) 968cdf0e10cSrcweir 969cdf0e10cSrcweir RTLFUNC(InStr) 970cdf0e10cSrcweir { 971cdf0e10cSrcweir (void)pBasic; 972cdf0e10cSrcweir (void)bWrite; 973cdf0e10cSrcweir 974cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count()-1; 975cdf0e10cSrcweir if ( nArgCount < 2 ) 976cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 977cdf0e10cSrcweir else 978cdf0e10cSrcweir { 979cdf0e10cSrcweir sal_uInt16 nStartPos = 1; 980cdf0e10cSrcweir 981cdf0e10cSrcweir sal_uInt16 nFirstStringPos = 1; 982cdf0e10cSrcweir if ( nArgCount >= 3 ) 983cdf0e10cSrcweir { 984cdf0e10cSrcweir sal_Int32 lStartPos = rPar.Get(1)->GetLong(); 985cdf0e10cSrcweir if( lStartPos <= 0 || lStartPos > 0xffff ) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 988cdf0e10cSrcweir lStartPos = 1; 989cdf0e10cSrcweir } 990cdf0e10cSrcweir nStartPos = (sal_uInt16)lStartPos; 991cdf0e10cSrcweir nFirstStringPos++; 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir SbiInstance* pInst = pINST; 995cdf0e10cSrcweir int bTextMode; 996cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 997cdf0e10cSrcweir if( bCompatibility ) 998cdf0e10cSrcweir { 999cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL; 1000cdf0e10cSrcweir bTextMode = pRT ? pRT->GetImageFlag( SBIMG_COMPARETEXT ) : sal_False; 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir else 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir bTextMode = 1;; 1005cdf0e10cSrcweir } 1006cdf0e10cSrcweir if ( nArgCount == 4 ) 1007cdf0e10cSrcweir bTextMode = rPar.Get(4)->GetInteger(); 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir sal_uInt16 nPos; 1010cdf0e10cSrcweir const String& rToken = rPar.Get(nFirstStringPos+1)->GetString(); 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir // #97545 Always find empty string 1013cdf0e10cSrcweir if( !rToken.Len() ) 1014cdf0e10cSrcweir { 1015cdf0e10cSrcweir nPos = nStartPos; 1016cdf0e10cSrcweir } 1017cdf0e10cSrcweir else 1018cdf0e10cSrcweir { 1019cdf0e10cSrcweir if( !bTextMode ) 1020cdf0e10cSrcweir { 1021cdf0e10cSrcweir const String& rStr1 = rPar.Get(nFirstStringPos)->GetString(); 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir nPos = rStr1.Search( rToken, nStartPos-1 ); 1024cdf0e10cSrcweir if ( nPos == STRING_NOTFOUND ) 1025cdf0e10cSrcweir nPos = 0; 1026cdf0e10cSrcweir else 1027cdf0e10cSrcweir nPos++; 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir else 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir String aStr1 = rPar.Get(nFirstStringPos)->GetString(); 1032cdf0e10cSrcweir String aToken = rToken; 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir aStr1.ToUpperAscii(); 1035cdf0e10cSrcweir aToken.ToUpperAscii(); 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir nPos = aStr1.Search( aToken, nStartPos-1 ); 1038cdf0e10cSrcweir if ( nPos == STRING_NOTFOUND ) 1039cdf0e10cSrcweir nPos = 0; 1040cdf0e10cSrcweir else 1041cdf0e10cSrcweir nPos++; 1042cdf0e10cSrcweir } 1043cdf0e10cSrcweir } 1044cdf0e10cSrcweir rPar.Get(0)->PutLong( nPos ); 1045cdf0e10cSrcweir } 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir 1049cdf0e10cSrcweir // InstrRev(string1, string2[, start[, compare]]) 1050cdf0e10cSrcweir 1051cdf0e10cSrcweir RTLFUNC(InStrRev) 1052cdf0e10cSrcweir { 1053cdf0e10cSrcweir (void)pBasic; 1054cdf0e10cSrcweir (void)bWrite; 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count()-1; 1057cdf0e10cSrcweir if ( nArgCount < 2 ) 1058cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1059cdf0e10cSrcweir else 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir String aStr1 = rPar.Get(1)->GetString(); 1062cdf0e10cSrcweir String aToken = rPar.Get(2)->GetString(); 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir sal_Int32 lStartPos = -1; 1065cdf0e10cSrcweir if ( nArgCount >= 3 ) 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir lStartPos = rPar.Get(3)->GetLong(); 1068cdf0e10cSrcweir if( (lStartPos <= 0 && lStartPos != -1) || lStartPos > 0xffff ) 1069cdf0e10cSrcweir { 1070cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1071cdf0e10cSrcweir lStartPos = -1; 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir } 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir SbiInstance* pInst = pINST; 1076cdf0e10cSrcweir int bTextMode; 1077cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 1078cdf0e10cSrcweir if( bCompatibility ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL; 1081cdf0e10cSrcweir bTextMode = pRT ? pRT->GetImageFlag( SBIMG_COMPARETEXT ) : sal_False; 1082cdf0e10cSrcweir } 1083cdf0e10cSrcweir else 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir bTextMode = 1;; 1086cdf0e10cSrcweir } 1087cdf0e10cSrcweir if ( nArgCount == 4 ) 1088cdf0e10cSrcweir bTextMode = rPar.Get(4)->GetInteger(); 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir sal_uInt16 nStrLen = aStr1.Len(); 1091cdf0e10cSrcweir sal_uInt16 nStartPos = lStartPos == -1 ? nStrLen : (sal_uInt16)lStartPos; 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir sal_uInt16 nPos = 0; 1094cdf0e10cSrcweir if( nStartPos <= nStrLen ) 1095cdf0e10cSrcweir { 1096cdf0e10cSrcweir sal_uInt16 nTokenLen = aToken.Len(); 1097cdf0e10cSrcweir if( !nTokenLen ) 1098cdf0e10cSrcweir { 1099cdf0e10cSrcweir // Always find empty string 1100cdf0e10cSrcweir nPos = nStartPos; 1101cdf0e10cSrcweir } 1102cdf0e10cSrcweir else if( nStrLen > 0 ) 1103cdf0e10cSrcweir { 1104cdf0e10cSrcweir if( !bTextMode ) 1105cdf0e10cSrcweir { 1106cdf0e10cSrcweir ::rtl::OUString aOUStr1 ( aStr1 ); 1107cdf0e10cSrcweir ::rtl::OUString aOUToken( aToken ); 1108cdf0e10cSrcweir sal_Int32 nRet = aOUStr1.lastIndexOf( aOUToken, nStartPos ); 1109cdf0e10cSrcweir if( nRet == -1 ) 1110cdf0e10cSrcweir nPos = 0; 1111cdf0e10cSrcweir else 1112cdf0e10cSrcweir nPos = (sal_uInt16)nRet + 1; 1113cdf0e10cSrcweir } 1114cdf0e10cSrcweir else 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir aStr1.ToUpperAscii(); 1117cdf0e10cSrcweir aToken.ToUpperAscii(); 1118cdf0e10cSrcweir 1119cdf0e10cSrcweir ::rtl::OUString aOUStr1 ( aStr1 ); 1120cdf0e10cSrcweir ::rtl::OUString aOUToken( aToken ); 1121cdf0e10cSrcweir sal_Int32 nRet = aOUStr1.lastIndexOf( aOUToken, nStartPos ); 1122cdf0e10cSrcweir 1123cdf0e10cSrcweir if( nRet == -1 ) 1124cdf0e10cSrcweir nPos = 0; 1125cdf0e10cSrcweir else 1126cdf0e10cSrcweir nPos = (sal_uInt16)nRet + 1; 1127cdf0e10cSrcweir } 1128cdf0e10cSrcweir } 1129cdf0e10cSrcweir } 1130cdf0e10cSrcweir rPar.Get(0)->PutLong( nPos ); 1131cdf0e10cSrcweir } 1132cdf0e10cSrcweir } 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir /* 1136cdf0e10cSrcweir Int( 2.8 ) = 2.0 1137cdf0e10cSrcweir Int( -2.8 ) = -3.0 1138cdf0e10cSrcweir Fix( 2.8 ) = 2.0 1139cdf0e10cSrcweir Fix( -2.8 ) = -2.0 <- !! 1140cdf0e10cSrcweir */ 1141cdf0e10cSrcweir 1142cdf0e10cSrcweir RTLFUNC(Int) 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir (void)pBasic; 1145cdf0e10cSrcweir (void)bWrite; 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1148cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1149cdf0e10cSrcweir else 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 1152cdf0e10cSrcweir double aDouble= pArg->GetDouble(); 1153cdf0e10cSrcweir /* 1154cdf0e10cSrcweir floor( 2.8 ) = 2.0 1155cdf0e10cSrcweir floor( -2.8 ) = -3.0 1156cdf0e10cSrcweir */ 1157cdf0e10cSrcweir aDouble = floor( aDouble ); 1158cdf0e10cSrcweir rPar.Get(0)->PutDouble( aDouble ); 1159cdf0e10cSrcweir } 1160cdf0e10cSrcweir } 1161cdf0e10cSrcweir 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir 1164cdf0e10cSrcweir RTLFUNC(Fix) 1165cdf0e10cSrcweir { 1166cdf0e10cSrcweir (void)pBasic; 1167cdf0e10cSrcweir (void)bWrite; 1168cdf0e10cSrcweir 1169cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1170cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1171cdf0e10cSrcweir else 1172cdf0e10cSrcweir { 1173cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 1174cdf0e10cSrcweir double aDouble = pArg->GetDouble(); 1175cdf0e10cSrcweir if ( aDouble >= 0.0 ) 1176cdf0e10cSrcweir aDouble = floor( aDouble ); 1177cdf0e10cSrcweir else 1178cdf0e10cSrcweir aDouble = ceil( aDouble ); 1179cdf0e10cSrcweir rPar.Get(0)->PutDouble( aDouble ); 1180cdf0e10cSrcweir } 1181cdf0e10cSrcweir } 1182cdf0e10cSrcweir 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir RTLFUNC(LCase) 1185cdf0e10cSrcweir { 1186cdf0e10cSrcweir (void)pBasic; 1187cdf0e10cSrcweir (void)bWrite; 1188cdf0e10cSrcweir 1189cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1190cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1191cdf0e10cSrcweir else 1192cdf0e10cSrcweir { 1193cdf0e10cSrcweir CharClass& rCharClass = GetCharClass(); 1194cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 1195cdf0e10cSrcweir rCharClass.toLower( aStr ); 1196cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1197cdf0e10cSrcweir } 1198cdf0e10cSrcweir } 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir RTLFUNC(Left) 1201cdf0e10cSrcweir { 1202cdf0e10cSrcweir (void)pBasic; 1203cdf0e10cSrcweir (void)bWrite; 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir if ( rPar.Count() < 3 ) 1206cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1207cdf0e10cSrcweir else 1208cdf0e10cSrcweir { 1209cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 1210cdf0e10cSrcweir sal_Int32 lResultLen = rPar.Get(2)->GetLong(); 1211cdf0e10cSrcweir if( lResultLen > 0xffff ) 1212cdf0e10cSrcweir { 1213cdf0e10cSrcweir lResultLen = 0xffff; 1214cdf0e10cSrcweir } 1215cdf0e10cSrcweir else if( lResultLen < 0 ) 1216cdf0e10cSrcweir { 1217cdf0e10cSrcweir lResultLen = 0; 1218cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1219cdf0e10cSrcweir } 1220cdf0e10cSrcweir aStr.Erase( (sal_uInt16)lResultLen ); 1221cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1222cdf0e10cSrcweir } 1223cdf0e10cSrcweir } 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir RTLFUNC(Log) 1226cdf0e10cSrcweir { 1227cdf0e10cSrcweir (void)pBasic; 1228cdf0e10cSrcweir (void)bWrite; 1229cdf0e10cSrcweir 1230cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1231cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1232cdf0e10cSrcweir else 1233cdf0e10cSrcweir { 1234cdf0e10cSrcweir double aArg = rPar.Get(1)->GetDouble(); 1235cdf0e10cSrcweir if ( aArg > 0 ) 1236cdf0e10cSrcweir { 1237cdf0e10cSrcweir double d = log( aArg ); 1238cdf0e10cSrcweir checkArithmeticOverflow( d ); 1239cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( d ); 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir else 1242cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1243cdf0e10cSrcweir } 1244cdf0e10cSrcweir } 1245cdf0e10cSrcweir 1246cdf0e10cSrcweir RTLFUNC(LTrim) 1247cdf0e10cSrcweir { 1248cdf0e10cSrcweir (void)pBasic; 1249cdf0e10cSrcweir (void)bWrite; 1250cdf0e10cSrcweir 1251cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1252cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1253cdf0e10cSrcweir else 1254cdf0e10cSrcweir { 1255cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 1256cdf0e10cSrcweir aStr.EraseLeadingChars(); 1257cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1258cdf0e10cSrcweir } 1259cdf0e10cSrcweir } 1260cdf0e10cSrcweir 1261cdf0e10cSrcweir 1262cdf0e10cSrcweir // Mid( String, nStart, nLength ) 1263cdf0e10cSrcweir 1264cdf0e10cSrcweir RTLFUNC(Mid) 1265cdf0e10cSrcweir { 1266cdf0e10cSrcweir (void)pBasic; 1267cdf0e10cSrcweir (void)bWrite; 1268cdf0e10cSrcweir 1269cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count()-1; 1270cdf0e10cSrcweir if ( nArgCount < 2 ) 1271cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1272cdf0e10cSrcweir else 1273cdf0e10cSrcweir { 1274cdf0e10cSrcweir // #23178: Funktionalitaet von Mid$ als Anweisung nachbilden, indem 1275cdf0e10cSrcweir // als weiterer (4.) Parameter ein Ersetzungsstring aufgenommen wird. 1276cdf0e10cSrcweir // Anders als im Original kann in dieser Variante der 3. Parameter 1277cdf0e10cSrcweir // nLength nicht weggelassen werden. Ist ueber bWrite schon vorgesehen. 1278cdf0e10cSrcweir if( nArgCount == 4 ) 1279cdf0e10cSrcweir bWrite = sal_True; 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir String aArgStr = rPar.Get(1)->GetString(); 1282cdf0e10cSrcweir sal_uInt16 nStartPos = (sal_uInt16)(rPar.Get(2)->GetLong() ); 1283cdf0e10cSrcweir if ( nStartPos == 0 ) 1284cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1285cdf0e10cSrcweir else 1286cdf0e10cSrcweir { 1287cdf0e10cSrcweir nStartPos--; 1288cdf0e10cSrcweir sal_uInt16 nLen = 0xffff; 1289cdf0e10cSrcweir bool bWriteNoLenParam = false; 1290cdf0e10cSrcweir if ( nArgCount == 3 || bWrite ) 1291cdf0e10cSrcweir { 1292cdf0e10cSrcweir sal_Int32 n = rPar.Get(3)->GetLong(); 1293cdf0e10cSrcweir if( bWrite && n == -1 ) 1294cdf0e10cSrcweir bWriteNoLenParam = true; 1295cdf0e10cSrcweir nLen = (sal_uInt16)n; 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir String aResultStr; 1298cdf0e10cSrcweir if ( bWrite ) 1299cdf0e10cSrcweir { 1300cdf0e10cSrcweir SbiInstance* pInst = pINST; 1301cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 1302cdf0e10cSrcweir if( bCompatibility ) 1303cdf0e10cSrcweir { 1304cdf0e10cSrcweir sal_uInt16 nArgLen = aArgStr.Len(); 1305cdf0e10cSrcweir if( nStartPos + 1 > nArgLen ) 1306cdf0e10cSrcweir { 1307cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1308cdf0e10cSrcweir return; 1309cdf0e10cSrcweir } 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir String aReplaceStr = rPar.Get(4)->GetString(); 1312cdf0e10cSrcweir sal_uInt16 nReplaceStrLen = aReplaceStr.Len(); 1313cdf0e10cSrcweir sal_uInt16 nReplaceLen; 1314cdf0e10cSrcweir if( bWriteNoLenParam ) 1315cdf0e10cSrcweir { 1316cdf0e10cSrcweir nReplaceLen = nReplaceStrLen; 1317cdf0e10cSrcweir } 1318cdf0e10cSrcweir else 1319cdf0e10cSrcweir { 1320cdf0e10cSrcweir nReplaceLen = nLen; 1321cdf0e10cSrcweir if( nReplaceLen > nReplaceStrLen ) 1322cdf0e10cSrcweir nReplaceLen = nReplaceStrLen; 1323cdf0e10cSrcweir } 1324cdf0e10cSrcweir 1325cdf0e10cSrcweir sal_uInt16 nReplaceEndPos = nStartPos + nReplaceLen; 1326cdf0e10cSrcweir if( nReplaceEndPos > nArgLen ) 1327cdf0e10cSrcweir nReplaceLen -= (nReplaceEndPos - nArgLen); 1328cdf0e10cSrcweir 1329cdf0e10cSrcweir aResultStr = aArgStr; 1330cdf0e10cSrcweir sal_uInt16 nErase = nReplaceLen; 1331cdf0e10cSrcweir aResultStr.Erase( nStartPos, nErase ); 1332cdf0e10cSrcweir aResultStr.Insert( aReplaceStr, 0, nReplaceLen, nStartPos ); 1333cdf0e10cSrcweir } 1334cdf0e10cSrcweir else 1335cdf0e10cSrcweir { 1336cdf0e10cSrcweir aResultStr = aArgStr; 1337cdf0e10cSrcweir aResultStr.Erase( nStartPos, nLen ); 1338cdf0e10cSrcweir aResultStr.Insert(rPar.Get(4)->GetString(),0,nLen,nStartPos); 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir rPar.Get(1)->PutString( aResultStr ); 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir else 1344cdf0e10cSrcweir { 1345cdf0e10cSrcweir aResultStr = aArgStr.Copy( nStartPos, nLen ); 1346cdf0e10cSrcweir rPar.Get(0)->PutString( aResultStr ); 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir } 1349cdf0e10cSrcweir } 1350cdf0e10cSrcweir } 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir RTLFUNC(Oct) 1353cdf0e10cSrcweir { 1354cdf0e10cSrcweir (void)pBasic; 1355cdf0e10cSrcweir (void)bWrite; 1356cdf0e10cSrcweir 1357cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1358cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1359cdf0e10cSrcweir else 1360cdf0e10cSrcweir { 1361cdf0e10cSrcweir char aBuffer[16]; 1362cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 1363cdf0e10cSrcweir if ( pArg->IsInteger() ) 1364cdf0e10cSrcweir snprintf( aBuffer, sizeof(aBuffer), "%o", pArg->GetInteger() ); 1365cdf0e10cSrcweir else 1366cdf0e10cSrcweir snprintf( aBuffer, sizeof(aBuffer), "%lo", static_cast<long unsigned int>(pArg->GetLong()) ); 1367cdf0e10cSrcweir rPar.Get(0)->PutString( String::CreateFromAscii( aBuffer ) ); 1368cdf0e10cSrcweir } 1369cdf0e10cSrcweir } 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir // Replace(expression, find, replace[, start[, count[, compare]]]) 1372cdf0e10cSrcweir 1373cdf0e10cSrcweir RTLFUNC(Replace) 1374cdf0e10cSrcweir { 1375cdf0e10cSrcweir (void)pBasic; 1376cdf0e10cSrcweir (void)bWrite; 1377cdf0e10cSrcweir 1378cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count()-1; 1379cdf0e10cSrcweir if ( nArgCount < 3 || nArgCount > 6 ) 1380cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1381cdf0e10cSrcweir else 1382cdf0e10cSrcweir { 1383cdf0e10cSrcweir String aExpStr = rPar.Get(1)->GetString(); 1384cdf0e10cSrcweir String aFindStr = rPar.Get(2)->GetString(); 1385cdf0e10cSrcweir String aReplaceStr = rPar.Get(3)->GetString(); 1386cdf0e10cSrcweir 1387cdf0e10cSrcweir sal_Int32 lStartPos = 1; 1388cdf0e10cSrcweir if ( nArgCount >= 4 ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir if( rPar.Get(4)->GetType() != SbxEMPTY ) 1391cdf0e10cSrcweir lStartPos = rPar.Get(4)->GetLong(); 1392cdf0e10cSrcweir if( lStartPos < 1 || lStartPos > 0xffff ) 1393cdf0e10cSrcweir { 1394cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1395cdf0e10cSrcweir lStartPos = 1; 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir } 1398cdf0e10cSrcweir 1399cdf0e10cSrcweir sal_Int32 lCount = -1; 1400cdf0e10cSrcweir if( nArgCount >=5 ) 1401cdf0e10cSrcweir { 1402cdf0e10cSrcweir if( rPar.Get(5)->GetType() != SbxEMPTY ) 1403cdf0e10cSrcweir lCount = rPar.Get(5)->GetLong(); 1404cdf0e10cSrcweir if( lCount < -1 || lCount > 0xffff ) 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1407cdf0e10cSrcweir lCount = -1; 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir } 1410cdf0e10cSrcweir 1411cdf0e10cSrcweir SbiInstance* pInst = pINST; 1412cdf0e10cSrcweir int bTextMode; 1413cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 1414cdf0e10cSrcweir if( bCompatibility ) 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL; 1417cdf0e10cSrcweir bTextMode = pRT ? pRT->GetImageFlag( SBIMG_COMPARETEXT ) : sal_False; 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir else 1420cdf0e10cSrcweir { 1421cdf0e10cSrcweir bTextMode = 1; 1422cdf0e10cSrcweir } 1423cdf0e10cSrcweir if ( nArgCount == 6 ) 1424cdf0e10cSrcweir bTextMode = rPar.Get(6)->GetInteger(); 1425cdf0e10cSrcweir 1426cdf0e10cSrcweir sal_uInt16 nExpStrLen = aExpStr.Len(); 1427cdf0e10cSrcweir sal_uInt16 nFindStrLen = aFindStr.Len(); 1428cdf0e10cSrcweir sal_uInt16 nReplaceStrLen = aReplaceStr.Len(); 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir if( lStartPos <= nExpStrLen ) 1431cdf0e10cSrcweir { 1432cdf0e10cSrcweir sal_uInt16 nPos = static_cast<sal_uInt16>( lStartPos - 1 ); 1433cdf0e10cSrcweir sal_uInt16 nCounts = 0; 1434cdf0e10cSrcweir while( lCount == -1 || lCount > nCounts ) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir String aSrcStr( aExpStr ); 1437cdf0e10cSrcweir if( bTextMode ) 1438cdf0e10cSrcweir { 1439cdf0e10cSrcweir aSrcStr.ToUpperAscii(); 1440cdf0e10cSrcweir aFindStr.ToUpperAscii(); 1441cdf0e10cSrcweir } 1442cdf0e10cSrcweir nPos = aSrcStr.Search( aFindStr, nPos ); 1443cdf0e10cSrcweir if( nPos != STRING_NOTFOUND ) 1444cdf0e10cSrcweir { 1445cdf0e10cSrcweir aExpStr.Replace( nPos, nFindStrLen, aReplaceStr ); 1446cdf0e10cSrcweir nPos = nPos - nFindStrLen + nReplaceStrLen + 1; 1447cdf0e10cSrcweir nCounts++; 1448cdf0e10cSrcweir } 1449cdf0e10cSrcweir else 1450cdf0e10cSrcweir { 1451cdf0e10cSrcweir break; 1452cdf0e10cSrcweir } 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir rPar.Get(0)->PutString( aExpStr.Copy( static_cast<sal_uInt16>(lStartPos - 1) ) ); 1456cdf0e10cSrcweir } 1457cdf0e10cSrcweir } 1458cdf0e10cSrcweir 1459cdf0e10cSrcweir RTLFUNC(Right) 1460cdf0e10cSrcweir { 1461cdf0e10cSrcweir (void)pBasic; 1462cdf0e10cSrcweir (void)bWrite; 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir if ( rPar.Count() < 3 ) 1465cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1466cdf0e10cSrcweir else 1467cdf0e10cSrcweir { 1468cdf0e10cSrcweir const String& rStr = rPar.Get(1)->GetString(); 1469cdf0e10cSrcweir sal_Int32 lResultLen = rPar.Get(2)->GetLong(); 1470cdf0e10cSrcweir if( lResultLen > 0xffff ) 1471cdf0e10cSrcweir { 1472cdf0e10cSrcweir lResultLen = 0xffff; 1473cdf0e10cSrcweir } 1474cdf0e10cSrcweir else if( lResultLen < 0 ) 1475cdf0e10cSrcweir { 1476cdf0e10cSrcweir lResultLen = 0; 1477cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1478cdf0e10cSrcweir } 1479cdf0e10cSrcweir sal_uInt16 nResultLen = (sal_uInt16)lResultLen; 1480cdf0e10cSrcweir sal_uInt16 nStrLen = rStr.Len(); 1481cdf0e10cSrcweir if ( nResultLen > nStrLen ) 1482cdf0e10cSrcweir nResultLen = nStrLen; 1483cdf0e10cSrcweir String aResultStr = rStr.Copy( nStrLen-nResultLen ); 1484cdf0e10cSrcweir rPar.Get(0)->PutString( aResultStr ); 1485cdf0e10cSrcweir } 1486cdf0e10cSrcweir } 1487cdf0e10cSrcweir 1488cdf0e10cSrcweir RTLFUNC(RTL) 1489cdf0e10cSrcweir { 1490cdf0e10cSrcweir (void)pBasic; 1491cdf0e10cSrcweir (void)bWrite; 1492cdf0e10cSrcweir 1493cdf0e10cSrcweir rPar.Get( 0 )->PutObject( pBasic->getRTL() ); 1494cdf0e10cSrcweir } 1495cdf0e10cSrcweir 1496cdf0e10cSrcweir RTLFUNC(RTrim) 1497cdf0e10cSrcweir { 1498cdf0e10cSrcweir (void)pBasic; 1499cdf0e10cSrcweir (void)bWrite; 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1502cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1503cdf0e10cSrcweir else 1504cdf0e10cSrcweir { 1505cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 1506cdf0e10cSrcweir aStr.EraseTrailingChars(); 1507cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir } 1510cdf0e10cSrcweir 1511cdf0e10cSrcweir RTLFUNC(Sgn) 1512cdf0e10cSrcweir { 1513cdf0e10cSrcweir (void)pBasic; 1514cdf0e10cSrcweir (void)bWrite; 1515cdf0e10cSrcweir 1516cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1517cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1518cdf0e10cSrcweir else 1519cdf0e10cSrcweir { 1520cdf0e10cSrcweir double aDouble = rPar.Get(1)->GetDouble(); 1521cdf0e10cSrcweir sal_Int16 nResult = 0; 1522cdf0e10cSrcweir if ( aDouble > 0 ) 1523cdf0e10cSrcweir nResult = 1; 1524cdf0e10cSrcweir else if ( aDouble < 0 ) 1525cdf0e10cSrcweir nResult = -1; 1526cdf0e10cSrcweir rPar.Get(0)->PutInteger( nResult ); 1527cdf0e10cSrcweir } 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir 1530cdf0e10cSrcweir RTLFUNC(Space) 1531cdf0e10cSrcweir { 1532cdf0e10cSrcweir (void)pBasic; 1533cdf0e10cSrcweir (void)bWrite; 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1536cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1537cdf0e10cSrcweir else 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir String aStr; 1540cdf0e10cSrcweir aStr.Fill( (sal_uInt16)(rPar.Get(1)->GetLong() )); 1541cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1542cdf0e10cSrcweir } 1543cdf0e10cSrcweir } 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir RTLFUNC(Spc) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir (void)pBasic; 1548cdf0e10cSrcweir (void)bWrite; 1549cdf0e10cSrcweir 1550cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1551cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1552cdf0e10cSrcweir else 1553cdf0e10cSrcweir { 1554cdf0e10cSrcweir String aStr; 1555cdf0e10cSrcweir aStr.Fill( (sal_uInt16)(rPar.Get(1)->GetLong() )); 1556cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir 1560cdf0e10cSrcweir RTLFUNC(Sqr) 1561cdf0e10cSrcweir { 1562cdf0e10cSrcweir (void)pBasic; 1563cdf0e10cSrcweir (void)bWrite; 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1566cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1567cdf0e10cSrcweir else 1568cdf0e10cSrcweir { 1569cdf0e10cSrcweir double aDouble = rPar.Get(1)->GetDouble(); 1570cdf0e10cSrcweir if ( aDouble >= 0 ) 1571cdf0e10cSrcweir rPar.Get(0)->PutDouble( sqrt( aDouble )); 1572cdf0e10cSrcweir else 1573cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1574cdf0e10cSrcweir } 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir 1577cdf0e10cSrcweir RTLFUNC(Str) 1578cdf0e10cSrcweir { 1579cdf0e10cSrcweir (void)pBasic; 1580cdf0e10cSrcweir (void)bWrite; 1581cdf0e10cSrcweir 1582cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1583cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1584cdf0e10cSrcweir else 1585cdf0e10cSrcweir { 1586cdf0e10cSrcweir String aStr; 1587cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 1588cdf0e10cSrcweir pArg->Format( aStr ); 1589cdf0e10cSrcweir 1590cdf0e10cSrcweir // Numbers start with a space 1591cdf0e10cSrcweir if( pArg->IsNumericRTL() ) 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir // Kommas durch Punkte ersetzen, damit es symmetrisch zu Val ist! 1594cdf0e10cSrcweir aStr.SearchAndReplace( ',', '.' ); 1595cdf0e10cSrcweir 1596cdf0e10cSrcweir SbiInstance* pInst = pINST; 1597cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 1598cdf0e10cSrcweir if( bCompatibility ) 1599cdf0e10cSrcweir { 1600cdf0e10cSrcweir xub_StrLen nLen = aStr.Len(); 1601cdf0e10cSrcweir 1602cdf0e10cSrcweir const sal_Unicode* pBuf = aStr.GetBuffer(); 1603cdf0e10cSrcweir 1604cdf0e10cSrcweir bool bNeg = ( pBuf[0] == '-' ); 1605cdf0e10cSrcweir sal_uInt16 iZeroSearch = 0; 1606cdf0e10cSrcweir if( bNeg ) 1607cdf0e10cSrcweir iZeroSearch++; 1608cdf0e10cSrcweir 1609cdf0e10cSrcweir sal_uInt16 iNext = iZeroSearch + 1; 1610cdf0e10cSrcweir if( pBuf[iZeroSearch] == '0' && nLen > iNext && pBuf[iNext] == '.' ) 1611cdf0e10cSrcweir { 1612cdf0e10cSrcweir aStr.Erase( iZeroSearch, 1 ); 1613cdf0e10cSrcweir pBuf = aStr.GetBuffer(); 1614cdf0e10cSrcweir } 1615cdf0e10cSrcweir if( !bNeg ) 1616cdf0e10cSrcweir aStr.Insert( ' ', 0 ); 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir else 1619cdf0e10cSrcweir aStr.Insert( ' ', 0 ); 1620cdf0e10cSrcweir } 1621cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1622cdf0e10cSrcweir } 1623cdf0e10cSrcweir } 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir RTLFUNC(StrComp) 1626cdf0e10cSrcweir { 1627cdf0e10cSrcweir (void)pBasic; 1628cdf0e10cSrcweir (void)bWrite; 1629cdf0e10cSrcweir 1630cdf0e10cSrcweir if ( rPar.Count() < 3 ) 1631cdf0e10cSrcweir { 1632cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1633cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 1634cdf0e10cSrcweir return; 1635cdf0e10cSrcweir } 1636cdf0e10cSrcweir const String& rStr1 = rPar.Get(1)->GetString(); 1637cdf0e10cSrcweir const String& rStr2 = rPar.Get(2)->GetString(); 1638cdf0e10cSrcweir 1639cdf0e10cSrcweir SbiInstance* pInst = pINST; 1640cdf0e10cSrcweir sal_Int16 nTextCompare; 1641cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 1642cdf0e10cSrcweir if( bCompatibility ) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL; 1645cdf0e10cSrcweir nTextCompare = pRT ? pRT->GetImageFlag( SBIMG_COMPARETEXT ) : sal_False; 1646cdf0e10cSrcweir } 1647cdf0e10cSrcweir else 1648cdf0e10cSrcweir { 1649cdf0e10cSrcweir nTextCompare = sal_True; 1650cdf0e10cSrcweir } 1651cdf0e10cSrcweir if ( rPar.Count() == 4 ) 1652cdf0e10cSrcweir nTextCompare = rPar.Get(3)->GetInteger(); 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir if( !bCompatibility ) 1655cdf0e10cSrcweir nTextCompare = !nTextCompare; 1656cdf0e10cSrcweir 1657cdf0e10cSrcweir StringCompare aResult; 1658cdf0e10cSrcweir sal_Int32 nRetValue = 0; 1659cdf0e10cSrcweir if( nTextCompare ) 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir ::utl::TransliterationWrapper* pTransliterationWrapper = GetSbData()->pTransliterationWrapper; 1662cdf0e10cSrcweir if( !pTransliterationWrapper ) 1663cdf0e10cSrcweir { 1664cdf0e10cSrcweir com::sun::star::uno::Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory(); 1665cdf0e10cSrcweir pTransliterationWrapper = GetSbData()->pTransliterationWrapper = 1666cdf0e10cSrcweir new ::utl::TransliterationWrapper( xSMgr, 1667cdf0e10cSrcweir ::com::sun::star::i18n::TransliterationModules_IGNORE_CASE | 1668cdf0e10cSrcweir ::com::sun::star::i18n::TransliterationModules_IGNORE_KANA | 1669cdf0e10cSrcweir ::com::sun::star::i18n::TransliterationModules_IGNORE_WIDTH ); 1670cdf0e10cSrcweir } 1671cdf0e10cSrcweir 1672cdf0e10cSrcweir LanguageType eLangType = GetpApp()->GetSettings().GetLanguage(); 1673cdf0e10cSrcweir pTransliterationWrapper->loadModuleIfNeeded( eLangType ); 1674cdf0e10cSrcweir nRetValue = pTransliterationWrapper->compareString( rStr1, rStr2 ); 1675cdf0e10cSrcweir } 1676cdf0e10cSrcweir else 1677cdf0e10cSrcweir { 1678cdf0e10cSrcweir aResult = rStr1.CompareTo( rStr2 ); 1679cdf0e10cSrcweir if ( aResult == COMPARE_LESS ) 1680cdf0e10cSrcweir nRetValue = -1; 1681cdf0e10cSrcweir else if ( aResult == COMPARE_GREATER ) 1682cdf0e10cSrcweir nRetValue = 1; 1683cdf0e10cSrcweir } 1684cdf0e10cSrcweir 1685cdf0e10cSrcweir rPar.Get(0)->PutInteger( sal::static_int_cast< sal_Int16 >( nRetValue ) ); 1686cdf0e10cSrcweir } 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir RTLFUNC(String) 1689cdf0e10cSrcweir { 1690cdf0e10cSrcweir (void)pBasic; 1691cdf0e10cSrcweir (void)bWrite; 1692cdf0e10cSrcweir 1693cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1694cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1695cdf0e10cSrcweir else 1696cdf0e10cSrcweir { 1697cdf0e10cSrcweir String aStr; 1698cdf0e10cSrcweir sal_Unicode aFiller; 1699cdf0e10cSrcweir sal_Int32 lCount = rPar.Get(1)->GetLong(); 1700cdf0e10cSrcweir if( lCount < 0 || lCount > 0xffff ) 1701cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1702cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16)lCount; 1703cdf0e10cSrcweir if( rPar.Get(2)->GetType() == SbxINTEGER ) 1704cdf0e10cSrcweir aFiller = (sal_Unicode)rPar.Get(2)->GetInteger(); 1705cdf0e10cSrcweir else 1706cdf0e10cSrcweir { 1707cdf0e10cSrcweir const String& rStr = rPar.Get(2)->GetString(); 1708cdf0e10cSrcweir aFiller = rStr.GetBuffer()[0]; 1709cdf0e10cSrcweir } 1710cdf0e10cSrcweir aStr.Fill( nCount, aFiller ); 1711cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1712cdf0e10cSrcweir } 1713cdf0e10cSrcweir } 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir RTLFUNC(Tan) 1716cdf0e10cSrcweir { 1717cdf0e10cSrcweir (void)pBasic; 1718cdf0e10cSrcweir (void)bWrite; 1719cdf0e10cSrcweir 1720cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1721cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1722cdf0e10cSrcweir else 1723cdf0e10cSrcweir { 1724cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 1725cdf0e10cSrcweir rPar.Get( 0 )->PutDouble( tan( pArg->GetDouble() ) ); 1726cdf0e10cSrcweir } 1727cdf0e10cSrcweir } 1728cdf0e10cSrcweir 1729cdf0e10cSrcweir RTLFUNC(UCase) 1730cdf0e10cSrcweir { 1731cdf0e10cSrcweir (void)pBasic; 1732cdf0e10cSrcweir (void)bWrite; 1733cdf0e10cSrcweir 1734cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1735cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1736cdf0e10cSrcweir else 1737cdf0e10cSrcweir { 1738cdf0e10cSrcweir CharClass& rCharClass = GetCharClass(); 1739cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 1740cdf0e10cSrcweir rCharClass.toUpper( aStr ); 1741cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1742cdf0e10cSrcweir } 1743cdf0e10cSrcweir } 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir 1746cdf0e10cSrcweir RTLFUNC(Val) 1747cdf0e10cSrcweir { 1748cdf0e10cSrcweir (void)pBasic; 1749cdf0e10cSrcweir (void)bWrite; 1750cdf0e10cSrcweir 1751cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1752cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1753cdf0e10cSrcweir else 1754cdf0e10cSrcweir { 1755cdf0e10cSrcweir double nResult = 0.0; 1756cdf0e10cSrcweir char* pEndPtr; 1757cdf0e10cSrcweir 1758cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 1759cdf0e10cSrcweir // lt. Mikkysoft bei Kommas abbrechen! 1760cdf0e10cSrcweir // for( sal_uInt16 n=0; n < aStr.Len(); n++ ) 1761cdf0e10cSrcweir // if( aStr[n] == ',' ) aStr[n] = '.'; 1762cdf0e10cSrcweir 1763cdf0e10cSrcweir FilterWhiteSpace( aStr ); 1764cdf0e10cSrcweir if ( aStr.GetBuffer()[0] == '&' && aStr.Len() > 1 ) 1765cdf0e10cSrcweir { 1766cdf0e10cSrcweir int nRadix = 10; 1767cdf0e10cSrcweir char aChar = (char)aStr.GetBuffer()[1]; 1768cdf0e10cSrcweir if ( aChar == 'h' || aChar == 'H' ) 1769cdf0e10cSrcweir nRadix = 16; 1770cdf0e10cSrcweir else if ( aChar == 'o' || aChar == 'O' ) 1771cdf0e10cSrcweir nRadix = 8; 1772cdf0e10cSrcweir if ( nRadix != 10 ) 1773cdf0e10cSrcweir { 1774cdf0e10cSrcweir ByteString aByteStr( aStr, gsl_getSystemTextEncoding() ); 1775cdf0e10cSrcweir sal_Int16 nlResult = (sal_Int16)strtol( aByteStr.GetBuffer()+2, &pEndPtr, nRadix); 1776cdf0e10cSrcweir nResult = (double)nlResult; 1777cdf0e10cSrcweir } 1778cdf0e10cSrcweir } 1779cdf0e10cSrcweir else 1780cdf0e10cSrcweir { 1781cdf0e10cSrcweir // #57844 Lokalisierte Funktion benutzen 1782cdf0e10cSrcweir nResult = ::rtl::math::stringToDouble( aStr, '.', ',', NULL, NULL ); 1783cdf0e10cSrcweir checkArithmeticOverflow( nResult ); 1784cdf0e10cSrcweir // ATL: nResult = strtod( aStr.GetStr(), &pEndPtr ); 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir rPar.Get(0)->PutDouble( nResult ); 1788cdf0e10cSrcweir } 1789cdf0e10cSrcweir } 1790cdf0e10cSrcweir 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir // Helper functions for date conversion 1793cdf0e10cSrcweir sal_Int16 implGetDateDay( double aDate ) 1794cdf0e10cSrcweir { 1795cdf0e10cSrcweir aDate -= 2.0; // normieren: 1.1.1900 => 0.0 1796cdf0e10cSrcweir Date aRefDate( 1, 1, 1900 ); 1797cdf0e10cSrcweir if ( aDate >= 0.0 ) 1798cdf0e10cSrcweir { 1799cdf0e10cSrcweir aDate = floor( aDate ); 1800cdf0e10cSrcweir aRefDate += (sal_uIntPtr)aDate; 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir else 1803cdf0e10cSrcweir { 1804cdf0e10cSrcweir aDate = ceil( aDate ); 1805cdf0e10cSrcweir aRefDate -= (sal_uIntPtr)(-1.0 * aDate); 1806cdf0e10cSrcweir } 1807cdf0e10cSrcweir 1808cdf0e10cSrcweir sal_Int16 nRet = (sal_Int16)( aRefDate.GetDay() ); 1809cdf0e10cSrcweir return nRet; 1810cdf0e10cSrcweir } 1811cdf0e10cSrcweir 1812cdf0e10cSrcweir sal_Int16 implGetDateMonth( double aDate ) 1813cdf0e10cSrcweir { 1814cdf0e10cSrcweir Date aRefDate( 1,1,1900 ); 1815cdf0e10cSrcweir long nDays = (long)aDate; 1816cdf0e10cSrcweir nDays -= 2; // normieren: 1.1.1900 => 0.0 1817cdf0e10cSrcweir aRefDate += nDays; 1818cdf0e10cSrcweir sal_Int16 nRet = (sal_Int16)( aRefDate.GetMonth() ); 1819cdf0e10cSrcweir return nRet; 1820cdf0e10cSrcweir } 1821cdf0e10cSrcweir 1822cdf0e10cSrcweir sal_Int16 implGetDateYear( double aDate ) 1823cdf0e10cSrcweir { 1824cdf0e10cSrcweir Date aRefDate( 1,1,1900 ); 1825cdf0e10cSrcweir long nDays = (long) aDate; 1826cdf0e10cSrcweir nDays -= 2; // normieren: 1.1.1900 => 0.0 1827cdf0e10cSrcweir aRefDate += nDays; 1828cdf0e10cSrcweir sal_Int16 nRet = (sal_Int16)( aRefDate.GetYear() ); 1829cdf0e10cSrcweir return nRet; 1830cdf0e10cSrcweir } 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir sal_Bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, double& rdRet ) 1833cdf0e10cSrcweir { 1834cdf0e10cSrcweir if ( nYear < 30 && SbiRuntime::isVBAEnabled() ) 1835cdf0e10cSrcweir nYear += 2000; 1836cdf0e10cSrcweir else if ( nYear < 100 ) 1837cdf0e10cSrcweir nYear += 1900; 1838cdf0e10cSrcweir Date aCurDate( nDay, nMonth, nYear ); 1839cdf0e10cSrcweir if ((nYear < 100 || nYear > 9999) ) 1840cdf0e10cSrcweir { 1841cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1842cdf0e10cSrcweir return sal_False; 1843cdf0e10cSrcweir } 1844cdf0e10cSrcweir if ( !SbiRuntime::isVBAEnabled() ) 1845cdf0e10cSrcweir { 1846cdf0e10cSrcweir if ( (nMonth < 1 || nMonth > 12 )|| 1847cdf0e10cSrcweir (nDay < 1 || nDay > 31 ) ) 1848cdf0e10cSrcweir { 1849cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1850cdf0e10cSrcweir return sal_False; 1851cdf0e10cSrcweir } 1852cdf0e10cSrcweir } 1853cdf0e10cSrcweir else 1854cdf0e10cSrcweir { 1855cdf0e10cSrcweir // grab the year & month 1856cdf0e10cSrcweir aCurDate = Date( 1, (( nMonth % 12 ) > 0 ) ? ( nMonth % 12 ) : 12 + ( nMonth % 12 ), nYear ); 1857cdf0e10cSrcweir 1858cdf0e10cSrcweir // adjust year based on month value 1859cdf0e10cSrcweir // e.g. 2000, 0, xx = 1999, 12, xx ( or December of the previous year ) 1860cdf0e10cSrcweir // 2000, 13, xx = 2001, 1, xx ( or January of the following year ) 1861cdf0e10cSrcweir if( ( nMonth < 1 ) || ( nMonth > 12 ) ) 1862cdf0e10cSrcweir { 1863cdf0e10cSrcweir // inacurrate around leap year, don't use days to calculate, 1864cdf0e10cSrcweir // just modify the months directory 1865cdf0e10cSrcweir sal_Int16 nYearAdj = ( nMonth /12 ); // default to positive months inputed 1866cdf0e10cSrcweir if ( nMonth <=0 ) 1867cdf0e10cSrcweir nYearAdj = ( ( nMonth -12 ) / 12 ); 1868cdf0e10cSrcweir aCurDate.SetYear( aCurDate.GetYear() + nYearAdj ); 1869cdf0e10cSrcweir } 1870cdf0e10cSrcweir 1871cdf0e10cSrcweir // adjust day value, 1872cdf0e10cSrcweir // e.g. 2000, 2, 0 = 2000, 1, 31 or the last day of the previous month 1873cdf0e10cSrcweir // 2000, 1, 32 = 2000, 2, 1 or the first day of the following month 1874cdf0e10cSrcweir if( ( nDay < 1 ) || ( nDay > aCurDate.GetDaysInMonth() ) ) 1875cdf0e10cSrcweir aCurDate += nDay - 1; 1876cdf0e10cSrcweir else 1877cdf0e10cSrcweir aCurDate.SetDay( nDay ); 1878cdf0e10cSrcweir } 1879cdf0e10cSrcweir 1880cdf0e10cSrcweir long nDiffDays = GetDayDiff( aCurDate ); 1881cdf0e10cSrcweir rdRet = (double)nDiffDays; 1882cdf0e10cSrcweir return sal_True; 1883cdf0e10cSrcweir } 1884cdf0e10cSrcweir 1885cdf0e10cSrcweir // Function to convert date to ISO 8601 date format 1886cdf0e10cSrcweir RTLFUNC(CDateToIso) 1887cdf0e10cSrcweir { 1888cdf0e10cSrcweir (void)pBasic; 1889cdf0e10cSrcweir (void)bWrite; 1890cdf0e10cSrcweir 1891cdf0e10cSrcweir if ( rPar.Count() == 2 ) 1892cdf0e10cSrcweir { 1893cdf0e10cSrcweir double aDate = rPar.Get(1)->GetDate(); 1894cdf0e10cSrcweir 1895cdf0e10cSrcweir char Buffer[9]; 1896cdf0e10cSrcweir snprintf( Buffer, sizeof( Buffer ), "%04d%02d%02d", 1897cdf0e10cSrcweir implGetDateYear( aDate ), 1898cdf0e10cSrcweir implGetDateMonth( aDate ), 1899cdf0e10cSrcweir implGetDateDay( aDate ) ); 1900cdf0e10cSrcweir String aRetStr = String::CreateFromAscii( Buffer ); 1901cdf0e10cSrcweir rPar.Get(0)->PutString( aRetStr ); 1902cdf0e10cSrcweir } 1903cdf0e10cSrcweir else 1904cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1905cdf0e10cSrcweir } 1906cdf0e10cSrcweir 1907cdf0e10cSrcweir // Function to convert date from ISO 8601 date format 1908cdf0e10cSrcweir RTLFUNC(CDateFromIso) 1909cdf0e10cSrcweir { 1910cdf0e10cSrcweir (void)pBasic; 1911cdf0e10cSrcweir (void)bWrite; 1912cdf0e10cSrcweir 1913cdf0e10cSrcweir if ( rPar.Count() == 2 ) 1914cdf0e10cSrcweir { 1915cdf0e10cSrcweir String aStr = rPar.Get(1)->GetString(); 1916cdf0e10cSrcweir sal_Int16 iMonthStart = aStr.Len() - 4; 1917cdf0e10cSrcweir String aYearStr = aStr.Copy( 0, iMonthStart ); 1918cdf0e10cSrcweir String aMonthStr = aStr.Copy( iMonthStart, 2 ); 1919cdf0e10cSrcweir String aDayStr = aStr.Copy( iMonthStart+2, 2 ); 1920cdf0e10cSrcweir 1921cdf0e10cSrcweir double dDate; 1922cdf0e10cSrcweir if( implDateSerial( (sal_Int16)aYearStr.ToInt32(), 1923cdf0e10cSrcweir (sal_Int16)aMonthStr.ToInt32(), (sal_Int16)aDayStr.ToInt32(), dDate ) ) 1924cdf0e10cSrcweir { 1925cdf0e10cSrcweir rPar.Get(0)->PutDate( dDate ); 1926cdf0e10cSrcweir } 1927cdf0e10cSrcweir } 1928cdf0e10cSrcweir else 1929cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1930cdf0e10cSrcweir } 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir RTLFUNC(DateSerial) 1933cdf0e10cSrcweir { 1934cdf0e10cSrcweir (void)pBasic; 1935cdf0e10cSrcweir (void)bWrite; 1936cdf0e10cSrcweir 1937cdf0e10cSrcweir if ( rPar.Count() < 4 ) 1938cdf0e10cSrcweir { 1939cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1940cdf0e10cSrcweir return; 1941cdf0e10cSrcweir } 1942cdf0e10cSrcweir sal_Int16 nYear = rPar.Get(1)->GetInteger(); 1943cdf0e10cSrcweir sal_Int16 nMonth = rPar.Get(2)->GetInteger(); 1944cdf0e10cSrcweir sal_Int16 nDay = rPar.Get(3)->GetInteger(); 1945cdf0e10cSrcweir 1946cdf0e10cSrcweir double dDate; 1947cdf0e10cSrcweir if( implDateSerial( nYear, nMonth, nDay, dDate ) ) 1948cdf0e10cSrcweir rPar.Get(0)->PutDate( dDate ); 1949cdf0e10cSrcweir } 1950cdf0e10cSrcweir 1951cdf0e10cSrcweir RTLFUNC(TimeSerial) 1952cdf0e10cSrcweir { 1953cdf0e10cSrcweir (void)pBasic; 1954cdf0e10cSrcweir (void)bWrite; 1955cdf0e10cSrcweir 1956cdf0e10cSrcweir if ( rPar.Count() < 4 ) 1957cdf0e10cSrcweir { 1958cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1959cdf0e10cSrcweir return; 1960cdf0e10cSrcweir } 1961cdf0e10cSrcweir sal_Int16 nHour = rPar.Get(1)->GetInteger(); 1962cdf0e10cSrcweir if ( nHour == 24 ) 1963cdf0e10cSrcweir nHour = 0; // Wegen UNO DateTimes, die bis 24 Uhr gehen 1964cdf0e10cSrcweir sal_Int16 nMinute = rPar.Get(2)->GetInteger(); 1965cdf0e10cSrcweir sal_Int16 nSecond = rPar.Get(3)->GetInteger(); 1966cdf0e10cSrcweir if ((nHour < 0 || nHour > 23) || 1967cdf0e10cSrcweir (nMinute < 0 || nMinute > 59 ) || 1968cdf0e10cSrcweir (nSecond < 0 || nSecond > 59 )) 1969cdf0e10cSrcweir { 1970cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1971cdf0e10cSrcweir return; 1972cdf0e10cSrcweir } 1973cdf0e10cSrcweir 1974cdf0e10cSrcweir sal_Int32 nSeconds = nHour; 1975cdf0e10cSrcweir nSeconds *= 3600; 1976cdf0e10cSrcweir nSeconds += nMinute * 60; 1977cdf0e10cSrcweir nSeconds += nSecond; 1978cdf0e10cSrcweir double nDays = ((double)nSeconds) / (double)(86400.0); 1979cdf0e10cSrcweir rPar.Get(0)->PutDate( nDays ); // JSM 1980cdf0e10cSrcweir } 1981cdf0e10cSrcweir 1982cdf0e10cSrcweir RTLFUNC(DateValue) 1983cdf0e10cSrcweir { 1984cdf0e10cSrcweir (void)pBasic; 1985cdf0e10cSrcweir (void)bWrite; 1986cdf0e10cSrcweir 1987cdf0e10cSrcweir if ( rPar.Count() < 2 ) 1988cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1989cdf0e10cSrcweir else 1990cdf0e10cSrcweir { 1991cdf0e10cSrcweir // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden 1992cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL; 1993cdf0e10cSrcweir if( pINST ) 1994cdf0e10cSrcweir pFormatter = pINST->GetNumberFormatter(); 1995cdf0e10cSrcweir else 1996cdf0e10cSrcweir { 1997cdf0e10cSrcweir sal_uInt32 n; // Dummy 1998cdf0e10cSrcweir SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n ); 1999cdf0e10cSrcweir } 2000cdf0e10cSrcweir 2001cdf0e10cSrcweir sal_uInt32 nIndex; 2002cdf0e10cSrcweir double fResult; 2003cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 2004cdf0e10cSrcweir sal_Bool bSuccess = pFormatter->IsNumberFormat( aStr, nIndex, fResult ); 2005cdf0e10cSrcweir short nType = pFormatter->GetType( nIndex ); 2006cdf0e10cSrcweir 2007cdf0e10cSrcweir // DateValue("February 12, 1969") raises error if the system locale is not en_US 2008cdf0e10cSrcweir // by using SbiInstance::GetNumberFormatter. 2009cdf0e10cSrcweir // It seems that both locale number formatter and English number formatter 2010cdf0e10cSrcweir // are supported in Visual Basic. 2011cdf0e10cSrcweir LanguageType eLangType = GetpApp()->GetSettings().GetLanguage(); 2012cdf0e10cSrcweir if( !bSuccess && ( eLangType != LANGUAGE_ENGLISH_US ) ) 2013cdf0e10cSrcweir { 2014cdf0e10cSrcweir // Create a new SvNumberFormatter by using LANGUAGE_ENGLISH to get the date value; 2015cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > 2016cdf0e10cSrcweir xFactory = comphelper::getProcessServiceFactory(); 2017cdf0e10cSrcweir SvNumberFormatter aFormatter( xFactory, LANGUAGE_ENGLISH_US ); 2018cdf0e10cSrcweir bSuccess = aFormatter.IsNumberFormat( aStr, nIndex, fResult ); 2019cdf0e10cSrcweir nType = aFormatter.GetType( nIndex ); 2020cdf0e10cSrcweir } 2021cdf0e10cSrcweir 2022cdf0e10cSrcweir if(bSuccess && (nType==NUMBERFORMAT_DATE || nType==NUMBERFORMAT_DATETIME)) 2023cdf0e10cSrcweir { 2024cdf0e10cSrcweir if ( nType == NUMBERFORMAT_DATETIME ) 2025cdf0e10cSrcweir { 2026cdf0e10cSrcweir // Zeit abschneiden 2027cdf0e10cSrcweir if ( fResult > 0.0 ) 2028cdf0e10cSrcweir fResult = floor( fResult ); 2029cdf0e10cSrcweir else 2030cdf0e10cSrcweir fResult = ceil( fResult ); 2031cdf0e10cSrcweir } 2032cdf0e10cSrcweir // fResult += 2.0; // Anpassung StarCalcFormatter 2033cdf0e10cSrcweir rPar.Get(0)->PutDate( fResult ); // JSM 2034cdf0e10cSrcweir } 2035cdf0e10cSrcweir else 2036cdf0e10cSrcweir StarBASIC::Error( SbERR_CONVERSION ); 2037cdf0e10cSrcweir 2038cdf0e10cSrcweir // #39629 pFormatter kann selbst angefordert sein 2039cdf0e10cSrcweir if( !pINST ) 2040cdf0e10cSrcweir delete pFormatter; 2041cdf0e10cSrcweir } 2042cdf0e10cSrcweir } 2043cdf0e10cSrcweir 2044cdf0e10cSrcweir RTLFUNC(TimeValue) 2045cdf0e10cSrcweir { 2046cdf0e10cSrcweir (void)pBasic; 2047cdf0e10cSrcweir (void)bWrite; 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2050cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2051cdf0e10cSrcweir else 2052cdf0e10cSrcweir { 2053cdf0e10cSrcweir // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden 2054cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL; 2055cdf0e10cSrcweir if( pINST ) 2056cdf0e10cSrcweir pFormatter = pINST->GetNumberFormatter(); 2057cdf0e10cSrcweir else 2058cdf0e10cSrcweir { 2059cdf0e10cSrcweir sal_uInt32 n; // Dummy 2060cdf0e10cSrcweir SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n ); 2061cdf0e10cSrcweir } 2062cdf0e10cSrcweir 2063cdf0e10cSrcweir sal_uInt32 nIndex; 2064cdf0e10cSrcweir double fResult; 2065cdf0e10cSrcweir sal_Bool bSuccess = pFormatter->IsNumberFormat( rPar.Get(1)->GetString(), 2066cdf0e10cSrcweir nIndex, fResult ); 2067cdf0e10cSrcweir short nType = pFormatter->GetType(nIndex); 2068cdf0e10cSrcweir if(bSuccess && (nType==NUMBERFORMAT_TIME||nType==NUMBERFORMAT_DATETIME)) 2069cdf0e10cSrcweir { 2070cdf0e10cSrcweir if ( nType == NUMBERFORMAT_DATETIME ) 2071cdf0e10cSrcweir // Tage abschneiden 2072cdf0e10cSrcweir fResult = fmod( fResult, 1 ); 2073cdf0e10cSrcweir rPar.Get(0)->PutDate( fResult ); // JSM 2074cdf0e10cSrcweir } 2075cdf0e10cSrcweir else 2076cdf0e10cSrcweir StarBASIC::Error( SbERR_CONVERSION ); 2077cdf0e10cSrcweir 2078cdf0e10cSrcweir // #39629 pFormatter kann selbst angefordert sein 2079cdf0e10cSrcweir if( !pINST ) 2080cdf0e10cSrcweir delete pFormatter; 2081cdf0e10cSrcweir } 2082cdf0e10cSrcweir } 2083cdf0e10cSrcweir 2084cdf0e10cSrcweir RTLFUNC(Day) 2085cdf0e10cSrcweir { 2086cdf0e10cSrcweir (void)pBasic; 2087cdf0e10cSrcweir (void)bWrite; 2088cdf0e10cSrcweir 2089cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2090cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2091cdf0e10cSrcweir else 2092cdf0e10cSrcweir { 2093cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 2094cdf0e10cSrcweir double aDate = pArg->GetDate(); 2095cdf0e10cSrcweir 2096cdf0e10cSrcweir sal_Int16 nDay = implGetDateDay( aDate ); 2097cdf0e10cSrcweir rPar.Get(0)->PutInteger( nDay ); 2098cdf0e10cSrcweir } 2099cdf0e10cSrcweir } 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir RTLFUNC(Year) 2102cdf0e10cSrcweir { 2103cdf0e10cSrcweir (void)pBasic; 2104cdf0e10cSrcweir (void)bWrite; 2105cdf0e10cSrcweir 2106cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2107cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2108cdf0e10cSrcweir else 2109cdf0e10cSrcweir { 2110cdf0e10cSrcweir sal_Int16 nYear = implGetDateYear( rPar.Get(1)->GetDate() ); 2111cdf0e10cSrcweir rPar.Get(0)->PutInteger( nYear ); 2112cdf0e10cSrcweir } 2113cdf0e10cSrcweir } 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir sal_Int16 implGetHour( double dDate ) 2116cdf0e10cSrcweir { 2117cdf0e10cSrcweir if( dDate < 0.0 ) 2118cdf0e10cSrcweir dDate *= -1.0; 2119cdf0e10cSrcweir double nFrac = dDate - floor( dDate ); 2120cdf0e10cSrcweir nFrac *= 86400.0; 2121cdf0e10cSrcweir sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5); 2122cdf0e10cSrcweir sal_Int16 nHour = (sal_Int16)(nSeconds / 3600); 2123cdf0e10cSrcweir return nHour; 2124cdf0e10cSrcweir } 2125cdf0e10cSrcweir 2126cdf0e10cSrcweir RTLFUNC(Hour) 2127cdf0e10cSrcweir { 2128cdf0e10cSrcweir (void)pBasic; 2129cdf0e10cSrcweir (void)bWrite; 2130cdf0e10cSrcweir 2131cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2132cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2133cdf0e10cSrcweir else 2134cdf0e10cSrcweir { 2135cdf0e10cSrcweir double nArg = rPar.Get(1)->GetDate(); 2136cdf0e10cSrcweir sal_Int16 nHour = implGetHour( nArg ); 2137cdf0e10cSrcweir rPar.Get(0)->PutInteger( nHour ); 2138cdf0e10cSrcweir } 2139cdf0e10cSrcweir } 2140cdf0e10cSrcweir 2141cdf0e10cSrcweir sal_Int16 implGetMinute( double dDate ) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir if( dDate < 0.0 ) 2144cdf0e10cSrcweir dDate *= -1.0; 2145cdf0e10cSrcweir double nFrac = dDate - floor( dDate ); 2146cdf0e10cSrcweir nFrac *= 86400.0; 2147cdf0e10cSrcweir sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5); 2148cdf0e10cSrcweir sal_Int16 nTemp = (sal_Int16)(nSeconds % 3600); 2149cdf0e10cSrcweir sal_Int16 nMin = nTemp / 60; 2150cdf0e10cSrcweir return nMin; 2151cdf0e10cSrcweir } 2152cdf0e10cSrcweir 2153cdf0e10cSrcweir RTLFUNC(Minute) 2154cdf0e10cSrcweir { 2155cdf0e10cSrcweir (void)pBasic; 2156cdf0e10cSrcweir (void)bWrite; 2157cdf0e10cSrcweir 2158cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2159cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2160cdf0e10cSrcweir else 2161cdf0e10cSrcweir { 2162cdf0e10cSrcweir double nArg = rPar.Get(1)->GetDate(); 2163cdf0e10cSrcweir sal_Int16 nMin = implGetMinute( nArg ); 2164cdf0e10cSrcweir rPar.Get(0)->PutInteger( nMin ); 2165cdf0e10cSrcweir } 2166cdf0e10cSrcweir } 2167cdf0e10cSrcweir 2168cdf0e10cSrcweir RTLFUNC(Month) 2169cdf0e10cSrcweir { 2170cdf0e10cSrcweir (void)pBasic; 2171cdf0e10cSrcweir (void)bWrite; 2172cdf0e10cSrcweir 2173cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2174cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2175cdf0e10cSrcweir else 2176cdf0e10cSrcweir { 2177cdf0e10cSrcweir sal_Int16 nMonth = implGetDateMonth( rPar.Get(1)->GetDate() ); 2178cdf0e10cSrcweir rPar.Get(0)->PutInteger( nMonth ); 2179cdf0e10cSrcweir } 2180cdf0e10cSrcweir } 2181cdf0e10cSrcweir 2182cdf0e10cSrcweir sal_Int16 implGetSecond( double dDate ) 2183cdf0e10cSrcweir { 2184cdf0e10cSrcweir if( dDate < 0.0 ) 2185cdf0e10cSrcweir dDate *= -1.0; 2186cdf0e10cSrcweir double nFrac = dDate - floor( dDate ); 2187cdf0e10cSrcweir nFrac *= 86400.0; 2188cdf0e10cSrcweir sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5); 2189cdf0e10cSrcweir sal_Int16 nTemp = (sal_Int16)(nSeconds / 3600); 2190cdf0e10cSrcweir nSeconds -= nTemp * 3600; 2191cdf0e10cSrcweir nTemp = (sal_Int16)(nSeconds / 60); 2192cdf0e10cSrcweir nSeconds -= nTemp * 60; 2193cdf0e10cSrcweir 2194cdf0e10cSrcweir sal_Int16 nRet = (sal_Int16)nSeconds; 2195cdf0e10cSrcweir return nRet; 2196cdf0e10cSrcweir } 2197cdf0e10cSrcweir 2198cdf0e10cSrcweir RTLFUNC(Second) 2199cdf0e10cSrcweir { 2200cdf0e10cSrcweir (void)pBasic; 2201cdf0e10cSrcweir (void)bWrite; 2202cdf0e10cSrcweir 2203cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2204cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2205cdf0e10cSrcweir else 2206cdf0e10cSrcweir { 2207cdf0e10cSrcweir double nArg = rPar.Get(1)->GetDate(); 2208cdf0e10cSrcweir sal_Int16 nSecond = implGetSecond( nArg ); 2209cdf0e10cSrcweir rPar.Get(0)->PutInteger( nSecond ); 2210cdf0e10cSrcweir } 2211cdf0e10cSrcweir } 2212cdf0e10cSrcweir 2213cdf0e10cSrcweir double Now_Impl() 2214cdf0e10cSrcweir { 2215cdf0e10cSrcweir Date aDate; 2216cdf0e10cSrcweir Time aTime; 2217cdf0e10cSrcweir double aSerial = (double)GetDayDiff( aDate ); 2218cdf0e10cSrcweir long nSeconds = aTime.GetHour(); 2219cdf0e10cSrcweir nSeconds *= 3600; 2220cdf0e10cSrcweir nSeconds += aTime.GetMin() * 60; 2221cdf0e10cSrcweir nSeconds += aTime.GetSec(); 2222cdf0e10cSrcweir double nDays = ((double)nSeconds) / (double)(24.0*3600.0); 2223cdf0e10cSrcweir aSerial += nDays; 2224cdf0e10cSrcweir return aSerial; 2225cdf0e10cSrcweir } 2226cdf0e10cSrcweir 2227cdf0e10cSrcweir // Date Now(void) 2228cdf0e10cSrcweir 2229cdf0e10cSrcweir RTLFUNC(Now) 2230cdf0e10cSrcweir { 2231cdf0e10cSrcweir (void)pBasic; 2232cdf0e10cSrcweir (void)bWrite; 2233cdf0e10cSrcweir rPar.Get(0)->PutDate( Now_Impl() ); 2234cdf0e10cSrcweir } 2235cdf0e10cSrcweir 2236cdf0e10cSrcweir // Date Time(void) 2237cdf0e10cSrcweir 2238cdf0e10cSrcweir RTLFUNC(Time) 2239cdf0e10cSrcweir { 2240cdf0e10cSrcweir (void)pBasic; 2241cdf0e10cSrcweir 2242cdf0e10cSrcweir if ( !bWrite ) 2243cdf0e10cSrcweir { 2244cdf0e10cSrcweir Time aTime; 2245cdf0e10cSrcweir SbxVariable* pMeth = rPar.Get( 0 ); 2246cdf0e10cSrcweir String aRes; 2247cdf0e10cSrcweir if( pMeth->IsFixed() ) 2248cdf0e10cSrcweir { 2249cdf0e10cSrcweir // Time$: hh:mm:ss 2250cdf0e10cSrcweir char buf[ 20 ]; 2251cdf0e10cSrcweir snprintf( buf, sizeof(buf), "%02d:%02d:%02d", 2252cdf0e10cSrcweir aTime.GetHour(), aTime.GetMin(), aTime.GetSec() ); 2253cdf0e10cSrcweir aRes = String::CreateFromAscii( buf ); 2254cdf0e10cSrcweir } 2255cdf0e10cSrcweir else 2256cdf0e10cSrcweir { 2257cdf0e10cSrcweir // Time: system dependent 2258cdf0e10cSrcweir long nSeconds=aTime.GetHour(); 2259cdf0e10cSrcweir nSeconds *= 3600; 2260cdf0e10cSrcweir nSeconds += aTime.GetMin() * 60; 2261cdf0e10cSrcweir nSeconds += aTime.GetSec(); 2262cdf0e10cSrcweir double nDays = (double)nSeconds * ( 1.0 / (24.0*3600.0) ); 2263cdf0e10cSrcweir Color* pCol; 2264cdf0e10cSrcweir 2265cdf0e10cSrcweir // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden 2266cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL; 2267cdf0e10cSrcweir sal_uInt32 nIndex; 2268cdf0e10cSrcweir if( pINST ) 2269cdf0e10cSrcweir { 2270cdf0e10cSrcweir pFormatter = pINST->GetNumberFormatter(); 2271cdf0e10cSrcweir nIndex = pINST->GetStdTimeIdx(); 2272cdf0e10cSrcweir } 2273cdf0e10cSrcweir else 2274cdf0e10cSrcweir { 2275cdf0e10cSrcweir sal_uInt32 n; // Dummy 2276cdf0e10cSrcweir SbiInstance::PrepareNumberFormatter( pFormatter, n, nIndex, n ); 2277cdf0e10cSrcweir } 2278cdf0e10cSrcweir 2279cdf0e10cSrcweir pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol ); 2280cdf0e10cSrcweir 2281cdf0e10cSrcweir // #39629 pFormatter kann selbst angefordert sein 2282cdf0e10cSrcweir if( !pINST ) 2283cdf0e10cSrcweir delete pFormatter; 2284cdf0e10cSrcweir } 2285cdf0e10cSrcweir pMeth->PutString( aRes ); 2286cdf0e10cSrcweir } 2287cdf0e10cSrcweir else 2288cdf0e10cSrcweir { 2289cdf0e10cSrcweir StarBASIC::Error( SbERR_NOT_IMPLEMENTED ); 2290cdf0e10cSrcweir } 2291cdf0e10cSrcweir } 2292cdf0e10cSrcweir 2293cdf0e10cSrcweir RTLFUNC(Timer) 2294cdf0e10cSrcweir { 2295cdf0e10cSrcweir (void)pBasic; 2296cdf0e10cSrcweir (void)bWrite; 2297cdf0e10cSrcweir 2298cdf0e10cSrcweir Time aTime; 2299cdf0e10cSrcweir long nSeconds = aTime.GetHour(); 2300cdf0e10cSrcweir nSeconds *= 3600; 2301cdf0e10cSrcweir nSeconds += aTime.GetMin() * 60; 2302cdf0e10cSrcweir nSeconds += aTime.GetSec(); 2303cdf0e10cSrcweir rPar.Get(0)->PutDate( (double)nSeconds ); 2304cdf0e10cSrcweir } 2305cdf0e10cSrcweir 2306cdf0e10cSrcweir 2307cdf0e10cSrcweir RTLFUNC(Date) 2308cdf0e10cSrcweir { 2309cdf0e10cSrcweir (void)pBasic; 2310cdf0e10cSrcweir (void)bWrite; 2311cdf0e10cSrcweir 2312cdf0e10cSrcweir if ( !bWrite ) 2313cdf0e10cSrcweir { 2314cdf0e10cSrcweir Date aToday; 2315cdf0e10cSrcweir double nDays = (double)GetDayDiff( aToday ); 2316cdf0e10cSrcweir SbxVariable* pMeth = rPar.Get( 0 ); 2317cdf0e10cSrcweir if( pMeth->IsString() ) 2318cdf0e10cSrcweir { 2319cdf0e10cSrcweir String aRes; 2320cdf0e10cSrcweir Color* pCol; 2321cdf0e10cSrcweir 2322cdf0e10cSrcweir // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden 2323cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL; 2324cdf0e10cSrcweir sal_uInt32 nIndex; 2325cdf0e10cSrcweir if( pINST ) 2326cdf0e10cSrcweir { 2327cdf0e10cSrcweir pFormatter = pINST->GetNumberFormatter(); 2328cdf0e10cSrcweir nIndex = pINST->GetStdDateIdx(); 2329cdf0e10cSrcweir } 2330cdf0e10cSrcweir else 2331cdf0e10cSrcweir { 2332cdf0e10cSrcweir sal_uInt32 n; // Dummy 2333cdf0e10cSrcweir SbiInstance::PrepareNumberFormatter( pFormatter, nIndex, n, n ); 2334cdf0e10cSrcweir } 2335cdf0e10cSrcweir 2336cdf0e10cSrcweir pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol ); 2337cdf0e10cSrcweir pMeth->PutString( aRes ); 2338cdf0e10cSrcweir 2339cdf0e10cSrcweir // #39629 pFormatter kann selbst angefordert sein 2340cdf0e10cSrcweir if( !pINST ) 2341cdf0e10cSrcweir delete pFormatter; 2342cdf0e10cSrcweir } 2343cdf0e10cSrcweir else 2344cdf0e10cSrcweir pMeth->PutDate( nDays ); 2345cdf0e10cSrcweir } 2346cdf0e10cSrcweir else 2347cdf0e10cSrcweir { 2348cdf0e10cSrcweir StarBASIC::Error( SbERR_NOT_IMPLEMENTED ); 2349cdf0e10cSrcweir } 2350cdf0e10cSrcweir } 2351cdf0e10cSrcweir 2352cdf0e10cSrcweir RTLFUNC(IsArray) 2353cdf0e10cSrcweir { 2354cdf0e10cSrcweir (void)pBasic; 2355cdf0e10cSrcweir (void)bWrite; 2356cdf0e10cSrcweir 2357cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2358cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2359cdf0e10cSrcweir else 2360cdf0e10cSrcweir rPar.Get(0)->PutBool((rPar.Get(1)->GetType() & SbxARRAY) ? sal_True : sal_False ); 2361cdf0e10cSrcweir } 2362cdf0e10cSrcweir 2363cdf0e10cSrcweir RTLFUNC(IsObject) 2364cdf0e10cSrcweir { 2365cdf0e10cSrcweir (void)pBasic; 2366cdf0e10cSrcweir (void)bWrite; 2367cdf0e10cSrcweir 2368cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2369cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2370cdf0e10cSrcweir else 2371cdf0e10cSrcweir { 2372cdf0e10cSrcweir SbxVariable* pVar = rPar.Get(1); 2373cdf0e10cSrcweir SbxBase* pObj = (SbxBase*)pVar->GetObject(); 2374cdf0e10cSrcweir 2375cdf0e10cSrcweir // #100385: GetObject can result in an error, so reset it 2376cdf0e10cSrcweir SbxBase::ResetError(); 2377cdf0e10cSrcweir 2378cdf0e10cSrcweir SbUnoClass* pUnoClass; 2379cdf0e10cSrcweir sal_Bool bObject; 2380cdf0e10cSrcweir if( pObj && NULL != ( pUnoClass=PTR_CAST(SbUnoClass,pObj) ) ) 2381cdf0e10cSrcweir { 2382cdf0e10cSrcweir bObject = pUnoClass->getUnoClass().is(); 2383cdf0e10cSrcweir } 2384cdf0e10cSrcweir else 2385cdf0e10cSrcweir { 2386cdf0e10cSrcweir bObject = pVar->IsObject(); 2387cdf0e10cSrcweir } 2388cdf0e10cSrcweir rPar.Get( 0 )->PutBool( bObject ); 2389cdf0e10cSrcweir } 2390cdf0e10cSrcweir } 2391cdf0e10cSrcweir 2392cdf0e10cSrcweir RTLFUNC(IsDate) 2393cdf0e10cSrcweir { 2394cdf0e10cSrcweir (void)pBasic; 2395cdf0e10cSrcweir (void)bWrite; 2396cdf0e10cSrcweir 2397cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2398cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2399cdf0e10cSrcweir else 2400cdf0e10cSrcweir { 2401cdf0e10cSrcweir // #46134 Nur String wird konvertiert, andere Typen ergeben sal_False 2402cdf0e10cSrcweir SbxVariableRef xArg = rPar.Get( 1 ); 2403cdf0e10cSrcweir SbxDataType eType = xArg->GetType(); 2404cdf0e10cSrcweir sal_Bool bDate = sal_False; 2405cdf0e10cSrcweir 2406cdf0e10cSrcweir if( eType == SbxDATE ) 2407cdf0e10cSrcweir { 2408cdf0e10cSrcweir bDate = sal_True; 2409cdf0e10cSrcweir } 2410cdf0e10cSrcweir else if( eType == SbxSTRING ) 2411cdf0e10cSrcweir { 2412cdf0e10cSrcweir // Error loeschen 2413cdf0e10cSrcweir SbxError nPrevError = SbxBase::GetError(); 2414cdf0e10cSrcweir SbxBase::ResetError(); 2415cdf0e10cSrcweir 2416cdf0e10cSrcweir // Konvertierung des Parameters nach SbxDATE erzwingen 2417cdf0e10cSrcweir xArg->SbxValue::GetDate(); 2418cdf0e10cSrcweir 2419cdf0e10cSrcweir // Bei Fehler ist es kein Date 2420cdf0e10cSrcweir bDate = !SbxBase::IsError(); 2421cdf0e10cSrcweir 2422cdf0e10cSrcweir // Error-Situation wiederherstellen 2423cdf0e10cSrcweir SbxBase::ResetError(); 2424cdf0e10cSrcweir SbxBase::SetError( nPrevError ); 2425cdf0e10cSrcweir } 2426cdf0e10cSrcweir rPar.Get( 0 )->PutBool( bDate ); 2427cdf0e10cSrcweir } 2428cdf0e10cSrcweir } 2429cdf0e10cSrcweir 2430cdf0e10cSrcweir RTLFUNC(IsEmpty) 2431cdf0e10cSrcweir { 2432cdf0e10cSrcweir (void)pBasic; 2433cdf0e10cSrcweir (void)bWrite; 2434cdf0e10cSrcweir 2435cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2436cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2437cdf0e10cSrcweir else 2438cdf0e10cSrcweir rPar.Get( 0 )->PutBool( rPar.Get(1)->IsEmpty() ); 2439cdf0e10cSrcweir } 2440cdf0e10cSrcweir 2441cdf0e10cSrcweir RTLFUNC(IsError) 2442cdf0e10cSrcweir { 2443cdf0e10cSrcweir (void)pBasic; 2444cdf0e10cSrcweir (void)bWrite; 2445cdf0e10cSrcweir 2446cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2447cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2448cdf0e10cSrcweir else 2449cdf0e10cSrcweir rPar.Get( 0 )->PutBool( rPar.Get(1)->IsErr() ); 2450cdf0e10cSrcweir } 2451cdf0e10cSrcweir 2452cdf0e10cSrcweir RTLFUNC(IsNull) 2453cdf0e10cSrcweir { 2454cdf0e10cSrcweir (void)pBasic; 2455cdf0e10cSrcweir (void)bWrite; 2456cdf0e10cSrcweir 2457cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2458cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2459cdf0e10cSrcweir else 2460cdf0e10cSrcweir { 2461cdf0e10cSrcweir // #51475 Wegen Uno-Objekten auch true liefern, 2462cdf0e10cSrcweir // wenn der pObj-Wert NULL ist 2463cdf0e10cSrcweir SbxVariableRef pArg = rPar.Get( 1 ); 2464cdf0e10cSrcweir sal_Bool bNull = rPar.Get(1)->IsNull(); 2465cdf0e10cSrcweir if( !bNull && pArg->GetType() == SbxOBJECT ) 2466cdf0e10cSrcweir { 2467cdf0e10cSrcweir SbxBase* pObj = pArg->GetObject(); 2468cdf0e10cSrcweir if( !pObj ) 2469cdf0e10cSrcweir bNull = sal_True; 2470cdf0e10cSrcweir } 2471cdf0e10cSrcweir rPar.Get( 0 )->PutBool( bNull ); 2472cdf0e10cSrcweir } 2473cdf0e10cSrcweir } 2474cdf0e10cSrcweir 2475cdf0e10cSrcweir RTLFUNC(IsNumeric) 2476cdf0e10cSrcweir { 2477cdf0e10cSrcweir (void)pBasic; 2478cdf0e10cSrcweir (void)bWrite; 2479cdf0e10cSrcweir 2480cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2481cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2482cdf0e10cSrcweir else 2483cdf0e10cSrcweir rPar.Get( 0 )->PutBool( rPar.Get( 1 )->IsNumericRTL() ); 2484cdf0e10cSrcweir } 2485cdf0e10cSrcweir 2486cdf0e10cSrcweir // Das machen wir auf die billige Tour 2487cdf0e10cSrcweir 2488cdf0e10cSrcweir RTLFUNC(IsMissing) 2489cdf0e10cSrcweir { 2490cdf0e10cSrcweir (void)pBasic; 2491cdf0e10cSrcweir (void)bWrite; 2492cdf0e10cSrcweir 2493cdf0e10cSrcweir if ( rPar.Count() < 2 ) 2494cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2495cdf0e10cSrcweir else 2496cdf0e10cSrcweir // #57915 Missing wird durch Error angezeigt 2497cdf0e10cSrcweir rPar.Get( 0 )->PutBool( rPar.Get(1)->IsErr() ); 2498cdf0e10cSrcweir } 2499cdf0e10cSrcweir 2500cdf0e10cSrcweir // Dir( [Maske] [,Attrs] ) 2501cdf0e10cSrcweir // ToDo: Library-globaler Datenbereich fuer Dir-Objekt und Flags 2502cdf0e10cSrcweir 2503cdf0e10cSrcweir 2504cdf0e10cSrcweir String getDirectoryPath( String aPathStr ) 2505cdf0e10cSrcweir { 2506cdf0e10cSrcweir String aRetStr; 2507cdf0e10cSrcweir 2508cdf0e10cSrcweir DirectoryItem aItem; 2509cdf0e10cSrcweir FileBase::RC nRet = DirectoryItem::get( aPathStr, aItem ); 2510cdf0e10cSrcweir if( nRet == FileBase::E_None ) 2511cdf0e10cSrcweir { 2512cdf0e10cSrcweir FileStatus aFileStatus( FileStatusMask_Type ); 2513cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus ); 2514cdf0e10cSrcweir if( nRet == FileBase::E_None ) 2515cdf0e10cSrcweir { 2516cdf0e10cSrcweir FileStatus::Type aType = aFileStatus.getFileType(); 2517cdf0e10cSrcweir if( isFolder( aType ) ) 2518cdf0e10cSrcweir { 2519cdf0e10cSrcweir aRetStr = aPathStr; 2520cdf0e10cSrcweir } 2521cdf0e10cSrcweir else if( aType == FileStatus::Link ) 2522cdf0e10cSrcweir { 2523cdf0e10cSrcweir FileStatus aFileStatus2( FileStatusMask_LinkTargetURL ); 2524cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus2 ); 2525cdf0e10cSrcweir if( nRet == FileBase::E_None ) 2526cdf0e10cSrcweir aRetStr = getDirectoryPath( aFileStatus2.getLinkTargetURL() ); 2527cdf0e10cSrcweir } 2528cdf0e10cSrcweir } 2529cdf0e10cSrcweir } 2530cdf0e10cSrcweir return aRetStr; 2531cdf0e10cSrcweir } 2532cdf0e10cSrcweir 2533cdf0e10cSrcweir // Function looks for wildcards, removes them and always returns the pure path 2534cdf0e10cSrcweir String implSetupWildcard( const String& rFileParam, SbiRTLData* pRTLData ) 2535cdf0e10cSrcweir { 2536cdf0e10cSrcweir static String aAsterisk = String::CreateFromAscii( "*" ); 2537cdf0e10cSrcweir static sal_Char cDelim1 = (sal_Char)'/'; 2538cdf0e10cSrcweir static sal_Char cDelim2 = (sal_Char)'\\'; 2539cdf0e10cSrcweir static sal_Char cWild1 = '*'; 2540cdf0e10cSrcweir static sal_Char cWild2 = '?'; 2541cdf0e10cSrcweir 2542cdf0e10cSrcweir delete pRTLData->pWildCard; 2543cdf0e10cSrcweir pRTLData->pWildCard = NULL; 2544cdf0e10cSrcweir pRTLData->sFullNameToBeChecked = String(); 2545cdf0e10cSrcweir 2546cdf0e10cSrcweir String aFileParam = rFileParam; 2547cdf0e10cSrcweir xub_StrLen nLastWild = aFileParam.SearchBackward( cWild1 ); 2548cdf0e10cSrcweir if( nLastWild == STRING_NOTFOUND ) 2549cdf0e10cSrcweir nLastWild = aFileParam.SearchBackward( cWild2 ); 2550cdf0e10cSrcweir sal_Bool bHasWildcards = ( nLastWild != STRING_NOTFOUND ); 2551cdf0e10cSrcweir 2552cdf0e10cSrcweir 2553cdf0e10cSrcweir xub_StrLen nLastDelim = aFileParam.SearchBackward( cDelim1 ); 2554cdf0e10cSrcweir if( nLastDelim == STRING_NOTFOUND ) 2555cdf0e10cSrcweir nLastDelim = aFileParam.SearchBackward( cDelim2 ); 2556cdf0e10cSrcweir 2557cdf0e10cSrcweir if( bHasWildcards ) 2558cdf0e10cSrcweir { 2559cdf0e10cSrcweir // Wildcards in path? 2560cdf0e10cSrcweir if( nLastDelim != STRING_NOTFOUND && nLastDelim > nLastWild ) 2561cdf0e10cSrcweir return aFileParam; 2562cdf0e10cSrcweir } 2563cdf0e10cSrcweir else 2564cdf0e10cSrcweir { 2565cdf0e10cSrcweir String aPathStr = getFullPath( aFileParam ); 2566cdf0e10cSrcweir if( nLastDelim != aFileParam.Len() - 1 ) 2567cdf0e10cSrcweir pRTLData->sFullNameToBeChecked = aPathStr; 2568cdf0e10cSrcweir return aPathStr; 2569cdf0e10cSrcweir } 2570cdf0e10cSrcweir 2571cdf0e10cSrcweir String aPureFileName; 2572cdf0e10cSrcweir if( nLastDelim == STRING_NOTFOUND ) 2573cdf0e10cSrcweir { 2574cdf0e10cSrcweir aPureFileName = aFileParam; 2575cdf0e10cSrcweir aFileParam = String(); 2576cdf0e10cSrcweir } 2577cdf0e10cSrcweir else 2578cdf0e10cSrcweir { 2579cdf0e10cSrcweir aPureFileName = aFileParam.Copy( nLastDelim + 1 ); 2580cdf0e10cSrcweir aFileParam = aFileParam.Copy( 0, nLastDelim ); 2581cdf0e10cSrcweir } 2582cdf0e10cSrcweir 2583cdf0e10cSrcweir // Try again to get a valid URL/UNC-path with only the path 2584cdf0e10cSrcweir String aPathStr = getFullPath( aFileParam ); 2585cdf0e10cSrcweir xub_StrLen nPureLen = aPureFileName.Len(); 2586cdf0e10cSrcweir 2587cdf0e10cSrcweir // Is there a pure file name left? Otherwise the path is 2588cdf0e10cSrcweir // invalid anyway because it was not accepted by OSL before 2589cdf0e10cSrcweir if( nPureLen && aPureFileName != aAsterisk ) 2590cdf0e10cSrcweir { 2591cdf0e10cSrcweir pRTLData->pWildCard = new WildCard( aPureFileName ); 2592cdf0e10cSrcweir } 2593cdf0e10cSrcweir return aPathStr; 2594cdf0e10cSrcweir } 2595cdf0e10cSrcweir 2596cdf0e10cSrcweir inline sal_Bool implCheckWildcard( const String& rName, SbiRTLData* pRTLData ) 2597cdf0e10cSrcweir { 2598cdf0e10cSrcweir sal_Bool bMatch = sal_True; 2599cdf0e10cSrcweir 2600cdf0e10cSrcweir if( pRTLData->pWildCard ) 2601cdf0e10cSrcweir bMatch = pRTLData->pWildCard->Matches( rName ); 2602cdf0e10cSrcweir return bMatch; 2603cdf0e10cSrcweir } 2604cdf0e10cSrcweir 2605cdf0e10cSrcweir 2606cdf0e10cSrcweir bool isRootDir( String aDirURLStr ) 2607cdf0e10cSrcweir { 2608cdf0e10cSrcweir INetURLObject aDirURLObj( aDirURLStr ); 2609cdf0e10cSrcweir sal_Bool bRoot = sal_False; 2610cdf0e10cSrcweir 2611cdf0e10cSrcweir // Check if it's a root directory 2612cdf0e10cSrcweir sal_Int32 nCount = aDirURLObj.getSegmentCount(); 2613cdf0e10cSrcweir 2614cdf0e10cSrcweir // No segment means Unix root directory "file:///" 2615cdf0e10cSrcweir if( nCount == 0 ) 2616cdf0e10cSrcweir { 2617cdf0e10cSrcweir bRoot = sal_True; 2618cdf0e10cSrcweir } 2619cdf0e10cSrcweir // Exactly one segment needs further checking, because it 2620cdf0e10cSrcweir // can be Unix "file:///foo/" -> no root 2621cdf0e10cSrcweir // or Windows "file:///c:/" -> root 2622cdf0e10cSrcweir else if( nCount == 1 ) 2623cdf0e10cSrcweir { 2624cdf0e10cSrcweir ::rtl::OUString aSeg1 = aDirURLObj.getName( 0, sal_True, 2625cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 2626cdf0e10cSrcweir if( aSeg1.getStr()[1] == (sal_Unicode)':' ) 2627cdf0e10cSrcweir { 2628cdf0e10cSrcweir bRoot = sal_True; 2629cdf0e10cSrcweir } 2630cdf0e10cSrcweir } 2631cdf0e10cSrcweir // More than one segments can never be root 2632cdf0e10cSrcweir // so bRoot remains sal_False 2633cdf0e10cSrcweir 2634cdf0e10cSrcweir return bRoot; 2635cdf0e10cSrcweir } 2636cdf0e10cSrcweir 2637cdf0e10cSrcweir RTLFUNC(Dir) 2638cdf0e10cSrcweir { 2639cdf0e10cSrcweir (void)pBasic; 2640cdf0e10cSrcweir (void)bWrite; 2641cdf0e10cSrcweir 2642cdf0e10cSrcweir String aPath; 2643cdf0e10cSrcweir 2644cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 2645cdf0e10cSrcweir if( nParCount > 3 ) 2646cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2647cdf0e10cSrcweir else 2648cdf0e10cSrcweir { 2649cdf0e10cSrcweir SbiRTLData* pRTLData = pINST->GetRTLData(); 2650cdf0e10cSrcweir 2651cdf0e10cSrcweir // #34645: Kann auch von der URL-Zeile ueber 'macro: Dir' aufgerufen werden 2652cdf0e10cSrcweir // dann existiert kein pRTLData und die Methode muss verlassen werden 2653cdf0e10cSrcweir if( !pRTLData ) 2654cdf0e10cSrcweir return; 2655cdf0e10cSrcweir 2656cdf0e10cSrcweir // <-- UCB 2657cdf0e10cSrcweir if( hasUno() ) 2658cdf0e10cSrcweir { 2659cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 2660cdf0e10cSrcweir if( xSFI.is() ) 2661cdf0e10cSrcweir { 2662cdf0e10cSrcweir if ( nParCount >= 2 ) 2663cdf0e10cSrcweir { 2664cdf0e10cSrcweir String aFileParam = rPar.Get(1)->GetString(); 2665cdf0e10cSrcweir 2666cdf0e10cSrcweir String aFileURLStr = implSetupWildcard( aFileParam, pRTLData ); 2667cdf0e10cSrcweir if( pRTLData->sFullNameToBeChecked.Len() > 0 ) 2668cdf0e10cSrcweir { 2669cdf0e10cSrcweir sal_Bool bExists = sal_False; 2670cdf0e10cSrcweir try { bExists = xSFI->exists( aFileURLStr ); } 2671cdf0e10cSrcweir catch( Exception & ) {} 2672cdf0e10cSrcweir 2673cdf0e10cSrcweir String aNameOnlyStr; 2674cdf0e10cSrcweir if( bExists ) 2675cdf0e10cSrcweir { 2676cdf0e10cSrcweir INetURLObject aFileURL( aFileURLStr ); 2677cdf0e10cSrcweir aNameOnlyStr = aFileURL.getName( INetURLObject::LAST_SEGMENT, 2678cdf0e10cSrcweir true, INetURLObject::DECODE_WITH_CHARSET ); 2679cdf0e10cSrcweir } 2680cdf0e10cSrcweir rPar.Get(0)->PutString( aNameOnlyStr ); 2681cdf0e10cSrcweir return; 2682cdf0e10cSrcweir } 2683cdf0e10cSrcweir 2684cdf0e10cSrcweir try 2685cdf0e10cSrcweir { 2686cdf0e10cSrcweir String aDirURLStr; 2687cdf0e10cSrcweir sal_Bool bFolder = xSFI->isFolder( aFileURLStr ); 2688cdf0e10cSrcweir 2689cdf0e10cSrcweir if( bFolder ) 2690cdf0e10cSrcweir { 2691cdf0e10cSrcweir aDirURLStr = aFileURLStr; 2692cdf0e10cSrcweir } 2693cdf0e10cSrcweir else 2694cdf0e10cSrcweir { 2695cdf0e10cSrcweir String aEmptyStr; 2696cdf0e10cSrcweir rPar.Get(0)->PutString( aEmptyStr ); 2697cdf0e10cSrcweir } 2698cdf0e10cSrcweir 2699cdf0e10cSrcweir sal_uInt16 nFlags = 0; 2700cdf0e10cSrcweir if ( nParCount > 2 ) 2701cdf0e10cSrcweir pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger(); 2702cdf0e10cSrcweir else 2703cdf0e10cSrcweir pRTLData->nDirFlags = 0; 2704cdf0e10cSrcweir 2705cdf0e10cSrcweir // Read directory 2706cdf0e10cSrcweir sal_Bool bIncludeFolders = ((nFlags & Sb_ATTR_DIRECTORY) != 0); 2707cdf0e10cSrcweir pRTLData->aDirSeq = xSFI->getFolderContents( aDirURLStr, bIncludeFolders ); 2708cdf0e10cSrcweir pRTLData->nCurDirPos = 0; 2709cdf0e10cSrcweir 2710cdf0e10cSrcweir // #78651 Add "." and ".." directories for VB compatibility 2711cdf0e10cSrcweir if( bIncludeFolders ) 2712cdf0e10cSrcweir { 2713cdf0e10cSrcweir sal_Bool bRoot = isRootDir( aDirURLStr ); 2714cdf0e10cSrcweir 2715cdf0e10cSrcweir // If it's no root directory we flag the need for 2716cdf0e10cSrcweir // the "." and ".." directories by the value -2 2717cdf0e10cSrcweir // for the actual position. Later for -2 will be 2718cdf0e10cSrcweir // returned "." and for -1 ".." 2719cdf0e10cSrcweir if( !bRoot ) 2720cdf0e10cSrcweir { 2721cdf0e10cSrcweir pRTLData->nCurDirPos = -2; 2722cdf0e10cSrcweir } 2723cdf0e10cSrcweir } 2724cdf0e10cSrcweir } 2725cdf0e10cSrcweir catch( Exception & ) 2726cdf0e10cSrcweir { 2727cdf0e10cSrcweir //StarBASIC::Error( ERRCODE_IO_GENERAL ); 2728cdf0e10cSrcweir } 2729cdf0e10cSrcweir } 2730cdf0e10cSrcweir 2731cdf0e10cSrcweir 2732cdf0e10cSrcweir if( pRTLData->aDirSeq.getLength() > 0 ) 2733cdf0e10cSrcweir { 2734cdf0e10cSrcweir sal_Bool bFolderFlag = ((pRTLData->nDirFlags & Sb_ATTR_DIRECTORY) != 0); 2735cdf0e10cSrcweir 2736cdf0e10cSrcweir SbiInstance* pInst = pINST; 2737cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 2738cdf0e10cSrcweir for( ;; ) 2739cdf0e10cSrcweir { 2740cdf0e10cSrcweir if( pRTLData->nCurDirPos < 0 ) 2741cdf0e10cSrcweir { 2742cdf0e10cSrcweir if( pRTLData->nCurDirPos == -2 ) 2743cdf0e10cSrcweir { 2744cdf0e10cSrcweir aPath = ::rtl::OUString::createFromAscii( "." ); 2745cdf0e10cSrcweir } 2746cdf0e10cSrcweir else if( pRTLData->nCurDirPos == -1 ) 2747cdf0e10cSrcweir { 2748cdf0e10cSrcweir aPath = ::rtl::OUString::createFromAscii( ".." ); 2749cdf0e10cSrcweir } 2750cdf0e10cSrcweir pRTLData->nCurDirPos++; 2751cdf0e10cSrcweir } 2752cdf0e10cSrcweir else if( pRTLData->nCurDirPos >= pRTLData->aDirSeq.getLength() ) 2753cdf0e10cSrcweir { 2754cdf0e10cSrcweir pRTLData->aDirSeq.realloc( 0 ); 2755cdf0e10cSrcweir aPath.Erase(); 2756cdf0e10cSrcweir break; 2757cdf0e10cSrcweir } 2758cdf0e10cSrcweir else 2759cdf0e10cSrcweir { 2760cdf0e10cSrcweir ::rtl::OUString aFile = pRTLData->aDirSeq.getConstArray()[pRTLData->nCurDirPos++]; 2761cdf0e10cSrcweir 2762cdf0e10cSrcweir if( bCompatibility ) 2763cdf0e10cSrcweir { 2764cdf0e10cSrcweir if( !bFolderFlag ) 2765cdf0e10cSrcweir { 2766cdf0e10cSrcweir sal_Bool bFolder = xSFI->isFolder( aFile ); 2767cdf0e10cSrcweir if( bFolder ) 2768cdf0e10cSrcweir continue; 2769cdf0e10cSrcweir } 2770cdf0e10cSrcweir } 2771cdf0e10cSrcweir else 2772cdf0e10cSrcweir { 2773cdf0e10cSrcweir // Only directories 2774cdf0e10cSrcweir if( bFolderFlag ) 2775cdf0e10cSrcweir { 2776cdf0e10cSrcweir sal_Bool bFolder = xSFI->isFolder( aFile ); 2777cdf0e10cSrcweir if( !bFolder ) 2778cdf0e10cSrcweir continue; 2779cdf0e10cSrcweir } 2780cdf0e10cSrcweir } 2781cdf0e10cSrcweir 2782cdf0e10cSrcweir INetURLObject aURL( aFile ); 2783cdf0e10cSrcweir aPath = aURL.getName( INetURLObject::LAST_SEGMENT, sal_True, 2784cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 2785cdf0e10cSrcweir } 2786cdf0e10cSrcweir 2787cdf0e10cSrcweir sal_Bool bMatch = implCheckWildcard( aPath, pRTLData ); 2788cdf0e10cSrcweir if( !bMatch ) 2789cdf0e10cSrcweir continue; 2790cdf0e10cSrcweir 2791cdf0e10cSrcweir break; 2792cdf0e10cSrcweir } 2793cdf0e10cSrcweir } 2794cdf0e10cSrcweir rPar.Get(0)->PutString( aPath ); 2795cdf0e10cSrcweir } 2796cdf0e10cSrcweir } 2797cdf0e10cSrcweir else 2798cdf0e10cSrcweir // --> UCB 2799cdf0e10cSrcweir { 2800cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 2801cdf0e10cSrcweir if ( nParCount >= 2 ) 2802cdf0e10cSrcweir { 2803cdf0e10cSrcweir delete pRTLData->pDir; 2804cdf0e10cSrcweir pRTLData->pDir = 0; // wg. Sonderbehandlung Sb_ATTR_VOLUME 2805cdf0e10cSrcweir DirEntry aEntry( rPar.Get(1)->GetString() ); 2806cdf0e10cSrcweir FileStat aStat( aEntry ); 2807cdf0e10cSrcweir if(!aStat.GetError() && (aStat.GetKind() & FSYS_KIND_FILE)) 2808cdf0e10cSrcweir { 2809cdf0e10cSrcweir // ah ja, ist nur ein dateiname 2810cdf0e10cSrcweir // Pfad abschneiden (wg. VB4) 2811cdf0e10cSrcweir rPar.Get(0)->PutString( aEntry.GetName() ); 2812cdf0e10cSrcweir return; 2813cdf0e10cSrcweir } 2814cdf0e10cSrcweir sal_uInt16 nFlags = 0; 2815cdf0e10cSrcweir if ( nParCount > 2 ) 2816cdf0e10cSrcweir pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger(); 2817cdf0e10cSrcweir else 2818cdf0e10cSrcweir pRTLData->nDirFlags = 0; 2819cdf0e10cSrcweir 2820cdf0e10cSrcweir // Sb_ATTR_VOLUME wird getrennt gehandelt 2821cdf0e10cSrcweir if( pRTLData->nDirFlags & Sb_ATTR_VOLUME ) 2822cdf0e10cSrcweir aPath = aEntry.GetVolume(); 2823cdf0e10cSrcweir else 2824cdf0e10cSrcweir { 2825cdf0e10cSrcweir // Die richtige Auswahl treffen 2826cdf0e10cSrcweir sal_uInt16 nMode = FSYS_KIND_FILE; 2827cdf0e10cSrcweir if( nFlags & Sb_ATTR_DIRECTORY ) 2828cdf0e10cSrcweir nMode |= FSYS_KIND_DIR; 2829cdf0e10cSrcweir if( nFlags == Sb_ATTR_DIRECTORY ) 2830cdf0e10cSrcweir nMode = FSYS_KIND_DIR; 2831cdf0e10cSrcweir pRTLData->pDir = new Dir( aEntry, (DirEntryKind) nMode ); 2832cdf0e10cSrcweir pRTLData->nCurDirPos = 0; 2833cdf0e10cSrcweir } 2834cdf0e10cSrcweir } 2835cdf0e10cSrcweir 2836cdf0e10cSrcweir if( pRTLData->pDir ) 2837cdf0e10cSrcweir { 2838cdf0e10cSrcweir for( ;; ) 2839cdf0e10cSrcweir { 2840cdf0e10cSrcweir if( pRTLData->nCurDirPos >= pRTLData->pDir->Count() ) 2841cdf0e10cSrcweir { 2842cdf0e10cSrcweir delete pRTLData->pDir; 2843cdf0e10cSrcweir pRTLData->pDir = 0; 2844cdf0e10cSrcweir aPath.Erase(); 2845cdf0e10cSrcweir break; 2846cdf0e10cSrcweir } 2847cdf0e10cSrcweir DirEntry aNextEntry=(*(pRTLData->pDir))[pRTLData->nCurDirPos++]; 2848cdf0e10cSrcweir aPath = aNextEntry.GetName(); //Full(); 2849cdf0e10cSrcweir break; 2850cdf0e10cSrcweir } 2851cdf0e10cSrcweir } 2852cdf0e10cSrcweir rPar.Get(0)->PutString( aPath ); 2853cdf0e10cSrcweir #else 2854cdf0e10cSrcweir // TODO: OSL 2855cdf0e10cSrcweir if ( nParCount >= 2 ) 2856cdf0e10cSrcweir { 2857cdf0e10cSrcweir String aFileParam = rPar.Get(1)->GetString(); 2858cdf0e10cSrcweir 2859cdf0e10cSrcweir String aDirURL = implSetupWildcard( aFileParam, pRTLData ); 2860cdf0e10cSrcweir 2861cdf0e10cSrcweir sal_uInt16 nFlags = 0; 2862cdf0e10cSrcweir if ( nParCount > 2 ) 2863cdf0e10cSrcweir pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger(); 2864cdf0e10cSrcweir else 2865cdf0e10cSrcweir pRTLData->nDirFlags = 0; 2866cdf0e10cSrcweir 2867cdf0e10cSrcweir // Read directory 2868cdf0e10cSrcweir sal_Bool bIncludeFolders = ((nFlags & Sb_ATTR_DIRECTORY) != 0); 2869cdf0e10cSrcweir pRTLData->pDir = new Directory( aDirURL ); 2870cdf0e10cSrcweir FileBase::RC nRet = pRTLData->pDir->open(); 2871cdf0e10cSrcweir if( nRet != FileBase::E_None ) 2872cdf0e10cSrcweir { 2873cdf0e10cSrcweir delete pRTLData->pDir; 2874cdf0e10cSrcweir pRTLData->pDir = NULL; 2875cdf0e10cSrcweir rPar.Get(0)->PutString( String() ); 2876cdf0e10cSrcweir return; 2877cdf0e10cSrcweir } 2878cdf0e10cSrcweir 2879cdf0e10cSrcweir // #86950 Add "." and ".." directories for VB compatibility 2880cdf0e10cSrcweir pRTLData->nCurDirPos = 0; 2881cdf0e10cSrcweir if( bIncludeFolders ) 2882cdf0e10cSrcweir { 2883cdf0e10cSrcweir sal_Bool bRoot = isRootDir( aDirURL ); 2884cdf0e10cSrcweir 2885cdf0e10cSrcweir // If it's no root directory we flag the need for 2886cdf0e10cSrcweir // the "." and ".." directories by the value -2 2887cdf0e10cSrcweir // for the actual position. Later for -2 will be 2888cdf0e10cSrcweir // returned "." and for -1 ".." 2889cdf0e10cSrcweir if( !bRoot ) 2890cdf0e10cSrcweir { 2891cdf0e10cSrcweir pRTLData->nCurDirPos = -2; 2892cdf0e10cSrcweir } 2893cdf0e10cSrcweir } 2894cdf0e10cSrcweir 2895cdf0e10cSrcweir } 2896cdf0e10cSrcweir 2897cdf0e10cSrcweir if( pRTLData->pDir ) 2898cdf0e10cSrcweir { 2899cdf0e10cSrcweir sal_Bool bFolderFlag = ((pRTLData->nDirFlags & Sb_ATTR_DIRECTORY) != 0); 2900cdf0e10cSrcweir for( ;; ) 2901cdf0e10cSrcweir { 2902cdf0e10cSrcweir if( pRTLData->nCurDirPos < 0 ) 2903cdf0e10cSrcweir { 2904cdf0e10cSrcweir if( pRTLData->nCurDirPos == -2 ) 2905cdf0e10cSrcweir { 2906cdf0e10cSrcweir aPath = ::rtl::OUString::createFromAscii( "." ); 2907cdf0e10cSrcweir } 2908cdf0e10cSrcweir else if( pRTLData->nCurDirPos == -1 ) 2909cdf0e10cSrcweir { 2910cdf0e10cSrcweir aPath = ::rtl::OUString::createFromAscii( ".." ); 2911cdf0e10cSrcweir } 2912cdf0e10cSrcweir pRTLData->nCurDirPos++; 2913cdf0e10cSrcweir } 2914cdf0e10cSrcweir else 2915cdf0e10cSrcweir { 2916cdf0e10cSrcweir DirectoryItem aItem; 2917cdf0e10cSrcweir FileBase::RC nRet = pRTLData->pDir->getNextItem( aItem ); 2918cdf0e10cSrcweir if( nRet != FileBase::E_None ) 2919cdf0e10cSrcweir { 2920cdf0e10cSrcweir delete pRTLData->pDir; 2921cdf0e10cSrcweir pRTLData->pDir = NULL; 2922cdf0e10cSrcweir aPath.Erase(); 2923cdf0e10cSrcweir break; 2924cdf0e10cSrcweir } 2925cdf0e10cSrcweir 2926cdf0e10cSrcweir // Handle flags 2927cdf0e10cSrcweir FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileName ); 2928cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus ); 2929cdf0e10cSrcweir 2930cdf0e10cSrcweir // Only directories? 2931cdf0e10cSrcweir if( bFolderFlag ) 2932cdf0e10cSrcweir { 2933cdf0e10cSrcweir FileStatus::Type aType = aFileStatus.getFileType(); 2934cdf0e10cSrcweir sal_Bool bFolder = isFolder( aType ); 2935cdf0e10cSrcweir if( !bFolder ) 2936cdf0e10cSrcweir continue; 2937cdf0e10cSrcweir } 2938cdf0e10cSrcweir 2939cdf0e10cSrcweir aPath = aFileStatus.getFileName(); 2940cdf0e10cSrcweir } 2941cdf0e10cSrcweir 2942cdf0e10cSrcweir sal_Bool bMatch = implCheckWildcard( aPath, pRTLData ); 2943cdf0e10cSrcweir if( !bMatch ) 2944cdf0e10cSrcweir continue; 2945cdf0e10cSrcweir 2946cdf0e10cSrcweir break; 2947cdf0e10cSrcweir } 2948cdf0e10cSrcweir } 2949cdf0e10cSrcweir rPar.Get(0)->PutString( aPath ); 2950cdf0e10cSrcweir #endif 2951cdf0e10cSrcweir } 2952cdf0e10cSrcweir } 2953cdf0e10cSrcweir } 2954cdf0e10cSrcweir 2955cdf0e10cSrcweir 2956cdf0e10cSrcweir RTLFUNC(GetAttr) 2957cdf0e10cSrcweir { 2958cdf0e10cSrcweir (void)pBasic; 2959cdf0e10cSrcweir (void)bWrite; 2960cdf0e10cSrcweir 2961cdf0e10cSrcweir if ( rPar.Count() == 2 ) 2962cdf0e10cSrcweir { 2963cdf0e10cSrcweir sal_Int16 nFlags = 0; 2964cdf0e10cSrcweir 2965cdf0e10cSrcweir // In Windows, We want to use Windows API to get the file attributes 2966cdf0e10cSrcweir // for VBA interoperability. 2967cdf0e10cSrcweir #if defined( WNT ) 2968cdf0e10cSrcweir if( SbiRuntime::isVBAEnabled() ) 2969cdf0e10cSrcweir { 2970cdf0e10cSrcweir DirEntry aEntry( rPar.Get(1)->GetString() ); 2971cdf0e10cSrcweir aEntry.ToAbs(); 2972cdf0e10cSrcweir 2973cdf0e10cSrcweir // #57064 Bei virtuellen URLs den Real-Path extrahieren 2974cdf0e10cSrcweir ByteString aByteStrFullPath( aEntry.GetFull(), gsl_getSystemTextEncoding() ); 2975cdf0e10cSrcweir DWORD nRealFlags = GetFileAttributes (aByteStrFullPath.GetBuffer()); 2976cdf0e10cSrcweir if (nRealFlags != 0xffffffff) 2977cdf0e10cSrcweir { 2978cdf0e10cSrcweir if (nRealFlags == FILE_ATTRIBUTE_NORMAL) 2979cdf0e10cSrcweir nRealFlags = 0; 2980cdf0e10cSrcweir nFlags = (sal_Int16) (nRealFlags); 2981cdf0e10cSrcweir } 2982cdf0e10cSrcweir else 2983cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 2984cdf0e10cSrcweir 2985cdf0e10cSrcweir rPar.Get(0)->PutInteger( nFlags ); 2986cdf0e10cSrcweir 2987cdf0e10cSrcweir return; 2988cdf0e10cSrcweir } 2989cdf0e10cSrcweir #endif 2990cdf0e10cSrcweir 2991cdf0e10cSrcweir // <-- UCB 2992cdf0e10cSrcweir if( hasUno() ) 2993cdf0e10cSrcweir { 2994cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 2995cdf0e10cSrcweir if( xSFI.is() ) 2996cdf0e10cSrcweir { 2997cdf0e10cSrcweir try 2998cdf0e10cSrcweir { 2999cdf0e10cSrcweir String aPath = getFullPath( rPar.Get(1)->GetString() ); 3000cdf0e10cSrcweir sal_Bool bExists = sal_False; 3001cdf0e10cSrcweir try { bExists = xSFI->exists( aPath ); } 3002cdf0e10cSrcweir catch( Exception & ) {} 3003cdf0e10cSrcweir if( !bExists ) 3004cdf0e10cSrcweir { 3005cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 3006cdf0e10cSrcweir return; 3007cdf0e10cSrcweir } 3008cdf0e10cSrcweir 3009cdf0e10cSrcweir sal_Bool bReadOnly = xSFI->isReadOnly( aPath ); 3010cdf0e10cSrcweir sal_Bool bHidden = xSFI->isHidden( aPath ); 3011cdf0e10cSrcweir sal_Bool bDirectory = xSFI->isFolder( aPath ); 3012cdf0e10cSrcweir if( bReadOnly ) 3013cdf0e10cSrcweir nFlags |= 0x0001; // ATTR_READONLY 3014cdf0e10cSrcweir if( bHidden ) 3015cdf0e10cSrcweir nFlags |= 0x0002; // ATTR_HIDDEN 3016cdf0e10cSrcweir if( bDirectory ) 3017cdf0e10cSrcweir nFlags |= 0x0010; // ATTR_DIRECTORY 3018cdf0e10cSrcweir } 3019cdf0e10cSrcweir catch( Exception & ) 3020cdf0e10cSrcweir { 3021cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 3022cdf0e10cSrcweir } 3023cdf0e10cSrcweir } 3024cdf0e10cSrcweir } 3025cdf0e10cSrcweir else 3026cdf0e10cSrcweir // --> UCB 3027cdf0e10cSrcweir { 3028cdf0e10cSrcweir DirectoryItem aItem; 3029cdf0e10cSrcweir FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( rPar.Get(1)->GetString() ), aItem ); 3030cdf0e10cSrcweir FileStatus aFileStatus( FileStatusMask_Attributes | FileStatusMask_Type ); 3031cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus ); 3032cdf0e10cSrcweir sal_uInt64 nAttributes = aFileStatus.getAttributes(); 3033cdf0e10cSrcweir sal_Bool bReadOnly = (nAttributes & Attribute_ReadOnly) != 0; 3034cdf0e10cSrcweir 3035cdf0e10cSrcweir FileStatus::Type aType = aFileStatus.getFileType(); 3036cdf0e10cSrcweir sal_Bool bDirectory = isFolder( aType ); 3037cdf0e10cSrcweir if( bReadOnly ) 3038cdf0e10cSrcweir nFlags |= 0x0001; // ATTR_READONLY 3039cdf0e10cSrcweir if( bDirectory ) 3040cdf0e10cSrcweir nFlags |= 0x0010; // ATTR_DIRECTORY 3041cdf0e10cSrcweir } 3042cdf0e10cSrcweir rPar.Get(0)->PutInteger( nFlags ); 3043cdf0e10cSrcweir } 3044cdf0e10cSrcweir else 3045cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3046cdf0e10cSrcweir } 3047cdf0e10cSrcweir 3048cdf0e10cSrcweir 3049cdf0e10cSrcweir RTLFUNC(FileDateTime) 3050cdf0e10cSrcweir { 3051cdf0e10cSrcweir (void)pBasic; 3052cdf0e10cSrcweir (void)bWrite; 3053cdf0e10cSrcweir 3054cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3055cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3056cdf0e10cSrcweir else 3057cdf0e10cSrcweir { 3058cdf0e10cSrcweir // <-- UCB 3059cdf0e10cSrcweir String aPath = rPar.Get(1)->GetString(); 3060cdf0e10cSrcweir Time aTime; 3061cdf0e10cSrcweir Date aDate; 3062cdf0e10cSrcweir if( hasUno() ) 3063cdf0e10cSrcweir { 3064cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 3065cdf0e10cSrcweir if( xSFI.is() ) 3066cdf0e10cSrcweir { 3067cdf0e10cSrcweir try 3068cdf0e10cSrcweir { 3069cdf0e10cSrcweir com::sun::star::util::DateTime aUnoDT = xSFI->getDateTimeModified( aPath ); 3070cdf0e10cSrcweir aTime = Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ); 3071cdf0e10cSrcweir aDate = Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ); 3072cdf0e10cSrcweir } 3073cdf0e10cSrcweir catch( Exception & ) 3074cdf0e10cSrcweir { 3075cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 3076cdf0e10cSrcweir } 3077cdf0e10cSrcweir } 3078cdf0e10cSrcweir } 3079cdf0e10cSrcweir else 3080cdf0e10cSrcweir // --> UCB 3081cdf0e10cSrcweir { 3082cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 3083cdf0e10cSrcweir DirEntry aEntry( aPath ); 3084cdf0e10cSrcweir FileStat aStat( aEntry ); 3085cdf0e10cSrcweir aTime = Time( aStat.TimeModified() ); 3086cdf0e10cSrcweir aDate = Date( aStat.DateModified() ); 3087cdf0e10cSrcweir #else 3088cdf0e10cSrcweir DirectoryItem aItem; 3089cdf0e10cSrcweir FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( aPath ), aItem ); 3090cdf0e10cSrcweir FileStatus aFileStatus( FileStatusMask_ModifyTime ); 3091cdf0e10cSrcweir nRet = aItem.getFileStatus( aFileStatus ); 3092cdf0e10cSrcweir TimeValue aTimeVal = aFileStatus.getModifyTime(); 3093cdf0e10cSrcweir oslDateTime aDT; 3094cdf0e10cSrcweir osl_getDateTimeFromTimeValue( &aTimeVal, &aDT ); 3095cdf0e10cSrcweir 3096cdf0e10cSrcweir aTime = Time( aDT.Hours, aDT.Minutes, aDT.Seconds, 10000000*aDT.NanoSeconds ); 3097cdf0e10cSrcweir aDate = Date( aDT.Day, aDT.Month, aDT.Year ); 3098cdf0e10cSrcweir #endif 3099cdf0e10cSrcweir } 3100cdf0e10cSrcweir 3101cdf0e10cSrcweir double fSerial = (double)GetDayDiff( aDate ); 3102cdf0e10cSrcweir long nSeconds = aTime.GetHour(); 3103cdf0e10cSrcweir nSeconds *= 3600; 3104cdf0e10cSrcweir nSeconds += aTime.GetMin() * 60; 3105cdf0e10cSrcweir nSeconds += aTime.GetSec(); 3106cdf0e10cSrcweir double nDays = ((double)nSeconds) / (double)(24.0*3600.0); 3107cdf0e10cSrcweir fSerial += nDays; 3108cdf0e10cSrcweir 3109cdf0e10cSrcweir Color* pCol; 3110cdf0e10cSrcweir 3111cdf0e10cSrcweir // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden 3112cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL; 3113cdf0e10cSrcweir sal_uInt32 nIndex; 3114cdf0e10cSrcweir if( pINST ) 3115cdf0e10cSrcweir { 3116cdf0e10cSrcweir pFormatter = pINST->GetNumberFormatter(); 3117cdf0e10cSrcweir nIndex = pINST->GetStdDateTimeIdx(); 3118cdf0e10cSrcweir } 3119cdf0e10cSrcweir else 3120cdf0e10cSrcweir { 3121cdf0e10cSrcweir sal_uInt32 n; // Dummy 3122cdf0e10cSrcweir SbiInstance::PrepareNumberFormatter( pFormatter, n, n, nIndex ); 3123cdf0e10cSrcweir } 3124cdf0e10cSrcweir 3125cdf0e10cSrcweir String aRes; 3126cdf0e10cSrcweir pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol ); 3127cdf0e10cSrcweir rPar.Get(0)->PutString( aRes ); 3128cdf0e10cSrcweir 3129cdf0e10cSrcweir // #39629 pFormatter kann selbst angefordert sein 3130cdf0e10cSrcweir if( !pINST ) 3131cdf0e10cSrcweir delete pFormatter; 3132cdf0e10cSrcweir } 3133cdf0e10cSrcweir } 3134cdf0e10cSrcweir 3135cdf0e10cSrcweir 3136cdf0e10cSrcweir RTLFUNC(EOF) 3137cdf0e10cSrcweir { 3138cdf0e10cSrcweir (void)pBasic; 3139cdf0e10cSrcweir (void)bWrite; 3140cdf0e10cSrcweir 3141cdf0e10cSrcweir // AB 08/16/2000: No changes for UCB 3142cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3143cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3144cdf0e10cSrcweir else 3145cdf0e10cSrcweir { 3146cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3147cdf0e10cSrcweir // nChannel--; // macht MD beim Oeffnen auch nicht 3148cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 3149cdf0e10cSrcweir SbiStream* pSbStrm = pIO->GetStream( nChannel ); 3150cdf0e10cSrcweir if ( !pSbStrm ) 3151cdf0e10cSrcweir { 3152cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 3153cdf0e10cSrcweir return; 3154cdf0e10cSrcweir } 3155cdf0e10cSrcweir sal_Bool bIsEof; 3156cdf0e10cSrcweir SvStream* pSvStrm = pSbStrm->GetStrm(); 3157cdf0e10cSrcweir if ( pSbStrm->IsText() ) 3158cdf0e10cSrcweir { 3159cdf0e10cSrcweir char cBla; 3160cdf0e10cSrcweir (*pSvStrm) >> cBla; // koennen wir noch ein Zeichen lesen 3161cdf0e10cSrcweir bIsEof = pSvStrm->IsEof(); 3162cdf0e10cSrcweir if ( !bIsEof ) 3163cdf0e10cSrcweir pSvStrm->SeekRel( -1 ); 3164cdf0e10cSrcweir } 3165cdf0e10cSrcweir else 3166cdf0e10cSrcweir bIsEof = pSvStrm->IsEof(); // fuer binaerdateien! 3167cdf0e10cSrcweir rPar.Get(0)->PutBool( bIsEof ); 3168cdf0e10cSrcweir } 3169cdf0e10cSrcweir } 3170cdf0e10cSrcweir 3171cdf0e10cSrcweir RTLFUNC(FileAttr) 3172cdf0e10cSrcweir { 3173cdf0e10cSrcweir (void)pBasic; 3174cdf0e10cSrcweir (void)bWrite; 3175cdf0e10cSrcweir 3176cdf0e10cSrcweir // AB 08/16/2000: No changes for UCB 3177cdf0e10cSrcweir 3178cdf0e10cSrcweir // #57064 Obwohl diese Funktion nicht mit DirEntry arbeitet, ist sie von 3179cdf0e10cSrcweir // der Anpassung an virtuelle URLs nich betroffen, da sie nur auf bereits 3180cdf0e10cSrcweir // geoeffneten Dateien arbeitet und der Name hier keine Rolle spielt. 3181cdf0e10cSrcweir 3182cdf0e10cSrcweir if ( rPar.Count() != 3 ) 3183cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3184cdf0e10cSrcweir else 3185cdf0e10cSrcweir { 3186cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3187cdf0e10cSrcweir // nChannel--; 3188cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 3189cdf0e10cSrcweir SbiStream* pSbStrm = pIO->GetStream( nChannel ); 3190cdf0e10cSrcweir if ( !pSbStrm ) 3191cdf0e10cSrcweir { 3192cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 3193cdf0e10cSrcweir return; 3194cdf0e10cSrcweir } 3195cdf0e10cSrcweir sal_Int16 nRet; 3196cdf0e10cSrcweir if ( rPar.Get(2)->GetInteger() == 1 ) 3197cdf0e10cSrcweir nRet = (sal_Int16)(pSbStrm->GetMode()); 3198cdf0e10cSrcweir else 3199cdf0e10cSrcweir nRet = 0; // System file handle not supported 3200cdf0e10cSrcweir 3201cdf0e10cSrcweir rPar.Get(0)->PutInteger( nRet ); 3202cdf0e10cSrcweir } 3203cdf0e10cSrcweir } 3204cdf0e10cSrcweir RTLFUNC(Loc) 3205cdf0e10cSrcweir { 3206cdf0e10cSrcweir (void)pBasic; 3207cdf0e10cSrcweir (void)bWrite; 3208cdf0e10cSrcweir 3209cdf0e10cSrcweir // AB 08/16/2000: No changes for UCB 3210cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3211cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3212cdf0e10cSrcweir else 3213cdf0e10cSrcweir { 3214cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3215cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 3216cdf0e10cSrcweir SbiStream* pSbStrm = pIO->GetStream( nChannel ); 3217cdf0e10cSrcweir if ( !pSbStrm ) 3218cdf0e10cSrcweir { 3219cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 3220cdf0e10cSrcweir return; 3221cdf0e10cSrcweir } 3222cdf0e10cSrcweir SvStream* pSvStrm = pSbStrm->GetStrm(); 3223cdf0e10cSrcweir sal_uIntPtr nPos; 3224cdf0e10cSrcweir if( pSbStrm->IsRandom()) 3225cdf0e10cSrcweir { 3226cdf0e10cSrcweir short nBlockLen = pSbStrm->GetBlockLen(); 3227cdf0e10cSrcweir nPos = nBlockLen ? (pSvStrm->Tell() / nBlockLen) : 0; 3228cdf0e10cSrcweir nPos++; // Blockpositionen beginnen bei 1 3229cdf0e10cSrcweir } 3230cdf0e10cSrcweir else if ( pSbStrm->IsText() ) 3231cdf0e10cSrcweir nPos = pSbStrm->GetLine(); 3232cdf0e10cSrcweir else if( pSbStrm->IsBinary() ) 3233cdf0e10cSrcweir nPos = pSvStrm->Tell(); 3234cdf0e10cSrcweir else if ( pSbStrm->IsSeq() ) 3235cdf0e10cSrcweir nPos = ( pSvStrm->Tell()+1 ) / 128; 3236cdf0e10cSrcweir else 3237cdf0e10cSrcweir nPos = pSvStrm->Tell(); 3238cdf0e10cSrcweir rPar.Get(0)->PutLong( (sal_Int32)nPos ); 3239cdf0e10cSrcweir } 3240cdf0e10cSrcweir } 3241cdf0e10cSrcweir 3242cdf0e10cSrcweir RTLFUNC(Lof) 3243cdf0e10cSrcweir { 3244cdf0e10cSrcweir (void)pBasic; 3245cdf0e10cSrcweir (void)bWrite; 3246cdf0e10cSrcweir 3247cdf0e10cSrcweir // AB 08/16/2000: No changes for UCB 3248cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3249cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3250cdf0e10cSrcweir else 3251cdf0e10cSrcweir { 3252cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3253cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 3254cdf0e10cSrcweir SbiStream* pSbStrm = pIO->GetStream( nChannel ); 3255cdf0e10cSrcweir if ( !pSbStrm ) 3256cdf0e10cSrcweir { 3257cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 3258cdf0e10cSrcweir return; 3259cdf0e10cSrcweir } 3260cdf0e10cSrcweir SvStream* pSvStrm = pSbStrm->GetStrm(); 3261cdf0e10cSrcweir sal_uIntPtr nOldPos = pSvStrm->Tell(); 3262cdf0e10cSrcweir sal_uIntPtr nLen = pSvStrm->Seek( STREAM_SEEK_TO_END ); 3263cdf0e10cSrcweir pSvStrm->Seek( nOldPos ); 3264cdf0e10cSrcweir rPar.Get(0)->PutLong( (sal_Int32)nLen ); 3265cdf0e10cSrcweir } 3266cdf0e10cSrcweir } 3267cdf0e10cSrcweir 3268cdf0e10cSrcweir 3269cdf0e10cSrcweir RTLFUNC(Seek) 3270cdf0e10cSrcweir { 3271cdf0e10cSrcweir (void)pBasic; 3272cdf0e10cSrcweir (void)bWrite; 3273cdf0e10cSrcweir 3274cdf0e10cSrcweir // AB 08/16/2000: No changes for UCB 3275cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3276cdf0e10cSrcweir if ( nArgs < 2 || nArgs > 3 ) 3277cdf0e10cSrcweir { 3278cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3279cdf0e10cSrcweir return; 3280cdf0e10cSrcweir } 3281cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3282cdf0e10cSrcweir // nChannel--; 3283cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 3284cdf0e10cSrcweir SbiStream* pSbStrm = pIO->GetStream( nChannel ); 3285cdf0e10cSrcweir if ( !pSbStrm ) 3286cdf0e10cSrcweir { 3287cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 3288cdf0e10cSrcweir return; 3289cdf0e10cSrcweir } 3290cdf0e10cSrcweir SvStream* pStrm = pSbStrm->GetStrm(); 3291cdf0e10cSrcweir 3292cdf0e10cSrcweir if ( nArgs == 2 ) // Seek-Function 3293cdf0e10cSrcweir { 3294cdf0e10cSrcweir sal_uIntPtr nPos = pStrm->Tell(); 3295cdf0e10cSrcweir if( pSbStrm->IsRandom() ) 3296cdf0e10cSrcweir nPos = nPos / pSbStrm->GetBlockLen(); 3297cdf0e10cSrcweir nPos++; // Basic zaehlt ab 1 3298cdf0e10cSrcweir rPar.Get(0)->PutLong( (sal_Int32)nPos ); 3299cdf0e10cSrcweir } 3300cdf0e10cSrcweir else // Seek-Statement 3301cdf0e10cSrcweir { 3302cdf0e10cSrcweir sal_Int32 nPos = rPar.Get(2)->GetLong(); 3303cdf0e10cSrcweir if ( nPos < 1 ) 3304cdf0e10cSrcweir { 3305cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3306cdf0e10cSrcweir return; 3307cdf0e10cSrcweir } 3308cdf0e10cSrcweir nPos--; // Basic zaehlt ab 1, SvStreams zaehlen ab 0 3309cdf0e10cSrcweir pSbStrm->SetExpandOnWriteTo( 0 ); 3310cdf0e10cSrcweir if ( pSbStrm->IsRandom() ) 3311cdf0e10cSrcweir nPos *= pSbStrm->GetBlockLen(); 3312cdf0e10cSrcweir pStrm->Seek( (sal_uIntPtr)nPos ); 3313cdf0e10cSrcweir pSbStrm->SetExpandOnWriteTo( nPos ); 3314cdf0e10cSrcweir } 3315cdf0e10cSrcweir } 3316cdf0e10cSrcweir 3317cdf0e10cSrcweir RTLFUNC(Format) 3318cdf0e10cSrcweir { 3319cdf0e10cSrcweir (void)pBasic; 3320cdf0e10cSrcweir (void)bWrite; 3321cdf0e10cSrcweir 3322cdf0e10cSrcweir sal_uInt16 nArgCount = (sal_uInt16)rPar.Count(); 3323cdf0e10cSrcweir if ( nArgCount < 2 || nArgCount > 3 ) 3324cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3325cdf0e10cSrcweir else 3326cdf0e10cSrcweir { 3327cdf0e10cSrcweir String aResult; 3328cdf0e10cSrcweir if( nArgCount == 2 ) 3329cdf0e10cSrcweir rPar.Get(1)->Format( aResult ); 3330cdf0e10cSrcweir else 3331cdf0e10cSrcweir { 3332cdf0e10cSrcweir String aFmt( rPar.Get(2)->GetString() ); 3333cdf0e10cSrcweir rPar.Get(1)->Format( aResult, &aFmt ); 3334cdf0e10cSrcweir } 3335cdf0e10cSrcweir rPar.Get(0)->PutString( aResult ); 3336cdf0e10cSrcweir } 3337cdf0e10cSrcweir } 3338cdf0e10cSrcweir 3339cdf0e10cSrcweir RTLFUNC(Randomize) 3340cdf0e10cSrcweir { 3341cdf0e10cSrcweir (void)pBasic; 3342cdf0e10cSrcweir (void)bWrite; 3343cdf0e10cSrcweir 3344cdf0e10cSrcweir if ( rPar.Count() > 2 ) 3345cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3346cdf0e10cSrcweir sal_Int16 nSeed; 3347cdf0e10cSrcweir if( rPar.Count() == 2 ) 3348cdf0e10cSrcweir nSeed = (sal_Int16)rPar.Get(1)->GetInteger(); 3349cdf0e10cSrcweir else 3350cdf0e10cSrcweir nSeed = (sal_Int16)rand(); 3351cdf0e10cSrcweir srand( nSeed ); 3352cdf0e10cSrcweir } 3353cdf0e10cSrcweir 3354cdf0e10cSrcweir RTLFUNC(Rnd) 3355cdf0e10cSrcweir { 3356cdf0e10cSrcweir (void)pBasic; 3357cdf0e10cSrcweir (void)bWrite; 3358cdf0e10cSrcweir 3359cdf0e10cSrcweir if ( rPar.Count() > 2 ) 3360cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3361cdf0e10cSrcweir else 3362cdf0e10cSrcweir { 3363cdf0e10cSrcweir double nRand = (double)rand(); 3364cdf0e10cSrcweir nRand = ( nRand / (double)RAND_MAX ); 3365cdf0e10cSrcweir rPar.Get(0)->PutDouble( nRand ); 3366cdf0e10cSrcweir } 3367cdf0e10cSrcweir } 3368cdf0e10cSrcweir 3369cdf0e10cSrcweir 3370cdf0e10cSrcweir // 3371cdf0e10cSrcweir // Syntax: Shell("Path",[ Window-Style,[ "Params", [ bSync = sal_False ]]]) 3372cdf0e10cSrcweir // 3373cdf0e10cSrcweir // WindowStyles (VBA-kompatibel): 3374cdf0e10cSrcweir // 2 == Minimized 3375cdf0e10cSrcweir // 3 == Maximized 3376cdf0e10cSrcweir // 10 == Full-Screen (Textmodus-Anwendungen OS/2, WIN95, WNT) 3377cdf0e10cSrcweir // 3378cdf0e10cSrcweir // !!!HACK der WindowStyle wird im Creator an Application::StartApp 3379cdf0e10cSrcweir // uebergeben. Format: "xxxx2" 3380cdf0e10cSrcweir // 3381cdf0e10cSrcweir 3382cdf0e10cSrcweir 3383cdf0e10cSrcweir RTLFUNC(Shell) 3384cdf0e10cSrcweir { 3385cdf0e10cSrcweir (void)pBasic; 3386cdf0e10cSrcweir (void)bWrite; 3387cdf0e10cSrcweir 3388cdf0e10cSrcweir // No shell command for "virtual" portal users 3389cdf0e10cSrcweir if( needSecurityRestrictions() ) 3390cdf0e10cSrcweir { 3391cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3392cdf0e10cSrcweir return; 3393cdf0e10cSrcweir } 3394cdf0e10cSrcweir 3395cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count(); 3396cdf0e10cSrcweir if ( nArgCount < 2 || nArgCount > 5 ) 3397cdf0e10cSrcweir { 3398cdf0e10cSrcweir rPar.Get(0)->PutLong(0); 3399cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3400cdf0e10cSrcweir } 3401cdf0e10cSrcweir else 3402cdf0e10cSrcweir { 3403cdf0e10cSrcweir sal_uInt16 nOptions = vos::OProcess::TOption_SearchPath| 3404cdf0e10cSrcweir vos::OProcess::TOption_Detached; 3405cdf0e10cSrcweir String aCmdLine = rPar.Get(1)->GetString(); 3406cdf0e10cSrcweir // Zusaetzliche Parameter anhaengen, es muss eh alles geparsed werden 3407cdf0e10cSrcweir if( nArgCount >= 4 ) 3408cdf0e10cSrcweir { 3409cdf0e10cSrcweir aCmdLine.AppendAscii( " " ); 3410cdf0e10cSrcweir aCmdLine += rPar.Get(3)->GetString(); 3411cdf0e10cSrcweir } 3412cdf0e10cSrcweir else if( !aCmdLine.Len() ) 3413cdf0e10cSrcweir { 3414cdf0e10cSrcweir // Spezial-Behandlung (leere Liste) vermeiden 3415cdf0e10cSrcweir aCmdLine.AppendAscii( " " ); 3416cdf0e10cSrcweir } 3417cdf0e10cSrcweir sal_uInt16 nLen = aCmdLine.Len(); 3418cdf0e10cSrcweir 3419cdf0e10cSrcweir // #55735 Wenn Parameter dabei sind, muessen die abgetrennt werden 3420cdf0e10cSrcweir // #72471 Auch die einzelnen Parameter trennen 3421cdf0e10cSrcweir std::list<String> aTokenList; 3422cdf0e10cSrcweir String aToken; 3423cdf0e10cSrcweir sal_uInt16 i = 0; 3424cdf0e10cSrcweir sal_Unicode c; 3425cdf0e10cSrcweir while( i < nLen ) 3426cdf0e10cSrcweir { 3427cdf0e10cSrcweir // Spaces weg 3428cdf0e10cSrcweir for ( ;; ++i ) 3429cdf0e10cSrcweir { 3430cdf0e10cSrcweir c = aCmdLine.GetBuffer()[ i ]; 3431cdf0e10cSrcweir if ( c != ' ' && c != '\t' ) 3432cdf0e10cSrcweir break; 3433cdf0e10cSrcweir } 3434cdf0e10cSrcweir 3435cdf0e10cSrcweir if( c == '\"' || c == '\'' ) 3436cdf0e10cSrcweir { 3437cdf0e10cSrcweir sal_uInt16 iFoundPos = aCmdLine.Search( c, i + 1 ); 3438cdf0e10cSrcweir 3439cdf0e10cSrcweir // Wenn nichts gefunden wurde, Rest kopieren 3440cdf0e10cSrcweir if( iFoundPos == STRING_NOTFOUND ) 3441cdf0e10cSrcweir { 3442cdf0e10cSrcweir aToken = aCmdLine.Copy( i, STRING_LEN ); 3443cdf0e10cSrcweir i = nLen; 3444cdf0e10cSrcweir } 3445cdf0e10cSrcweir else 3446cdf0e10cSrcweir { 3447cdf0e10cSrcweir aToken = aCmdLine.Copy( i + 1, (iFoundPos - i - 1) ); 3448cdf0e10cSrcweir i = iFoundPos + 1; 3449cdf0e10cSrcweir } 3450cdf0e10cSrcweir } 3451cdf0e10cSrcweir else 3452cdf0e10cSrcweir { 3453cdf0e10cSrcweir sal_uInt16 iFoundSpacePos = aCmdLine.Search( ' ', i ); 3454cdf0e10cSrcweir sal_uInt16 iFoundTabPos = aCmdLine.Search( '\t', i ); 3455cdf0e10cSrcweir sal_uInt16 iFoundPos = Min( iFoundSpacePos, iFoundTabPos ); 3456cdf0e10cSrcweir 3457cdf0e10cSrcweir // Wenn nichts gefunden wurde, Rest kopieren 3458cdf0e10cSrcweir if( iFoundPos == STRING_NOTFOUND ) 3459cdf0e10cSrcweir { 3460cdf0e10cSrcweir aToken = aCmdLine.Copy( i, STRING_LEN ); 3461cdf0e10cSrcweir i = nLen; 3462cdf0e10cSrcweir } 3463cdf0e10cSrcweir else 3464cdf0e10cSrcweir { 3465cdf0e10cSrcweir aToken = aCmdLine.Copy( i, (iFoundPos - i) ); 3466cdf0e10cSrcweir i = iFoundPos; 3467cdf0e10cSrcweir } 3468cdf0e10cSrcweir } 3469cdf0e10cSrcweir 3470cdf0e10cSrcweir // In die Liste uebernehmen 3471cdf0e10cSrcweir aTokenList.push_back( aToken ); 3472cdf0e10cSrcweir } 3473cdf0e10cSrcweir // #55735 / #72471 Ende 3474cdf0e10cSrcweir 3475cdf0e10cSrcweir sal_Int16 nWinStyle = 0; 3476cdf0e10cSrcweir if( nArgCount >= 3 ) 3477cdf0e10cSrcweir { 3478cdf0e10cSrcweir nWinStyle = rPar.Get(2)->GetInteger(); 3479cdf0e10cSrcweir switch( nWinStyle ) 3480cdf0e10cSrcweir { 3481cdf0e10cSrcweir case 2: 3482cdf0e10cSrcweir nOptions |= vos::OProcess::TOption_Minimized; 3483cdf0e10cSrcweir break; 3484cdf0e10cSrcweir case 3: 3485cdf0e10cSrcweir nOptions |= vos::OProcess::TOption_Maximized; 3486cdf0e10cSrcweir break; 3487cdf0e10cSrcweir case 10: 3488cdf0e10cSrcweir nOptions |= vos::OProcess::TOption_FullScreen; 3489cdf0e10cSrcweir break; 3490cdf0e10cSrcweir } 3491cdf0e10cSrcweir 3492cdf0e10cSrcweir sal_Bool bSync = sal_False; 3493cdf0e10cSrcweir if( nArgCount >= 5 ) 3494cdf0e10cSrcweir bSync = rPar.Get(4)->GetBool(); 3495cdf0e10cSrcweir if( bSync ) 3496cdf0e10cSrcweir nOptions |= vos::OProcess::TOption_Wait; 3497cdf0e10cSrcweir } 3498cdf0e10cSrcweir vos::OProcess::TProcessOption eOptions = 3499cdf0e10cSrcweir (vos::OProcess::TProcessOption)nOptions; 3500cdf0e10cSrcweir 3501cdf0e10cSrcweir 3502cdf0e10cSrcweir // #72471 Parameter aufbereiten 3503cdf0e10cSrcweir std::list<String>::const_iterator iter = aTokenList.begin(); 3504cdf0e10cSrcweir const String& rStr = *iter; 3505cdf0e10cSrcweir ::rtl::OUString aOUStrProg( rStr.GetBuffer(), rStr.Len() ); 3506cdf0e10cSrcweir String aOUStrProgUNC = getFullPathUNC( aOUStrProg ); 3507cdf0e10cSrcweir 3508cdf0e10cSrcweir iter++; 3509cdf0e10cSrcweir 3510cdf0e10cSrcweir sal_uInt16 nParamCount = sal::static_int_cast< sal_uInt16 >( 3511cdf0e10cSrcweir aTokenList.size() - 1 ); 3512cdf0e10cSrcweir ::rtl::OUString* pArgumentList = NULL; 3513cdf0e10cSrcweir //const char** pParamList = NULL; 3514cdf0e10cSrcweir if( nParamCount ) 3515cdf0e10cSrcweir { 3516cdf0e10cSrcweir pArgumentList = new ::rtl::OUString[ nParamCount ]; 3517cdf0e10cSrcweir //pParamList = new const char*[ nParamCount ]; 3518cdf0e10cSrcweir sal_uInt16 iList = 0; 3519cdf0e10cSrcweir while( iter != aTokenList.end() ) 3520cdf0e10cSrcweir { 3521cdf0e10cSrcweir const String& rParamStr = (*iter); 3522cdf0e10cSrcweir pArgumentList[iList++] = ::rtl::OUString( rParamStr.GetBuffer(), rParamStr.Len() ); 3523cdf0e10cSrcweir //pParamList[iList++] = (*iter).GetStr(); 3524cdf0e10cSrcweir iter++; 3525cdf0e10cSrcweir } 3526cdf0e10cSrcweir } 3527cdf0e10cSrcweir 3528cdf0e10cSrcweir //const char* pParams = aParams.Len() ? aParams.GetStr() : 0; 3529cdf0e10cSrcweir vos::OProcess* pApp; 3530cdf0e10cSrcweir pApp = new vos::OProcess( aOUStrProgUNC ); 3531cdf0e10cSrcweir sal_Bool bSucc; 3532cdf0e10cSrcweir if( nParamCount == 0 ) 3533cdf0e10cSrcweir { 3534cdf0e10cSrcweir bSucc = pApp->execute( eOptions ) == vos::OProcess::E_None; 3535cdf0e10cSrcweir } 3536cdf0e10cSrcweir else 3537cdf0e10cSrcweir { 3538cdf0e10cSrcweir vos::OArgumentList aArgList( pArgumentList, nParamCount ); 3539cdf0e10cSrcweir bSucc = pApp->execute( eOptions, aArgList ) == vos::OProcess::E_None; 3540cdf0e10cSrcweir } 3541cdf0e10cSrcweir 3542cdf0e10cSrcweir /* 3543cdf0e10cSrcweir if( nParamCount == 0 ) 3544cdf0e10cSrcweir pApp = new vos::OProcess( pProg ); 3545cdf0e10cSrcweir else 3546cdf0e10cSrcweir pApp = new vos::OProcess( pProg, pParamList, nParamCount ); 3547cdf0e10cSrcweir sal_Bool bSucc = pApp->execute( eOptions ) == vos::OProcess::E_None; 3548cdf0e10cSrcweir */ 3549cdf0e10cSrcweir 3550cdf0e10cSrcweir delete pApp; 3551cdf0e10cSrcweir delete[] pArgumentList; 3552cdf0e10cSrcweir if( !bSucc ) 3553cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 3554cdf0e10cSrcweir else 3555cdf0e10cSrcweir rPar.Get(0)->PutLong( 0 ); 3556cdf0e10cSrcweir } 3557cdf0e10cSrcweir } 3558cdf0e10cSrcweir 3559cdf0e10cSrcweir RTLFUNC(VarType) 3560cdf0e10cSrcweir { 3561cdf0e10cSrcweir (void)pBasic; 3562cdf0e10cSrcweir (void)bWrite; 3563cdf0e10cSrcweir 3564cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3565cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3566cdf0e10cSrcweir else 3567cdf0e10cSrcweir { 3568cdf0e10cSrcweir SbxDataType eType = rPar.Get(1)->GetType(); 3569cdf0e10cSrcweir rPar.Get(0)->PutInteger( (sal_Int16)eType ); 3570cdf0e10cSrcweir } 3571cdf0e10cSrcweir } 3572cdf0e10cSrcweir 3573cdf0e10cSrcweir // Exported function 3574cdf0e10cSrcweir String getBasicTypeName( SbxDataType eType ) 3575cdf0e10cSrcweir { 3576cdf0e10cSrcweir static const char* pTypeNames[] = 3577cdf0e10cSrcweir { 3578cdf0e10cSrcweir "Empty", // SbxEMPTY 3579cdf0e10cSrcweir "Null", // SbxNULL 3580cdf0e10cSrcweir "Integer", // SbxINTEGER 3581cdf0e10cSrcweir "Long", // SbxLONG 3582cdf0e10cSrcweir "Single", // SbxSINGLE 3583cdf0e10cSrcweir "Double", // SbxDOUBLE 3584cdf0e10cSrcweir "Currency", // SbxCURRENCY 3585cdf0e10cSrcweir "Date", // SbxDATE 3586cdf0e10cSrcweir "String", // SbxSTRING 3587cdf0e10cSrcweir "Object", // SbxOBJECT 3588cdf0e10cSrcweir "Error", // SbxERROR 3589cdf0e10cSrcweir "Boolean", // SbxBOOL 3590cdf0e10cSrcweir "Variant", // SbxVARIANT 3591cdf0e10cSrcweir "DataObject", // SbxDATAOBJECT 3592cdf0e10cSrcweir "Unknown Type", // 3593cdf0e10cSrcweir "Unknown Type", // 3594cdf0e10cSrcweir "Char", // SbxCHAR 3595cdf0e10cSrcweir "Byte", // SbxBYTE 3596cdf0e10cSrcweir "UShort", // SbxUSHORT 3597cdf0e10cSrcweir "ULong", // SbxULONG 3598cdf0e10cSrcweir "Long64", // SbxLONG64 3599cdf0e10cSrcweir "ULong64", // SbxULONG64 3600cdf0e10cSrcweir "Int", // SbxINT 3601cdf0e10cSrcweir "UInt", // SbxUINT 3602cdf0e10cSrcweir "Void", // SbxVOID 3603cdf0e10cSrcweir "HResult", // SbxHRESULT 3604cdf0e10cSrcweir "Pointer", // SbxPOINTER 3605cdf0e10cSrcweir "DimArray", // SbxDIMARRAY 3606cdf0e10cSrcweir "CArray", // SbxCARRAY 3607cdf0e10cSrcweir "Userdef", // SbxUSERDEF 3608cdf0e10cSrcweir "Lpstr", // SbxLPSTR 3609cdf0e10cSrcweir "Lpwstr", // SbxLPWSTR 3610cdf0e10cSrcweir "Unknown Type", // SbxCoreSTRING 3611cdf0e10cSrcweir "WString", // SbxWSTRING 3612cdf0e10cSrcweir "WChar", // SbxWCHAR 3613cdf0e10cSrcweir "Int64", // SbxSALINT64 3614cdf0e10cSrcweir "UInt64", // SbxSALUINT64 3615cdf0e10cSrcweir "Decimal", // SbxDECIMAL 3616cdf0e10cSrcweir }; 3617cdf0e10cSrcweir 3618cdf0e10cSrcweir int nPos = ((int)eType) & 0x0FFF; 3619cdf0e10cSrcweir sal_uInt16 nTypeNameCount = sizeof( pTypeNames ) / sizeof( char* ); 3620cdf0e10cSrcweir if ( nPos < 0 || nPos >= nTypeNameCount ) 3621cdf0e10cSrcweir nPos = nTypeNameCount - 1; 3622cdf0e10cSrcweir String aRetStr = String::CreateFromAscii( pTypeNames[nPos] ); 3623cdf0e10cSrcweir return aRetStr; 3624cdf0e10cSrcweir } 3625cdf0e10cSrcweir 3626cdf0e10cSrcweir RTLFUNC(TypeName) 3627cdf0e10cSrcweir { 3628cdf0e10cSrcweir (void)pBasic; 3629cdf0e10cSrcweir (void)bWrite; 3630cdf0e10cSrcweir 3631cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3632cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3633cdf0e10cSrcweir else 3634cdf0e10cSrcweir { 3635cdf0e10cSrcweir SbxDataType eType = rPar.Get(1)->GetType(); 3636cdf0e10cSrcweir sal_Bool bIsArray = ( ( eType & SbxARRAY ) != 0 ); 3637cdf0e10cSrcweir String aRetStr = getBasicTypeName( eType ); 3638cdf0e10cSrcweir if( bIsArray ) 3639cdf0e10cSrcweir aRetStr.AppendAscii( "()" ); 3640cdf0e10cSrcweir rPar.Get(0)->PutString( aRetStr ); 3641cdf0e10cSrcweir } 3642cdf0e10cSrcweir } 3643cdf0e10cSrcweir 3644cdf0e10cSrcweir RTLFUNC(Len) 3645cdf0e10cSrcweir { 3646cdf0e10cSrcweir (void)pBasic; 3647cdf0e10cSrcweir (void)bWrite; 3648cdf0e10cSrcweir 3649cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3650cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3651cdf0e10cSrcweir else 3652cdf0e10cSrcweir { 3653cdf0e10cSrcweir const String& rStr = rPar.Get(1)->GetString(); 3654cdf0e10cSrcweir rPar.Get(0)->PutLong( (sal_Int32)rStr.Len() ); 3655cdf0e10cSrcweir } 3656cdf0e10cSrcweir } 3657cdf0e10cSrcweir 3658cdf0e10cSrcweir RTLFUNC(DDEInitiate) 3659cdf0e10cSrcweir { 3660cdf0e10cSrcweir (void)pBasic; 3661cdf0e10cSrcweir (void)bWrite; 3662cdf0e10cSrcweir 3663cdf0e10cSrcweir // No DDE for "virtual" portal users 3664cdf0e10cSrcweir if( needSecurityRestrictions() ) 3665cdf0e10cSrcweir { 3666cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3667cdf0e10cSrcweir return; 3668cdf0e10cSrcweir } 3669cdf0e10cSrcweir 3670cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3671cdf0e10cSrcweir if ( nArgs != 3 ) 3672cdf0e10cSrcweir { 3673cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3674cdf0e10cSrcweir return; 3675cdf0e10cSrcweir } 3676cdf0e10cSrcweir const String& rApp = rPar.Get(1)->GetString(); 3677cdf0e10cSrcweir const String& rTopic = rPar.Get(2)->GetString(); 3678cdf0e10cSrcweir 3679cdf0e10cSrcweir SbiDdeControl* pDDE = pINST->GetDdeControl(); 3680cdf0e10cSrcweir sal_Int16 nChannel; 3681cdf0e10cSrcweir SbError nDdeErr = pDDE->Initiate( rApp, rTopic, nChannel ); 3682cdf0e10cSrcweir if( nDdeErr ) 3683cdf0e10cSrcweir StarBASIC::Error( nDdeErr ); 3684cdf0e10cSrcweir else 3685cdf0e10cSrcweir rPar.Get(0)->PutInteger( nChannel ); 3686cdf0e10cSrcweir } 3687cdf0e10cSrcweir 3688cdf0e10cSrcweir RTLFUNC(DDETerminate) 3689cdf0e10cSrcweir { 3690cdf0e10cSrcweir (void)pBasic; 3691cdf0e10cSrcweir (void)bWrite; 3692cdf0e10cSrcweir 3693cdf0e10cSrcweir // No DDE for "virtual" portal users 3694cdf0e10cSrcweir if( needSecurityRestrictions() ) 3695cdf0e10cSrcweir { 3696cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3697cdf0e10cSrcweir return; 3698cdf0e10cSrcweir } 3699cdf0e10cSrcweir 3700cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 3701cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3702cdf0e10cSrcweir if ( nArgs != 2 ) 3703cdf0e10cSrcweir { 3704cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3705cdf0e10cSrcweir return; 3706cdf0e10cSrcweir } 3707cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3708cdf0e10cSrcweir SbiDdeControl* pDDE = pINST->GetDdeControl(); 3709cdf0e10cSrcweir SbError nDdeErr = pDDE->Terminate( nChannel ); 3710cdf0e10cSrcweir if( nDdeErr ) 3711cdf0e10cSrcweir StarBASIC::Error( nDdeErr ); 3712cdf0e10cSrcweir } 3713cdf0e10cSrcweir 3714cdf0e10cSrcweir RTLFUNC(DDETerminateAll) 3715cdf0e10cSrcweir { 3716cdf0e10cSrcweir (void)pBasic; 3717cdf0e10cSrcweir (void)bWrite; 3718cdf0e10cSrcweir 3719cdf0e10cSrcweir // No DDE for "virtual" portal users 3720cdf0e10cSrcweir if( needSecurityRestrictions() ) 3721cdf0e10cSrcweir { 3722cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3723cdf0e10cSrcweir return; 3724cdf0e10cSrcweir } 3725cdf0e10cSrcweir 3726cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 3727cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3728cdf0e10cSrcweir if ( nArgs != 1 ) 3729cdf0e10cSrcweir { 3730cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3731cdf0e10cSrcweir return; 3732cdf0e10cSrcweir } 3733cdf0e10cSrcweir 3734cdf0e10cSrcweir SbiDdeControl* pDDE = pINST->GetDdeControl(); 3735cdf0e10cSrcweir SbError nDdeErr = pDDE->TerminateAll(); 3736cdf0e10cSrcweir if( nDdeErr ) 3737cdf0e10cSrcweir StarBASIC::Error( nDdeErr ); 3738cdf0e10cSrcweir 3739cdf0e10cSrcweir } 3740cdf0e10cSrcweir 3741cdf0e10cSrcweir RTLFUNC(DDERequest) 3742cdf0e10cSrcweir { 3743cdf0e10cSrcweir (void)pBasic; 3744cdf0e10cSrcweir (void)bWrite; 3745cdf0e10cSrcweir 3746cdf0e10cSrcweir // No DDE for "virtual" portal users 3747cdf0e10cSrcweir if( needSecurityRestrictions() ) 3748cdf0e10cSrcweir { 3749cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3750cdf0e10cSrcweir return; 3751cdf0e10cSrcweir } 3752cdf0e10cSrcweir 3753cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3754cdf0e10cSrcweir if ( nArgs != 3 ) 3755cdf0e10cSrcweir { 3756cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3757cdf0e10cSrcweir return; 3758cdf0e10cSrcweir } 3759cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3760cdf0e10cSrcweir const String& rItem = rPar.Get(2)->GetString(); 3761cdf0e10cSrcweir SbiDdeControl* pDDE = pINST->GetDdeControl(); 3762cdf0e10cSrcweir String aResult; 3763cdf0e10cSrcweir SbError nDdeErr = pDDE->Request( nChannel, rItem, aResult ); 3764cdf0e10cSrcweir if( nDdeErr ) 3765cdf0e10cSrcweir StarBASIC::Error( nDdeErr ); 3766cdf0e10cSrcweir else 3767cdf0e10cSrcweir rPar.Get(0)->PutString( aResult ); 3768cdf0e10cSrcweir } 3769cdf0e10cSrcweir 3770cdf0e10cSrcweir RTLFUNC(DDEExecute) 3771cdf0e10cSrcweir { 3772cdf0e10cSrcweir (void)pBasic; 3773cdf0e10cSrcweir (void)bWrite; 3774cdf0e10cSrcweir 3775cdf0e10cSrcweir // No DDE for "virtual" portal users 3776cdf0e10cSrcweir if( needSecurityRestrictions() ) 3777cdf0e10cSrcweir { 3778cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3779cdf0e10cSrcweir return; 3780cdf0e10cSrcweir } 3781cdf0e10cSrcweir 3782cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 3783cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3784cdf0e10cSrcweir if ( nArgs != 3 ) 3785cdf0e10cSrcweir { 3786cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3787cdf0e10cSrcweir return; 3788cdf0e10cSrcweir } 3789cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3790cdf0e10cSrcweir const String& rCommand = rPar.Get(2)->GetString(); 3791cdf0e10cSrcweir SbiDdeControl* pDDE = pINST->GetDdeControl(); 3792cdf0e10cSrcweir SbError nDdeErr = pDDE->Execute( nChannel, rCommand ); 3793cdf0e10cSrcweir if( nDdeErr ) 3794cdf0e10cSrcweir StarBASIC::Error( nDdeErr ); 3795cdf0e10cSrcweir } 3796cdf0e10cSrcweir 3797cdf0e10cSrcweir RTLFUNC(DDEPoke) 3798cdf0e10cSrcweir { 3799cdf0e10cSrcweir (void)pBasic; 3800cdf0e10cSrcweir (void)bWrite; 3801cdf0e10cSrcweir 3802cdf0e10cSrcweir // No DDE for "virtual" portal users 3803cdf0e10cSrcweir if( needSecurityRestrictions() ) 3804cdf0e10cSrcweir { 3805cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 3806cdf0e10cSrcweir return; 3807cdf0e10cSrcweir } 3808cdf0e10cSrcweir 3809cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 3810cdf0e10cSrcweir int nArgs = (int)rPar.Count(); 3811cdf0e10cSrcweir if ( nArgs != 4 ) 3812cdf0e10cSrcweir { 3813cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3814cdf0e10cSrcweir return; 3815cdf0e10cSrcweir } 3816cdf0e10cSrcweir sal_Int16 nChannel = rPar.Get(1)->GetInteger(); 3817cdf0e10cSrcweir const String& rItem = rPar.Get(2)->GetString(); 3818cdf0e10cSrcweir const String& rData = rPar.Get(3)->GetString(); 3819cdf0e10cSrcweir SbiDdeControl* pDDE = pINST->GetDdeControl(); 3820cdf0e10cSrcweir SbError nDdeErr = pDDE->Poke( nChannel, rItem, rData ); 3821cdf0e10cSrcweir if( nDdeErr ) 3822cdf0e10cSrcweir StarBASIC::Error( nDdeErr ); 3823cdf0e10cSrcweir } 3824cdf0e10cSrcweir 3825cdf0e10cSrcweir 3826cdf0e10cSrcweir RTLFUNC(FreeFile) 3827cdf0e10cSrcweir { 3828cdf0e10cSrcweir (void)pBasic; 3829cdf0e10cSrcweir (void)bWrite; 3830cdf0e10cSrcweir 3831cdf0e10cSrcweir if ( rPar.Count() != 1 ) 3832cdf0e10cSrcweir { 3833cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3834cdf0e10cSrcweir return; 3835cdf0e10cSrcweir } 3836cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 3837cdf0e10cSrcweir short nChannel = 1; 3838cdf0e10cSrcweir while( nChannel < CHANNELS ) 3839cdf0e10cSrcweir { 3840cdf0e10cSrcweir SbiStream* pStrm = pIO->GetStream( nChannel ); 3841cdf0e10cSrcweir if( !pStrm ) 3842cdf0e10cSrcweir { 3843cdf0e10cSrcweir rPar.Get(0)->PutInteger( nChannel ); 3844cdf0e10cSrcweir return; 3845cdf0e10cSrcweir } 3846cdf0e10cSrcweir nChannel++; 3847cdf0e10cSrcweir } 3848cdf0e10cSrcweir StarBASIC::Error( SbERR_TOO_MANY_FILES ); 3849cdf0e10cSrcweir } 3850cdf0e10cSrcweir 3851cdf0e10cSrcweir RTLFUNC(LBound) 3852cdf0e10cSrcweir { 3853cdf0e10cSrcweir (void)pBasic; 3854cdf0e10cSrcweir (void)bWrite; 3855cdf0e10cSrcweir 3856cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 3857cdf0e10cSrcweir if ( nParCount != 3 && nParCount != 2 ) 3858cdf0e10cSrcweir { 3859cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3860cdf0e10cSrcweir return; 3861cdf0e10cSrcweir } 3862cdf0e10cSrcweir SbxBase* pParObj = rPar.Get(1)->GetObject(); 3863cdf0e10cSrcweir SbxDimArray* pArr = PTR_CAST(SbxDimArray,pParObj); 3864cdf0e10cSrcweir if( pArr ) 3865cdf0e10cSrcweir { 3866cdf0e10cSrcweir sal_Int32 nLower, nUpper; 3867cdf0e10cSrcweir short nDim = (nParCount == 3) ? (short)rPar.Get(2)->GetInteger() : 1; 3868cdf0e10cSrcweir if( !pArr->GetDim32( nDim, nLower, nUpper ) ) 3869cdf0e10cSrcweir StarBASIC::Error( SbERR_OUT_OF_RANGE ); 3870cdf0e10cSrcweir else 3871cdf0e10cSrcweir rPar.Get(0)->PutLong( nLower ); 3872cdf0e10cSrcweir } 3873cdf0e10cSrcweir else 3874cdf0e10cSrcweir StarBASIC::Error( SbERR_MUST_HAVE_DIMS ); 3875cdf0e10cSrcweir } 3876cdf0e10cSrcweir 3877cdf0e10cSrcweir RTLFUNC(UBound) 3878cdf0e10cSrcweir { 3879cdf0e10cSrcweir (void)pBasic; 3880cdf0e10cSrcweir (void)bWrite; 3881cdf0e10cSrcweir 3882cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 3883cdf0e10cSrcweir if ( nParCount != 3 && nParCount != 2 ) 3884cdf0e10cSrcweir { 3885cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3886cdf0e10cSrcweir return; 3887cdf0e10cSrcweir } 3888cdf0e10cSrcweir 3889cdf0e10cSrcweir SbxBase* pParObj = rPar.Get(1)->GetObject(); 3890cdf0e10cSrcweir SbxDimArray* pArr = PTR_CAST(SbxDimArray,pParObj); 3891cdf0e10cSrcweir if( pArr ) 3892cdf0e10cSrcweir { 3893cdf0e10cSrcweir sal_Int32 nLower, nUpper; 3894cdf0e10cSrcweir short nDim = (nParCount == 3) ? (short)rPar.Get(2)->GetInteger() : 1; 3895cdf0e10cSrcweir if( !pArr->GetDim32( nDim, nLower, nUpper ) ) 3896cdf0e10cSrcweir StarBASIC::Error( SbERR_OUT_OF_RANGE ); 3897cdf0e10cSrcweir else 3898cdf0e10cSrcweir rPar.Get(0)->PutLong( nUpper ); 3899cdf0e10cSrcweir } 3900cdf0e10cSrcweir else 3901cdf0e10cSrcweir StarBASIC::Error( SbERR_MUST_HAVE_DIMS ); 3902cdf0e10cSrcweir } 3903cdf0e10cSrcweir 3904cdf0e10cSrcweir RTLFUNC(RGB) 3905cdf0e10cSrcweir { 3906cdf0e10cSrcweir (void)pBasic; 3907cdf0e10cSrcweir (void)bWrite; 3908cdf0e10cSrcweir 3909cdf0e10cSrcweir if ( rPar.Count() != 4 ) 3910cdf0e10cSrcweir { 3911cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3912cdf0e10cSrcweir return; 3913cdf0e10cSrcweir } 3914cdf0e10cSrcweir 3915cdf0e10cSrcweir sal_uIntPtr nRed = rPar.Get(1)->GetInteger() & 0xFF; 3916cdf0e10cSrcweir sal_uIntPtr nGreen = rPar.Get(2)->GetInteger() & 0xFF; 3917cdf0e10cSrcweir sal_uIntPtr nBlue = rPar.Get(3)->GetInteger() & 0xFF; 3918cdf0e10cSrcweir sal_uIntPtr nRGB; 3919cdf0e10cSrcweir 3920cdf0e10cSrcweir SbiInstance* pInst = pINST; 3921cdf0e10cSrcweir bool bCompatibility = ( pInst && pInst->IsCompatibility() ); 3922cdf0e10cSrcweir if( bCompatibility ) 3923cdf0e10cSrcweir { 3924cdf0e10cSrcweir nRGB = (nBlue << 16) | (nGreen << 8) | nRed; 3925cdf0e10cSrcweir } 3926cdf0e10cSrcweir else 3927cdf0e10cSrcweir { 3928cdf0e10cSrcweir nRGB = (nRed << 16) | (nGreen << 8) | nBlue; 3929cdf0e10cSrcweir } 3930cdf0e10cSrcweir rPar.Get(0)->PutLong( nRGB ); 3931cdf0e10cSrcweir } 3932cdf0e10cSrcweir 3933cdf0e10cSrcweir RTLFUNC(QBColor) 3934cdf0e10cSrcweir { 3935cdf0e10cSrcweir (void)pBasic; 3936cdf0e10cSrcweir (void)bWrite; 3937cdf0e10cSrcweir 3938cdf0e10cSrcweir static const sal_Int32 pRGB[] = 3939cdf0e10cSrcweir { 3940cdf0e10cSrcweir 0x000000, 3941cdf0e10cSrcweir 0x800000, 3942cdf0e10cSrcweir 0x008000, 3943cdf0e10cSrcweir 0x808000, 3944cdf0e10cSrcweir 0x000080, 3945cdf0e10cSrcweir 0x800080, 3946cdf0e10cSrcweir 0x008080, 3947cdf0e10cSrcweir 0xC0C0C0, 3948cdf0e10cSrcweir 0x808080, 3949cdf0e10cSrcweir 0xFF0000, 3950cdf0e10cSrcweir 0x00FF00, 3951cdf0e10cSrcweir 0xFFFF00, 3952cdf0e10cSrcweir 0x0000FF, 3953cdf0e10cSrcweir 0xFF00FF, 3954cdf0e10cSrcweir 0x00FFFF, 3955cdf0e10cSrcweir 0xFFFFFF, 3956cdf0e10cSrcweir }; 3957cdf0e10cSrcweir 3958cdf0e10cSrcweir if ( rPar.Count() != 2 ) 3959cdf0e10cSrcweir { 3960cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3961cdf0e10cSrcweir return; 3962cdf0e10cSrcweir } 3963cdf0e10cSrcweir 3964cdf0e10cSrcweir sal_Int16 nCol = rPar.Get(1)->GetInteger(); 3965cdf0e10cSrcweir if( nCol < 0 || nCol > 15 ) 3966cdf0e10cSrcweir { 3967cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3968cdf0e10cSrcweir return; 3969cdf0e10cSrcweir } 3970cdf0e10cSrcweir sal_Int32 nRGB = pRGB[ nCol ]; 3971cdf0e10cSrcweir rPar.Get(0)->PutLong( nRGB ); 3972cdf0e10cSrcweir } 3973cdf0e10cSrcweir 3974cdf0e10cSrcweir // StrConv(string, conversion, LCID) 3975cdf0e10cSrcweir RTLFUNC(StrConv) 3976cdf0e10cSrcweir { 3977cdf0e10cSrcweir (void)pBasic; 3978cdf0e10cSrcweir (void)bWrite; 3979cdf0e10cSrcweir 3980cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count()-1; 3981cdf0e10cSrcweir if( nArgCount < 2 || nArgCount > 3 ) 3982cdf0e10cSrcweir { 3983cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 3984cdf0e10cSrcweir return; 3985cdf0e10cSrcweir } 3986cdf0e10cSrcweir 3987cdf0e10cSrcweir String aOldStr = rPar.Get(1)->GetString(); 3988cdf0e10cSrcweir sal_Int32 nConversion = rPar.Get(2)->GetLong(); 3989cdf0e10cSrcweir 3990cdf0e10cSrcweir sal_uInt16 nLanguage = LANGUAGE_SYSTEM; 3991cdf0e10cSrcweir if( nArgCount == 3 ) 3992cdf0e10cSrcweir { 3993cdf0e10cSrcweir // LCID not supported now 3994cdf0e10cSrcweir //nLanguage = rPar.Get(3)->GetInteger(); 3995cdf0e10cSrcweir } 3996cdf0e10cSrcweir 3997cdf0e10cSrcweir sal_uInt16 nOldLen = aOldStr.Len(); 3998cdf0e10cSrcweir if( nOldLen == 0 ) 3999cdf0e10cSrcweir { 4000cdf0e10cSrcweir // null string,return 4001cdf0e10cSrcweir rPar.Get(0)->PutString(aOldStr); 4002cdf0e10cSrcweir return; 4003cdf0e10cSrcweir } 4004cdf0e10cSrcweir 4005cdf0e10cSrcweir sal_Int32 nType = 0; 4006cdf0e10cSrcweir if ( (nConversion & 0x03) == 3 ) // vbProperCase 4007cdf0e10cSrcweir { 4008cdf0e10cSrcweir CharClass& rCharClass = GetCharClass(); 4009cdf0e10cSrcweir aOldStr = rCharClass.toTitle( aOldStr.ToLowerAscii(), 0, nOldLen ); 4010cdf0e10cSrcweir } 4011cdf0e10cSrcweir else if ( (nConversion & 0x01) == 1 ) // vbUpperCase 4012cdf0e10cSrcweir nType |= ::com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE; 4013cdf0e10cSrcweir else if ( (nConversion & 0x02) == 2 ) // vbLowerCase 4014cdf0e10cSrcweir nType |= ::com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE; 4015cdf0e10cSrcweir 4016cdf0e10cSrcweir if ( (nConversion & 0x04) == 4 ) // vbWide 4017cdf0e10cSrcweir nType |= ::com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH; 4018cdf0e10cSrcweir else if ( (nConversion & 0x08) == 8 ) // vbNarrow 4019cdf0e10cSrcweir nType |= ::com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH; 4020cdf0e10cSrcweir 4021cdf0e10cSrcweir if ( (nConversion & 0x10) == 16) // vbKatakana 4022cdf0e10cSrcweir nType |= ::com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA; 4023cdf0e10cSrcweir else if ( (nConversion & 0x20) == 32 ) // vbHiragana 4024cdf0e10cSrcweir nType |= ::com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA; 4025cdf0e10cSrcweir 4026cdf0e10cSrcweir String aNewStr( aOldStr ); 4027cdf0e10cSrcweir if( nType != 0 ) 4028cdf0e10cSrcweir { 4029cdf0e10cSrcweir com::sun::star::uno::Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory(); 4030cdf0e10cSrcweir ::utl::TransliterationWrapper aTransliterationWrapper( xSMgr,nType ); 4031cdf0e10cSrcweir com::sun::star::uno::Sequence<sal_Int32> aOffsets; 4032cdf0e10cSrcweir aTransliterationWrapper.loadModuleIfNeeded( nLanguage ); 4033cdf0e10cSrcweir aNewStr = aTransliterationWrapper.transliterate( aOldStr, nLanguage, 0, nOldLen, &aOffsets ); 4034cdf0e10cSrcweir } 4035cdf0e10cSrcweir 4036cdf0e10cSrcweir if ( (nConversion & 0x40) == 64 ) // vbUnicode 4037cdf0e10cSrcweir { 4038cdf0e10cSrcweir // convert the string to byte string, preserving unicode (2 bytes per character) 4039cdf0e10cSrcweir sal_uInt16 nSize = aNewStr.Len()*2; 4040cdf0e10cSrcweir const sal_Unicode* pSrc = aNewStr.GetBuffer(); 4041cdf0e10cSrcweir sal_Char* pChar = new sal_Char[nSize+1]; 4042cdf0e10cSrcweir for( sal_uInt16 i=0; i < nSize; i++ ) 4043cdf0e10cSrcweir { 4044cdf0e10cSrcweir pChar[i] = static_cast< sal_Char >( i%2 ? ((*pSrc) >> 8) & 0xff : (*pSrc) & 0xff ); 4045cdf0e10cSrcweir if( i%2 ) 4046cdf0e10cSrcweir pSrc++; 4047cdf0e10cSrcweir } 4048cdf0e10cSrcweir pChar[nSize] = '\0'; 4049cdf0e10cSrcweir ::rtl::OString aOStr(pChar); 4050cdf0e10cSrcweir 4051cdf0e10cSrcweir // there is no concept about default codepage in unix. so it is incorrectly in unix 4052cdf0e10cSrcweir ::rtl::OUString aOUStr = ::rtl::OStringToOUString(aOStr, osl_getThreadTextEncoding()); 4053cdf0e10cSrcweir aNewStr = String(aOUStr); 4054cdf0e10cSrcweir rPar.Get(0)->PutString( aNewStr ); 4055cdf0e10cSrcweir return; 4056cdf0e10cSrcweir } 4057cdf0e10cSrcweir else if ( (nConversion & 0x80) == 128 ) // vbFromUnicode 4058cdf0e10cSrcweir { 4059cdf0e10cSrcweir ::rtl::OUString aOUStr(aNewStr); 4060cdf0e10cSrcweir // there is no concept about default codepage in unix. so it is incorrectly in unix 4061cdf0e10cSrcweir ::rtl::OString aOStr = ::rtl::OUStringToOString(aNewStr,osl_getThreadTextEncoding()); 4062cdf0e10cSrcweir const sal_Char* pChar = aOStr.getStr(); 4063cdf0e10cSrcweir sal_uInt16 nArraySize = static_cast< sal_uInt16 >( aOStr.getLength() ); 4064cdf0e10cSrcweir SbxDimArray* pArray = new SbxDimArray(SbxBYTE); 4065cdf0e10cSrcweir bool bIncIndex = (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() ); 4066cdf0e10cSrcweir if(nArraySize) 4067cdf0e10cSrcweir { 4068cdf0e10cSrcweir if( bIncIndex ) 4069cdf0e10cSrcweir pArray->AddDim( 1, nArraySize ); 4070cdf0e10cSrcweir else 4071cdf0e10cSrcweir pArray->AddDim( 0, nArraySize-1 ); 4072cdf0e10cSrcweir } 4073cdf0e10cSrcweir else 4074cdf0e10cSrcweir { 4075cdf0e10cSrcweir pArray->unoAddDim( 0, -1 ); 4076cdf0e10cSrcweir } 4077cdf0e10cSrcweir 4078cdf0e10cSrcweir for( sal_uInt16 i=0; i< nArraySize; i++) 4079cdf0e10cSrcweir { 4080cdf0e10cSrcweir SbxVariable* pNew = new SbxVariable( SbxBYTE ); 4081cdf0e10cSrcweir pNew->PutByte(*pChar); 4082cdf0e10cSrcweir pChar++; 4083cdf0e10cSrcweir pNew->SetFlag( SBX_WRITE ); 4084cdf0e10cSrcweir short index = i; 4085cdf0e10cSrcweir if( bIncIndex ) 4086cdf0e10cSrcweir ++index; 4087cdf0e10cSrcweir pArray->Put( pNew, &index ); 4088cdf0e10cSrcweir } 4089cdf0e10cSrcweir 4090cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 4091cdf0e10cSrcweir sal_uInt16 nFlags = refVar->GetFlags(); 4092cdf0e10cSrcweir refVar->ResetFlag( SBX_FIXED ); 4093cdf0e10cSrcweir refVar->PutObject( pArray ); 4094cdf0e10cSrcweir refVar->SetFlags( nFlags ); 4095cdf0e10cSrcweir refVar->SetParameters( NULL ); 4096cdf0e10cSrcweir return; 4097cdf0e10cSrcweir } 4098cdf0e10cSrcweir 4099cdf0e10cSrcweir rPar.Get(0)->PutString(aNewStr); 4100cdf0e10cSrcweir } 4101cdf0e10cSrcweir 4102cdf0e10cSrcweir 4103cdf0e10cSrcweir RTLFUNC(Beep) 4104cdf0e10cSrcweir { 4105cdf0e10cSrcweir (void)pBasic; 4106cdf0e10cSrcweir (void)bWrite; 4107cdf0e10cSrcweir 4108cdf0e10cSrcweir if ( rPar.Count() != 1 ) 4109cdf0e10cSrcweir { 4110cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4111cdf0e10cSrcweir return; 4112cdf0e10cSrcweir } 4113cdf0e10cSrcweir Sound::Beep(); 4114cdf0e10cSrcweir } 4115cdf0e10cSrcweir 4116cdf0e10cSrcweir RTLFUNC(Load) 4117cdf0e10cSrcweir { 4118cdf0e10cSrcweir (void)pBasic; 4119cdf0e10cSrcweir (void)bWrite; 4120cdf0e10cSrcweir 4121cdf0e10cSrcweir if( rPar.Count() != 2 ) 4122cdf0e10cSrcweir { 4123cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4124cdf0e10cSrcweir return; 4125cdf0e10cSrcweir } 4126cdf0e10cSrcweir 4127cdf0e10cSrcweir // Diesen Call einfach an das Object weiterreichen 4128cdf0e10cSrcweir SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject(); 4129cdf0e10cSrcweir if ( pObj ) 4130cdf0e10cSrcweir { 4131cdf0e10cSrcweir if( pObj->IsA( TYPE( SbUserFormModule ) ) ) 4132cdf0e10cSrcweir { 4133cdf0e10cSrcweir ((SbUserFormModule*)pObj)->Load(); 4134cdf0e10cSrcweir } 4135cdf0e10cSrcweir else if( pObj->IsA( TYPE( SbxObject ) ) ) 4136cdf0e10cSrcweir { 4137cdf0e10cSrcweir SbxVariable* pVar = ((SbxObject*)pObj)-> 4138cdf0e10cSrcweir Find( String( RTL_CONSTASCII_USTRINGPARAM("Load") ), SbxCLASS_METHOD ); 4139cdf0e10cSrcweir if( pVar ) 4140cdf0e10cSrcweir pVar->GetInteger(); 4141cdf0e10cSrcweir } 4142cdf0e10cSrcweir } 4143cdf0e10cSrcweir } 4144cdf0e10cSrcweir 4145cdf0e10cSrcweir RTLFUNC(Unload) 4146cdf0e10cSrcweir { 4147cdf0e10cSrcweir (void)pBasic; 4148cdf0e10cSrcweir (void)bWrite; 4149cdf0e10cSrcweir 4150cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 4151cdf0e10cSrcweir if( rPar.Count() != 2 ) 4152cdf0e10cSrcweir { 4153cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4154cdf0e10cSrcweir return; 4155cdf0e10cSrcweir } 4156cdf0e10cSrcweir 4157cdf0e10cSrcweir // Diesen Call einfach an das Object weitereichen 4158cdf0e10cSrcweir SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject(); 4159cdf0e10cSrcweir if ( pObj ) 4160cdf0e10cSrcweir { 4161cdf0e10cSrcweir if( pObj->IsA( TYPE( SbUserFormModule ) ) ) 4162cdf0e10cSrcweir { 4163cdf0e10cSrcweir SbUserFormModule* pFormModule = ( SbUserFormModule* )pObj; 4164cdf0e10cSrcweir pFormModule->Unload(); 4165cdf0e10cSrcweir } 4166cdf0e10cSrcweir else if( pObj->IsA( TYPE( SbxObject ) ) ) 4167cdf0e10cSrcweir { 4168cdf0e10cSrcweir SbxVariable* pVar = ((SbxObject*)pObj)-> 4169cdf0e10cSrcweir Find( String( RTL_CONSTASCII_USTRINGPARAM("Unload") ), SbxCLASS_METHOD ); 4170cdf0e10cSrcweir if( pVar ) 4171cdf0e10cSrcweir pVar->GetInteger(); 4172cdf0e10cSrcweir } 4173cdf0e10cSrcweir } 4174cdf0e10cSrcweir } 4175cdf0e10cSrcweir 4176cdf0e10cSrcweir RTLFUNC(LoadPicture) 4177cdf0e10cSrcweir { 4178cdf0e10cSrcweir (void)pBasic; 4179cdf0e10cSrcweir (void)bWrite; 4180cdf0e10cSrcweir 4181cdf0e10cSrcweir if( rPar.Count() != 2 ) 4182cdf0e10cSrcweir { 4183cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4184cdf0e10cSrcweir return; 4185cdf0e10cSrcweir } 4186cdf0e10cSrcweir 4187cdf0e10cSrcweir String aFileURL = getFullPath( rPar.Get(1)->GetString() ); 4188cdf0e10cSrcweir SvStream* pStream = utl::UcbStreamHelper::CreateStream( aFileURL, STREAM_READ ); 4189cdf0e10cSrcweir if( pStream != NULL ) 4190cdf0e10cSrcweir { 4191cdf0e10cSrcweir Bitmap aBmp; 4192cdf0e10cSrcweir *pStream >> aBmp; 4193cdf0e10cSrcweir Graphic aGraphic( aBmp ); 4194cdf0e10cSrcweir 4195cdf0e10cSrcweir SbxObjectRef xRef = new SbStdPicture; 4196cdf0e10cSrcweir ((SbStdPicture*)(SbxObject*)xRef)->SetGraphic( aGraphic ); 4197cdf0e10cSrcweir rPar.Get(0)->PutObject( xRef ); 4198cdf0e10cSrcweir } 4199cdf0e10cSrcweir delete pStream; 4200cdf0e10cSrcweir } 4201cdf0e10cSrcweir 4202cdf0e10cSrcweir RTLFUNC(SavePicture) 4203cdf0e10cSrcweir { 4204cdf0e10cSrcweir (void)pBasic; 4205cdf0e10cSrcweir (void)bWrite; 4206cdf0e10cSrcweir 4207cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 4208cdf0e10cSrcweir if( rPar.Count() != 3 ) 4209cdf0e10cSrcweir { 4210cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4211cdf0e10cSrcweir return; 4212cdf0e10cSrcweir } 4213cdf0e10cSrcweir 4214cdf0e10cSrcweir SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject(); 4215cdf0e10cSrcweir if( pObj->IsA( TYPE( SbStdPicture ) ) ) 4216cdf0e10cSrcweir { 4217cdf0e10cSrcweir SvFileStream aOStream( rPar.Get(2)->GetString(), STREAM_WRITE | STREAM_TRUNC ); 4218cdf0e10cSrcweir Graphic aGraphic = ((SbStdPicture*)pObj)->GetGraphic(); 4219cdf0e10cSrcweir aOStream << aGraphic; 4220cdf0e10cSrcweir } 4221cdf0e10cSrcweir } 4222cdf0e10cSrcweir 4223cdf0e10cSrcweir 4224cdf0e10cSrcweir //----------------------------------------------------------------------------------------- 4225cdf0e10cSrcweir 4226cdf0e10cSrcweir RTLFUNC(AboutStarBasic) 4227cdf0e10cSrcweir { 4228cdf0e10cSrcweir (void)pBasic; 4229cdf0e10cSrcweir (void)bWrite; 4230cdf0e10cSrcweir (void)rPar; 4231cdf0e10cSrcweir } 4232cdf0e10cSrcweir 4233cdf0e10cSrcweir RTLFUNC(MsgBox) 4234cdf0e10cSrcweir { 4235cdf0e10cSrcweir (void)pBasic; 4236cdf0e10cSrcweir (void)bWrite; 4237cdf0e10cSrcweir 4238cdf0e10cSrcweir static const WinBits nStyleMap[] = 4239cdf0e10cSrcweir { 4240cdf0e10cSrcweir WB_OK, // MB_OK 4241cdf0e10cSrcweir WB_OK_CANCEL, // MB_OKCANCEL 4242cdf0e10cSrcweir WB_ABORT_RETRY_IGNORE, // MB_ABORTRETRYIGNORE 4243cdf0e10cSrcweir WB_YES_NO_CANCEL, // MB_YESNOCANCEL 4244cdf0e10cSrcweir WB_YES_NO, // MB_YESNO 4245cdf0e10cSrcweir WB_RETRY_CANCEL // MB_RETRYCANCEL 4246cdf0e10cSrcweir }; 4247cdf0e10cSrcweir static const sal_Int16 nButtonMap[] = 4248cdf0e10cSrcweir { 4249cdf0e10cSrcweir 2, // #define RET_CANCEL sal_False 4250cdf0e10cSrcweir 1, // #define RET_OK sal_True 4251cdf0e10cSrcweir 6, // #define RET_YES 2 4252cdf0e10cSrcweir 7, // #define RET_NO 3 4253cdf0e10cSrcweir 4 // #define RET_RETRY 4 4254cdf0e10cSrcweir }; 4255cdf0e10cSrcweir 4256cdf0e10cSrcweir 4257cdf0e10cSrcweir sal_uInt16 nArgCount = (sal_uInt16)rPar.Count(); 4258cdf0e10cSrcweir if( nArgCount < 2 || nArgCount > 6 ) 4259cdf0e10cSrcweir { 4260cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4261cdf0e10cSrcweir return; 4262cdf0e10cSrcweir } 4263cdf0e10cSrcweir WinBits nWinBits; 4264cdf0e10cSrcweir WinBits nType = 0; // MB_OK 4265cdf0e10cSrcweir if( nArgCount >= 3 ) 4266cdf0e10cSrcweir nType = (WinBits)rPar.Get(2)->GetInteger(); 4267cdf0e10cSrcweir WinBits nStyle = nType; 4268cdf0e10cSrcweir nStyle &= 15; // Bits 4-16 loeschen 4269cdf0e10cSrcweir if( nStyle > 5 ) 4270cdf0e10cSrcweir nStyle = 0; 4271cdf0e10cSrcweir 4272cdf0e10cSrcweir nWinBits = nStyleMap[ nStyle ]; 4273cdf0e10cSrcweir 4274cdf0e10cSrcweir WinBits nWinDefBits; 4275cdf0e10cSrcweir nWinDefBits = (WB_DEF_OK | WB_DEF_RETRY | WB_DEF_YES); 4276cdf0e10cSrcweir if( nType & 256 ) 4277cdf0e10cSrcweir { 4278cdf0e10cSrcweir if( nStyle == 5 ) 4279cdf0e10cSrcweir nWinDefBits = WB_DEF_CANCEL; 4280cdf0e10cSrcweir else if( nStyle == 2 ) 4281cdf0e10cSrcweir nWinDefBits = WB_DEF_RETRY; 4282cdf0e10cSrcweir else 4283cdf0e10cSrcweir nWinDefBits = (WB_DEF_CANCEL | WB_DEF_RETRY | WB_DEF_NO); 4284cdf0e10cSrcweir } 4285cdf0e10cSrcweir else if( nType & 512 ) 4286cdf0e10cSrcweir { 4287cdf0e10cSrcweir if( nStyle == 2) 4288cdf0e10cSrcweir nWinDefBits = WB_DEF_IGNORE; 4289cdf0e10cSrcweir else 4290cdf0e10cSrcweir nWinDefBits = WB_DEF_CANCEL; 4291cdf0e10cSrcweir } 4292cdf0e10cSrcweir else if( nStyle == 2) 4293cdf0e10cSrcweir nWinDefBits = WB_DEF_CANCEL; 4294cdf0e10cSrcweir nWinBits |= nWinDefBits; 4295cdf0e10cSrcweir 4296cdf0e10cSrcweir String aMsg = rPar.Get(1)->GetString(); 4297cdf0e10cSrcweir String aTitle; 4298cdf0e10cSrcweir if( nArgCount >= 4 ) 4299cdf0e10cSrcweir aTitle = rPar.Get(3)->GetString(); 4300cdf0e10cSrcweir else 4301cdf0e10cSrcweir aTitle = GetpApp()->GetAppName(); 4302cdf0e10cSrcweir 4303cdf0e10cSrcweir nType &= (16+32+64); 4304cdf0e10cSrcweir MessBox* pBox = 0; 4305cdf0e10cSrcweir Window* pParent = GetpApp()->GetDefDialogParent(); 4306cdf0e10cSrcweir switch( nType ) 4307cdf0e10cSrcweir { 4308cdf0e10cSrcweir case 16: 4309cdf0e10cSrcweir pBox = new ErrorBox( pParent, nWinBits, aMsg ); 4310cdf0e10cSrcweir break; 4311cdf0e10cSrcweir case 32: 4312cdf0e10cSrcweir pBox = new QueryBox( pParent, nWinBits, aMsg ); 4313cdf0e10cSrcweir break; 4314cdf0e10cSrcweir case 48: 4315cdf0e10cSrcweir pBox = new WarningBox( pParent, nWinBits, aMsg ); 4316cdf0e10cSrcweir break; 4317cdf0e10cSrcweir case 64: 4318cdf0e10cSrcweir pBox = new InfoBox( pParent, aMsg ); 4319cdf0e10cSrcweir break; 4320cdf0e10cSrcweir default: 4321cdf0e10cSrcweir pBox = new MessBox( pParent, nWinBits, aTitle, aMsg ); 4322cdf0e10cSrcweir } 4323cdf0e10cSrcweir pBox->SetText( aTitle ); 4324cdf0e10cSrcweir sal_uInt16 nRet = (sal_uInt16)pBox->Execute(); 4325cdf0e10cSrcweir if( nRet == sal_True ) 4326cdf0e10cSrcweir nRet = 1; 4327cdf0e10cSrcweir 4328cdf0e10cSrcweir sal_Int16 nMappedRet; 4329cdf0e10cSrcweir if( nStyle == 2 ) 4330cdf0e10cSrcweir { 4331cdf0e10cSrcweir nMappedRet = nRet; 4332cdf0e10cSrcweir if( nMappedRet == 0 ) 4333cdf0e10cSrcweir nMappedRet = 3; // Abort 4334cdf0e10cSrcweir } 4335cdf0e10cSrcweir else 4336cdf0e10cSrcweir nMappedRet = nButtonMap[ nRet ]; 4337cdf0e10cSrcweir 4338cdf0e10cSrcweir rPar.Get(0)->PutInteger( nMappedRet ); 4339cdf0e10cSrcweir delete pBox; 4340cdf0e10cSrcweir } 4341cdf0e10cSrcweir 4342cdf0e10cSrcweir RTLFUNC(SetAttr) // JSM 4343cdf0e10cSrcweir { 4344cdf0e10cSrcweir (void)pBasic; 4345cdf0e10cSrcweir (void)bWrite; 4346cdf0e10cSrcweir 4347cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 4348cdf0e10cSrcweir if ( rPar.Count() == 3 ) 4349cdf0e10cSrcweir { 4350cdf0e10cSrcweir String aStr = rPar.Get(1)->GetString(); 4351cdf0e10cSrcweir sal_Int16 nFlags = rPar.Get(2)->GetInteger(); 4352cdf0e10cSrcweir 4353cdf0e10cSrcweir // <-- UCB 4354cdf0e10cSrcweir if( hasUno() ) 4355cdf0e10cSrcweir { 4356cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 4357cdf0e10cSrcweir if( xSFI.is() ) 4358cdf0e10cSrcweir { 4359cdf0e10cSrcweir try 4360cdf0e10cSrcweir { 4361cdf0e10cSrcweir sal_Bool bReadOnly = (nFlags & 0x0001) != 0; // ATTR_READONLY 4362cdf0e10cSrcweir xSFI->setReadOnly( aStr, bReadOnly ); 4363cdf0e10cSrcweir sal_Bool bHidden = (nFlags & 0x0002) != 0; // ATTR_HIDDEN 4364cdf0e10cSrcweir xSFI->setHidden( aStr, bHidden ); 4365cdf0e10cSrcweir } 4366cdf0e10cSrcweir catch( Exception & ) 4367cdf0e10cSrcweir { 4368cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 4369cdf0e10cSrcweir } 4370cdf0e10cSrcweir } 4371cdf0e10cSrcweir } 4372cdf0e10cSrcweir else 4373cdf0e10cSrcweir // --> UCB 4374cdf0e10cSrcweir { 4375cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 4376cdf0e10cSrcweir // #57064 Bei virtuellen URLs den Real-Path extrahieren 4377cdf0e10cSrcweir DirEntry aEntry( aStr ); 4378cdf0e10cSrcweir String aFile = aEntry.GetFull(); 4379cdf0e10cSrcweir ByteString aByteFile( aFile, gsl_getSystemTextEncoding() ); 4380cdf0e10cSrcweir #ifdef WNT 4381cdf0e10cSrcweir if (!SetFileAttributes (aByteFile.GetBuffer(),(DWORD)nFlags)) 4382cdf0e10cSrcweir StarBASIC::Error(SbERR_FILE_NOT_FOUND); 4383cdf0e10cSrcweir #endif 4384cdf0e10cSrcweir #ifdef OS2 4385cdf0e10cSrcweir FILESTATUS3 aFileStatus; 4386cdf0e10cSrcweir APIRET rc = DosQueryPathInfo(aByteFile.GetBuffer(),1, 4387cdf0e10cSrcweir &aFileStatus,sizeof(FILESTATUS3)); 4388cdf0e10cSrcweir if (!rc) 4389cdf0e10cSrcweir { 4390cdf0e10cSrcweir if (aFileStatus.attrFile != nFlags) 4391cdf0e10cSrcweir { 4392cdf0e10cSrcweir aFileStatus.attrFile = nFlags; 4393cdf0e10cSrcweir rc = DosSetPathInfo(aFile.GetStr(),1, 4394cdf0e10cSrcweir &aFileStatus,sizeof(FILESTATUS3),0); 4395cdf0e10cSrcweir if (rc) 4396cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 4397cdf0e10cSrcweir } 4398cdf0e10cSrcweir } 4399cdf0e10cSrcweir else 4400cdf0e10cSrcweir StarBASIC::Error( SbERR_FILE_NOT_FOUND ); 4401cdf0e10cSrcweir #endif 4402cdf0e10cSrcweir #else 4403cdf0e10cSrcweir // Not implemented 4404cdf0e10cSrcweir #endif 4405cdf0e10cSrcweir } 4406cdf0e10cSrcweir } 4407cdf0e10cSrcweir else 4408cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4409cdf0e10cSrcweir } 4410cdf0e10cSrcweir 4411cdf0e10cSrcweir RTLFUNC(Reset) // JSM 4412cdf0e10cSrcweir { 4413cdf0e10cSrcweir (void)pBasic; 4414cdf0e10cSrcweir (void)bWrite; 4415cdf0e10cSrcweir (void)rPar; 4416cdf0e10cSrcweir 4417cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 4418cdf0e10cSrcweir if (pIO) 4419cdf0e10cSrcweir pIO->CloseAll(); 4420cdf0e10cSrcweir } 4421cdf0e10cSrcweir 4422cdf0e10cSrcweir RTLFUNC(DumpAllObjects) 4423cdf0e10cSrcweir { 4424cdf0e10cSrcweir (void)pBasic; 4425cdf0e10cSrcweir (void)bWrite; 4426cdf0e10cSrcweir 4427cdf0e10cSrcweir sal_uInt16 nArgCount = (sal_uInt16)rPar.Count(); 4428cdf0e10cSrcweir if( nArgCount < 2 || nArgCount > 3 ) 4429cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4430cdf0e10cSrcweir else if( !pBasic ) 4431cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 4432cdf0e10cSrcweir else 4433cdf0e10cSrcweir { 4434cdf0e10cSrcweir SbxObject* p = pBasic; 4435cdf0e10cSrcweir while( p->GetParent() ) 4436cdf0e10cSrcweir p = p->GetParent(); 4437cdf0e10cSrcweir SvFileStream aStrm( rPar.Get( 1 )->GetString(), 4438cdf0e10cSrcweir STREAM_WRITE | STREAM_TRUNC ); 4439cdf0e10cSrcweir p->Dump( aStrm, rPar.Get( 2 )->GetBool() ); 4440cdf0e10cSrcweir aStrm.Close(); 4441cdf0e10cSrcweir if( aStrm.GetError() != SVSTREAM_OK ) 4442cdf0e10cSrcweir StarBASIC::Error( SbERR_IO_ERROR ); 4443cdf0e10cSrcweir } 4444cdf0e10cSrcweir } 4445cdf0e10cSrcweir 4446cdf0e10cSrcweir 4447cdf0e10cSrcweir RTLFUNC(FileExists) 4448cdf0e10cSrcweir { 4449cdf0e10cSrcweir (void)pBasic; 4450cdf0e10cSrcweir (void)bWrite; 4451cdf0e10cSrcweir 4452cdf0e10cSrcweir if ( rPar.Count() == 2 ) 4453cdf0e10cSrcweir { 4454cdf0e10cSrcweir String aStr = rPar.Get(1)->GetString(); 4455cdf0e10cSrcweir sal_Bool bExists = sal_False; 4456cdf0e10cSrcweir 4457cdf0e10cSrcweir // <-- UCB 4458cdf0e10cSrcweir if( hasUno() ) 4459cdf0e10cSrcweir { 4460cdf0e10cSrcweir com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); 4461cdf0e10cSrcweir if( xSFI.is() ) 4462cdf0e10cSrcweir { 4463cdf0e10cSrcweir try 4464cdf0e10cSrcweir { 4465cdf0e10cSrcweir bExists = xSFI->exists( aStr ); 4466cdf0e10cSrcweir } 4467cdf0e10cSrcweir catch( Exception & ) 4468cdf0e10cSrcweir { 4469cdf0e10cSrcweir StarBASIC::Error( ERRCODE_IO_GENERAL ); 4470cdf0e10cSrcweir } 4471cdf0e10cSrcweir } 4472cdf0e10cSrcweir } 4473cdf0e10cSrcweir else 4474cdf0e10cSrcweir // --> UCB 4475cdf0e10cSrcweir { 4476cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL 4477cdf0e10cSrcweir DirEntry aEntry( aStr ); 4478cdf0e10cSrcweir bExists = aEntry.Exists(); 4479cdf0e10cSrcweir #else 4480cdf0e10cSrcweir DirectoryItem aItem; 4481cdf0e10cSrcweir FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( aStr ), aItem ); 4482cdf0e10cSrcweir bExists = (nRet == FileBase::E_None); 4483cdf0e10cSrcweir #endif 4484cdf0e10cSrcweir } 4485cdf0e10cSrcweir rPar.Get(0)->PutBool( bExists ); 4486cdf0e10cSrcweir } 4487cdf0e10cSrcweir else 4488cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4489cdf0e10cSrcweir } 4490cdf0e10cSrcweir 4491cdf0e10cSrcweir RTLFUNC(Partition) 4492cdf0e10cSrcweir { 4493cdf0e10cSrcweir (void)pBasic; 4494cdf0e10cSrcweir (void)bWrite; 4495cdf0e10cSrcweir 4496cdf0e10cSrcweir if ( rPar.Count() != 5 ) 4497cdf0e10cSrcweir { 4498cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4499cdf0e10cSrcweir return; 4500cdf0e10cSrcweir } 4501cdf0e10cSrcweir 4502cdf0e10cSrcweir sal_Int32 nNumber = rPar.Get(1)->GetLong(); 4503cdf0e10cSrcweir sal_Int32 nStart = rPar.Get(2)->GetLong(); 4504cdf0e10cSrcweir sal_Int32 nStop = rPar.Get(3)->GetLong(); 4505cdf0e10cSrcweir sal_Int32 nInterval = rPar.Get(4)->GetLong(); 4506cdf0e10cSrcweir 4507cdf0e10cSrcweir if( nStart < 0 || nStop <= nStart || nInterval < 1 ) 4508cdf0e10cSrcweir { 4509cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 4510cdf0e10cSrcweir return; 4511cdf0e10cSrcweir } 4512cdf0e10cSrcweir 4513cdf0e10cSrcweir // the Partition function inserts leading spaces before lowervalue and uppervalue 4514cdf0e10cSrcweir // so that they both have the same number of characters as the string 4515cdf0e10cSrcweir // representation of the value (Stop + 1). This ensures that if you use the output 4516cdf0e10cSrcweir // of the Partition function with several values of Number, the resulting text 4517cdf0e10cSrcweir // will be handled properly during any subsequent sort operation. 4518cdf0e10cSrcweir 4519cdf0e10cSrcweir // calculate the maximun number of characters before lowervalue and uppervalue 4520cdf0e10cSrcweir ::rtl::OUString aBeforeStart = ::rtl::OUString::valueOf( nStart - 1 ); 4521cdf0e10cSrcweir ::rtl::OUString aAfterStop = ::rtl::OUString::valueOf( nStop + 1 ); 4522cdf0e10cSrcweir sal_Int32 nLen1 = aBeforeStart.getLength(); 4523cdf0e10cSrcweir sal_Int32 nLen2 = aAfterStop.getLength(); 4524cdf0e10cSrcweir sal_Int32 nLen = nLen1 >= nLen2 ? nLen1:nLen2; 4525cdf0e10cSrcweir 4526cdf0e10cSrcweir ::rtl::OUStringBuffer aRetStr( nLen * 2 + 1); 4527cdf0e10cSrcweir ::rtl::OUString aLowerValue; 4528cdf0e10cSrcweir ::rtl::OUString aUpperValue; 4529cdf0e10cSrcweir if( nNumber < nStart ) 4530cdf0e10cSrcweir { 4531cdf0e10cSrcweir aUpperValue = aBeforeStart; 4532cdf0e10cSrcweir } 4533cdf0e10cSrcweir else if( nNumber > nStop ) 4534cdf0e10cSrcweir { 4535cdf0e10cSrcweir aLowerValue = aAfterStop; 4536cdf0e10cSrcweir } 4537cdf0e10cSrcweir else 4538cdf0e10cSrcweir { 4539cdf0e10cSrcweir sal_Int32 nLowerValue = nNumber; 4540cdf0e10cSrcweir sal_Int32 nUpperValue = nLowerValue; 4541cdf0e10cSrcweir if( nInterval > 1 ) 4542cdf0e10cSrcweir { 4543cdf0e10cSrcweir nLowerValue = ((( nNumber - nStart ) / nInterval ) * nInterval ) + nStart; 4544cdf0e10cSrcweir nUpperValue = nLowerValue + nInterval - 1; 4545cdf0e10cSrcweir } 4546cdf0e10cSrcweir 4547cdf0e10cSrcweir aLowerValue = ::rtl::OUString::valueOf( nLowerValue ); 4548cdf0e10cSrcweir aUpperValue = ::rtl::OUString::valueOf( nUpperValue ); 4549cdf0e10cSrcweir } 4550cdf0e10cSrcweir 4551cdf0e10cSrcweir nLen1 = aLowerValue.getLength(); 4552cdf0e10cSrcweir nLen2 = aUpperValue.getLength(); 4553cdf0e10cSrcweir 4554cdf0e10cSrcweir if( nLen > nLen1 ) 4555cdf0e10cSrcweir { 4556cdf0e10cSrcweir // appending the leading spaces for the lowervalue 4557cdf0e10cSrcweir for ( sal_Int32 i= (nLen - nLen1) ; i > 0; --i ) 4558cdf0e10cSrcweir aRetStr.appendAscii(" "); 4559cdf0e10cSrcweir } 4560cdf0e10cSrcweir aRetStr.append( aLowerValue ).appendAscii(":"); 4561cdf0e10cSrcweir if( nLen > nLen2 ) 4562cdf0e10cSrcweir { 4563cdf0e10cSrcweir // appending the leading spaces for the uppervalue 4564cdf0e10cSrcweir for ( sal_Int32 i= (nLen - nLen2) ; i > 0; --i ) 4565cdf0e10cSrcweir aRetStr.appendAscii(" "); 4566cdf0e10cSrcweir } 4567cdf0e10cSrcweir aRetStr.append( aUpperValue ); 4568cdf0e10cSrcweir rPar.Get(0)->PutString( String(aRetStr.makeStringAndClear()) ); 4569cdf0e10cSrcweir } 4570