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

Skip to content

Commit 250f1fc

Browse files
cgoeschekarelzak
authored andcommitted
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 b6f9362)
1 parent f997901 commit 250f1fc

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, "%!\\"))
@@ -1674,6 +1678,7 @@ static int more_key_command(struct more_control *ctl, char *filename)
16741678
else
16751679
ctl->report_errors = 0;
16761680
ctl->search_called = 0;
1681+
ctl->prev_command_called = 0;
16771682
for (;;) {
16781683
if (more_poll(ctl, -1, &stderr_active) <= 0)
16791684
continue;
@@ -1682,10 +1687,13 @@ static int more_key_command(struct more_control *ctl, char *filename)
16821687
cmd = read_command(ctl);
16831688
if (cmd.key == more_kc_unknown_command)
16841689
continue;
1685-
if (cmd.key == more_kc_repeat_previous)
1690+
if (cmd.key == more_kc_repeat_previous) {
16861691
cmd = ctl->previous_command;
1687-
else
1692+
ctl->prev_command_called = 1;
1693+
}
1694+
else {
16881695
ctl->previous_command = cmd;
1696+
}
16891697

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

0 commit comments

Comments
 (0)
0