root / ImageMagick / branches / ImageMagick-6.4.0 / winpath.sh

Revision 7647, 1.4 kB (checked in by cristy, 12 months ago)
  • Property svn:executable set to *
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# Written by Bob Friesenhahn, June 2002
12#
13arg="$1"
14escapes=0
15if test -n "$2"
16then
17  escapes="$2"
18fi
19if test $escapes -gt 3
20then
21  echo "$0: escape level must in range 0 - 3"
22  exit 1
23fi
24result=''
25length=0
26max_length=0
27mount | sed -e 's:\\:/:g'  | (
28  IFS="\n"
29  while read mount_entry
30  do
31    win_mount_path=`echo "$mount_entry" | sed -e 's: .*::g'`
32    unix_mount_path=`echo "$mount_entry" | sed -e 's:.* on ::;s: type .*::'`
33    temp=`echo "$arg" | sed -e "s!^$unix_mount_path!$win_mount_path!"`
34    if test "$temp" != "$arg"
35    then
36      candidate="$temp"
37      length=${#unix_mount_path}
38      if test $length -gt $max_length
39      then
40        result=$candidate
41        max_length=$length
42      fi
43    fi
44  done
45  if test -z "$result"
46  then
47    echo "$0: path \"$arg\" is not mounted"
48    exit 1
49  fi
50  case $escapes in
51    0)
52     echo "$result" | sed -e 's:/:\\:g'
53     ;;
54    1)
55     echo "$result" | sed -e 's:/:\\\\:g'
56     ;;
57    2)
58     echo "$result" | sed -e 's:/:\\\\\\\\:g'
59     ;;
60    3)
61     echo "$result" | sed -e 's:/:\\\\\\\\\\\\\\\\:g'
62     ;;
63  esac
64  exit 0;
65 )
Note: See TracBrowser for help on using the browser.