Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gwsw/less
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Dec 25, 2021
2 parents 3102e64 + fc0ea4f commit 24dea15
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
1 change: 0 additions & 1 deletion Makefile.aut
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ ${srcdir}/configure ${srcdir}/defines.h.in: ${srcdir}/configure.ac ${srcdir}/Mak
funcs.h: ${SRC:%=${srcdir}/%}
-mv -f ${srcdir}/funcs.h ${srcdir}/funcs.h.old
${srcdir}/${MKFUNCS} ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h
if cmp -s funcs.h funcs.h.old; then mv -f funcs.h.old funcs.h; fi

lint:
lint -I. ${CPPFLAGS} ${SRC}
Expand Down
2 changes: 1 addition & 1 deletion forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public int screen_trashed;
public int squished;
public int no_back_scroll = 0;
public int forw_prompt;
public int first_time = 1;

extern int sigs;
extern int top_scroll;
Expand Down Expand Up @@ -227,7 +228,6 @@ forw(n, pos, force, only_last, nblank)
{
int nlines = 0;
int do_repaint;
static int first_time = 1;

squish_check();

Expand Down
2 changes: 1 addition & 1 deletion less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ Each integer is a value between 0 and 255 inclusive which selects
a "CSI 38;5" color value (see
.br
.nh
https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters)
https://en.wikipedia.org/wiki/ANSI_escape_code#SGR)
.hy
If either integer is a "-" or is omitted,
the corresponding color is set to that of normal text.
Expand Down
6 changes: 6 additions & 0 deletions lesskey.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ program is therefore deprecated, although the file format remains supported by
.I less
itself.
.PP
.SH DESCRIPTION
A
.I lesskey
file specifies a set of key bindings and environment variables
to be used by subsequent invocations of
.I less.
.SH FILE FORMAT
The input file consists of one or more
.I sections.
Expand Down
23 changes: 18 additions & 5 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ parse_error(fmt, arg1)
{
char buf[1024];
int n = snprintf(buf, sizeof(buf), "%s: line %d: ", lesskey_file, linenum);
snprintf(buf+n, sizeof(buf)-n, fmt, arg1);
if (n >= 0 && n < sizeof(buf))
snprintf(buf+n, sizeof(buf)-n, fmt, arg1);
++errors;
lesskey_parse_error(buf);
}
Expand Down Expand Up @@ -179,6 +180,18 @@ char_string(buf, ch, lit)
return buf;
}

/*
* Increment char pointer by one up to terminating nul byte.
*/
static char *
increment_pointer(p)
char *p;
{
if (*p == '\0')
return p;
return p+1;
}

/*
* Parse one character of a string.
*/
Expand Down Expand Up @@ -254,7 +267,7 @@ tstr(pp, xlate)
case '1': ch = SK_F1; break;
default:
parse_error("invalid escape sequence \"\\k%s\"", char_string(buf, *p, 0));
*pp = p+1;
*pp = increment_pointer(p);
return ("");
}
*pp = p+1;
Expand All @@ -273,7 +286,7 @@ tstr(pp, xlate)
* Backslash followed by any other char
* just means that char.
*/
*pp = p+1;
*pp = increment_pointer(p);
char_string(buf, *p, 1);
if (xlate && buf[0] == CONTROL('K'))
return tstr_control_k;
Expand All @@ -283,13 +296,13 @@ tstr(pp, xlate)
/*
* Caret means CONTROL.
*/
*pp = p+2;
*pp = increment_pointer(p+1);
char_string(buf, CONTROL(p[1]), 1);
if (xlate && buf[0] == CONTROL('K'))
return tstr_control_k;
return (buf);
}
*pp = p+1;
*pp = increment_pointer(p);
char_string(buf, *p, 1);
if (xlate && buf[0] == CONTROL('K'))
return tstr_control_k;
Expand Down
33 changes: 19 additions & 14 deletions lesstest/lt_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ void screen_init() {
screen.in_esc = 0;
screen.curr_attr = 0;
screen.curr_fg_color = screen.curr_bg_color = 0;
screen.param_top = 0;
screen.params[0] = 0; // start with a 0 on the stack
screen.param_top = -1;
screen.params[0] = 0;
}

void param_print() {
int i;
fprintf(stderr, "(");
for (i = 0; i <= screen.param_top; ++i)
fprintf(stderr, "%d ", screen.params[i]);
fprintf(stderr, ")");
}

void param_push(int v) {
if (screen.param_top >= countof(screen.params)-1)
if (screen.param_top >= (int) countof(screen.params)-1)
return;
screen.params[++screen.param_top] = v;
}

int param_pop() {
int v = screen.params[screen.param_top];
if (screen.param_top > 0)
--screen.param_top;
return v;
int param_pop(){
if (screen.param_top < 0)
return 0; // missing param is assumed to be 0
return screen.params[screen.param_top--];
}

int screen_x(int x) {
Expand Down Expand Up @@ -205,9 +212,7 @@ int exec_esc(wchar ch) {
int x, y, count;
if (verbose) {
fprintf(stderr, "exec ESC-%c ", (char)ch);
int i;
for (i = 0; i <= screen.param_top; ++i)
fprintf(stderr, "%d ", screen.params[i]);
param_print();
fprintf(stderr, "\n");
}
switch (ch) {
Expand All @@ -218,12 +223,12 @@ int exec_esc(wchar ch) {
case 'S': // clear from cursor to end of screen
return screen_clear(screen.cx, screen.cy,
(screen.w - screen.cx) + (screen.h - screen.cy -1) * screen.w);
case 'R': // read screen contents
case 'R': // read N3 chars starting at (N1,N2)
count = param_pop();
y = param_pop();
x = param_pop();
return screen_read(x, y, count);
case 'j': // cursor jump to address
case 'j': // jump cursor to (N1,N2)
y = param_pop();
x = param_pop();
return screen_move(x, y);
Expand Down Expand Up @@ -334,7 +339,7 @@ int setup(int argc, char** argv) {
ready_pid = atoi(optarg);
break;
case 'v':
verbose = 1;
++verbose;
break;
case 'w':
screen.w = atoi(optarg);
Expand Down
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern int no_init;
extern int errmsgs;
extern int redraw_on_quit;
extern int term_init_done;
extern int first_time;

/*
* Entry point.
Expand Down Expand Up @@ -422,6 +423,7 @@ quit(status)
* alternate screen, which now (since deinit) cannot be seen.
* redraw_on_quit tells us to redraw it on the main screen.
*/
first_time = 1; /* Don't print "skipping" or tildes */
repaint();
flush();
}
Expand Down

0 comments on commit 24dea15

Please sign in to comment.