thinko: multibyte characters are not always 1 column wide

This commit is contained in:
tg 2008-05-02 18:55:37 +00:00
parent 1ed64c3e26
commit 4230cf91de
5 changed files with 19 additions and 22 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.188 2008/04/22 19:00:40 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.189 2008/05/02 18:55:35 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R33 2008/04/22
@(#)MIRBSD KSH R33 2008/05/02
description:
Check version of shell.
category: pdksh

11
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.125 2008/04/20 02:01:42 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.126 2008/05/02 18:55:35 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -59,7 +59,6 @@ static int x_command_glob(int, const char *, int, char ***);
static int x_locate_word(const char *, int, int, int *, bool *);
static int x_e_getmbc(char *);
static inline char *utf_getcpfromcols(char *, int);
/* +++ generic editing functions +++ */
@ -828,13 +827,13 @@ utf_cptradj(const char *src, const char **dst)
#define utf_ptradj(s,d) utf_cptradj((s), (const char **)(d))
#endif
static inline char *
utf_getcpfromcols(char *p, int cols)
const char *
utf_skipcols(const char *p, int cols)
{
int c = 0;
while (c < cols)
c += utf_widthadj(p, (const char **)&p);
c += utf_widthadj(p, &p);
return (p);
}
@ -1823,7 +1822,7 @@ x_goto(char *cp)
if (Flag(FUTFHACK))
while ((cp > xbuf) && ((*cp & 0xC0) == 0x80))
--cp;
if (cp < xbp || cp >= utf_getcpfromcols(xbp, x_displen)) {
if (cp < xbp || cp >= utf_skipcols(xbp, x_displen)) {
/* we are heading off screen */
xcp = cp;
x_adjust();

5
sh.h
View File

@ -96,9 +96,9 @@
#define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.212 2008/04/22 19:00:41 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.213 2008/05/02 18:55:36 tg Exp $");
#endif
#define MKSH_VERSION "R33 2008/04/22"
#define MKSH_VERSION "R33 2008/05/02"
#ifndef MKSH_INCLUDES_ONLY
@ -1228,6 +1228,7 @@ void utf_cptradj(const char *, const char **);
int utf_widthadj(const char *, const char **);
int utf_mbswidth(const char *);
int utf_wcwidth(unsigned int);
const char *utf_skipcols(const char *, int);
/* eval.c */
char *substitute(const char *, int);
char **eval(const char **, int);

7
shf.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.19 2008/04/19 22:15:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.20 2008/05/02 18:55:37 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -978,11 +978,10 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
field = 0;
if (precision > 0) {
const char *q = s;
const char *q;
nwritten += precision;
while (precision-- > 0)
utf_cptradj(q, &q);
q = utf_skipcols(s, precision);
do {
shf_putc(*s, shf);
} while (++s < q);

14
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.54 2008/04/19 22:15:06 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.55 2008/05/02 18:55:37 tg Exp $");
/*
* Variables
@ -525,14 +525,14 @@ formatstr(struct tbl *vp, const char *s)
p = (char *)alloc((psiz = nlen * /* MB_LEN_MAX */ 3 + 1), ATEMP);
if (vp->flag & (RJUST|LJUST)) {
int slen = olen, i;
int slen = olen, i = 0;
if (vp->flag & RJUST) {
const char *qq = s;
int n = 0;
for (i = 0; i < slen; ++i)
utf_widthadj(qq, &qq);
while (i < slen)
i += utf_widthadj(qq, &qq);
/* strip trailing spaces (at&t uses qq[-1] == ' ') */
while (qq > s && ksh_isspace(qq[-1])) {
--qq;
@ -550,10 +550,8 @@ formatstr(struct tbl *vp, const char *s)
memcpy(p, s, n);
s += n;
}
while (slen > vp->u2.field) {
utf_widthadj(s, &s);
--slen;
}
while (slen > vp->u2.field)
slen -= utf_widthadj(s, &s);
if (vp->u2.field - slen)
memset(p + n, (vp->flag & ZEROFIL) ? '0' : ' ',
vp->u2.field - slen);