File: winpath.sh

package info (click to toggle)
imagemagick 6:6.0.6.2-2.9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 33,284 kB
  • ctags: 14,844
  • sloc: ansic: 190,790; cpp: 17,203; sh: 8,740; perl: 4,190; makefile: 1,740; tcl: 459
file content (65 lines) | stat: -rwxr-xr-x 1,484 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
#
# Convert the specified POSIX path to a Windows path under MinGW and Cygwin
# The optional second parameter specifies the level of backslash escaping
# to apply for each Windows backslash position in order to support varying
# levels of variable substitutions in scripts.
#
# Note that Cygwin includes the 'cygpath' utility, which already provides
# path translation capability.
#
# Written by Bob Friesenhahn, June 2002
#
arg="$1"
escapes=0
if test -n "$2"
then
  escapes="$2"
fi
if test $escapes -gt 3
then
  echo "$0: escape level must in range 0 - 3"
  exit 1
fi
result=''
length=0
max_length=0
mount | sed -e 's:\\:/:g'  | (
  IFS="\n"
  while read mount_entry
  do
    win_mount_path=`echo "$mount_entry" | sed -e 's: .*::g'`
    unix_mount_path=`echo "$mount_entry" | sed -e 's:.* on ::;s: type .*::'`
    temp=`echo "$arg" | sed -e "s!^$unix_mount_path!$win_mount_path!"`
    if test "$temp" != "$arg"
    then
      candidate="$temp"
      length=${#unix_mount_path}
      if test $length -gt $max_length
      then
        result=$candidate
        max_length=$length
      fi
    fi
  done
  if test -z "$result"
  then
    echo "$0: path \"$arg\" is not mounted"
    exit 1
  fi
  case $escapes in
    0)
     echo "$result" | sed -e 's:/:\\:g'
     ;;
    1)
     echo "$result" | sed -e 's:/:\\\\:g'
     ;;
    2)
     echo "$result" | sed -e 's:/:\\\\\\\\:g'
     ;;
    3)
     echo "$result" | sed -e 's:/:\\\\\\\\\\\\\\\\:g'
     ;;
  esac
  exit 0;
 )