Index: NEWS =================================================================== RCS file: /home/ncvs/src/contrib/less/NEWS,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 NEWS --- NEWS 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ NEWS 2 Oct 2007 00:21:06 -0000 @@ -13,6 +13,18 @@ ====================================================================== + Major changes between "less" versions 406 and 408 + +* Support CSI escape sequences, like SGR escape sequences. + +* Fix bug which caused screen to fail to repaint when window is resized. + +* Fix bug in using -i and -I flags with non-ASCII text. + +* Fix configure bug on systems which don't support langinfo.h. + +====================================================================== + Major changes between "less" versions 394 and 406 * Allow decimal point in number for % (percent) command. Index: README =================================================================== RCS file: /home/ncvs/src/contrib/less/README,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 README --- README 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ README 2 Oct 2007 00:21:06 -0000 @@ -1,7 +1,7 @@ - Less, version 406 + Less, version 408 - This is the distribution of less, version 406, released 19 Jun 2007. + This is the distribution of less, version 408, released 01 Oct 2007. This program is part of the GNU project (http://www.gnu.org). This program is free software. You may redistribute it and/or Index: ch.c =================================================================== RCS file: /home/ncvs/src/contrib/less/ch.c,v retrieving revision 1.1.1.5 diff -u -p -r1.1.1.5 ch.c --- ch.c 4 Jun 2007 01:42:20 -0000 1.1.1.5 +++ ch.c 2 Oct 2007 00:21:06 -0000 @@ -128,6 +128,9 @@ fch_get() POSITION pos; POSITION len; + if (thisfile == NULL) + return (EOI); + slept = FALSE; /* @@ -416,6 +419,9 @@ ch_seek(pos) BLOCKNUM new_block; POSITION len; + if (thisfile == NULL) + return (0); + len = ch_length(); if (pos < ch_zero() || (len != NULL_POSITION && pos > len)) return (1); @@ -450,6 +456,9 @@ ch_end_seek() { POSITION len; + if (thisfile == NULL) + return (0); + if (ch_flags & CH_CANSEEK) ch_fsize = filesize(ch_file); @@ -503,6 +512,8 @@ ch_beg_seek() public POSITION ch_length() { + if (thisfile == NULL) + return (NULL_POSITION); if (ignore_eoi) return (NULL_POSITION); if (ch_flags & CH_HELPFILE) @@ -516,6 +527,8 @@ ch_length() public POSITION ch_tell() { + if (thisfile == NULL) + return (NULL_POSITION); return (ch_block * LBUFSIZE) + ch_offset; } @@ -527,6 +540,8 @@ ch_forw_get() { register int c; + if (thisfile == NULL) + return (EOI); c = ch_get(); if (c == EOI) return (EOI); @@ -546,6 +561,8 @@ ch_forw_get() public int ch_back_get() { + if (thisfile == NULL) + return (EOI); if (ch_offset > 0) ch_offset --; else @@ -586,6 +603,9 @@ ch_flush() { register struct buf *bp; + if (thisfile == NULL) + return; + if (!(ch_flags & CH_CANSEEK)) { /* @@ -769,6 +789,9 @@ ch_close() { int keepstate = FALSE; + if (thisfile == NULL) + return; + if (ch_flags & (CH_CANSEEK|CH_POPENED|CH_HELPFILE)) { /* @@ -807,6 +830,8 @@ ch_close() public int ch_getflags() { + if (thisfile == NULL) + return (0); return (ch_flags); } Index: charset.c =================================================================== RCS file: /home/ncvs/src/contrib/less/charset.c,v retrieving revision 1.1.1.5 diff -u -p -r1.1.1.5 charset.c --- charset.c 4 Jun 2007 01:42:21 -0000 1.1.1.5 +++ charset.c 2 Oct 2007 00:21:06 -0000 @@ -567,24 +567,29 @@ get_wchar(p) { case 1: default: + /* 0xxxxxxx */ return (LWCHAR) (p[0] & 0xFF); case 2: + /* 110xxxxx 10xxxxxx */ return (LWCHAR) ( ((p[0] & 0x1F) << 6) | (p[1] & 0x3F)); case 3: + /* 1110xxxx 10xxxxxx 10xxxxxx */ return (LWCHAR) ( ((p[0] & 0x0F) << 12) | ((p[1] & 0x3F) << 6) | (p[2] & 0x3F)); case 4: + /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ return (LWCHAR) ( ((p[0] & 0x07) << 18) | ((p[1] & 0x3F) << 12) | ((p[2] & 0x3F) << 6) | (p[3] & 0x3F)); case 5: + /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ return (LWCHAR) ( ((p[0] & 0x03) << 24) | ((p[1] & 0x3F) << 18) | @@ -592,6 +597,7 @@ get_wchar(p) ((p[3] & 0x3F) << 6) | (p[4] & 0x3F)); case 6: + /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ return (LWCHAR) ( ((p[0] & 0x01) << 30) | ((p[1] & 0x3F) << 24) | @@ -603,6 +609,56 @@ get_wchar(p) } /* + * Store a character into a UTF-8 string. + */ + public void +put_wchar(pp, ch) + char **pp; + LWCHAR ch; +{ + if (!utf_mode || ch < 0x80) + { + /* 0xxxxxxx */ + *(*pp)++ = (char) ch; + } else if (ch < 0x800) + { + /* 110xxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xC0 | ((ch >> 6) & 0x1F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x10000) + { + /* 1110xxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xE0 | ((ch >> 12) & 0x0F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x200000) + { + /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xF0 | ((ch >> 18) & 0x07)); + *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x4000000) + { + /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xF0 | ((ch >> 24) & 0x03)); + *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } else + { + /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *(*pp)++ = (char) (0xF0 | ((ch >> 30) & 0x01)); + *(*pp)++ = (char) (0x80 | ((ch >> 24) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *(*pp)++ = (char) (0x80 | (ch & 0x3F)); + } +} + +/* * Step forward or backward one character in a string. */ public LWCHAR Index: configure =================================================================== RCS file: /home/ncvs/src/contrib/less/configure,v retrieving revision 1.1.1.6 diff -u -p -r1.1.1.6 configure --- configure 4 Jun 2007 01:42:29 -0000 1.1.1.6 +++ configure 2 Oct 2007 00:21:06 -0000 @@ -6473,6 +6473,7 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ #include #include +#include int main () { Index: configure.ac =================================================================== RCS file: /home/ncvs/src/contrib/less/configure.ac,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 configure.ac --- configure.ac 4 Jun 2007 01:42:30 -0000 1.1.1.3 +++ configure.ac 2 Oct 2007 00:21:06 -0000 @@ -304,7 +304,8 @@ fi AC_MSG_CHECKING(for locale) AC_TRY_LINK([#include -#include ], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);], +#include +#include ], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOCALE)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for ctype functions) AC_TRY_LINK([ Index: filename.c =================================================================== RCS file: /home/ncvs/src/contrib/less/filename.c,v retrieving revision 1.1.1.5 diff -u -p -r1.1.1.5 filename.c --- filename.c 4 Jun 2007 01:42:33 -0000 1.1.1.5 +++ filename.c 2 Oct 2007 00:21:06 -0000 @@ -482,7 +482,7 @@ bin_file(f) for (i = 0; i < n; i++) { char c = data[i]; - if (ctldisp == OPT_ONPLUS && c == ESC) + if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) { while (++i < n && is_ansi_middle(data[i])) continue; Index: funcs.h =================================================================== RCS file: /home/ncvs/src/contrib/less/funcs.h,v retrieving revision 1.1.1.6 diff -u -p -r1.1.1.6 funcs.h --- funcs.h 4 Jun 2007 01:42:34 -0000 1.1.1.6 +++ funcs.h 2 Oct 2007 00:21:06 -0000 @@ -56,6 +56,7 @@ public int utf_len (); public int is_utf8_well_formed (); public LWCHAR get_wchar (); + public void put_wchar (); public LWCHAR step_char (); public int is_composing_char (); public int is_ubin_char (); Index: jump.c =================================================================== RCS file: /home/ncvs/src/contrib/less/jump.c,v retrieving revision 1.1.1.4 diff -u -p -r1.1.1.4 jump.c --- jump.c 4 Jun 2007 01:42:36 -0000 1.1.1.4 +++ jump.c 2 Oct 2007 00:21:06 -0000 @@ -31,6 +31,7 @@ extern int top_scroll; jump_forw() { POSITION pos; + POSITION end_pos; if (ch_end_seek()) { @@ -42,11 +43,17 @@ jump_forw() * Go back one line from the end of the file * to get to the beginning of the last line. */ - pos = back_line(ch_tell()); + pos_clear(); + end_pos = ch_tell(); + pos = back_line(end_pos); if (pos == NULL_POSITION) jump_loc((POSITION)0, sc_height-1); else + { jump_loc(pos, sc_height-1); + if (position(sc_height-1) != end_pos) + repaint(); + } } /* Index: less.h =================================================================== RCS file: /home/ncvs/src/contrib/less/less.h,v retrieving revision 1.7 diff -u -p -r1.7 less.h --- less.h 4 Jun 2007 01:43:11 -0000 1.7 +++ less.h 2 Oct 2007 00:21:06 -0000 @@ -150,6 +150,8 @@ void free(); #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9') #endif +#define IS_CSI_START(c) ((c) == ESC || ((unsigned char)(c)) == CSI) + #ifndef NULL #define NULL 0 #endif @@ -425,6 +427,7 @@ struct textlist #endif /* IS_EBCDIC_HOST */ #define ESC CONTROL('[') +#define CSI ((unsigned char)'\233') #if _OSK_MWC32 #define LSIGNAL(sig,func) os9_signal(sig,func) Index: less.man =================================================================== RCS file: /home/ncvs/src/contrib/less/less.man,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 less.man --- less.man 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ less.man 2 Oct 2007 00:21:06 -0000 @@ -1544,4 +1544,4 @@ LESS(1) - Version 406: 19 Jun 2007 LESS(1) + Version 408: 01 Oct 2007 LESS(1) Index: less.nro =================================================================== RCS file: /home/ncvs/src/contrib/less/less.nro,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 less.nro --- less.nro 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ less.nro 2 Oct 2007 00:21:06 -0000 @@ -1,4 +1,4 @@ -.TH LESS 1 "Version 406: 19 Jun 2007" +.TH LESS 1 "Version 408: 01 Oct 2007" .SH NAME less \- opposite of more .SH SYNOPSIS Index: lessecho.man =================================================================== RCS file: /home/ncvs/src/contrib/less/lessecho.man,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 lessecho.man --- lessecho.man 21 Jun 2007 10:42:55 -0000 1.1.1.3 +++ lessecho.man 2 Oct 2007 00:21:06 -0000 @@ -46,4 +46,4 @@ LESSECHO(1) - Version 406: 19 Jun 2007 LESSECHO(1) + Version 408: 01 Oct 2007 LESSECHO(1) Index: lessecho.nro =================================================================== RCS file: /home/ncvs/src/contrib/less/lessecho.nro,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 lessecho.nro --- lessecho.nro 21 Jun 2007 10:42:55 -0000 1.1.1.3 +++ lessecho.nro 2 Oct 2007 00:21:06 -0000 @@ -1,4 +1,4 @@ -.TH LESSECHO 1 "Version 406: 19 Jun 2007" +.TH LESSECHO 1 "Version 408: 01 Oct 2007" .SH NAME lessecho \- expand metacharacters .SH SYNOPSIS Index: lesskey.man =================================================================== RCS file: /home/ncvs/src/contrib/less/lesskey.man,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 lesskey.man --- lesskey.man 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ lesskey.man 2 Oct 2007 00:21:06 -0000 @@ -357,4 +357,4 @@ LESSKEY(1) - Version 406: 19 Jun 2007 LESSKEY(1) + Version 408: 01 Oct 2007 LESSKEY(1) Index: lesskey.nro =================================================================== RCS file: /home/ncvs/src/contrib/less/lesskey.nro,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 lesskey.nro --- lesskey.nro 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ lesskey.nro 2 Oct 2007 00:21:06 -0000 @@ -1,4 +1,4 @@ -.TH LESSKEY 1 "Version 406: 19 Jun 2007" +.TH LESSKEY 1 "Version 408: 01 Oct 2007" .SH NAME lesskey \- specify key bindings for less .SH SYNOPSIS Index: line.c =================================================================== RCS file: /home/ncvs/src/contrib/less/line.c,v retrieving revision 1.4 diff -u -p -r1.4 line.c --- line.c 4 Jun 2007 01:43:11 -0000 1.4 +++ line.c 2 Oct 2007 00:21:06 -0000 @@ -269,7 +269,7 @@ pshift(shift) while (shifted <= shift && from < curr) { c = linebuf[from]; - if (c == ESC && ctldisp == OPT_ONPLUS) + if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) { /* Keep cumulative effect. */ linebuf[to] = c; @@ -524,7 +524,7 @@ in_ansi_esc_seq() for (p = &linebuf[curr]; p > linebuf; ) { LWCHAR ch = step_char(&p, -1, linebuf); - if (ch == ESC) + if (IS_CSI_START(ch)) return (1); if (!is_ansi_middle(ch)) return (0); @@ -603,13 +603,13 @@ store_char(ch, a, rep, pos) /* Remove whole unrecognized sequence. */ do { --curr; - } while (linebuf[curr] != ESC); + } while (!IS_CSI_START(linebuf[curr])); return 0; } a = AT_ANSI; /* Will force re-AT_'ing around it. */ w = 0; } - else if (ctldisp == OPT_ONPLUS && ch == ESC) + else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)) { a = AT_ANSI; /* Will force re-AT_'ing around it. */ w = 0; @@ -943,7 +943,7 @@ do_append(ch, rep, pos) } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) { do_control_char: - if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && ch == ESC)) + if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && IS_CSI_START(ch))) { /* * Output as a normal character. Index: search.c =================================================================== RCS file: /home/ncvs/src/contrib/less/search.c,v retrieving revision 1.8 diff -u -p -r1.8 search.c --- search.c 17 Jun 2007 23:20:43 -0000 1.8 +++ search.c 2 Oct 2007 00:21:06 -0000 @@ -16,6 +16,7 @@ #include "less.h" #include "position.h" +#include "charset.h" #define MINPOS(a,b) (((a) < (b)) ? (a) : (b)) #define MAXPOS(a,b) (((a) > (b)) ? (a) : (b)) @@ -120,24 +121,31 @@ cvt_text(odst, osrc, lenp, ops) int *lenp; int ops; { - register char *dst; - register char *src; + char *dst; + char *src; register char *src_end; + LWCHAR ch; if (lenp != NULL) src_end = osrc + *lenp; else src_end = osrc + strlen(osrc); - for (src = osrc, dst = odst; src < src_end; src++) + for (src = osrc, dst = odst; src < src_end; ) { - if ((ops & CVT_TO_LC) && IS_UPPER(*src)) + ch = step_char(&src, +1, src_end); + if ((ops & CVT_TO_LC) && IS_UPPER(ch)) + { /* Convert uppercase to lowercase. */ - *dst++ = TO_LOWER(*src); - else if ((ops & CVT_BS) && *src == '\b' && dst > odst) + put_wchar(&dst, TO_LOWER(ch)); + } else if ((ops & CVT_BS) && ch == '\b' && dst > odst) + { /* Delete BS and preceding char. */ - dst--; - else if ((ops & CVT_ANSI) && *src == ESC) + do { + dst--; + } while (dst > odst && + !IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst)); + } else if ((ops & CVT_ANSI) && IS_CSI_START(ch)) { /* Skip to end of ANSI escape sequence. */ while (src + 1 != src_end) @@ -145,7 +153,7 @@ cvt_text(odst, osrc, lenp, ops) break; } else /* Just copy. */ - *dst++ = *src; + put_wchar(&dst, ch); } if ((ops & CVT_CRLF) && dst > odst && dst[-1] == '\r') dst--; @@ -182,14 +190,18 @@ get_cvt_ops() * Are there any uppercase letters in this string? */ static int -is_ucase(s) - char *s; +is_ucase(str) + char *str; { - register char *p; + char *str_end = str + strlen(str); + LWCHAR ch; - for (p = s; *p != '\0'; p++) - if (IS_UPPER(*p)) + while (str < str_end) + { + ch = step_char(&str, +1, str_end); + if (IS_UPPER(ch)) return (1); + } return (0); } @@ -679,7 +691,7 @@ adj_hilite_ansi(cvt_ops, line, line_len, char *line_end = *line + line_len; if (cvt_ops & CVT_ANSI) - while (**line == ESC) + while (IS_CSI_START(**line)) { /* * Found an ESC. The file position moves Index: signal.c =================================================================== RCS file: /home/ncvs/src/contrib/less/signal.c,v retrieving revision 1.5 diff -u -p -r1.5 signal.c --- signal.c 4 Jun 2007 01:43:11 -0000 1.5 +++ signal.c 2 Oct 2007 00:21:06 -0000 @@ -93,6 +93,8 @@ winch(type) { LSIGNAL(SIGWINCH, winch); sigs |= S_WINCH; + if (reading) + intread(); } #else #ifdef SIGWIND Index: version.c =================================================================== RCS file: /home/ncvs/src/contrib/less/version.c,v retrieving revision 1.1.1.7 diff -u -p -r1.1.1.7 version.c --- version.c 21 Jun 2007 10:42:55 -0000 1.1.1.7 +++ version.c 2 Oct 2007 00:21:06 -0000 @@ -693,6 +693,8 @@ v403 5/25/07 Fix Windows build. v404 6/5/07 Fix display bug with F command and long lines. v405 6/17/07 Fix display bug when using -w option. v406 6/17/07 Fix secure build. +v407 8/16/07 Fix bugs; support CSI chars. +v408 10/1/07 Fix bug in -i with non-ASCII chars. */ -char version[] = "406"; +char version[] = "408";