blob: b881b378156ba0f1bbf345f30dd938f6e9269355 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001#!/bin/sh
Cristy7ce65e72015-12-12 18:03:16 -05002# Copyright (C) 1999-2016 ImageMagick Studio LLC
cristy3ed852e2009-09-05 21:47:34 +00003# Copyright (C) 2003 - 2008 GraphicsMagick Group
4#
5# This program is covered by multiple licenses, which are described in
6# LICENSE. You should have received a copy of LICENSE with this
Cristy64599592016-11-04 22:32:09 -04007# package; otherwise see https://www.imagemagick.org/script/license.php.
cristy3ed852e2009-09-05 21:47:34 +00008#
9# Convert the specified POSIX path to a Windows path under MinGW and Cygwin
10# The optional second parameter specifies the level of backslash escaping
11# to apply for each Windows backslash position in order to support varying
12# levels of variable substitutions in scripts.
13#
14# Note that Cygwin includes the 'cygpath' utility, which already provides
15# path translation capability.
16#
17# Written by Bob Friesenhahn, June 2002
18#
19arg="$1"
20escapes=0
21if test -n "$2"
22then
23 escapes="$2"
24fi
25if test $escapes -gt 3
26then
27 echo "$0: escape level must in range 0 - 3"
28 exit 1
29fi
30result=''
31length=0
32max_length=0
33mount | sed -e 's:\\:/:g' | (
34 IFS="\n"
35 while read mount_entry
36 do
37 win_mount_path=`echo "$mount_entry" | sed -e 's: .*::g'`
38 unix_mount_path=`echo "$mount_entry" | sed -e 's:.* on ::;s: type .*::'`
Cristy4cff7472016-11-08 06:30:29 -050039 temp=`echo "$arg" | sed -e "s!^$unix_mount_path!$win_mount_path/!"`
cristy3ed852e2009-09-05 21:47:34 +000040 if test "$temp" != "$arg"
41 then
42 candidate="$temp"
43 length=${#unix_mount_path}
44 if test $length -gt $max_length
45 then
46 result=$candidate
47 max_length=$length
48 fi
49 fi
50 done
51 if test -z "$result"
52 then
53 echo "$0: path \"$arg\" is not mounted"
54 exit 1
55 fi
56 case $escapes in
57 0)
58 echo "$result" | sed -e 's:/:\\:g'
59 ;;
60 1)
61 echo "$result" | sed -e 's:/:\\\\:g'
62 ;;
63 2)
64 echo "$result" | sed -e 's:/:\\\\\\\\:g'
65 ;;
66 3)
67 echo "$result" | sed -e 's:/:\\\\\\\\\\\\\\\\:g'
68 ;;
69 esac
70 exit 0;
71 )