diff options
| author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-02-19 06:14:24 +0000 |
|---|---|---|
| committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-02-19 06:14:24 +0000 |
| commit | 6fafeb146e9efd59140ea58cebd7dd38ae9a6379 (patch) | |
| tree | 7db89ba6a28932514b105d620bba4884ec332ec3 /libdde_linux26/mk/rel2abs.sh | |
| parent | 38c2c2458e3f4ecb329ff35621806252aac209b9 (diff) | |
| parent | 8df772b3c665e663f6f9d2a70f9c691590bd3f91 (diff) | |
Merge branch 'dde' into upstream-merged
Diffstat (limited to 'libdde_linux26/mk/rel2abs.sh')
| -rwxr-xr-x | libdde_linux26/mk/rel2abs.sh | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/libdde_linux26/mk/rel2abs.sh b/libdde_linux26/mk/rel2abs.sh new file mode 100755 index 00000000..33dd8a5b --- /dev/null +++ b/libdde_linux26/mk/rel2abs.sh @@ -0,0 +1,72 @@ +#! /bin/bash +# +# Convert relative path to absolute one +# +# Adam Lackorzynski <adam@os.inf.tu-dresden.de> +# + +help() +{ + echo PWD=\$PWD $0 relpath1 [relpath2 [..]] + exit $1 +} + +convertpath() +{ + relpath=$1 + basepath=$PWD + # sanity checks + [ -z "$relpath" -o -z "$basepath" ] && help 1 + [ "${basepath#/}" = "${basepath}" ] && help 1 + [ "${basepath/\/..\//}" = "${basepath}" ] || help 1 + [ "${basepath/\/.\//}" = "${basepath}" ] || help 1 + [ "${basepath/%\/../}" = "${basepath}" ] || help 1 + [ "${basepath/%\/./}" = "${basepath}" ] || help 1 + + + # remove slashes at the end + while [ "${relpath%/}" != "${relpath}" ]; + do relpath="${relpath%/}"; done + + # remove double/multi slashes + while [ "${relpath/\/\///}" != "${relpath}" ]; + do relpath=${relpath/\/\///}; done + + # is relpath relative? + if [ "${relpath#/}" != "${relpath}" ]; then + basepath='' + relpath=${relpath#/} + fi + + relpath="$relpath/" + + while [ -n "$relpath" ]; + do + elem=${relpath%%/*} + relpath=${relpath#*/} + + case $elem in + .) # skip + ;; + ..) + basepath=${basepath%/*} + ;; + *) + basepath=$basepath/$elem + ;; + esac + + done + + [ -z "$basepath" ] && basepath=/$basepath + + echo $basepath +} + +while [ -n "$1" ]; +do + convertpath $1 + shift +done + +exit 0 |
