64 lines
2.2 KiB
Diff
64 lines
2.2 KiB
Diff
From: cgoesche <cgoesc2@wgu.edu>
|
|
Date: Sat, 5 Apr 2025 01:29:35 -0400
|
|
Subject: more: fix implicit previous shell_line execution #3508
|
|
|
|
run_shell() will implicitly execute the previous ctl->shell_line
|
|
not only if the function was indirectly invoked by the '.' command
|
|
but also by a subsequent '!' command.
|
|
|
|
Addresses: #3508
|
|
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
|
|
(cherry picked from commit b6f9362988dbe5427d52b31ac3add37a7ddb6b12)
|
|
---
|
|
text-utils/more.c | 14 +++++++++++---
|
|
1 file changed, 11 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/text-utils/more.c b/text-utils/more.c
|
|
index a035591..f80aeff 100644
|
|
--- a/text-utils/more.c
|
|
+++ b/text-utils/more.c
|
|
@@ -226,6 +226,7 @@ struct more_control {
|
|
print_banner, /* print file name banner */
|
|
reading_num, /* are we reading leading_number */
|
|
report_errors, /* is an error reported */
|
|
+ prev_command_called, /* previous more command is called */
|
|
search_at_start, /* search pattern defined at start up */
|
|
search_called, /* previous more command was a search */
|
|
squeeze_spaces, /* suppress white space */
|
|
@@ -1295,8 +1296,11 @@ static void run_shell(struct more_control *ctl, char *filename)
|
|
erase_to_col(ctl, 0);
|
|
putchar('!');
|
|
fflush(NULL);
|
|
- if (ctl->previous_command.key == more_kc_run_shell && ctl->shell_line)
|
|
+ if (ctl->previous_command.key == more_kc_run_shell && ctl->shell_line
|
|
+ && ctl->prev_command_called == 1) {
|
|
fputs(ctl->shell_line, stderr);
|
|
+ ctl->prev_command_called = 0;
|
|
+ }
|
|
else {
|
|
ttyin(ctl, cmdbuf, sizeof(cmdbuf) - 2, '!');
|
|
if (strpbrk(cmdbuf, "%!\\"))
|
|
@@ -1674,6 +1678,7 @@ static int more_key_command(struct more_control *ctl, char *filename)
|
|
else
|
|
ctl->report_errors = 0;
|
|
ctl->search_called = 0;
|
|
+ ctl->prev_command_called = 0;
|
|
for (;;) {
|
|
if (more_poll(ctl, -1, &stderr_active) <= 0)
|
|
continue;
|
|
@@ -1682,10 +1687,13 @@ static int more_key_command(struct more_control *ctl, char *filename)
|
|
cmd = read_command(ctl);
|
|
if (cmd.key == more_kc_unknown_command)
|
|
continue;
|
|
- if (cmd.key == more_kc_repeat_previous)
|
|
+ if (cmd.key == more_kc_repeat_previous) {
|
|
cmd = ctl->previous_command;
|
|
- else
|
|
+ ctl->prev_command_called = 1;
|
|
+ }
|
|
+ else {
|
|
ctl->previous_command = cmd;
|
|
+ }
|
|
|
|
switch (cmd.key) {
|
|
case more_kc_backwards:
|