From 195a0afd02cd8c02d0984a7d544dfae80b82f5a6 Mon Sep 17 00:00:00 2001 From: skimo Date: Thu, 20 Jul 2000 19:21:53 +0000 Subject: [PATCH] Make r(eplace) work on wide chars. Fix leftright mode on wide chars. Don't display half a wide char at the end of a line. --- common/key.h | 6 +++++- common/util.c | 14 +++++++++++++- vi/v_replace.c | 6 +++--- vi/vs_line.c | 10 +++++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/common/key.h b/common/key.h index 74764b6f..4d1da54e 100644 --- a/common/key.h +++ b/common/key.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: key.h,v 10.29 2000/07/19 17:05:18 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:18 $ + * $Id: key.h,v 10.30 2000/07/20 19:21:53 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:53 $ */ #include "multibyte.h" @@ -40,6 +40,8 @@ typedef u_int ARG_CHAR_T; #define INT2DISP(sp,w,wlen,n,nlen) \ sp->conv->int2disp(sp->conv, w, wlen, &n, &nlen) #define CONST +#define CHARSET(s,c,n) \ + v_charset(s,c,n) #else #define FILE2INT(sp,n,nlen,w,wlen) \ w = n, wlen = nlen @@ -52,6 +54,8 @@ typedef u_int ARG_CHAR_T; #define INT2DISP(sp,w,wlen,n,nlen) \ n = w, nlen = wlen #define CONST const +#define CHARSET(s,c,n) \ + memset(s,c,n); #endif #define ISCNTRL(ch) \ diff --git a/common/util.c b/common/util.c index be817d1f..1979148a 100644 --- a/common/util.c +++ b/common/util.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: util.c,v 10.17 2000/07/19 20:31:58 skimo Exp $ (Berkeley) $Date: 2000/07/19 20:31:58 $"; +static const char sccsid[] = "$Id: util.c,v 10.18 2000/07/20 19:21:53 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:53 $"; #endif /* not lint */ #include @@ -176,6 +176,18 @@ v_strlen(const CHAR_T *str) } /* + * PUBLIC: void * v_charset __P((CHAR_T *s, CHAR_T c, size_t n)); + */ +void * +v_charset(CHAR_T *s, CHAR_T c, size_t n) +{ + CHAR_T *ss = s; + + while (n--) *s++ = c; + return ss; +} + +/* * PUBLIC: int v_strcmp __P((const CHAR_T *s1, const CHAR_T *s2)) */ int diff --git a/vi/v_replace.c b/vi/v_replace.c index a9ebfef7..085d5137 100644 --- a/vi/v_replace.c +++ b/vi/v_replace.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: v_replace.c,v 10.21 2000/07/15 20:26:36 skimo Exp $ (Berkeley) $Date: 2000/07/15 20:26:36 $"; +static const char sccsid[] = "$Id: v_replace.c,v 10.22 2000/07/20 19:21:54 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:54 $"; #endif /* not lint */ #include @@ -146,7 +146,7 @@ next: if (v_event_get(sp, &ev, 0, 0)) /* Copy the line. */ GET_SPACE_RETW(sp, bp, blen, len); - MEMMOVEW(bp, p, len); + MEMMOVE(bp, p, len); p = bp; /* @@ -194,7 +194,7 @@ err_ret: rval = 1; rval = 0; } } else { - memset(bp + vp->m_start.cno, vip->rlast, cnt); + CHARSET(bp + vp->m_start.cno, vip->rlast, cnt); rval = db_set(sp, vp->m_start.lno, bp, len); } FREE_SPACEW(sp, bp, blen); diff --git a/vi/vs_line.c b/vi/vs_line.c index 9bf6f218..f34ad374 100644 --- a/vi/vs_line.c +++ b/vi/vs_line.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: vs_line.c,v 10.25 2000/07/19 17:05:19 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:19 $"; +static const char sccsid[] = "$Id: vs_line.c,v 10.26 2000/07/20 19:21:54 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:54 $"; #endif /* not lint */ #include @@ -258,7 +258,7 @@ empty: (void)gp->scr_addstr(sp, /* Do it the hard way, for leftright scrolling screens. */ if (O_ISSET(sp, O_LEFTRIGHT)) { for (; offset_in_line < len; ++offset_in_line) { - chlen = (ch = *(u_char *)p++) == '\t' && !list_tab ? + chlen = (ch = *(UCHAR_T *)p++) == '\t' && !list_tab ? TAB_OFF(scno) : KEY_COL(sp, ch); if ((scno += chlen) >= skip_cols) break; @@ -282,7 +282,7 @@ empty: (void)gp->scr_addstr(sp, /* Do it the hard way, for historic line-folding screens. */ else { for (; offset_in_line < len; ++offset_in_line) { - chlen = (ch = *(u_char *)p++) == '\t' && !list_tab ? + chlen = (ch = *(UCHAR_T *)p++) == '\t' && !list_tab ? TAB_OFF(scno) : KEY_COL(sp, ch); if ((scno += chlen) < cols_per_screen) continue; @@ -363,6 +363,10 @@ display: } smp->c_eboff = offset_in_line; + /* don't display half a wide character */ + if (is_partial && CHAR_WIDTH(sp, ch) > 1) + break; + /* Terminate the loop. */ offset_in_line = len; } -- 2.11.4.GIT