Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Mon, 30 Jun 2003 23:53:45 -0400 To: cygwin AT cygwin DOT com Subject: Re: example needed pls: `cygpath -c ' Message-ID: <20030701035345.GC7604@ny-kenton2a-710.buf.adelphia.net> Mail-Followup-To: cygwin AT cygwin DOT com References: <3EFDDF97 DOT 29F49125 AT dessent DOT net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.28i From: somian AT adelphia DOT net (Soren Andersen) Hi! 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: "/" where 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 ---------------------------------------- #!/usr/bin/perl # "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". exec $ARGV[0], map { if(s/^\^//) { $_; } elsif(/^\-/) { $_; } else { $_ = quotemeta($_); chomp($_ = `cygpath -wsa $_ 2>/dev/null`); $_; } } @ARGV[1 .. $#ARGV] ; __END__ -------------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 http://savannah.gnu.org/people/viewgpg.php?user_id=6050 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: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/