summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornatano <natano@openbsd.org>2016-03-26 08:59:29 +0000
committernatano <natano@openbsd.org>2016-03-26 08:59:29 +0000
commitcaf25107394b6b4130f8174553e378f4c171a61c (patch)
tree0a3f8f6d1eb1876e8af730054a1c5a862b2ed6b4
parentremove some unused ancient test files from 4.4 BSD (diff)
downloadwireguard-openbsd-caf25107394b6b4130f8174553e378f4c171a61c.tar.xz
wireguard-openbsd-caf25107394b6b4130f8174553e378f4c171a61c.zip
Improve handling of ambiguous overstrike sequences. A sequence of _\b_
can either mean an underlined underscore or a bold underscore. This ambiguity can be 'resolved' by takeing the state of the surrounding text into account. If surrounded by bold text, the result should probably be bold and likewise for underlined. less(1) previously only looked at the preceding text and ul(1) didn't examine the context at all. tweaks and ok schwarze ok tb (on a previous version of the diff)
-rw-r--r--usr.bin/less/less.h1
-rw-r--r--usr.bin/less/line.c35
-rw-r--r--usr.bin/ul/ul.c20
3 files changed, 43 insertions, 13 deletions
diff --git a/usr.bin/less/less.h b/usr.bin/less/less.h
index a67401e9bf9..a7fe3220534 100644
--- a/usr.bin/less/less.h
+++ b/usr.bin/less/less.h
@@ -149,6 +149,7 @@ struct textlist {
#define AT_ANSI (1 << 4) /* Content-supplied "ANSI" escape sequence */
#define AT_BINARY (1 << 5) /* LESS*BINFMT representation */
#define AT_HILITE (1 << 6) /* Internal highlights (e.g., for search) */
+#define AT_INDET (1 << 7) /* Indeterminate: either bold or underline */
#define CONTROL(c) ((c)&037)
diff --git a/usr.bin/less/line.c b/usr.bin/less/line.c
index fe2fe9ff1f5..ebf4b1b5b97 100644
--- a/usr.bin/less/line.c
+++ b/usr.bin/less/line.c
@@ -32,7 +32,6 @@ off_t highest_hilite; /* Pos of last hilite in file found so far */
static int curr; /* Index into linebuf */
static int column; /* Printable length, accounting for backspaces, etc. */
static int overstrike; /* Next char should overstrike previous char */
-static int last_overstrike = AT_NORMAL;
static int is_null_line; /* There is no current line */
static int lmargin; /* Left margin */
static char pendc;
@@ -127,7 +126,6 @@ prewind(void)
column = 0;
cshift = 0;
overstrike = 0;
- last_overstrike = AT_NORMAL;
mbc_buf_len = 0;
is_null_line = 0;
pendc = '\0';
@@ -515,10 +513,6 @@ store_char(LWCHAR ch, char a, char *rep, off_t pos)
char cs;
int matches;
- w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */
- if (w != AT_NORMAL)
- last_overstrike = w;
-
if (is_hilited(pos, pos+1, 0, &matches)) {
/*
* This character should be highlighted.
@@ -808,10 +802,12 @@ do_append(LWCHAR ch, char *rep, off_t pos)
if (ch == '_') {
if ((a & (AT_BOLD|AT_UNDERLINE)) != AT_NORMAL)
a |= (AT_BOLD|AT_UNDERLINE);
- else if (last_overstrike != AT_NORMAL)
- a |= last_overstrike;
- else
+ else if (curr > 0 && attr[curr - 1] & AT_UNDERLINE)
+ a |= AT_UNDERLINE;
+ else if (curr > 0 && attr[curr - 1] & AT_BOLD)
a |= AT_BOLD;
+ else
+ a |= AT_INDET;
} else {
a |= AT_BOLD;
}
@@ -825,10 +821,13 @@ do_append(LWCHAR ch, char *rep, off_t pos)
/* Else we replace prev_ch, but we keep its attributes. */
} else if (overstrike < 0) {
if (is_composing_char(ch) ||
- is_combining_char(get_wchar(linebuf + curr), ch))
+ is_combining_char(get_wchar(linebuf + curr), ch)) {
/* Continuation of the same overstrike. */
- a = last_overstrike;
- else
+ if (curr > 0)
+ a = attr[curr - 1] & (AT_UNDERLINE | AT_BOLD);
+ else
+ a = AT_NORMAL;
+ } else
overstrike = 0;
}
@@ -894,6 +893,8 @@ pflushmbc(void)
void
pdone(int endline, int forw)
{
+ int i;
+
(void) pflushmbc();
if (pendc && (pendc != '\r' || !endline))
@@ -904,6 +905,16 @@ pdone(int endline, int forw)
*/
(void) do_append(pendc, NULL, pendpos);
+ for (i = curr - 1; i >= 0; i--) {
+ if (attr[i] & AT_INDET) {
+ attr[i] &= ~AT_INDET;
+ if (i < curr - 1 && attr[i + 1] & AT_BOLD)
+ attr[i] |= AT_BOLD;
+ else
+ attr[i] |= AT_UNDERLINE;
+ }
+ }
+
/*
* Make sure we've shifted the line, if we need to.
*/
diff --git a/usr.bin/ul/ul.c b/usr.bin/ul/ul.c
index 847d1013373..d5f894b4b61 100644
--- a/usr.bin/ul/ul.c
+++ b/usr.bin/ul/ul.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ul.c,v 1.20 2016/01/18 17:34:26 schwarze Exp $ */
+/* $OpenBSD: ul.c,v 1.21 2016/03/26 08:59:29 natano Exp $ */
/* $NetBSD: ul.c,v 1.3 1994/12/07 00:28:24 jtc Exp $ */
/*
@@ -55,6 +55,7 @@
#define SUBSC 004 /* Dim | Ul */
#define UNDERL 010 /* Ul */
#define BOLD 020 /* Bold */
+#define INDET 040 /* Indeterminate: either Bold or Ul */
int must_use_uc, must_overstrike;
char *CURS_UP, *CURS_RIGHT, *CURS_LEFT,
@@ -266,6 +267,13 @@ mfilter(FILE *f)
if (obuf[col].c_char == L'\0') {
obuf[col].c_char = L'_';
obuf[col].c_width = 1;
+ } else if (obuf[col].c_char == L'_') {
+ if (obuf[col - 1].c_mode & UNDERL)
+ obuf[col].c_mode |= UNDERL | mode;
+ else if (obuf[col - 1].c_mode & BOLD)
+ obuf[col].c_mode |= BOLD | mode;
+ else
+ obuf[col].c_mode |= INDET | mode;
} else
obuf[col].c_mode |= UNDERL | mode;
/* FALLTHROUGH */
@@ -326,6 +334,16 @@ flushln(void)
int lastmode, i;
int hadmodes = 0;
+ for (i = maxcol; i > 0; i--) {
+ if (obuf[i].c_mode & INDET) {
+ obuf[i].c_mode &= ~INDET;
+ if (i < maxcol && obuf[i + 1].c_mode & BOLD)
+ obuf[i].c_mode |= BOLD;
+ else
+ obuf[i].c_mode |= UNDERL;
+ }
+ }
+
lastmode = NORMAL;
for (i = 1; i < maxcol; i++) {
if (obuf[i].c_mode != lastmode) {