xref: /trunk/main/basic/source/runtime/methods.cxx (revision 0848378beb0d0fcd9a9bf3cafa6204dbc20d39f7)
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
10cdf0e10cSrcweir  *
11e1f63238SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
118cdf0e10cSrcweir static void FilterWhiteSpace( String& rStr )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     rStr.EraseAllChars( ' ' );
121cdf0e10cSrcweir     rStr.EraseAllChars( '\t' );
122cdf0e10cSrcweir     rStr.EraseAllChars( '\n' );
123cdf0e10cSrcweir     rStr.EraseAllChars( '\r' );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
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 
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 
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
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 
172*0848378bSHerbert 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
181cdf0e10cSrcweir void implChDir( const String& aDir )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     (void)aDir;
184cdf0e10cSrcweir     // TODO
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // Sets (virtual) current drive for UCB file access
188cdf0e10cSrcweir void implChDrive( const String& aDrive )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     (void)aDrive;
191cdf0e10cSrcweir     // TODO
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // Returns (virtual) current path for UCB file access
195cdf0e10cSrcweir String implGetCurDir( void )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     String aRetStr;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     return aRetStr;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // TODO: -> SbiGlobals
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 
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 
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() );
286*0848378bSHerbert 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 
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 
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 
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 
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 
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 
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 
406cdf0e10cSrcweir RTLFUNC(Chr)
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     (void)pBasic;
409cdf0e10cSrcweir     (void)bWrite;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     bool bChrW = false;
412cdf0e10cSrcweir     implChr( rPar, bChrW );
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
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 
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 
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 
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
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
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 
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 
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 
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
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 );
1442cdf0e10cSrcweir                     nPos = nPos - nFindStrLen + nReplaceStrLen + 1;
1443cdf0e10cSrcweir                     nCounts++;
1444cdf0e10cSrcweir                 }
1445cdf0e10cSrcweir                 else
1446cdf0e10cSrcweir                 {
1447cdf0e10cSrcweir                     break;
1448cdf0e10cSrcweir                 }
1449cdf0e10cSrcweir             }
1450cdf0e10cSrcweir         }
1451cdf0e10cSrcweir         rPar.Get(0)->PutString( aExpStr.Copy( static_cast<sal_uInt16>(lStartPos - 1) )  );
1452cdf0e10cSrcweir     }
1453cdf0e10cSrcweir }
1454cdf0e10cSrcweir 
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 
1484cdf0e10cSrcweir RTLFUNC(RTL)
1485cdf0e10cSrcweir {
1486cdf0e10cSrcweir     (void)pBasic;
1487cdf0e10cSrcweir     (void)bWrite;
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir     rPar.Get( 0 )->PutObject( pBasic->getRTL() );
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir 
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 
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 
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 
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 
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 
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 
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 
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 
1711cdf0e10cSrcweir RTLFUNC(Tan)
1712cdf0e10cSrcweir {
1713cdf0e10cSrcweir     (void)pBasic;
1714cdf0e10cSrcweir     (void)bWrite;
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir     if ( rPar.Count() < 2 )
1717cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1718cdf0e10cSrcweir     else
1719cdf0e10cSrcweir     {
1720cdf0e10cSrcweir         SbxVariableRef pArg = rPar.Get( 1 );
1721cdf0e10cSrcweir         rPar.Get( 0 )->PutDouble( tan( pArg->GetDouble() ) );
1722cdf0e10cSrcweir     }
1723cdf0e10cSrcweir }
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir RTLFUNC(UCase)
1726cdf0e10cSrcweir {
1727cdf0e10cSrcweir     (void)pBasic;
1728cdf0e10cSrcweir     (void)bWrite;
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir     if ( rPar.Count() < 2 )
1731cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1732cdf0e10cSrcweir     else
1733cdf0e10cSrcweir     {
1734cdf0e10cSrcweir         CharClass& rCharClass = GetCharClass();
1735cdf0e10cSrcweir         String aStr( rPar.Get(1)->GetString() );
1736cdf0e10cSrcweir         rCharClass.toUpper( aStr );
1737cdf0e10cSrcweir         rPar.Get(0)->PutString( aStr );
1738cdf0e10cSrcweir     }
1739cdf0e10cSrcweir }
1740cdf0e10cSrcweir 
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir RTLFUNC(Val)
1743cdf0e10cSrcweir {
1744cdf0e10cSrcweir     (void)pBasic;
1745cdf0e10cSrcweir     (void)bWrite;
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir     if ( rPar.Count() < 2 )
1748cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1749cdf0e10cSrcweir     else
1750cdf0e10cSrcweir     {
1751cdf0e10cSrcweir         double nResult = 0.0;
1752cdf0e10cSrcweir         char* pEndPtr;
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir         String aStr( rPar.Get(1)->GetString() );
1755cdf0e10cSrcweir // lt. Mikkysoft bei Kommas abbrechen!
1756cdf0e10cSrcweir //      for( sal_uInt16 n=0; n < aStr.Len(); n++ )
1757cdf0e10cSrcweir //          if( aStr[n] == ',' ) aStr[n] = '.';
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir         FilterWhiteSpace( aStr );
1760cdf0e10cSrcweir         if ( aStr.GetBuffer()[0] == '&' && aStr.Len() > 1 )
1761cdf0e10cSrcweir         {
1762cdf0e10cSrcweir             int nRadix = 10;
1763cdf0e10cSrcweir             char aChar = (char)aStr.GetBuffer()[1];
1764cdf0e10cSrcweir             if ( aChar == 'h' || aChar == 'H' )
1765cdf0e10cSrcweir                 nRadix = 16;
1766cdf0e10cSrcweir             else if ( aChar == 'o' || aChar == 'O' )
1767cdf0e10cSrcweir                 nRadix = 8;
1768cdf0e10cSrcweir             if ( nRadix != 10 )
1769cdf0e10cSrcweir             {
1770cdf0e10cSrcweir                 ByteString aByteStr( aStr, gsl_getSystemTextEncoding() );
1771cdf0e10cSrcweir                 sal_Int16 nlResult = (sal_Int16)strtol( aByteStr.GetBuffer()+2, &pEndPtr, nRadix);
1772cdf0e10cSrcweir                 nResult = (double)nlResult;
1773cdf0e10cSrcweir             }
1774cdf0e10cSrcweir         }
1775cdf0e10cSrcweir         else
1776cdf0e10cSrcweir         {
1777cdf0e10cSrcweir             // #57844 Lokalisierte Funktion benutzen
1778cdf0e10cSrcweir             nResult = ::rtl::math::stringToDouble( aStr, '.', ',', NULL, NULL );
1779cdf0e10cSrcweir             checkArithmeticOverflow( nResult );
1780cdf0e10cSrcweir             // ATL: nResult = strtod( aStr.GetStr(), &pEndPtr );
1781cdf0e10cSrcweir         }
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir         rPar.Get(0)->PutDouble( nResult );
1784cdf0e10cSrcweir     }
1785cdf0e10cSrcweir }
1786cdf0e10cSrcweir 
1787cdf0e10cSrcweir 
1788cdf0e10cSrcweir // Helper functions for date conversion
1789cdf0e10cSrcweir sal_Int16 implGetDateDay( double aDate )
1790cdf0e10cSrcweir {
1791cdf0e10cSrcweir     aDate -= 2.0; // normieren: 1.1.1900 => 0.0
1792cdf0e10cSrcweir     Date aRefDate( 1, 1, 1900 );
1793cdf0e10cSrcweir     if ( aDate >= 0.0 )
1794cdf0e10cSrcweir     {
1795cdf0e10cSrcweir         aDate = floor( aDate );
1796cdf0e10cSrcweir         aRefDate += (sal_uIntPtr)aDate;
1797cdf0e10cSrcweir     }
1798cdf0e10cSrcweir     else
1799cdf0e10cSrcweir     {
1800cdf0e10cSrcweir         aDate = ceil( aDate );
1801cdf0e10cSrcweir         aRefDate -= (sal_uIntPtr)(-1.0 * aDate);
1802cdf0e10cSrcweir     }
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir     sal_Int16 nRet = (sal_Int16)( aRefDate.GetDay() );
1805cdf0e10cSrcweir     return nRet;
1806cdf0e10cSrcweir }
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir sal_Int16 implGetDateMonth( double aDate )
1809cdf0e10cSrcweir {
1810cdf0e10cSrcweir     Date aRefDate( 1,1,1900 );
1811cdf0e10cSrcweir     long nDays = (long)aDate;
1812cdf0e10cSrcweir     nDays -= 2; // normieren: 1.1.1900 => 0.0
1813cdf0e10cSrcweir     aRefDate += nDays;
1814cdf0e10cSrcweir     sal_Int16 nRet = (sal_Int16)( aRefDate.GetMonth() );
1815cdf0e10cSrcweir     return nRet;
1816cdf0e10cSrcweir }
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir sal_Int16 implGetDateYear( double aDate )
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir     Date aRefDate( 1,1,1900 );
1821cdf0e10cSrcweir     long nDays = (long) aDate;
1822cdf0e10cSrcweir     nDays -= 2; // normieren: 1.1.1900 => 0.0
1823cdf0e10cSrcweir     aRefDate += nDays;
1824cdf0e10cSrcweir     sal_Int16 nRet = (sal_Int16)( aRefDate.GetYear() );
1825cdf0e10cSrcweir     return nRet;
1826cdf0e10cSrcweir }
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir sal_Bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, double& rdRet )
1829cdf0e10cSrcweir {
1830cdf0e10cSrcweir     if ( nYear < 30 && SbiRuntime::isVBAEnabled() )
1831cdf0e10cSrcweir         nYear += 2000;
1832cdf0e10cSrcweir     else if ( nYear < 100 )
1833cdf0e10cSrcweir         nYear += 1900;
1834cdf0e10cSrcweir     Date aCurDate( nDay, nMonth, nYear );
1835cdf0e10cSrcweir     if ((nYear < 100 || nYear > 9999) )
1836cdf0e10cSrcweir     {
1837cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1838cdf0e10cSrcweir         return sal_False;
1839cdf0e10cSrcweir     }
1840cdf0e10cSrcweir     if ( !SbiRuntime::isVBAEnabled() )
1841cdf0e10cSrcweir     {
1842cdf0e10cSrcweir         if ( (nMonth < 1 || nMonth > 12 )||
1843cdf0e10cSrcweir         (nDay < 1 || nDay > 31 ) )
1844cdf0e10cSrcweir         {
1845cdf0e10cSrcweir             StarBASIC::Error( SbERR_BAD_ARGUMENT );
1846cdf0e10cSrcweir             return sal_False;
1847cdf0e10cSrcweir         }
1848cdf0e10cSrcweir     }
1849cdf0e10cSrcweir     else
1850cdf0e10cSrcweir     {
1851cdf0e10cSrcweir         // grab the year & month
1852cdf0e10cSrcweir         aCurDate = Date( 1, (( nMonth % 12 ) > 0 ) ? ( nMonth % 12 ) : 12 + ( nMonth % 12 ), nYear );
1853cdf0e10cSrcweir 
1854cdf0e10cSrcweir         // adjust year based on month value
1855cdf0e10cSrcweir         // e.g. 2000, 0, xx = 1999, 12, xx ( or December of the previous year )
1856cdf0e10cSrcweir         //      2000, 13, xx = 2001, 1, xx ( or January of the following year )
1857cdf0e10cSrcweir         if( ( nMonth < 1 ) || ( nMonth > 12 ) )
1858cdf0e10cSrcweir         {
1859cdf0e10cSrcweir             // inacurrate around leap year, don't use days to calculate,
1860cdf0e10cSrcweir             // just modify the months directory
1861cdf0e10cSrcweir             sal_Int16 nYearAdj = ( nMonth /12 ); // default to positive months inputed
1862cdf0e10cSrcweir             if ( nMonth <=0 )
1863cdf0e10cSrcweir                 nYearAdj = ( ( nMonth -12 ) / 12 );
1864cdf0e10cSrcweir             aCurDate.SetYear( aCurDate.GetYear() + nYearAdj );
1865cdf0e10cSrcweir         }
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir         // adjust day value,
1868cdf0e10cSrcweir         // e.g. 2000, 2, 0 = 2000, 1, 31 or the last day of the previous month
1869cdf0e10cSrcweir         //      2000, 1, 32 = 2000, 2, 1 or the first day of the following month
1870cdf0e10cSrcweir         if( ( nDay < 1 ) || ( nDay > aCurDate.GetDaysInMonth() ) )
1871cdf0e10cSrcweir             aCurDate += nDay - 1;
1872cdf0e10cSrcweir         else
1873cdf0e10cSrcweir             aCurDate.SetDay( nDay );
1874cdf0e10cSrcweir     }
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir     long nDiffDays = GetDayDiff( aCurDate );
1877cdf0e10cSrcweir     rdRet = (double)nDiffDays;
1878cdf0e10cSrcweir     return sal_True;
1879cdf0e10cSrcweir }
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir // Function to convert date to ISO 8601 date format
1882cdf0e10cSrcweir RTLFUNC(CDateToIso)
1883cdf0e10cSrcweir {
1884cdf0e10cSrcweir     (void)pBasic;
1885cdf0e10cSrcweir     (void)bWrite;
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir     if ( rPar.Count() == 2 )
1888cdf0e10cSrcweir     {
1889cdf0e10cSrcweir         double aDate = rPar.Get(1)->GetDate();
1890cdf0e10cSrcweir 
1891cdf0e10cSrcweir         char Buffer[9];
1892cdf0e10cSrcweir         snprintf( Buffer, sizeof( Buffer ), "%04d%02d%02d",
1893cdf0e10cSrcweir             implGetDateYear( aDate ),
1894cdf0e10cSrcweir             implGetDateMonth( aDate ),
1895cdf0e10cSrcweir             implGetDateDay( aDate ) );
1896cdf0e10cSrcweir         String aRetStr = String::CreateFromAscii( Buffer );
1897cdf0e10cSrcweir         rPar.Get(0)->PutString( aRetStr );
1898cdf0e10cSrcweir     }
1899cdf0e10cSrcweir     else
1900cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1901cdf0e10cSrcweir }
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir // Function to convert date from ISO 8601 date format
1904cdf0e10cSrcweir RTLFUNC(CDateFromIso)
1905cdf0e10cSrcweir {
1906cdf0e10cSrcweir     (void)pBasic;
1907cdf0e10cSrcweir     (void)bWrite;
1908cdf0e10cSrcweir 
1909cdf0e10cSrcweir     if ( rPar.Count() == 2 )
1910cdf0e10cSrcweir     {
1911cdf0e10cSrcweir         String aStr = rPar.Get(1)->GetString();
1912cdf0e10cSrcweir         sal_Int16 iMonthStart = aStr.Len() - 4;
1913cdf0e10cSrcweir         String aYearStr  = aStr.Copy( 0, iMonthStart );
1914cdf0e10cSrcweir         String aMonthStr = aStr.Copy( iMonthStart, 2 );
1915cdf0e10cSrcweir         String aDayStr   = aStr.Copy( iMonthStart+2, 2 );
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir         double dDate;
1918cdf0e10cSrcweir         if( implDateSerial( (sal_Int16)aYearStr.ToInt32(),
1919cdf0e10cSrcweir             (sal_Int16)aMonthStr.ToInt32(), (sal_Int16)aDayStr.ToInt32(), dDate ) )
1920cdf0e10cSrcweir         {
1921cdf0e10cSrcweir             rPar.Get(0)->PutDate( dDate );
1922cdf0e10cSrcweir         }
1923cdf0e10cSrcweir     }
1924cdf0e10cSrcweir     else
1925cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1926cdf0e10cSrcweir }
1927cdf0e10cSrcweir 
1928cdf0e10cSrcweir RTLFUNC(DateSerial)
1929cdf0e10cSrcweir {
1930cdf0e10cSrcweir     (void)pBasic;
1931cdf0e10cSrcweir     (void)bWrite;
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir     if ( rPar.Count() < 4 )
1934cdf0e10cSrcweir     {
1935cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1936cdf0e10cSrcweir         return;
1937cdf0e10cSrcweir     }
1938cdf0e10cSrcweir     sal_Int16 nYear = rPar.Get(1)->GetInteger();
1939cdf0e10cSrcweir     sal_Int16 nMonth = rPar.Get(2)->GetInteger();
1940cdf0e10cSrcweir     sal_Int16 nDay = rPar.Get(3)->GetInteger();
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir     double dDate;
1943cdf0e10cSrcweir     if( implDateSerial( nYear, nMonth, nDay, dDate ) )
1944cdf0e10cSrcweir         rPar.Get(0)->PutDate( dDate );
1945cdf0e10cSrcweir }
1946cdf0e10cSrcweir 
1947cdf0e10cSrcweir RTLFUNC(TimeSerial)
1948cdf0e10cSrcweir {
1949cdf0e10cSrcweir     (void)pBasic;
1950cdf0e10cSrcweir     (void)bWrite;
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir     if ( rPar.Count() < 4 )
1953cdf0e10cSrcweir     {
1954cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1955cdf0e10cSrcweir         return;
1956cdf0e10cSrcweir     }
1957cdf0e10cSrcweir     sal_Int16 nHour = rPar.Get(1)->GetInteger();
1958cdf0e10cSrcweir     if ( nHour == 24 )
1959cdf0e10cSrcweir         nHour = 0;                      // Wegen UNO DateTimes, die bis 24 Uhr gehen
1960cdf0e10cSrcweir     sal_Int16 nMinute = rPar.Get(2)->GetInteger();
1961cdf0e10cSrcweir     sal_Int16 nSecond = rPar.Get(3)->GetInteger();
1962cdf0e10cSrcweir     if ((nHour < 0 || nHour > 23)   ||
1963cdf0e10cSrcweir         (nMinute < 0 || nMinute > 59 )  ||
1964cdf0e10cSrcweir         (nSecond < 0 || nSecond > 59 ))
1965cdf0e10cSrcweir     {
1966cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1967cdf0e10cSrcweir         return;
1968cdf0e10cSrcweir     }
1969cdf0e10cSrcweir 
1970cdf0e10cSrcweir     sal_Int32 nSeconds = nHour;
1971cdf0e10cSrcweir     nSeconds *= 3600;
1972cdf0e10cSrcweir     nSeconds += nMinute * 60;
1973cdf0e10cSrcweir     nSeconds += nSecond;
1974cdf0e10cSrcweir     double nDays = ((double)nSeconds) / (double)(86400.0);
1975cdf0e10cSrcweir     rPar.Get(0)->PutDate( nDays ); // JSM
1976cdf0e10cSrcweir }
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir RTLFUNC(DateValue)
1979cdf0e10cSrcweir {
1980cdf0e10cSrcweir     (void)pBasic;
1981cdf0e10cSrcweir     (void)bWrite;
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir     if ( rPar.Count() < 2 )
1984cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
1985cdf0e10cSrcweir     else
1986cdf0e10cSrcweir     {
1987cdf0e10cSrcweir         // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden
1988cdf0e10cSrcweir         SvNumberFormatter* pFormatter = NULL;
1989cdf0e10cSrcweir         if( pINST )
1990cdf0e10cSrcweir             pFormatter = pINST->GetNumberFormatter();
1991cdf0e10cSrcweir         else
1992cdf0e10cSrcweir         {
1993cdf0e10cSrcweir             sal_uInt32 n;   // Dummy
1994cdf0e10cSrcweir             SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n );
1995cdf0e10cSrcweir         }
1996cdf0e10cSrcweir 
1997cdf0e10cSrcweir         sal_uInt32 nIndex;
1998cdf0e10cSrcweir         double fResult;
1999cdf0e10cSrcweir         String aStr( rPar.Get(1)->GetString() );
2000cdf0e10cSrcweir         sal_Bool bSuccess = pFormatter->IsNumberFormat( aStr, nIndex, fResult );
2001cdf0e10cSrcweir         short nType = pFormatter->GetType( nIndex );
2002cdf0e10cSrcweir 
2003cdf0e10cSrcweir         // DateValue("February 12, 1969") raises error if the system locale is not en_US
2004cdf0e10cSrcweir         // by using SbiInstance::GetNumberFormatter.
2005cdf0e10cSrcweir         // It seems that both locale number formatter and English number formatter
2006cdf0e10cSrcweir         // are supported in Visual Basic.
2007cdf0e10cSrcweir         LanguageType eLangType = GetpApp()->GetSettings().GetLanguage();
2008cdf0e10cSrcweir         if( !bSuccess && ( eLangType != LANGUAGE_ENGLISH_US ) )
2009cdf0e10cSrcweir         {
2010cdf0e10cSrcweir             // Create a new SvNumberFormatter by using LANGUAGE_ENGLISH to get the date value;
2011cdf0e10cSrcweir             com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
2012cdf0e10cSrcweir                 xFactory = comphelper::getProcessServiceFactory();
2013cdf0e10cSrcweir             SvNumberFormatter aFormatter( xFactory, LANGUAGE_ENGLISH_US );
2014cdf0e10cSrcweir             bSuccess = aFormatter.IsNumberFormat( aStr, nIndex, fResult );
2015cdf0e10cSrcweir             nType = aFormatter.GetType( nIndex );
2016cdf0e10cSrcweir         }
2017cdf0e10cSrcweir 
2018cdf0e10cSrcweir         if(bSuccess && (nType==NUMBERFORMAT_DATE || nType==NUMBERFORMAT_DATETIME))
2019cdf0e10cSrcweir         {
2020cdf0e10cSrcweir             if ( nType == NUMBERFORMAT_DATETIME )
2021cdf0e10cSrcweir             {
2022cdf0e10cSrcweir                 // Zeit abschneiden
2023cdf0e10cSrcweir                 if ( fResult  > 0.0 )
2024cdf0e10cSrcweir                     fResult = floor( fResult );
2025cdf0e10cSrcweir                 else
2026cdf0e10cSrcweir                     fResult = ceil( fResult );
2027cdf0e10cSrcweir             }
2028cdf0e10cSrcweir             // fResult += 2.0; // Anpassung  StarCalcFormatter
2029cdf0e10cSrcweir             rPar.Get(0)->PutDate( fResult ); // JSM
2030cdf0e10cSrcweir         }
2031cdf0e10cSrcweir         else
2032cdf0e10cSrcweir             StarBASIC::Error( SbERR_CONVERSION );
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir         // #39629 pFormatter kann selbst angefordert sein
2035cdf0e10cSrcweir         if( !pINST )
2036cdf0e10cSrcweir             delete pFormatter;
2037cdf0e10cSrcweir     }
2038cdf0e10cSrcweir }
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir RTLFUNC(TimeValue)
2041cdf0e10cSrcweir {
2042cdf0e10cSrcweir     (void)pBasic;
2043cdf0e10cSrcweir     (void)bWrite;
2044cdf0e10cSrcweir 
2045cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2046cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2047cdf0e10cSrcweir     else
2048cdf0e10cSrcweir     {
2049cdf0e10cSrcweir         // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden
2050cdf0e10cSrcweir         SvNumberFormatter* pFormatter = NULL;
2051cdf0e10cSrcweir         if( pINST )
2052cdf0e10cSrcweir             pFormatter = pINST->GetNumberFormatter();
2053cdf0e10cSrcweir         else
2054cdf0e10cSrcweir         {
2055cdf0e10cSrcweir             sal_uInt32 n;   // Dummy
2056cdf0e10cSrcweir             SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n );
2057cdf0e10cSrcweir         }
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir         sal_uInt32 nIndex;
2060cdf0e10cSrcweir         double fResult;
2061cdf0e10cSrcweir         sal_Bool bSuccess = pFormatter->IsNumberFormat( rPar.Get(1)->GetString(),
2062cdf0e10cSrcweir                                                    nIndex, fResult );
2063cdf0e10cSrcweir         short nType = pFormatter->GetType(nIndex);
2064cdf0e10cSrcweir         if(bSuccess && (nType==NUMBERFORMAT_TIME||nType==NUMBERFORMAT_DATETIME))
2065cdf0e10cSrcweir         {
2066cdf0e10cSrcweir             if ( nType == NUMBERFORMAT_DATETIME )
2067cdf0e10cSrcweir                 // Tage abschneiden
2068cdf0e10cSrcweir                 fResult = fmod( fResult, 1 );
2069cdf0e10cSrcweir             rPar.Get(0)->PutDate( fResult ); // JSM
2070cdf0e10cSrcweir         }
2071cdf0e10cSrcweir         else
2072cdf0e10cSrcweir             StarBASIC::Error( SbERR_CONVERSION );
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir         // #39629 pFormatter kann selbst angefordert sein
2075cdf0e10cSrcweir         if( !pINST )
2076cdf0e10cSrcweir             delete pFormatter;
2077cdf0e10cSrcweir     }
2078cdf0e10cSrcweir }
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir RTLFUNC(Day)
2081cdf0e10cSrcweir {
2082cdf0e10cSrcweir     (void)pBasic;
2083cdf0e10cSrcweir     (void)bWrite;
2084cdf0e10cSrcweir 
2085cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2086cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2087cdf0e10cSrcweir     else
2088cdf0e10cSrcweir     {
2089cdf0e10cSrcweir         SbxVariableRef pArg = rPar.Get( 1 );
2090cdf0e10cSrcweir         double aDate = pArg->GetDate();
2091cdf0e10cSrcweir 
2092cdf0e10cSrcweir         sal_Int16 nDay = implGetDateDay( aDate );
2093cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nDay );
2094cdf0e10cSrcweir     }
2095cdf0e10cSrcweir }
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir RTLFUNC(Year)
2098cdf0e10cSrcweir {
2099cdf0e10cSrcweir     (void)pBasic;
2100cdf0e10cSrcweir     (void)bWrite;
2101cdf0e10cSrcweir 
2102cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2103cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2104cdf0e10cSrcweir     else
2105cdf0e10cSrcweir     {
2106cdf0e10cSrcweir         sal_Int16 nYear = implGetDateYear( rPar.Get(1)->GetDate() );
2107cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nYear );
2108cdf0e10cSrcweir     }
2109cdf0e10cSrcweir }
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir sal_Int16 implGetHour( double dDate )
2112cdf0e10cSrcweir {
2113cdf0e10cSrcweir     if( dDate < 0.0 )
2114cdf0e10cSrcweir         dDate *= -1.0;
2115cdf0e10cSrcweir     double nFrac = dDate - floor( dDate );
2116cdf0e10cSrcweir     nFrac *= 86400.0;
2117cdf0e10cSrcweir     sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5);
2118cdf0e10cSrcweir     sal_Int16 nHour = (sal_Int16)(nSeconds / 3600);
2119cdf0e10cSrcweir     return nHour;
2120cdf0e10cSrcweir }
2121cdf0e10cSrcweir 
2122cdf0e10cSrcweir RTLFUNC(Hour)
2123cdf0e10cSrcweir {
2124cdf0e10cSrcweir     (void)pBasic;
2125cdf0e10cSrcweir     (void)bWrite;
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2128cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2129cdf0e10cSrcweir     else
2130cdf0e10cSrcweir     {
2131cdf0e10cSrcweir         double nArg = rPar.Get(1)->GetDate();
2132cdf0e10cSrcweir         sal_Int16 nHour = implGetHour( nArg );
2133cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nHour );
2134cdf0e10cSrcweir     }
2135cdf0e10cSrcweir }
2136cdf0e10cSrcweir 
2137cdf0e10cSrcweir sal_Int16 implGetMinute( double dDate )
2138cdf0e10cSrcweir {
2139cdf0e10cSrcweir     if( dDate < 0.0 )
2140cdf0e10cSrcweir         dDate *= -1.0;
2141cdf0e10cSrcweir     double nFrac = dDate - floor( dDate );
2142cdf0e10cSrcweir     nFrac *= 86400.0;
2143cdf0e10cSrcweir     sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5);
2144cdf0e10cSrcweir     sal_Int16 nTemp = (sal_Int16)(nSeconds % 3600);
2145cdf0e10cSrcweir     sal_Int16 nMin = nTemp / 60;
2146cdf0e10cSrcweir     return nMin;
2147cdf0e10cSrcweir }
2148cdf0e10cSrcweir 
2149cdf0e10cSrcweir RTLFUNC(Minute)
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir     (void)pBasic;
2152cdf0e10cSrcweir     (void)bWrite;
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2155cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2156cdf0e10cSrcweir     else
2157cdf0e10cSrcweir     {
2158cdf0e10cSrcweir         double nArg = rPar.Get(1)->GetDate();
2159cdf0e10cSrcweir         sal_Int16 nMin = implGetMinute( nArg );
2160cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nMin );
2161cdf0e10cSrcweir     }
2162cdf0e10cSrcweir }
2163cdf0e10cSrcweir 
2164cdf0e10cSrcweir RTLFUNC(Month)
2165cdf0e10cSrcweir {
2166cdf0e10cSrcweir     (void)pBasic;
2167cdf0e10cSrcweir     (void)bWrite;
2168cdf0e10cSrcweir 
2169cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2170cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2171cdf0e10cSrcweir     else
2172cdf0e10cSrcweir     {
2173cdf0e10cSrcweir         sal_Int16 nMonth = implGetDateMonth( rPar.Get(1)->GetDate() );
2174cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nMonth );
2175cdf0e10cSrcweir     }
2176cdf0e10cSrcweir }
2177cdf0e10cSrcweir 
2178cdf0e10cSrcweir sal_Int16 implGetSecond( double dDate )
2179cdf0e10cSrcweir {
2180cdf0e10cSrcweir     if( dDate < 0.0 )
2181cdf0e10cSrcweir         dDate *= -1.0;
2182cdf0e10cSrcweir     double nFrac = dDate - floor( dDate );
2183cdf0e10cSrcweir     nFrac *= 86400.0;
2184cdf0e10cSrcweir     sal_Int32 nSeconds = (sal_Int32)(nFrac + 0.5);
2185cdf0e10cSrcweir     sal_Int16 nTemp = (sal_Int16)(nSeconds / 3600);
2186cdf0e10cSrcweir     nSeconds -= nTemp * 3600;
2187cdf0e10cSrcweir     nTemp = (sal_Int16)(nSeconds / 60);
2188cdf0e10cSrcweir     nSeconds -= nTemp * 60;
2189cdf0e10cSrcweir 
2190cdf0e10cSrcweir     sal_Int16 nRet = (sal_Int16)nSeconds;
2191cdf0e10cSrcweir     return nRet;
2192cdf0e10cSrcweir }
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir RTLFUNC(Second)
2195cdf0e10cSrcweir {
2196cdf0e10cSrcweir     (void)pBasic;
2197cdf0e10cSrcweir     (void)bWrite;
2198cdf0e10cSrcweir 
2199cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2200cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2201cdf0e10cSrcweir     else
2202cdf0e10cSrcweir     {
2203cdf0e10cSrcweir         double nArg = rPar.Get(1)->GetDate();
2204cdf0e10cSrcweir         sal_Int16 nSecond = implGetSecond( nArg );
2205cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nSecond );
2206cdf0e10cSrcweir     }
2207cdf0e10cSrcweir }
2208cdf0e10cSrcweir 
2209cdf0e10cSrcweir double Now_Impl()
2210cdf0e10cSrcweir {
2211cdf0e10cSrcweir     Date aDate;
2212cdf0e10cSrcweir     Time aTime;
2213cdf0e10cSrcweir     double aSerial = (double)GetDayDiff( aDate );
2214cdf0e10cSrcweir     long nSeconds = aTime.GetHour();
2215cdf0e10cSrcweir     nSeconds *= 3600;
2216cdf0e10cSrcweir     nSeconds += aTime.GetMin() * 60;
2217cdf0e10cSrcweir     nSeconds += aTime.GetSec();
2218cdf0e10cSrcweir     double nDays = ((double)nSeconds) / (double)(24.0*3600.0);
2219cdf0e10cSrcweir     aSerial += nDays;
2220cdf0e10cSrcweir     return aSerial;
2221cdf0e10cSrcweir }
2222cdf0e10cSrcweir 
2223cdf0e10cSrcweir // Date Now(void)
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir RTLFUNC(Now)
2226cdf0e10cSrcweir {
2227cdf0e10cSrcweir         (void)pBasic;
2228cdf0e10cSrcweir         (void)bWrite;
2229cdf0e10cSrcweir     rPar.Get(0)->PutDate( Now_Impl() );
2230cdf0e10cSrcweir }
2231cdf0e10cSrcweir 
2232cdf0e10cSrcweir // Date Time(void)
2233cdf0e10cSrcweir 
2234cdf0e10cSrcweir RTLFUNC(Time)
2235cdf0e10cSrcweir {
2236cdf0e10cSrcweir     (void)pBasic;
2237cdf0e10cSrcweir 
2238cdf0e10cSrcweir     if ( !bWrite )
2239cdf0e10cSrcweir     {
2240cdf0e10cSrcweir         Time aTime;
2241cdf0e10cSrcweir         SbxVariable* pMeth = rPar.Get( 0 );
2242cdf0e10cSrcweir         String aRes;
2243cdf0e10cSrcweir         if( pMeth->IsFixed() )
2244cdf0e10cSrcweir         {
2245cdf0e10cSrcweir             // Time$: hh:mm:ss
2246cdf0e10cSrcweir             char buf[ 20 ];
2247cdf0e10cSrcweir             snprintf( buf, sizeof(buf), "%02d:%02d:%02d",
2248cdf0e10cSrcweir                 aTime.GetHour(), aTime.GetMin(), aTime.GetSec() );
2249cdf0e10cSrcweir             aRes = String::CreateFromAscii( buf );
2250cdf0e10cSrcweir         }
2251cdf0e10cSrcweir         else
2252cdf0e10cSrcweir         {
2253cdf0e10cSrcweir             // Time: system dependent
2254cdf0e10cSrcweir             long nSeconds=aTime.GetHour();
2255cdf0e10cSrcweir             nSeconds *= 3600;
2256cdf0e10cSrcweir             nSeconds += aTime.GetMin() * 60;
2257cdf0e10cSrcweir             nSeconds += aTime.GetSec();
2258cdf0e10cSrcweir             double nDays = (double)nSeconds * ( 1.0 / (24.0*3600.0) );
2259cdf0e10cSrcweir             Color* pCol;
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir             // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden
2262cdf0e10cSrcweir             SvNumberFormatter* pFormatter = NULL;
2263cdf0e10cSrcweir             sal_uInt32 nIndex;
2264cdf0e10cSrcweir             if( pINST )
2265cdf0e10cSrcweir             {
2266cdf0e10cSrcweir                 pFormatter = pINST->GetNumberFormatter();
2267cdf0e10cSrcweir                 nIndex = pINST->GetStdTimeIdx();
2268cdf0e10cSrcweir             }
2269cdf0e10cSrcweir             else
2270cdf0e10cSrcweir             {
2271cdf0e10cSrcweir                 sal_uInt32 n;   // Dummy
2272cdf0e10cSrcweir                 SbiInstance::PrepareNumberFormatter( pFormatter, n, nIndex, n );
2273cdf0e10cSrcweir             }
2274cdf0e10cSrcweir 
2275cdf0e10cSrcweir             pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol );
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir             // #39629 pFormatter kann selbst angefordert sein
2278cdf0e10cSrcweir             if( !pINST )
2279cdf0e10cSrcweir                 delete pFormatter;
2280cdf0e10cSrcweir         }
2281cdf0e10cSrcweir         pMeth->PutString( aRes );
2282cdf0e10cSrcweir     }
2283cdf0e10cSrcweir     else
2284cdf0e10cSrcweir     {
2285cdf0e10cSrcweir         StarBASIC::Error( SbERR_NOT_IMPLEMENTED );
2286cdf0e10cSrcweir     }
2287cdf0e10cSrcweir }
2288cdf0e10cSrcweir 
2289cdf0e10cSrcweir RTLFUNC(Timer)
2290cdf0e10cSrcweir {
2291cdf0e10cSrcweir     (void)pBasic;
2292cdf0e10cSrcweir     (void)bWrite;
2293cdf0e10cSrcweir 
2294cdf0e10cSrcweir     Time aTime;
2295cdf0e10cSrcweir     long nSeconds = aTime.GetHour();
2296cdf0e10cSrcweir     nSeconds *= 3600;
2297cdf0e10cSrcweir     nSeconds += aTime.GetMin() * 60;
2298cdf0e10cSrcweir     nSeconds += aTime.GetSec();
2299cdf0e10cSrcweir     rPar.Get(0)->PutDate( (double)nSeconds );
2300cdf0e10cSrcweir }
2301cdf0e10cSrcweir 
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir RTLFUNC(Date)
2304cdf0e10cSrcweir {
2305cdf0e10cSrcweir     (void)pBasic;
2306cdf0e10cSrcweir     (void)bWrite;
2307cdf0e10cSrcweir 
2308cdf0e10cSrcweir     if ( !bWrite )
2309cdf0e10cSrcweir     {
2310cdf0e10cSrcweir         Date aToday;
2311cdf0e10cSrcweir         double nDays = (double)GetDayDiff( aToday );
2312cdf0e10cSrcweir         SbxVariable* pMeth = rPar.Get( 0 );
2313cdf0e10cSrcweir         if( pMeth->IsString() )
2314cdf0e10cSrcweir         {
2315cdf0e10cSrcweir             String aRes;
2316cdf0e10cSrcweir             Color* pCol;
2317cdf0e10cSrcweir 
2318cdf0e10cSrcweir             // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden
2319cdf0e10cSrcweir             SvNumberFormatter* pFormatter = NULL;
2320cdf0e10cSrcweir             sal_uInt32 nIndex;
2321cdf0e10cSrcweir             if( pINST )
2322cdf0e10cSrcweir             {
2323cdf0e10cSrcweir                 pFormatter = pINST->GetNumberFormatter();
2324cdf0e10cSrcweir                 nIndex = pINST->GetStdDateIdx();
2325cdf0e10cSrcweir             }
2326cdf0e10cSrcweir             else
2327cdf0e10cSrcweir             {
2328cdf0e10cSrcweir                 sal_uInt32 n;   // Dummy
2329cdf0e10cSrcweir                 SbiInstance::PrepareNumberFormatter( pFormatter, nIndex, n, n );
2330cdf0e10cSrcweir             }
2331cdf0e10cSrcweir 
2332cdf0e10cSrcweir             pFormatter->GetOutputString( nDays, nIndex, aRes, &pCol );
2333cdf0e10cSrcweir             pMeth->PutString( aRes );
2334cdf0e10cSrcweir 
2335cdf0e10cSrcweir             // #39629 pFormatter kann selbst angefordert sein
2336cdf0e10cSrcweir             if( !pINST )
2337cdf0e10cSrcweir                 delete pFormatter;
2338cdf0e10cSrcweir         }
2339cdf0e10cSrcweir         else
2340cdf0e10cSrcweir             pMeth->PutDate( nDays );
2341cdf0e10cSrcweir     }
2342cdf0e10cSrcweir     else
2343cdf0e10cSrcweir     {
2344cdf0e10cSrcweir         StarBASIC::Error( SbERR_NOT_IMPLEMENTED );
2345cdf0e10cSrcweir     }
2346cdf0e10cSrcweir }
2347cdf0e10cSrcweir 
2348cdf0e10cSrcweir RTLFUNC(IsArray)
2349cdf0e10cSrcweir {
2350cdf0e10cSrcweir     (void)pBasic;
2351cdf0e10cSrcweir     (void)bWrite;
2352cdf0e10cSrcweir 
2353cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2354cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2355cdf0e10cSrcweir     else
2356cdf0e10cSrcweir         rPar.Get(0)->PutBool((rPar.Get(1)->GetType() & SbxARRAY) ? sal_True : sal_False );
2357cdf0e10cSrcweir }
2358cdf0e10cSrcweir 
2359cdf0e10cSrcweir RTLFUNC(IsObject)
2360cdf0e10cSrcweir {
2361cdf0e10cSrcweir     (void)pBasic;
2362cdf0e10cSrcweir     (void)bWrite;
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2365cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2366cdf0e10cSrcweir     else
2367cdf0e10cSrcweir     {
2368cdf0e10cSrcweir         SbxVariable* pVar = rPar.Get(1);
2369cdf0e10cSrcweir         SbxBase* pObj = (SbxBase*)pVar->GetObject();
2370cdf0e10cSrcweir 
2371cdf0e10cSrcweir         // #100385: GetObject can result in an error, so reset it
2372cdf0e10cSrcweir         SbxBase::ResetError();
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir         SbUnoClass* pUnoClass;
2375cdf0e10cSrcweir         sal_Bool bObject;
2376cdf0e10cSrcweir         if( pObj &&  NULL != ( pUnoClass=PTR_CAST(SbUnoClass,pObj) ) )
2377cdf0e10cSrcweir         {
2378cdf0e10cSrcweir             bObject = pUnoClass->getUnoClass().is();
2379cdf0e10cSrcweir         }
2380cdf0e10cSrcweir         else
2381cdf0e10cSrcweir         {
2382cdf0e10cSrcweir             bObject = pVar->IsObject();
2383cdf0e10cSrcweir         }
2384cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( bObject );
2385cdf0e10cSrcweir     }
2386cdf0e10cSrcweir }
2387cdf0e10cSrcweir 
2388cdf0e10cSrcweir RTLFUNC(IsDate)
2389cdf0e10cSrcweir {
2390cdf0e10cSrcweir     (void)pBasic;
2391cdf0e10cSrcweir     (void)bWrite;
2392cdf0e10cSrcweir 
2393cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2394cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2395cdf0e10cSrcweir     else
2396cdf0e10cSrcweir     {
2397cdf0e10cSrcweir         // #46134 Nur String wird konvertiert, andere Typen ergeben sal_False
2398cdf0e10cSrcweir         SbxVariableRef xArg = rPar.Get( 1 );
2399cdf0e10cSrcweir         SbxDataType eType = xArg->GetType();
2400cdf0e10cSrcweir         sal_Bool bDate = sal_False;
2401cdf0e10cSrcweir 
2402cdf0e10cSrcweir         if( eType == SbxDATE )
2403cdf0e10cSrcweir         {
2404cdf0e10cSrcweir             bDate = sal_True;
2405cdf0e10cSrcweir         }
2406cdf0e10cSrcweir         else if( eType == SbxSTRING )
2407cdf0e10cSrcweir         {
2408cdf0e10cSrcweir             // Error loeschen
2409cdf0e10cSrcweir             SbxError nPrevError = SbxBase::GetError();
2410cdf0e10cSrcweir             SbxBase::ResetError();
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir             // Konvertierung des Parameters nach SbxDATE erzwingen
2413cdf0e10cSrcweir             xArg->SbxValue::GetDate();
2414cdf0e10cSrcweir 
2415cdf0e10cSrcweir             // Bei Fehler ist es kein Date
2416cdf0e10cSrcweir             bDate = !SbxBase::IsError();
2417cdf0e10cSrcweir 
2418cdf0e10cSrcweir             // Error-Situation wiederherstellen
2419cdf0e10cSrcweir             SbxBase::ResetError();
2420cdf0e10cSrcweir             SbxBase::SetError( nPrevError );
2421cdf0e10cSrcweir         }
2422cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( bDate );
2423cdf0e10cSrcweir     }
2424cdf0e10cSrcweir }
2425cdf0e10cSrcweir 
2426cdf0e10cSrcweir RTLFUNC(IsEmpty)
2427cdf0e10cSrcweir {
2428cdf0e10cSrcweir     (void)pBasic;
2429cdf0e10cSrcweir     (void)bWrite;
2430cdf0e10cSrcweir 
2431cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2432cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2433cdf0e10cSrcweir     else
2434cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( rPar.Get(1)->IsEmpty() );
2435cdf0e10cSrcweir }
2436cdf0e10cSrcweir 
2437cdf0e10cSrcweir RTLFUNC(IsError)
2438cdf0e10cSrcweir {
2439cdf0e10cSrcweir     (void)pBasic;
2440cdf0e10cSrcweir     (void)bWrite;
2441cdf0e10cSrcweir 
2442cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2443cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2444cdf0e10cSrcweir     else
2445cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( rPar.Get(1)->IsErr() );
2446cdf0e10cSrcweir }
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir RTLFUNC(IsNull)
2449cdf0e10cSrcweir {
2450cdf0e10cSrcweir     (void)pBasic;
2451cdf0e10cSrcweir     (void)bWrite;
2452cdf0e10cSrcweir 
2453cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2454cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2455cdf0e10cSrcweir     else
2456cdf0e10cSrcweir     {
2457cdf0e10cSrcweir         // #51475 Wegen Uno-Objekten auch true liefern,
2458cdf0e10cSrcweir         // wenn der pObj-Wert NULL ist
2459cdf0e10cSrcweir         SbxVariableRef pArg = rPar.Get( 1 );
2460cdf0e10cSrcweir         sal_Bool bNull = rPar.Get(1)->IsNull();
2461cdf0e10cSrcweir         if( !bNull && pArg->GetType() == SbxOBJECT )
2462cdf0e10cSrcweir         {
2463cdf0e10cSrcweir             SbxBase* pObj = pArg->GetObject();
2464cdf0e10cSrcweir             if( !pObj )
2465cdf0e10cSrcweir                 bNull = sal_True;
2466cdf0e10cSrcweir         }
2467cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( bNull );
2468cdf0e10cSrcweir     }
2469cdf0e10cSrcweir }
2470cdf0e10cSrcweir 
2471cdf0e10cSrcweir RTLFUNC(IsNumeric)
2472cdf0e10cSrcweir {
2473cdf0e10cSrcweir     (void)pBasic;
2474cdf0e10cSrcweir     (void)bWrite;
2475cdf0e10cSrcweir 
2476cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2477cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2478cdf0e10cSrcweir     else
2479cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( rPar.Get( 1 )->IsNumericRTL() );
2480cdf0e10cSrcweir }
2481cdf0e10cSrcweir 
2482cdf0e10cSrcweir // Das machen wir auf die billige Tour
2483cdf0e10cSrcweir 
2484cdf0e10cSrcweir RTLFUNC(IsMissing)
2485cdf0e10cSrcweir {
2486cdf0e10cSrcweir     (void)pBasic;
2487cdf0e10cSrcweir     (void)bWrite;
2488cdf0e10cSrcweir 
2489cdf0e10cSrcweir     if ( rPar.Count() < 2 )
2490cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2491cdf0e10cSrcweir     else
2492cdf0e10cSrcweir         // #57915 Missing wird durch Error angezeigt
2493cdf0e10cSrcweir         rPar.Get( 0 )->PutBool( rPar.Get(1)->IsErr() );
2494cdf0e10cSrcweir }
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir // Dir( [Maske] [,Attrs] )
2497cdf0e10cSrcweir // ToDo: Library-globaler Datenbereich fuer Dir-Objekt und Flags
2498cdf0e10cSrcweir 
2499cdf0e10cSrcweir 
2500cdf0e10cSrcweir String getDirectoryPath( String aPathStr )
2501cdf0e10cSrcweir {
2502cdf0e10cSrcweir     String aRetStr;
2503cdf0e10cSrcweir 
2504cdf0e10cSrcweir     DirectoryItem aItem;
2505cdf0e10cSrcweir     FileBase::RC nRet = DirectoryItem::get( aPathStr, aItem );
2506cdf0e10cSrcweir     if( nRet == FileBase::E_None )
2507cdf0e10cSrcweir     {
2508cdf0e10cSrcweir         FileStatus aFileStatus( FileStatusMask_Type );
2509cdf0e10cSrcweir         nRet = aItem.getFileStatus( aFileStatus );
2510cdf0e10cSrcweir         if( nRet == FileBase::E_None )
2511cdf0e10cSrcweir         {
2512cdf0e10cSrcweir             FileStatus::Type aType = aFileStatus.getFileType();
2513cdf0e10cSrcweir             if( isFolder( aType ) )
2514cdf0e10cSrcweir             {
2515cdf0e10cSrcweir                 aRetStr = aPathStr;
2516cdf0e10cSrcweir             }
2517cdf0e10cSrcweir             else if( aType == FileStatus::Link )
2518cdf0e10cSrcweir             {
2519cdf0e10cSrcweir                 FileStatus aFileStatus2( FileStatusMask_LinkTargetURL );
2520cdf0e10cSrcweir                 nRet = aItem.getFileStatus( aFileStatus2 );
2521cdf0e10cSrcweir                 if( nRet == FileBase::E_None )
2522cdf0e10cSrcweir                     aRetStr = getDirectoryPath( aFileStatus2.getLinkTargetURL() );
2523cdf0e10cSrcweir             }
2524cdf0e10cSrcweir         }
2525cdf0e10cSrcweir     }
2526cdf0e10cSrcweir     return aRetStr;
2527cdf0e10cSrcweir }
2528cdf0e10cSrcweir 
2529cdf0e10cSrcweir // Function looks for wildcards, removes them and always returns the pure path
2530cdf0e10cSrcweir String implSetupWildcard( const String& rFileParam, SbiRTLData* pRTLData )
2531cdf0e10cSrcweir {
2532cdf0e10cSrcweir     static String aAsterisk = String::CreateFromAscii( "*" );
2533cdf0e10cSrcweir     static sal_Char cDelim1 = (sal_Char)'/';
2534cdf0e10cSrcweir     static sal_Char cDelim2 = (sal_Char)'\\';
2535cdf0e10cSrcweir     static sal_Char cWild1 = '*';
2536cdf0e10cSrcweir     static sal_Char cWild2 = '?';
2537cdf0e10cSrcweir 
2538cdf0e10cSrcweir     delete pRTLData->pWildCard;
2539cdf0e10cSrcweir     pRTLData->pWildCard = NULL;
2540cdf0e10cSrcweir     pRTLData->sFullNameToBeChecked = String();
2541cdf0e10cSrcweir 
2542cdf0e10cSrcweir     String aFileParam = rFileParam;
2543cdf0e10cSrcweir     xub_StrLen nLastWild = aFileParam.SearchBackward( cWild1 );
2544cdf0e10cSrcweir     if( nLastWild == STRING_NOTFOUND )
2545cdf0e10cSrcweir         nLastWild = aFileParam.SearchBackward( cWild2 );
2546cdf0e10cSrcweir     sal_Bool bHasWildcards = ( nLastWild != STRING_NOTFOUND );
2547cdf0e10cSrcweir 
2548cdf0e10cSrcweir 
2549cdf0e10cSrcweir     xub_StrLen nLastDelim = aFileParam.SearchBackward( cDelim1 );
2550cdf0e10cSrcweir     if( nLastDelim == STRING_NOTFOUND )
2551cdf0e10cSrcweir         nLastDelim = aFileParam.SearchBackward( cDelim2 );
2552cdf0e10cSrcweir 
2553cdf0e10cSrcweir     if( bHasWildcards )
2554cdf0e10cSrcweir     {
2555cdf0e10cSrcweir         // Wildcards in path?
2556cdf0e10cSrcweir         if( nLastDelim != STRING_NOTFOUND && nLastDelim > nLastWild )
2557cdf0e10cSrcweir             return aFileParam;
2558cdf0e10cSrcweir     }
2559cdf0e10cSrcweir     else
2560cdf0e10cSrcweir     {
2561cdf0e10cSrcweir         String aPathStr = getFullPath( aFileParam );
2562cdf0e10cSrcweir         if( nLastDelim != aFileParam.Len() - 1 )
2563cdf0e10cSrcweir             pRTLData->sFullNameToBeChecked = aPathStr;
2564cdf0e10cSrcweir         return aPathStr;
2565cdf0e10cSrcweir     }
2566cdf0e10cSrcweir 
2567cdf0e10cSrcweir     String aPureFileName;
2568cdf0e10cSrcweir     if( nLastDelim == STRING_NOTFOUND )
2569cdf0e10cSrcweir     {
2570cdf0e10cSrcweir         aPureFileName = aFileParam;
2571cdf0e10cSrcweir         aFileParam = String();
2572cdf0e10cSrcweir     }
2573cdf0e10cSrcweir     else
2574cdf0e10cSrcweir     {
2575cdf0e10cSrcweir         aPureFileName = aFileParam.Copy( nLastDelim + 1 );
2576cdf0e10cSrcweir         aFileParam = aFileParam.Copy( 0, nLastDelim );
2577cdf0e10cSrcweir     }
2578cdf0e10cSrcweir 
2579cdf0e10cSrcweir     // Try again to get a valid URL/UNC-path with only the path
2580cdf0e10cSrcweir     String aPathStr = getFullPath( aFileParam );
2581cdf0e10cSrcweir     xub_StrLen nPureLen = aPureFileName.Len();
2582cdf0e10cSrcweir 
2583cdf0e10cSrcweir     // Is there a pure file name left? Otherwise the path is
2584cdf0e10cSrcweir     // invalid anyway because it was not accepted by OSL before
2585cdf0e10cSrcweir     if( nPureLen && aPureFileName != aAsterisk )
2586cdf0e10cSrcweir     {
2587cdf0e10cSrcweir         pRTLData->pWildCard = new WildCard( aPureFileName );
2588cdf0e10cSrcweir     }
2589cdf0e10cSrcweir     return aPathStr;
2590cdf0e10cSrcweir }
2591cdf0e10cSrcweir 
2592cdf0e10cSrcweir inline sal_Bool implCheckWildcard( const String& rName, SbiRTLData* pRTLData )
2593cdf0e10cSrcweir {
2594cdf0e10cSrcweir     sal_Bool bMatch = sal_True;
2595cdf0e10cSrcweir 
2596cdf0e10cSrcweir     if( pRTLData->pWildCard )
2597cdf0e10cSrcweir         bMatch = pRTLData->pWildCard->Matches( rName );
2598cdf0e10cSrcweir     return bMatch;
2599cdf0e10cSrcweir }
2600cdf0e10cSrcweir 
2601cdf0e10cSrcweir 
2602cdf0e10cSrcweir bool isRootDir( String aDirURLStr )
2603cdf0e10cSrcweir {
2604cdf0e10cSrcweir     INetURLObject aDirURLObj( aDirURLStr );
2605cdf0e10cSrcweir     sal_Bool bRoot = sal_False;
2606cdf0e10cSrcweir 
2607cdf0e10cSrcweir     // Check if it's a root directory
2608cdf0e10cSrcweir     sal_Int32 nCount = aDirURLObj.getSegmentCount();
2609cdf0e10cSrcweir 
2610cdf0e10cSrcweir     // No segment means Unix root directory "file:///"
2611cdf0e10cSrcweir     if( nCount == 0 )
2612cdf0e10cSrcweir     {
2613cdf0e10cSrcweir         bRoot = sal_True;
2614cdf0e10cSrcweir     }
2615cdf0e10cSrcweir     // Exactly one segment needs further checking, because it
2616cdf0e10cSrcweir     // can be Unix "file:///foo/" -> no root
2617cdf0e10cSrcweir     // or Windows  "file:///c:/"  -> root
2618cdf0e10cSrcweir     else if( nCount == 1 )
2619cdf0e10cSrcweir     {
2620cdf0e10cSrcweir         ::rtl::OUString aSeg1 = aDirURLObj.getName( 0, sal_True,
2621cdf0e10cSrcweir             INetURLObject::DECODE_WITH_CHARSET );
2622cdf0e10cSrcweir         if( aSeg1.getStr()[1] == (sal_Unicode)':' )
2623cdf0e10cSrcweir         {
2624cdf0e10cSrcweir             bRoot = sal_True;
2625cdf0e10cSrcweir         }
2626cdf0e10cSrcweir     }
2627cdf0e10cSrcweir     // More than one segments can never be root
2628cdf0e10cSrcweir     // so bRoot remains sal_False
2629cdf0e10cSrcweir 
2630cdf0e10cSrcweir     return bRoot;
2631cdf0e10cSrcweir }
2632cdf0e10cSrcweir 
2633cdf0e10cSrcweir RTLFUNC(Dir)
2634cdf0e10cSrcweir {
2635cdf0e10cSrcweir     (void)pBasic;
2636cdf0e10cSrcweir     (void)bWrite;
2637cdf0e10cSrcweir 
2638cdf0e10cSrcweir     String aPath;
2639cdf0e10cSrcweir 
2640cdf0e10cSrcweir     sal_uInt16 nParCount = rPar.Count();
2641cdf0e10cSrcweir     if( nParCount > 3 )
2642cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
2643cdf0e10cSrcweir     else
2644cdf0e10cSrcweir     {
2645cdf0e10cSrcweir         SbiRTLData* pRTLData = pINST->GetRTLData();
2646cdf0e10cSrcweir 
2647cdf0e10cSrcweir         // #34645: Kann auch von der URL-Zeile ueber 'macro: Dir' aufgerufen werden
2648cdf0e10cSrcweir         // dann existiert kein pRTLData und die Methode muss verlassen werden
2649cdf0e10cSrcweir         if( !pRTLData )
2650cdf0e10cSrcweir             return;
2651cdf0e10cSrcweir 
2652cdf0e10cSrcweir         // <-- UCB
2653cdf0e10cSrcweir         if( hasUno() )
2654cdf0e10cSrcweir         {
2655cdf0e10cSrcweir             com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
2656cdf0e10cSrcweir             if( xSFI.is() )
2657cdf0e10cSrcweir             {
2658cdf0e10cSrcweir                 if ( nParCount >= 2 )
2659cdf0e10cSrcweir                 {
2660cdf0e10cSrcweir                     String aFileParam = rPar.Get(1)->GetString();
2661cdf0e10cSrcweir 
2662cdf0e10cSrcweir                     String aFileURLStr = implSetupWildcard( aFileParam, pRTLData );
2663cdf0e10cSrcweir                     if( pRTLData->sFullNameToBeChecked.Len() > 0 )
2664cdf0e10cSrcweir                     {
2665cdf0e10cSrcweir                         sal_Bool bExists = sal_False;
2666cdf0e10cSrcweir                         try { bExists = xSFI->exists( aFileURLStr ); }
2667cdf0e10cSrcweir                         catch( Exception & ) {}
2668cdf0e10cSrcweir 
2669cdf0e10cSrcweir                         String aNameOnlyStr;
2670cdf0e10cSrcweir                         if( bExists )
2671cdf0e10cSrcweir                         {
2672cdf0e10cSrcweir                             INetURLObject aFileURL( aFileURLStr );
2673cdf0e10cSrcweir                             aNameOnlyStr = aFileURL.getName( INetURLObject::LAST_SEGMENT,
2674cdf0e10cSrcweir                                 true, INetURLObject::DECODE_WITH_CHARSET );
2675cdf0e10cSrcweir                         }
2676cdf0e10cSrcweir                         rPar.Get(0)->PutString( aNameOnlyStr );
2677cdf0e10cSrcweir                         return;
2678cdf0e10cSrcweir                     }
2679cdf0e10cSrcweir 
2680cdf0e10cSrcweir                     try
2681cdf0e10cSrcweir                     {
2682cdf0e10cSrcweir                         String aDirURLStr;
2683cdf0e10cSrcweir                         sal_Bool bFolder = xSFI->isFolder( aFileURLStr );
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir                         if( bFolder )
2686cdf0e10cSrcweir                         {
2687cdf0e10cSrcweir                             aDirURLStr = aFileURLStr;
2688cdf0e10cSrcweir                         }
2689cdf0e10cSrcweir                         else
2690cdf0e10cSrcweir                         {
2691cdf0e10cSrcweir                             String aEmptyStr;
2692cdf0e10cSrcweir                             rPar.Get(0)->PutString( aEmptyStr );
2693cdf0e10cSrcweir                         }
2694cdf0e10cSrcweir 
2695cdf0e10cSrcweir                         sal_uInt16 nFlags = 0;
2696cdf0e10cSrcweir                         if ( nParCount > 2 )
2697cdf0e10cSrcweir                             pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger();
2698cdf0e10cSrcweir                         else
2699cdf0e10cSrcweir                             pRTLData->nDirFlags = 0;
2700cdf0e10cSrcweir 
2701cdf0e10cSrcweir                         // Read directory
2702cdf0e10cSrcweir                         sal_Bool bIncludeFolders = ((nFlags & Sb_ATTR_DIRECTORY) != 0);
2703cdf0e10cSrcweir                         pRTLData->aDirSeq = xSFI->getFolderContents( aDirURLStr, bIncludeFolders );
2704cdf0e10cSrcweir                         pRTLData->nCurDirPos = 0;
2705cdf0e10cSrcweir 
2706cdf0e10cSrcweir                         // #78651 Add "." and ".." directories for VB compatibility
2707cdf0e10cSrcweir                         if( bIncludeFolders )
2708cdf0e10cSrcweir                         {
2709cdf0e10cSrcweir                             sal_Bool bRoot = isRootDir( aDirURLStr );
2710cdf0e10cSrcweir 
2711cdf0e10cSrcweir                             // If it's no root directory we flag the need for
2712cdf0e10cSrcweir                             // the "." and ".." directories by the value -2
2713cdf0e10cSrcweir                             // for the actual position. Later for -2 will be
2714cdf0e10cSrcweir                             // returned "." and for -1 ".."
2715cdf0e10cSrcweir                             if( !bRoot )
2716cdf0e10cSrcweir                             {
2717cdf0e10cSrcweir                                 pRTLData->nCurDirPos = -2;
2718cdf0e10cSrcweir                             }
2719cdf0e10cSrcweir                         }
2720cdf0e10cSrcweir                     }
2721cdf0e10cSrcweir                     catch( Exception & )
2722cdf0e10cSrcweir                     {
2723cdf0e10cSrcweir                         //StarBASIC::Error( ERRCODE_IO_GENERAL );
2724cdf0e10cSrcweir                     }
2725cdf0e10cSrcweir                 }
2726cdf0e10cSrcweir 
2727cdf0e10cSrcweir 
2728cdf0e10cSrcweir                 if( pRTLData->aDirSeq.getLength() > 0 )
2729cdf0e10cSrcweir                 {
2730cdf0e10cSrcweir                     sal_Bool bFolderFlag = ((pRTLData->nDirFlags & Sb_ATTR_DIRECTORY) != 0);
2731cdf0e10cSrcweir 
2732cdf0e10cSrcweir                     SbiInstance* pInst = pINST;
2733cdf0e10cSrcweir                     bool bCompatibility = ( pInst && pInst->IsCompatibility() );
2734cdf0e10cSrcweir                     for( ;; )
2735cdf0e10cSrcweir                     {
2736cdf0e10cSrcweir                         if( pRTLData->nCurDirPos < 0 )
2737cdf0e10cSrcweir                         {
2738cdf0e10cSrcweir                             if( pRTLData->nCurDirPos == -2 )
2739cdf0e10cSrcweir                             {
2740cdf0e10cSrcweir                                 aPath = ::rtl::OUString::createFromAscii( "." );
2741cdf0e10cSrcweir                             }
2742cdf0e10cSrcweir                             else if( pRTLData->nCurDirPos == -1 )
2743cdf0e10cSrcweir                             {
2744cdf0e10cSrcweir                                 aPath = ::rtl::OUString::createFromAscii( ".." );
2745cdf0e10cSrcweir                             }
2746cdf0e10cSrcweir                             pRTLData->nCurDirPos++;
2747cdf0e10cSrcweir                         }
2748cdf0e10cSrcweir                         else if( pRTLData->nCurDirPos >= pRTLData->aDirSeq.getLength() )
2749cdf0e10cSrcweir                         {
2750cdf0e10cSrcweir                             pRTLData->aDirSeq.realloc( 0 );
2751cdf0e10cSrcweir                             aPath.Erase();
2752cdf0e10cSrcweir                             break;
2753cdf0e10cSrcweir                         }
2754cdf0e10cSrcweir                         else
2755cdf0e10cSrcweir                         {
2756cdf0e10cSrcweir                             ::rtl::OUString aFile = pRTLData->aDirSeq.getConstArray()[pRTLData->nCurDirPos++];
2757cdf0e10cSrcweir 
2758cdf0e10cSrcweir                             if( bCompatibility )
2759cdf0e10cSrcweir                             {
2760cdf0e10cSrcweir                                 if( !bFolderFlag )
2761cdf0e10cSrcweir                                 {
2762cdf0e10cSrcweir                                     sal_Bool bFolder = xSFI->isFolder( aFile );
2763cdf0e10cSrcweir                                     if( bFolder )
2764cdf0e10cSrcweir                                         continue;
2765cdf0e10cSrcweir                                 }
2766cdf0e10cSrcweir                             }
2767cdf0e10cSrcweir                             else
2768cdf0e10cSrcweir                             {
2769cdf0e10cSrcweir                                 // Only directories
2770cdf0e10cSrcweir                                 if( bFolderFlag )
2771cdf0e10cSrcweir                                 {
2772cdf0e10cSrcweir                                     sal_Bool bFolder = xSFI->isFolder( aFile );
2773cdf0e10cSrcweir                                     if( !bFolder )
2774cdf0e10cSrcweir                                         continue;
2775cdf0e10cSrcweir                                 }
2776cdf0e10cSrcweir                             }
2777cdf0e10cSrcweir 
2778cdf0e10cSrcweir                             INetURLObject aURL( aFile );
2779cdf0e10cSrcweir                             aPath = aURL.getName( INetURLObject::LAST_SEGMENT, sal_True,
2780cdf0e10cSrcweir                                 INetURLObject::DECODE_WITH_CHARSET );
2781cdf0e10cSrcweir                         }
2782cdf0e10cSrcweir 
2783cdf0e10cSrcweir                         sal_Bool bMatch = implCheckWildcard( aPath, pRTLData );
2784cdf0e10cSrcweir                         if( !bMatch )
2785cdf0e10cSrcweir                             continue;
2786cdf0e10cSrcweir 
2787cdf0e10cSrcweir                         break;
2788cdf0e10cSrcweir                     }
2789cdf0e10cSrcweir                 }
2790cdf0e10cSrcweir                 rPar.Get(0)->PutString( aPath );
2791cdf0e10cSrcweir             }
2792cdf0e10cSrcweir         }
2793cdf0e10cSrcweir         else
2794cdf0e10cSrcweir         // --> UCB
2795cdf0e10cSrcweir         {
2796cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL
2797cdf0e10cSrcweir             if ( nParCount >= 2 )
2798cdf0e10cSrcweir             {
2799cdf0e10cSrcweir                 delete pRTLData->pDir;
2800cdf0e10cSrcweir                 pRTLData->pDir = 0; // wg. Sonderbehandlung Sb_ATTR_VOLUME
2801cdf0e10cSrcweir                 DirEntry aEntry( rPar.Get(1)->GetString() );
2802cdf0e10cSrcweir                 FileStat aStat( aEntry );
2803cdf0e10cSrcweir                 if(!aStat.GetError() && (aStat.GetKind() & FSYS_KIND_FILE))
2804cdf0e10cSrcweir                 {
2805cdf0e10cSrcweir                     // ah ja, ist nur ein dateiname
2806cdf0e10cSrcweir                     // Pfad abschneiden (wg. VB4)
2807cdf0e10cSrcweir                     rPar.Get(0)->PutString( aEntry.GetName() );
2808cdf0e10cSrcweir                     return;
2809cdf0e10cSrcweir                 }
2810cdf0e10cSrcweir                 sal_uInt16 nFlags = 0;
2811cdf0e10cSrcweir                 if ( nParCount > 2 )
2812cdf0e10cSrcweir                     pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger();
2813cdf0e10cSrcweir                 else
2814cdf0e10cSrcweir                     pRTLData->nDirFlags = 0;
2815cdf0e10cSrcweir 
2816cdf0e10cSrcweir                 // Sb_ATTR_VOLUME wird getrennt gehandelt
2817cdf0e10cSrcweir                 if( pRTLData->nDirFlags & Sb_ATTR_VOLUME )
2818cdf0e10cSrcweir                     aPath = aEntry.GetVolume();
2819cdf0e10cSrcweir                 else
2820cdf0e10cSrcweir                 {
2821cdf0e10cSrcweir                     // Die richtige Auswahl treffen
2822cdf0e10cSrcweir                     sal_uInt16 nMode = FSYS_KIND_FILE;
2823cdf0e10cSrcweir                     if( nFlags & Sb_ATTR_DIRECTORY )
2824cdf0e10cSrcweir                         nMode |= FSYS_KIND_DIR;
2825cdf0e10cSrcweir                     if( nFlags == Sb_ATTR_DIRECTORY )
2826cdf0e10cSrcweir                         nMode = FSYS_KIND_DIR;
2827cdf0e10cSrcweir                     pRTLData->pDir = new Dir( aEntry, (DirEntryKind) nMode );
2828cdf0e10cSrcweir                     pRTLData->nCurDirPos = 0;
2829cdf0e10cSrcweir                 }
2830cdf0e10cSrcweir             }
2831cdf0e10cSrcweir 
2832cdf0e10cSrcweir             if( pRTLData->pDir )
2833cdf0e10cSrcweir             {
2834cdf0e10cSrcweir                 for( ;; )
2835cdf0e10cSrcweir                 {
2836cdf0e10cSrcweir                     if( pRTLData->nCurDirPos >= pRTLData->pDir->Count() )
2837cdf0e10cSrcweir                     {
2838cdf0e10cSrcweir                         delete pRTLData->pDir;
2839cdf0e10cSrcweir                         pRTLData->pDir = 0;
2840cdf0e10cSrcweir                         aPath.Erase();
2841cdf0e10cSrcweir                         break;
2842cdf0e10cSrcweir                     }
2843cdf0e10cSrcweir                     DirEntry aNextEntry=(*(pRTLData->pDir))[pRTLData->nCurDirPos++];
2844cdf0e10cSrcweir                     aPath = aNextEntry.GetName(); //Full();
2845cdf0e10cSrcweir                     break;
2846cdf0e10cSrcweir                 }
2847cdf0e10cSrcweir             }
2848cdf0e10cSrcweir             rPar.Get(0)->PutString( aPath );
2849cdf0e10cSrcweir #else
2850cdf0e10cSrcweir             // TODO: OSL
2851cdf0e10cSrcweir             if ( nParCount >= 2 )
2852cdf0e10cSrcweir             {
2853cdf0e10cSrcweir                 String aFileParam = rPar.Get(1)->GetString();
2854cdf0e10cSrcweir 
2855cdf0e10cSrcweir                 String aDirURL = implSetupWildcard( aFileParam, pRTLData );
2856cdf0e10cSrcweir 
2857cdf0e10cSrcweir                 sal_uInt16 nFlags = 0;
2858cdf0e10cSrcweir                 if ( nParCount > 2 )
2859cdf0e10cSrcweir                     pRTLData->nDirFlags = nFlags = rPar.Get(2)->GetInteger();
2860cdf0e10cSrcweir                 else
2861cdf0e10cSrcweir                     pRTLData->nDirFlags = 0;
2862cdf0e10cSrcweir 
2863cdf0e10cSrcweir                 // Read directory
2864cdf0e10cSrcweir                 sal_Bool bIncludeFolders = ((nFlags & Sb_ATTR_DIRECTORY) != 0);
2865cdf0e10cSrcweir                 pRTLData->pDir = new Directory( aDirURL );
2866cdf0e10cSrcweir                 FileBase::RC nRet = pRTLData->pDir->open();
2867cdf0e10cSrcweir                 if( nRet != FileBase::E_None )
2868cdf0e10cSrcweir                 {
2869cdf0e10cSrcweir                     delete pRTLData->pDir;
2870cdf0e10cSrcweir                     pRTLData->pDir = NULL;
2871cdf0e10cSrcweir                     rPar.Get(0)->PutString( String() );
2872cdf0e10cSrcweir                     return;
2873cdf0e10cSrcweir                 }
2874cdf0e10cSrcweir 
2875cdf0e10cSrcweir                 // #86950 Add "." and ".." directories for VB compatibility
2876cdf0e10cSrcweir                 pRTLData->nCurDirPos = 0;
2877cdf0e10cSrcweir                 if( bIncludeFolders )
2878cdf0e10cSrcweir                 {
2879cdf0e10cSrcweir                     sal_Bool bRoot = isRootDir( aDirURL );
2880cdf0e10cSrcweir 
2881cdf0e10cSrcweir                     // If it's no root directory we flag the need for
2882cdf0e10cSrcweir                     // the "." and ".." directories by the value -2
2883cdf0e10cSrcweir                     // for the actual position. Later for -2 will be
2884cdf0e10cSrcweir                     // returned "." and for -1 ".."
2885cdf0e10cSrcweir                     if( !bRoot )
2886cdf0e10cSrcweir                     {
2887cdf0e10cSrcweir                         pRTLData->nCurDirPos = -2;
2888cdf0e10cSrcweir                     }
2889cdf0e10cSrcweir                 }
2890cdf0e10cSrcweir 
2891cdf0e10cSrcweir             }
2892cdf0e10cSrcweir 
2893cdf0e10cSrcweir             if( pRTLData->pDir )
2894cdf0e10cSrcweir             {
2895cdf0e10cSrcweir                 sal_Bool bFolderFlag = ((pRTLData->nDirFlags & Sb_ATTR_DIRECTORY) != 0);
2896cdf0e10cSrcweir                 for( ;; )
2897cdf0e10cSrcweir                 {
2898cdf0e10cSrcweir                     if( pRTLData->nCurDirPos < 0 )
2899cdf0e10cSrcweir                     {
2900cdf0e10cSrcweir                         if( pRTLData->nCurDirPos == -2 )
2901cdf0e10cSrcweir                         {
2902cdf0e10cSrcweir                             aPath = ::rtl::OUString::createFromAscii( "." );
2903cdf0e10cSrcweir                         }
2904cdf0e10cSrcweir                         else if( pRTLData->nCurDirPos == -1 )
2905cdf0e10cSrcweir                         {
2906cdf0e10cSrcweir                             aPath = ::rtl::OUString::createFromAscii( ".." );
2907cdf0e10cSrcweir                         }
2908cdf0e10cSrcweir                         pRTLData->nCurDirPos++;
2909cdf0e10cSrcweir                     }
2910cdf0e10cSrcweir                     else
2911cdf0e10cSrcweir                     {
2912cdf0e10cSrcweir                         DirectoryItem aItem;
2913cdf0e10cSrcweir                         FileBase::RC nRet = pRTLData->pDir->getNextItem( aItem );
2914cdf0e10cSrcweir                         if( nRet != FileBase::E_None )
2915cdf0e10cSrcweir                         {
2916cdf0e10cSrcweir                             delete pRTLData->pDir;
2917cdf0e10cSrcweir                             pRTLData->pDir = NULL;
2918cdf0e10cSrcweir                             aPath.Erase();
2919cdf0e10cSrcweir                             break;
2920cdf0e10cSrcweir                         }
2921cdf0e10cSrcweir 
2922cdf0e10cSrcweir                         // Handle flags
2923cdf0e10cSrcweir                         FileStatus aFileStatus( FileStatusMask_Type | FileStatusMask_FileName );
2924cdf0e10cSrcweir                         nRet = aItem.getFileStatus( aFileStatus );
2925cdf0e10cSrcweir 
2926cdf0e10cSrcweir                         // Only directories?
2927cdf0e10cSrcweir                         if( bFolderFlag )
2928cdf0e10cSrcweir                         {
2929cdf0e10cSrcweir                             FileStatus::Type aType = aFileStatus.getFileType();
2930cdf0e10cSrcweir                             sal_Bool bFolder = isFolder( aType );
2931cdf0e10cSrcweir                             if( !bFolder )
2932cdf0e10cSrcweir                                 continue;
2933cdf0e10cSrcweir                         }
2934cdf0e10cSrcweir 
2935cdf0e10cSrcweir                         aPath = aFileStatus.getFileName();
2936cdf0e10cSrcweir                     }
2937cdf0e10cSrcweir 
2938cdf0e10cSrcweir                     sal_Bool bMatch = implCheckWildcard( aPath, pRTLData );
2939cdf0e10cSrcweir                     if( !bMatch )
2940cdf0e10cSrcweir                         continue;
2941cdf0e10cSrcweir 
2942cdf0e10cSrcweir                     break;
2943cdf0e10cSrcweir                 }
2944cdf0e10cSrcweir             }
2945cdf0e10cSrcweir             rPar.Get(0)->PutString( aPath );
2946cdf0e10cSrcweir #endif
2947cdf0e10cSrcweir         }
2948cdf0e10cSrcweir     }
2949cdf0e10cSrcweir }
2950cdf0e10cSrcweir 
2951cdf0e10cSrcweir 
2952cdf0e10cSrcweir RTLFUNC(GetAttr)
2953cdf0e10cSrcweir {
2954cdf0e10cSrcweir     (void)pBasic;
2955cdf0e10cSrcweir     (void)bWrite;
2956cdf0e10cSrcweir 
2957cdf0e10cSrcweir     if ( rPar.Count() == 2 )
2958cdf0e10cSrcweir     {
2959cdf0e10cSrcweir         sal_Int16 nFlags = 0;
2960cdf0e10cSrcweir 
2961cdf0e10cSrcweir         // In Windows, We want to use Windows API to get the file attributes
2962cdf0e10cSrcweir         // for VBA interoperability.
2963cdf0e10cSrcweir     #if defined( WNT )
2964cdf0e10cSrcweir         if( SbiRuntime::isVBAEnabled() )
2965cdf0e10cSrcweir         {
2966cdf0e10cSrcweir             DirEntry aEntry( rPar.Get(1)->GetString() );
2967cdf0e10cSrcweir             aEntry.ToAbs();
2968cdf0e10cSrcweir 
2969cdf0e10cSrcweir             // #57064 Bei virtuellen URLs den Real-Path extrahieren
2970cdf0e10cSrcweir             ByteString aByteStrFullPath( aEntry.GetFull(), gsl_getSystemTextEncoding() );
2971cdf0e10cSrcweir             DWORD nRealFlags = GetFileAttributes (aByteStrFullPath.GetBuffer());
2972cdf0e10cSrcweir             if (nRealFlags != 0xffffffff)
2973cdf0e10cSrcweir             {
2974cdf0e10cSrcweir                 if (nRealFlags == FILE_ATTRIBUTE_NORMAL)
2975cdf0e10cSrcweir                     nRealFlags = 0;
2976cdf0e10cSrcweir                 nFlags = (sal_Int16) (nRealFlags);
2977cdf0e10cSrcweir             }
2978cdf0e10cSrcweir             else
2979cdf0e10cSrcweir                 StarBASIC::Error( SbERR_FILE_NOT_FOUND );
2980cdf0e10cSrcweir 
2981cdf0e10cSrcweir             rPar.Get(0)->PutInteger( nFlags );
2982cdf0e10cSrcweir 
2983cdf0e10cSrcweir             return;
2984cdf0e10cSrcweir         }
2985cdf0e10cSrcweir     #endif
2986cdf0e10cSrcweir 
2987cdf0e10cSrcweir         // <-- UCB
2988cdf0e10cSrcweir         if( hasUno() )
2989cdf0e10cSrcweir         {
2990cdf0e10cSrcweir             com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
2991cdf0e10cSrcweir             if( xSFI.is() )
2992cdf0e10cSrcweir             {
2993cdf0e10cSrcweir                 try
2994cdf0e10cSrcweir                 {
2995cdf0e10cSrcweir                     String aPath = getFullPath( rPar.Get(1)->GetString() );
2996cdf0e10cSrcweir                     sal_Bool bExists = sal_False;
2997cdf0e10cSrcweir                     try { bExists = xSFI->exists( aPath ); }
2998cdf0e10cSrcweir                     catch( Exception & ) {}
2999cdf0e10cSrcweir                     if( !bExists )
3000cdf0e10cSrcweir                     {
3001cdf0e10cSrcweir                         StarBASIC::Error( SbERR_FILE_NOT_FOUND );
3002cdf0e10cSrcweir                         return;
3003cdf0e10cSrcweir                     }
3004cdf0e10cSrcweir 
3005cdf0e10cSrcweir                     sal_Bool bReadOnly = xSFI->isReadOnly( aPath );
3006cdf0e10cSrcweir                     sal_Bool bHidden = xSFI->isHidden( aPath );
3007cdf0e10cSrcweir                     sal_Bool bDirectory = xSFI->isFolder( aPath );
3008cdf0e10cSrcweir                     if( bReadOnly )
3009cdf0e10cSrcweir                         nFlags |= 0x0001; // ATTR_READONLY
3010cdf0e10cSrcweir                     if( bHidden )
3011cdf0e10cSrcweir                         nFlags |= 0x0002; // ATTR_HIDDEN
3012cdf0e10cSrcweir                     if( bDirectory )
3013cdf0e10cSrcweir                         nFlags |= 0x0010; // ATTR_DIRECTORY
3014cdf0e10cSrcweir                 }
3015cdf0e10cSrcweir                 catch( Exception & )
3016cdf0e10cSrcweir                 {
3017cdf0e10cSrcweir                     StarBASIC::Error( ERRCODE_IO_GENERAL );
3018cdf0e10cSrcweir                 }
3019cdf0e10cSrcweir             }
3020cdf0e10cSrcweir         }
3021cdf0e10cSrcweir         else
3022cdf0e10cSrcweir         // --> UCB
3023cdf0e10cSrcweir         {
3024cdf0e10cSrcweir             DirectoryItem aItem;
3025cdf0e10cSrcweir             FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( rPar.Get(1)->GetString() ), aItem );
3026cdf0e10cSrcweir             FileStatus aFileStatus( FileStatusMask_Attributes | FileStatusMask_Type );
3027cdf0e10cSrcweir             nRet = aItem.getFileStatus( aFileStatus );
3028cdf0e10cSrcweir             sal_uInt64 nAttributes = aFileStatus.getAttributes();
3029cdf0e10cSrcweir             sal_Bool bReadOnly = (nAttributes & Attribute_ReadOnly) != 0;
3030cdf0e10cSrcweir 
3031cdf0e10cSrcweir             FileStatus::Type aType = aFileStatus.getFileType();
3032cdf0e10cSrcweir             sal_Bool bDirectory = isFolder( aType );
3033cdf0e10cSrcweir             if( bReadOnly )
3034cdf0e10cSrcweir                 nFlags |= 0x0001; // ATTR_READONLY
3035cdf0e10cSrcweir             if( bDirectory )
3036cdf0e10cSrcweir                 nFlags |= 0x0010; // ATTR_DIRECTORY
3037cdf0e10cSrcweir         }
3038cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nFlags );
3039cdf0e10cSrcweir     }
3040cdf0e10cSrcweir     else
3041cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3042cdf0e10cSrcweir }
3043cdf0e10cSrcweir 
3044cdf0e10cSrcweir 
3045cdf0e10cSrcweir RTLFUNC(FileDateTime)
3046cdf0e10cSrcweir {
3047cdf0e10cSrcweir     (void)pBasic;
3048cdf0e10cSrcweir     (void)bWrite;
3049cdf0e10cSrcweir 
3050cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3051cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3052cdf0e10cSrcweir     else
3053cdf0e10cSrcweir     {
3054cdf0e10cSrcweir         // <-- UCB
3055cdf0e10cSrcweir         String aPath = rPar.Get(1)->GetString();
3056cdf0e10cSrcweir         Time aTime;
3057cdf0e10cSrcweir         Date aDate;
3058cdf0e10cSrcweir         if( hasUno() )
3059cdf0e10cSrcweir         {
3060cdf0e10cSrcweir             com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
3061cdf0e10cSrcweir             if( xSFI.is() )
3062cdf0e10cSrcweir             {
3063cdf0e10cSrcweir                 try
3064cdf0e10cSrcweir                 {
3065cdf0e10cSrcweir                     com::sun::star::util::DateTime aUnoDT = xSFI->getDateTimeModified( aPath );
3066cdf0e10cSrcweir                     aTime = Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds );
3067cdf0e10cSrcweir                     aDate = Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year );
3068cdf0e10cSrcweir                 }
3069cdf0e10cSrcweir                 catch( Exception & )
3070cdf0e10cSrcweir                 {
3071cdf0e10cSrcweir                     StarBASIC::Error( ERRCODE_IO_GENERAL );
3072cdf0e10cSrcweir                 }
3073cdf0e10cSrcweir             }
3074cdf0e10cSrcweir         }
3075cdf0e10cSrcweir         else
3076cdf0e10cSrcweir         // --> UCB
3077cdf0e10cSrcweir         {
3078cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL
3079cdf0e10cSrcweir             DirEntry aEntry( aPath );
3080cdf0e10cSrcweir             FileStat aStat( aEntry );
3081cdf0e10cSrcweir             aTime = Time( aStat.TimeModified() );
3082cdf0e10cSrcweir             aDate = Date( aStat.DateModified() );
3083cdf0e10cSrcweir #else
3084cdf0e10cSrcweir             DirectoryItem aItem;
3085cdf0e10cSrcweir             FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( aPath ), aItem );
3086cdf0e10cSrcweir             FileStatus aFileStatus( FileStatusMask_ModifyTime );
3087cdf0e10cSrcweir             nRet = aItem.getFileStatus( aFileStatus );
3088cdf0e10cSrcweir             TimeValue aTimeVal = aFileStatus.getModifyTime();
3089cdf0e10cSrcweir             oslDateTime aDT;
3090cdf0e10cSrcweir             osl_getDateTimeFromTimeValue( &aTimeVal, &aDT );
3091cdf0e10cSrcweir 
3092cdf0e10cSrcweir             aTime = Time( aDT.Hours, aDT.Minutes, aDT.Seconds, 10000000*aDT.NanoSeconds );
3093cdf0e10cSrcweir             aDate = Date( aDT.Day, aDT.Month, aDT.Year );
3094cdf0e10cSrcweir #endif
3095cdf0e10cSrcweir         }
3096cdf0e10cSrcweir 
3097cdf0e10cSrcweir         double fSerial = (double)GetDayDiff( aDate );
3098cdf0e10cSrcweir         long nSeconds = aTime.GetHour();
3099cdf0e10cSrcweir         nSeconds *= 3600;
3100cdf0e10cSrcweir         nSeconds += aTime.GetMin() * 60;
3101cdf0e10cSrcweir         nSeconds += aTime.GetSec();
3102cdf0e10cSrcweir         double nDays = ((double)nSeconds) / (double)(24.0*3600.0);
3103cdf0e10cSrcweir         fSerial += nDays;
3104cdf0e10cSrcweir 
3105cdf0e10cSrcweir         Color* pCol;
3106cdf0e10cSrcweir 
3107cdf0e10cSrcweir         // #39629 pINST pruefen, kann aus URL-Zeile gerufen werden
3108cdf0e10cSrcweir         SvNumberFormatter* pFormatter = NULL;
3109cdf0e10cSrcweir         sal_uInt32 nIndex;
3110cdf0e10cSrcweir         if( pINST )
3111cdf0e10cSrcweir         {
3112cdf0e10cSrcweir             pFormatter = pINST->GetNumberFormatter();
3113cdf0e10cSrcweir             nIndex = pINST->GetStdDateTimeIdx();
3114cdf0e10cSrcweir         }
3115cdf0e10cSrcweir         else
3116cdf0e10cSrcweir         {
3117cdf0e10cSrcweir             sal_uInt32 n;   // Dummy
3118cdf0e10cSrcweir             SbiInstance::PrepareNumberFormatter( pFormatter, n, n, nIndex );
3119cdf0e10cSrcweir         }
3120cdf0e10cSrcweir 
3121cdf0e10cSrcweir         String aRes;
3122cdf0e10cSrcweir         pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol );
3123cdf0e10cSrcweir         rPar.Get(0)->PutString( aRes );
3124cdf0e10cSrcweir 
3125cdf0e10cSrcweir         // #39629 pFormatter kann selbst angefordert sein
3126cdf0e10cSrcweir         if( !pINST )
3127cdf0e10cSrcweir             delete pFormatter;
3128cdf0e10cSrcweir     }
3129cdf0e10cSrcweir }
3130cdf0e10cSrcweir 
3131cdf0e10cSrcweir 
3132cdf0e10cSrcweir RTLFUNC(EOF)
3133cdf0e10cSrcweir {
3134cdf0e10cSrcweir     (void)pBasic;
3135cdf0e10cSrcweir     (void)bWrite;
3136cdf0e10cSrcweir 
3137cdf0e10cSrcweir     // AB 08/16/2000: No changes for UCB
3138cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3139cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3140cdf0e10cSrcweir     else
3141cdf0e10cSrcweir     {
3142cdf0e10cSrcweir         sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3143cdf0e10cSrcweir         // nChannel--;  // macht MD beim Oeffnen auch nicht
3144cdf0e10cSrcweir         SbiIoSystem* pIO = pINST->GetIoSystem();
3145cdf0e10cSrcweir         SbiStream* pSbStrm = pIO->GetStream( nChannel );
3146cdf0e10cSrcweir         if ( !pSbStrm )
3147cdf0e10cSrcweir         {
3148cdf0e10cSrcweir             StarBASIC::Error( SbERR_BAD_CHANNEL );
3149cdf0e10cSrcweir             return;
3150cdf0e10cSrcweir         }
3151cdf0e10cSrcweir         sal_Bool bIsEof;
3152cdf0e10cSrcweir         SvStream* pSvStrm = pSbStrm->GetStrm();
3153cdf0e10cSrcweir         if ( pSbStrm->IsText() )
3154cdf0e10cSrcweir         {
3155cdf0e10cSrcweir             char cBla;
3156cdf0e10cSrcweir             (*pSvStrm) >> cBla; // koennen wir noch ein Zeichen lesen
3157cdf0e10cSrcweir             bIsEof = pSvStrm->IsEof();
3158cdf0e10cSrcweir             if ( !bIsEof )
3159cdf0e10cSrcweir                 pSvStrm->SeekRel( -1 );
3160cdf0e10cSrcweir         }
3161cdf0e10cSrcweir         else
3162cdf0e10cSrcweir             bIsEof = pSvStrm->IsEof();  // fuer binaerdateien!
3163cdf0e10cSrcweir         rPar.Get(0)->PutBool( bIsEof );
3164cdf0e10cSrcweir     }
3165cdf0e10cSrcweir }
3166cdf0e10cSrcweir 
3167cdf0e10cSrcweir RTLFUNC(FileAttr)
3168cdf0e10cSrcweir {
3169cdf0e10cSrcweir     (void)pBasic;
3170cdf0e10cSrcweir     (void)bWrite;
3171cdf0e10cSrcweir 
3172cdf0e10cSrcweir     // AB 08/16/2000: No changes for UCB
3173cdf0e10cSrcweir 
3174cdf0e10cSrcweir     // #57064 Obwohl diese Funktion nicht mit DirEntry arbeitet, ist sie von
3175cdf0e10cSrcweir     // der Anpassung an virtuelle URLs nich betroffen, da sie nur auf bereits
3176cdf0e10cSrcweir     // geoeffneten Dateien arbeitet und der Name hier keine Rolle spielt.
3177cdf0e10cSrcweir 
3178cdf0e10cSrcweir     if ( rPar.Count() != 3 )
3179cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3180cdf0e10cSrcweir     else
3181cdf0e10cSrcweir     {
3182cdf0e10cSrcweir         sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3183cdf0e10cSrcweir //      nChannel--;
3184cdf0e10cSrcweir         SbiIoSystem* pIO = pINST->GetIoSystem();
3185cdf0e10cSrcweir         SbiStream* pSbStrm = pIO->GetStream( nChannel );
3186cdf0e10cSrcweir         if ( !pSbStrm )
3187cdf0e10cSrcweir         {
3188cdf0e10cSrcweir             StarBASIC::Error( SbERR_BAD_CHANNEL );
3189cdf0e10cSrcweir             return;
3190cdf0e10cSrcweir         }
3191cdf0e10cSrcweir         sal_Int16 nRet;
3192cdf0e10cSrcweir         if ( rPar.Get(2)->GetInteger() == 1 )
3193cdf0e10cSrcweir             nRet = (sal_Int16)(pSbStrm->GetMode());
3194cdf0e10cSrcweir         else
3195cdf0e10cSrcweir             nRet = 0; // System file handle not supported
3196cdf0e10cSrcweir 
3197cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nRet );
3198cdf0e10cSrcweir     }
3199cdf0e10cSrcweir }
3200cdf0e10cSrcweir RTLFUNC(Loc)
3201cdf0e10cSrcweir {
3202cdf0e10cSrcweir     (void)pBasic;
3203cdf0e10cSrcweir     (void)bWrite;
3204cdf0e10cSrcweir 
3205cdf0e10cSrcweir     // AB 08/16/2000: No changes for UCB
3206cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3207cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3208cdf0e10cSrcweir     else
3209cdf0e10cSrcweir     {
3210cdf0e10cSrcweir         sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3211cdf0e10cSrcweir         SbiIoSystem* pIO = pINST->GetIoSystem();
3212cdf0e10cSrcweir         SbiStream* pSbStrm = pIO->GetStream( nChannel );
3213cdf0e10cSrcweir         if ( !pSbStrm )
3214cdf0e10cSrcweir         {
3215cdf0e10cSrcweir             StarBASIC::Error( SbERR_BAD_CHANNEL );
3216cdf0e10cSrcweir             return;
3217cdf0e10cSrcweir         }
3218cdf0e10cSrcweir         SvStream* pSvStrm = pSbStrm->GetStrm();
3219cdf0e10cSrcweir         sal_uIntPtr nPos;
3220cdf0e10cSrcweir         if( pSbStrm->IsRandom())
3221cdf0e10cSrcweir         {
3222cdf0e10cSrcweir             short nBlockLen = pSbStrm->GetBlockLen();
3223cdf0e10cSrcweir             nPos = nBlockLen ? (pSvStrm->Tell() / nBlockLen) : 0;
3224cdf0e10cSrcweir             nPos++; // Blockpositionen beginnen bei 1
3225cdf0e10cSrcweir         }
3226cdf0e10cSrcweir         else if ( pSbStrm->IsText() )
3227cdf0e10cSrcweir             nPos = pSbStrm->GetLine();
3228cdf0e10cSrcweir         else if( pSbStrm->IsBinary() )
3229cdf0e10cSrcweir             nPos = pSvStrm->Tell();
3230cdf0e10cSrcweir         else if ( pSbStrm->IsSeq() )
3231cdf0e10cSrcweir             nPos = ( pSvStrm->Tell()+1 ) / 128;
3232cdf0e10cSrcweir         else
3233cdf0e10cSrcweir             nPos = pSvStrm->Tell();
3234cdf0e10cSrcweir         rPar.Get(0)->PutLong( (sal_Int32)nPos );
3235cdf0e10cSrcweir     }
3236cdf0e10cSrcweir }
3237cdf0e10cSrcweir 
3238cdf0e10cSrcweir RTLFUNC(Lof)
3239cdf0e10cSrcweir {
3240cdf0e10cSrcweir     (void)pBasic;
3241cdf0e10cSrcweir     (void)bWrite;
3242cdf0e10cSrcweir 
3243cdf0e10cSrcweir     // AB 08/16/2000: No changes for UCB
3244cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3245cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3246cdf0e10cSrcweir     else
3247cdf0e10cSrcweir     {
3248cdf0e10cSrcweir         sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3249cdf0e10cSrcweir         SbiIoSystem* pIO = pINST->GetIoSystem();
3250cdf0e10cSrcweir         SbiStream* pSbStrm = pIO->GetStream( nChannel );
3251cdf0e10cSrcweir         if ( !pSbStrm )
3252cdf0e10cSrcweir         {
3253cdf0e10cSrcweir             StarBASIC::Error( SbERR_BAD_CHANNEL );
3254cdf0e10cSrcweir             return;
3255cdf0e10cSrcweir         }
3256cdf0e10cSrcweir         SvStream* pSvStrm = pSbStrm->GetStrm();
3257cdf0e10cSrcweir         sal_uIntPtr nOldPos = pSvStrm->Tell();
3258cdf0e10cSrcweir         sal_uIntPtr nLen = pSvStrm->Seek( STREAM_SEEK_TO_END );
3259cdf0e10cSrcweir         pSvStrm->Seek( nOldPos );
3260cdf0e10cSrcweir         rPar.Get(0)->PutLong( (sal_Int32)nLen );
3261cdf0e10cSrcweir     }
3262cdf0e10cSrcweir }
3263cdf0e10cSrcweir 
3264cdf0e10cSrcweir 
3265cdf0e10cSrcweir RTLFUNC(Seek)
3266cdf0e10cSrcweir {
3267cdf0e10cSrcweir     (void)pBasic;
3268cdf0e10cSrcweir     (void)bWrite;
3269cdf0e10cSrcweir 
3270cdf0e10cSrcweir     // AB 08/16/2000: No changes for UCB
3271cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3272cdf0e10cSrcweir     if ( nArgs < 2 || nArgs > 3 )
3273cdf0e10cSrcweir     {
3274cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3275cdf0e10cSrcweir         return;
3276cdf0e10cSrcweir     }
3277cdf0e10cSrcweir     sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3278cdf0e10cSrcweir //  nChannel--;
3279cdf0e10cSrcweir     SbiIoSystem* pIO = pINST->GetIoSystem();
3280cdf0e10cSrcweir     SbiStream* pSbStrm = pIO->GetStream( nChannel );
3281cdf0e10cSrcweir     if ( !pSbStrm )
3282cdf0e10cSrcweir     {
3283cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_CHANNEL );
3284cdf0e10cSrcweir         return;
3285cdf0e10cSrcweir     }
3286cdf0e10cSrcweir     SvStream* pStrm = pSbStrm->GetStrm();
3287cdf0e10cSrcweir 
3288cdf0e10cSrcweir     if ( nArgs == 2 )   // Seek-Function
3289cdf0e10cSrcweir     {
3290cdf0e10cSrcweir         sal_uIntPtr nPos = pStrm->Tell();
3291cdf0e10cSrcweir         if( pSbStrm->IsRandom() )
3292cdf0e10cSrcweir             nPos = nPos / pSbStrm->GetBlockLen();
3293cdf0e10cSrcweir         nPos++; // Basic zaehlt ab 1
3294cdf0e10cSrcweir         rPar.Get(0)->PutLong( (sal_Int32)nPos );
3295cdf0e10cSrcweir     }
3296cdf0e10cSrcweir     else                // Seek-Statement
3297cdf0e10cSrcweir     {
3298cdf0e10cSrcweir         sal_Int32 nPos = rPar.Get(2)->GetLong();
3299cdf0e10cSrcweir         if ( nPos < 1 )
3300cdf0e10cSrcweir         {
3301cdf0e10cSrcweir             StarBASIC::Error( SbERR_BAD_ARGUMENT );
3302cdf0e10cSrcweir             return;
3303cdf0e10cSrcweir         }
3304cdf0e10cSrcweir         nPos--; // Basic zaehlt ab 1, SvStreams zaehlen ab 0
3305cdf0e10cSrcweir         pSbStrm->SetExpandOnWriteTo( 0 );
3306cdf0e10cSrcweir         if ( pSbStrm->IsRandom() )
3307cdf0e10cSrcweir             nPos *= pSbStrm->GetBlockLen();
3308cdf0e10cSrcweir         pStrm->Seek( (sal_uIntPtr)nPos );
3309cdf0e10cSrcweir         pSbStrm->SetExpandOnWriteTo( nPos );
3310cdf0e10cSrcweir     }
3311cdf0e10cSrcweir }
3312cdf0e10cSrcweir 
3313cdf0e10cSrcweir RTLFUNC(Format)
3314cdf0e10cSrcweir {
3315cdf0e10cSrcweir     (void)pBasic;
3316cdf0e10cSrcweir     (void)bWrite;
3317cdf0e10cSrcweir 
3318cdf0e10cSrcweir     sal_uInt16 nArgCount = (sal_uInt16)rPar.Count();
3319cdf0e10cSrcweir     if ( nArgCount < 2 || nArgCount > 3 )
3320cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3321cdf0e10cSrcweir     else
3322cdf0e10cSrcweir     {
3323cdf0e10cSrcweir         String aResult;
3324cdf0e10cSrcweir         if( nArgCount == 2 )
3325cdf0e10cSrcweir             rPar.Get(1)->Format( aResult );
3326cdf0e10cSrcweir         else
3327cdf0e10cSrcweir         {
3328cdf0e10cSrcweir             String aFmt( rPar.Get(2)->GetString() );
3329cdf0e10cSrcweir             rPar.Get(1)->Format( aResult, &aFmt );
3330cdf0e10cSrcweir         }
3331cdf0e10cSrcweir         rPar.Get(0)->PutString( aResult );
3332cdf0e10cSrcweir     }
3333cdf0e10cSrcweir }
3334cdf0e10cSrcweir 
3335cdf0e10cSrcweir RTLFUNC(Randomize)
3336cdf0e10cSrcweir {
3337cdf0e10cSrcweir     (void)pBasic;
3338cdf0e10cSrcweir     (void)bWrite;
3339cdf0e10cSrcweir 
3340cdf0e10cSrcweir     if ( rPar.Count() > 2 )
3341cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3342cdf0e10cSrcweir     sal_Int16 nSeed;
3343cdf0e10cSrcweir     if( rPar.Count() == 2 )
3344cdf0e10cSrcweir         nSeed = (sal_Int16)rPar.Get(1)->GetInteger();
3345cdf0e10cSrcweir     else
3346cdf0e10cSrcweir         nSeed = (sal_Int16)rand();
3347cdf0e10cSrcweir     srand( nSeed );
3348cdf0e10cSrcweir }
3349cdf0e10cSrcweir 
3350cdf0e10cSrcweir RTLFUNC(Rnd)
3351cdf0e10cSrcweir {
3352cdf0e10cSrcweir     (void)pBasic;
3353cdf0e10cSrcweir     (void)bWrite;
3354cdf0e10cSrcweir 
3355cdf0e10cSrcweir     if ( rPar.Count() > 2 )
3356cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3357cdf0e10cSrcweir     else
3358cdf0e10cSrcweir     {
3359cdf0e10cSrcweir         double nRand = (double)rand();
3360cdf0e10cSrcweir         nRand = ( nRand / (double)RAND_MAX );
3361cdf0e10cSrcweir         rPar.Get(0)->PutDouble( nRand );
3362cdf0e10cSrcweir     }
3363cdf0e10cSrcweir }
3364cdf0e10cSrcweir 
3365cdf0e10cSrcweir 
3366cdf0e10cSrcweir //
3367cdf0e10cSrcweir //  Syntax: Shell("Path",[ Window-Style,[ "Params", [ bSync = sal_False ]]])
3368cdf0e10cSrcweir //
3369cdf0e10cSrcweir //  WindowStyles (VBA-kompatibel):
3370cdf0e10cSrcweir //      2 == Minimized
3371cdf0e10cSrcweir //      3 == Maximized
3372cdf0e10cSrcweir //     10 == Full-Screen (Textmodus-Anwendungen OS/2, WIN95, WNT)
3373cdf0e10cSrcweir //
3374cdf0e10cSrcweir // !!!HACK der WindowStyle wird im Creator an Application::StartApp
3375cdf0e10cSrcweir //         uebergeben. Format: "xxxx2"
3376cdf0e10cSrcweir //
3377cdf0e10cSrcweir 
3378cdf0e10cSrcweir 
3379cdf0e10cSrcweir RTLFUNC(Shell)
3380cdf0e10cSrcweir {
3381cdf0e10cSrcweir     (void)pBasic;
3382cdf0e10cSrcweir     (void)bWrite;
3383cdf0e10cSrcweir 
3384cdf0e10cSrcweir     // No shell command for "virtual" portal users
3385cdf0e10cSrcweir     if( needSecurityRestrictions() )
3386cdf0e10cSrcweir     {
3387cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3388cdf0e10cSrcweir         return;
3389cdf0e10cSrcweir     }
3390cdf0e10cSrcweir 
3391cdf0e10cSrcweir     sal_uIntPtr nArgCount = rPar.Count();
3392cdf0e10cSrcweir     if ( nArgCount < 2 || nArgCount > 5 )
3393cdf0e10cSrcweir     {
3394cdf0e10cSrcweir         rPar.Get(0)->PutLong(0);
3395cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3396cdf0e10cSrcweir     }
3397cdf0e10cSrcweir     else
3398cdf0e10cSrcweir     {
3399cdf0e10cSrcweir         sal_uInt16 nOptions = vos::OProcess::TOption_SearchPath|
3400cdf0e10cSrcweir                           vos::OProcess::TOption_Detached;
3401cdf0e10cSrcweir         String aCmdLine = rPar.Get(1)->GetString();
3402cdf0e10cSrcweir         // Zusaetzliche Parameter anhaengen, es muss eh alles geparsed werden
3403cdf0e10cSrcweir         if( nArgCount >= 4 )
3404cdf0e10cSrcweir         {
3405cdf0e10cSrcweir             aCmdLine.AppendAscii( " " );
3406cdf0e10cSrcweir             aCmdLine += rPar.Get(3)->GetString();
3407cdf0e10cSrcweir         }
3408cdf0e10cSrcweir         else if( !aCmdLine.Len() )
3409cdf0e10cSrcweir         {
3410cdf0e10cSrcweir             // Spezial-Behandlung (leere Liste) vermeiden
3411cdf0e10cSrcweir             aCmdLine.AppendAscii( " " );
3412cdf0e10cSrcweir         }
3413cdf0e10cSrcweir         sal_uInt16 nLen = aCmdLine.Len();
3414cdf0e10cSrcweir 
3415cdf0e10cSrcweir         // #55735 Wenn Parameter dabei sind, muessen die abgetrennt werden
3416cdf0e10cSrcweir         // #72471 Auch die einzelnen Parameter trennen
3417cdf0e10cSrcweir         std::list<String> aTokenList;
3418cdf0e10cSrcweir         String aToken;
3419cdf0e10cSrcweir         sal_uInt16 i = 0;
3420cdf0e10cSrcweir         sal_Unicode c;
3421cdf0e10cSrcweir         while( i < nLen )
3422cdf0e10cSrcweir         {
3423cdf0e10cSrcweir             // Spaces weg
3424cdf0e10cSrcweir             for ( ;; ++i )
3425cdf0e10cSrcweir             {
3426cdf0e10cSrcweir                 c = aCmdLine.GetBuffer()[ i ];
3427cdf0e10cSrcweir                 if ( c != ' ' && c != '\t' )
3428cdf0e10cSrcweir                     break;
3429cdf0e10cSrcweir             }
3430cdf0e10cSrcweir 
3431cdf0e10cSrcweir             if( c == '\"' || c == '\'' )
3432cdf0e10cSrcweir             {
3433cdf0e10cSrcweir                 sal_uInt16 iFoundPos = aCmdLine.Search( c, i + 1 );
3434cdf0e10cSrcweir 
3435cdf0e10cSrcweir                 // Wenn nichts gefunden wurde, Rest kopieren
3436cdf0e10cSrcweir                 if( iFoundPos == STRING_NOTFOUND )
3437cdf0e10cSrcweir                 {
3438cdf0e10cSrcweir                     aToken = aCmdLine.Copy( i, STRING_LEN );
3439cdf0e10cSrcweir                     i = nLen;
3440cdf0e10cSrcweir                 }
3441cdf0e10cSrcweir                 else
3442cdf0e10cSrcweir                 {
3443cdf0e10cSrcweir                     aToken = aCmdLine.Copy( i + 1, (iFoundPos - i - 1) );
3444cdf0e10cSrcweir                     i = iFoundPos + 1;
3445cdf0e10cSrcweir                 }
3446cdf0e10cSrcweir             }
3447cdf0e10cSrcweir             else
3448cdf0e10cSrcweir             {
3449cdf0e10cSrcweir                 sal_uInt16 iFoundSpacePos = aCmdLine.Search( ' ', i );
3450cdf0e10cSrcweir                 sal_uInt16 iFoundTabPos = aCmdLine.Search( '\t', i );
3451cdf0e10cSrcweir                 sal_uInt16 iFoundPos = Min( iFoundSpacePos, iFoundTabPos );
3452cdf0e10cSrcweir 
3453cdf0e10cSrcweir                 // Wenn nichts gefunden wurde, Rest kopieren
3454cdf0e10cSrcweir                 if( iFoundPos == STRING_NOTFOUND )
3455cdf0e10cSrcweir                 {
3456cdf0e10cSrcweir                     aToken = aCmdLine.Copy( i, STRING_LEN );
3457cdf0e10cSrcweir                     i = nLen;
3458cdf0e10cSrcweir                 }
3459cdf0e10cSrcweir                 else
3460cdf0e10cSrcweir                 {
3461cdf0e10cSrcweir                     aToken = aCmdLine.Copy( i, (iFoundPos - i) );
3462cdf0e10cSrcweir                     i = iFoundPos;
3463cdf0e10cSrcweir                 }
3464cdf0e10cSrcweir             }
3465cdf0e10cSrcweir 
3466cdf0e10cSrcweir             // In die Liste uebernehmen
3467cdf0e10cSrcweir             aTokenList.push_back( aToken );
3468cdf0e10cSrcweir         }
3469cdf0e10cSrcweir         // #55735 / #72471 Ende
3470cdf0e10cSrcweir 
3471cdf0e10cSrcweir         sal_Int16 nWinStyle = 0;
3472cdf0e10cSrcweir         if( nArgCount >= 3 )
3473cdf0e10cSrcweir         {
3474cdf0e10cSrcweir             nWinStyle = rPar.Get(2)->GetInteger();
3475cdf0e10cSrcweir             switch( nWinStyle )
3476cdf0e10cSrcweir             {
3477cdf0e10cSrcweir                 case 2:
3478cdf0e10cSrcweir                     nOptions |= vos::OProcess::TOption_Minimized;
3479cdf0e10cSrcweir                     break;
3480cdf0e10cSrcweir                 case 3:
3481cdf0e10cSrcweir                     nOptions |= vos::OProcess::TOption_Maximized;
3482cdf0e10cSrcweir                     break;
3483cdf0e10cSrcweir                 case 10:
3484cdf0e10cSrcweir                     nOptions |= vos::OProcess::TOption_FullScreen;
3485cdf0e10cSrcweir                     break;
3486cdf0e10cSrcweir             }
3487cdf0e10cSrcweir 
3488cdf0e10cSrcweir             sal_Bool bSync = sal_False;
3489cdf0e10cSrcweir             if( nArgCount >= 5 )
3490cdf0e10cSrcweir                 bSync = rPar.Get(4)->GetBool();
3491cdf0e10cSrcweir             if( bSync )
3492cdf0e10cSrcweir                 nOptions |= vos::OProcess::TOption_Wait;
3493cdf0e10cSrcweir         }
3494cdf0e10cSrcweir         vos::OProcess::TProcessOption eOptions =
3495cdf0e10cSrcweir             (vos::OProcess::TProcessOption)nOptions;
3496cdf0e10cSrcweir 
3497cdf0e10cSrcweir 
3498cdf0e10cSrcweir         // #72471 Parameter aufbereiten
3499cdf0e10cSrcweir         std::list<String>::const_iterator iter = aTokenList.begin();
3500cdf0e10cSrcweir         const String& rStr = *iter;
3501cdf0e10cSrcweir         ::rtl::OUString aOUStrProg( rStr.GetBuffer(), rStr.Len() );
3502cdf0e10cSrcweir         String aOUStrProgUNC = getFullPathUNC( aOUStrProg );
3503cdf0e10cSrcweir 
3504cdf0e10cSrcweir         iter++;
3505cdf0e10cSrcweir 
3506cdf0e10cSrcweir         sal_uInt16 nParamCount = sal::static_int_cast< sal_uInt16 >(
3507cdf0e10cSrcweir             aTokenList.size() - 1 );
3508cdf0e10cSrcweir         ::rtl::OUString* pArgumentList = NULL;
3509cdf0e10cSrcweir         //const char** pParamList = NULL;
3510cdf0e10cSrcweir         if( nParamCount )
3511cdf0e10cSrcweir         {
3512cdf0e10cSrcweir             pArgumentList = new ::rtl::OUString[ nParamCount ];
3513cdf0e10cSrcweir             //pParamList = new const char*[ nParamCount ];
3514cdf0e10cSrcweir             sal_uInt16 iList = 0;
3515cdf0e10cSrcweir             while( iter != aTokenList.end() )
3516cdf0e10cSrcweir             {
3517cdf0e10cSrcweir                 const String& rParamStr = (*iter);
3518cdf0e10cSrcweir                 pArgumentList[iList++] = ::rtl::OUString( rParamStr.GetBuffer(), rParamStr.Len() );
3519cdf0e10cSrcweir                 //pParamList[iList++] = (*iter).GetStr();
3520cdf0e10cSrcweir                 iter++;
3521cdf0e10cSrcweir             }
3522cdf0e10cSrcweir         }
3523cdf0e10cSrcweir 
3524cdf0e10cSrcweir         //const char* pParams = aParams.Len() ? aParams.GetStr() : 0;
3525cdf0e10cSrcweir         vos::OProcess* pApp;
3526cdf0e10cSrcweir         pApp = new vos::OProcess( aOUStrProgUNC );
3527cdf0e10cSrcweir         sal_Bool bSucc;
3528cdf0e10cSrcweir         if( nParamCount == 0 )
3529cdf0e10cSrcweir         {
3530cdf0e10cSrcweir             bSucc = pApp->execute( eOptions ) == vos::OProcess::E_None;
3531cdf0e10cSrcweir         }
3532cdf0e10cSrcweir         else
3533cdf0e10cSrcweir         {
3534cdf0e10cSrcweir             vos::OArgumentList aArgList( pArgumentList, nParamCount );
3535cdf0e10cSrcweir             bSucc = pApp->execute( eOptions, aArgList ) == vos::OProcess::E_None;
3536cdf0e10cSrcweir         }
3537cdf0e10cSrcweir 
3538cdf0e10cSrcweir         /*
3539cdf0e10cSrcweir         if( nParamCount == 0 )
3540cdf0e10cSrcweir             pApp = new vos::OProcess( pProg );
3541cdf0e10cSrcweir         else
3542cdf0e10cSrcweir             pApp = new vos::OProcess( pProg, pParamList, nParamCount );
3543cdf0e10cSrcweir         sal_Bool bSucc = pApp->execute( eOptions ) == vos::OProcess::E_None;
3544cdf0e10cSrcweir         */
3545cdf0e10cSrcweir 
3546cdf0e10cSrcweir         delete pApp;
3547cdf0e10cSrcweir         delete[] pArgumentList;
3548cdf0e10cSrcweir         if( !bSucc )
3549cdf0e10cSrcweir             StarBASIC::Error( SbERR_FILE_NOT_FOUND );
3550cdf0e10cSrcweir         else
3551cdf0e10cSrcweir             rPar.Get(0)->PutLong( 0 );
3552cdf0e10cSrcweir     }
3553cdf0e10cSrcweir }
3554cdf0e10cSrcweir 
3555cdf0e10cSrcweir RTLFUNC(VarType)
3556cdf0e10cSrcweir {
3557cdf0e10cSrcweir     (void)pBasic;
3558cdf0e10cSrcweir     (void)bWrite;
3559cdf0e10cSrcweir 
3560cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3561cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3562cdf0e10cSrcweir     else
3563cdf0e10cSrcweir     {
3564cdf0e10cSrcweir         SbxDataType eType = rPar.Get(1)->GetType();
3565cdf0e10cSrcweir         rPar.Get(0)->PutInteger( (sal_Int16)eType );
3566cdf0e10cSrcweir     }
3567cdf0e10cSrcweir }
3568cdf0e10cSrcweir 
3569cdf0e10cSrcweir // Exported function
3570cdf0e10cSrcweir String getBasicTypeName( SbxDataType eType )
3571cdf0e10cSrcweir {
3572cdf0e10cSrcweir     static const char* pTypeNames[] =
3573cdf0e10cSrcweir     {
3574cdf0e10cSrcweir         "Empty",            // SbxEMPTY
3575cdf0e10cSrcweir         "Null",             // SbxNULL
3576cdf0e10cSrcweir         "Integer",          // SbxINTEGER
3577cdf0e10cSrcweir         "Long",             // SbxLONG
3578cdf0e10cSrcweir         "Single",           // SbxSINGLE
3579cdf0e10cSrcweir         "Double",           // SbxDOUBLE
3580cdf0e10cSrcweir         "Currency",         // SbxCURRENCY
3581cdf0e10cSrcweir         "Date",             // SbxDATE
3582cdf0e10cSrcweir         "String",           // SbxSTRING
3583cdf0e10cSrcweir         "Object",           // SbxOBJECT
3584cdf0e10cSrcweir         "Error",            // SbxERROR
3585cdf0e10cSrcweir         "Boolean",          // SbxBOOL
3586cdf0e10cSrcweir         "Variant",          // SbxVARIANT
3587cdf0e10cSrcweir         "DataObject",       // SbxDATAOBJECT
3588cdf0e10cSrcweir         "Unknown Type",     //
3589cdf0e10cSrcweir         "Unknown Type",     //
3590cdf0e10cSrcweir         "Char",             // SbxCHAR
3591cdf0e10cSrcweir         "Byte",             // SbxBYTE
3592cdf0e10cSrcweir         "UShort",           // SbxUSHORT
3593cdf0e10cSrcweir         "ULong",            // SbxULONG
3594cdf0e10cSrcweir         "Long64",           // SbxLONG64
3595cdf0e10cSrcweir         "ULong64",          // SbxULONG64
3596cdf0e10cSrcweir         "Int",              // SbxINT
3597cdf0e10cSrcweir         "UInt",             // SbxUINT
3598cdf0e10cSrcweir         "Void",             // SbxVOID
3599cdf0e10cSrcweir         "HResult",          // SbxHRESULT
3600cdf0e10cSrcweir         "Pointer",          // SbxPOINTER
3601cdf0e10cSrcweir         "DimArray",         // SbxDIMARRAY
3602cdf0e10cSrcweir         "CArray",           // SbxCARRAY
3603cdf0e10cSrcweir         "Userdef",          // SbxUSERDEF
3604cdf0e10cSrcweir         "Lpstr",            // SbxLPSTR
3605cdf0e10cSrcweir         "Lpwstr",           // SbxLPWSTR
3606cdf0e10cSrcweir         "Unknown Type",     // SbxCoreSTRING
3607cdf0e10cSrcweir         "WString",          // SbxWSTRING
3608cdf0e10cSrcweir         "WChar",            // SbxWCHAR
3609cdf0e10cSrcweir         "Int64",            // SbxSALINT64
3610cdf0e10cSrcweir         "UInt64",           // SbxSALUINT64
3611cdf0e10cSrcweir         "Decimal",          // SbxDECIMAL
3612cdf0e10cSrcweir     };
3613cdf0e10cSrcweir 
3614cdf0e10cSrcweir     int nPos = ((int)eType) & 0x0FFF;
3615cdf0e10cSrcweir     sal_uInt16 nTypeNameCount = sizeof( pTypeNames ) / sizeof( char* );
3616cdf0e10cSrcweir     if ( nPos < 0 || nPos >= nTypeNameCount )
3617cdf0e10cSrcweir         nPos = nTypeNameCount - 1;
3618cdf0e10cSrcweir     String aRetStr = String::CreateFromAscii( pTypeNames[nPos] );
3619cdf0e10cSrcweir     return aRetStr;
3620cdf0e10cSrcweir }
3621cdf0e10cSrcweir 
3622cdf0e10cSrcweir RTLFUNC(TypeName)
3623cdf0e10cSrcweir {
3624cdf0e10cSrcweir     (void)pBasic;
3625cdf0e10cSrcweir     (void)bWrite;
3626cdf0e10cSrcweir 
3627cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3628cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3629cdf0e10cSrcweir     else
3630cdf0e10cSrcweir     {
3631cdf0e10cSrcweir         SbxDataType eType = rPar.Get(1)->GetType();
3632cdf0e10cSrcweir         sal_Bool bIsArray = ( ( eType & SbxARRAY ) != 0 );
3633cdf0e10cSrcweir         String aRetStr = getBasicTypeName( eType );
3634cdf0e10cSrcweir         if( bIsArray )
3635cdf0e10cSrcweir             aRetStr.AppendAscii( "()" );
3636cdf0e10cSrcweir         rPar.Get(0)->PutString( aRetStr );
3637cdf0e10cSrcweir     }
3638cdf0e10cSrcweir }
3639cdf0e10cSrcweir 
3640cdf0e10cSrcweir RTLFUNC(Len)
3641cdf0e10cSrcweir {
3642cdf0e10cSrcweir     (void)pBasic;
3643cdf0e10cSrcweir     (void)bWrite;
3644cdf0e10cSrcweir 
3645cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3646cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3647cdf0e10cSrcweir     else
3648cdf0e10cSrcweir     {
3649cdf0e10cSrcweir         const String& rStr = rPar.Get(1)->GetString();
3650cdf0e10cSrcweir         rPar.Get(0)->PutLong( (sal_Int32)rStr.Len() );
3651cdf0e10cSrcweir     }
3652cdf0e10cSrcweir }
3653cdf0e10cSrcweir 
3654cdf0e10cSrcweir RTLFUNC(DDEInitiate)
3655cdf0e10cSrcweir {
3656cdf0e10cSrcweir     (void)pBasic;
3657cdf0e10cSrcweir     (void)bWrite;
3658cdf0e10cSrcweir 
3659cdf0e10cSrcweir     // No DDE for "virtual" portal users
3660cdf0e10cSrcweir     if( needSecurityRestrictions() )
3661cdf0e10cSrcweir     {
3662cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3663cdf0e10cSrcweir         return;
3664cdf0e10cSrcweir     }
3665cdf0e10cSrcweir 
3666cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3667cdf0e10cSrcweir     if ( nArgs != 3 )
3668cdf0e10cSrcweir     {
3669cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3670cdf0e10cSrcweir         return;
3671cdf0e10cSrcweir     }
3672cdf0e10cSrcweir     const String& rApp = rPar.Get(1)->GetString();
3673cdf0e10cSrcweir     const String& rTopic = rPar.Get(2)->GetString();
3674cdf0e10cSrcweir 
3675cdf0e10cSrcweir     SbiDdeControl* pDDE = pINST->GetDdeControl();
3676cdf0e10cSrcweir     sal_Int16 nChannel;
3677cdf0e10cSrcweir     SbError nDdeErr = pDDE->Initiate( rApp, rTopic, nChannel );
3678cdf0e10cSrcweir     if( nDdeErr )
3679cdf0e10cSrcweir         StarBASIC::Error( nDdeErr );
3680cdf0e10cSrcweir     else
3681cdf0e10cSrcweir         rPar.Get(0)->PutInteger( nChannel );
3682cdf0e10cSrcweir }
3683cdf0e10cSrcweir 
3684cdf0e10cSrcweir RTLFUNC(DDETerminate)
3685cdf0e10cSrcweir {
3686cdf0e10cSrcweir     (void)pBasic;
3687cdf0e10cSrcweir     (void)bWrite;
3688cdf0e10cSrcweir 
3689cdf0e10cSrcweir     // No DDE for "virtual" portal users
3690cdf0e10cSrcweir     if( needSecurityRestrictions() )
3691cdf0e10cSrcweir     {
3692cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3693cdf0e10cSrcweir         return;
3694cdf0e10cSrcweir     }
3695cdf0e10cSrcweir 
3696cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
3697cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3698cdf0e10cSrcweir     if ( nArgs != 2 )
3699cdf0e10cSrcweir     {
3700cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3701cdf0e10cSrcweir         return;
3702cdf0e10cSrcweir     }
3703cdf0e10cSrcweir     sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3704cdf0e10cSrcweir     SbiDdeControl* pDDE = pINST->GetDdeControl();
3705cdf0e10cSrcweir     SbError nDdeErr = pDDE->Terminate( nChannel );
3706cdf0e10cSrcweir     if( nDdeErr )
3707cdf0e10cSrcweir         StarBASIC::Error( nDdeErr );
3708cdf0e10cSrcweir }
3709cdf0e10cSrcweir 
3710cdf0e10cSrcweir RTLFUNC(DDETerminateAll)
3711cdf0e10cSrcweir {
3712cdf0e10cSrcweir     (void)pBasic;
3713cdf0e10cSrcweir     (void)bWrite;
3714cdf0e10cSrcweir 
3715cdf0e10cSrcweir     // No DDE for "virtual" portal users
3716cdf0e10cSrcweir     if( needSecurityRestrictions() )
3717cdf0e10cSrcweir     {
3718cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3719cdf0e10cSrcweir         return;
3720cdf0e10cSrcweir     }
3721cdf0e10cSrcweir 
3722cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
3723cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3724cdf0e10cSrcweir     if ( nArgs != 1 )
3725cdf0e10cSrcweir     {
3726cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3727cdf0e10cSrcweir         return;
3728cdf0e10cSrcweir     }
3729cdf0e10cSrcweir 
3730cdf0e10cSrcweir     SbiDdeControl* pDDE = pINST->GetDdeControl();
3731cdf0e10cSrcweir     SbError nDdeErr = pDDE->TerminateAll();
3732cdf0e10cSrcweir     if( nDdeErr )
3733cdf0e10cSrcweir         StarBASIC::Error( nDdeErr );
3734cdf0e10cSrcweir 
3735cdf0e10cSrcweir }
3736cdf0e10cSrcweir 
3737cdf0e10cSrcweir RTLFUNC(DDERequest)
3738cdf0e10cSrcweir {
3739cdf0e10cSrcweir     (void)pBasic;
3740cdf0e10cSrcweir     (void)bWrite;
3741cdf0e10cSrcweir 
3742cdf0e10cSrcweir     // No DDE for "virtual" portal users
3743cdf0e10cSrcweir     if( needSecurityRestrictions() )
3744cdf0e10cSrcweir     {
3745cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3746cdf0e10cSrcweir         return;
3747cdf0e10cSrcweir     }
3748cdf0e10cSrcweir 
3749cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3750cdf0e10cSrcweir     if ( nArgs != 3 )
3751cdf0e10cSrcweir     {
3752cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3753cdf0e10cSrcweir         return;
3754cdf0e10cSrcweir     }
3755cdf0e10cSrcweir     sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3756cdf0e10cSrcweir     const String& rItem = rPar.Get(2)->GetString();
3757cdf0e10cSrcweir     SbiDdeControl* pDDE = pINST->GetDdeControl();
3758cdf0e10cSrcweir     String aResult;
3759cdf0e10cSrcweir     SbError nDdeErr = pDDE->Request( nChannel, rItem, aResult );
3760cdf0e10cSrcweir     if( nDdeErr )
3761cdf0e10cSrcweir         StarBASIC::Error( nDdeErr );
3762cdf0e10cSrcweir     else
3763cdf0e10cSrcweir         rPar.Get(0)->PutString( aResult );
3764cdf0e10cSrcweir }
3765cdf0e10cSrcweir 
3766cdf0e10cSrcweir RTLFUNC(DDEExecute)
3767cdf0e10cSrcweir {
3768cdf0e10cSrcweir     (void)pBasic;
3769cdf0e10cSrcweir     (void)bWrite;
3770cdf0e10cSrcweir 
3771cdf0e10cSrcweir     // No DDE for "virtual" portal users
3772cdf0e10cSrcweir     if( needSecurityRestrictions() )
3773cdf0e10cSrcweir     {
3774cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3775cdf0e10cSrcweir         return;
3776cdf0e10cSrcweir     }
3777cdf0e10cSrcweir 
3778cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
3779cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3780cdf0e10cSrcweir     if ( nArgs != 3 )
3781cdf0e10cSrcweir     {
3782cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3783cdf0e10cSrcweir         return;
3784cdf0e10cSrcweir     }
3785cdf0e10cSrcweir     sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3786cdf0e10cSrcweir     const String& rCommand = rPar.Get(2)->GetString();
3787cdf0e10cSrcweir     SbiDdeControl* pDDE = pINST->GetDdeControl();
3788cdf0e10cSrcweir     SbError nDdeErr = pDDE->Execute( nChannel, rCommand );
3789cdf0e10cSrcweir     if( nDdeErr )
3790cdf0e10cSrcweir         StarBASIC::Error( nDdeErr );
3791cdf0e10cSrcweir }
3792cdf0e10cSrcweir 
3793cdf0e10cSrcweir RTLFUNC(DDEPoke)
3794cdf0e10cSrcweir {
3795cdf0e10cSrcweir     (void)pBasic;
3796cdf0e10cSrcweir     (void)bWrite;
3797cdf0e10cSrcweir 
3798cdf0e10cSrcweir     // No DDE for "virtual" portal users
3799cdf0e10cSrcweir     if( needSecurityRestrictions() )
3800cdf0e10cSrcweir     {
3801cdf0e10cSrcweir         StarBASIC::Error(SbERR_NOT_IMPLEMENTED);
3802cdf0e10cSrcweir         return;
3803cdf0e10cSrcweir     }
3804cdf0e10cSrcweir 
3805cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
3806cdf0e10cSrcweir     int nArgs = (int)rPar.Count();
3807cdf0e10cSrcweir     if ( nArgs != 4 )
3808cdf0e10cSrcweir     {
3809cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3810cdf0e10cSrcweir         return;
3811cdf0e10cSrcweir     }
3812cdf0e10cSrcweir     sal_Int16 nChannel = rPar.Get(1)->GetInteger();
3813cdf0e10cSrcweir     const String& rItem = rPar.Get(2)->GetString();
3814cdf0e10cSrcweir     const String& rData = rPar.Get(3)->GetString();
3815cdf0e10cSrcweir     SbiDdeControl* pDDE = pINST->GetDdeControl();
3816cdf0e10cSrcweir     SbError nDdeErr = pDDE->Poke( nChannel, rItem, rData );
3817cdf0e10cSrcweir     if( nDdeErr )
3818cdf0e10cSrcweir         StarBASIC::Error( nDdeErr );
3819cdf0e10cSrcweir }
3820cdf0e10cSrcweir 
3821cdf0e10cSrcweir 
3822cdf0e10cSrcweir RTLFUNC(FreeFile)
3823cdf0e10cSrcweir {
3824cdf0e10cSrcweir     (void)pBasic;
3825cdf0e10cSrcweir     (void)bWrite;
3826cdf0e10cSrcweir 
3827cdf0e10cSrcweir     if ( rPar.Count() != 1 )
3828cdf0e10cSrcweir     {
3829cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3830cdf0e10cSrcweir         return;
3831cdf0e10cSrcweir     }
3832cdf0e10cSrcweir     SbiIoSystem* pIO = pINST->GetIoSystem();
3833cdf0e10cSrcweir     short nChannel = 1;
3834cdf0e10cSrcweir     while( nChannel < CHANNELS )
3835cdf0e10cSrcweir     {
3836cdf0e10cSrcweir         SbiStream* pStrm = pIO->GetStream( nChannel );
3837cdf0e10cSrcweir         if( !pStrm )
3838cdf0e10cSrcweir         {
3839cdf0e10cSrcweir             rPar.Get(0)->PutInteger( nChannel );
3840cdf0e10cSrcweir             return;
3841cdf0e10cSrcweir         }
3842cdf0e10cSrcweir         nChannel++;
3843cdf0e10cSrcweir     }
3844cdf0e10cSrcweir     StarBASIC::Error( SbERR_TOO_MANY_FILES );
3845cdf0e10cSrcweir }
3846cdf0e10cSrcweir 
3847cdf0e10cSrcweir RTLFUNC(LBound)
3848cdf0e10cSrcweir {
3849cdf0e10cSrcweir     (void)pBasic;
3850cdf0e10cSrcweir     (void)bWrite;
3851cdf0e10cSrcweir 
3852cdf0e10cSrcweir     sal_uInt16 nParCount = rPar.Count();
3853cdf0e10cSrcweir     if ( nParCount != 3 && nParCount != 2 )
3854cdf0e10cSrcweir     {
3855cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3856cdf0e10cSrcweir         return;
3857cdf0e10cSrcweir     }
3858cdf0e10cSrcweir     SbxBase* pParObj = rPar.Get(1)->GetObject();
3859cdf0e10cSrcweir     SbxDimArray* pArr = PTR_CAST(SbxDimArray,pParObj);
3860cdf0e10cSrcweir     if( pArr )
3861cdf0e10cSrcweir     {
3862cdf0e10cSrcweir         sal_Int32 nLower, nUpper;
3863cdf0e10cSrcweir         short nDim = (nParCount == 3) ? (short)rPar.Get(2)->GetInteger() : 1;
3864cdf0e10cSrcweir         if( !pArr->GetDim32( nDim, nLower, nUpper ) )
3865cdf0e10cSrcweir             StarBASIC::Error( SbERR_OUT_OF_RANGE );
3866cdf0e10cSrcweir         else
3867cdf0e10cSrcweir             rPar.Get(0)->PutLong( nLower );
3868cdf0e10cSrcweir     }
3869cdf0e10cSrcweir     else
3870cdf0e10cSrcweir         StarBASIC::Error( SbERR_MUST_HAVE_DIMS );
3871cdf0e10cSrcweir }
3872cdf0e10cSrcweir 
3873cdf0e10cSrcweir RTLFUNC(UBound)
3874cdf0e10cSrcweir {
3875cdf0e10cSrcweir     (void)pBasic;
3876cdf0e10cSrcweir     (void)bWrite;
3877cdf0e10cSrcweir 
3878cdf0e10cSrcweir     sal_uInt16 nParCount = rPar.Count();
3879cdf0e10cSrcweir     if ( nParCount != 3 && nParCount != 2 )
3880cdf0e10cSrcweir     {
3881cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3882cdf0e10cSrcweir         return;
3883cdf0e10cSrcweir     }
3884cdf0e10cSrcweir 
3885cdf0e10cSrcweir     SbxBase* pParObj = rPar.Get(1)->GetObject();
3886cdf0e10cSrcweir     SbxDimArray* pArr = PTR_CAST(SbxDimArray,pParObj);
3887cdf0e10cSrcweir     if( pArr )
3888cdf0e10cSrcweir     {
3889cdf0e10cSrcweir         sal_Int32 nLower, nUpper;
3890cdf0e10cSrcweir         short nDim = (nParCount == 3) ? (short)rPar.Get(2)->GetInteger() : 1;
3891cdf0e10cSrcweir         if( !pArr->GetDim32( nDim, nLower, nUpper ) )
3892cdf0e10cSrcweir             StarBASIC::Error( SbERR_OUT_OF_RANGE );
3893cdf0e10cSrcweir         else
3894cdf0e10cSrcweir             rPar.Get(0)->PutLong( nUpper );
3895cdf0e10cSrcweir     }
3896cdf0e10cSrcweir     else
3897cdf0e10cSrcweir         StarBASIC::Error( SbERR_MUST_HAVE_DIMS );
3898cdf0e10cSrcweir }
3899cdf0e10cSrcweir 
3900cdf0e10cSrcweir RTLFUNC(RGB)
3901cdf0e10cSrcweir {
3902cdf0e10cSrcweir     (void)pBasic;
3903cdf0e10cSrcweir     (void)bWrite;
3904cdf0e10cSrcweir 
3905cdf0e10cSrcweir     if ( rPar.Count() != 4 )
3906cdf0e10cSrcweir     {
3907cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3908cdf0e10cSrcweir         return;
3909cdf0e10cSrcweir     }
3910cdf0e10cSrcweir 
3911cdf0e10cSrcweir     sal_uIntPtr nRed     = rPar.Get(1)->GetInteger() & 0xFF;
3912cdf0e10cSrcweir     sal_uIntPtr nGreen = rPar.Get(2)->GetInteger() & 0xFF;
3913cdf0e10cSrcweir     sal_uIntPtr nBlue  = rPar.Get(3)->GetInteger() & 0xFF;
3914cdf0e10cSrcweir     sal_uIntPtr nRGB;
3915cdf0e10cSrcweir 
3916cdf0e10cSrcweir     SbiInstance* pInst = pINST;
3917cdf0e10cSrcweir     bool bCompatibility = ( pInst && pInst->IsCompatibility() );
3918cdf0e10cSrcweir     if( bCompatibility )
3919cdf0e10cSrcweir     {
3920cdf0e10cSrcweir         nRGB   = (nBlue << 16) | (nGreen << 8) | nRed;
3921cdf0e10cSrcweir     }
3922cdf0e10cSrcweir     else
3923cdf0e10cSrcweir     {
3924cdf0e10cSrcweir         nRGB   = (nRed << 16) | (nGreen << 8) | nBlue;
3925cdf0e10cSrcweir     }
3926cdf0e10cSrcweir     rPar.Get(0)->PutLong( nRGB );
3927cdf0e10cSrcweir }
3928cdf0e10cSrcweir 
3929cdf0e10cSrcweir RTLFUNC(QBColor)
3930cdf0e10cSrcweir {
3931cdf0e10cSrcweir     (void)pBasic;
3932cdf0e10cSrcweir     (void)bWrite;
3933cdf0e10cSrcweir 
3934cdf0e10cSrcweir     static const sal_Int32 pRGB[] =
3935cdf0e10cSrcweir     {
3936cdf0e10cSrcweir         0x000000,
3937cdf0e10cSrcweir         0x800000,
3938cdf0e10cSrcweir         0x008000,
3939cdf0e10cSrcweir         0x808000,
3940cdf0e10cSrcweir         0x000080,
3941cdf0e10cSrcweir         0x800080,
3942cdf0e10cSrcweir         0x008080,
3943cdf0e10cSrcweir         0xC0C0C0,
3944cdf0e10cSrcweir         0x808080,
3945cdf0e10cSrcweir         0xFF0000,
3946cdf0e10cSrcweir         0x00FF00,
3947cdf0e10cSrcweir         0xFFFF00,
3948cdf0e10cSrcweir         0x0000FF,
3949cdf0e10cSrcweir         0xFF00FF,
3950cdf0e10cSrcweir         0x00FFFF,
3951cdf0e10cSrcweir         0xFFFFFF,
3952cdf0e10cSrcweir     };
3953cdf0e10cSrcweir 
3954cdf0e10cSrcweir     if ( rPar.Count() != 2 )
3955cdf0e10cSrcweir     {
3956cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3957cdf0e10cSrcweir         return;
3958cdf0e10cSrcweir     }
3959cdf0e10cSrcweir 
3960cdf0e10cSrcweir     sal_Int16 nCol = rPar.Get(1)->GetInteger();
3961cdf0e10cSrcweir     if( nCol < 0 || nCol > 15 )
3962cdf0e10cSrcweir     {
3963cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3964cdf0e10cSrcweir         return;
3965cdf0e10cSrcweir     }
3966cdf0e10cSrcweir     sal_Int32 nRGB = pRGB[ nCol ];
3967cdf0e10cSrcweir     rPar.Get(0)->PutLong( nRGB );
3968cdf0e10cSrcweir }
3969cdf0e10cSrcweir 
3970cdf0e10cSrcweir // StrConv(string, conversion, LCID)
3971cdf0e10cSrcweir RTLFUNC(StrConv)
3972cdf0e10cSrcweir {
3973cdf0e10cSrcweir     (void)pBasic;
3974cdf0e10cSrcweir     (void)bWrite;
3975cdf0e10cSrcweir 
3976cdf0e10cSrcweir     sal_uIntPtr nArgCount = rPar.Count()-1;
3977cdf0e10cSrcweir     if( nArgCount < 2 || nArgCount > 3 )
3978cdf0e10cSrcweir     {
3979cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
3980cdf0e10cSrcweir         return;
3981cdf0e10cSrcweir     }
3982cdf0e10cSrcweir 
3983cdf0e10cSrcweir     String aOldStr = rPar.Get(1)->GetString();
3984cdf0e10cSrcweir     sal_Int32 nConversion = rPar.Get(2)->GetLong();
3985cdf0e10cSrcweir 
3986cdf0e10cSrcweir     sal_uInt16 nLanguage = LANGUAGE_SYSTEM;
3987cdf0e10cSrcweir     if( nArgCount == 3 )
3988cdf0e10cSrcweir     {
3989cdf0e10cSrcweir         // LCID not supported now
3990cdf0e10cSrcweir         //nLanguage = rPar.Get(3)->GetInteger();
3991cdf0e10cSrcweir     }
3992cdf0e10cSrcweir 
3993cdf0e10cSrcweir     sal_uInt16 nOldLen = aOldStr.Len();
3994cdf0e10cSrcweir     if( nOldLen == 0 )
3995cdf0e10cSrcweir     {
3996cdf0e10cSrcweir         // null string,return
3997cdf0e10cSrcweir         rPar.Get(0)->PutString(aOldStr);
3998cdf0e10cSrcweir         return;
3999cdf0e10cSrcweir     }
4000cdf0e10cSrcweir 
4001cdf0e10cSrcweir     sal_Int32 nType = 0;
4002cdf0e10cSrcweir     if ( (nConversion & 0x03) == 3 ) //  vbProperCase
4003cdf0e10cSrcweir     {
4004cdf0e10cSrcweir         CharClass& rCharClass = GetCharClass();
4005cdf0e10cSrcweir         aOldStr = rCharClass.toTitle( aOldStr.ToLowerAscii(), 0, nOldLen );
4006cdf0e10cSrcweir     }
4007cdf0e10cSrcweir     else if ( (nConversion & 0x01) == 1 ) // vbUpperCase
4008cdf0e10cSrcweir         nType |= ::com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE;
4009cdf0e10cSrcweir     else if ( (nConversion & 0x02) == 2 ) // vbLowerCase
4010cdf0e10cSrcweir         nType |= ::com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE;
4011cdf0e10cSrcweir 
4012cdf0e10cSrcweir     if ( (nConversion & 0x04) == 4 ) // vbWide
4013cdf0e10cSrcweir         nType |= ::com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH;
4014cdf0e10cSrcweir     else if ( (nConversion & 0x08) == 8 ) // vbNarrow
4015cdf0e10cSrcweir         nType |= ::com::sun::star::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH;
4016cdf0e10cSrcweir 
4017cdf0e10cSrcweir     if ( (nConversion & 0x10) == 16) // vbKatakana
4018cdf0e10cSrcweir         nType |= ::com::sun::star::i18n::TransliterationModules_HIRAGANA_KATAKANA;
4019cdf0e10cSrcweir     else if ( (nConversion & 0x20) == 32 ) // vbHiragana
4020cdf0e10cSrcweir         nType |= ::com::sun::star::i18n::TransliterationModules_KATAKANA_HIRAGANA;
4021cdf0e10cSrcweir 
4022cdf0e10cSrcweir     String aNewStr( aOldStr );
4023cdf0e10cSrcweir     if( nType != 0 )
4024cdf0e10cSrcweir     {
4025cdf0e10cSrcweir         com::sun::star::uno::Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
4026cdf0e10cSrcweir         ::utl::TransliterationWrapper aTransliterationWrapper( xSMgr,nType );
4027cdf0e10cSrcweir         com::sun::star::uno::Sequence<sal_Int32> aOffsets;
4028cdf0e10cSrcweir         aTransliterationWrapper.loadModuleIfNeeded( nLanguage );
4029cdf0e10cSrcweir         aNewStr = aTransliterationWrapper.transliterate( aOldStr, nLanguage, 0, nOldLen, &aOffsets );
4030cdf0e10cSrcweir     }
4031cdf0e10cSrcweir 
4032cdf0e10cSrcweir     if ( (nConversion & 0x40) == 64 ) // vbUnicode
4033cdf0e10cSrcweir     {
4034cdf0e10cSrcweir         // convert the string to byte string, preserving unicode (2 bytes per character)
4035cdf0e10cSrcweir         sal_uInt16 nSize = aNewStr.Len()*2;
4036cdf0e10cSrcweir         const sal_Unicode* pSrc = aNewStr.GetBuffer();
4037cdf0e10cSrcweir         sal_Char* pChar = new sal_Char[nSize+1];
4038cdf0e10cSrcweir         for( sal_uInt16 i=0; i < nSize; i++ )
4039cdf0e10cSrcweir         {
4040cdf0e10cSrcweir             pChar[i] = static_cast< sal_Char >( i%2 ? ((*pSrc) >> 8) & 0xff : (*pSrc) & 0xff );
4041cdf0e10cSrcweir             if( i%2 )
4042cdf0e10cSrcweir                 pSrc++;
4043cdf0e10cSrcweir         }
4044cdf0e10cSrcweir         pChar[nSize] = '\0';
4045cdf0e10cSrcweir         ::rtl::OString aOStr(pChar);
4046cdf0e10cSrcweir 
4047cdf0e10cSrcweir         // there is no concept about default codepage in unix. so it is incorrectly in unix
4048cdf0e10cSrcweir         ::rtl::OUString aOUStr = ::rtl::OStringToOUString(aOStr, osl_getThreadTextEncoding());
4049cdf0e10cSrcweir         aNewStr = String(aOUStr);
4050cdf0e10cSrcweir         rPar.Get(0)->PutString( aNewStr );
4051cdf0e10cSrcweir         return;
4052cdf0e10cSrcweir     }
4053cdf0e10cSrcweir     else if ( (nConversion & 0x80) == 128 ) // vbFromUnicode
4054cdf0e10cSrcweir     {
4055cdf0e10cSrcweir         ::rtl::OUString aOUStr(aNewStr);
4056cdf0e10cSrcweir         // there is no concept about default codepage in unix. so it is incorrectly in unix
4057cdf0e10cSrcweir         ::rtl::OString aOStr = ::rtl::OUStringToOString(aNewStr,osl_getThreadTextEncoding());
4058cdf0e10cSrcweir         const sal_Char* pChar = aOStr.getStr();
4059cdf0e10cSrcweir         sal_uInt16 nArraySize = static_cast< sal_uInt16 >( aOStr.getLength() );
4060cdf0e10cSrcweir         SbxDimArray* pArray = new SbxDimArray(SbxBYTE);
4061cdf0e10cSrcweir         bool bIncIndex = (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() );
4062cdf0e10cSrcweir         if(nArraySize)
4063cdf0e10cSrcweir         {
4064cdf0e10cSrcweir             if( bIncIndex )
4065cdf0e10cSrcweir                 pArray->AddDim( 1, nArraySize );
4066cdf0e10cSrcweir             else
4067cdf0e10cSrcweir                 pArray->AddDim( 0, nArraySize-1 );
4068cdf0e10cSrcweir         }
4069cdf0e10cSrcweir         else
4070cdf0e10cSrcweir         {
4071cdf0e10cSrcweir             pArray->unoAddDim( 0, -1 );
4072cdf0e10cSrcweir         }
4073cdf0e10cSrcweir 
4074cdf0e10cSrcweir         for( sal_uInt16 i=0; i< nArraySize; i++)
4075cdf0e10cSrcweir         {
4076cdf0e10cSrcweir             SbxVariable* pNew = new SbxVariable( SbxBYTE );
4077cdf0e10cSrcweir             pNew->PutByte(*pChar);
4078cdf0e10cSrcweir             pChar++;
4079cdf0e10cSrcweir             pNew->SetFlag( SBX_WRITE );
4080cdf0e10cSrcweir             short index = i;
4081cdf0e10cSrcweir             if( bIncIndex )
4082cdf0e10cSrcweir                 ++index;
4083cdf0e10cSrcweir             pArray->Put( pNew, &index );
4084cdf0e10cSrcweir         }
4085cdf0e10cSrcweir 
4086cdf0e10cSrcweir         SbxVariableRef refVar = rPar.Get(0);
4087cdf0e10cSrcweir         sal_uInt16 nFlags = refVar->GetFlags();
4088cdf0e10cSrcweir         refVar->ResetFlag( SBX_FIXED );
4089cdf0e10cSrcweir         refVar->PutObject( pArray );
4090cdf0e10cSrcweir         refVar->SetFlags( nFlags );
4091cdf0e10cSrcweir         refVar->SetParameters( NULL );
4092cdf0e10cSrcweir         return;
4093cdf0e10cSrcweir     }
4094cdf0e10cSrcweir 
4095cdf0e10cSrcweir     rPar.Get(0)->PutString(aNewStr);
4096cdf0e10cSrcweir }
4097cdf0e10cSrcweir 
4098cdf0e10cSrcweir 
4099cdf0e10cSrcweir RTLFUNC(Beep)
4100cdf0e10cSrcweir {
4101cdf0e10cSrcweir     (void)pBasic;
4102cdf0e10cSrcweir     (void)bWrite;
4103cdf0e10cSrcweir 
4104cdf0e10cSrcweir     if ( rPar.Count() != 1 )
4105cdf0e10cSrcweir     {
4106cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4107cdf0e10cSrcweir         return;
4108cdf0e10cSrcweir     }
4109cdf0e10cSrcweir     Sound::Beep();
4110cdf0e10cSrcweir }
4111cdf0e10cSrcweir 
4112cdf0e10cSrcweir RTLFUNC(Load)
4113cdf0e10cSrcweir {
4114cdf0e10cSrcweir     (void)pBasic;
4115cdf0e10cSrcweir     (void)bWrite;
4116cdf0e10cSrcweir 
4117cdf0e10cSrcweir     if( rPar.Count() != 2 )
4118cdf0e10cSrcweir     {
4119cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4120cdf0e10cSrcweir         return;
4121cdf0e10cSrcweir     }
4122cdf0e10cSrcweir 
4123cdf0e10cSrcweir     // Diesen Call einfach an das Object weiterreichen
4124cdf0e10cSrcweir     SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
4125cdf0e10cSrcweir     if ( pObj )
4126cdf0e10cSrcweir     {
4127cdf0e10cSrcweir         if( pObj->IsA( TYPE( SbUserFormModule ) ) )
4128cdf0e10cSrcweir         {
4129cdf0e10cSrcweir             ((SbUserFormModule*)pObj)->Load();
4130cdf0e10cSrcweir         }
4131cdf0e10cSrcweir         else if( pObj->IsA( TYPE( SbxObject ) ) )
4132cdf0e10cSrcweir         {
4133cdf0e10cSrcweir             SbxVariable* pVar = ((SbxObject*)pObj)->
4134cdf0e10cSrcweir                 Find( String( RTL_CONSTASCII_USTRINGPARAM("Load") ), SbxCLASS_METHOD );
4135cdf0e10cSrcweir             if( pVar )
4136cdf0e10cSrcweir                 pVar->GetInteger();
4137cdf0e10cSrcweir         }
4138cdf0e10cSrcweir     }
4139cdf0e10cSrcweir }
4140cdf0e10cSrcweir 
4141cdf0e10cSrcweir RTLFUNC(Unload)
4142cdf0e10cSrcweir {
4143cdf0e10cSrcweir     (void)pBasic;
4144cdf0e10cSrcweir     (void)bWrite;
4145cdf0e10cSrcweir 
4146cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
4147cdf0e10cSrcweir     if( rPar.Count() != 2 )
4148cdf0e10cSrcweir     {
4149cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4150cdf0e10cSrcweir         return;
4151cdf0e10cSrcweir     }
4152cdf0e10cSrcweir 
4153cdf0e10cSrcweir     // Diesen Call einfach an das Object weitereichen
4154cdf0e10cSrcweir     SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
4155cdf0e10cSrcweir     if ( pObj )
4156cdf0e10cSrcweir     {
4157cdf0e10cSrcweir         if( pObj->IsA( TYPE( SbUserFormModule ) ) )
4158cdf0e10cSrcweir         {
4159cdf0e10cSrcweir             SbUserFormModule* pFormModule = ( SbUserFormModule* )pObj;
4160cdf0e10cSrcweir             pFormModule->Unload();
4161cdf0e10cSrcweir         }
4162cdf0e10cSrcweir         else if( pObj->IsA( TYPE( SbxObject ) ) )
4163cdf0e10cSrcweir         {
4164cdf0e10cSrcweir             SbxVariable* pVar = ((SbxObject*)pObj)->
4165cdf0e10cSrcweir                 Find( String( RTL_CONSTASCII_USTRINGPARAM("Unload") ), SbxCLASS_METHOD );
4166cdf0e10cSrcweir             if( pVar )
4167cdf0e10cSrcweir                 pVar->GetInteger();
4168cdf0e10cSrcweir         }
4169cdf0e10cSrcweir     }
4170cdf0e10cSrcweir }
4171cdf0e10cSrcweir 
4172cdf0e10cSrcweir RTLFUNC(LoadPicture)
4173cdf0e10cSrcweir {
4174cdf0e10cSrcweir     (void)pBasic;
4175cdf0e10cSrcweir     (void)bWrite;
4176cdf0e10cSrcweir 
4177cdf0e10cSrcweir     if( rPar.Count() != 2 )
4178cdf0e10cSrcweir     {
4179cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4180cdf0e10cSrcweir         return;
4181cdf0e10cSrcweir     }
4182cdf0e10cSrcweir 
4183cdf0e10cSrcweir     String aFileURL = getFullPath( rPar.Get(1)->GetString() );
4184cdf0e10cSrcweir     SvStream* pStream = utl::UcbStreamHelper::CreateStream( aFileURL, STREAM_READ );
4185cdf0e10cSrcweir     if( pStream != NULL )
4186cdf0e10cSrcweir     {
4187cdf0e10cSrcweir         Bitmap aBmp;
418845fd3b9aSArmin Le Grand         ReadDIB(aBmp, *pStream, true);
4189cdf0e10cSrcweir         Graphic aGraphic(aBmp);
4190cdf0e10cSrcweir 
4191cdf0e10cSrcweir         SbxObjectRef xRef = new SbStdPicture;
4192cdf0e10cSrcweir         ((SbStdPicture*)(SbxObject*)xRef)->SetGraphic( aGraphic );
4193cdf0e10cSrcweir         rPar.Get(0)->PutObject( xRef );
4194cdf0e10cSrcweir     }
4195cdf0e10cSrcweir     delete pStream;
4196cdf0e10cSrcweir }
4197cdf0e10cSrcweir 
4198cdf0e10cSrcweir RTLFUNC(SavePicture)
4199cdf0e10cSrcweir {
4200cdf0e10cSrcweir     (void)pBasic;
4201cdf0e10cSrcweir     (void)bWrite;
4202cdf0e10cSrcweir 
4203cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
4204cdf0e10cSrcweir     if( rPar.Count() != 3 )
4205cdf0e10cSrcweir     {
4206cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4207cdf0e10cSrcweir         return;
4208cdf0e10cSrcweir     }
4209cdf0e10cSrcweir 
4210cdf0e10cSrcweir     SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
4211cdf0e10cSrcweir     if( pObj->IsA( TYPE( SbStdPicture ) ) )
4212cdf0e10cSrcweir     {
4213cdf0e10cSrcweir         SvFileStream aOStream( rPar.Get(2)->GetString(), STREAM_WRITE | STREAM_TRUNC );
4214cdf0e10cSrcweir         Graphic aGraphic = ((SbStdPicture*)pObj)->GetGraphic();
4215cdf0e10cSrcweir         aOStream << aGraphic;
4216cdf0e10cSrcweir     }
4217cdf0e10cSrcweir }
4218cdf0e10cSrcweir 
4219cdf0e10cSrcweir 
4220cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
4221cdf0e10cSrcweir 
4222cdf0e10cSrcweir RTLFUNC(AboutStarBasic)
4223cdf0e10cSrcweir {
4224cdf0e10cSrcweir     (void)pBasic;
4225cdf0e10cSrcweir     (void)bWrite;
4226cdf0e10cSrcweir     (void)rPar;
4227cdf0e10cSrcweir }
4228cdf0e10cSrcweir 
4229cdf0e10cSrcweir RTLFUNC(MsgBox)
4230cdf0e10cSrcweir {
4231cdf0e10cSrcweir     (void)pBasic;
4232cdf0e10cSrcweir     (void)bWrite;
4233cdf0e10cSrcweir 
4234cdf0e10cSrcweir     static const WinBits nStyleMap[] =
4235cdf0e10cSrcweir     {
4236cdf0e10cSrcweir         WB_OK,              // MB_OK
4237cdf0e10cSrcweir         WB_OK_CANCEL,       // MB_OKCANCEL
4238cdf0e10cSrcweir         WB_ABORT_RETRY_IGNORE,    // MB_ABORTRETRYIGNORE
4239cdf0e10cSrcweir         WB_YES_NO_CANCEL,   // MB_YESNOCANCEL
4240cdf0e10cSrcweir         WB_YES_NO,          // MB_YESNO
4241cdf0e10cSrcweir         WB_RETRY_CANCEL     // MB_RETRYCANCEL
4242cdf0e10cSrcweir     };
4243cdf0e10cSrcweir     static const sal_Int16 nButtonMap[] =
4244cdf0e10cSrcweir     {
4245cdf0e10cSrcweir         2, // #define RET_CANCEL sal_False
4246cdf0e10cSrcweir         1, // #define RET_OK     sal_True
4247cdf0e10cSrcweir         6, // #define RET_YES    2
4248cdf0e10cSrcweir         7, // #define RET_NO     3
4249cdf0e10cSrcweir         4  // #define RET_RETRY  4
4250cdf0e10cSrcweir     };
4251cdf0e10cSrcweir 
4252cdf0e10cSrcweir 
4253cdf0e10cSrcweir     sal_uInt16 nArgCount = (sal_uInt16)rPar.Count();
4254cdf0e10cSrcweir     if( nArgCount < 2 || nArgCount > 6 )
4255cdf0e10cSrcweir     {
4256cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4257cdf0e10cSrcweir         return;
4258cdf0e10cSrcweir     }
4259cdf0e10cSrcweir     WinBits nWinBits;
4260cdf0e10cSrcweir     WinBits nType = 0; // MB_OK
4261cdf0e10cSrcweir     if( nArgCount >= 3 )
4262cdf0e10cSrcweir         nType = (WinBits)rPar.Get(2)->GetInteger();
4263cdf0e10cSrcweir     WinBits nStyle = nType;
4264cdf0e10cSrcweir     nStyle &= 15; // Bits 4-16 loeschen
4265cdf0e10cSrcweir     if( nStyle > 5 )
4266cdf0e10cSrcweir         nStyle = 0;
4267cdf0e10cSrcweir 
4268cdf0e10cSrcweir     nWinBits = nStyleMap[ nStyle ];
4269cdf0e10cSrcweir 
4270cdf0e10cSrcweir     WinBits nWinDefBits;
4271cdf0e10cSrcweir     nWinDefBits = (WB_DEF_OK | WB_DEF_RETRY | WB_DEF_YES);
4272cdf0e10cSrcweir     if( nType & 256 )
4273cdf0e10cSrcweir     {
4274cdf0e10cSrcweir         if( nStyle == 5 )
4275cdf0e10cSrcweir             nWinDefBits = WB_DEF_CANCEL;
4276cdf0e10cSrcweir         else if( nStyle == 2 )
4277cdf0e10cSrcweir             nWinDefBits = WB_DEF_RETRY;
4278cdf0e10cSrcweir         else
4279cdf0e10cSrcweir             nWinDefBits = (WB_DEF_CANCEL | WB_DEF_RETRY | WB_DEF_NO);
4280cdf0e10cSrcweir     }
4281cdf0e10cSrcweir     else if( nType & 512 )
4282cdf0e10cSrcweir     {
4283cdf0e10cSrcweir         if( nStyle == 2)
4284cdf0e10cSrcweir             nWinDefBits = WB_DEF_IGNORE;
4285cdf0e10cSrcweir         else
4286cdf0e10cSrcweir             nWinDefBits = WB_DEF_CANCEL;
4287cdf0e10cSrcweir     }
4288cdf0e10cSrcweir     else if( nStyle == 2)
4289cdf0e10cSrcweir         nWinDefBits = WB_DEF_CANCEL;
4290cdf0e10cSrcweir     nWinBits |= nWinDefBits;
4291cdf0e10cSrcweir 
4292cdf0e10cSrcweir     String aMsg = rPar.Get(1)->GetString();
4293cdf0e10cSrcweir     String aTitle;
4294cdf0e10cSrcweir     if( nArgCount >= 4 )
4295cdf0e10cSrcweir         aTitle = rPar.Get(3)->GetString();
4296cdf0e10cSrcweir     else
4297cdf0e10cSrcweir         aTitle = GetpApp()->GetAppName();
4298cdf0e10cSrcweir 
4299cdf0e10cSrcweir     nType &= (16+32+64);
4300cdf0e10cSrcweir     MessBox* pBox = 0;
4301cdf0e10cSrcweir     Window* pParent = GetpApp()->GetDefDialogParent();
4302cdf0e10cSrcweir     switch( nType )
4303cdf0e10cSrcweir     {
4304cdf0e10cSrcweir         case 16:
4305cdf0e10cSrcweir             pBox = new ErrorBox( pParent, nWinBits, aMsg );
4306cdf0e10cSrcweir             break;
4307cdf0e10cSrcweir         case 32:
4308cdf0e10cSrcweir             pBox = new QueryBox( pParent, nWinBits, aMsg );
4309cdf0e10cSrcweir             break;
4310cdf0e10cSrcweir         case 48:
4311cdf0e10cSrcweir             pBox = new WarningBox( pParent, nWinBits, aMsg );
4312cdf0e10cSrcweir             break;
4313cdf0e10cSrcweir         case 64:
4314ae642d40SHerbert Dürr             pBox = new InfoBox( pParent, nWinBits, aMsg );
4315cdf0e10cSrcweir             break;
4316cdf0e10cSrcweir         default:
4317cdf0e10cSrcweir             pBox = new MessBox( pParent, nWinBits, aTitle, aMsg );
4318cdf0e10cSrcweir     }
4319cdf0e10cSrcweir     pBox->SetText( aTitle );
4320cdf0e10cSrcweir     sal_uInt16 nRet = (sal_uInt16)pBox->Execute();
4321cdf0e10cSrcweir     if( nRet == sal_True )
4322cdf0e10cSrcweir         nRet = 1;
4323cdf0e10cSrcweir 
4324cdf0e10cSrcweir     sal_Int16 nMappedRet;
4325cdf0e10cSrcweir     if( nStyle == 2 )
4326cdf0e10cSrcweir     {
4327cdf0e10cSrcweir         nMappedRet = nRet;
4328cdf0e10cSrcweir         if( nMappedRet == 0 )
4329cdf0e10cSrcweir             nMappedRet = 3; // Abort
4330cdf0e10cSrcweir     }
4331cdf0e10cSrcweir     else
4332cdf0e10cSrcweir         nMappedRet = nButtonMap[ nRet ];
4333cdf0e10cSrcweir 
4334cdf0e10cSrcweir     rPar.Get(0)->PutInteger( nMappedRet );
4335cdf0e10cSrcweir     delete pBox;
4336cdf0e10cSrcweir }
4337cdf0e10cSrcweir 
4338cdf0e10cSrcweir RTLFUNC(SetAttr) // JSM
4339cdf0e10cSrcweir {
4340cdf0e10cSrcweir     (void)pBasic;
4341cdf0e10cSrcweir     (void)bWrite;
4342cdf0e10cSrcweir 
4343cdf0e10cSrcweir     rPar.Get(0)->PutEmpty();
4344cdf0e10cSrcweir     if ( rPar.Count() == 3 )
4345cdf0e10cSrcweir     {
4346cdf0e10cSrcweir         String aStr = rPar.Get(1)->GetString();
4347cdf0e10cSrcweir         sal_Int16 nFlags = rPar.Get(2)->GetInteger();
4348cdf0e10cSrcweir 
4349cdf0e10cSrcweir         // <-- UCB
4350cdf0e10cSrcweir         if( hasUno() )
4351cdf0e10cSrcweir         {
4352cdf0e10cSrcweir             com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
4353cdf0e10cSrcweir             if( xSFI.is() )
4354cdf0e10cSrcweir             {
4355cdf0e10cSrcweir                 try
4356cdf0e10cSrcweir                 {
4357cdf0e10cSrcweir                     sal_Bool bReadOnly = (nFlags & 0x0001) != 0; // ATTR_READONLY
4358cdf0e10cSrcweir                     xSFI->setReadOnly( aStr, bReadOnly );
4359cdf0e10cSrcweir                     sal_Bool bHidden   = (nFlags & 0x0002) != 0; // ATTR_HIDDEN
4360cdf0e10cSrcweir                     xSFI->setHidden( aStr, bHidden );
4361cdf0e10cSrcweir                 }
4362cdf0e10cSrcweir                 catch( Exception & )
4363cdf0e10cSrcweir                 {
4364cdf0e10cSrcweir                     StarBASIC::Error( ERRCODE_IO_GENERAL );
4365cdf0e10cSrcweir                 }
4366cdf0e10cSrcweir             }
4367cdf0e10cSrcweir         }
4368cdf0e10cSrcweir         else
4369cdf0e10cSrcweir         // --> UCB
4370cdf0e10cSrcweir         {
4371cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL
4372cdf0e10cSrcweir             // #57064 Bei virtuellen URLs den Real-Path extrahieren
4373cdf0e10cSrcweir             DirEntry aEntry( aStr );
4374cdf0e10cSrcweir             String aFile = aEntry.GetFull();
4375cdf0e10cSrcweir             ByteString aByteFile( aFile, gsl_getSystemTextEncoding() );
4376cdf0e10cSrcweir     #ifdef WNT
4377cdf0e10cSrcweir             if (!SetFileAttributes (aByteFile.GetBuffer(),(DWORD)nFlags))
4378cdf0e10cSrcweir                 StarBASIC::Error(SbERR_FILE_NOT_FOUND);
4379cdf0e10cSrcweir     #endif
4380cdf0e10cSrcweir     #ifdef OS2
4381cdf0e10cSrcweir             FILESTATUS3 aFileStatus;
4382cdf0e10cSrcweir             APIRET rc = DosQueryPathInfo(aByteFile.GetBuffer(),1,
4383cdf0e10cSrcweir                                          &aFileStatus,sizeof(FILESTATUS3));
4384cdf0e10cSrcweir             if (!rc)
4385cdf0e10cSrcweir             {
4386cdf0e10cSrcweir                 if (aFileStatus.attrFile != nFlags)
4387cdf0e10cSrcweir                 {
4388cdf0e10cSrcweir                     aFileStatus.attrFile = nFlags;
4389cdf0e10cSrcweir                     rc = DosSetPathInfo(aFile.GetStr(),1,
4390cdf0e10cSrcweir                                         &aFileStatus,sizeof(FILESTATUS3),0);
4391cdf0e10cSrcweir                     if (rc)
4392cdf0e10cSrcweir                         StarBASIC::Error( SbERR_FILE_NOT_FOUND );
4393cdf0e10cSrcweir                 }
4394cdf0e10cSrcweir             }
4395cdf0e10cSrcweir             else
4396cdf0e10cSrcweir                 StarBASIC::Error( SbERR_FILE_NOT_FOUND );
4397cdf0e10cSrcweir     #endif
4398cdf0e10cSrcweir #else
4399cdf0e10cSrcweir             // Not implemented
4400cdf0e10cSrcweir #endif
4401cdf0e10cSrcweir         }
4402cdf0e10cSrcweir     }
4403cdf0e10cSrcweir     else
4404cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4405cdf0e10cSrcweir }
4406cdf0e10cSrcweir 
4407cdf0e10cSrcweir RTLFUNC(Reset)  // JSM
4408cdf0e10cSrcweir {
4409cdf0e10cSrcweir     (void)pBasic;
4410cdf0e10cSrcweir     (void)bWrite;
4411cdf0e10cSrcweir     (void)rPar;
4412cdf0e10cSrcweir 
4413cdf0e10cSrcweir     SbiIoSystem* pIO = pINST->GetIoSystem();
4414cdf0e10cSrcweir     if (pIO)
4415cdf0e10cSrcweir         pIO->CloseAll();
4416cdf0e10cSrcweir }
4417cdf0e10cSrcweir 
4418cdf0e10cSrcweir RTLFUNC(DumpAllObjects)
4419cdf0e10cSrcweir {
4420cdf0e10cSrcweir     (void)pBasic;
4421cdf0e10cSrcweir     (void)bWrite;
4422cdf0e10cSrcweir 
4423cdf0e10cSrcweir     sal_uInt16 nArgCount = (sal_uInt16)rPar.Count();
4424cdf0e10cSrcweir     if( nArgCount < 2 || nArgCount > 3 )
4425cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4426cdf0e10cSrcweir     else if( !pBasic )
4427cdf0e10cSrcweir         StarBASIC::Error( SbERR_INTERNAL_ERROR );
4428cdf0e10cSrcweir     else
4429cdf0e10cSrcweir     {
4430cdf0e10cSrcweir         SbxObject* p = pBasic;
4431cdf0e10cSrcweir         while( p->GetParent() )
4432cdf0e10cSrcweir             p = p->GetParent();
4433cdf0e10cSrcweir         SvFileStream aStrm( rPar.Get( 1 )->GetString(),
4434cdf0e10cSrcweir                             STREAM_WRITE | STREAM_TRUNC );
4435cdf0e10cSrcweir         p->Dump( aStrm, rPar.Get( 2 )->GetBool() );
4436cdf0e10cSrcweir         aStrm.Close();
4437cdf0e10cSrcweir         if( aStrm.GetError() != SVSTREAM_OK )
4438cdf0e10cSrcweir             StarBASIC::Error( SbERR_IO_ERROR );
4439cdf0e10cSrcweir     }
4440cdf0e10cSrcweir }
4441cdf0e10cSrcweir 
4442cdf0e10cSrcweir 
4443cdf0e10cSrcweir RTLFUNC(FileExists)
4444cdf0e10cSrcweir {
4445cdf0e10cSrcweir     (void)pBasic;
4446cdf0e10cSrcweir     (void)bWrite;
4447cdf0e10cSrcweir 
4448cdf0e10cSrcweir     if ( rPar.Count() == 2 )
4449cdf0e10cSrcweir     {
4450cdf0e10cSrcweir         String aStr = rPar.Get(1)->GetString();
4451cdf0e10cSrcweir         sal_Bool bExists = sal_False;
4452cdf0e10cSrcweir 
4453cdf0e10cSrcweir         // <-- UCB
4454cdf0e10cSrcweir         if( hasUno() )
4455cdf0e10cSrcweir         {
4456cdf0e10cSrcweir             com::sun::star::uno::Reference< XSimpleFileAccess3 > xSFI = getFileAccess();
4457cdf0e10cSrcweir             if( xSFI.is() )
4458cdf0e10cSrcweir             {
4459cdf0e10cSrcweir                 try
4460cdf0e10cSrcweir                 {
4461cdf0e10cSrcweir                     bExists = xSFI->exists( aStr );
4462cdf0e10cSrcweir                 }
4463cdf0e10cSrcweir                 catch( Exception & )
4464cdf0e10cSrcweir                 {
4465cdf0e10cSrcweir                     StarBASIC::Error( ERRCODE_IO_GENERAL );
4466cdf0e10cSrcweir                 }
4467cdf0e10cSrcweir             }
4468cdf0e10cSrcweir         }
4469cdf0e10cSrcweir         else
4470cdf0e10cSrcweir         // --> UCB
4471cdf0e10cSrcweir         {
4472cdf0e10cSrcweir #ifdef _OLD_FILE_IMPL
4473cdf0e10cSrcweir             DirEntry aEntry( aStr );
4474cdf0e10cSrcweir             bExists = aEntry.Exists();
4475cdf0e10cSrcweir #else
4476cdf0e10cSrcweir             DirectoryItem aItem;
4477cdf0e10cSrcweir             FileBase::RC nRet = DirectoryItem::get( getFullPathUNC( aStr ), aItem );
4478cdf0e10cSrcweir             bExists = (nRet == FileBase::E_None);
4479cdf0e10cSrcweir #endif
4480cdf0e10cSrcweir         }
4481cdf0e10cSrcweir         rPar.Get(0)->PutBool( bExists );
4482cdf0e10cSrcweir     }
4483cdf0e10cSrcweir     else
4484cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4485cdf0e10cSrcweir }
4486cdf0e10cSrcweir 
4487cdf0e10cSrcweir RTLFUNC(Partition)
4488cdf0e10cSrcweir {
4489cdf0e10cSrcweir     (void)pBasic;
4490cdf0e10cSrcweir     (void)bWrite;
4491cdf0e10cSrcweir 
4492cdf0e10cSrcweir     if ( rPar.Count() != 5 )
4493cdf0e10cSrcweir     {
4494cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4495cdf0e10cSrcweir         return;
4496cdf0e10cSrcweir     }
4497cdf0e10cSrcweir 
4498cdf0e10cSrcweir     sal_Int32 nNumber = rPar.Get(1)->GetLong();
4499cdf0e10cSrcweir     sal_Int32 nStart = rPar.Get(2)->GetLong();
4500cdf0e10cSrcweir     sal_Int32 nStop = rPar.Get(3)->GetLong();
4501cdf0e10cSrcweir     sal_Int32 nInterval = rPar.Get(4)->GetLong();
4502cdf0e10cSrcweir 
4503cdf0e10cSrcweir     if( nStart < 0 || nStop <= nStart || nInterval < 1 )
4504cdf0e10cSrcweir     {
4505cdf0e10cSrcweir         StarBASIC::Error( SbERR_BAD_ARGUMENT );
4506cdf0e10cSrcweir         return;
4507cdf0e10cSrcweir     }
4508cdf0e10cSrcweir 
4509cdf0e10cSrcweir     // the Partition function inserts leading spaces before lowervalue and uppervalue
4510cdf0e10cSrcweir     // so that they both have the same number of characters as the string
4511cdf0e10cSrcweir     // representation of the value (Stop + 1). This ensures that if you use the output
4512cdf0e10cSrcweir     // of the Partition function with several values of Number, the resulting text
4513cdf0e10cSrcweir     // will be handled properly during any subsequent sort operation.
4514cdf0e10cSrcweir 
4515cdf0e10cSrcweir     // calculate the  maximun number of characters before lowervalue and uppervalue
4516cdf0e10cSrcweir     ::rtl::OUString aBeforeStart = ::rtl::OUString::valueOf( nStart - 1 );
4517cdf0e10cSrcweir     ::rtl::OUString aAfterStop = ::rtl::OUString::valueOf( nStop + 1 );
4518cdf0e10cSrcweir     sal_Int32 nLen1 = aBeforeStart.getLength();
4519cdf0e10cSrcweir     sal_Int32 nLen2 = aAfterStop.getLength();
4520cdf0e10cSrcweir     sal_Int32 nLen = nLen1 >= nLen2 ? nLen1:nLen2;
4521cdf0e10cSrcweir 
4522cdf0e10cSrcweir     ::rtl::OUStringBuffer aRetStr( nLen * 2 + 1);
4523cdf0e10cSrcweir     ::rtl::OUString aLowerValue;
4524cdf0e10cSrcweir     ::rtl::OUString aUpperValue;
4525cdf0e10cSrcweir     if( nNumber < nStart )
4526cdf0e10cSrcweir     {
4527cdf0e10cSrcweir         aUpperValue = aBeforeStart;
4528cdf0e10cSrcweir     }
4529cdf0e10cSrcweir     else if( nNumber > nStop )
4530cdf0e10cSrcweir     {
4531cdf0e10cSrcweir         aLowerValue = aAfterStop;
4532cdf0e10cSrcweir     }
4533cdf0e10cSrcweir     else
4534cdf0e10cSrcweir     {
4535cdf0e10cSrcweir         sal_Int32 nLowerValue = nNumber;
4536cdf0e10cSrcweir         sal_Int32 nUpperValue = nLowerValue;
4537cdf0e10cSrcweir         if( nInterval > 1 )
4538cdf0e10cSrcweir         {
4539cdf0e10cSrcweir             nLowerValue = ((( nNumber - nStart ) / nInterval ) * nInterval ) + nStart;
4540cdf0e10cSrcweir             nUpperValue = nLowerValue + nInterval - 1;
4541cdf0e10cSrcweir         }
4542cdf0e10cSrcweir 
4543cdf0e10cSrcweir         aLowerValue = ::rtl::OUString::valueOf( nLowerValue );
4544cdf0e10cSrcweir         aUpperValue = ::rtl::OUString::valueOf( nUpperValue );
4545cdf0e10cSrcweir     }
4546cdf0e10cSrcweir 
4547cdf0e10cSrcweir     nLen1 = aLowerValue.getLength();
4548cdf0e10cSrcweir     nLen2 = aUpperValue.getLength();
4549cdf0e10cSrcweir 
4550cdf0e10cSrcweir     if( nLen > nLen1 )
4551cdf0e10cSrcweir     {
4552cdf0e10cSrcweir         // appending the leading spaces for the lowervalue
4553cdf0e10cSrcweir         for ( sal_Int32 i= (nLen - nLen1) ; i > 0; --i )
4554cdf0e10cSrcweir             aRetStr.appendAscii(" ");
4555cdf0e10cSrcweir     }
4556cdf0e10cSrcweir     aRetStr.append( aLowerValue ).appendAscii(":");
4557cdf0e10cSrcweir     if( nLen > nLen2 )
4558cdf0e10cSrcweir     {
4559cdf0e10cSrcweir         // appending the leading spaces for the uppervalue
4560cdf0e10cSrcweir         for ( sal_Int32 i= (nLen - nLen2) ; i > 0; --i )
4561cdf0e10cSrcweir             aRetStr.appendAscii(" ");
4562cdf0e10cSrcweir     }
4563cdf0e10cSrcweir     aRetStr.append( aUpperValue );
4564cdf0e10cSrcweir     rPar.Get(0)->PutString( String(aRetStr.makeStringAndClear()) );
4565cdf0e10cSrcweir }
4566