tbell@487: #!/bin/perl tbell@487: tbell@487: # tbell@487: # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. tbell@487: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tbell@487: # tbell@487: # This code is free software; you can redistribute it and/or modify it tbell@487: # under the terms of the GNU General Public License version 2 only, as tbell@487: # published by the Free Software Foundation. Oracle designates this tbell@487: # particular file as subject to the "Classpath" exception as provided tbell@487: # by Oracle in the LICENSE file that accompanied this code. tbell@487: # tbell@487: # This code is distributed in the hope that it will be useful, but WITHOUT tbell@487: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tbell@487: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tbell@487: # version 2 for more details (a copy is included in the LICENSE file that tbell@487: # accompanied this code). tbell@487: # tbell@487: # You should have received a copy of the GNU General Public License version tbell@487: # 2 along with this work; if not, write to the Free Software Foundation, tbell@487: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tbell@487: # tbell@487: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA tbell@487: # or visit www.oracle.com if you need additional information or have any tbell@487: # questions. tbell@487: # tbell@487: tbell@487: # Crunch down the input(s) to Windows short (mangled) form. tbell@487: # Any elements not actually found in the filesystem will be dropped. tbell@487: # tbell@487: # This script needs three modes: tbell@487: # 1) DOS mode with drive letter followed by : and ; path separator tbell@487: # 2) Cygwin mode with /cygdrive// and : path separator tbell@487: # 3) MinGW/MSYS mode with // and : path separator tbell@487: tbell@487: use strict; tbell@487: use warnings; tbell@487: use Getopt::Std; tbell@487: tbell@487: sub Usage() { tbell@487: print ("Usage:\n $0 -d | -c | -m \\n"); tbell@487: print (" -d DOS style (drive letter, :, and ; path separator)\n"); tbell@487: print (" -c Cywgin style (/cygdrive/drive/ and : path separator)\n"); tbell@487: print (" -m MinGW style (/drive/ and : path separator)\n"); tbell@487: exit 1; tbell@487: } tbell@487: # Process command line options: tbell@487: my %opts; tbell@487: getopts('dcm', \%opts) || Usage(); tbell@487: tbell@487: if (scalar(@ARGV) != 1) {Usage()}; tbell@487: tbell@487: # Translate drive letters such as C:/ tbell@487: # if MSDOS, Win32::GetShortPathName() does the work (see below). tbell@487: # if Cygwin, use the /cygdrive/c/ form. tbell@487: # if MinGW, use the /c/ form. tbell@487: my $path0; tbell@487: my $sep2; tbell@487: if (defined ($opts{'d'})) { tbell@487: #MSDOS tbell@487: $path0 = ''; tbell@487: $sep2 = ';'; tbell@487: } elsif (defined ($opts{'c'})) { tbell@487: #Cygwin tbell@487: $path0 = '/cygdrive'; tbell@487: $sep2 = ':'; tbell@487: } elsif (defined ($opts{'m'})) { tbell@487: #MinGW/MSYS tbell@487: $path0 = ''; tbell@487: $sep2 = ':'; tbell@487: } else { tbell@487: Usage(); tbell@487: } tbell@487: tbell@487: my $input = $ARGV[0]; tbell@487: my $sep1; tbell@487: tbell@487: # Is the input ';' separated, or ':' separated, or a simple string? tbell@487: if (($input =~ tr/;/;/) > 0) { tbell@487: # One or more ';' implies Windows style path. tbell@487: $sep1 = ';'; tbell@487: } elsif (($input =~ tr/:/:/) > 1) { tbell@487: # Two or more ':' implies Cygwin or MinGW/MSYS style path. tbell@487: $sep1 = ':'; tbell@487: } else { tbell@487: # Otherwise, this is not a path - take up to the end of string in tbell@487: # one piece. tbell@487: $sep1 = '/$/'; tbell@487: } tbell@487: tbell@487: # Split the input on $sep1 PATH separator and process the pieces. tbell@487: my @pieces; tbell@487: for (split($sep1, $input)) { tbell@487: my $try = $_; tbell@487: tbell@487: if (($try =~ /^\/cygdrive\/(.)\/(.*)$/) || ($try =~ /^\/(.)\/(.*)$/)) { tbell@487: # Special case #1: This is a Cygwin /cygrive/ 1)) { tbell@487: $result = join ($sep2, @pieces); tbell@487: } else { tbell@487: $result = $pieces[0]; tbell@487: } tbell@487: tbell@487: if (defined ($result)) { tbell@487: tbell@487: # Change all '\' to '/' tbell@487: $result =~ s/\\/\//g; tbell@487: tbell@487: # Remove duplicate '/' tbell@487: $result =~ s/\/\//\//g; tbell@487: tbell@487: # Map to lower case tbell@487: $result =~ tr/A-Z/a-z/; tbell@487: tbell@487: print ("$result\n"); tbell@487: }