summaryrefslogtreecommitdiff
path: root/print_cmd.c
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2011-12-12 21:56:08 -0500
committerChet Ramey <chet.ramey@case.edu>2011-12-12 21:56:08 -0500
commit1b13a2904ae75ef7bf1c7550c99d41a11a070321 (patch)
treea81c92a2db29cca7001089e2a32e81e4866c391e /print_cmd.c
parent640b1cb0f76cb97b080f810360937dd6d5a81485 (diff)
downloadbash-1b13a2904ae75ef7bf1c7550c99d41a11a070321.tar.gz
commit bash-20100318 snapshot
Diffstat (limited to 'print_cmd.c')
-rw-r--r--print_cmd.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/print_cmd.c b/print_cmd.c
index 5a5ff6d7..53d5adb1 100644
--- a/print_cmd.c
+++ b/print_cmd.c
@@ -113,6 +113,12 @@ FILE *xtrace_fp = 0;
#define CHECK_XTRACE_FP xtrace_fp = (xtrace_fp ? xtrace_fp : stderr)
+#define PRINT_DEFERRED_HEREDOCS(x) \
+ do { \
+ if (deferred_heredocs) \
+ print_deferred_heredocs (x); \
+ } while (0)
+
/* Non-zero means the stuff being printed is inside of a function def. */
static int inside_function_def;
static int skip_this_indent;
@@ -293,8 +299,7 @@ make_command_string_internal (command)
}
make_command_string_internal (command->value.Connection->second);
- if (deferred_heredocs)
- print_deferred_heredocs ("");
+ PRINT_DEFERRED_HEREDOCS ("");
printing_connection--;
break;
@@ -560,13 +565,15 @@ print_for_command (for_command)
FOR_COM *for_command;
{
print_for_command_head (for_command);
-
cprintf (";");
newline ("do\n");
+
indentation += indentation_amount;
make_command_string_internal (for_command->action);
+ PRINT_DEFERRED_HEREDOCS ("");
semicolon ();
indentation -= indentation_amount;
+
newline ("done");
}
@@ -620,6 +627,7 @@ print_select_command (select_command)
newline ("do\n");
indentation += indentation_amount;
make_command_string_internal (select_command->action);
+ PRINT_DEFERRED_HEREDOCS ("");
semicolon ();
indentation -= indentation_amount;
newline ("done");
@@ -703,6 +711,7 @@ print_case_clauses (clauses)
indentation += indentation_amount;
make_command_string_internal (clauses->action);
indentation -= indentation_amount;
+ PRINT_DEFERRED_HEREDOCS ("");
if (clauses->flags & CASEPAT_FALLTHROUGH)
newline (";&");
else if (clauses->flags & CASEPAT_TESTNEXT)
@@ -736,10 +745,12 @@ print_until_or_while (while_command, which)
cprintf ("%s ", which);
skip_this_indent++;
make_command_string_internal (while_command->test);
+ PRINT_DEFERRED_HEREDOCS ("");
semicolon ();
cprintf (" do\n"); /* was newline ("do\n"); */
indentation += indentation_amount;
make_command_string_internal (while_command->action);
+ PRINT_DEFERRED_HEREDOCS ("");
indentation -= indentation_amount;
semicolon ();
newline ("done");
@@ -756,6 +767,7 @@ print_if_command (if_command)
cprintf (" then\n");
indentation += indentation_amount;
make_command_string_internal (if_command->true_case);
+ PRINT_DEFERRED_HEREDOCS ("");
indentation -= indentation_amount;
if (if_command->false_case)
@@ -764,6 +776,7 @@ print_if_command (if_command)
newline ("else\n");
indentation += indentation_amount;
make_command_string_internal (if_command->false_case);
+ PRINT_DEFERRED_HEREDOCS ("");
indentation -= indentation_amount;
}
semicolon ();
@@ -943,7 +956,7 @@ print_deferred_heredocs (cstring)
cprintf (" ");
print_heredoc_header (hdtail);
}
- if (cstring[0] != ';' || cstring[1])
+ if (cstring[0] && (cstring[0] != ';' || cstring[1]))
cprintf ("%s", cstring);
if (deferred_heredocs)
cprintf ("\n");