michael@0: #!env perl michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: use File::Spec::Unix; michael@0: use strict; michael@0: michael@0: print "Usage: $0 dest_path start_path\n" if ($#ARGV+1 != 2); michael@0: my $finish = my_canonpath(shift); michael@0: my $start = my_canonpath(shift); michael@0: michael@0: my $res = File::Spec::Unix->abs2rel($finish, $start); michael@0: michael@0: #print STDERR "abs2rel($finish,$start) = $res\n"; michael@0: print "$res\n"; michael@0: michael@0: sub my_canonpath($) { michael@0: my ($file) = @_; michael@0: my (@inlist, @outlist, $dir); michael@0: michael@0: # Do what File::Spec::Unix->no_upwards should do michael@0: my @inlist = split(/\//, File::Spec::Unix->canonpath($file)); michael@0: foreach $dir (@inlist) { michael@0: if ($dir eq '..') { michael@0: pop @outlist; michael@0: } else { michael@0: push @outlist, $dir; michael@0: } michael@0: } michael@0: $file = join '/',@outlist; michael@0: return $file; michael@0: } michael@0: