[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: hush: first pass at heredocs
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2009-03-30 16:26:04
Message-ID: 1158166a0903300926s554d3d0co87df4ec15f73a317 () mail ! gmail ! com
[Download RAW message or body]

2009/3/30 Mike Frysinger <vapier@gentoo.org>:
> i doubt you'll like it, but it seems to be fairly usable atm ...

+                               /* So now our here string contains the
contents ... reconstruct
+                                * things like so to be no-mmu friendly:
+                                *   $ cat <<word
+                                *   foo
+                                *   word
+                                * ... becomes ...
+                                *   printf "foo\n" | cat
+                                */
+                               done_command(ctx);
+                               o_addstr(dest, "printf", strlen("printf"));
+                               done_word(dest, ctx);
+                               o_reset(dest);
+                               done_word(here, ctx);
+                               o_reset(here);
+                               done_command(ctx);
+                               pi = ctx->pipe;
+                               cmd = pi->cmds[pi->num_cmds - 1];
+                               pi->cmds[pi->num_cmds - 1] =
pi->cmds[pi->num_cmds - 2];
+                               pi->cmds[pi->num_cmds - 2] = cmd;

:shock: :gulp:

This will make "cat" run in a subprocess. For "cat" it's ok,
for, say, "while ... do ... done" it wouldn't be.

Let's do it cleanly at once. At parsing time, just remember the whole
HERE document and store it in struct command::redirects
(which is a list of struct redir_struct's. You will need to add
a field there probably). Don't worry for now about
embedded NULs.

At execution stage, fork a child and let it supply the input.
On NOMMU, vfork and re-exec the child as "hush -Htext-is-here".
In the parent, redirect the read pipe end as stdin.
--
vda
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic