make jobs reporting deal with UTF-8 (in utf8-mode)

reported by Andrew Kudryashov, 10x
This commit is contained in:
tg
2012-02-06 17:42:24 +00:00
parent bee3bbaaf8
commit 929bc9ee9e
4 changed files with 42 additions and 23 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.514 2012/01/29 01:41:09 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.515 2012/02/06 17:42:20 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas 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: 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 $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R40 2012/01/28 @(#)MIRBSD KSH R40 2012/02/06
description: description:
Check version of shell. Check version of shell.
stdin: stdin:

6
jobs.c
View File

@ -1,7 +1,7 @@
/* $OpenBSD: jobs.c,v 1.38 2009/12/12 04:28:44 deraadt Exp $ */ /* $OpenBSD: jobs.c,v 1.38 2009/12/12 04:28:44 deraadt Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012
* Thorsten Glaser <tg@mirbsd.org> * Thorsten Glaser <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
@ -22,7 +22,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.82 2011/12/31 00:52:22 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.83 2012/02/06 17:42:23 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
#define mksh_killpg killpg #define mksh_killpg killpg
@ -43,7 +43,7 @@ struct proc {
pid_t pid; /* process id */ pid_t pid; /* process id */
int state; int state;
int status; /* wait status */ int status; /* wait status */
char command[48]; /* process command string */ char command[44]; /* process command string */
}; };
/* Notify/print flag - j_print() argument */ /* Notify/print flag - j_print() argument */

4
sh.h
View File

@ -152,9 +152,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.520 2012/01/29 01:41:15 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.521 2012/02/06 17:42:23 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2012/01/28" #define MKSH_VERSION "R40 2012/02/06"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES

43
tree.c
View File

@ -1,7 +1,8 @@
/* $OpenBSD: tree.c,v 1.19 2008/08/11 21:50:35 jaredy Exp $ */ /* $OpenBSD: tree.c,v 1.19 2008/08/11 21:50:35 jaredy Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012
* Thorsten Glaser <tg@mirbsd.org> * Thorsten Glaser <tg@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
@ -22,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.55 2011/12/31 00:27:27 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.56 2012/02/06 17:42:24 tg Exp $");
#define INDENT 8 #define INDENT 8
@ -712,24 +713,42 @@ fpFUNCTf(struct shf *shf, int i, bool isksh, const char *k, struct op *v)
void void
vistree(char *dst, size_t sz, struct op *t) vistree(char *dst, size_t sz, struct op *t)
{ {
int c; unsigned int c;
char *cp, *buf; char *cp, *buf;
size_t n;
buf = alloc(sz, ATEMP); buf = alloc(sz + 8, ATEMP);
snptreef(buf, sz, "%T", t); snptreef(buf, sz + 8, "%T", t);
cp = buf; cp = buf;
while ((c = *cp++)) { vist_loop:
if (((c & 0x60) == 0) || ((c & 0x7F) == 0x7F)) { if (UTFMODE && (n = utf_mbtowc(&c, cp)) != (size_t)-1) {
if (c == 0 || n >= sz)
/* NUL or not enough free space */
goto vist_out;
/* copy multibyte char */
sz -= n;
while (n--)
*dst++ = *cp++;
goto vist_loop;
}
if (--sz == 0 || (c = (unsigned char)(*cp++)) == 0)
/* NUL or not enough free space */
goto vist_out;
if ((c & 0x60) == 0 || (c & 0x7F) == 0x7F) {
/* C0 or C1 control character or DEL */ /* C0 or C1 control character or DEL */
if (!--sz) if (--sz == 0)
break; /* not enough free space for two chars */
goto vist_out;
*dst++ = (c & 0x80) ? '$' : '^'; *dst++ = (c & 0x80) ? '$' : '^';
c = (c & 0x7F) ^ 0x40; c = (c & 0x7F) ^ 0x40;
} else if (UTFMODE && c > 0x7F) {
/* better not try to display broken multibyte chars */
c = '?';
} }
if (!--sz)
break;
*dst++ = c; *dst++ = c;
} goto vist_loop;
vist_out:
*dst = '\0'; *dst = '\0';
afree(buf, ATEMP); afree(buf, ATEMP);
} }