1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tutil.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_soltools.hxx"
38 // getcwd hack is deprecated as soon as normalizePath works as intend
40 #define _getcwd getcwd
41 #include <direct.h> // _getcwd
43 #include <unistd.h> // getcwd
46 // <function_cnvrtPth>
47 ::rtl::OUString
cnvrtPth( ::rtl::OString sysPth
) {
49 using ::osl::FileBase
;
50 using ::rtl::OUString
;
54 sysPth
= sysPth
.replace( '\\','/' );
55 OUString
pth( OUString::createFromAscii( sysPth
.getStr() ) );
57 if ( sysPth
.indexOf("..") != -1 ) {
59 // <hack> for osl_normalizePath() can't handle relatives
61 OString
curPth(getcwd(buffer
,256));
64 FileBase::normalizePath( OUString::createFromAscii( curPth
) ,
66 FileBase::getAbsolutePath( nrmCurPth
, pth
, ret
);
69 FileBase::normalizePath( pth
, ret
);
73 } // </function_cnvrtPth>
75 // <function_getEntriesFromFile>
76 sal_uInt32
getEntriesFromFile( sal_Char
* fName
,
77 vector
< sal_Char
* >& entries
) {
79 ::osl::File
inFile( cnvrtPth( fName
) );
80 if ( inFile
.open( OpenFlag_Read
) == ::osl::FileBase::E_None
) {
81 ::rtl::ByteSequence byteSeq
;
82 inFile
.readLine( byteSeq
);
83 while ( byteSeq
.getLength() ) {
84 sal_uInt32 len
= byteSeq
.getLength();
86 sal_Char
* pEnt
= new sal_Char
[ len
+1 ];
87 sal_Char
* bsPtr
= (sal_Char
*)byteSeq
.getArray();
88 for ( i
=0; i
<len
; i
++ ) {
92 entries
.push_back( pEnt
);
94 inFile
.readLine( byteSeq
);
97 return ( entries
.size() );
99 } // </function_getEntriesFromFile>
102 sal_Char
* cpy( sal_Char
** dest
, const sal_Char
* src
) {
104 *dest
= new sal_Char
[ ln(src
)+1 ];
106 sal_Char
* pdest
= *dest
;
107 const sal_Char
* psrc
= src
;
109 // copy string by char
110 while( *pdest
++ = *psrc
++ );
117 sal_Char
* cat( const sal_Char
* str1
, const sal_Char
* str2
) {
119 // allocate memory for destination string
120 sal_Char
* dest
= new sal_Char
[ ln(str1
)+ln(str2
)+1 ];
123 sal_Char
* pdest
= dest
;
124 const sal_Char
* psrc
= str1
;
126 // copy string1 by char to dest
127 while( *pdest
++ = *psrc
++ );
130 while( *pdest
++ = *psrc
++ );
137 sal_uInt32
ln( const sal_Char
* str
) {
140 const sal_Char
* ptr
= str
;
143 while( *ptr
++ ) len
++;
149 } // </namespace_tstutl>