source: josm/trunk/tools/japicc/modules/Internals/Path.pm

Last change on this file was 13595, checked in by Don-vip, 7 years ago

tools update: Groovy 2.4.15, PMD 6.2.0, JAPICC 2.4

File size: 1.9 KB
Line 
1###########################################################################
2# A module with functions to handle paths
3#
4# Copyright (C) 2017-2018 Andrey Ponomarenko's ABI Laboratory
5#
6# Written by Andrey Ponomarenko
7#
8# This library is free software; you can redistribute it and/or
9# modify it under the terms of the GNU Lesser General Public
10# License as published by the Free Software Foundation; either
11# version 2.1 of the License, or (at your option) any later version.
12#
13# This library is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public
19# License along with this library; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21# MA 02110-1301 USA.
22###########################################################################
23use strict;
24use Cwd qw(realpath);
25
26sub pathFmt(@)
27{
28 my $Path = shift(@_);
29 my $Fmt = $In::Opt{"OS"};
30 if(@_) {
31 $Fmt = shift(@_);
32 }
33
34 $Path=~s/[\/\\]+\.?\Z//g;
35 if($Fmt eq "windows")
36 {
37 $Path=~s/\//\\/g;
38 $Path = lc($Path);
39 }
40 else {
41 $Path=~s/\\/\//g;
42 }
43
44 $Path=~s/[\/\\]+\Z//g;
45
46 return $Path;
47}
48
49sub getAbsPath($)
50{ # abs_path() should NOT be called for absolute inputs
51 # because it can change them
52 my $Path = $_[0];
53 if(not isAbsPath($Path)) {
54 $Path = abs_path($Path);
55 }
56 return pathFmt($Path, $In::Opt{"OS"});
57}
58
59sub realpath_F($)
60{
61 my $Path = $_[0];
62 return pathFmt(realpath($Path));
63}
64
65sub join_P($$)
66{
67 my $S = "/";
68 if($In::Opt{"OS"} eq "windows") {
69 $S = "\\";
70 }
71 return join($S, @_);
72}
73
74sub join_A($$)
75{
76 my $S = ":";
77 if($In::Opt{"OS"} eq "windows") {
78 $S = ";";
79 }
80 return join($S, @_);
81}
82
83return 1;
Note: See TracBrowser for help on using the repository browser.