summaryrefslogtreecommitdiff
path: root/usr.bin/less
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2019-02-26 11:01:55 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2019-02-26 11:01:55 +0000
commit555ee9dc210c327d69b5493bee594636e70c6209 (patch)
tree4ecfebcc7893d3b36540928b2c18c14daab118e6 /usr.bin/less
parent53e9bec00e25346b3912553bc6d4181a422fa229 (diff)
To simplify the upcoming UTF-8 cleanup in less(1), delete support
for ANSI escape sequences introduced by an 8-bit CSI (e.g. "\23343m") because these are neither compatible with UTF-8 nor strictly compatible with pure ASCII and for those introduced by an UTF-8 CSI (e.g. "\302\23343m") because not even xterm(1) supports them at all, not even with a non-default configuration, because both forms are very rarely used, if at all, and because the current code trying to support them doesn't even appear to work according to my tests. Full support for the ESC-[ CSI (e.g. "\033[43m") remains. Tweaks and OK millert@, OK nicm@, and sthen@ agrees with the general direction.
Diffstat (limited to 'usr.bin/less')
-rw-r--r--usr.bin/less/cvt.c2
-rw-r--r--usr.bin/less/filename.c2
-rw-r--r--usr.bin/less/less.h4
-rw-r--r--usr.bin/less/line.c22
4 files changed, 11 insertions, 19 deletions
diff --git a/usr.bin/less/cvt.c b/usr.bin/less/cvt.c
index d47ef133ede..ed7c72d69a1 100644
--- a/usr.bin/less/cvt.c
+++ b/usr.bin/less/cvt.c
@@ -77,7 +77,7 @@ cvt_text(char *odst, char *osrc, int *chpos, int *lenp, int ops)
dst--;
} while (dst > odst &&
!IS_ASCII_OCTET(*dst) && !IS_UTF8_LEAD(*dst));
- } else if ((ops & CVT_ANSI) && IS_CSI_START(ch)) {
+ } else if ((ops & CVT_ANSI) && ch == ESC) {
/* Skip to end of ANSI escape sequence. */
src++; /* skip the CSI start char */
while (src < src_end)
diff --git a/usr.bin/less/filename.c b/usr.bin/less/filename.c
index 00bf8573ce5..2e480e6445d 100644
--- a/usr.bin/less/filename.c
+++ b/usr.bin/less/filename.c
@@ -348,7 +348,7 @@ bin_file(int f)
pend = &data[n];
for (p = data; p < pend; ) {
LWCHAR c = step_char(&p, +1, pend);
- if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) {
+ if (ctldisp == OPT_ONPLUS && c == ESC) {
do {
c = step_char(&p, +1, pend);
} while (p < pend && is_ansi_middle(c));
diff --git a/usr.bin/less/less.h b/usr.bin/less/less.h
index a3a389b52af..3bd9e307201 100644
--- a/usr.bin/less/less.h
+++ b/usr.bin/less/less.h
@@ -38,8 +38,6 @@
#define IS_SPACE(c) isspace((unsigned char)(c))
#define IS_DIGIT(c) isdigit((unsigned char)(c))
-#define IS_CSI_START(c) (((LWCHAR)(c)) == ESC || (((LWCHAR)(c)) == CSI))
-
#ifndef TRUE
#define TRUE 1
#endif
@@ -151,9 +149,7 @@ struct textlist {
#define AT_INDET (1 << 7) /* Indeterminate: either bold or underline */
#define CONTROL(c) ((c)&037)
-
#define ESC CONTROL('[')
-#define CSI ((unsigned char)'\233')
#define S_INTERRUPT 01
#define S_STOP 02
diff --git a/usr.bin/less/line.c b/usr.bin/less/line.c
index c39a639fef4..e8ce55ade3e 100644
--- a/usr.bin/less/line.c
+++ b/usr.bin/less/line.c
@@ -230,7 +230,7 @@ pshift(int shift)
*/
while (shifted <= shift && from < curr) {
c = linebuf[from];
- if (ctldisp == OPT_ONPLUS && IS_CSI_START(c)) {
+ if (ctldisp == OPT_ONPLUS && c == ESC) {
/* Keep cumulative effect. */
linebuf[to] = c;
attr[to++] = attr[from++];
@@ -463,17 +463,16 @@ backc(void)
static int
in_ansi_esc_seq(void)
{
- char *p;
+ int i;
/*
* Search backwards for either an ESC (which means we ARE in a seq);
* or an end char (which means we're NOT in a seq).
*/
- for (p = &linebuf[curr]; p > linebuf; ) {
- LWCHAR ch = step_char(&p, -1, linebuf);
- if (IS_CSI_START(ch))
+ for (i = curr - 1; i >= 0; i--) {
+ if (linebuf[i] == ESC)
return (1);
- if (!is_ansi_middle(ch))
+ if (!is_ansi_middle(linebuf[i]))
return (0);
}
return (0);
@@ -533,17 +532,14 @@ store_char(LWCHAR ch, char a, char *rep, off_t pos)
if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) {
if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {
/* Remove whole unrecognized sequence. */
- char *p = &linebuf[curr];
- LWCHAR bch;
do {
- bch = step_char(&p, -1, linebuf);
- } while (p > linebuf && !IS_CSI_START(bch));
- curr = p - linebuf;
+ curr--;
+ } while (curr > 0 && linebuf[curr] != ESC);
return (0);
}
a = AT_ANSI; /* Will force re-AT_'ing around it. */
w = 0;
- } else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)) {
+ } else if (ctldisp == OPT_ONPLUS && ch == ESC) {
a = AT_ANSI; /* Will force re-AT_'ing around it. */
w = 0;
} else {
@@ -851,7 +847,7 @@ do_append(LWCHAR ch, char *rep, off_t pos)
} else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) {
do_control_char:
if (ctldisp == OPT_ON ||
- (ctldisp == OPT_ONPLUS && IS_CSI_START(ch))) {
+ (ctldisp == OPT_ONPLUS && ch == ESC)) {
/*
* Output as a normal character.
*/