summaryrefslogtreecommitdiff
path: root/usr.bin/less/line.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/less/line.c')
-rw-r--r--usr.bin/less/line.c53
1 files changed, 8 insertions, 45 deletions
diff --git a/usr.bin/less/line.c b/usr.bin/less/line.c
index aa1a2b834fc..123353d2121 100644
--- a/usr.bin/less/line.c
+++ b/usr.bin/less/line.c
@@ -437,44 +437,20 @@ backc(void)
wchar_t ch, prev_ch;
int i, len, width;
- i = curr - 1;
- if (utf_mode) {
- while (i >= lmargin && IS_UTF8_TRAIL(linebuf[i]))
- i--;
- }
- if (i < lmargin)
+ if ((len = mbtowc_left(&ch, linebuf + curr, curr)) <= 0)
return (0);
- if (utf_mode) {
- len = mbtowc(&ch, linebuf + i, curr - i);
- if (len == -1 || i + len < curr) {
- (void)mbtowc(NULL, NULL, MB_CUR_MAX);
- return (0);
- }
- } else
- ch = linebuf[i];
+ curr -= len;
/* This assumes that there is no '\b' in linebuf. */
- while (curr > lmargin && column > lmargin &&
- (!(attr[curr - 1] & (AT_ANSI|AT_BINARY)))) {
- curr = i--;
- if (utf_mode) {
- while (i >= lmargin && IS_UTF8_TRAIL(linebuf[i]))
- i--;
- }
- if (i < lmargin)
+ while (curr >= lmargin && column > lmargin &&
+ !(attr[curr] & (AT_ANSI|AT_BINARY))) {
+ if ((len = mbtowc_left(&prev_ch, linebuf + curr, curr)) <= 0)
prev_ch = L'\0';
- else if (utf_mode) {
- len = mbtowc(&prev_ch, linebuf + i, curr - i);
- if (len == -1 || i + len < curr) {
- (void)mbtowc(NULL, NULL, MB_CUR_MAX);
- prev_ch = L'\0';
- }
- } else
- prev_ch = linebuf[i];
width = pwidth(ch, attr[curr], prev_ch);
column -= width;
if (width > 0)
return (1);
+ curr -= len;
if (prev_ch == L'\0')
return (0);
ch = prev_ch;
@@ -554,21 +530,8 @@ store_char(LWCHAR ch, char a, char *rep, off_t pos)
}
if (w == -1) {
wchar_t prev_ch;
-
- if (utf_mode) {
- for (i = curr - 1; i >= 0; i--)
- if (!IS_UTF8_TRAIL(linebuf[i]))
- break;
- if (i >= 0) {
- w = mbtowc(&prev_ch, linebuf + i, curr - i);
- if (w == -1 || i + w < curr) {
- (void)mbtowc(NULL, NULL, MB_CUR_MAX);
- prev_ch = L' ';
- }
- } else
- prev_ch = L' ';
- } else
- prev_ch = curr > 0 ? linebuf[curr - 1] : L' ';
+ if (mbtowc_left(&prev_ch, linebuf + curr, curr) <= 0)
+ prev_ch = L' ';
w = pwidth(ch, a, prev_ch);
}