hush: first pass at heredocs
Denys Vlasenko
vda.linux at googlemail.com
Mon Mar 30 16:26:04 UTC 2009
2009/3/30 Mike Frysinger <vapier at 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
More information about the busybox
mailing list