fix utf_widthadj/utf_skipcols handling for the remaining cases I can spot

This commit is contained in:
tg 2016-05-05 22:56:15 +00:00
parent 3d130b606a
commit 92833fc6ce
5 changed files with 23 additions and 16 deletions

4
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.295 2016/04/14 11:51:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.296 2016/05/05 22:56:12 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -1576,7 +1576,7 @@ static void
x_goto(char *cp)
{
cp = cp >= xep ? xep : x_bs0(cp, xbuf);
if (cp < xbp || cp >= utf_skipcols(xbp, x_displen)) {
if (cp < xbp || cp >= utf_skipcols(xbp, x_displen, NULL)) {
/* we are heading off screen */
xcp = cp;
x_adjust();

15
expr.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.84 2016/05/05 21:33:46 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.85 2016/05/05 22:56:13 tg Exp $");
/* the order of these enums is constrained by the order of opinfo[] */
enum token {
@ -809,19 +809,26 @@ utf_mbswidth(const char *s)
}
const char *
utf_skipcols(const char *p, int cols)
utf_skipcols(const char *p, int cols, int *colp)
{
int c = 0;
const char *q;
while (c < cols) {
if (!*p)
return (p + cols - c);
if (!*p) {
/* end of input; special handling for edit.c */
if (!colp)
return (p + cols - c);
*colp = c;
return (p);
}
c += utf_widthadj(p, &p);
}
if (UTFMODE)
while (utf_widthadj(p, &q) == 0)
p = q;
if (colp)
*colp = c;
return (p);
}

6
sh.h
View File

@ -175,9 +175,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.770 2016/04/14 15:38:38 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.771 2016/05/05 22:56:14 tg Exp $");
#endif
#define MKSH_VERSION "R52 2016/04/14"
#define MKSH_VERSION "R52 2016/05/05"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -1756,7 +1756,7 @@ size_t utf_mbtowc(unsigned int *, const char *);
size_t utf_wctomb(char *, unsigned int);
int utf_widthadj(const char *, const char **);
size_t utf_mbswidth(const char *) MKSH_A_PURE;
const char *utf_skipcols(const char *, int) MKSH_A_PURE;
const char *utf_skipcols(const char *, int, int *);
size_t utf_ptradj(const char *) MKSH_A_PURE;
#ifdef MIRBSD_BOOTFLOPPY
#define utf_wcwidth(i) wcwidth((wchar_t)(i))

4
shf.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.72 2016/05/05 21:38:12 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.73 2016/05/05 22:56:15 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -1041,7 +1041,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
field = 0;
nwritten += precision;
precision = utf_skipcols(s, precision) - s;
precision = utf_skipcols(s, precision, &tmp) - s;
while (precision--)
shf_putc(*s++, shf);

10
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.201 2016/03/01 20:28:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.202 2016/05/05 22:56:15 tg Exp $");
/*-
* Variables
@ -649,14 +649,14 @@ formatstr(struct tbl *vp, const char *s)
p = alloc((psiz = nlen * /* MB_LEN_MAX */ 3 + 1), ATEMP);
if (vp->flag & (RJUST|LJUST)) {
int slen = olen, i = 0;
int slen = olen;
if (vp->flag & RJUST) {
const char *qq = s;
const char *qq;
int n = 0;
while (i < slen)
i += utf_widthadj(qq, &qq);
qq = utf_skipcols(s, slen, &slen);
/* strip trailing spaces (AT&T uses qq[-1] == ' ') */
while (qq > s && ksh_isspace(qq[-1])) {
--qq;