edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Adam Thompson <arthompson1990@gmail.com>
To: Karl Dahlke <eklhad@comcast.net>
Cc: Edbrowse-dev@lists.the-brannons.com
Subject: Re: [Edbrowse-dev] wordexp again
Date: Sat, 18 Apr 2015 11:49:19 +0100	[thread overview]
Message-ID: <20150418104919.GI5949@toaster.adamthompson.me.uk> (raw)
In-Reply-To: <20150318001800.eklhad@comcast.net>

[-- Attachment #1: Type: text/plain, Size: 4031 bytes --]

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.
> 
> #include <stdio.h>
> #include <wordexp.h>
> 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.

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 possibly
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 ` character
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 code
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 understanding
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.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2015-04-18 10:50 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-16 21:40 Karl Dahlke
2015-04-17  7:12 ` Adam Thompson
2015-04-17 12:50   ` Adam Thompson
2015-04-17 13:33     ` Karl Dahlke
2015-04-17 17:59       ` Adam Thompson
2015-04-17 13:47     ` Karl Dahlke
2015-04-17 18:01     ` Karl Dahlke
2015-04-17 21:34       ` Adam Thompson
2015-04-17 21:58         ` Adam Thompson
2015-04-17 22:25           ` Karl Dahlke
2015-04-17 22:43             ` Adam Thompson
2015-04-17 23:14               ` Karl Dahlke
2015-04-17 22:28           ` Adam Thompson
2015-04-17 22:39             ` Karl Dahlke
2015-04-18 10:53               ` Adam Thompson
2015-04-18  4:18     ` Karl Dahlke
2015-04-18 10:49       ` Adam Thompson [this message]
2015-04-18 11:34         ` Karl Dahlke
2015-04-18 13:09           ` Adam Thompson
2015-04-18 19:33             ` Chris Brannon
2015-04-18 20:05               ` Adam Thompson
2015-04-18 23:03                 ` Chris Brannon
2015-04-18 12:36         ` Karl Dahlke
2015-04-18 12:54           ` Adam Thompson
2015-04-18 13:09             ` Karl Dahlke
2015-04-18 13:24               ` Adam Thompson
2015-04-18 13:45                 ` Karl Dahlke
2015-04-18 17:44                   ` Adam Thompson
2015-04-18 19:48                     ` Karl Dahlke
  -- strict thread matches above, loose matches on Subject: below --
2015-01-09 22:44 Karl Dahlke
2015-01-09 22:19 Karl Dahlke
2015-01-09 22:29 ` Chris Brannon
2015-01-09 21:16 Chris Brannon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150418104919.GI5949@toaster.adamthompson.me.uk \
    --to=arthompson1990@gmail.com \
    --cc=Edbrowse-dev@lists.the-brannons.com \
    --cc=eklhad@comcast.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).