more small fixes to command printing code; simplify readline username completion if getpwent is not available

This commit is contained in:
Chet Ramey
2023-07-03 10:29:28 -04:00
parent 6a9e77e881
commit 935fe11af0
4 changed files with 38 additions and 15 deletions
+21
View 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>
+3 -9
View 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
+10 -2
View 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)
{
+4 -4
View 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"
}