bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: isabella parakiss
Date: Wed, 22 Jun 2016 23:00:16 +0200

From 6732f0277455ff8d8c6a09261490377890dc986d Mon Sep 17 00:00:00 2001
From: izabera <izaberina@gmail.com>
Date: Wed, 22 Jun 2016 22:43:53 +0200
Subject: [PATCH] fix a couple of bugs in print_cmd.c

1. print all heredoc headers before printing their contents
2. don't print all the heredocs after any other redir

sample code:
f(){ : <<x <<<xyz <file1 <<-y >&- <file2
foo
x
bar
y
}
declare -f f

old output:
f ()
{
    :  <<< xyz < file1  1>&- < file2 <<x
foo
x
<<-y
bar
y

}

new output:
f ()
{
    : <<x <<< xyz < file1 <<-y 1>&- < file2
foo
x
bar
y

}
---
 print_cmd.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/print_cmd.c b/print_cmd.c
index 617501e..0ba972c 100644
--- a/print_cmd.c
+++ b/print_cmd.c
@@ -1024,21 +1024,7 @@ print_redirection_list (redirects)
   was_heredoc = 0;
   while (redirects)
     {
-      /* Defer printing the here documents until we've printed the
-        rest of the redirections. */
-      if (redirects->instruction == r_reading_until || redirects->instruction 
== r_deblank_reading_until)
-       {
-         newredir = copy_redirect (redirects);
-         newredir->next = (REDIRECT *)NULL;
-         if (heredocs)
-           {
-             hdtail->next = newredir;
-             hdtail = newredir;
-           }
-         else
-           hdtail = heredocs = newredir;
-       }
-      else if (redirects->instruction == r_duplicating_output_word && 
(redirects->flags & REDIR_VARASSIGN) == 0 && redirects->redirector.dest == 1)
+      if (redirects->instruction == r_duplicating_output_word && 
(redirects->flags & REDIR_VARASSIGN) == 0 && redirects->redirector.dest == 1)
        {
          /* Temporarily translate it as the execution code does. */
          rw = redirects->redirectee.filename->word;
@@ -1048,7 +1034,25 @@ print_redirection_list (redirects)
          redirects->instruction = r_duplicating_output_word;
        }
       else
-       print_redirection (redirects);
+       {
+       /* Defer printing the here documents' bodies until we've printed the
+          rest of the redirections. */
+         if (redirects->instruction == r_reading_until || 
redirects->instruction == r_deblank_reading_until)
+           {
+             newredir = copy_redirect (redirects);
+             print_heredoc_header (newredir);
+             newredir->next = (REDIRECT *)NULL;
+             if (heredocs)
+               {
+                 hdtail->next = newredir;
+                 hdtail = newredir;
+               }
+             else
+               hdtail = heredocs = newredir;
+           }
+         else
+           print_redirection (redirects);
+       }
 
       redirects = redirects->next;
       if (redirects)
@@ -1061,7 +1065,12 @@ print_redirection_list (redirects)
     deferred_heredocs = heredocs;
   else if (heredocs)
     {
-      print_heredocs (heredocs);
+      cprintf("\n");
+      for (; heredocs; heredocs = heredocs->next)
+       {
+         print_heredoc_body (heredocs);
+         cprintf ("\n");
+       }
       dispose_redirects (heredocs);
     }
 }
-- 
2.9.0


---
xoxo iza



reply via email to

[Prev in Thread] Current Thread [Next in Thread]