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 35c5543 + fc0ea4f commit 2badb9c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 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
20 changes: 16 additions & 4 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,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 @@ -255,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 @@ -274,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 @@ -284,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: 1 addition & 1 deletion line.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ back_raw_line(curr_pos, linep, line_lenp)
*/
static int
pappstr(str)
char *str;
constant char *str;
{
while (*str != '\0')
{
Expand Down

0 comments on commit 2badb9c

Please sign in to comment.