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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <cstring> 32*cdf0e10cSrcweir #include <sys/stat.h> 33*cdf0e10cSrcweir #include <unistd.h> 34*cdf0e10cSrcweir #include <limits.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "vcl/helper.hxx" 37*cdf0e10cSrcweir #include "vcl/ppdparser.hxx" 38*cdf0e10cSrcweir #include "tools/string.hxx" 39*cdf0e10cSrcweir #include "tools/urlobj.hxx" 40*cdf0e10cSrcweir #include "osl/file.hxx" 41*cdf0e10cSrcweir #include "osl/process.h" 42*cdf0e10cSrcweir #include "rtl/bootstrap.hxx" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using namespace rtl; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir namespace psp { 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir OUString getOfficePath( enum whichOfficePath ePath ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir static OUString aNetPath; 51*cdf0e10cSrcweir static OUString aUserPath; 52*cdf0e10cSrcweir static OUString aConfigPath; 53*cdf0e10cSrcweir static OUString aEmpty; 54*cdf0e10cSrcweir static bool bOnce = false; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir if( ! bOnce ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir bOnce = true; 59*cdf0e10cSrcweir OUString aIni; 60*cdf0e10cSrcweir Bootstrap::get( OUString( RTL_CONSTASCII_USTRINGPARAM( "BRAND_BASE_DIR" ) ), aIni ); 61*cdf0e10cSrcweir aIni += OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/" SAL_CONFIGFILE( "bootstrap" ) ) ); 62*cdf0e10cSrcweir Bootstrap aBootstrap( aIni ); 63*cdf0e10cSrcweir aBootstrap.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomDataUrl" ) ), aConfigPath ); 64*cdf0e10cSrcweir aBootstrap.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseInstallation" ) ), aNetPath ); 65*cdf0e10cSrcweir aBootstrap.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "UserInstallation" ) ), aUserPath ); 66*cdf0e10cSrcweir OUString aUPath = aUserPath; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir if( ! aConfigPath.compareToAscii( "file://", 7 ) ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir OUString aSysPath; 71*cdf0e10cSrcweir if( osl_getSystemPathFromFileURL( aConfigPath.pData, &aSysPath.pData ) == osl_File_E_None ) 72*cdf0e10cSrcweir aConfigPath = aSysPath; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir if( ! aNetPath.compareToAscii( "file://", 7 ) ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir OUString aSysPath; 77*cdf0e10cSrcweir if( osl_getSystemPathFromFileURL( aNetPath.pData, &aSysPath.pData ) == osl_File_E_None ) 78*cdf0e10cSrcweir aNetPath = aSysPath; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir if( ! aUserPath.compareToAscii( "file://", 7 ) ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir OUString aSysPath; 83*cdf0e10cSrcweir if( osl_getSystemPathFromFileURL( aUserPath.pData, &aSysPath.pData ) == osl_File_E_None ) 84*cdf0e10cSrcweir aUserPath = aSysPath; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir // ensure user path exists 87*cdf0e10cSrcweir aUPath += OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/psprint" ) ); 88*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 89*cdf0e10cSrcweir oslFileError eErr = 90*cdf0e10cSrcweir #endif 91*cdf0e10cSrcweir osl_createDirectoryPath( aUPath.pData, NULL, NULL ); 92*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 93*cdf0e10cSrcweir fprintf( stderr, "try to create \"%s\" = %d\n", OUStringToOString( aUPath, RTL_TEXTENCODING_UTF8 ).getStr(), eErr ); 94*cdf0e10cSrcweir #endif 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir switch( ePath ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir case ConfigPath: return aConfigPath; 100*cdf0e10cSrcweir case NetPath: return aNetPath; 101*cdf0e10cSrcweir case UserPath: return aUserPath; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir return aEmpty; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir static OString getEnvironmentPath( const char* pKey ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir OString aPath; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir const char* pValue = getenv( pKey ); 111*cdf0e10cSrcweir if( pValue && *pValue ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir aPath = OString( pValue ); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir return aPath; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir } // namespace psp 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void psp::getPrinterPathList( std::list< OUString >& rPathList, const char* pSubDir ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir rPathList.clear(); 123*cdf0e10cSrcweir rtl_TextEncoding aEncoding = osl_getThreadTextEncoding(); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir OUStringBuffer aPathBuffer( 256 ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // append net path 128*cdf0e10cSrcweir aPathBuffer.append( getOfficePath( psp::NetPath ) ); 129*cdf0e10cSrcweir if( aPathBuffer.getLength() ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir aPathBuffer.appendAscii( "/share/psprint" ); 132*cdf0e10cSrcweir if( pSubDir ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir aPathBuffer.append( sal_Unicode('/') ); 135*cdf0e10cSrcweir aPathBuffer.appendAscii( pSubDir ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir rPathList.push_back( aPathBuffer.makeStringAndClear() ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir // append user path 140*cdf0e10cSrcweir aPathBuffer.append( getOfficePath( psp::UserPath ) ); 141*cdf0e10cSrcweir if( aPathBuffer.getLength() ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir aPathBuffer.appendAscii( "/user/psprint" ); 144*cdf0e10cSrcweir if( pSubDir ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir aPathBuffer.append( sal_Unicode('/') ); 147*cdf0e10cSrcweir aPathBuffer.appendAscii( pSubDir ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir rPathList.push_back( aPathBuffer.makeStringAndClear() ); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir OString aPath( getEnvironmentPath("SAL_PSPRINT") ); 153*cdf0e10cSrcweir sal_Int32 nIndex = 0; 154*cdf0e10cSrcweir do 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir OString aDir( aPath.getToken( 0, ':', nIndex ) ); 157*cdf0e10cSrcweir if( ! aDir.getLength() ) 158*cdf0e10cSrcweir continue; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir if( pSubDir ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir aDir += "/"; 163*cdf0e10cSrcweir aDir += pSubDir; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir struct stat aStat; 166*cdf0e10cSrcweir if( stat( aDir.getStr(), &aStat ) || ! S_ISDIR( aStat.st_mode ) ) 167*cdf0e10cSrcweir continue; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir rPathList.push_back( OStringToOUString( aDir, aEncoding ) ); 170*cdf0e10cSrcweir } while( nIndex != -1 ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir #ifdef SYSTEM_PPD_DIR 173*cdf0e10cSrcweir if( pSubDir && rtl_str_compare( pSubDir, PRINTER_PPDDIR ) == 0 ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir rPathList.push_back( rtl::OStringToOUString( rtl::OString( SYSTEM_PPD_DIR ), RTL_TEXTENCODING_UTF8 ) ); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir #endif 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir if( rPathList.empty() ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir // last resort: next to program file (mainly for setup) 182*cdf0e10cSrcweir OUString aExe; 183*cdf0e10cSrcweir if( osl_getExecutableFile( &aExe.pData ) == osl_Process_E_None ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir INetURLObject aDir( aExe ); 186*cdf0e10cSrcweir aDir.removeSegment(); 187*cdf0e10cSrcweir aExe = aDir.GetMainURL( INetURLObject::NO_DECODE ); 188*cdf0e10cSrcweir OUString aSysPath; 189*cdf0e10cSrcweir if( osl_getSystemPathFromFileURL( aExe.pData, &aSysPath.pData ) == osl_File_E_None ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir rPathList.push_back( aSysPath ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir OUString psp::getFontPath() 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir static OUString aPath; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir if( ! aPath.getLength() ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir OUStringBuffer aPathBuffer( 512 ); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir OUString aConfigPath( getOfficePath( psp::ConfigPath ) ); 206*cdf0e10cSrcweir OUString aNetPath( getOfficePath( psp::NetPath ) ); 207*cdf0e10cSrcweir OUString aUserPath( getOfficePath( psp::UserPath ) ); 208*cdf0e10cSrcweir if( aConfigPath.getLength() ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir // #i53530# Path from CustomDataUrl will completely 211*cdf0e10cSrcweir // replace net and user paths if the path exists 212*cdf0e10cSrcweir aPathBuffer.append(aConfigPath); 213*cdf0e10cSrcweir aPathBuffer.appendAscii("/share/fonts"); 214*cdf0e10cSrcweir // check existance of config path 215*cdf0e10cSrcweir struct stat aStat; 216*cdf0e10cSrcweir if( 0 != stat( OUStringToOString( aPathBuffer.makeStringAndClear(), osl_getThreadTextEncoding() ).getStr(), &aStat ) 217*cdf0e10cSrcweir || ! S_ISDIR( aStat.st_mode ) ) 218*cdf0e10cSrcweir aConfigPath = OUString(); 219*cdf0e10cSrcweir else 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir aPathBuffer.append(aConfigPath); 222*cdf0e10cSrcweir aPathBuffer.appendAscii("/share/fonts"); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir if( aConfigPath.getLength() == 0 ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir if( aNetPath.getLength() ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir aPathBuffer.append( aNetPath ); 230*cdf0e10cSrcweir aPathBuffer.appendAscii( "/share/fonts/truetype;"); 231*cdf0e10cSrcweir aPathBuffer.append( aNetPath ); 232*cdf0e10cSrcweir aPathBuffer.appendAscii( "/share/fonts/type1;" ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir if( aUserPath.getLength() ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir aPathBuffer.append( aUserPath ); 237*cdf0e10cSrcweir aPathBuffer.appendAscii( "/user/fonts" ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir OString aEnvPath( getEnvironmentPath( "SAL_FONTPATH_PRIVATE" ) ); 241*cdf0e10cSrcweir if( aEnvPath.getLength() ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir aPathBuffer.append( sal_Unicode(';') ); 244*cdf0e10cSrcweir aPathBuffer.append( OStringToOUString( aEnvPath, osl_getThreadTextEncoding() ) ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir aPath = aPathBuffer.makeStringAndClear(); 248*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 249*cdf0e10cSrcweir fprintf( stderr, "initializing font path to \"%s\"\n", OUStringToOString( aPath, RTL_TEXTENCODING_ISO_8859_1 ).getStr() ); 250*cdf0e10cSrcweir #endif 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir return aPath; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir bool psp::convertPfbToPfa( ::osl::File& rInFile, ::osl::File& rOutFile ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir static unsigned char hexDigits[] = 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir '0', '1', '2', '3', '4', '5', '6', '7', 260*cdf0e10cSrcweir '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' 261*cdf0e10cSrcweir }; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir bool bSuccess = true; 264*cdf0e10cSrcweir bool bEof = false; 265*cdf0e10cSrcweir unsigned char buffer[256]; 266*cdf0e10cSrcweir sal_uInt64 nRead; 267*cdf0e10cSrcweir sal_uInt64 nOrgPos = 0; 268*cdf0e10cSrcweir rInFile.getPos( nOrgPos ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir while( bSuccess && ! bEof ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir // read leading bytes 273*cdf0e10cSrcweir bEof = ! rInFile.read( buffer, 6, nRead ) && nRead == 6 ? false : true; 274*cdf0e10cSrcweir unsigned int nType = buffer[ 1 ]; 275*cdf0e10cSrcweir unsigned int nBytesToRead = buffer[2] | buffer[3] << 8 | buffer[4] << 16 | buffer[5] << 24; 276*cdf0e10cSrcweir if( buffer[0] != 0x80 ) // test for pfb m_agic number 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir // this migt be a pfa font already 279*cdf0e10cSrcweir sal_uInt64 nWrite = 0; 280*cdf0e10cSrcweir if( ! rInFile.read( buffer+6, 9, nRead ) && nRead == 9 && 281*cdf0e10cSrcweir ( ! std::strncmp( (char*)buffer, "%!FontType1-", 12 ) || 282*cdf0e10cSrcweir ! std::strncmp( (char*)buffer, "%!PS-AdobeFont-", 15 ) ) ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir if( rOutFile.write( buffer, 15, nWrite ) || nWrite != 15 ) 285*cdf0e10cSrcweir bSuccess = false; 286*cdf0e10cSrcweir while( bSuccess && 287*cdf0e10cSrcweir ! rInFile.read( buffer, sizeof( buffer ), nRead ) && 288*cdf0e10cSrcweir nRead != 0 ) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir if( rOutFile.write( buffer, nRead, nWrite ) || 291*cdf0e10cSrcweir nWrite != nRead ) 292*cdf0e10cSrcweir bSuccess = false; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir bEof = true; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir else 297*cdf0e10cSrcweir bSuccess = false; 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir else if( nType == 1 || nType == 2 ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir unsigned char* pBuffer = new unsigned char[ nBytesToRead+1 ]; 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir if( ! rInFile.read( pBuffer, nBytesToRead, nRead ) && nRead == nBytesToRead ) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir if( nType == 1 ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir // ascii data, convert dos lineends( \r\n ) and 308*cdf0e10cSrcweir // m_ac lineends( \r ) to \n 309*cdf0e10cSrcweir unsigned char * pWriteBuffer = new unsigned char[ nBytesToRead ]; 310*cdf0e10cSrcweir unsigned int nBytesToWrite = 0; 311*cdf0e10cSrcweir for( unsigned int i = 0; i < nBytesToRead; i++ ) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir if( pBuffer[i] != '\r' ) 314*cdf0e10cSrcweir pWriteBuffer[ nBytesToWrite++ ] = pBuffer[i]; 315*cdf0e10cSrcweir else if( pBuffer[ i+1 ] == '\n' ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir i++; 318*cdf0e10cSrcweir pWriteBuffer[ nBytesToWrite++ ] = '\n'; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir else 321*cdf0e10cSrcweir pWriteBuffer[ nBytesToWrite++ ] = '\n'; 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir if( rOutFile.write( pWriteBuffer, nBytesToWrite, nRead ) || nRead != nBytesToWrite ) 324*cdf0e10cSrcweir bSuccess = false; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir delete [] pWriteBuffer; 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir else 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir // binary data 331*cdf0e10cSrcweir unsigned int nBuffer = 0; 332*cdf0e10cSrcweir for( unsigned int i = 0; i < nBytesToRead && bSuccess; i++ ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir buffer[ nBuffer++ ] = hexDigits[ pBuffer[ i ] >> 4 ]; 335*cdf0e10cSrcweir buffer[ nBuffer++ ] = hexDigits[ pBuffer[ i ] & 15 ]; 336*cdf0e10cSrcweir if( nBuffer >= 80 ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir buffer[ nBuffer++ ] = '\n'; 339*cdf0e10cSrcweir if( rOutFile.write( buffer, nBuffer, nRead ) || nRead != nBuffer ) 340*cdf0e10cSrcweir bSuccess = false; 341*cdf0e10cSrcweir nBuffer = 0; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir if( nBuffer > 0 && bSuccess ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir buffer[ nBuffer++ ] = '\n'; 347*cdf0e10cSrcweir if( rOutFile.write( buffer, nBuffer, nRead ) || nRead != nBuffer ) 348*cdf0e10cSrcweir bSuccess = false; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir else 353*cdf0e10cSrcweir bSuccess = false; 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir delete [] pBuffer; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir else if( nType == 3 ) 358*cdf0e10cSrcweir bEof = true; 359*cdf0e10cSrcweir else 360*cdf0e10cSrcweir bSuccess = false; 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir return bSuccess; 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir void psp::normPath( OString& rPath ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir char buf[PATH_MAX]; 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir ByteString aPath( rPath ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir // double slashes and slash at end are probably 373*cdf0e10cSrcweir // removed by realpath anyway, but since this runs 374*cdf0e10cSrcweir // on many different platforms let's play it safe 375*cdf0e10cSrcweir while( aPath.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) 376*cdf0e10cSrcweir ; 377*cdf0e10cSrcweir if( aPath.Len() > 0 && aPath.GetChar( aPath.Len()-1 ) == '/' ) 378*cdf0e10cSrcweir aPath.Erase( aPath.Len()-1 ); 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir if( ( aPath.Search( "./" ) != STRING_NOTFOUND || 381*cdf0e10cSrcweir aPath.Search( "~" ) != STRING_NOTFOUND ) 382*cdf0e10cSrcweir && realpath( aPath.GetBuffer(), buf ) ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir rPath = buf; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir else 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir rPath = aPath; 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir void psp::splitPath( OString& rPath, OString& rDir, OString& rBase ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir normPath( rPath ); 395*cdf0e10cSrcweir sal_Int32 nIndex = rPath.lastIndexOf( '/' ); 396*cdf0e10cSrcweir if( nIndex > 0 ) 397*cdf0e10cSrcweir rDir = rPath.copy( 0, nIndex ); 398*cdf0e10cSrcweir else if( nIndex == 0 ) // root dir 399*cdf0e10cSrcweir rDir = rPath.copy( 0, 1 ); 400*cdf0e10cSrcweir if( rPath.getLength() > nIndex+1 ) 401*cdf0e10cSrcweir rBase = rPath.copy( nIndex+1 ); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir 405