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