Skip to content

Commit

Permalink
Add M and ESC-M commands.
Browse files Browse the repository at this point in the history
Fix buffering bug when using stdin with LESSOPEN pipe
(h,q displays corrupt data).
  • Loading branch information
gwsw committed Jul 17, 2017
1 parent ded5c3d commit 05e12cd
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* When using -S, mark truncated lines with a special character.
The character can be changed or disabled via the new --rscroll option.

* New command M visually marks the last line displayed on the screen.

* Status column (enabled via -J) now shows mark letters.

* Do same ANSI escape code filtering for tag matching that we do for
Expand All @@ -27,6 +29,8 @@

* Fix bug initializing default charset on Windows.

* Fix buffering bug when using stdin with a LESSOPEN pipe.

* Update Unicode tables to 2017-03-08.

* Pass-thru Unicode formating chars (Cf type) instead of treating them
Expand Down
5 changes: 2 additions & 3 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,12 @@ ch_init(f, flags)
calloc(1, sizeof(struct filestate));
thisfile->buflist.next = thisfile->buflist.prev = END_OF_CHAIN;
thisfile->nbufs = 0;
thisfile->flags = 0;
thisfile->flags = flags;
thisfile->fpos = 0;
thisfile->block = 0;
thisfile->offset = 0;
thisfile->file = -1;
thisfile->fsize = NULL_POSITION;
ch_flags = flags;
init_hashtbl();
/*
* Try to seek; set CH_CANSEEK if it works.
Expand All @@ -891,7 +890,7 @@ ch_close()
if (thisfile == NULL)
return;

if (ch_flags & (CH_CANSEEK|CH_HELPFILE))
if ((ch_flags & (CH_CANSEEK|CH_POPENED|CH_HELPFILE)) && !(ch_flags & CH_KEEPOPEN))
{
/*
* We can seek or re-open, so we don't need to keep buffers.
Expand Down
1 change: 1 addition & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#define A_LLSHIFT 58
#define A_RRSHIFT 59
#define A_SETATTN 60
#define A_CLRATTN 61

#define A_INVALID 100
#define A_NOACTION 101
Expand Down
8 changes: 6 additions & 2 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern int hshift;
extern int bs_mode;
extern int show_attn;
extern int sticky_attn;
extern int status_col;
extern POSITION highest_hilite;
extern char *every_first_cmd;
extern char *curr_altfilename;
Expand Down Expand Up @@ -85,10 +86,8 @@ static void multi_search();
static void
cmd_exec()
{
#if HILITE_SEARCH
if (!sticky_attn)
clear_attn();
#endif
clear_bot();
flush();
}
Expand Down Expand Up @@ -1787,10 +1786,15 @@ commands()
break;

case A_SETATTN:
status_col = 1;
set_attnpos(position(BOTTOM), 1);
repaint();
break;

case A_CLRATTN:
clear_attn();
break;

case A_PREFIX:
/*
* The command is incomplete (more chars are needed).
Expand Down
1 change: 1 addition & 0 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ static unsigned char cmdtable[] =
'&',0, A_FILTER,
'm',0, A_SETMARK,
'M',0, A_SETATTN,
ESC,'M',0, A_CLRATTN,
'\'',0, A_GOMARK,
CONTROL('X'),CONTROL('X'),0, A_GOMARK,
'E',0, A_EXAMINE,
Expand Down
10 changes: 9 additions & 1 deletion edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,17 @@ edit_ifile(ifile)
}

filename = save(get_filename(ifile));

/*
* See if LESSOPEN specifies an "alternate" file to open.
*/
alt_pipe = NULL;
alt_filename = open_altfile(filename, &f, &alt_pipe);
if (strcmp(filename, FAKE_HELPFILE) == 0 ||
strcmp(filename, FAKE_EMPTYFILE) == 0)
alt_filename = NULL;
else
alt_filename = open_altfile(filename, &f, &alt_pipe);

open_filename = (alt_filename != NULL) ? alt_filename : filename;
qopen_filename = shell_unquote(open_filename);

Expand All @@ -282,6 +288,8 @@ edit_ifile(ifile)
* via popen(), and pclose() wants to close it.
*/
chflags |= CH_POPENED;
if (strcmp(open_filename, "-") == 0)
chflags |= CH_KEEPOPEN;
} else if (strcmp(open_filename, "-") == 0)
{
/*
Expand Down
1 change: 1 addition & 0 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ close_altfile(altfilename, filename, pipefd)

if (secure)
return;
ch_ungetchar(-1);
if (pipefd != NULL)
{
#if OS2
Expand Down
1 change: 0 additions & 1 deletion less.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ struct wchar_range_table
#define CH_HELPFILE 010
#define CH_NODATA 020 /* Special case for zero length files */


#define ch_zero() ((POSITION)0)

#define FAKE_HELPFILE "@/\\less/\\help/\\file/\\@"
Expand Down
7 changes: 7 additions & 0 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ Marks are preserved when a new file is examined,
so the ' command can be used to switch between input files.
.IP "^X^X"
Same as single quote.
.IP M
Visually marks the last line displayed on the screen.
The status column is enabled to show the mark if it is not already enabled via the -J option.
This can be useful to keep track of a particular line while moving in the file
or while new lines are displayed during the F command.
.IP "ESC-M"
Removes the mark set by a previous M command.
.IP /pattern
Search forward in the file for the N-th line containing the pattern.
N defaults to 1.
Expand Down
4 changes: 3 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ v501 7/12/17 Make sure rscroll char is standout by default.
v502 7/13/17 Control rscroll char via command line option not env variable.
v503 7/13/17 Switch to git.
v504 7/13/17 Call opt_rscroll at startup; change mkhelp.c to mkhelp.pl.
v505 7/17/17 Add M and ESC-M commands;
fix buffer handling with stdin and LESSOPEN.
*/

char version[] = "504";
char version[] = "505";

0 comments on commit 05e12cd

Please sign in to comment.