commit bash-20070503 snapshot

This commit is contained in:
Chet Ramey
2011-12-07 09:07:29 -05:00
parent b709b946e4
commit 641d8f00ab
29 changed files with 1539 additions and 90 deletions
+35 -14
View File
@@ -106,7 +106,15 @@ int command_string_index = 0;
/* Non-zero means the stuff being printed is inside of a function def. */
static int inside_function_def;
/* Used to decide where to put the `|' if the command in the pipeline has
here documents associated with it. If non-zero, print_redirection
prints the `|' before the text of the here document and print_connection
suppresses the `|'. */
static int inside_pipeline;
static int skip_this_indent;
/* Flag indicating we printed a here-document. */
static int was_heredoc;
/* The depth of the group commands that we are currently printing. This
@@ -133,7 +141,7 @@ char *
make_command_string (command)
COMMAND *command;
{
command_string_index = was_heredoc = 0;
command_string_index = was_heredoc = inside_pipeline = 0;
make_command_string_internal (command);
return (the_printed_command);
}
@@ -215,7 +223,11 @@ make_command_string_internal (command)
case cm_connection:
skip_this_indent++;
if (command->value.Connection->connector == '|')
inside_pipeline = 1;
make_command_string_internal (command->value.Connection->first);
if (command->value.Connection->connector == '|')
inside_pipeline = 0;
switch (command->value.Connection->connector)
{
@@ -223,7 +235,10 @@ make_command_string_internal (command)
case '|':
{
char c = command->value.Connection->connector;
cprintf (" %c", c);
if (c == '&' || was_heredoc == 0)
cprintf (" %c", c);
else
was_heredoc = 0;
if (c != '&' || command->value.Connection->second)
{
cprintf (" ");
@@ -851,6 +866,10 @@ print_redirection_list (redirects)
print the here documents. */
if (heredocs)
{
if (inside_pipeline)
{
itrace("print_redirection_list: here documents inside pipeline");
}
cprintf (" ");
for (hdtail = heredocs; hdtail; hdtail = hdtail->next)
{
@@ -868,6 +887,7 @@ print_redirection (redirect)
{
int kill_leading, redirector, redir_fd;
WORD_DESC *redirectee;
char *x;
kill_leading = 0;
redirectee = redirect->redirectee.filename;
@@ -905,17 +925,16 @@ print_redirection (redirect)
if (redirector != 0)
cprintf ("%d", redirector);
/* If the here document delimiter is quoted, single-quote it. */
if (redirect->redirectee.filename->flags & W_QUOTED)
{
char *x;
x = sh_single_quote (redirect->here_doc_eof);
cprintf ("<<%s%s\n", kill_leading? "-" : "", x);
free (x);
}
else
cprintf ("<<%s%s\n", kill_leading? "-" : "", redirect->here_doc_eof);
cprintf ("%s%s",
redirect->redirectee.filename->word, redirect->here_doc_eof);
x = (redirect->redirectee.filename->flags & W_QUOTED)
? sh_single_quote (redirect->here_doc_eof)
: redirect->here_doc_eof;
cprintf ("<<%s%s", kill_leading? "-" : "", x);
if (x != redirect->here_doc_eof)
free (x);
if (inside_pipeline)
cprintf (" |");
cprintf ("\n");
cprintf ("%s%s", redirect->redirectee.filename->word, redirect->here_doc_eof);
break;
case r_reading_string:
@@ -991,6 +1010,7 @@ reset_locals ()
{
inside_function_def = 0;
indentation = 0;
inside_pipeline = 0;
}
static void
@@ -1010,7 +1030,7 @@ print_function_def (func)
inside_function_def++;
indentation += indentation_amount;
cmdcopy = copy_command (func->command);
cmdcopy = copy_command (func->command); /* possible mem leak on unwind-protect */
if (cmdcopy->type == cm_group)
{
func_redirects = cmdcopy->redirects;
@@ -1055,6 +1075,7 @@ named_function_string (name, command, multi_line)
old_indent = indentation;
old_amount = indentation_amount;
command_string_index = was_heredoc = 0;
inside_pipeline = 0;
if (name && *name)
cprintf ("%s ", name);