Improve GambitREPL for iOS example.
[gambit-c.git] / relpath
blob43dd2d2de53d1f1188e685522156d95c5e7845fb
1 #! /bin/sh
3 # Conversion of an absolute path to a relative path.
5 # Copyright (c) 2008 by Marc Feeley, All Rights Reserved.
7 TARGET_PATH=`echo "$1" | sed -e 's#\\\\#/#g' -e 's#//*#/#g' -e 's#/$##' -e 's#\([/]\{0,1\}\)\(.*\)#\2/#' -e 's#^/$##'`
8 ORIG_DIR=`echo "$2" | sed -e 's#\\\\#/#g' -e 's#//*#/#g' -e 's#/$##' -e 's#\([/]\{0,1\}\)\(.*\)#\2/#' -e 's#^/$##'`
9 ENABLE_MV="$3"
11 while test "$TARGET_PATH" != "" -a "$ORIG_DIR" != ""; do
12 TP_CAR=`echo "$TARGET_PATH" | sed -e 's#\([^/]*[/]\)\(.*\)#\1#'`
13 TP_CDR=`echo "$TARGET_PATH" | sed -e 's#\([^/]*[/]\)\(.*\)#\2#'`
14 OD_CAR=`echo "$ORIG_DIR" | sed -e 's#\([^/]*[/]\)\(.*\)#\1#'`
15 OD_CDR=`echo "$ORIG_DIR" | sed -e 's#\([^/]*[/]\)\(.*\)#\2#'`
16 if test "$TP_CAR" = "$OD_CAR"; then
17 TARGET_PATH="$TP_CDR"
18 ORIG_DIR="$OD_CDR"
19 else
20 break
22 done
24 REL_PATH=`echo "$ORIG_DIR" | sed -e 's#[^/]*[/]#../#g'`"$TARGET_PATH"
26 if test "$ENABLE_MV" = "yes"; then
27 echo "$REL_PATH" | sed -e 's#^#/#' -e 's#^\(.*/\)\([^/][^/]*\)/\([^/][^/]*\)/$#\1current/\3/#' -e 's#^/##'
28 else
29 echo "$REL_PATH"