8000 more: fix implicit previous shell_line execution #3508 · util-linux/util-linux@b6f9362 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6f9362

Browse files
committed
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>
1 parent d2dadb7 commit b6f9362

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

text-utils/more.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ struct more_control {
226226
print_banner, /* print file name banner */
227227
reading_num, /* are we reading leading_number */
228228
report_errors, /* is an error reported */
229+
prev_command_called, /* previous more command is called */
229230
search_at_start, /* search pattern defined at start up */
230231
search_called, /* previous more command was a search */
231232
squeeze_spaces, /* suppress white space */
@@ -1295,8 +1296,11 @@ static void run_shell(struct more_control *ctl, char *filename)
12951296
erase_to_col(ctl, 0);
12961297
putchar('!');
12971298
fflush(NULL);
1298-
if (ctl->previous_command.key == more_kc_run_shell && ctl->shell_line)
1299+
if (ctl->previous_command.key == more_kc_run_shell && ctl->shell_line
1300+
&& ctl->prev_command_called == 1) {
12991301
fputs(ctl->shell_line, stderr);
1302+
ctl->prev_command_called = 0;
1303+
}
13001304
else {
13011305
ttyin(ctl, cmdbuf, sizeof(cmdbuf) - 2, '!');
13021306
if (strpbrk(cmdbuf, "%!\\"))
@@ -1675,6 +1679,7 @@ static int more_key_command(struct more_control *ctl, char *filename)
16751679
else
16761680
ctl->report_errors = 0;
16771681
ctl->search_called = 0;
1682+
ctl->prev_command_called = 0;
16781683
for (;;) {
16791684
if (more_poll(ctl, -1, &stderr_active) <= 0)
16801685
continue;
@@ -1683,10 +1688,13 @@ static int more_key_command(struct more_control *ctl, char *filename)
16831688
cmd = read_command(ctl);
16841689
if (cmd.key == more_kc_unknown_command)
16851690
continue;
1686-
if (cmd.key == more_kc_repeat_previous)
1691+
if (cmd.key == more_kc_repeat_previous) {
16871692
cmd = ctl->previous_command;
1688-
else
1693+
ctl->prev_command_called = 1;
1694+
}
1695+
else {
16891696
ctl->previous_command = cmd;
1697+
}
16901698

16911699
switch (cmd.key) {
16921700
case more_kc_backwards:

0 commit comments

Comments
 (0)
0