From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-x22a.google.com (mail-wg0-x22a.google.com [IPv6:2a00:1450:400c:c00::22a]) by hurricane.the-brannons.com (Postfix) with ESMTPS id 875A07AEF7 for ; Sat, 18 Apr 2015 03:50:28 -0700 (PDT) Received: by wgyo15 with SMTP id o15so135626521wgy.2 for ; Sat, 18 Apr 2015 03:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=OJSb0dBLEZI5KW76SECOuasjdvPF2jZcBwjeIJP/Yzk=; b=a6akWE5XLVcnkTgHttvKTUO4IN19ZG/XpvpZuCFbxoCGZKE77EwlX/2ViusMo//DrY qn9JZG2MHg+PpwSaqDu2iNd5qrppwj9nbtiQaYNuTqfW/QuHBpFLi3qmlc515SnQ+3kZ DW4qABuUBdgDgj27Sr6CvLG6JmGwKYpfEyDBUSPksbN/UevuFUc+z7zg8rJgh6vJu2Am HovnC6YhG4unQ5Dak+VCSPUG18i+RCh9q38WJEWvCsqsjzBfPzyWlqR7h4FyxMLJic7V sGc5RBvZv53HZECkw/s+EAI7NXQgcHd8ecc4eMgaWbM4HMTO6wtejUjadj/0iEuE+PCF DImQ== X-Received: by 10.181.13.198 with SMTP id fa6mr8835801wid.41.1429354162678; Sat, 18 Apr 2015 03:49:22 -0700 (PDT) Received: from toaster.adamthompson.me.uk (toaster.adamthompson.me.uk. [2001:8b0:1142:9042::2]) by mx.google.com with ESMTPSA id ub1sm18426333wjc.43.2015.04.18.03.49.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Apr 2015 03:49:21 -0700 (PDT) Date: Sat, 18 Apr 2015 11:49:19 +0100 From: Adam Thompson To: Karl Dahlke Message-ID: <20150418104919.GI5949@toaster.adamthompson.me.uk> References: <20150316174053.eklhad@comcast.net> <20150417125002.GA14517@toaster.adamthompson.me.uk> <20150318001800.eklhad@comcast.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0XMZdl/q8hSSmFeD" Content-Disposition: inline In-Reply-To: <20150318001800.eklhad@comcast.net> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: Edbrowse-dev@lists.the-brannons.com Subject: Re: [Edbrowse-dev] wordexp again X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Apr 2015 10:50:29 -0000 --0XMZdl/q8hSSmFeD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 18, 2015 at 12:18:00AM -0400, Karl Dahlke wrote: > Well a very smart person told me to write a 10 line C program. Here it is. >=20 > #include > #include > main(int argc, char **argv) > { > wordexp_t w; > char line[80]; > while(gets(line)) { > wordexp(line, &w, 0); > printf("%s\n", w.we_wordv[0]); > wordfree(&w); > } > } >=20 > Create the two files abc and ab\d > Run the program and type in various strings. > Here is input and output. >=20 > jkl jkl > \\ \ > \\\\ \\ > ab? abc > ab\\e ab\e > ab\\* ab\* (should be ab\d) > ab\\$HOME ab\/home/eklhad > $HOME\\ab /home/eklhad/\ab > \\'j' \j > ab\\\\* ab\d >=20 > So backslashes are crunched once, and \' becomes ', and \| becomes |, > and so on as $variables are replaced. > Then, the next pass, globbing, if globbing occurs, > or if you want it to occur, then \\ becomes \ once again. > However \' does not become ', only \\ is crunched. > This second crunching is the bug, and there is really no way around it. > That's why ab\\\\* expands the way ab\\* should. >=20 > If I have the energy, and I'm not sure if I do, > but if I do, I believe the right answer is to write my own wordexp functi= on > that does the following: >=20 > pass 1 > ignore ' " | () [] ; \ blah blah blah, > no nasty side effects of calling this function. > No confusion, and no reason not to run it all the time. > don't have to start with a ` to invoke it, just run it because > it doesn't do anything weird. > Replace $var with its environment value, > and maybe even ${var}. > Let's be honest, this software is easy, and entirely portable. >=20 > pass 2 > Call glob() to expand any shell wild cards. > This is the hard part, so let the library do that, > but glob doesn't screw up other characters in the string. >=20 > That's what I will sleep on tonight, > and see how I feel about it in the morning. I notice you miss out the ~whatever expansion here, which is a missing feature of this. As I said, I think the ` inverting probably fixes most of this, with the caveat about the cd command. I also think we shouldn't be using glob to scan a directory, we should be using scandir and alphasort, no need to append / or /* to strings in this case and no other oddness poss= ibly caused by odd directory names (I've got a suspician there's another escaping bug with this code somewhere). I'm also not entirely sure I'd mind having command substitution enabled, particularly as I use this a lot in file name expansions now. I definitely think we need to talk about this, particularly now we have a more or less fixed version of edbrowse. What the last couple of days have shown is that making undiscussed changes = is just going to get circular due to differing user requirements and opinions. In the environment inwhich I use Edbrowse, the more file name expansion features I can have enabled the better, however other people aren't as comfrtable in the shell. I'd quite like a sort of hybrid approach actually which keeps the ` charact= er for full wordexp (with command substitution as well) but may be some sort of glob (plus ~ expansion) without it. If you're specifying environment variables then your probably in the realm = of the shell, and then you may as well have all the power that implies. @Karl: I think one of the other issues here is that you've been using the c= ode the way you wrote it for years, whereas I'm coming to the env var expansion stuff fairly fresh and based on years of using the shell. That gives two different perspectives on what the "right" thing is in this case. As for the bug in wordexp, I need to read through the posix standard to se = how it handles escaping to see if this is a genuine bug or just us not understandi= ng how wordexp is supposed to work with quoting. At the end of the day, people claim wordexp's expansion is the same as the shell, but it's not the same function and thus the expansions are slightly = different. Cheers, Adam. --0XMZdl/q8hSSmFeD Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVMjavAAoJELZ22lNQBzHOxNwH/RjiPRi3d5ODdOblPsSs38z0 jgf0FCKz/0ouXOLXPMgkIQPbywOVKgU6lkQayLdkSWLcJguYkSYv4v3M72ABbCWi vWv8ZeMVacjBo7XUT7mD3l8GdJHt7sVxv/wMrLzRFsjHlU88tbjpxVF/h0fqrxOC dCdOctzgxLP9Sb2Ura/Ipo1eKMQTHEzIMBLOvX91vfg1Ic6dTsIzNwXOTzgJA1Xp mfFc45mFkYwvmJL61adGfVhhcTnkquzdjHlKdPzfHZ6IEKq+EOkyLSxy3B/iPwP7 TmnkK5cc9L7gbrr41Ke4kKlpgWLtvQDU1hAKc8R7y25znMQxcVAbRgTPtfa8uAg= =d3cZ -----END PGP SIGNATURE----- --0XMZdl/q8hSSmFeD--