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: filehelper.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_testshl2.hxx"
39 #include "testshl/filehelper.hxx"
40 #include "testshl/getopt.hxx"
42 #include <osl/process.h>
43 #include <osl/file.hxx>
51 // -----------------------------------------------------------------------------
53 std::string
getTempPath()
57 char const * pTmp
= getenv( "TEMP" );
58 if (pTmp
== NULL
) pTmp
= getenv("temp");
59 if (pTmp
== NULL
) pTmp
= getenv("TMP");
60 if (pTmp
== NULL
) pTmp
= getenv("tmp");
62 if( pTmp
&& strlen(pTmp
) >= 2 )
64 sTempDir
= std::string( pTmp
);
68 #if (defined UNX) || (defined OS2)
72 if (pTmp
[ nLen
- 1] == '/')
76 strncpy( pBuf
, pTmp
, nLen
- 1 );
77 pBuf
[nLen
- 1] = '\0';
78 sTempDir
= std::string( pBuf
);
82 sTempDir
= std::string( pTmp
);
85 fprintf(stderr
, "error: No temp dir found.\n");
91 // -----------------------------------------------------------------------------
92 rtl::OUString
convertPath( rtl::OUString
const& _suSysPath
)
94 // PRE: String should contain a filename, relativ or absolut
96 bool bRelativ
= false;
98 sal_Char cFileSep
[] = "\\";
100 #if (defined UNX) || (defined OS2)
101 sal_Char cFileSep
[] = "/";
104 if ( _suSysPath
.indexOf(rtl::OUString::createFromAscii("..")) == 0 )
108 else if ( _suSysPath
.indexOf(rtl::OUString::createFromAscii(cFileSep
)) != 0 )
110 // no fileseparator found at first position found, must be relative
116 // filepath contains '..' so it's a relative path make it absolut.
117 rtl::OUString curDirPth
;
118 osl_getProcessWorkingDir( &curDirPth
.pData
);
120 // rtl::OString sCurDirPath = rtl::OUStringToOString(curDirPth, RTL_TEXTENCODING_ASCII_US);
121 // fprintf(stderr, "Current Dir '%s'.\n", sCurDirPath.getStr());
123 osl::FileBase::getAbsoluteFileURL( curDirPth
, _suSysPath
, suURL
);
125 // rtl::OString sURL = rtl::OUStringToOString(suURL, RTL_TEXTENCODING_ASCII_US);
126 // fprintf(stderr, " File URL: '%s'.\n", sURL.getStr());
130 osl::FileBase::getFileURLFromSystemPath( _suSysPath
, suURL
);
134 // -----------------------------------------------------------------------------
135 rtl::OUString
convertPath( rtl::OString
const& sysPth
)
137 rtl::OUString
sysPath( rtl::OUString::createFromAscii( sysPth
.getStr() ) );
138 return convertPath(sysPath
);
142 * create bitmap of comandline parameters
145 //# CmdLineBits createFlags( vector< sal_Char* > const& cmdln )
147 //# CmdLineBits retflags = rtl_tres_Flag_OK;
149 //# vector< sal_Char* >::const_iterator iter = cmdln.begin();
150 //# while( iter != cmdln.end() )
152 //# fprintf( stderr, "%s\n", *iter );
153 //# if ( *iter[0] == '-' )
155 //# rtl::OString item( *iter );
156 //# if ( item == "-boom" ) // stop near error position, exception only
157 //# retflags |= rtl_tres_Flag_BOOM;
159 //# if ( item == "-verbose" )
160 //# retflags |= rtl_tres_Flag_VERBOSE;
162 //# if ( item == "-skip" )
163 //# retflags |= rtl_tres_Flag_SKIP;
165 //# if ( item == "-log" )
166 //# retflags |= rtl_tres_Flag_LOG;
168 //# if ( item == "-his" )
169 //# retflags |= rtl_tres_Flag_HIS;
171 //# if ( item == "-time" )
172 //# retflags |= rtl_tres_Flag_TIME;
174 //# if ( item == "-msg" )
175 //# retflags |= rtl_tres_Flag_MSG;
183 //# CmdLineBits createFlags(int argc, char* argv[])
185 //# vector< sal_Char* > cmdln;
188 //# /* collect comandline */
189 //# for ( i = 1; i < argc; i++ )
190 //# cmdln.push_back( argv[i] );
192 //# return createFlags(cmdln);
195 CmdLineBits
createFlags( GetOpt
& _aOptions
)
197 CmdLineBits retflags
= rtl_tres_Flag_OK
;
199 if (_aOptions
.hasOpt("-boom")) // stop near error position, exception only
201 retflags
|= rtl_tres_Flag_BOOM
;
204 if (_aOptions
.hasOpt("-verbose"))
206 retflags
|= rtl_tres_Flag_VERBOSE
;
209 if (_aOptions
.hasOpt("-quiet"))
211 retflags
|= rtl_tres_Flag_QUIET
;
215 // -----------------------------------------------------------------------------
218 * display usage screen
224 //# "USAGE: testshl shlname [-boom][-verbose][-log][-his][-msg]\n" );
229 } // namespace FileHelper