]>
Commit | Line | Data |
---|---|---|
3ceb7608 | 1 | #!/usr/bin/awk -f |
6008aabe ZK |
2 | # |
3 | # Copyright (C) 2010 Red Hat, Inc. All rights reserved. | |
4 | # | |
5 | # This file is part of LVM2. | |
6 | # | |
7 | # This copyrighted material is made available to anyone wishing to use, | |
8 | # modify, copy, or redistribute it subject to the terms and conditions | |
9 | # of the GNU General Public License v.2. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program; if not, write to the Free Software Foundation, | |
13 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
14 | ||
15 | # relpath.awk: Script is used to calculate relative path | |
16 | # between two real absolute paths. | |
17 | # | |
18 | # echo /a/b/c/d /a/b/e/f | relpath.awk | |
19 | # -> ../../e/f/ | |
20 | ||
21 | { | |
3ed801fb MP |
22 | length_from = split($1, from, "/"); |
23 | length_to = split($2, to, "/") ; | |
6008aabe | 24 | l = 1; |
3ed801fb | 25 | while (l <= length_from && l <= length_to && from[l] == to[l]) |
6008aabe | 26 | l++; |
3ed801fb | 27 | for (i = l; i <= length_from && length(from[i]); i++) { |
6008aabe ZK |
28 | if (i > l) |
29 | p = sprintf("%s/", p); | |
30 | p = sprintf("%s..", p); | |
31 | } | |
3ed801fb | 32 | for (i = l; i <= length_to && length(to[i]); i++) { |
6008aabe ZK |
33 | if (length(p) > 0) |
34 | p = sprintf("%s/", p); | |
35 | p = sprintf("%s%s", p, to[i]); | |
36 | } | |
37 | if (length(p)) | |
38 | p = sprintf("%s/", p); | |
39 | print p | |
40 | } |