]> sourceware.org Git - lvm2.git/blob - scripts/relpath.awk
Refer to details of snapshot of raid problem.
[lvm2.git] / scripts / relpath.awk
1 #!/usr/bin/awk -f
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 {
22 length_from = split($1, from, "/");
23 length_to = split($2, to, "/") ;
24 l = 1;
25 while (l <= length_from && l <= length_to && from[l] == to[l])
26 l++;
27 for (i = l; i <= length_from && length(from[i]); i++) {
28 if (i > l)
29 p = sprintf("%s/", p);
30 p = sprintf("%s..", p);
31 }
32 for (i = l; i <= length_to && length(to[i]); i++) {
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 }
This page took 0.036138 seconds and 5 git commands to generate.