]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
more small fixes to command printing code; simplify readline username completion...
authorChet Ramey <chet.ramey@case.edu>
Mon, 3 Jul 2023 14:29:28 +0000 (10:29 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 3 Jul 2023 14:29:28 +0000 (10:29 -0400)
CWRU/CWRU.chlog
lib/readline/complete.c
print_cmd.c
tests/type.right

index b149c6199d26fbea41a3275a8108751e4ce4099f..2c2c7669199babe9f1ad9879ac984e5b09683db6 100644 (file)
@@ -7004,3 +7004,24 @@ configure.ac
        - if --enable-static-link is supplied, add -static to LDFLAGS on
          Linux if opt_profiling isn't enabled
          From a report from Emanuele Torre <torreemanuele6@gmail.com>
+
+print_cmd.c
+       - make_command_string_internal: if we're recursively printing a list
+         (connection) with more than two elements, don't print any deferred
+         here-documents after the make_command_string_internal on the right
+         side of the connection unless we're at the end of the list
+         (printing_connection == 1). This way the caller gets to add the
+         appropriate connector before printing the deferred here-documents.
+         From a report by Grisha Levit <grishalevit@gmail.com>
+       - make_command_string_internal,print_group_command: after we call
+         PRINT_DEFERRED_HEREDOCS and follow it with a closing `)' (subshell)
+         or `}' (group command), we can set was_heredoc to 0 because we are
+         no longer printing a here-document
+         From a report by Grisha Levit <grishalevit@gmail.com>
+
+                                   7/3
+                                   ---
+lib/readline/complete.c
+       - rl_username_completion_function: simplify things by just skipping the
+         function body if HAVE_GETPWENT is not defined.
+         From a report by Grisha Levit <grishalevit@gmail.com>
index 349c87a1f0e19d3dbb6d39f0e211e87ee22c1523..d531f54100869b2fe9f9119db2992b3d430a7acd 100644 (file)
@@ -2321,9 +2321,9 @@ rl_completion_matches (const char *text, rl_compentry_func_t *entry_function)
 char *
 rl_username_completion_function (const char *text, int state)
 {
-#if defined (_WIN32) || defined (__OPENNT)
+#if defined (_WIN32) || defined (__OPENNT) || !defined (HAVE_GETPWENT)
   return (char *)NULL;
-#else /* !_WIN32 && !__OPENNT) */
+#else /* !_WIN32 && !__OPENNT) && HAVE_GETPWENT */
   static char *username = (char *)NULL;
   static struct passwd *entry;
   static int namelen, first_char, first_char_loc;
@@ -2338,25 +2338,19 @@ rl_username_completion_function (const char *text, int state)
 
       username = savestring (&text[first_char_loc]);
       namelen = strlen (username);
-#if defined (HAVE_GETPWENT)
       setpwent ();
-#endif
     }
 
-#if defined (HAVE_GETPWENT)
   while (entry = getpwent ())
     {
       /* Null usernames should result in all users as possible completions. */
       if (namelen == 0 || (STREQN (username, entry->pw_name, namelen)))
        break;
     }
-#endif
 
   if (entry == 0)
     {
-#if defined (HAVE_GETPWENT)
       endpwent ();
-#endif
       return ((char *)NULL);
     }
   else
@@ -2372,7 +2366,7 @@ rl_username_completion_function (const char *text, int state)
 
       return (value);
     }
-#endif /* !_WIN32 && !__OPENNT */
+#endif /* !_WIN32 && !__OPENNT && HAVE_GETPWENT */
 }
 
 /* Return non-zero if CONVFN matches FILENAME up to the length of FILENAME
index d7c5bbf9cbf00c636044d58164ca2a9a11029041..30e354d3ea111d3259d88eb7116868b13a1159a0 100644 (file)
@@ -327,7 +327,13 @@ make_command_string_internal (COMMAND *command)
            }
 
          make_command_string_internal (command->value.Connection->second);
-         PRINT_DEFERRED_HEREDOCS ("");
+         /* If this is a recursive call to make_command_string_internal to
+            print a connection with more than two components, defer printing
+            the here-document bodies until our caller can print the
+            connector. Remember that the parser builds lists to be left-side
+            heavy. */
+         if (printing_connection == 1)
+           PRINT_DEFERRED_HEREDOCS ("");
          printing_connection--;                  
          break;
 
@@ -345,6 +351,7 @@ make_command_string_internal (COMMAND *command)
          make_command_string_internal (command->value.Subshell->command);
          PRINT_DEFERRED_HEREDOCS ("");
          cprintf (" )");
+         was_heredoc = 0;      /* last wasn't heredoc/newline */
          break;
 
        case cm_coproc:
@@ -698,6 +705,7 @@ print_group_command (GROUP_COM *group_command)
     }
 
   cprintf ("}");
+  was_heredoc = 0;     /* last wasn't heredoc/newline */
 
   group_command_nesting--;
 }
@@ -1029,7 +1037,7 @@ print_redirection_list (REDIRECT *redirects)
   was_heredoc = 0;
   while (redirects)
     {
-      /* Defer printing the here document bodiess until we've printed the rest of the
+      /* Defer printing the here document bodies until we've printed the rest of the
          redirections, but print the headers in the order they're given.  */
       if (redirects->instruction == r_reading_until || redirects->instruction == r_deblank_reading_until)
        {
index bbc228e850dfa08a367f3beeecf741168867eb07..6cfa14edcebbe619b7d8f671cd8867ea81536bcb 100644 (file)
@@ -103,7 +103,7 @@ bb ()
 foo
 bar
 EOF
- )
+ );
     echo after subshell
 }
 mkcoprocs is a function
@@ -114,13 +114,13 @@ mkcoprocs ()
 producer 1
 EOF1
 
-    }
+    };
     coproc b { 
         cat <<EOF2
 producer 2
 EOF2
 
-    }
+    };
     echo "coprocs created"
 }
 mkcoprocs is a function
@@ -130,6 +130,6 @@ mkcoprocs ()
 heredoc
 body
 EOF
- )
+ );
     echo "coprocs created"
 }