summaryrefslogtreecommitdiffstats
path: root/scripts/libptxdist.sh
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2012-04-07 22:10:11 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2012-12-17 15:13:42 +0100
commit391daa2727f7b4c1631d1607bd66c39db47715a9 (patch)
treed97e9458d0fe20d854862b95bdf06fd5e074fc28 /scripts/libptxdist.sh
parent98002fb28048d96366d4b41400e271ebf5054039 (diff)
downloadptxdist-391daa2727f7b4c1631d1607bd66c39db47715a9.tar.gz
ptxdist-391daa2727f7b4c1631d1607bd66c39db47715a9.tar.xz
move ptxd_abs2rel to libptxdist.sh
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts/libptxdist.sh')
-rw-r--r--scripts/libptxdist.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/libptxdist.sh b/scripts/libptxdist.sh
index 42b9965ce..6c93e57f5 100644
--- a/scripts/libptxdist.sh
+++ b/scripts/libptxdist.sh
@@ -585,6 +585,50 @@ export -f ptxd_abspath
#
+# calculate the relative path from one absolute path to another
+#
+# $1 from path
+# $2 to path
+#
+ptxd_abs2rel() {
+ local from from_parts to to_parts max orig_IFS
+ if [ $# -ne 2 ]; then
+ ptxd_bailout "usage: ptxd_abs2rel <from> <to>"
+ fi
+
+ from="${1}"
+ to="${2}"
+
+ orig_IFS="${IFS}"
+ IFS="/"
+ from_parts=(${from#/})
+ to_parts=(${to#/})
+
+ if [ ${#from_parts[@]} -gt ${#to_parts[@]} ]; then
+ max=${#from_parts[@]}
+ else
+ max=${#to_parts[@]}
+ fi
+
+ for ((i = 0; i < ${max}; i++)); do
+ from="${from_parts[i]}"
+ to="${to_parts[i]}"
+
+ if [ "${from}" = "${to}" ]; then
+ unset from_parts[$i]
+ unset to_parts[$i]
+ elif [ -n "${from}" ]; then
+ from_parts[$i]=".."
+ fi
+ done
+
+ echo "${from_parts[*]}${from_parts[*]:+/}${to_parts[*]}"
+ IFS="${orig_IFS}"
+}
+export -f ptxd_abs2rel
+
+
+#
# prints a path but removes non interesting prefixes
#
ptxd_print_path() {