#include "sh.h"
-__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.89 2017/04/12 16:46:23 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.93 2017/05/05 22:53:32 tg Exp $");
#define INDENT 8
case EOS:
return (--wp);
case ADELIM:
- if (*wp == /*{*/'}') {
+ if (ord(*wp) == ord(/*{*/ '}')) {
++wp;
goto wdvarput_csubst;
}
/* FALLTHROUGH */
case CHAR:
- c = *wp++;
+ c = ord(*wp++);
shf_putc(c, shf);
break;
case QCHAR:
- c = *wp++;
+ c = ord(*wp++);
if (opmode & WDS_TPUTS)
switch (c) {
- case '\n':
+ case ord('\n'):
if (quotelevel == 0) {
- c = '\'';
+ c = ord('\'');
shf_putc(c, shf);
- shf_putc('\n', shf);
+ shf_putc(ord('\n'), shf);
}
break;
default:
if (quotelevel == 0)
/* FALLTHROUGH */
- case '"':
- case '`':
- case '$':
- case '\\':
- shf_putc('\\', shf);
+ case ord('"'):
+ case ord('`'):
+ case ord('$'):
+ case ord('\\'):
+ shf_putc(ord('\\'), shf);
break;
}
shf_putc(c, shf);
case COMSUB:
shf_puts("$(", shf);
cs = ")";
- if (*wp == '(' /*)*/)
+ if (ord(*wp) == ord('(' /*)*/))
shf_putc(' ', shf);
pSUB:
while ((c = *wp++) != 0)
break;
case FUNASUB:
case FUNSUB:
- c = ' ';
+ c = ord(' ');
if (0)
/* FALLTHROUGH */
case VALSUB:
- c = '|';
+ c = ord('|');
shf_putc('$', shf);
shf_putc('{', shf);
shf_putc(c, shf);
break;
case OSUBST:
shf_putc('$', shf);
- if (*wp++ == '{')
+ if (ord(*wp++) == ord('{'))
shf_putc('{', shf);
while ((c = *wp++) != 0)
shf_putc(c, shf);
wp = wdvarput(shf, wp, 0, opmode);
break;
case CSUBST:
- if (*wp++ == '}') {
+ if (ord(*wp++) == ord('}')) {
wdvarput_csubst:
shf_putc('}', shf);
}
shf_putc('(', shf);
break;
case SPAT:
- c = '|';
+ c = ord('|');
if (0)
/* FALLTHROUGH */
case CPAT:
- c = /*(*/ ')';
+ c = ord(/*(*/ ')');
shf_putc(c, shf);
break;
}
{
int c;
- while ((c = *fmt++)) {
+ while ((c = ord(*fmt++))) {
if (c == '%') {
- switch ((c = *fmt++)) {
- case 'c':
+ switch ((c = ord(*fmt++))) {
+ case ord('c'):
/* character (octet, probably) */
shf_putchar(va_arg(va, int), shf);
break;
- case 's':
+ case ord('s'):
/* string */
shf_puts(va_arg(va, char *), shf);
break;
- case 'S':
+ case ord('S'):
/* word */
wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS);
break;
- case 'd':
+ case ord('d'):
/* signed decimal */
shf_fprintf(shf, Tf_d, va_arg(va, int));
break;
- case 'u':
+ case ord('u'):
/* unsigned decimal */
shf_fprintf(shf, "%u", va_arg(va, unsigned int));
break;
- case 'T':
+ case ord('T'):
/* format tree */
ptree(va_arg(va, struct op *), indent, shf);
goto dont_trash_prevent_semicolon;
- case ';':
+ case ord(';'):
/* newline or ; */
- case 'N':
+ case ord('N'):
/* newline or space */
if (shf->flags & SHF_STRING) {
- if (c == ';' && !prevent_semicolon)
+ if (c == ord(';') && !prevent_semicolon)
shf_putc(';', shf);
shf_putc(' ', shf);
} else {
shf_putc(' ', shf);
}
break;
- case 'R':
+ case ord('R'):
/* I/O redirection */
pioact(shf, va_arg(va, struct ioword *));
break;
case ADELIM:
if (c == ADELIM && nest == 0)
return (wp + 1);
- if (*wp == /*{*/'}')
+ if (ord(*wp) == ord(/*{*/ '}'))
goto wdscan_csubst;
/* FALLTHROUGH */
case CHAR:
*dst++ = *cp++;
goto vist_loop;
}
- if (--sz == 0 || (c = (unsigned char)(*cp++)) == 0)
+ if (--sz == 0 || (c = ord(*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);
- } else if (UTFMODE && c > 0x7F) {
+ *dst++ = '^';
+ c = ksh_unctrl(c);
+ } else if (UTFMODE && rtt2asc(c) > 0x7F) {
/* better not try to display broken multibyte chars */
/* also go easy on the Unicode: no U+FFFD here */
- c = '?';
+ c = ord('?');
}
*dst++ = c;
goto vist_loop;
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);
}
shf_puts("EOS", shf);
return (--wp);
case ADELIM:
- if (*wp == /*{*/'}') {
+ if (ord(*wp) == ord(/*{*/ '}')) {
shf_puts(/*{*/ "]ADELIM(})", shf);
return (wp + 1);
}
break;
case QCHAR:
shf_puts("QCHAR<", shf);
- c = *wp++;
- if (quotelevel == 0 ||
- (c == '"' || c == '`' || c == '$' || c == '\\'))
+ c = ord(*wp++);
+ if (quotelevel == 0 || c == ord('"') ||
+ c == ord('\\') || ctype(c, C_DOLAR | C_GRAVE))
shf_putc('\\', shf);
dumpchar(shf, c);
goto closeandout;