edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Karl Dahlke <eklhad@comcast.net>
To: Edbrowse-dev@lists.the-brannons.com
Subject: [Edbrowse-dev]     wordexp again
Date: Sat, 18 Apr 2015 00:18:00 -0400	[thread overview]
Message-ID: <20150318001800.eklhad@comcast.net> (raw)
In-Reply-To: <20150417125002.GA14517@toaster.adamthompson.me.uk>

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.

Karl Dahlke

  parent reply	other threads:[~2015-04-18  4:19 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 [this message]
2015-04-18 10:49       ` Adam Thompson
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=20150318001800.eklhad@comcast.net \
    --to=eklhad@comcast.net \
    --cc=Edbrowse-dev@lists.the-brannons.com \
    /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).