1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #include <cstdarg> 30*cdf0e10cSrcweir #include <vector> 31*cdf0e10cSrcweir #include <rtl/ustring.hxx> 32*cdf0e10cSrcweir #include <rtl/instance.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "vos/process.hxx" 35*cdf0e10cSrcweir #include "vos/diagnose.hxx" 36*cdf0e10cSrcweir #include <osl/file.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #define MAX_RESOURCES 100 39*cdf0e10cSrcweir #define MAX_ARGS 100 40*cdf0e10cSrcweir #define MAX_ENVIROMENTS 100 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace vos; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 45*cdf0e10cSrcweir /// Argument 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir OArgumentList::OArgumentList() : 48*cdf0e10cSrcweir n_Args(0), 49*cdf0e10cSrcweir m_aVec(0) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir // empty 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir OArgumentList::OArgumentList( sal_uInt32 nArgs, const ::rtl::OUString* aArgument1, ... ) : 55*cdf0e10cSrcweir n_Args( nArgs ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir m_aVec = new rtl_uString* [nArgs]; 58*cdf0e10cSrcweir std::va_list pArgs; 59*cdf0e10cSrcweir sal_uInt32 i = 0; 60*cdf0e10cSrcweir const rtl::OUString* aArgument; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir va_start ( pArgs, aArgument1 ); 63*cdf0e10cSrcweir aArgument = aArgument1; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir while( true ) { 66*cdf0e10cSrcweir m_aVec[i] = aArgument->pData; 67*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i++] ); 68*cdf0e10cSrcweir if( i < n_Args ) 69*cdf0e10cSrcweir aArgument = va_arg( pArgs,rtl::OUString* ); 70*cdf0e10cSrcweir else 71*cdf0e10cSrcweir break; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir va_end( pArgs ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir OArgumentList::OArgumentList( const rtl::OUString aArgumentList[], sal_uInt32 nArgs ) : 78*cdf0e10cSrcweir n_Args( nArgs ) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir m_aVec = new rtl_uString* [n_Args]; 81*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < n_Args; ++ i ) { 82*cdf0e10cSrcweir m_aVec[i] = aArgumentList[i].pData; 83*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i] ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir OArgumentList::OArgumentList( const OArgumentList& rOther ) : n_Args( rOther.n_Args ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir m_aVec = new rtl_uString* [n_Args]; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir sal_uInt32 i; 92*cdf0e10cSrcweir for ( i = 0; i < n_Args; ++i ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir m_aVec[i] = rOther.m_aVec[i]; 95*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i] ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir OArgumentList& OArgumentList::operator=( const OArgumentList& rOther ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if ( this != &rOther ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // delete the old one 105*cdf0e10cSrcweir sal_uInt32 i; 106*cdf0e10cSrcweir for ( i = 0; i < n_Args; ++i ) 107*cdf0e10cSrcweir rtl_uString_release( m_aVec[i] ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir delete [] m_aVec; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir n_Args = rOther.n_Args; 113*cdf0e10cSrcweir m_aVec = new rtl_uString* [n_Args]; 114*cdf0e10cSrcweir for( i = 0; i < n_Args; ++i ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir m_aVec[i] = rOther.m_aVec[i]; 117*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i] ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir return *this; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir OArgumentList::~OArgumentList( ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < n_Args; ++i ) rtl_uString_release( m_aVec[i] ); 127*cdf0e10cSrcweir delete[] m_aVec; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////// 132*cdf0e10cSrcweir /// Environment 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir OEnvironment::OEnvironment() : 135*cdf0e10cSrcweir n_Vars( 0 ), 136*cdf0e10cSrcweir m_aVec( 0 ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir OEnvironment::OEnvironment( sal_Int32 nVars, const ::rtl::OUString* aArgument1, ... ) : 141*cdf0e10cSrcweir n_Vars( nVars ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir m_aVec = new rtl_uString* [nVars]; 144*cdf0e10cSrcweir std::va_list pArgs; 145*cdf0e10cSrcweir sal_Int32 i = 0; 146*cdf0e10cSrcweir const rtl::OUString* aArgument; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir va_start ( pArgs, aArgument1 ); 149*cdf0e10cSrcweir aArgument = aArgument1; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir while( true ) { 152*cdf0e10cSrcweir m_aVec[i] = aArgument->pData; 153*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i++] ); 154*cdf0e10cSrcweir if( i < n_Vars ) 155*cdf0e10cSrcweir aArgument = va_arg( pArgs,rtl::OUString* ); 156*cdf0e10cSrcweir else 157*cdf0e10cSrcweir break; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir va_end( pArgs ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir OEnvironment::OEnvironment( const ::rtl::OUString aVariableList[], sal_Int32 nVars ) : 164*cdf0e10cSrcweir n_Vars( nVars ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir m_aVec = new rtl_uString* [n_Vars]; 167*cdf0e10cSrcweir for( sal_Int32 i = 0; i < n_Vars; ++ i ) { 168*cdf0e10cSrcweir m_aVec[i] = aVariableList[i].pData; 169*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i] ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir OEnvironment::OEnvironment( const OEnvironment& rOther ) : n_Vars( rOther.n_Vars ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir m_aVec = new rtl_uString* [n_Vars]; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir sal_Int32 i; 178*cdf0e10cSrcweir for ( i = 0; i < n_Vars; ++i ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir m_aVec[i] = rOther.m_aVec[i]; 181*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i] ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir OEnvironment& OEnvironment::operator=( const OEnvironment& rOther ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir if ( this != &rOther ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir sal_Int32 i; 190*cdf0e10cSrcweir for ( i = 0; i < n_Vars; ++i ) 191*cdf0e10cSrcweir rtl_uString_release( m_aVec[i] ); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir delete [] m_aVec; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir n_Vars = rOther.n_Vars; 196*cdf0e10cSrcweir m_aVec = new rtl_uString* [n_Vars]; 197*cdf0e10cSrcweir for ( i = 0; i < n_Vars; ++i ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir m_aVec[i] = rOther.m_aVec[i]; 200*cdf0e10cSrcweir rtl_uString_acquire( m_aVec[i] ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir return *this; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir OEnvironment::~OEnvironment() 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir for( sal_Int32 i = 0; i < n_Vars; ++i ) rtl_uString_release( m_aVec[i] ); 210*cdf0e10cSrcweir delete[] m_aVec; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 214*cdf0e10cSrcweir // Process 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO( 218*cdf0e10cSrcweir VOS_CLASSNAME(OProcess, vos), 219*cdf0e10cSrcweir VOS_NAMESPACE(OProcess, vos), 220*cdf0e10cSrcweir VOS_NAMESPACE(OObject, vos), 0); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir OProcess::OProcess( ) : 224*cdf0e10cSrcweir m_strImageName( ), 225*cdf0e10cSrcweir m_strDirectory(), 226*cdf0e10cSrcweir m_Process(0) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir OProcess::OProcess( const rtl::OUString& strImageName ) : 232*cdf0e10cSrcweir m_strImageName( strImageName ), 233*cdf0e10cSrcweir m_strDirectory(), 234*cdf0e10cSrcweir m_Process(0) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir // empty 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir OProcess::OProcess(const rtl::OUString& strImageName, const rtl::OUString& strWorkingDirectory) : 241*cdf0e10cSrcweir m_strImageName( strImageName ), 242*cdf0e10cSrcweir m_strDirectory( strWorkingDirectory ), 243*cdf0e10cSrcweir m_Process(0) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir // empty 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir OProcess::~OProcess() 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir osl_freeProcessHandle(m_Process); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir OProcess* OProcess::getProcess(TProcessIdentifier Identifier) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir oslProcess hProcess = osl_getProcess(Identifier); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir if (hProcess) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir OProcess* pProcess = new OProcess( ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir pProcess->m_Process = hProcess; 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir return pProcess; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir return 0; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir OProcess::TProcessError OProcess::execute(TProcessOption Options, 272*cdf0e10cSrcweir const OArgumentList& aArgumentList, 273*cdf0e10cSrcweir const OEnvironment& aEnvironment ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir return ((TProcessError)osl_executeProcess(m_strImageName.pData, 276*cdf0e10cSrcweir aArgumentList.m_aVec, 277*cdf0e10cSrcweir aArgumentList.n_Args, 278*cdf0e10cSrcweir Options, 279*cdf0e10cSrcweir 0, 280*cdf0e10cSrcweir m_strDirectory.pData, 281*cdf0e10cSrcweir aEnvironment.m_aVec, 282*cdf0e10cSrcweir aEnvironment.n_Vars, 283*cdf0e10cSrcweir &m_Process)); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir OProcess::TProcessError OProcess::execute( TProcessOption Options, 288*cdf0e10cSrcweir const OSecurity &Security, 289*cdf0e10cSrcweir const OArgumentList& aArgumentList, 290*cdf0e10cSrcweir const OEnvironment& aEnvironment ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir return ((TProcessError)osl_executeProcess(m_strImageName.pData, 293*cdf0e10cSrcweir aArgumentList.m_aVec, 294*cdf0e10cSrcweir aArgumentList.n_Args, 295*cdf0e10cSrcweir Options, 296*cdf0e10cSrcweir Security, 297*cdf0e10cSrcweir m_strDirectory.pData, 298*cdf0e10cSrcweir aEnvironment.m_aVec, 299*cdf0e10cSrcweir aEnvironment.n_Vars, 300*cdf0e10cSrcweir &m_Process)); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir OProcess::TProcessError OProcess::terminate() 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir return (TProcessError)osl_terminateProcess(m_Process); 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir OProcess::TProcessError OProcess::getInfo(TProcessData Data, TProcessInfo* pInfo) const 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir return (TProcessError)osl_getProcessInfo(m_Process, Data, pInfo); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir OProcess::TProcessError OProcess::getCurrentInfo(TProcessData Data, TProcessInfo* pInfo) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir return (TProcessError)osl_getProcessInfo(0, Data, pInfo); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir OProcess::TProcessError OProcess::join() 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir return (TProcessError)osl_joinProcess(m_Process); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir /* 326*cdf0e10cSrcweir OProcess::TProcessError OProcess::searchPath(const sal_Char* Name, sal_Char *Buffer, sal_uInt32 Max, 327*cdf0e10cSrcweir const sal_Char* Path, sal_Char Separator) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir return (TProcessError)osl_searchPath(Name, Path, Separator, Buffer, Max); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir */ 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 334*cdf0e10cSrcweir // StartupInfo 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO( 337*cdf0e10cSrcweir VOS_CLASSNAME(OStartupInfo, vos), 338*cdf0e10cSrcweir VOS_NAMESPACE(OStartupInfo, vos), 339*cdf0e10cSrcweir VOS_NAMESPACE(OObject, vos), 0); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir OStartupInfo::OStartupInfo() 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir OStartupInfo::~OStartupInfo() 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir OStartupInfo::TStartupError OStartupInfo::getExecutableFile( 350*cdf0e10cSrcweir rtl::OUString& strImageName ) const 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir return (TStartupError) osl_getExecutableFile( &strImageName.pData ); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir OStartupInfo::TStartupError OStartupInfo::getCommandArg(sal_uInt32 nArg, rtl::OUString& strCommandArg) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir return ( TStartupError ) osl_getCommandArg( nArg,&strCommandArg.pData ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir sal_uInt32 OStartupInfo::getCommandArgCount() 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir return osl_getCommandArgCount(); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir OStartupInfo::TStartupError OStartupInfo::getEnvironment(const rtl::OUString& strVar, 367*cdf0e10cSrcweir rtl::OUString& strValue) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir return ( TStartupError ) osl_getEnvironment( strVar.pData, &strValue.pData ); 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 375*cdf0e10cSrcweir // 376*cdf0e10cSrcweir // OExtCommandLineImpl 377*cdf0e10cSrcweir // 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir namespace vos 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir class OExtCommandLineImpl 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir void init(); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aExtArgVector; 387*cdf0e10cSrcweir sal_uInt32 m_nArgCount; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir public: 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir OExtCommandLineImpl(); 392*cdf0e10cSrcweir ~OExtCommandLineImpl(); 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir sal_uInt32 SAL_CALL getCommandArgCount(); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir sal_Bool SAL_CALL getCommandArg(sal_uInt32 nArg, ::rtl::OUString& strCommandArg); 397*cdf0e10cSrcweir }; 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir OExtCommandLineImpl::OExtCommandLineImpl() 402*cdf0e10cSrcweir : m_nArgCount(0) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir init(); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir OExtCommandLineImpl::~OExtCommandLineImpl() 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir sal_uInt32 SAL_CALL OExtCommandLineImpl::getCommandArgCount() 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir return m_nArgCount; 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir sal_Bool SAL_CALL OExtCommandLineImpl::getCommandArg(sal_uInt32 nArg, ::rtl::OUString& strCommandArg) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir if ( nArg >= m_nArgCount ) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir return sal_False; 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir strCommandArg = aExtArgVector[nArg]; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir return sal_True; 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir void OExtCommandLineImpl::init() 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir OStartupInfo aStartInfo; 435*cdf0e10cSrcweir sal_uInt32 nIndex=0; 436*cdf0e10cSrcweir sal_uInt32 nArgs = aStartInfo.getCommandArgCount(); 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir for ( nIndex = 0 ; nIndex < nArgs ; ++nIndex ) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir ::rtl::OUString aString; 441*cdf0e10cSrcweir aStartInfo.getCommandArg(nIndex,aString); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir if ( aString[0] == (sal_Unicode) '@' ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir ::rtl::OUString aFileName = aString.copy(1); 446*cdf0e10cSrcweir ::osl::File aFile(aFileName); 447*cdf0e10cSrcweir ::rtl::ByteSequence aSeq; 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir ::osl::FileBase::RC aErr = aFile.open(OpenFlag_Read); 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir if ( aErr != ::osl::FileBase::E_None ) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir break; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir do 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir aErr = aFile.readLine(aSeq); 459*cdf0e10cSrcweir if ( aSeq.getLength() != 0 ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir ::rtl::OUString newString((sal_Char*)aSeq.getArray(), aSeq.getLength(), RTL_TEXTENCODING_ASCII_US); 462*cdf0e10cSrcweir aExtArgVector.push_back( newString ); 463*cdf0e10cSrcweir m_nArgCount++; 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir while ( aErr == ::osl::FileBase::E_None && aSeq.getLength() > 0 ); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir aFile.close(); 469*cdf0e10cSrcweir aFile.remove(aFileName); 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir else 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir aExtArgVector.push_back( aString ); 474*cdf0e10cSrcweir m_nArgCount++; 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 482*cdf0e10cSrcweir // 483*cdf0e10cSrcweir // OExtCommandLine 484*cdf0e10cSrcweir // 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir namespace 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir struct lclMutex : public rtl::Static< vos::OMutex, lclMutex > {}; 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir OExtCommandLineImpl* OExtCommandLine::pExtImpl=0; 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir VOS_IMPLEMENT_CLASSINFO( 495*cdf0e10cSrcweir VOS_CLASSNAME(OExtCommandLine, vos), 496*cdf0e10cSrcweir VOS_NAMESPACE(OExtCommandLine, vos), 497*cdf0e10cSrcweir VOS_NAMESPACE(OObject, vos), 0); 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir OExtCommandLine::OExtCommandLine() 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir OGuard Guard(lclMutex::get()); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir if ( pExtImpl == NULL ) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir pExtImpl = new OExtCommandLineImpl; 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir OExtCommandLine::~OExtCommandLine() 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir sal_uInt32 SAL_CALL OExtCommandLine::getCommandArgCount() 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir return pExtImpl->getCommandArgCount(); 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir sal_Bool SAL_CALL OExtCommandLine::getCommandArg(sal_uInt32 nArg, ::rtl::OUString& strCommandArg) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir return pExtImpl->getCommandArg(nArg,strCommandArg); 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526