Skip to content

Commit

Permalink
Allow control-X to interrupt F command loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Dec 1, 2020
1 parent 6a070fc commit 5bf862f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ AC_TRY_COMPILE([], [int f(int a) { return a; }],

# Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([fsync popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod realpath])
AC_CHECK_FUNCS([fsync poll popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod realpath])

# AC_CHECK_FUNCS may not work for inline functions, so test these separately.
AC_MSG_CHECKING(for memcpy)
Expand Down
2 changes: 2 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Normally this command would be used when already at the end of the file.
It is a way to monitor the tail of a file which is growing
while it is being viewed.
(The behavior is similar to the "tail \-f" command.)
To stop waiting for more data, enter the interrupt character (usually ^C).
On some systems you can also use ^X.
.IP "ESC-F"
Like F, but as soon as a line is found which matches
the last search pattern, the terminal bell is rung
Expand Down
7 changes: 4 additions & 3 deletions linenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ longish(VOID_PARAM)
static void
abort_long(VOID_PARAM)
{
if (loopcount >= 0)
return;
if (linenums == OPT_ONPLUS)
/*
* We were displaying line numbers, so need to repaint.
Expand Down Expand Up @@ -301,6 +303,7 @@ find_linenum(pos)
#if HAVE_TIME
startime = get_time();
#endif
loopcount = 0;
if (p == &anchor || pos - p->prev->pos < p->pos - pos)
{
/*
Expand All @@ -309,7 +312,6 @@ find_linenum(pos)
p = p->prev;
if (ch_seek(p->pos))
return (0);
loopcount = 0;
for (linenum = p->line, cpos = p->pos; cpos < pos; linenum++)
{
/*
Expand Down Expand Up @@ -341,7 +343,6 @@ find_linenum(pos)
*/
if (ch_seek(p->pos))
return (0);
loopcount = 0;
for (linenum = p->line, cpos = p->pos; cpos > pos; linenum--)
{
/*
Expand All @@ -361,7 +362,7 @@ find_linenum(pos)
*/
add_lnum(linenum, cpos);
}

loopcount = 0;
return (linenum);
}

Expand Down
27 changes: 26 additions & 1 deletion os.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#if HAVE_VALUES_H
#include <values.h>
#endif
#if HAVE_POLL
#include <poll.h>
#endif

/*
* BSD setjmp() saves (and longjmp() restores) the signal mask.
Expand All @@ -46,6 +49,10 @@ public int reading;
static jmp_buf read_label;

extern int sigs;
extern int ignore_eoi;
#if !MSDOS_COMPILER
extern int tty;
#endif

/*
* Like read() system call, but is deliberately interruptible.
Expand Down Expand Up @@ -119,6 +126,25 @@ iread(fd, buf, len)
if (select(fd+1, &readfds, 0, 0, 0) == -1)
return (-1);
}
#endif
#if HAVE_POLL && !MSDOS_COMPILER
if (ignore_eoi)
{
struct pollfd poll_tty = { tty, POLLIN, 0 };
n = poll(&poll_tty, 1, 0);
if (n > 0)
{
if (poll_tty.revents & POLLIN)
{
n = read(tty, buf, 1);
if (n > 0 && buf[0] == CONTROL('X'))
{
sigs |= S_INTERRUPT;
return (READ_INTR);
}
}
}
}
#endif
n = read(fd, buf, len);
#if 1
Expand All @@ -128,7 +154,6 @@ iread(fd, buf, len)
* start returning 0 forever, instead of -1.
*/
{
extern int ignore_eoi;
if (!ignore_eoi)
{
static int consecutive_nulls = 0;
Expand Down
3 changes: 2 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,8 @@ v567 11/25/20 Fix typo.
v568 11/29/20 Fix some hyperlink bugs; add ^W search modifier
(thanks to Arminius); allow Makefile.aut to use Python
instead of Perl (thanks to Charlie Lin).
v569 Allow multiple & filters (thanks to Mattias Johansson).
v569 Allow multiple & filters (thanks to Mattias Johansson),
allow ^X to exit F command.
*/

char version[] = "569x";

0 comments on commit 5bf862f

Please sign in to comment.