refactor c_print into a loop

This commit is contained in:
tg 2016-11-11 18:50:09 +00:00
parent 4e855b1be2
commit 4ed09871a9

21
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.307 2016/11/11 18:44:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.308 2016/11/11 18:50:09 tg Exp $");
#if HAVE_KILLPG
/*
@ -433,9 +433,11 @@ c_print(const char **wp)
Xinit(xs, xp, 128, ATEMP);
if (*wp != NULL && po.chars) {
while (*wp != NULL) {
if (po.chars) {
do {
if (!evaluate(*wp, &po.wc, KSH_RETURN_ERROR, true))
if (!evaluate(*wp, &po.wc,
KSH_RETURN_ERROR, true))
return (1);
Xcheck(xs, xp);
if (UTFMODE) {
@ -447,8 +449,7 @@ c_print(const char **wp)
} else
Xput(xs, xp, po.wc & 0xFF);
} while (*++wp);
} else if (*wp != NULL) {
print_read_arg:
} else {
s = *wp;
while ((c = *s++) != '\0') {
Xcheck(xs, xp);
@ -457,7 +458,7 @@ c_print(const char **wp)
c = unbksl(false, s_get, s_put);
s = s_ptr;
if (c == -1) {
/* rejected by generic function */
/* rejected by generic unbksl */
switch ((c = *s++)) {
case 'c':
po.nl = false;
@ -471,8 +472,9 @@ c_print(const char **wp)
Xput(xs, xp, '\\');
}
} else if ((unsigned int)c > 0xFF) {
/* generic function returned Unicode */
po.ts[utf_wctomb(po.ts, c - 0x100)] = 0;
/* unbksl returned Unicode */
po.ts[utf_wctomb(po.ts,
c - 0x100)] = 0;
c = 0;
do {
Xput(xs, xp, po.ts[c]);
@ -482,9 +484,8 @@ c_print(const char **wp)
}
Xput(xs, xp, c);
}
if (*++wp != NULL) {
if (*++wp != NULL)
Xput(xs, xp, ' ');
goto print_read_arg;
}
}
if (po.nl)