update dev300-m58
[ooovba.git] / testshl2 / source / filehelper.cxx
blobca868e054bedbff70bfed2e51bdb24a5cfee8bad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filehelper.cxx,v $
10 * $Revision: 1.12 $
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"
34 #include <string.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string>
39 #include "testshl/filehelper.hxx"
40 #include "testshl/getopt.hxx"
42 #include <osl/process.h>
43 #include <osl/file.hxx>
45 #ifndef _SAL_TRES_H_
46 #include <rtl/tres.h>
47 #endif
49 namespace FileHelper
51 // -----------------------------------------------------------------------------
52 // taken from setup2
53 std::string getTempPath()
55 std::string sTempDir;
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 );
66 else
68 #if (defined UNX) || (defined OS2)
69 int nLen;
70 pTmp = P_tmpdir;
71 nLen = strlen(pTmp);
72 if (pTmp[ nLen - 1] == '/')
74 char cBuf[256];
75 char* pBuf = cBuf;
76 strncpy( pBuf, pTmp, nLen - 1 );
77 pBuf[nLen - 1] = '\0';
78 sTempDir = std::string( pBuf );
80 else
82 sTempDir = std::string( pTmp );
84 #else
85 fprintf(stderr, "error: No temp dir found.\n");
86 #endif
88 return sTempDir;
91 // -----------------------------------------------------------------------------
92 rtl::OUString convertPath( rtl::OUString const& _suSysPath )
94 // PRE: String should contain a filename, relativ or absolut
95 rtl::OUString suURL;
96 bool bRelativ = false;
97 #ifdef WNT
98 sal_Char cFileSep[] = "\\";
99 #endif
100 #if (defined UNX) || (defined OS2)
101 sal_Char cFileSep[] = "/";
102 #endif
104 if ( _suSysPath.indexOf(rtl::OUString::createFromAscii("..")) == 0 )
106 bRelativ = true;
108 else if ( _suSysPath.indexOf(rtl::OUString::createFromAscii(cFileSep)) != 0 )
110 // no fileseparator found at first position found, must be relative
111 bRelativ = true;
114 if (bRelativ)
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());
128 else
130 osl::FileBase::getFileURLFromSystemPath( _suSysPath, suURL );
132 return 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 )
146 //# {
147 //# CmdLineBits retflags = rtl_tres_Flag_OK;
148 //#
149 //# vector< sal_Char* >::const_iterator iter = cmdln.begin();
150 //# while( iter != cmdln.end() )
151 //# {
152 //# fprintf( stderr, "%s\n", *iter );
153 //# if ( *iter[0] == '-' )
154 //# {
155 //# rtl::OString item( *iter );
156 //# if ( item == "-boom" ) // stop near error position, exception only
157 //# retflags |= rtl_tres_Flag_BOOM;
158 //#
159 //# if ( item == "-verbose" )
160 //# retflags |= rtl_tres_Flag_VERBOSE;
161 //#
162 //# if ( item == "-skip" )
163 //# retflags |= rtl_tres_Flag_SKIP;
164 //#
165 //# if ( item == "-log" )
166 //# retflags |= rtl_tres_Flag_LOG;
167 //#
168 //# if ( item == "-his" )
169 //# retflags |= rtl_tres_Flag_HIS;
170 //#
171 //# if ( item == "-time" )
172 //# retflags |= rtl_tres_Flag_TIME;
173 //#
174 //# if ( item == "-msg" )
175 //# retflags |= rtl_tres_Flag_MSG;
176 //# }
177 //# iter++;
178 //# }
179 //#
180 //# return retflags;
181 //# }
182 //#
183 //# CmdLineBits createFlags(int argc, char* argv[])
184 //# {
185 //# vector< sal_Char* > cmdln;
186 //# sal_Int32 i;
187 //#
188 //# /* collect comandline */
189 //# for ( i = 1; i < argc; i++ )
190 //# cmdln.push_back( argv[i] );
191 //#
192 //# return createFlags(cmdln);
193 //# }
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;
213 return retflags;
215 // -----------------------------------------------------------------------------
218 * display usage screen
221 //# void usage()
222 //# {
223 //# fprintf( stdout,
224 //# "USAGE: testshl shlname [-boom][-verbose][-log][-his][-msg]\n" );
225 //# exit(0);
226 //# }
229 } // namespace FileHelper