]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/walk.sh
41d24b0319dc35b09c49311504ccb4b3fcb4cb7f
[lilypond.git] / buildscripts / walk.sh
1 #!@SHELL@
2 # walk.sh
3 # ugh
4 # print reversed relative path to $1
5
6 function base ()
7 {
8     expr "$1" : "\(/[^/]*\)"
9 }
10
11 function unbase ()
12 {
13     expr "$1" : "/[^/]*\(.*\)"
14 }
15
16 function walk ()
17 {
18     from=`(cd "$1" && pwd)`
19     to=`pwd`
20     t=`base "$to"`
21     f=`base "$from"`
22     while [ -n "$t" -a "$t" = "$f" ]; do
23         to=`unbase "$to"`
24         from=`unbase "$from"`
25         t=`base "$to"`
26         f=`base "$from"`
27     done
28     i=`echo $from | sed -e 's/[^/]\+/../g'`
29     if expr "$from" : '/' > /dev/null 2>&1; then
30         c=..
31     fi
32     echo $c$i$to
33 }
34
35 walk $1
36