2001-05-08 10:46:10 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 09:20:20 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
2008-04-11 09:20:20 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
2008-04-11 09:20:20 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
2008-04-11 09:20:20 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
2008-04-11 09:20:20 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
2008-04-11 09:20:20 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2001-05-08 10:46:10 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 11:34:47 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
2009-03-06 09:33:41 +00:00
|
|
|
#include "precompiled_vcl.hxx"
|
2006-09-16 11:34:47 +00:00
|
|
|
|
2002-05-31 10:30:32 +00:00
|
|
|
#include <cstring>
|
2003-04-11 16:18:29 +00:00
|
|
|
#include <sys/stat.h>
|
2002-05-31 10:30:32 +00:00
|
|
|
#include <unistd.h>
|
2008-02-04 12:35:18 +00:00
|
|
|
#include <limits.h>
|
2002-05-31 10:30:32 +00:00
|
|
|
|
2009-03-06 09:33:41 +00:00
|
|
|
#include "vcl/helper.hxx"
|
|
|
|
#include "vcl/ppdparser.hxx"
|
2008-04-03 15:46:50 +00:00
|
|
|
#include "tools/string.hxx"
|
|
|
|
#include "tools/urlobj.hxx"
|
|
|
|
#include "osl/file.hxx"
|
|
|
|
#include "osl/process.h"
|
|
|
|
#include "rtl/bootstrap.hxx"
|
2001-05-08 10:46:10 +00:00
|
|
|
|
2003-04-11 16:18:29 +00:00
|
|
|
using namespace rtl;
|
|
|
|
|
2001-09-27 12:19:27 +00:00
|
|
|
namespace psp {
|
|
|
|
|
2009-03-06 09:33:41 +00:00
|
|
|
OUString getOfficePath( enum whichOfficePath ePath )
|
2001-09-27 12:19:27 +00:00
|
|
|
{
|
2003-04-11 16:18:29 +00:00
|
|
|
static OUString aNetPath;
|
|
|
|
static OUString aUserPath;
|
2005-11-11 10:45:18 +00:00
|
|
|
static OUString aConfigPath;
|
2003-04-11 16:18:29 +00:00
|
|
|
static OUString aEmpty;
|
2002-04-10 07:58:10 +00:00
|
|
|
static bool bOnce = false;
|
2001-09-27 12:19:27 +00:00
|
|
|
|
2002-04-10 07:58:10 +00:00
|
|
|
if( ! bOnce )
|
|
|
|
{
|
|
|
|
bOnce = true;
|
2003-04-11 16:18:29 +00:00
|
|
|
OUString aIni;
|
2008-03-18 11:13:45 +00:00
|
|
|
Bootstrap::get( OUString( RTL_CONSTASCII_USTRINGPARAM( "BRAND_BASE_DIR" ) ), aIni );
|
|
|
|
aIni += OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/" SAL_CONFIGFILE( "bootstrap" ) ) );
|
2003-04-11 16:18:29 +00:00
|
|
|
Bootstrap aBootstrap( aIni );
|
2005-11-11 10:45:18 +00:00
|
|
|
aBootstrap.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "CustomDataUrl" ) ), aConfigPath );
|
2003-04-11 16:18:29 +00:00
|
|
|
aBootstrap.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseInstallation" ) ), aNetPath );
|
|
|
|
aBootstrap.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "UserInstallation" ) ), aUserPath );
|
2006-04-06 14:29:08 +00:00
|
|
|
OUString aUPath = aUserPath;
|
2002-04-10 07:58:10 +00:00
|
|
|
|
2005-11-11 10:45:18 +00:00
|
|
|
if( ! aConfigPath.compareToAscii( "file://", 7 ) )
|
|
|
|
{
|
|
|
|
OUString aSysPath;
|
|
|
|
if( osl_getSystemPathFromFileURL( aConfigPath.pData, &aSysPath.pData ) == osl_File_E_None )
|
|
|
|
aConfigPath = aSysPath;
|
|
|
|
}
|
2002-04-10 07:58:10 +00:00
|
|
|
if( ! aNetPath.compareToAscii( "file://", 7 ) )
|
2002-07-10 10:48:46 +00:00
|
|
|
{
|
2003-04-11 16:18:29 +00:00
|
|
|
OUString aSysPath;
|
2002-07-10 10:48:46 +00:00
|
|
|
if( osl_getSystemPathFromFileURL( aNetPath.pData, &aSysPath.pData ) == osl_File_E_None )
|
|
|
|
aNetPath = aSysPath;
|
|
|
|
}
|
2002-04-10 07:58:10 +00:00
|
|
|
if( ! aUserPath.compareToAscii( "file://", 7 ) )
|
2002-07-10 10:48:46 +00:00
|
|
|
{
|
2003-04-11 16:18:29 +00:00
|
|
|
OUString aSysPath;
|
2002-07-10 10:48:46 +00:00
|
|
|
if( osl_getSystemPathFromFileURL( aUserPath.pData, &aSysPath.pData ) == osl_File_E_None )
|
|
|
|
aUserPath = aSysPath;
|
|
|
|
}
|
2006-04-06 14:29:08 +00:00
|
|
|
// ensure user path exists
|
|
|
|
aUPath += OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/psprint" ) );
|
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
oslFileError eErr =
|
|
|
|
#endif
|
|
|
|
osl_createDirectoryPath( aUPath.pData, NULL, NULL );
|
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
fprintf( stderr, "try to create \"%s\" = %d\n", OUStringToOString( aUPath, RTL_TEXTENCODING_UTF8 ).getStr(), eErr );
|
|
|
|
#endif
|
2002-04-10 07:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( ePath )
|
|
|
|
{
|
2005-11-11 10:45:18 +00:00
|
|
|
case ConfigPath: return aConfigPath;
|
2002-04-10 07:58:10 +00:00
|
|
|
case NetPath: return aNetPath;
|
|
|
|
case UserPath: return aUserPath;
|
|
|
|
}
|
|
|
|
return aEmpty;
|
2001-09-27 12:19:27 +00:00
|
|
|
}
|
|
|
|
|
2006-03-22 09:12:06 +00:00
|
|
|
static OString getEnvironmentPath( const char* pKey )
|
2001-09-27 12:19:27 +00:00
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
OString aPath;
|
2001-09-27 12:19:27 +00:00
|
|
|
|
|
|
|
const char* pValue = getenv( pKey );
|
|
|
|
if( pValue && *pValue )
|
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
aPath = OString( pValue );
|
2001-09-27 12:19:27 +00:00
|
|
|
}
|
|
|
|
return aPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace psp
|
|
|
|
|
2006-03-22 09:12:06 +00:00
|
|
|
void psp::getPrinterPathList( std::list< OUString >& rPathList, const char* pSubDir )
|
2001-05-08 10:46:10 +00:00
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
rPathList.clear();
|
|
|
|
rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
|
2004-02-02 17:55:04 +00:00
|
|
|
|
2006-03-22 09:12:06 +00:00
|
|
|
OUStringBuffer aPathBuffer( 256 );
|
|
|
|
|
|
|
|
// append net path
|
|
|
|
aPathBuffer.append( getOfficePath( psp::NetPath ) );
|
|
|
|
if( aPathBuffer.getLength() )
|
|
|
|
{
|
|
|
|
aPathBuffer.appendAscii( "/share/psprint" );
|
|
|
|
if( pSubDir )
|
2003-04-11 16:18:29 +00:00
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
aPathBuffer.append( sal_Unicode('/') );
|
|
|
|
aPathBuffer.appendAscii( pSubDir );
|
2003-04-11 16:18:29 +00:00
|
|
|
}
|
2006-03-22 09:12:06 +00:00
|
|
|
rPathList.push_back( aPathBuffer.makeStringAndClear() );
|
|
|
|
}
|
|
|
|
// append user path
|
|
|
|
aPathBuffer.append( getOfficePath( psp::UserPath ) );
|
|
|
|
if( aPathBuffer.getLength() )
|
|
|
|
{
|
|
|
|
aPathBuffer.appendAscii( "/user/psprint" );
|
|
|
|
if( pSubDir )
|
2003-04-11 16:18:29 +00:00
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
aPathBuffer.append( sal_Unicode('/') );
|
|
|
|
aPathBuffer.appendAscii( pSubDir );
|
2003-04-11 16:18:29 +00:00
|
|
|
}
|
2006-03-22 09:12:06 +00:00
|
|
|
rPathList.push_back( aPathBuffer.makeStringAndClear() );
|
2001-09-14 11:02:42 +00:00
|
|
|
}
|
2003-04-11 16:18:29 +00:00
|
|
|
|
2006-03-22 09:12:06 +00:00
|
|
|
OString aPath( getEnvironmentPath("SAL_PSPRINT") );
|
2003-04-11 16:18:29 +00:00
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
OString aDir( aPath.getToken( 0, ':', nIndex ) );
|
|
|
|
if( ! aDir.getLength() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pSubDir )
|
|
|
|
{
|
|
|
|
aDir += "/";
|
|
|
|
aDir += pSubDir;
|
|
|
|
}
|
|
|
|
struct stat aStat;
|
|
|
|
if( stat( aDir.getStr(), &aStat ) || ! S_ISDIR( aStat.st_mode ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rPathList.push_back( OStringToOUString( aDir, aEncoding ) );
|
|
|
|
} while( nIndex != -1 );
|
|
|
|
|
2008-06-25 13:21:05 +00:00
|
|
|
#ifdef SYSTEM_PPD_DIR
|
|
|
|
if( pSubDir && rtl_str_compare( pSubDir, PRINTER_PPDDIR ) == 0 )
|
|
|
|
{
|
|
|
|
rPathList.push_back( rtl::OStringToOUString( rtl::OString( SYSTEM_PPD_DIR ), RTL_TEXTENCODING_UTF8 ) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-04-11 16:18:29 +00:00
|
|
|
if( rPathList.empty() )
|
|
|
|
{
|
|
|
|
// last resort: next to program file (mainly for setup)
|
|
|
|
OUString aExe;
|
|
|
|
if( osl_getExecutableFile( &aExe.pData ) == osl_Process_E_None )
|
|
|
|
{
|
|
|
|
INetURLObject aDir( aExe );
|
|
|
|
aDir.removeSegment();
|
|
|
|
aExe = aDir.GetMainURL( INetURLObject::NO_DECODE );
|
|
|
|
OUString aSysPath;
|
|
|
|
if( osl_getSystemPathFromFileURL( aExe.pData, &aSysPath.pData ) == osl_File_E_None )
|
|
|
|
{
|
|
|
|
rPathList.push_back( aSysPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-06 09:33:41 +00:00
|
|
|
OUString psp::getFontPath()
|
2003-04-11 16:18:29 +00:00
|
|
|
{
|
|
|
|
static OUString aPath;
|
2001-09-27 12:19:27 +00:00
|
|
|
|
|
|
|
if( ! aPath.getLength() )
|
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
OUStringBuffer aPathBuffer( 512 );
|
|
|
|
|
2009-03-06 09:33:41 +00:00
|
|
|
OUString aConfigPath( getOfficePath( psp::ConfigPath ) );
|
|
|
|
OUString aNetPath( getOfficePath( psp::NetPath ) );
|
|
|
|
OUString aUserPath( getOfficePath( psp::UserPath ) );
|
2005-11-11 10:45:18 +00:00
|
|
|
if( aConfigPath.getLength() )
|
2003-04-11 16:18:29 +00:00
|
|
|
{
|
2005-11-11 10:45:18 +00:00
|
|
|
// #i53530# Path from CustomDataUrl will completely
|
|
|
|
// replace net and user paths if the path exists
|
2006-03-22 09:12:06 +00:00
|
|
|
aPathBuffer.append(aConfigPath);
|
|
|
|
aPathBuffer.appendAscii("/share/fonts");
|
2005-11-11 10:45:18 +00:00
|
|
|
// check existance of config path
|
|
|
|
struct stat aStat;
|
2006-03-22 09:12:06 +00:00
|
|
|
if( 0 != stat( OUStringToOString( aPathBuffer.makeStringAndClear(), osl_getThreadTextEncoding() ).getStr(), &aStat )
|
2005-11-11 10:45:18 +00:00
|
|
|
|| ! S_ISDIR( aStat.st_mode ) )
|
|
|
|
aConfigPath = OUString();
|
2006-03-22 09:12:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
aPathBuffer.append(aConfigPath);
|
|
|
|
aPathBuffer.appendAscii("/share/fonts");
|
|
|
|
}
|
2003-04-11 16:18:29 +00:00
|
|
|
}
|
2005-11-11 10:45:18 +00:00
|
|
|
if( aConfigPath.getLength() == 0 )
|
2003-04-11 16:18:29 +00:00
|
|
|
{
|
2005-11-11 10:45:18 +00:00
|
|
|
if( aNetPath.getLength() )
|
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
aPathBuffer.append( aNetPath );
|
|
|
|
aPathBuffer.appendAscii( "/share/fonts/truetype;");
|
|
|
|
aPathBuffer.append( aNetPath );
|
|
|
|
aPathBuffer.appendAscii( "/share/fonts/type1;" );
|
2005-11-11 10:45:18 +00:00
|
|
|
}
|
|
|
|
if( aUserPath.getLength() )
|
|
|
|
{
|
2006-03-22 09:12:06 +00:00
|
|
|
aPathBuffer.append( aUserPath );
|
|
|
|
aPathBuffer.appendAscii( "/user/fonts" );
|
2005-11-11 10:45:18 +00:00
|
|
|
}
|
2003-04-11 16:18:29 +00:00
|
|
|
}
|
2006-03-22 09:12:06 +00:00
|
|
|
OString aEnvPath( getEnvironmentPath( "SAL_FONTPATH_PRIVATE" ) );
|
|
|
|
if( aEnvPath.getLength() )
|
|
|
|
{
|
|
|
|
aPathBuffer.append( sal_Unicode(';') );
|
|
|
|
aPathBuffer.append( OStringToOUString( aEnvPath, osl_getThreadTextEncoding() ) );
|
|
|
|
}
|
2001-09-27 12:19:27 +00:00
|
|
|
|
2006-03-22 09:12:06 +00:00
|
|
|
aPath = aPathBuffer.makeStringAndClear();
|
2003-04-15 15:14:38 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2006-05-24 11:02:17 +00:00
|
|
|
fprintf( stderr, "initializing font path to \"%s\"\n", OUStringToOString( aPath, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
|
2001-09-27 12:19:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return aPath;
|
|
|
|
}
|
|
|
|
|
2001-05-08 10:46:10 +00:00
|
|
|
bool psp::convertPfbToPfa( ::osl::File& rInFile, ::osl::File& rOutFile )
|
|
|
|
{
|
|
|
|
static unsigned char hexDigits[] =
|
|
|
|
{
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
|
|
|
};
|
|
|
|
|
|
|
|
bool bSuccess = true;
|
|
|
|
bool bEof = false;
|
|
|
|
unsigned char buffer[256];
|
|
|
|
sal_uInt64 nRead;
|
|
|
|
sal_uInt64 nOrgPos = 0;
|
|
|
|
rInFile.getPos( nOrgPos );
|
|
|
|
|
|
|
|
while( bSuccess && ! bEof )
|
|
|
|
{
|
|
|
|
// read leading bytes
|
|
|
|
bEof = ! rInFile.read( buffer, 6, nRead ) && nRead == 6 ? false : true;
|
2004-03-17 09:50:28 +00:00
|
|
|
unsigned int nType = buffer[ 1 ];
|
|
|
|
unsigned int nBytesToRead = buffer[2] | buffer[3] << 8 | buffer[4] << 16 | buffer[5] << 24;
|
2001-05-08 10:46:10 +00:00
|
|
|
if( buffer[0] != 0x80 ) // test for pfb m_agic number
|
|
|
|
{
|
|
|
|
// this migt be a pfa font already
|
|
|
|
sal_uInt64 nWrite = 0;
|
|
|
|
if( ! rInFile.read( buffer+6, 9, nRead ) && nRead == 9 &&
|
2008-06-16 12:44:24 +00:00
|
|
|
( ! std::strncmp( (char*)buffer, "%!FontType1-", 12 ) ||
|
|
|
|
! std::strncmp( (char*)buffer, "%!PS-AdobeFont-", 15 ) ) )
|
2001-05-08 10:46:10 +00:00
|
|
|
{
|
|
|
|
if( rOutFile.write( buffer, 15, nWrite ) || nWrite != 15 )
|
|
|
|
bSuccess = false;
|
|
|
|
while( bSuccess &&
|
|
|
|
! rInFile.read( buffer, sizeof( buffer ), nRead ) &&
|
|
|
|
nRead != 0 )
|
|
|
|
{
|
|
|
|
if( rOutFile.write( buffer, nRead, nWrite ) ||
|
|
|
|
nWrite != nRead )
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
bEof = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
else if( nType == 1 || nType == 2 )
|
|
|
|
{
|
|
|
|
unsigned char* pBuffer = new unsigned char[ nBytesToRead+1 ];
|
|
|
|
|
|
|
|
if( ! rInFile.read( pBuffer, nBytesToRead, nRead ) && nRead == nBytesToRead )
|
|
|
|
{
|
|
|
|
if( nType == 1 )
|
|
|
|
{
|
|
|
|
// ascii data, convert dos lineends( \r\n ) and
|
|
|
|
// m_ac lineends( \r ) to \n
|
|
|
|
unsigned char * pWriteBuffer = new unsigned char[ nBytesToRead ];
|
2004-03-17 09:50:28 +00:00
|
|
|
unsigned int nBytesToWrite = 0;
|
|
|
|
for( unsigned int i = 0; i < nBytesToRead; i++ )
|
2001-05-08 10:46:10 +00:00
|
|
|
{
|
|
|
|
if( pBuffer[i] != '\r' )
|
|
|
|
pWriteBuffer[ nBytesToWrite++ ] = pBuffer[i];
|
|
|
|
else if( pBuffer[ i+1 ] == '\n' )
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
pWriteBuffer[ nBytesToWrite++ ] = '\n';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pWriteBuffer[ nBytesToWrite++ ] = '\n';
|
|
|
|
}
|
|
|
|
if( rOutFile.write( pWriteBuffer, nBytesToWrite, nRead ) || nRead != nBytesToWrite )
|
|
|
|
bSuccess = false;
|
|
|
|
|
2002-07-17 12:00:20 +00:00
|
|
|
delete [] pWriteBuffer;
|
2001-05-08 10:46:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// binary data
|
2004-03-17 09:50:28 +00:00
|
|
|
unsigned int nBuffer = 0;
|
|
|
|
for( unsigned int i = 0; i < nBytesToRead && bSuccess; i++ )
|
2001-05-08 10:46:10 +00:00
|
|
|
{
|
|
|
|
buffer[ nBuffer++ ] = hexDigits[ pBuffer[ i ] >> 4 ];
|
|
|
|
buffer[ nBuffer++ ] = hexDigits[ pBuffer[ i ] & 15 ];
|
|
|
|
if( nBuffer >= 80 )
|
|
|
|
{
|
|
|
|
buffer[ nBuffer++ ] = '\n';
|
|
|
|
if( rOutFile.write( buffer, nBuffer, nRead ) || nRead != nBuffer )
|
|
|
|
bSuccess = false;
|
|
|
|
nBuffer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( nBuffer > 0 && bSuccess )
|
|
|
|
{
|
|
|
|
buffer[ nBuffer++ ] = '\n';
|
|
|
|
if( rOutFile.write( buffer, nBuffer, nRead ) || nRead != nBuffer )
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bSuccess = false;
|
|
|
|
|
2002-07-17 12:00:20 +00:00
|
|
|
delete [] pBuffer;
|
2001-05-08 10:46:10 +00:00
|
|
|
}
|
|
|
|
else if( nType == 3 )
|
|
|
|
bEof = true;
|
|
|
|
else
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
2004-03-15 11:04:06 +00:00
|
|
|
|
|
|
|
void psp::normPath( OString& rPath )
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
2005-08-09 10:00:07 +00:00
|
|
|
|
2004-03-15 11:04:06 +00:00
|
|
|
ByteString aPath( rPath );
|
|
|
|
|
|
|
|
// double slashes and slash at end are probably
|
|
|
|
// removed by realpath anyway, but since this runs
|
|
|
|
// on many different platforms let's play it safe
|
|
|
|
while( aPath.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND )
|
|
|
|
;
|
|
|
|
if( aPath.Len() > 0 && aPath.GetChar( aPath.Len()-1 ) == '/' )
|
|
|
|
aPath.Erase( aPath.Len()-1 );
|
|
|
|
|
2005-08-09 10:00:07 +00:00
|
|
|
if( ( aPath.Search( "./" ) != STRING_NOTFOUND ||
|
|
|
|
aPath.Search( "~" ) != STRING_NOTFOUND )
|
|
|
|
&& realpath( aPath.GetBuffer(), buf ) )
|
|
|
|
{
|
2004-03-15 11:04:06 +00:00
|
|
|
rPath = buf;
|
2005-08-09 10:00:07 +00:00
|
|
|
}
|
2004-03-15 11:04:06 +00:00
|
|
|
else
|
2005-08-09 10:00:07 +00:00
|
|
|
{
|
2004-03-15 11:04:06 +00:00
|
|
|
rPath = aPath;
|
2005-08-09 10:00:07 +00:00
|
|
|
}
|
2004-03-15 11:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void psp::splitPath( OString& rPath, OString& rDir, OString& rBase )
|
|
|
|
{
|
|
|
|
normPath( rPath );
|
|
|
|
sal_Int32 nIndex = rPath.lastIndexOf( '/' );
|
|
|
|
if( nIndex > 0 )
|
|
|
|
rDir = rPath.copy( 0, nIndex );
|
|
|
|
else if( nIndex == 0 ) // root dir
|
|
|
|
rDir = rPath.copy( 0, 1 );
|
|
|
|
if( rPath.getLength() > nIndex+1 )
|
|
|
|
rBase = rPath.copy( nIndex+1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|