summaryrefslogtreecommitdiff
path: root/build-aux/msys-to-w32
blob: 8b1c970b99666fdce648b0f1a9b7b0eaa02d37d5 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# Convert a MSYS path list to Windows-native format.
# Status is zero if successful, nonzero otherwise.

# Copyright (C) 2013-2016 Free Software Foundation, Inc.

# 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
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

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

usage="usage: ${me} PATHLIST"

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

Convert a MSYS path list to Windows-native format.

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

1. Discard empty paths.
2. Replace: '\' with '/', '//' with '/' and ':' with ';'.
3. Translate absolute paths to Windows-native format.

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

[ $# -eq 1 ] || {
    echo "${me}: $usage" >&2
    exit 1
}

w32pathlist=""

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

for p
do
    [ -z "$p" ] && continue

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

	p=${p//\\//}
	p=${p//\/\///}
	p=${p%/}

	p1=$p
	while :
	do
	    p1=${p1%/*}
	    [ -z "$p1" ] && p1="/" && break
	    [ -d "$p1" ] && break
	done

	# translate the existing part and append the rest
	w32p=$(cd "${p1}" && pwd -W)
	remainder=${p#$p1}
	w32p=${w32p%/}/${remainder#/}
    fi

    w32pathlist="${w32pathlist};${w32p}"

done

echo "${w32pathlist:1}"