]>
sourceware.org Git - lvm2.git/blob - scripts/relpath.awk
3 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
5 # This file is part of LVM2.
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.
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
15 # relpath.awk: Script is used to calculate relative path
16 # between two real absolute paths.
18 # echo /a/b/c/d /a/b/e/f | relpath.awk
22 length_from =
split($
1, from
, "/");
23 length_to =
split($
2, to
, "/") ;
25 while (l
<= length_from
&& l
<= length_to
&& from
[l
] == to
[l
])
27 for (i = l
; i
<= length_from
&& length(from
[i
]); i
++) {
29 p =
sprintf("%s/", p
);
30 p =
sprintf("%s..", p
);
32 for (i = l
; i
<= length_to
&& length(to
[i
]); i
++) {
34 p =
sprintf("%s/", p
);
35 p =
sprintf("%s%s", p
, to
[i
]);
38 p =
sprintf("%s/", p
);
This page took 0.036138 seconds and 5 git commands to generate.