From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from resqmta-ch2-10v.sys.comcast.net (resqmta-ch2-10v.sys.comcast.net [IPv6:2001:558:fe21:29:69:252:207:42]) by hurricane.the-brannons.com (Postfix) with ESMTPS id A22B97AF0A for ; Fri, 17 Apr 2015 21:19:05 -0700 (PDT) Received: from resomta-ch2-07v.sys.comcast.net ([69.252.207.103]) by resqmta-ch2-10v.sys.comcast.net with comcast id HGJ11q0012EPM3101GJ1k0; Sat, 18 Apr 2015 04:18:01 +0000 Received: from eklhad ([IPv6:2601:4:5380:4ee:21e:4fff:fec2:a0f1]) by resomta-ch2-07v.sys.comcast.net with comcast id HGJ01q00B5LMg2101GJ0dk; Sat, 18 Apr 2015 04:18:00 +0000 To: Edbrowse-dev@lists.the-brannons.com From: Karl Dahlke Reply-to: Karl Dahlke References: <20150316174053.eklhad@comcast.net> <20150417125002.GA14517@toaster.adamthompson.me.uk> User-Agent: edbrowse/3.5.3+ Date: Sat, 18 Apr 2015 00:18:00 -0400 Message-ID: <20150318001800.eklhad@comcast.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1429330681; bh=5whFdzo0doNwsLCN3BvZBI9OWYpoNP32pNVt/yjNzf8=; h=Received:Received:To:From:Reply-to:Subject:Date:Message-ID: Mime-Version:Content-Type; b=eXTbWDCXTWSClFGlhakJU/7T9iSZkIvvZLqcDuEDYgsL/Pe7tTOCnvoYEUDOXsK9I eeVxsv4K6kbkWGHQ3SMrQ6MKbby+UWpK0njsx/UlsgKoPP3guanCuptXrd1XuBV+k7 8WlQAPpDleoxGd2UP/T4vKj0Psjie775HLZ+axBBZoYP2rR5gi3GaXCCYPJQUNqq/p +7MMKIiAaz790keyG0O1X/dUX8b6eji9SLTBVrHraHHkkrjzoNIyBTWSVjlNfaOKdK o49Pf6KsgVNbOjwMwOr21xZ9E0Al/XyE8f3VarcNx7N2KX9wj2eGo7IzP6YcLfMudC 1SB8VX2vfZqqw== Subject: [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 04:19:05 -0000 Well a very smart person told me to write a 10 line C program. Here it is. #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); } } Create the two files abc and ab\d Run the program and type in various strings. Here is input and output. 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 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. 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 function that does the following: 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. 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. That's what I will sleep on tonight, and see how I feel about it in the morning. Karl Dahlke