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 | ###########################################################################
|
---|
21 | use strict;
|
---|
22 | use Cwd qw(realpath);
|
---|
23 |
|
---|
24 | sub 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 |
|
---|
47 | sub 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 |
|
---|
57 | sub realpath_F($)
|
---|
58 | {
|
---|
59 | my $Path = $_[0];
|
---|
60 | return pathFmt(realpath($Path));
|
---|
61 | }
|
---|
62 |
|
---|
63 | sub join_P($$)
|
---|
64 | {
|
---|
65 | my $S = "/";
|
---|
66 | if($In::Opt{"OS"} eq "windows") {
|
---|
67 | $S = "\\";
|
---|
68 | }
|
---|
69 | return join($S, @_);
|
---|
70 | }
|
---|
71 |
|
---|
72 | sub join_A($$)
|
---|
73 | {
|
---|
74 | my $S = ":";
|
---|
75 | if($In::Opt{"OS"} eq "windows") {
|
---|
76 | $S = ";";
|
---|
77 | }
|
---|
78 | return join($S, @_);
|
---|
79 | }
|
---|
80 |
|
---|
81 | return 1;
|
---|