1*7a4715d3SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*7a4715d3SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*7a4715d3SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*7a4715d3SAndrew Rist * distributed with this work for additional information
6*7a4715d3SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*7a4715d3SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*7a4715d3SAndrew Rist * "License"); you may not use this file except in compliance
9*7a4715d3SAndrew Rist * with the License. You may obtain a copy of the License at
10*7a4715d3SAndrew Rist *
11*7a4715d3SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*7a4715d3SAndrew Rist *
13*7a4715d3SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*7a4715d3SAndrew Rist * software distributed under the License is distributed on an
15*7a4715d3SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7a4715d3SAndrew Rist * KIND, either express or implied. See the License for the
17*7a4715d3SAndrew Rist * specific language governing permissions and limitations
18*7a4715d3SAndrew Rist * under the License.
19*7a4715d3SAndrew Rist *
20*7a4715d3SAndrew Rist *************************************************************/
21*7a4715d3SAndrew Rist
22*7a4715d3SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_soltools.hxx"
26cdf0e10cSrcweir #include "tutil.hxx"
27cdf0e10cSrcweir
28cdf0e10cSrcweir // <namespace_tstutl>
29cdf0e10cSrcweir namespace tstutl {
30cdf0e10cSrcweir
31cdf0e10cSrcweir // getcwd hack is deprecated as soon as normalizePath works as intend
32cdf0e10cSrcweir #ifdef WNT
33cdf0e10cSrcweir #define _getcwd getcwd
34cdf0e10cSrcweir #include <direct.h> // _getcwd
35cdf0e10cSrcweir #else
36cdf0e10cSrcweir #include <unistd.h> // getcwd
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir
39cdf0e10cSrcweir // <function_cnvrtPth>
cnvrtPth(::rtl::OString sysPth)40cdf0e10cSrcweir ::rtl::OUString cnvrtPth( ::rtl::OString sysPth ) {
41cdf0e10cSrcweir
42cdf0e10cSrcweir using ::osl::FileBase;
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir using ::rtl::OString;
45cdf0e10cSrcweir
46cdf0e10cSrcweir ::rtl::OUString ret;
47cdf0e10cSrcweir sysPth = sysPth.replace( '\\','/' );
48cdf0e10cSrcweir OUString pth( OUString::createFromAscii( sysPth.getStr() ) );
49cdf0e10cSrcweir
50cdf0e10cSrcweir if ( sysPth.indexOf("..") != -1 ) {
51cdf0e10cSrcweir
52cdf0e10cSrcweir // <hack> for osl_normalizePath() can't handle relatives
53cdf0e10cSrcweir char buffer[256];
54cdf0e10cSrcweir OString curPth(getcwd(buffer,256));
55cdf0e10cSrcweir // </hack>
56cdf0e10cSrcweir OUString nrmCurPth;
57cdf0e10cSrcweir FileBase::normalizePath( OUString::createFromAscii( curPth ) ,
58cdf0e10cSrcweir nrmCurPth );
59cdf0e10cSrcweir FileBase::getAbsolutePath( nrmCurPth, pth, ret );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir else {
62cdf0e10cSrcweir FileBase::normalizePath( pth, ret );
63cdf0e10cSrcweir }
64cdf0e10cSrcweir return ret;
65cdf0e10cSrcweir
66cdf0e10cSrcweir } // </function_cnvrtPth>
67cdf0e10cSrcweir
68cdf0e10cSrcweir // <function_getEntriesFromFile>
getEntriesFromFile(sal_Char * fName,vector<sal_Char * > & entries)69cdf0e10cSrcweir sal_uInt32 getEntriesFromFile( sal_Char* fName,
70cdf0e10cSrcweir vector< sal_Char* >& entries ) {
71cdf0e10cSrcweir
72cdf0e10cSrcweir ::osl::File inFile( cnvrtPth( fName ) );
73cdf0e10cSrcweir if ( inFile.open( OpenFlag_Read ) == ::osl::FileBase::E_None) {
74cdf0e10cSrcweir ::rtl::ByteSequence byteSeq;
75cdf0e10cSrcweir inFile.readLine( byteSeq );
76cdf0e10cSrcweir while ( byteSeq.getLength() ) {
77cdf0e10cSrcweir sal_uInt32 len = byteSeq.getLength();
78cdf0e10cSrcweir sal_uInt32 i;
79cdf0e10cSrcweir sal_Char* pEnt = new sal_Char[ len+1 ];
80cdf0e10cSrcweir sal_Char* bsPtr = (sal_Char*)byteSeq.getArray();
81cdf0e10cSrcweir for ( i=0; i<len; i++ ) {
82cdf0e10cSrcweir pEnt[i] = bsPtr[i];
83cdf0e10cSrcweir }
84cdf0e10cSrcweir pEnt[len] = '\0';
85cdf0e10cSrcweir entries.push_back( pEnt );
86cdf0e10cSrcweir
87cdf0e10cSrcweir inFile.readLine( byteSeq );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir }
90cdf0e10cSrcweir return ( entries.size() );
91cdf0e10cSrcweir
92cdf0e10cSrcweir } // </function_getEntriesFromFile>
93cdf0e10cSrcweir
94cdf0e10cSrcweir // <function_cpy>
cpy(sal_Char ** dest,const sal_Char * src)95cdf0e10cSrcweir sal_Char* cpy( sal_Char** dest, const sal_Char* src ) {
96cdf0e10cSrcweir
97cdf0e10cSrcweir *dest = new sal_Char[ ln(src)+1 ];
98cdf0e10cSrcweir // set pointer
99cdf0e10cSrcweir sal_Char* pdest = *dest;
100cdf0e10cSrcweir const sal_Char* psrc = src;
101cdf0e10cSrcweir
102cdf0e10cSrcweir // copy string by char
103cdf0e10cSrcweir while( *pdest++ = *psrc++ );
104cdf0e10cSrcweir
105cdf0e10cSrcweir return ( *dest );
106cdf0e10cSrcweir
107cdf0e10cSrcweir } // </function_cpy>
108cdf0e10cSrcweir
109cdf0e10cSrcweir // <function_cat>
cat(const sal_Char * str1,const sal_Char * str2)110cdf0e10cSrcweir sal_Char* cat( const sal_Char* str1, const sal_Char* str2 ) {
111cdf0e10cSrcweir
112cdf0e10cSrcweir // allocate memory for destination string
113cdf0e10cSrcweir sal_Char* dest = new sal_Char[ ln(str1)+ln(str2)+1 ];
114cdf0e10cSrcweir
115cdf0e10cSrcweir // set pointers
116cdf0e10cSrcweir sal_Char* pdest = dest;
117cdf0e10cSrcweir const sal_Char* psrc = str1;
118cdf0e10cSrcweir
119cdf0e10cSrcweir // copy string1 by char to dest
120cdf0e10cSrcweir while( *pdest++ = *psrc++ );
121cdf0e10cSrcweir pdest--;
122cdf0e10cSrcweir psrc = str2;
123cdf0e10cSrcweir while( *pdest++ = *psrc++ );
124cdf0e10cSrcweir
125cdf0e10cSrcweir return ( dest );
126cdf0e10cSrcweir
127cdf0e10cSrcweir } // </function_cat>
128cdf0e10cSrcweir
129cdf0e10cSrcweir // <function_ln>
ln(const sal_Char * str)130cdf0e10cSrcweir sal_uInt32 ln( const sal_Char* str ) {
131cdf0e10cSrcweir
132cdf0e10cSrcweir sal_uInt32 len = 0;
133cdf0e10cSrcweir const sal_Char* ptr = str;
134cdf0e10cSrcweir
135cdf0e10cSrcweir if( ptr ) {
136cdf0e10cSrcweir while( *ptr++ ) len++;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir return(len);
140cdf0e10cSrcweir } // <function_ln>
141cdf0e10cSrcweir
142cdf0e10cSrcweir } // </namespace_tstutl>
143cdf0e10cSrcweir
144