1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
|
package filehelper;
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# 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.
#
# 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).
#
# 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.
#
#*************************************************************************
use strict;
use warnings;
use strict;
use English; # $OSNAME, ...
use stringhelper;
BEGIN {
use Exporter ();
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
$VERSION = 1.00;
# if using RCS/CVS, this may be preferred
$VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
@ISA = qw(Exporter);
@EXPORT = qw(&dospath &unixpath &appendPath &appendClass &setPrefix &getToolsPrefix &rmkdir &getJavaPathSeparator &getJavaFileDirSeparator &getFromPathes &convertCygwinPath);
%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
# your exported package globals go here,
# as well as any optionally exported functions
@EXPORT_OK = ( ); # qw($Var1 %Hashit &func3);
}
# ------------------------------------------------------------------------------
# helper, to change all file separators
sub dospath($)
{
my $sPath = shift;
if ($OSNAME eq "MSWin32")
{
# make out of '/' a '\'
$sPath =~ s/\//\\/g;
}
else
{
}
return $sPath;
}
sub unixpath($)
{
my $sPath = shift;
if ($OSNAME ne "MSWin32")
{
# make out of '\' a '/'
$sPath =~ s/\\/\//g;
}
else
{
}
return $sPath;
}
# ------------------------------------------------------------------------------
# sub getGlobalInstSet()
# {
# my $sJumbo;
# if ($OSNAME eq "MSWin32")
# {
# # $sJumbo = "\\\\so-gfxcmp-lin\\jumbo_ship\\install";
# $sJumbo = "\\\\jumbo.germany.sun.com\\ship\\install";
# }
# elsif ($OSNAME eq "cygwin")
# {
# $sJumbo = "//jumbo.germany.sun.com/ship/install";
# }
# else
# {
# $sJumbo = "/net/jumbo.germany.sun.com/ship/install";
# }
# return $sJumbo;
# }
# ------------------------------------------------------------------------------
# sub getSolarisLockFile()
# {
# my $sSolarisLockFile = "/tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e";
# return $sSolarisLockFile;
# }
#
# sub checkForSolarisLock()
# {
# if ($OSNAME eq "solaris")
# {
# # wait until the internal installer lock is gone
# while ( -e getSolarisLockFile() )
# {
# while ( -e getSolarisLockFile() )
# {
# log_print( "Warning: Wait active until installer lock is gone. \n");
# sleep 1;
# }
# sleep 5;
# }
# log_print( "[ok], lock is gone.\n");
# }
# }
#
# sub deleteSolarisLock()
# {
# if ($OSNAME eq "solaris")
# {
# sleep 1;
# unlink getSolarisLockFile();
#
# sleep 1;
# if ( -e getSolarisLockFile() )
# {
# # try delete the file as super user?
# `sudo rm -f getSolarisLockFile()`;
# sleep 1;
# }
# }
# }
# ------------------------------------------------------------------------------
sub appendPath($$)
{
my $sPath = shift;
my $sAddPath = shift;
if ($sPath && $sAddPath)
{
if (! endswith($sPath, "/") &&
! endswith($sPath, "\\"))
{
# getJavaFileDirSeparator();
$sPath .= "/";
}
$sPath .= $sAddPath;
}
return $sPath;
}
sub appendClass($$)
{
my $sPath = shift;
my $sAddPath = shift;
my $sSeparator = getJavaPathSeparator();
if ($sPath && $sAddPath)
{
if (! endswith($sPath, $sSeparator))
{
# getJavaFileDirSeparator();
$sPath .= $sSeparator;
}
$sPath .= $sAddPath;
}
return $sPath;
}
# ------------------------------------------------------------------------------
our $sPrefix;
sub setPrefix($)
{
$sPrefix = shift;
}
sub getPrefix()
{
return $sPrefix;
}
# ------------------------------------------------------------------------------
our $programprefix;
# sub getProgramPrefix($)
# {
# my $sDBDistinct = shift;
#
# my $sProgramPrefix;
# if (! $programprefix)
# {
# if ($OSNAME eq "MSWin32")
# {
# # $programprefix = "C:/gfxcmp/programs";
# $programprefix = "C:";
# if (getPrefix() eq "performance")
# {
# $programprefix = "D:";
# }
# $programprefix = appendPath($programprefix, "gp");
# }
# elsif ($OSNAME eq "linux")
# {
# $programprefix = "/space/" . getPrefix() . "/programs";
# }
# elsif ($OSNAME eq "solaris")
# {
# $programprefix = "/space/" . getPrefix() . "/programs";
# }
# else
# {
# print "Error: This environment isn't supported yet.\n";
# exit(1);
# }
# }
# $sProgramPrefix = appendPath($programprefix, substr($sDBDistinct, 0, 19));
# return $sProgramPrefix;
# }
# ------------------------------------------------------------------------------
our $toolsprefix;
sub getToolsPrefix()
{
my $sToolsPrefix;
if (! $toolsprefix)
{
if ($OSNAME eq "MSWin32")
{
$toolsprefix = "C:";
if (getPrefix() eq "performance")
{
$toolsprefix = "D:";
}
}
elsif ($OSNAME eq "linux")
{
$toolsprefix = "/space";
}
elsif ($OSNAME eq "solaris")
{
$toolsprefix = "/space";
}
else
{
print "Error: This environment isn't supported yet.\n";
exit(1);
}
$toolsprefix = appendPath($toolsprefix, getPrefix());
$toolsprefix = appendPath($toolsprefix, "tools");
}
$sToolsPrefix = $toolsprefix;
return $sToolsPrefix;
}
# also Windows safe
sub rmkdir($)
{
my($tpath) = shift;
my $dir;
my $accum = "";
my @dirs = split(/\//, $tpath);
if ( $#dirs eq 0 )
{
@dirs = split("\\\\", $tpath);
}
foreach $dir (@dirs)
{
$accum = "$accum$dir/";
if($dir ne "")
{
if(! -d "$accum")
{
mkdir ($accum);
chmod (0777,$accum);
}
}
}
}
# ------------------------------------------------------------------------------
sub getJavaPathSeparator()
{
my $ps = ":";
if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
{
$ps = ";";
}
return $ps;
}
# ------------------------------------------------------------------------------
sub getJavaFileDirSeparator()
{
my $sfs = "/";
if ($OSNAME eq "MSWin32")
{
$sfs = "\\";
}
return $sfs;
}
# ------------------------------------------------------------------------------
sub getFromPathes($$)
{
my $sPathesIni = shift;
my $searchvalue = shift;
my $sResult;
if ( -e $sPathesIni)
{
local *PATHES;
if (open(PATHES, "$sPathesIni"))
{
my $line;
while ($line = <PATHES>)
{
chomp($line);
if ($line =~ /^$searchvalue=(.*)$/)
{
$sResult = $1;
}
}
close(PATHES);
}
}
return $sResult;
}
sub convertCygwinPath($)
{
my $sPath = shift;
if ($OSNAME eq "cygwin")
{
# print "Cygwin Path Patch.\n" if ($verbose);
if ($sPath =~ /\/cygdrive\/(.)/)
{
my $Letter = $1;
$sPath =~ s/\/cygdrive\/${Letter}/${Letter}\:/;
# print "Cygwin Path Patch: '$sPath'\n" if ($verbose);
}
}
return $sPath;
}
1;
|