control character madness, but more compiler-friendly

This commit is contained in:
tg
2017-04-28 03:28:19 +00:00
parent 2482c8b73d
commit fba6940ba4
5 changed files with 177 additions and 107 deletions

14
tree.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.90 2017/04/28 00:38:33 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.91 2017/04/28 03:28:19 tg Exp $");
#define INDENT 8
@ -798,13 +798,13 @@ vistree(char *dst, size_t sz, struct op *t)
if (--sz == 0 || (c = (unsigned char)(*cp++)) == 0)
/* NUL or not enough free space */
goto vist_out;
if (ISCTRL(c & 0x7F)) {
if (ksh_isctrl(c)) {
/* C0 or C1 control character or DEL */
if (--sz == 0)
/* not enough free space for two chars */
goto vist_out;
*dst++ = (c & 0x80) ? '$' : '^';
c = UNCTRL(c & 0x7F);
*dst++ = '^';
c = ksh_unctrl(c);
} else if (UTFMODE && c > 0x7F) {
/* better not try to display broken multibyte chars */
/* also go easy on the Unicode: no U+FFFD here */
@ -822,10 +822,10 @@ vistree(char *dst, size_t sz, struct op *t)
void
dumpchar(struct shf *shf, int c)
{
if (ISCTRL(c & 0x7F)) {
if (ksh_isctrl(c)) {
/* C0 or C1 control character or DEL */
shf_putc((c & 0x80) ? '$' : '^', shf);
c = UNCTRL(c & 0x7F);
shf_putc('^', shf);
c = ksh_unctrl(c);
}
shf_putc(c, shf);
}