1#!/bin/sh 2# Copyright (C) 2003 GraphicsMagick Group 3# 4# This program is covered by multiple licenses, which are described in 5# Copyright.txt. You should have received a copy of Copyright.txt with this 6# package; otherwise see http://www.graphicsmagick.org/www/Copyright.html. 7# 8# Convert the specified POSIX path to a Windows path under MinGW and Cygwin 9# The optional second parameter specifies the level of backslash escaping 10# to apply for each Windows backslash position in order to support varying 11# levels of variable substitutions in scripts. 12# 13# Note that Cygwin includes the 'cygpath' utility, which already provides 14# path translation capability. 15# 16# Written by Bob Friesenhahn <bfriesen@simple.dallas.tx.us> June 2002 17# 18arg="$1" 19escapes=0 20if test -n "$2" 21then 22 escapes="$2" 23fi 24if test $escapes -gt 3 25then 26 echo "$0: escape level must in range 0 - 3" 27 exit 1 28fi 29result='' 30length=0 31max_length=0 32mount | sed -e 's:\\:/:g' | ( 33 IFS="\n" 34 while read mount_entry 35 do 36 win_mount_path=`echo "$mount_entry" | sed -e 's: .*::g'` 37 unix_mount_path=`echo "$mount_entry" | sed -e 's:.* on ::;s: type .*::'` 38 temp=`echo "$arg" | sed -e "s!^$unix_mount_path!$win_mount_path!"` 39 if test "$temp" != "$arg" 40 then 41 candidate="$temp" 42 length=${#unix_mount_path} 43 if test $length -gt $max_length 44 then 45 result=$candidate 46 max_length=$length 47 fi 48 fi 49 done 50 if test -z "$result" 51 then 52 echo "$0: path \"$arg\" is not mounted" 53 exit 1 54 fi 55 case $escapes in 56 0) 57 echo "$result" | sed -e 's:/:\\:g' 58 ;; 59 1) 60 echo "$result" | sed -e 's:/:\\\\:g' 61 ;; 62 2) 63 echo "$result" | sed -e 's:/:\\\\\\\\:g' 64 ;; 65 3) 66 echo "$result" | sed -e 's:/:\\\\\\\\\\\\\\\\:g' 67 ;; 68 esac 69 exit 0; 70 ) 71