root/WizardsToolkit/branches/WizardsToolkit-1.0.6/winpath.sh

Revision 1, 1.4 KB (checked in by cristy, 3 months ago)


Line 
1#!/bin/sh
2#
3# Convert the specified POSIX path to a Windows path under MinGW and Cygwin
4# The optional second parameter specifies the level of backslash escaping
5# to apply for each Windows backslash position in order to support varying
6# levels of variable substitutions in scripts.
7#
8# Note that Cygwin includes the 'cygpath' utility, which already provides
9# path translation capability.
10#
11#
12arg="$1"
13escapes=0
14if test -n "$2"
15then
16  escapes="$2"
17fi
18if test $escapes -gt 3
19then
20  echo "$0: escape level must in range 0 - 3"
21  exit 1
22fi
23result=''
24length=0
25max_length=0
26mount | sed -e 's:\\:/:g'  | (
27  IFS="\n"
28  while read mount_entry
29  do
30    win_mount_path=`echo "$mount_entry" | sed -e 's: .*::g'`
31    unix_mount_path=`echo "$mount_entry" | sed -e 's:.* on ::;s: type .*::'`
32    temp=`echo "$arg" | sed -e "s!^$unix_mount_path!$win_mount_path!"`
33    if test "$temp" != "$arg"
34    then
35      candidate="$temp"
36      length=${#unix_mount_path}
37      if test $length -gt $max_length
38      then
39        result=$candidate
40        max_length=$length
41      fi
42    fi
43  done
44  if test -z "$result"
45  then
46    echo "$0: path \"$arg\" is not mounted"
47    exit 1
48  fi
49  case $escapes in
50    0)
51     echo "$result" | sed -e 's:/:\\:g'
52     ;;
53    1)
54     echo "$result" | sed -e 's:/:\\\\:g'
55     ;;
56    2)
57     echo "$result" | sed -e 's:/:\\\\\\\\:g'
58     ;;
59    3)
60     echo "$result" | sed -e 's:/:\\\\\\\\\\\\\\\\:g'
61     ;;
62  esac
63  exit 0;
64 )
Note: See TracBrowser for help on using the browser.