Skip to content

Commit a2137dc

Browse files
committed
Make less read lesskey source file rather than binary file.
lesskey tool is no longer needed.
1 parent abf688a commit a2137dc

10 files changed

Lines changed: 142 additions & 57 deletions

File tree

‎Makefile.in‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ SHELL = /bin/sh
4646
OBJ = \
4747
main.${O} screen.${O} brac.${O} ch.${O} charset.${O} cmdbuf.${O} \
4848
command.${O} cvt.${O} decode.${O} edit.${O} filename.${O} forwback.${O} \
49-
help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
49+
help.${O} ifile.${O} input.${O} jump.${O} \
50+
lesskey_parse.${O} line.${O} linenum.${O} \
5051
lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
5152
output.${O} pattern.${O} position.${O} prompt.${O} search.${O} signal.${O} \
5253
tags.${O} ttyin.${O} version.${O} @REGEX_O@

‎NEWS.VER‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

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

39+
* Make less read lesskey source file, and add the --lesskey-src option.
40+
3941
* Display -w highlight even if highlighted line is empty.
4042

4143
* If search result is in a long line, scroll to ensure it is visible.

‎decode.c‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,17 @@ init_cmds(VOID_PARAM)
339339
#ifdef BINDIR
340340
add_hometable(NULL, BINDIR "/.sysless", 1);
341341
#endif
342-
/*
343-
* Try to add the tables in the system lesskey file.
344-
*/
345-
add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
346-
/*
347-
* Try to add the tables in the standard lesskey file "$HOME/.less".
348-
*/
349-
add_hometable("LESSKEY", LESSKEYFILE, 0);
342+
if (lesskey_src(NULL) != 0)
343+
{
344+
/*
345+
* Try to add the tables in the system lesskey file.
346+
*/
347+
add_hometable("LESSKEY_SYSTEM", LESSKEYFILE_SYS, 1);
348+
/*
349+
* Try to add the tables in the standard lesskey file "$HOME/.less".
350+
*/
351+
add_hometable("LESSKEY", LESSKEYFILE, 0);
352+
}
350353
#endif
351354
}
352355

@@ -870,6 +873,29 @@ lesskey(filename, sysvar)
870873
return (new_lesskey(buf, (int)len, sysvar));
871874
}
872875

876+
public int
877+
lesskey_src(filename)
878+
char *filename;
879+
{
880+
static struct lesskey_tables tables;
881+
int r = parse_lesskey(filename, &tables);
882+
if (r != 0)
883+
return (r);
884+
add_fcmd_table(tables.cmdtable.buf.data, tables.cmdtable.buf.end);
885+
add_ecmd_table(tables.edittable.buf.data, tables.edittable.buf.end);
886+
add_var_table(&list_var_tables, tables.vartable.buf.data, tables.vartable.buf.end);
887+
return (0);
888+
}
889+
890+
void
891+
lesskey_parse_error(s)
892+
char *s;
893+
{
894+
PARG parg;
895+
parg.p_string = s;
896+
error("%s", &parg);
897+
}
898+
873899
/*
874900
* Add the standard lesskey file "$HOME/.less"
875901
*/

‎less.nro.VER‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,23 @@ if a lesskey file is found in a standard place (see KEY BINDINGS),
766766
it is also used as a
767767
.I lesskey
768768
file.
769+
.IP "\-\-lesskey-src=\fIfilename\fP"
770+
Causes
771+
.I less
772+
to open and interpret the named file as a
773+
.IR lesskey (1)
774+
source file. The
775+
.I lesskey
776+
source file is the file which was used as the input file to the
777+
.I lesskey
778+
program in versions of less prior to v582.
779+
Current versions of
780+
.I less
781+
(v582 and later) do not require the
782+
.I lesskey
783+
program to be run, and instead interpret the
784+
.I lesskey
785+
source file directly.
769786
.IP "\-K or \-\-quit-on-intr"
770787
Causes
771788
.I less

‎lesskey.c‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ char endsection[1] = { END_SECTION };
9999
char *infile = NULL;
100100
char *outfile = NULL ;
101101

102-
extern char *homefile(char *filename);
103102
extern char version[];
104103

105104
static void
@@ -116,6 +115,44 @@ lesskey_parse_error(s)
116115
fprintf(stderr, "%s\n", s);
117116
}
118117

118+
static char *
119+
mkpathname(dirname, filename)
120+
char *dirname;
121+
char *filename;
122+
{
123+
char *pathname;
124+
125+
pathname = calloc(strlen(dirname) + strlen(filename) + 2, sizeof(char));
126+
strcpy(pathname, dirname);
127+
strcat(pathname, PATHNAME_SEP);
128+
strcat(pathname, filename);
129+
return (pathname);
130+
}
131+
132+
/*
133+
* Figure out the name of a default file (in the user's HOME directory).
134+
*/
135+
char *
136+
homefile(filename)
137+
char *filename;
138+
{
139+
char *p;
140+
char *pathname;
141+
142+
if ((p = getenv("HOME")) != NULL && *p != '\0')
143+
pathname = mkpathname(p, filename);
144+
#if OS2
145+
else if ((p = getenv("INIT")) != NULL && *p != '\0')
146+
pathname = mkpathname(p, filename);
147+
#endif
148+
else
149+
{
150+
fprintf(stderr, "cannot find $HOME - using current directory\n");
151+
pathname = mkpathname(".", filename);
152+
}
153+
return (pathname);
154+
}
155+
119156
/*
120157
* Parse command line arguments.
121158
*/
@@ -261,7 +298,7 @@ main(argc, argv)
261298
* Process command line arguments.
262299
*/
263300
parse_args(argc, argv);
264-
errors = parse_lesskey(NULL, &tables);
301+
errors = parse_lesskey(infile, &tables);
265302
if (errors)
266303
{
267304
fprintf(stderr, "%d errors; no output produced\n", errors);

‎lesskey.nro.VER‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'\" t
22
.TH LESSKEY 1 "Version @@VERSION@@: @@DATE@@"
33
.SH NAME
4-
lesskey \- specify key bindings for less
4+
lesskey \- specify key bindings for less (deprecated)
55
.SH SYNOPSIS
66
.B "lesskey [\-o output] [\-\-] [input]"
77
.br
@@ -10,6 +10,19 @@ lesskey \- specify key bindings for less
1010
.B "lesskey \-V"
1111
.br
1212
.B "lesskey \-\-version"
13+
.SH NOTE
14+
.I less
15+
version 582 and later no longer requires
16+
.I lesskey
17+
to be used. Instead, the source (non-binary)
18+
.I lesskey
19+
file is read directly by
20+
.IR less ,
21+
and any binary file produced by
22+
.I lesskey
23+
is ignored.
24+
This document describes the format of the source file.
25+
.PP
1326
.SH DESCRIPTION
1427
.I Lesskey
1528
is used to specify a set of key bindings to be used by
@@ -41,7 +54,7 @@ The \-V or \-\-version option causes
4154
.I lesskey
4255
to print its version number and immediately exit.
4356
If \-V or \-\-version is present, other options and arguments are ignored.
44-
.PP
57+
.SH SOURCE FILE
4558
The input file consists of one or more
4659
.I sections.
4760
Each section starts with a line that identifies the type of section.

‎lesskey_parse.c‎

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#define ESC CONTROL('[')
1010

1111
extern void lesskey_parse_error(char *s);
12+
extern char *homefile(char *filename);
1213

1314
static int linenum;
1415
static int errors;
16+
static char *lesskey_file;
1517

1618
static struct lesskey_cmdname cmdnames[] =
1719
{
@@ -107,7 +109,7 @@ static struct lesskey_cmdname editnames[] =
107109
{ NULL, 0 }
108110
};
109111

110-
void
112+
static void
111113
xbuf_init(xbuf)
112114
struct xbuffer *xbuf;
113115
{
@@ -116,7 +118,7 @@ xbuf_init(xbuf)
116118
xbuf->end = 0;
117119
}
118120

119-
void
121+
static void
120122
xbuf_add(xbuf, ch)
121123
struct xbuffer *xbuf;
122124
char ch;
@@ -136,50 +138,12 @@ xbuf_add(xbuf, ch)
136138
parse_error(msg)
137139
char *msg;
138140
{
139-
char buf[128];
141+
char buf[1024];
140142
++errors;
141-
snprintf(buf, sizeof(buf), "line %d: %s", linenum, msg);
143+
snprintf(buf, sizeof(buf), "%s, line %d: %s", lesskey_file, linenum, msg);
142144
lesskey_parse_error(buf);
143145
}
144146

145-
static char *
146-
mkpathname(dirname, filename)
147-
char *dirname;
148-
char *filename;
149-
{
150-
char *pathname;
151-
152-
pathname = calloc(strlen(dirname) + strlen(filename) + 2, sizeof(char));
153-
strcpy(pathname, dirname);
154-
strcat(pathname, PATHNAME_SEP);
155-
strcat(pathname, filename);
156-
return (pathname);
157-
}
158-
159-
/*
160-
* Figure out the name of a default file (in the user's HOME directory).
161-
*/
162-
char *
163-
homefile(filename)
164-
char *filename;
165-
{
166-
char *p;
167-
char *pathname;
168-
169-
if ((p = getenv("HOME")) != NULL && *p != '\0')
170-
pathname = mkpathname(p, filename);
171-
#if OS2
172-
else if ((p = getenv("INIT")) != NULL && *p != '\0')
173-
pathname = mkpathname(p, filename);
174-
#endif
175-
else
176-
{
177-
fprintf(stderr, "cannot find $HOME - using current directory\n");
178-
pathname = mkpathname(".", filename);
179-
}
180-
return (pathname);
181-
}
182-
183147
/*
184148
* Initialize data structures.
185149
*/
@@ -573,10 +537,10 @@ parse_lesskey(infile, tables)
573537
{
574538
FILE *desc;
575539
char line[1024];
576-
int linenum;
577540

578541
if (infile == NULL)
579542
infile = homefile(DEF_LESSKEYINFILE);
543+
lesskey_file = infile;
580544

581545
init_tables(tables);
582546

‎optfunc.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,25 @@ opt_k(type, s)
295295
break;
296296
}
297297
}
298+
299+
public void
300+
opt_ks(type, s)
301+
int type;
302+
char *s;
303+
{
304+
PARG parg;
305+
306+
switch (type)
307+
{
308+
case INIT:
309+
if (lesskey_src(s))
310+
{
311+
parg.p_string = s;
312+
error("Cannot use lesskey source file \"%s\"", &parg);
313+
}
314+
break;
315+
}
316+
}
298317
#endif
299318

300319
#if TAGS

‎opttbl.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static struct optname j_optname = { "jump-target", NULL };
8383
static struct optname J__optname = { "status-column", NULL };
8484
#if USERFILE
8585
static struct optname k_optname = { "lesskey-file", NULL };
86+
static struct optname ks_optname = { "lesskey-src", NULL };
8687
#endif
8788
static struct optname K__optname = { "quit-on-intr", NULL };
8889
static struct optname L__optname = { "no-lessopen", NULL };
@@ -267,6 +268,10 @@ static struct loption option[] =
267268
STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k,
268269
{ NULL, NULL, NULL }
269270
},
271+
{ OLETTER_NONE, &ks_optname,
272+
STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_ks,
273+
{ NULL, NULL, NULL }
274+
},
270275
#endif
271276
{ 'K', &K__optname,
272277
BOOL, OPT_OFF, &quit_on_intr, NULL,

‎version.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ v578 2/9/21 Doc
912912
v579 2/14/21 Fix double-width char bugs and non-match search crash.
913913
v580 3/2/21 Some color fixes; fix compiler warnings; some lesstest support.
914914
v581 4/6/21 Ignore SIGTSTP in secure mode; don't print "skipping" when filtering.
915-
v582 Fix bug in finding tags with backslashes.
915+
v582 Less now reads lesskey source file rather than binary;
916+
fix bug in finding tags with backslashes.
916917
*/
917918

918919
char version[] = "582x";

0 commit comments

Comments
 (0)