Mail Archives: cygwin/1996/12/10/13:20:38
Since a few people showed interest, I am posting 'path2win', a perl script
that converts Gnu-Win32 pathnames into ordinary Win32 pathnames. I won't
post any other scripts unless people are interested. Typical usage is:
win32prog `path2win /gnu/path //d/another/gnu/path`
which results in (assuming / corresponds to c: and //d to d:)
win32prog c:\gnu\path d:\another\gnu\path
If a program can handle (and prefers) c:/foo/bar type paths, specify
'path2win -u' for this format.
The main benefit is that you can keep all of your variables in Gnu-Win32
format and use variable/filename completion in bash right up to the point
that you invoke the Win32 program. The problem is that perl can be a bit
slow, but it would be very easy to rewrite this in sed.
The preamble will work on any Perl script to let you invoke Perl/Win32
scripts from the bash command line. The #! line is ignored since
bash/Gnu-Win32 does not support it, though Perl will pick up any switches.
Richard
--
richardd AT cix DOT compulink DOT co DOT uk http://www.inside-edge.co.uk/
Inside Edge Consultancy Client/Server and Internet Applications
PGP key from: pgp-public-keys AT keys DOT pgp DOT net -or- http://www.four11.com/
#!/usr/bin/perl -w
# -------------- Preamble to simulate '#!'
# Shell mode: Eval is needed to run Perl under Gnu-Win32 (which
# does not support #!). Perl will pick up any switches from
# the '#!' line.
eval 'exec perl -S $0 ${1+"$@"}'
if 0;
# Perl mode: Get rid of any -S switch - script cannot use -S as
# one of its own switches
shift if ($#ARGV >= 0 and $ARGV[0] eq '-S');
# -------------- Main program
# path2win: convert Gnu-Win32 pathnames to Win32 pathnames,
# with drive letters and backslashes. To retain /'s for
# Unix-oriented Win32 tools such as Vim for Win32, use the '-u' option.
#
# Usage: path2win [-u] path ...
#
# Version 1.0, 10th Dec 1996 richardd AT cix DOT compulink DOT co DOT uk
#
# If you update this script, please email me your version!
#
# Assumes that /[a-z]/ or //[a-z]/ maps onto a drive letter
#
# Tested on Perl 5.001m build 110 for Win32 under Gnu-Win32 B17 on Win95,
# but should work on other platforms. Note that Gnu-Win32 B16's pathname
# support is different to B17.
# *** You will need to edit this line if C: is not mounted as '/'
$rootdrive = "c:";
# Work properly with Gnu-Win32 and back quotes
binmode STDOUT;
if ($ARGV[0] eq "-u") {
$unixmode = 1; shift;
}
foreach $gnupath (@ARGV) {
$_ = $gnupath;
# Convert //D to d:
s# ^//([a-z])$ #\L$1:/#xi ;
# Convert //D/ to d:
s# ^//([a-z])/ #\L$1:/#xi ;
# Convert /D to d:
s# ^/([a-z])$ #\L$1:/#xi ;
# Convert /D/ to d:
s# ^/([a-z])/ #\L$1:/#xi ;
# Convert d: alone to d:/
s# ^([a-z]:)$ #\L$1/#xi ;
# Convert / to c:/
s# ^/ #${rootdrive}/#x ;
# Convert /'s to \'s unless in Unix mode
s# / #\\#gx unless $unixmode;
print; print "\n";
}
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -