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