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

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

update to japi-compliance-checker 2.1

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