Skip to content

Commit

Permalink
Better error messages from lesskey parsing.
Browse files Browse the repository at this point in the history
Documentation.
  • Loading branch information
gwsw committed Apr 14, 2021
1 parent 6ce718a commit b0dbdb8
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 130 deletions.
10 changes: 7 additions & 3 deletions NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

======================================================================

Major changes between "less" versions 563 and @@VERSION@@
Major changes between "less" versions 581 and @@VERSION@@

* Make less read lesskey source file, and add the --lesskey-src option.

======================================================================

Major changes between "less" versions 563 and 581

* Change ESC-u command to toggle, not disable, highlighting per man page.

Expand All @@ -36,8 +42,6 @@

* Add the --use-color and --color options.

* Make less read lesskey source file, and add the --lesskey-src option.

* Display -w highlight even if highlighted line is empty.

* If search result is in a long line, scroll to ensure it is visible.
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ AH_TOP([
#define LESSKEYFILE ".less"
#define LESSKEYFILE_SYS SYSDIR "/sysless"
#define DEF_LESSKEYINFILE ".lesskey"
#define LESSKEYINFILE_SYS SYSDIR "/syslesskey"
#define LESSHISTFILE ".lesshst"
Expand Down
57 changes: 28 additions & 29 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,37 +331,38 @@ init_cmds(VOID_PARAM)
*/
add_fcmd_table((char*)cmdtable, sizeof(cmdtable));
add_ecmd_table((char*)edittable, sizeof(edittable));

#if USERFILE
/*
* For backwards compatibility,
* try to add tables in the OLD system lesskey file.
*/
#ifdef BINDIR
add_hometable(NULL, BINDIR "/.sysless", 1);
#ifdef BINDIR /* For backwards compatibility */
/* Try to add tables in the OLD system lesskey file. */
add_hometable(lesskey, NULL, BINDIR "/.sysless", 1);
#endif
#ifdef LESSKEYSRCFILE_SYS
/*
* Try to add tables in system lesskey src file.
* Try to load lesskey source file or binary file.
* If the source file succeeds, don't load binary file.
* The binary file is likely to have been generated from
* a (possibly out of date) copy of the src file,
* so loading it is at best redundant.
*/
(void) lesskey_src(LESSKEYSRCFILE_SYS, 1);
#endif
/*
* Try to add the tables in the system lesskey file.
* Try to add tables in system lesskey src file.
*/
add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
if (add_hometable(lesskey_src, "LESSKEYIN_SYSTEM", LESSKEYINFILE_SYS, 1) != 0)
{
/*
* Try to add the tables in the system lesskey binary file.
*/
add_hometable(lesskey, "LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
}
/*
* Try to add tables in the lesskey src file "$HOME/.lesskey".
* If it succeeds, don't load binary file.
* The binary file is likely to have been generated from
* a (possibly out of date) copy of the src file,
* so loading it is at best redundant.
*/
if (lesskey_src(NULL, 0) != 0)
if (add_hometable(lesskey_src, "LESSKEYIN", DEF_LESSKEYINFILE, 0) != 0)
{
/*
* Try to add the tables in the standard lesskey file "$HOME/.less".
* Try to add the tables in the standard lesskey binary file "$HOME/.less".
*/
add_hometable("LESSKEY", LESSKEYFILE, 0);
add_hometable(lesskey, "LESSKEY", LESSKEYFILE, 0);
}
#endif
}
Expand Down Expand Up @@ -912,16 +913,17 @@ lesskey_parse_error(s)
}

/*
* Add the standard lesskey file "$HOME/.less"
* Add a lesskey file.
*/
public void
add_hometable(envname, def_filename, sysvar)
public int
add_hometable(call_lesskey, envname, def_filename, sysvar)
int (*call_lesskey)(char *, int);
char *envname;
char *def_filename;
int sysvar;
{
char *filename;
PARG parg;
int r;

if (envname != NULL && (filename = lgetenv(envname)) != NULL)
filename = save(filename);
Expand All @@ -930,13 +932,10 @@ add_hometable(envname, def_filename, sysvar)
else
filename = homefile(def_filename);
if (filename == NULL)
return;
if (lesskey(filename, sysvar) < 0)
{
parg.p_string = filename;
error("Cannot use lesskey file \"%s\"", &parg);
}
return -1;
r = (*call_lesskey)(filename, sysvar);
free(filename);
return (r);
}
#endif

Expand Down
1 change: 1 addition & 0 deletions defines.ds
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
#define LESSKEYFILE "_less"
#define LESSKEYFILE_SYS "c:\\_sysless"
#define DEF_LESSKEYINFILE "_lesskey"
#define LESSKEYINFILE_SYS "c:\\_syslesskey"
#define LESSHISTFILE "_lesshst"


Expand Down
1 change: 1 addition & 0 deletions defines.o2
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#define LESSKEYFILE "less.ini"
#define LESSKEYFILE_SYS "C:\\sysless.ini"
#define DEF_LESSKEYINFILE "lesskey.ini"
#define LESSKEYINFILE_SYS "C:\\syslesskey.ini"
#define LESSHISTFILE "lesshst.ini"


Expand Down
1 change: 1 addition & 0 deletions defines.o9
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
#define LESSKEYFILE ".less"
#define LESSKEYFILE_SYS "/.sysless"
#define DEF_LESSKEYINFILE ".lesskey"
#define LESSKEYINFILE_SYS "/.syslesskey"
#define LESSHISTFILE ".lesshst"


Expand Down
1 change: 1 addition & 0 deletions defines.wn
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#define LESSKEYFILE "_less"
#define LESSKEYFILE_SYS "c:\\_sysless"
#define DEF_LESSKEYINFILE "_lesskey"
#define LESSKEYINFILE_SYS "c:\\_syslesskey"
#define LESSHISTFILE "_lesshst"


Expand Down
92 changes: 56 additions & 36 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ Causes
.I less
to open and interpret the named file as a
.IR lesskey (1)
file.
binary file.
Multiple \-k options may be specified.
If the LESSKEY or LESSKEY_SYSTEM environment variable is set, or
if a lesskey file is found in a standard place (see KEY BINDINGS),
Expand All @@ -771,18 +771,26 @@ Causes
.I less
to open and interpret the named file as a
.IR lesskey (1)
source file. The
.I lesskey
source file is the file which was used as the input file to the
.I lesskey
program in versions of less prior to v582.
Current versions of
.I less
(v582 and later) do not require the
.I lesskey
program to be run, and instead interpret the
source file.
If the LESSKEYIN or LESSKEYIN_SYSTEM environment variable is set, or
if a lesskey source file is found in a standard place (see KEY BINDINGS),
it is also used as a
.I "lesskey source"
file.
Prior to version 582, the
.I lesskey
source file directly.
program needed to be run to convert a
.I "lesskey source"
file to a
.I "lesskey binary"
file for
.I less
to use.
Newer versions of
.I less
read the
.I "lesskey source"
file directly and ignore the binary file if the source file exists.
.IP "\-K or \-\-quit-on-intr"
Causes
.I less
Expand Down Expand Up @@ -1239,57 +1247,61 @@ Delete the entire command line and return to the main prompt.
.SH "KEY BINDINGS"
You may define your own
.I less
commands by using the program
.IR lesskey (1)
to create a lesskey file.
commands by creating a lesskey source file.
This file specifies a set of command keys and an action
associated with each key.
You may also use
.I lesskey
to change the line-editing keys (see LINE EDITING),
You may also change the line-editing keys (see LINE EDITING),
and to set environment variables.
If the environment variable LESSKEY is set,
If the environment variable LESSKEYIN is set,
.I less
uses that as the name of the lesskey file.
uses that as the name of the lesskey source file.
Otherwise,
.I less
looks in a standard place for the lesskey file:
looks in a standard place for the lesskey source file:
On Unix systems,
.I less
looks for a lesskey file called "$HOME/.less".
looks for a lesskey file called "$HOME/.lesskey".
On MS-DOS and Windows systems,
.I less
looks for a lesskey file called "$HOME/_less", and if it is not found there,
then looks for a lesskey file called "_less" in any directory specified
looks for a lesskey file called "$HOME/_lesskey", and if it is not found there,
then looks for a lesskey file called "_lesskey" in any directory specified
in the PATH environment variable.
On OS/2 systems,
.I less
looks for a lesskey file called "$HOME/less.ini", and if it is not found,
then looks for a lesskey file called "less.ini" in any directory specified
looks for a lesskey file called "$HOME/lesskey.ini", and if it is not found,
then looks for a lesskey file called "lesskey.ini" in any directory specified
in the INIT environment variable, and if it not found there,
then looks for a lesskey file called "less.ini" in any directory specified
then looks for a lesskey file called "lesskey.ini" in any directory specified
in the PATH environment variable.
See the
.I lesskey
manual page for more details.
.P
A system-wide lesskey file may also be set up to provide key bindings.
.PP
A system-wide lesskey source file may also be set up to provide key bindings.
If a key is defined in both a local lesskey file and in the
system-wide file, key bindings in the local file take precedence over
those in the system-wide file.
If the environment variable LESSKEY_SYSTEM is set,
If the environment variable LESSKEYIN_SYSTEM is set,
.I less
uses that as the name of the system-wide lesskey file.
Otherwise,
.I less
looks in a standard place for the system-wide lesskey file:
On Unix systems, the system-wide lesskey file is /usr/local/etc/sysless.
On Unix systems, the system-wide lesskey file is /usr/local/etc/syslesskey.
(However, if
.I less
was built with a different sysconf directory than /usr/local/etc,
that directory is where the sysless file is found.)
On MS-DOS and Windows systems, the system-wide lesskey file is c:\e_sysless.
On OS/2 systems, the system-wide lesskey file is c:\esysless.ini.
On MS-DOS and Windows systems, the system-wide lesskey file is c:\e_syslesskey.
On OS/2 systems, the system-wide lesskey file is c:\esyslesskey.ini.
.PP
Previous versions of
.I less
(before v582) used lesskey files with a binary format, produced by the
.I lesskey
program. It is no longer necessary to use the
.I lesskey
program.
.
.SH "INPUT PREPROCESSOR"
You may define an "input preprocessor" for
Expand Down Expand Up @@ -1913,14 +1925,22 @@ on OS/2 systems.
.IP LESSHISTSIZE
The maximum number of commands to save in the history file.
The default is 100.
.IP LESSKEYIN
Name of the default
.I "lesskey source"
file.
.IP LESSKEY
Name of the default
.IR lesskey (1)
.I "lesskey binary"
file. (Not used if "$LESSKEYIN" exists.)
.IP LESSKEYIN_SYSTEM
Name of the default system-wide
.I "lesskey source"
file.
.IP LESSKEY_SYSTEM
Name of the default system-wide
.IR lesskey (1)
file.
.I "lesskey binary"
file. (Not used if "$LESSKEYIN_SYSTEM" exists.)
.IP LESSMETACHARS
List of characters which are considered "metacharacters" by the shell.
.IP LESSMETAESCAPE
Expand Down
57 changes: 16 additions & 41 deletions lesskey.nro.VER
Original file line number Diff line number Diff line change
@@ -1,60 +1,35 @@
'\" t
.TH LESSKEY 1 "Version @@VERSION@@: @@DATE@@"
.SH NAME
lesskey \- specify key bindings for less (deprecated)
.SH SYNOPSIS
lesskey \- specify key bindings for less
.SH "SYNOPSIS (deprecated)"
.B "lesskey [\-o output] [\-\-] [input]"
.br
.B "lesskey [\-\-output=output] [\-\-] [input]"
.br
.B "lesskey \-V"
.br
.B "lesskey \-\-version"
.SH NOTE
.I less
version 582 and later no longer requires
.I lesskey
to be used. Instead, the source (non-binary)
.SH SCOPE
This document describes the format of the
.I lesskey
file is read directly by
source file, which is used by
.I less
version 582 and later.
In previous versions of
.IR less ,
and any binary file produced by
a separate program called
.I lesskey
is ignored.
This document describes the format of the source file.
.PP
.SH DESCRIPTION
.I Lesskey
is used to specify a set of key bindings to be used by
was used to compile the
.I lesskey
source file into a format understood by
.IR less .
The input file is a text file which describes the key bindings.
If the input file is "\-", standard input is read.
If no input file is specified, a standard filename is used
as the name of the input file, which depends on the system being used:
On Unix systems, "$HOME/.lesskey" is used;
on MS-DOS systems, "$HOME/_lesskey" is used;
and on OS/2 systems "$HOME/lesskey.ini" is used,
or "$INIT/lesskey.ini" if $HOME is undefined.
The output file is a binary file which is used by
.IR less .
If no output file is specified,
and the environment variable LESSKEY is set,
the value of LESSKEY is used as the name of the output file.
Otherwise, a standard filename is used as the name of the output file,
which depends on the system being used:
On Unix and OS-9 systems, "$HOME/.less" is used;
on MS-DOS systems, "$HOME/_less" is used;
and on OS/2 systems, "$HOME/less.ini" is used,
or "$INIT/less.ini" if $HOME is undefined.
If the output file already exists,
This compilation step is no longer required and the
.I lesskey
will overwrite it.
program is therefore deprecated although the file format remains supported by
.IR less .
.PP
The \-V or \-\-version option causes
.I lesskey
to print its version number and immediately exit.
If \-V or \-\-version is present, other options and arguments are ignored.
.SH SOURCE FILE
.SH FILE FORMAT
The input file consists of one or more
.I sections.
Each section starts with a line that identifies the type of section.
Expand Down
Loading

0 comments on commit b0dbdb8

Please sign in to comment.