This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: example needed pls: `cygpath -c <HANDLE>'

  Regarding reply by Brian Dessent <> wrote around 28 Jun 2003
> > Here's a little thing I cooked up that I find very useful, I call it
> > dodos.  It lets you run any DOS/Windows program and call it with unix
> > arguments.  For example, you could type "dodos notepad /etc/aliases"
> > or "dodos notepad /etc/hosts.*" and you'd get what you expect.

> > #!/usr/bin/perl -w
> > 
> > my @newargs = $ARGV[0];
> > 
> > foreach my $arg (@ARGV[1..$#ARGV]) {
> >         my $foo = quotemeta($arg);
> >         $foo = `cygpath -wsa $foo 2>/dev/null`;
> >         chomp $foo;
> >         push @newargs, $foo;
> > }
> > 
> > exec @newargs;

(I replied:)
> Heh. Looks like a candidate for a Schwartzian Transform, or the Orcish 
> Manuever, or something :-/. But good anyway. I'll add it to my toolset.

Well, brain misfire apparently happened; the ST and Orcish maneuver both
pertain to *sorts*, and there's no sorting going on here. What I was
thinking was that there ought to be a use for Perl's map() here, and
there is (of COURSE, because it's Perl so TMTOWTDI!). Nevertheless
although I can come up with a more highly obfuscated and terse way to do
this, it doesn't reduce down very much due to the external system call
to `cygpath'.

Soooo, risking that I'll just publicly expose *another* brain misfire,
I'll venture to offer some thinking I did about this. No warrenties
whatsoever, yaddayaddayadda.

Since my earlier reply I've done some serious playing around with this
code and discovered it suffers from severe limitations. On WindowsXP I
found almost no basic Windows tools that take just a list of filenames
characteristically, as args; most native tools take just one arg and a
bunch of flags, which usually look like: "/<X>" where <X> is one or more
characters. I don't think your code is going to handle that too well!

In short although I see what you are doing, I think it's too simple for
many cases and its lack of robustness makes it only marginally useful to
me (IMHO). If you could post some typical examples of how you use it, to
refute me, I'd be pleased.

One variation of your code I came up with looks like this, and
demonstrates the initial ~ 50% reduction in numbers of lines, but
handles a little more (and so num lines swelled back up):

-------------8<  snip here ----------------------------------------

    # "dofn4dos" - translate arguments to run a WinDOS application
    # from the Cygwin shell. Use "^" as a special (disposed-of)
    # escape char mechanism for flags like "/YO".
     map { if(s/^\^//)  {
	   } elsif(/^\-/)   {
	   }  else     {
	      $_ = quotemeta($_);
	      chomp($_ = `cygpath -wsa $_ 2>/dev/null`);
	 @ARGV[1 .. $#ARGV]


-------------8<  snip here ----------------------------------------

That's both pretty terse (perl-ish) and yet I think most people can see
what's going on; and also it handles a couple of common idioms for
passing flags in a command line: the "initial-hyphen" idiom typical of
*nix/POSIX tools, and the worrisome Win32/DOS idiom "/" (regular/forward
initial slash, which looks like a fqfn under *nix). Of course you have
to remember to put an "eatable caret" (GET IT!!??!!) in front of such a
flag arg to "protect" it from cygpath. When Perl is done the caret is
gone and `cygpath' has kept its paws off your flag.

See my OpenPGP key at
GnuPG public key fingerprint  | "Only when efforts to reform society have as
 BD26 A5D8 D781 C96B 9936     |  their point of departure the reformation of
 310F 0573 A3D9 4E24 4EA6     |  the inner life -- human revolution -- will
they lead us with certainty to a world of lasting peace and true human security."
                                -- Daisaku Ikeda

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]