msys-to-w32 2.29 KB
Newer Older
1
#!/bin/bash
Dani Moncayo's avatar
Dani Moncayo committed
2
# Convert a MSYS path list to Windows-native format.
3 4
# Status is zero if successful, nonzero otherwise.

Paul Eggert's avatar
Paul Eggert committed
5
# Copyright (C) 2013-2020 Free Software Foundation, Inc.
6 7 8 9 10 11 12 13 14 15 16 17

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
18
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 20 21 22

# Take only the basename from the full pathname
me=${0//*\//}

23
usage="usage: ${me} PATHLIST"
24 25 26 27

help="$usage
  or:  ${me} OPTION

Dani Moncayo's avatar
Dani Moncayo committed
28
Convert a MSYS path list to Windows-native format.
29 30 31

PATHLIST should be a colon-separated list of MSYS paths, which will be
written to the standard output after performing these transformations:
32 33

1. Discard empty paths.
34
2. Replace: '\' with '/', '//' with '/' and ':' with ';'.
35
3. Translate absolute paths to Windows-native format.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

Options:
  --help     display this help and exit

Report bugs to <bug-gnu-emacs@gnu.org>."

for arg
do
  case $arg in
    --help | --hel | --he | --h)
      exec echo "$help" ;;
    --)
      shift
      break ;;
    -*)
      echo "${me}: invalid option: $arg" >&2
      exit 1 ;;
    *)
      break ;;
  esac
done

58 59 60 61
[ $# -eq 1 ] || {
    echo "${me}: $usage" >&2
    exit 1
}
62 63 64

w32pathlist=""

65 66 67 68
# Put each MSYS path in one positional parameter and iterate through
# them
IFS=:
set -- $1
69

70 71 72
for p
do
    [ -z "$p" ] && continue
73

74
    if [ "${p:0:1}" != "/" ]
75 76
    then
	w32p=$p
77
    elif [ -d "$p" ]
78
    then
79
	w32p=$(cd "$p" && pwd -W)
80
    else
81 82
	# Make some cleanup in the path and look for its deepest
	# existing directory
83

84 85 86
	p=${p//\\//}
	p=${p//\/\///}
	p=${p%/}
87

Dani Moncayo's avatar
Dani Moncayo committed
88
	p1=$p
89
	while :
90
	do
Dani Moncayo's avatar
Dani Moncayo committed
91 92 93
	    p1=${p1%/*}
	    [ -z "$p1" ] && p1="/" && break
	    [ -d "$p1" ] && break
94 95
	done

96
	# translate the existing part and append the rest
Dani Moncayo's avatar
Dani Moncayo committed
97 98
	w32p=$(cd "${p1}" && pwd -W)
	remainder=${p#$p1}
99
	w32p=${w32p%/}/${remainder#/}
100 101
    fi

102
    w32pathlist="${w32pathlist};${w32p}"
103 104 105

done

106
echo "${w32pathlist:1}"