sprinkle tons more ord() around

this is really not funny… mksh-ng will use even more “unsigned only”
This commit is contained in:
tg 2017-05-05 22:53:32 +00:00
parent 5c72925bf3
commit 868d982efb
11 changed files with 423 additions and 412 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.791 2017/05/05 21:17:31 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.792 2017/05/05 22:53:24 tg Exp $
# -*- mode: sh -*- # -*- mode: sh -*-
#- #-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R55 2017/05/01 @(#)MIRBSD KSH R55 2017/05/05
description: description:
Check base version of full shell Check base version of full shell
stdin: stdin:

161
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.336 2017/05/05 20:36:00 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.337 2017/05/05 22:53:26 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -310,14 +310,14 @@ x_glob_hlp_add_qchar(char *cp)
* empirically made list of chars to escape * empirically made list of chars to escape
* for globbing as well as QCHAR itself * for globbing as well as QCHAR itself
*/ */
switch (ch) { switch (ord(ch)) {
case QCHAR: case QCHAR:
case '$': case ord('$'):
case '*': case ord('*'):
case '?': case ord('?'):
case '[': case ord('['):
case '\\': case ord('\\'):
case '`': case ord('`'):
*dp++ = QCHAR; *dp++ = QCHAR;
break; break;
} }
@ -650,10 +650,11 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp,
if (*s == '\\' && s[1]) if (*s == '\\' && s[1])
s++; s++;
else if (ctype(*s, C_QUEST | C_DOLAR) || else if (ctype(*s, C_QUEST | C_DOLAR) ||
*s == '*' || *s == '[' || ord(*s) == ord('*') || ord(*s) == ord('[') ||
/* ?() *() +() @() !() but two already checked */ /* ?() *() +() @() !() but two already checked */
(s[1] == '(' /*)*/ && (ord(s[1]) == ord('(' /*)*/) &&
(*s == '+' || *s == '@' || *s == '!'))) { (ord(*s) == ord('+') || ord(*s) == ord('@') ||
ord(*s) == ord('!')))) {
/* /*
* just expand based on the extglob * just expand based on the extglob
* or parameter * or parameter
@ -4119,14 +4120,14 @@ vi_cmd(int argcnt, const char *cmd)
lastac = argcnt; lastac = argcnt;
memmove(lastcmd, cmd, MAXVICMD); memmove(lastcmd, cmd, MAXVICMD);
} }
switch (*cmd) { switch (ord(*cmd)) {
case CTRL_L: case CTRL_L:
case CTRL_R: case CTRL_R:
redraw_line(true); redraw_line(true);
break; break;
case '@': case ord('@'):
{ {
static char alias[] = "_\0"; static char alias[] = "_\0";
struct tbl *ap; struct tbl *ap;
@ -4167,7 +4168,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case 'a': case ord('a'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
if (vs->linelen != 0) if (vs->linelen != 0)
@ -4175,7 +4176,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case 'A': case ord('A'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
del_range(0, 0); del_range(0, 0);
@ -4183,7 +4184,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case 'S': case ord('S'):
vs->cursor = domove(1, "^", 1); vs->cursor = domove(1, "^", 1);
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
modified = 1; modified = 1;
@ -4191,14 +4192,14 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case 'Y': case ord('Y'):
cmd = "y$"; cmd = "y$";
/* ahhhhhh... */ /* ahhhhhh... */
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'c': case ord('c'):
case 'd': case ord('d'):
case 'y': case ord('y'):
if (*cmd == cmd[1]) { if (*cmd == cmd[1]) {
c1 = *cmd == 'c' ? domove(1, "^", 1) : 0; c1 = *cmd == 'c' ? domove(1, "^", 1) : 0;
c2 = vs->linelen; c2 = vs->linelen;
@ -4237,7 +4238,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case 'p': case ord('p'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
if (vs->linelen != 0) if (vs->linelen != 0)
@ -4251,7 +4252,7 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
break; break;
case 'P': case ord('P'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
any = 0; any = 0;
@ -4264,25 +4265,25 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
break; break;
case 'C': case ord('C'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
insert = INSERT; insert = INSERT;
break; break;
case 'D': case ord('D'):
yank_range(vs->cursor, vs->linelen); yank_range(vs->cursor, vs->linelen);
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
if (vs->cursor != 0) if (vs->cursor != 0)
vs->cursor--; vs->cursor--;
break; break;
case 'g': case ord('g'):
if (!argcnt) if (!argcnt)
argcnt = hlast; argcnt = hlast;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'G': case ord('G'):
if (!argcnt) if (!argcnt)
argcnt = 1; argcnt = 1;
else else
@ -4295,21 +4296,21 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case 'i': case ord('i'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
insert = INSERT; insert = INSERT;
break; break;
case 'I': case ord('I'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
vs->cursor = domove(1, "^", 1); vs->cursor = domove(1, "^", 1);
insert = INSERT; insert = INSERT;
break; break;
case 'j': case ord('j'):
case '+': case ord('+'):
case CTRL_N: case CTRL_N:
if (grabhist(modified, hnum + argcnt) < 0) if (grabhist(modified, hnum + argcnt) < 0)
return (-1); return (-1);
@ -4319,8 +4320,8 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case 'k': case ord('k'):
case '-': case ord('-'):
case CTRL_P: case CTRL_P:
if (grabhist(modified, hnum - argcnt) < 0) if (grabhist(modified, hnum - argcnt) < 0)
return (-1); return (-1);
@ -4330,7 +4331,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case 'r': case ord('r'):
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
modified = 1; modified = 1;
@ -4348,13 +4349,13 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case 'R': case ord('R'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
insert = REPLACE; insert = REPLACE;
break; break;
case 's': case ord('s'):
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
modified = 1; modified = 1;
@ -4365,7 +4366,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case 'v': case ord('v'):
if (!argcnt) { if (!argcnt) {
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
@ -4388,7 +4389,7 @@ vi_cmd(int argcnt, const char *cmd)
vs->linelen = strlen(vs->cbuf); vs->linelen = strlen(vs->cbuf);
return (2); return (2);
case 'x': case ord('x'):
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
modified = 1; modified = 1;
@ -4399,7 +4400,7 @@ vi_cmd(int argcnt, const char *cmd)
del_range(vs->cursor, vs->cursor + argcnt); del_range(vs->cursor, vs->cursor + argcnt);
break; break;
case 'X': case ord('X'):
if (vs->cursor > 0) { if (vs->cursor > 0) {
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
@ -4412,13 +4413,13 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
break; break;
case 'u': case ord('u'):
t = vs; t = vs;
vs = undo; vs = undo;
undo = t; undo = t;
break; break;
case 'U': case ord('U'):
if (!modified) if (!modified)
return (-1); return (-1);
if (grabhist(modified, ohnum) < 0) if (grabhist(modified, ohnum) < 0)
@ -4427,19 +4428,19 @@ vi_cmd(int argcnt, const char *cmd)
hnum = ohnum; hnum = ohnum;
break; break;
case '?': case ord('?'):
if (hnum == hlast) if (hnum == hlast)
hnum = -1; hnum = -1;
/* ahhh */ /* ahhh */
/* FALLTHROUGH */ /* FALLTHROUGH */
case '/': case ord('/'):
c3 = 1; c3 = 1;
srchlen = 0; srchlen = 0;
lastsearch = *cmd; lastsearch = *cmd;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 'n': case ord('n'):
case 'N': case ord('N'):
if (lastsearch == ' ') if (lastsearch == ' ')
return (-1); return (-1);
if (lastsearch == '?') if (lastsearch == '?')
@ -4466,7 +4467,7 @@ vi_cmd(int argcnt, const char *cmd)
return (0); return (0);
} }
break; break;
case '_': case ord('_'):
{ {
bool inspace; bool inspace;
char *p, *sp; char *p, *sp;
@ -4518,7 +4519,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case '~': case ord('~'):
{ {
char *p; char *p;
int i; int i;
@ -4542,7 +4543,7 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
} }
case '#': case ord('#'):
{ {
int ret = x_do_comment(vs->cbuf, vs->cbufsize, int ret = x_do_comment(vs->cbuf, vs->cbufsize,
&vs->linelen); &vs->linelen);
@ -4552,7 +4553,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
/* AT&T ksh */ /* AT&T ksh */
case '=': case ord('='):
/* Nonstandard vi/ksh */ /* Nonstandard vi/ksh */
case CTRL_E: case CTRL_E:
print_expansions(vs, 1); print_expansions(vs, 1);
@ -4572,7 +4573,7 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
/* FALLTHROUGH */ /* FALLTHROUGH */
/* AT&T ksh */ /* AT&T ksh */
case '\\': case ord('\\'):
/* Nonstandard vi/ksh */ /* Nonstandard vi/ksh */
case CTRL_F: case CTRL_F:
complete_word(1, argcnt); complete_word(1, argcnt);
@ -4580,7 +4581,7 @@ vi_cmd(int argcnt, const char *cmd)
/* AT&T ksh */ /* AT&T ksh */
case '*': case ord('*'):
/* Nonstandard vi/ksh */ /* Nonstandard vi/ksh */
case CTRL_X: case CTRL_X:
expand_word(1); expand_word(1);
@ -4588,8 +4589,8 @@ vi_cmd(int argcnt, const char *cmd)
/* mksh: cursor movement */ /* mksh: cursor movement */
case '[': case ord('['):
case 'O': case ord('O'):
state = VPREFIX2; state = VPREFIX2;
if (vs->linelen != 0) if (vs->linelen != 0)
vs->cursor++; vs->cursor++;
@ -4608,20 +4609,20 @@ domove(int argcnt, const char *cmd, int sub)
int ncursor = 0, i = 0, t; int ncursor = 0, i = 0, t;
unsigned int bcount; unsigned int bcount;
switch (*cmd) { switch (ord(*cmd)) {
case 'b': case ord('b'):
if (!sub && vs->cursor == 0) if (!sub && vs->cursor == 0)
return (-1); return (-1);
ncursor = backword(argcnt); ncursor = backword(argcnt);
break; break;
case 'B': case ord('B'):
if (!sub && vs->cursor == 0) if (!sub && vs->cursor == 0)
return (-1); return (-1);
ncursor = Backword(argcnt); ncursor = Backword(argcnt);
break; break;
case 'e': case ord('e'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = endword(argcnt); ncursor = endword(argcnt);
@ -4629,7 +4630,7 @@ domove(int argcnt, const char *cmd, int sub)
ncursor++; ncursor++;
break; break;
case 'E': case ord('E'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = Endword(argcnt); ncursor = Endword(argcnt);
@ -4637,15 +4638,15 @@ domove(int argcnt, const char *cmd, int sub)
ncursor++; ncursor++;
break; break;
case 'f': case ord('f'):
case 'F': case ord('F'):
case 't': case ord('t'):
case 'T': case ord('T'):
fsavecmd = *cmd; fsavecmd = *cmd;
fsavech = cmd[1]; fsavech = cmd[1];
/* FALLTHROUGH */ /* FALLTHROUGH */
case ',': case ord(','):
case ';': case ord(';'):
if (fsavecmd == ' ') if (fsavecmd == ' ')
return (-1); return (-1);
i = ksh_eq(fsavecmd, 'F', 'f'); i = ksh_eq(fsavecmd, 'F', 'f');
@ -4659,7 +4660,7 @@ domove(int argcnt, const char *cmd, int sub)
ncursor++; ncursor++;
break; break;
case 'h': case ord('h'):
case CTRL_H: case CTRL_H:
if (!sub && vs->cursor == 0) if (!sub && vs->cursor == 0)
return (-1); return (-1);
@ -4668,8 +4669,8 @@ domove(int argcnt, const char *cmd, int sub)
ncursor = 0; ncursor = 0;
break; break;
case ' ': case ord(' '):
case 'l': case ord('l'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
if (vs->linelen != 0) { if (vs->linelen != 0) {
@ -4679,30 +4680,30 @@ domove(int argcnt, const char *cmd, int sub)
} }
break; break;
case 'w': case ord('w'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = forwword(argcnt); ncursor = forwword(argcnt);
break; break;
case 'W': case ord('W'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = Forwword(argcnt); ncursor = Forwword(argcnt);
break; break;
case '0': case ord('0'):
ncursor = 0; ncursor = 0;
break; break;
case '^': case ord('^'):
ncursor = 0; ncursor = 0;
while (ncursor < vs->linelen - 1 && while (ncursor < vs->linelen - 1 &&
ctype(vs->cbuf[ncursor], C_SPACE)) ctype(vs->cbuf[ncursor], C_SPACE))
ncursor++; ncursor++;
break; break;
case '|': case ord('|'):
ncursor = argcnt; ncursor = argcnt;
if (ncursor > vs->linelen) if (ncursor > vs->linelen)
ncursor = vs->linelen; ncursor = vs->linelen;
@ -4710,14 +4711,14 @@ domove(int argcnt, const char *cmd, int sub)
ncursor--; ncursor--;
break; break;
case '$': case ord('$'):
if (vs->linelen != 0) if (vs->linelen != 0)
ncursor = vs->linelen; ncursor = vs->linelen;
else else
ncursor = 0; ncursor = 0;
break; break;
case '%': case ord('%'):
ncursor = vs->cursor; ncursor = vs->cursor;
while (ncursor < vs->linelen && while (ncursor < vs->linelen &&
(i = bracktype(vs->cbuf[ncursor])) == 0) (i = bracktype(vs->cbuf[ncursor])) == 0)
@ -4772,24 +4773,24 @@ yank_range(int a, int b)
static int static int
bracktype(int ch) bracktype(int ch)
{ {
switch (ch) { switch (ord(ch)) {
case '(': case ord('('):
return (1); return (1);
case '[': case ord('['):
return (2); return (2);
case '{': case ord('{'):
return (3); return (3);
case ')': case ord(')'):
return (-1); return (-1);
case ']': case ord(']'):
return (-2); return (-2);
case '}': case ord('}'):
return (-3); return (-3);
default: default:

61
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.213 2017/05/05 20:36:01 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.214 2017/05/05 22:53:27 tg Exp $");
/* /*
* string expansion * string expansion
@ -283,18 +283,18 @@ expand(
switch (type) { switch (type) {
case XBASE: case XBASE:
/* original prefixed string */ /* original prefixed string */
c = *sp++; c = ord(*sp++);
switch (c) { switch (c) {
case EOS: case EOS:
c = 0; c = 0;
break; break;
case CHAR: case CHAR:
c = *sp++; c = ord(*sp++);
break; break;
case QCHAR: case QCHAR:
/* temporary quote */ /* temporary quote */
quote |= 2; quote |= 2;
c = *sp++; c = ord(*sp++);
break; break;
case OQUOTE: case OQUOTE:
if (word != IFS_WORD) if (word != IFS_WORD)
@ -320,21 +320,21 @@ expand(
case COMASUB: case COMASUB:
case COMSUB: case COMSUB:
*dp++ = '('; *dp++ = '(';
c = ')'; c = ord(')');
break; break;
case FUNASUB: case FUNASUB:
case FUNSUB: case FUNSUB:
case VALSUB: case VALSUB:
*dp++ = '{'; *dp++ = '{';
*dp++ = c == VALSUB ? '|' : ' '; *dp++ = c == VALSUB ? '|' : ' ';
c = '}'; c = ord('}');
break; break;
} }
while (*sp != '\0') { while (*sp != '\0') {
Xcheck(ds, dp); Xcheck(ds, dp);
*dp++ = *sp++; *dp++ = *sp++;
} }
if (c == '}') if (c == ord('}'))
*dp++ = ';'; *dp++ = ';';
*dp++ = c; *dp++ = c;
} else { } else {
@ -456,13 +456,13 @@ expand(
mid = beg + (wdscan(sp, ADELIM) - sp); mid = beg + (wdscan(sp, ADELIM) - sp);
stg = beg + (wdscan(sp, CSUBST) - sp); stg = beg + (wdscan(sp, CSUBST) - sp);
mid[-2] = EOS; mid[-2] = EOS;
if (ord(mid[-1]) == ord(/*{*/'}')) { if (ord(mid[-1]) == ord(/*{*/ '}')) {
sp += mid - beg - 1; sp += mid - beg - 1;
end = NULL; end = NULL;
} else { } else {
end = mid + end = mid +
(wdscan(mid, ADELIM) - mid); (wdscan(mid, ADELIM) - mid);
if (ord(end[-1]) != ord(/*{*/'}')) if (ord(end[-1]) != ord(/*{*/ '}'))
/* more than max delimiters */ /* more than max delimiters */
goto unwind_substsyn; goto unwind_substsyn;
end[-2] = EOS; end[-2] = EOS;
@ -506,7 +506,7 @@ expand(
p = s + (wdscan(sp, ADELIM) - sp); p = s + (wdscan(sp, ADELIM) - sp);
d = s + (wdscan(sp, CSUBST) - sp); d = s + (wdscan(sp, CSUBST) - sp);
p[-2] = EOS; p[-2] = EOS;
if (ord(p[-1]) == ord(/*{*/'}')) if (ord(p[-1]) == ord(/*{*/ '}'))
d = NULL; d = NULL;
else else
d[-2] = EOS; d[-2] = EOS;
@ -1002,11 +1002,11 @@ expand(
tilde_ok <<= 1; tilde_ok <<= 1;
/* mark any special second pass chars */ /* mark any special second pass chars */
if (!quote) if (!quote)
switch (c) { switch (ord(c)) {
case '[': case ord('['):
case '!': case ord('!'):
case '-': case ord('-'):
case ']': case ord(']'):
/* /*
* For character classes - doesn't hurt * For character classes - doesn't hurt
* to have magic !,-,]s outside of * to have magic !,-,]s outside of
@ -1014,28 +1014,29 @@ expand(
*/ */
if (f & (DOPAT | DOGLOB)) { if (f & (DOPAT | DOGLOB)) {
fdo |= DOMAGIC; fdo |= DOMAGIC;
if (c == '[') if (c == ord('['))
fdo |= f & DOGLOB; fdo |= f & DOGLOB;
*dp++ = MAGIC; *dp++ = MAGIC;
} }
break; break;
case '*': case ord('*'):
case '?': case ord('?'):
if (f & (DOPAT | DOGLOB)) { if (f & (DOPAT | DOGLOB)) {
fdo |= DOMAGIC | (f & DOGLOB); fdo |= DOMAGIC | (f & DOGLOB);
*dp++ = MAGIC; *dp++ = MAGIC;
} }
break; break;
case '{': case ord('{'):
case '}': case ord('}'):
case ',': case ord(','):
if ((f & DOBRACE) && (c == '{' /*}*/ || if ((f & DOBRACE) &&
(ord(c) == ord('{' /*}*/) ||
(fdo & DOBRACE))) { (fdo & DOBRACE))) {
fdo |= DOBRACE|DOMAGIC; fdo |= DOBRACE|DOMAGIC;
*dp++ = MAGIC; *dp++ = MAGIC;
} }
break; break;
case '=': case ord('='):
/* Note first unquoted = for ~ */ /* Note first unquoted = for ~ */
if (!(f & DOTEMP) && (!Flag(FPOSIX) || if (!(f & DOTEMP) && (!Flag(FPOSIX) ||
(f & DOASNTILDE)) && !saw_eq) { (f & DOASNTILDE)) && !saw_eq) {
@ -1043,13 +1044,13 @@ expand(
tilde_ok = 1; tilde_ok = 1;
} }
break; break;
case ':': case ord(':'):
/* : */ /* : */
/* Note unquoted : for ~ */ /* Note unquoted : for ~ */
if (!(f & DOTEMP) && (f & DOASNTILDE)) if (!(f & DOTEMP) && (f & DOASNTILDE))
tilde_ok = 1; tilde_ok = 1;
break; break;
case '~': case ord('~'):
/* /*
* tilde_ok is reset whenever * tilde_ok is reset whenever
* any of ' " $( $(( ${ } are seen. * any of ' " $( $(( ${ } are seen.
@ -1862,7 +1863,7 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
char *p = exp_start; char *p = exp_start;
/* search for open brace */ /* search for open brace */
while ((p = strchr(p, MAGIC)) && p[1] != '{' /*}*/) while ((p = strchr(p, MAGIC)) && ord(p[1]) != ord('{' /*}*/))
p += 2; p += 2;
brace_start = p; brace_start = p;
@ -1873,9 +1874,9 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
p += 2; p += 2;
while (*p && count) { while (*p && count) {
if (ISMAGIC(*p++)) { if (ISMAGIC(*p++)) {
if (*p == '{' /*}*/) if (ord(*p) == ord('{' /*}*/))
++count; ++count;
else if (*p == /*{*/ '}') else if (ord(*p) == ord(/*{*/ '}'))
--count; --count;
else if (*p == ',' && count == 1) else if (*p == ',' && count == 1)
comma = p; comma = p;
@ -1907,9 +1908,9 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
count = 1; count = 1;
for (p = brace_start + 2; p != brace_end; p++) { for (p = brace_start + 2; p != brace_end; p++) {
if (ISMAGIC(*p)) { if (ISMAGIC(*p)) {
if (*++p == '{' /*}*/) if (ord(*++p) == ord('{' /*}*/))
++count; ++count;
else if ((*p == /*{*/ '}' && --count == 0) || else if ((ord(*p) == ord(/*{*/ '}') && --count == 0) ||
(*p == ',' && count == 1)) { (*p == ',' && count == 1)) {
char *news; char *news;
int l1, l2, l3; int l1, l2, l3;

14
expr.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.97 2017/05/05 20:36:02 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/expr.c,v 1.98 2017/05/05 22:53:28 tg Exp $");
#define EXPRTOK_DEFNS #define EXPRTOK_DEFNS
#include "exprtok.h" #include "exprtok.h"
@ -558,9 +558,9 @@ exprtoken(Expr_state *es)
/* skip whitespace */ /* skip whitespace */
skip_spaces: skip_spaces:
while (ctype((c = *cp), C_SPACE)) while (ctype(ord((c = *cp)), C_SPACE))
++cp; ++cp;
if (es->tokp == es->expression && c == '#') { if (es->tokp == es->expression && c == ord('#')) {
/* expression begins with # */ /* expression begins with # */
/* switch to unsigned */ /* switch to unsigned */
es->natural = true; es->natural = true;
@ -573,9 +573,9 @@ exprtoken(Expr_state *es)
es->tok = END; es->tok = END;
else if (ctype(c, C_ALPHX)) { else if (ctype(c, C_ALPHX)) {
do { do {
c = *++cp; c = ord(*++cp);
} while (ctype(c, C_ALNUX)); } while (ctype(c, C_ALNUX));
if (c == '[') { if (c == ord('[')) {
size_t len; size_t len;
len = array_ref_len(cp); len = array_ref_len(cp);
@ -619,7 +619,7 @@ exprtoken(Expr_state *es)
#endif #endif
} else if (ctype(c, C_DIGIT)) { } else if (ctype(c, C_DIGIT)) {
while (ctype(c, C_ALNUM | C_HASH)) while (ctype(c, C_ALNUM | C_HASH))
c = *cp++; c = ord(*cp++);
strndupx(tvar, es->tokp, --cp - es->tokp, ATEMP); strndupx(tvar, es->tokp, --cp - es->tokp, ATEMP);
process_tvar: process_tvar:
es->val = tempvar(""); es->val = tempvar("");
@ -633,7 +633,7 @@ exprtoken(Expr_state *es)
} else { } else {
int i, n0; int i, n0;
for (i = 0; (n0 = opname[i][0]); i++) for (i = 0; (n0 = ord(opname[i][0])); i++)
if (c == n0 && strncmp(cp, opname[i], if (c == n0 && strncmp(cp, opname[i],
(size_t)oplen[i]) == 0) { (size_t)oplen[i]) == 0) {
es->tok = (enum token)i; es->tok = (enum token)i;

View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.349 2017/04/28 11:48:46 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.350 2017/05/05 22:53:28 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -2298,8 +2298,9 @@ c_unset(const char **wp)
size_t n; size_t n;
n = strlen(id); n = strlen(id);
if (n > 3 && id[n-3] == '[' && id[n-2] == '*' && if (n > 3 && ord(id[n - 3]) == ord('[') &&
id[n-1] == ']') { ord(id[n - 2]) == ord('*') &&
ord(id[n - 1]) == ord(']')) {
strndupx(cp, id, n - 3, ATEMP); strndupx(cp, id, n - 3, ATEMP);
id = cp; id = cp;
optc = 3; optc = 3;

233
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.238 2017/05/05 20:36:02 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.239 2017/05/05 22:53:29 tg Exp $");
/* /*
* states while lexing word * states while lexing word
@ -131,7 +131,7 @@ getsc_i(void)
} }
#if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST) #if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST)
#define getsc getsc_i #define getsc() ord(getsc_i())
#else #else
static int getsc_r(int); static int getsc_r(int);
@ -141,7 +141,7 @@ getsc_r(int c)
o_getsc_r(c); o_getsc_r(c);
} }
#define getsc() getsc_r(o_getsc()) #define getsc() ord(getsc_r(o_getsc()))
#endif #endif
#define STATE_BSIZE 8 #define STATE_BSIZE 8
@ -245,30 +245,30 @@ yylex(int cf)
while (!((c = getsc()) == 0 || while (!((c = getsc()) == 0 ||
((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) { ((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) {
if (state == SBASE && if (state == SBASE &&
subshell_nesting_type == /*{*/ '}' && subshell_nesting_type == ord(/*{*/ '}') &&
c == /*{*/ '}') c == ord(/*{*/ '}'))
/* possibly end ${ :;} */ /* possibly end ${ :;} */
break; break;
Xcheck(ws, wp); Xcheck(ws, wp);
switch (state) { switch (state) {
case SADELIM: case SADELIM:
if (c == '(') if (c == ord('('))
statep->nparen++; statep->nparen++;
else if (c == ')') else if (c == ord(')'))
statep->nparen--; statep->nparen--;
else if (statep->nparen == 0 && (c == /*{*/ '}' || else if (statep->nparen == 0 && (c == ord(/*{*/ '}') ||
c == (int)statep->ls_adelim.delimiter)) { c == (int)statep->ls_adelim.delimiter)) {
*wp++ = ADELIM; *wp++ = ADELIM;
*wp++ = c; *wp++ = c;
if (c == /*{*/ '}' || --statep->ls_adelim.num == 0) if (c == ord(/*{*/ '}') || --statep->ls_adelim.num == 0)
POP_STATE(); POP_STATE();
if (c == /*{*/ '}') if (c == ord(/*{*/ '}'))
POP_STATE(); POP_STATE();
break; break;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case SBASE: case SBASE:
if (c == '[' && (cf & CMDASN)) { if (c == ord('[') && (cf & CMDASN)) {
/* temporary */ /* temporary */
*wp = EOS; *wp = EOS;
if (is_wdvarname(Xstring(ws, wp), false)) { if (is_wdvarname(Xstring(ws, wp), false)) {
@ -303,7 +303,7 @@ yylex(int cf)
Sbase1: /* includes *(...|...) pattern (*+?@!) */ Sbase1: /* includes *(...|...) pattern (*+?@!) */
if (ctype(c, C_PATMO)) { if (ctype(c, C_PATMO)) {
c2 = getsc(); c2 = getsc();
if (c2 == '(' /*)*/ ) { if (c2 == ord('(' /*)*/)) {
*wp++ = OPAT; *wp++ = OPAT;
*wp++ = c; *wp++ = c;
PUSH_STATE(SPATTERN); PUSH_STATE(SPATTERN);
@ -314,7 +314,7 @@ yylex(int cf)
/* FALLTHROUGH */ /* FALLTHROUGH */
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */ Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
switch (c) { switch (c) {
case '\\': case ord('\\'):
getsc_qchar: getsc_qchar:
if ((c = getsc())) { if ((c = getsc())) {
/* trailing \ is lost */ /* trailing \ is lost */
@ -322,7 +322,7 @@ yylex(int cf)
*wp++ = c; *wp++ = c;
} }
break; break;
case '\'': case ord('\''):
open_ssquote_unless_heredoc: open_ssquote_unless_heredoc:
if ((cf & HEREDOC)) if ((cf & HEREDOC))
goto store_char; goto store_char;
@ -330,12 +330,12 @@ yylex(int cf)
ignore_backslash_newline++; ignore_backslash_newline++;
PUSH_STATE(SSQUOTE); PUSH_STATE(SSQUOTE);
break; break;
case '"': case ord('"'):
open_sdquote: open_sdquote:
*wp++ = OQUOTE; *wp++ = OQUOTE;
PUSH_STATE(SDQUOTE); PUSH_STATE(SDQUOTE);
break; break;
case '$': case ord('$'):
/* /*
* processing of dollar sign belongs into * processing of dollar sign belongs into
* Subst, except for those which can open * Subst, except for those which can open
@ -344,9 +344,9 @@ yylex(int cf)
subst_dollar_ex: subst_dollar_ex:
c = getsc(); c = getsc();
switch (c) { switch (c) {
case '"': case ord('"'):
goto open_sdquote; goto open_sdquote;
case '\'': case ord('\''):
goto open_sequote; goto open_sequote;
default: default:
goto SubstS; goto SubstS;
@ -358,15 +358,16 @@ yylex(int cf)
Subst: Subst:
switch (c) { switch (c) {
case '\\': case ord('\\'):
c = getsc(); c = getsc();
switch (c) { switch (c) {
case '"': case ord('"'):
if ((cf & HEREDOC)) if ((cf & HEREDOC))
goto heredocquote; goto heredocquote;
/* FALLTHROUGH */ /* FALLTHROUGH */
case '\\': case ord('\\'):
case '$': case '`': case ord('$'):
case ord('`'):
store_qchar: store_qchar:
*wp++ = QCHAR; *wp++ = QCHAR;
*wp++ = c; *wp++ = c;
@ -384,12 +385,12 @@ yylex(int cf)
break; break;
} }
break; break;
case '$': case ord('$'):
c = getsc(); c = getsc();
SubstS: SubstS:
if (c == '(') /*)*/ { if (c == ord('(' /*)*/)) {
c = getsc(); c = getsc();
if (c == '(') /*)*/ { if (c == ord('(' /*)*/)) {
*wp++ = EXPRSUB; *wp++ = EXPRSUB;
PUSH_SRETRACE(SASPAREN); PUSH_SRETRACE(SASPAREN);
statep->nparen = 2; statep->nparen = 2;
@ -406,8 +407,8 @@ yylex(int cf)
memcpy(wp, sp, cz); memcpy(wp, sp, cz);
wp += cz; wp += cz;
} }
} else if (c == '{') /*}*/ { } else if (c == ord('{' /*}*/)) {
if ((c = getsc()) == '|') { if ((c = getsc()) == ord('|')) {
/* /*
* non-subenvironment * non-subenvironment
* value substitution * value substitution
@ -424,15 +425,15 @@ yylex(int cf)
} }
ungetsc(c); ungetsc(c);
*wp++ = OSUBST; *wp++ = OSUBST;
*wp++ = '{'; /*}*/ *wp++ = '{' /*}*/;
wp = get_brace_var(&ws, wp); wp = get_brace_var(&ws, wp);
c = getsc(); c = getsc();
/* allow :# and :% (ksh88 compat) */ /* allow :# and :% (ksh88 compat) */
if (c == ':') { if (c == ord(':')) {
*wp++ = CHAR; *wp++ = CHAR;
*wp++ = c; *wp++ = c;
c = getsc(); c = getsc();
if (c == ':') { if (c == ord(':')) {
*wp++ = CHAR; *wp++ = CHAR;
*wp++ = '0'; *wp++ = '0';
*wp++ = ADELIM; *wp++ = ADELIM;
@ -445,7 +446,7 @@ yylex(int cf)
break; break;
} else if (ctype(c, C_DIGIT | C_DOLAR | C_SPC) || } else if (ctype(c, C_DIGIT | C_DOLAR | C_SPC) ||
/*XXX what else? */ /*XXX what else? */
c == '('/*)*/) { c == '(' /*)*/) {
/* substring subst. */ /* substring subst. */
if (c != ' ') { if (c != ' ') {
*wp++ = CHAR; *wp++ = CHAR;
@ -464,7 +465,7 @@ yylex(int cf)
parse_adelim_slash: parse_adelim_slash:
*wp++ = CHAR; *wp++ = CHAR;
*wp++ = c; *wp++ = c;
if ((c = getsc()) == '/') { if ((c = getsc()) == ord('/')) {
*wp++ = c2; *wp++ = c2;
*wp++ = c; *wp++ = c;
} else } else
@ -478,7 +479,7 @@ yylex(int cf)
} else if (c == '@') { } else if (c == '@') {
c2 = getsc(); c2 = getsc();
ungetsc(c2); ungetsc(c2);
if (c2 == '/') { if (c2 == ord('/')) {
c2 = CHAR; c2 = CHAR;
goto parse_adelim_slash; goto parse_adelim_slash;
} }
@ -527,7 +528,7 @@ yylex(int cf)
ungetsc(c); ungetsc(c);
} }
break; break;
case '`': case ord('`'):
subst_gravis: subst_gravis:
PUSH_STATE(SBQUOTE); PUSH_STATE(SBQUOTE);
*wp++ = COMASUB; *wp++ = COMASUB;
@ -571,11 +572,11 @@ yylex(int cf)
break; break;
case SEQUOTE: case SEQUOTE:
if (c == '\'') { if (c == ord('\'')) {
POP_STATE(); POP_STATE();
*wp++ = CQUOTE; *wp++ = CQUOTE;
ignore_backslash_newline--; ignore_backslash_newline--;
} else if (c == '\\') { } else if (c == ord('\\')) {
if ((c2 = unbksl(true, getsc_i, ungetsc)) == -1) if ((c2 = unbksl(true, getsc_i, ungetsc)) == -1)
c2 = getsc(); c2 = getsc();
if (c2 == 0) if (c2 == 0)
@ -603,7 +604,7 @@ yylex(int cf)
break; break;
case SSQUOTE: case SSQUOTE:
if (c == '\'') { if (c == ord('\'')) {
POP_STATE(); POP_STATE();
if ((cf & HEREDOC) || state == SQBRACE) if ((cf & HEREDOC) || state == SQBRACE)
goto store_char; goto store_char;
@ -616,7 +617,7 @@ yylex(int cf)
break; break;
case SDQUOTE: case SDQUOTE:
if (c == '"') { if (c == ord('"')) {
POP_STATE(); POP_STATE();
*wp++ = CQUOTE; *wp++ = CQUOTE;
} else } else
@ -625,15 +626,15 @@ yylex(int cf)
/* $(( ... )) */ /* $(( ... )) */
case SASPAREN: case SASPAREN:
if (c == '(') if (c == ord('('))
statep->nparen++; statep->nparen++;
else if (c == ')') { else if (c == ord(')')) {
statep->nparen--; statep->nparen--;
if (statep->nparen == 1) { if (statep->nparen == 1) {
/* end of EXPRSUB */ /* end of EXPRSUB */
POP_SRETRACE(); POP_SRETRACE();
if ((c2 = getsc()) == /*(*/ ')') { if ((c2 = getsc()) == ord(/*(*/ ')')) {
cz = strlen(sp) - 2; cz = strlen(sp) - 2;
XcheckN(ws, wp, cz); XcheckN(ws, wp, cz);
memcpy(wp, sp + 1, cz); memcpy(wp, sp + 1, cz);
@ -665,7 +666,7 @@ yylex(int cf)
goto Sbase2; goto Sbase2;
case SQBRACE: case SQBRACE:
if (c == '\\') { if (c == ord('\\')) {
/* /*
* perform POSIX "quote removal" if the back- * perform POSIX "quote removal" if the back-
* slash is "special", i.e. same cases as the * slash is "special", i.e. same cases as the
@ -674,26 +675,26 @@ yylex(int cf)
* write QCHAR+c, otherwise CHAR+\+CHAR+c are * write QCHAR+c, otherwise CHAR+\+CHAR+c are
* emitted (in heredocquote:) * emitted (in heredocquote:)
*/ */
if ((c = getsc()) == '"' || c == '\\' || if ((c = getsc()) == ord('"') || c == ord('\\') ||
ctype(c, C_DOLAR | C_GRAVE) || c == /*{*/'}') ctype(c, C_DOLAR | C_GRAVE) || c == ord(/*{*/ '}'))
goto store_qchar; goto store_qchar;
goto heredocquote; goto heredocquote;
} }
goto common_SQBRACE; goto common_SQBRACE;
case SBRACE: case SBRACE:
if (c == '\'') if (c == ord('\''))
goto open_ssquote_unless_heredoc; goto open_ssquote_unless_heredoc;
else if (c == '\\') else if (c == ord('\\'))
goto getsc_qchar; goto getsc_qchar;
common_SQBRACE: common_SQBRACE:
if (c == '"') if (c == ord('"'))
goto open_sdquote; goto open_sdquote;
else if (c == '$') else if (c == ord('$'))
goto subst_dollar_ex; goto subst_dollar_ex;
else if (c == '`') else if (c == ord('`'))
goto subst_gravis; goto subst_gravis;
else if (c != /*{*/ '}') else if (c != ord(/*{*/ '}'))
goto store_char; goto store_char;
POP_STATE(); POP_STATE();
*wp++ = CSUBST; *wp++ = CSUBST;
@ -702,16 +703,16 @@ yylex(int cf)
/* Same as SBASE, except (,|,) treated specially */ /* Same as SBASE, except (,|,) treated specially */
case STBRACEKORN: case STBRACEKORN:
if (c == '|') if (c == ord('|'))
*wp++ = SPAT; *wp++ = SPAT;
else if (c == '(') { else if (c == ord('(')) {
*wp++ = OPAT; *wp++ = OPAT;
/* simile for @ */ /* simile for @ */
*wp++ = ' '; *wp++ = ' ';
PUSH_STATE(SPATTERN); PUSH_STATE(SPATTERN);
} else /* FALLTHROUGH */ } else /* FALLTHROUGH */
case STBRACEBOURNE: case STBRACEBOURNE:
if (c == /*{*/ '}') { if (c == ord(/*{*/ '}')) {
POP_STATE(); POP_STATE();
*wp++ = CSUBST; *wp++ = CSUBST;
*wp++ = /*{*/ '}'; *wp++ = /*{*/ '}';
@ -720,20 +721,20 @@ yylex(int cf)
break; break;
case SBQUOTE: case SBQUOTE:
if (c == '`') { if (c == ord('`')) {
*wp++ = 0; *wp++ = 0;
POP_STATE(); POP_STATE();
} else if (c == '\\') { } else if (c == ord('\\')) {
switch (c = getsc()) { switch (c = getsc()) {
case 0: case 0:
/* trailing \ is lost */ /* trailing \ is lost */
break; break;
case '$': case ord('$'):
case '`': case ord('`'):
case '\\': case ord('\\'):
*wp++ = c; *wp++ = c;
break; break;
case '"': case ord('"'):
if (statep->ls_bool) { if (statep->ls_bool) {
*wp++ = c; *wp++ = c;
break; break;
@ -754,10 +755,10 @@ yylex(int cf)
/* LETEXPR: (( ... )) */ /* LETEXPR: (( ... )) */
case SLETPAREN: case SLETPAREN:
if (c == /*(*/ ')') { if (c == ord(/*(*/ ')')) {
if (statep->nparen > 0) if (statep->nparen > 0)
--statep->nparen; --statep->nparen;
else if ((c2 = getsc()) == /*(*/ ')') { else if ((c2 = getsc()) == ord(/*(*/ ')')) {
c = 0; c = 0;
*wp++ = CQUOTE; *wp++ = CQUOTE;
goto Done; goto Done;
@ -778,10 +779,10 @@ yylex(int cf)
s->start = s->str = s->u.freeme = dp; s->start = s->str = s->u.freeme = dp;
s->next = source; s->next = source;
source = s; source = s;
ungetsc('('/*)*/); ungetsc('(' /*)*/);
return ('('/*)*/); return (ord('(' /*)*/));
} }
} else if (c == '(') } else if (c == ord('('))
/* /*
* parentheses inside quotes and * parentheses inside quotes and
* backslashes are lost, but AT&T ksh * backslashes are lost, but AT&T ksh
@ -797,26 +798,26 @@ yylex(int cf)
* $ and `...` are not to be treated specially * $ and `...` are not to be treated specially
*/ */
switch (c) { switch (c) {
case '\\': case ord('\\'):
if ((c = getsc())) { if ((c = getsc())) {
/* trailing \ is lost */ /* trailing \ is lost */
*wp++ = QCHAR; *wp++ = QCHAR;
*wp++ = c; *wp++ = c;
} }
break; break;
case '\'': case ord('\''):
goto open_ssquote_unless_heredoc; goto open_ssquote_unless_heredoc;
case '$': case ord('$'):
if ((c2 = getsc()) == '\'') { if ((c2 = getsc()) == ord('\'')) {
open_sequote: open_sequote:
*wp++ = OQUOTE; *wp++ = OQUOTE;
ignore_backslash_newline++; ignore_backslash_newline++;
PUSH_STATE(SEQUOTE); PUSH_STATE(SEQUOTE);
statep->ls_bool = false; statep->ls_bool = false;
break; break;
} else if (c2 == '"') { } else if (c2 == ord('"')) {
/* FALLTHROUGH */ /* FALLTHROUGH */
case '"': case ord('"'):
PUSH_SRETRACE(SHEREDQUOTE); PUSH_SRETRACE(SHEREDQUOTE);
break; break;
} }
@ -830,7 +831,7 @@ yylex(int cf)
/* " in << or <<- delimiter */ /* " in << or <<- delimiter */
case SHEREDQUOTE: case SHEREDQUOTE:
if (c != '"') if (c != ord('"'))
goto Subst; goto Subst;
POP_SRETRACE(); POP_SRETRACE();
dp = strnul(sp) - 1; dp = strnul(sp) - 1;
@ -843,10 +844,10 @@ yylex(int cf)
while ((c = *dp++)) { while ((c = *dp++)) {
if (c == '\\') { if (c == '\\') {
switch ((c = *dp++)) { switch ((c = *dp++)) {
case '\\': case ord('\\'):
case '"': case ord('"'):
case '$': case ord('$'):
case '`': case ord('`'):
break; break;
default: default:
*wp++ = CHAR; *wp++ = CHAR;
@ -864,12 +865,12 @@ yylex(int cf)
/* in *(...|...) pattern (*+?@!) */ /* in *(...|...) pattern (*+?@!) */
case SPATTERN: case SPATTERN:
if (c == /*(*/ ')') { if (c == ord(/*(*/ ')')) {
*wp++ = CPAT; *wp++ = CPAT;
POP_STATE(); POP_STATE();
} else if (c == '|') { } else if (c == ord('|')) {
*wp++ = SPAT; *wp++ = SPAT;
} else if (c == '(') { } else if (c == ord('(')) {
*wp++ = OPAT; *wp++ = OPAT;
/* simile for @ */ /* simile for @ */
*wp++ = ' '; *wp++ = ' ';
@ -899,7 +900,7 @@ yylex(int cf)
iop->unit = c2 == 2 ? ksh_numdig(dp[1]) : c == '<' ? 0 : 1; iop->unit = c2 == 2 ? ksh_numdig(dp[1]) : c == '<' ? 0 : 1;
if (c == '&') { if (c == '&') {
if ((c2 = getsc()) != '>') { if ((c2 = getsc()) != ord('>')) {
ungetsc(c2); ungetsc(c2);
goto no_iop; goto no_iop;
} }
@ -910,22 +911,22 @@ yylex(int cf)
c2 = getsc(); c2 = getsc();
/* <<, >>, <> are ok, >< is not */ /* <<, >>, <> are ok, >< is not */
if (c == c2 || (c == '<' && c2 == '>')) { if (c == c2 || (c == ord('<') && c2 == ord('>'))) {
iop->ioflag |= c == c2 ? iop->ioflag |= c == c2 ?
(c == '>' ? IOCAT : IOHERE) : IORDWR; (c == ord('>') ? IOCAT : IOHERE) : IORDWR;
if (iop->ioflag == IOHERE) { if (iop->ioflag == IOHERE) {
if ((c2 = getsc()) == '-') if ((c2 = getsc()) == ord('-'))
iop->ioflag |= IOSKIP; iop->ioflag |= IOSKIP;
else if (c2 == '<') else if (c2 == ord('<'))
iop->ioflag |= IOHERESTR; iop->ioflag |= IOHERESTR;
else else
ungetsc(c2); ungetsc(c2);
} }
} else if (c2 == '&') } else if (c2 == ord('&'))
iop->ioflag |= IODUP | (c == '<' ? IORDUP : 0); iop->ioflag |= IODUP | (c == ord('<') ? IORDUP : 0);
else { else {
iop->ioflag |= c == '>' ? IOWRITE : IOREAD; iop->ioflag |= c == ord('>') ? IOWRITE : IOREAD;
if (c == '>' && c2 == '|') if (c == ord('>') && c2 == ord('|'))
iop->ioflag |= IOCLOB; iop->ioflag |= IOCLOB;
else else
ungetsc(c2); ungetsc(c2);
@ -946,29 +947,30 @@ yylex(int cf)
/* free word */ /* free word */
Xfree(ws, wp); Xfree(ws, wp);
/* no word, process LEX1 character */ /* no word, process LEX1 character */
if ((c == '|') || (c == '&') || (c == ';') || (c == '('/*)*/)) { if ((c == ord('|')) || (c == ord('&')) || (c == ord(';')) ||
(c == ord('(' /*)*/))) {
if ((c2 = getsc()) == c) if ((c2 = getsc()) == c)
c = (c == ';') ? BREAK : c = (c == ord(';')) ? BREAK :
(c == '|') ? LOGOR : (c == ord('|')) ? LOGOR :
(c == '&') ? LOGAND : (c == ord('&')) ? LOGAND :
/* c == '(' ) */ MDPAREN; /* c == ord('(' )) */ MDPAREN;
else if (c == '|' && c2 == '&') else if (c == ord('|') && c2 == ord('&'))
c = COPROC; c = COPROC;
else if (c == ';' && c2 == '|') else if (c == ord(';') && c2 == ord('|'))
c = BRKEV; c = BRKEV;
else if (c == ';' && c2 == '&') else if (c == ord(';') && c2 == ord('&'))
c = BRKFT; c = BRKFT;
else else
ungetsc(c2); ungetsc(c2);
#ifndef MKSH_SMALL #ifndef MKSH_SMALL
if (c == BREAK) { if (c == BREAK) {
if ((c2 = getsc()) == '&') if ((c2 = getsc()) == ord('&'))
c = BRKEV; c = BRKEV;
else else
ungetsc(c2); ungetsc(c2);
} }
#endif #endif
} else if (c == '\n') { } else if (c == ord('\n')) {
if (cf & HEREDELIM) if (cf & HEREDELIM)
ungetsc(c); ungetsc(c);
else { else {
@ -1023,7 +1025,7 @@ yylex(int cf)
if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) && if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) &&
(!(cf & ESACONLY) || p->val.i == ESAC || (!(cf & ESACONLY) || p->val.i == ESAC ||
p->val.i == /*{*/ '}')) { p->val.i == ord(/*{*/ '}'))) {
afree(yylval.cp, ATEMP); afree(yylval.cp, ATEMP);
return (p->val.i); return (p->val.i);
} }
@ -1134,7 +1136,7 @@ readhere(struct ioword *iop)
if (!*eofp) { if (!*eofp) {
/* end of here document marker, what to do? */ /* end of here document marker, what to do? */
switch (c) { switch (c) {
case /*(*/ ')': case ord(/*(*/ ')'):
if (!subshell_nesting_type) if (!subshell_nesting_type)
/*- /*-
* not allowed outside $(...) or (...) * not allowed outside $(...) or (...)
@ -1149,7 +1151,7 @@ readhere(struct ioword *iop)
* Allow EOF here to commands without trailing * Allow EOF here to commands without trailing
* newlines (mksh -c '...') will work as well. * newlines (mksh -c '...') will work as well.
*/ */
case '\n': case ord('\n'):
/* Newline terminates here document marker */ /* Newline terminates here document marker */
goto heredoc_found_terminator; goto heredoc_found_terminator;
} }
@ -1231,7 +1233,7 @@ getsc_uu(void)
Source *s = source; Source *s = source;
int c; int c;
while ((c = *s->str++) == 0) { while ((c = ord(*s->str++)) == 0) {
/* return 0 for EOF by default */ /* return 0 for EOF by default */
s->str = NULL; s->str = NULL;
switch (s->type) { switch (s->type) {
@ -1578,30 +1580,30 @@ get_brace_var(XString *wsp, char *wp)
c2 = getsc(); c2 = getsc();
ungetsc(c2); ungetsc(c2);
if (c2 != /*{*/ '}') { if (ord(c2) != ord(/*{*/ '}')) {
ungetsc(c); ungetsc(c);
goto out; goto out;
} }
} }
goto ps_common; goto ps_common;
case PS_SAW_BANG: case PS_SAW_BANG:
switch (c) { switch (ord(c)) {
case '@': case ord('@'):
case '#': case ord('#'):
case '-': case ord('-'):
case '?': case ord('?'):
goto out; goto out;
} }
goto ps_common; goto ps_common;
case PS_INITIAL: case PS_INITIAL:
switch (c) { switch (ord(c)) {
case '%': case ord('%'):
state = PS_SAW_PERCENT; state = PS_SAW_PERCENT;
goto next; goto next;
case '#': case ord('#'):
state = PS_SAW_HASH; state = PS_SAW_HASH;
goto next; goto next;
case '!': case ord('!'):
state = PS_SAW_BANG; state = PS_SAW_BANG;
goto next; goto next;
} }
@ -1619,13 +1621,14 @@ get_brace_var(XString *wsp, char *wp)
break; break;
case PS_IDENT: case PS_IDENT:
if (!ctype(c, C_ALNUX)) { if (!ctype(c, C_ALNUX)) {
if (c == '[') { if (ord(c) == ord('[')) {
char *tmp, *p; char *tmp, *p;
if (!arraysub(&tmp)) if (!arraysub(&tmp))
yyerror("missing ]"); yyerror("missing ]");
*wp++ = c; *wp++ = c;
for (p = tmp; *p; ) { p = tmp;
while (*p) {
Xcheck(*wsp, wp); Xcheck(*wsp, wp);
*wp++ = *p++; *wp++ = *p++;
} }
@ -1673,9 +1676,9 @@ arraysub(char **strp)
c = getsc(); c = getsc();
Xcheck(ws, wp); Xcheck(ws, wp);
*wp++ = c; *wp++ = c;
if (c == '[') if (ord(c) == ord('['))
depth++; depth++;
else if (c == ']') else if (ord(c) == ord(']'))
depth--; depth--;
} while (depth > 0 && c && c != '\n'); } while (depth > 0 && c && c != '\n');

34
misc.c
View File

@ -32,7 +32,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.276 2017/05/05 19:43:52 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.277 2017/05/05 22:53:30 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@ -746,7 +746,7 @@ has_globbing(const char *pat)
/* opening pattern */ /* opening pattern */
saw_glob = true; saw_glob = true;
++nest; ++nest;
} else if (ord(c) == ord(/*(*/')')) { } else if (ord(c) == ord(/*(*/ ')')) {
/* closing pattern */ /* closing pattern */
if (nest) if (nest)
--nest; --nest;
@ -779,8 +779,8 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
sl = sc; sl = sc;
continue; continue;
} }
switch (*p++) { switch (ord(*p++)) {
case '[': case ord('['):
/* BSD cclass extension? */ /* BSD cclass extension? */
if (ISMAGIC(p[0]) && ord(p[1]) == ord('[') && if (ISMAGIC(p[0]) && ord(p[1]) == ord('[') &&
ord(p[2]) == ord(':') && ord(p[2]) == ord(':') &&
@ -808,7 +808,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0); return (0);
break; break;
case '?': case ord('?'):
if (sc == 0) if (sc == 0)
return (0); return (0);
if (UTFMODE) { if (UTFMODE) {
@ -817,7 +817,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
} }
break; break;
case '*': case ord('*'):
if (p == pe) if (p == pe)
return (1); return (1);
s--; s--;
@ -833,14 +833,14 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
*/ */
/* matches one or more times */ /* matches one or more times */
case 0x80|'+': case 0x80|ord('+'):
/* matches zero or more times */ /* matches zero or more times */
case 0x80|'*': case 0x80|ord('*'):
if (!(prest = pat_scan(p, pe, false))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
/* take care of zero matches */ /* take care of zero matches */
if (p[-1] == (0x80 | '*') && if (ord(p[-1]) == (0x80 | ord('*')) &&
do_gmatch(s, se, prest, pe, smin)) do_gmatch(s, se, prest, pe, smin))
return (1); return (1);
for (psub = p; ; psub = pnext) { for (psub = p; ; psub = pnext) {
@ -858,16 +858,16 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0); return (0);
/* matches zero or once */ /* matches zero or once */
case 0x80|'?': case 0x80|ord('?'):
/* matches one of the patterns */ /* matches one of the patterns */
case 0x80|'@': case 0x80|ord('@'):
/* simile for @ */ /* simile for @ */
case 0x80|' ': case 0x80|ord(' '):
if (!(prest = pat_scan(p, pe, false))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
/* Take care of zero matches */ /* Take care of zero matches */
if (p[-1] == (0x80 | '?') && if (ord(p[-1]) == (0x80 | ord('?')) &&
do_gmatch(s, se, prest, pe, smin)) do_gmatch(s, se, prest, pe, smin))
return (1); return (1);
for (psub = p; ; psub = pnext) { for (psub = p; ; psub = pnext) {
@ -884,7 +884,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0); return (0);
/* matches none of the patterns */ /* matches none of the patterns */
case 0x80|'!': case 0x80|ord('!'):
if (!(prest = pat_scan(p, pe, false))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
@ -1046,7 +1046,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
found = true; found = true;
/* next character is (...) */ /* next character is (...) */
} }
c = '('/*)*/; c = '(' /*)*/;
} }
} }
/* range expression? */ /* range expression? */
@ -1127,10 +1127,10 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
subc = 0; subc = 0;
} else if (c == (0x80 | ' ')) { } else if (c == (0x80 | ' ')) {
/* 0x80|' ' is plain (...) */ /* 0x80|' ' is plain (...) */
c = '('/*)*/; c = '(' /*)*/;
} else if (!ISMAGIC(c) && (c & 0x80)) { } else if (!ISMAGIC(c) && (c & 0x80)) {
c &= 0x7F; c &= 0x7F;
subc = '('/*)*/; subc = '(' /*)*/;
} }
} }
/* now do the actual range match check */ /* now do the actual range match check */

140
sh.h
View File

@ -175,9 +175,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.835 2017/05/01 19:44:16 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.836 2017/05/05 22:53:30 tg Exp $");
#endif #endif
#define MKSH_VERSION "R55 2017/05/01" #define MKSH_VERSION "R55 2017/05/05"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES
@ -259,6 +259,8 @@ typedef MKSH_TYPEDEF_SSIZE_T ssize_t;
/* EBCDIC fun */ /* EBCDIC fun */
/* see the large comment in shf.c for an EBCDIC primer */
#if defined(MKSH_FOR_Z_OS) && defined(__MVS__) && defined(__IBMC__) && defined(__CHARSET_LIB) #if defined(MKSH_FOR_Z_OS) && defined(__MVS__) && defined(__IBMC__) && defined(__CHARSET_LIB)
# if !__CHARSET_LIB && !defined(MKSH_EBCDIC) # if !__CHARSET_LIB && !defined(MKSH_EBCDIC)
# error "Please compile with Build.sh -E for EBCDIC!" # error "Please compile with Build.sh -E for EBCDIC!"
@ -2171,76 +2173,76 @@ typedef union {
#define HERES 10 /* max number of << in line */ #define HERES 10 /* max number of << in line */
#ifdef MKSH_EBCDIC #ifdef MKSH_EBCDIC
#define CTRL_AT 0x00 #define CTRL_AT (0x00U)
#define CTRL_A 0x01 #define CTRL_A (0x01U)
#define CTRL_B 0x02 #define CTRL_B (0x02U)
#define CTRL_C 0x03 #define CTRL_C (0x03U)
#define CTRL_D 0x37 #define CTRL_D (0x37U)
#define CTRL_E 0x2D #define CTRL_E (0x2DU)
#define CTRL_F 0x2E #define CTRL_F (0x2EU)
#define CTRL_G 0x2F #define CTRL_G (0x2FU)
#define CTRL_H 0x16 #define CTRL_H (0x16U)
#define CTRL_I 0x05 #define CTRL_I (0x05U)
#define CTRL_J 0x15 #define CTRL_J (0x15U)
#define CTRL_K 0x0B #define CTRL_K (0x0BU)
#define CTRL_L 0x0C #define CTRL_L (0x0CU)
#define CTRL_M 0x0D #define CTRL_M (0x0DU)
#define CTRL_N 0x0E #define CTRL_N (0x0EU)
#define CTRL_O 0x0F #define CTRL_O (0x0FU)
#define CTRL_P 0x10 #define CTRL_P (0x10U)
#define CTRL_Q 0x11 #define CTRL_Q (0x11U)
#define CTRL_R 0x12 #define CTRL_R (0x12U)
#define CTRL_S 0x13 #define CTRL_S (0x13U)
#define CTRL_T 0x3C #define CTRL_T (0x3CU)
#define CTRL_U 0x3D #define CTRL_U (0x3DU)
#define CTRL_V 0x32 #define CTRL_V (0x32U)
#define CTRL_W 0x26 #define CTRL_W (0x26U)
#define CTRL_X 0x18 #define CTRL_X (0x18U)
#define CTRL_Y 0x19 #define CTRL_Y (0x19U)
#define CTRL_Z 0x3F #define CTRL_Z (0x3FU)
#define CTRL_BO 0x27 #define CTRL_BO (0x27U)
#define CTRL_BK 0x1C #define CTRL_BK (0x1CU)
#define CTRL_BC 0x1D #define CTRL_BC (0x1DU)
#define CTRL_CA 0x1E #define CTRL_CA (0x1EU)
#define CTRL_US 0x1F #define CTRL_US (0x1FU)
#define CTRL_QM 0x07 #define CTRL_QM (0x07U)
#else #else
#define CTRL_AT 0x00 #define CTRL_AT (0x00U)
#define CTRL_A 0x01 #define CTRL_A (0x01U)
#define CTRL_B 0x02 #define CTRL_B (0x02U)
#define CTRL_C 0x03 #define CTRL_C (0x03U)
#define CTRL_D 0x04 #define CTRL_D (0x04U)
#define CTRL_E 0x05 #define CTRL_E (0x05U)
#define CTRL_F 0x06 #define CTRL_F (0x06U)
#define CTRL_G 0x07 #define CTRL_G (0x07U)
#define CTRL_H 0x08 #define CTRL_H (0x08U)
#define CTRL_I 0x09 #define CTRL_I (0x09U)
#define CTRL_J 0x0A #define CTRL_J (0x0AU)
#define CTRL_K 0x0B #define CTRL_K (0x0BU)
#define CTRL_L 0x0C #define CTRL_L (0x0CU)
#define CTRL_M 0x0D #define CTRL_M (0x0DU)
#define CTRL_N 0x0E #define CTRL_N (0x0EU)
#define CTRL_O 0x0F #define CTRL_O (0x0FU)
#define CTRL_P 0x10 #define CTRL_P (0x10U)
#define CTRL_Q 0x11 #define CTRL_Q (0x11U)
#define CTRL_R 0x12 #define CTRL_R (0x12U)
#define CTRL_S 0x13 #define CTRL_S (0x13U)
#define CTRL_T 0x14 #define CTRL_T (0x14U)
#define CTRL_U 0x15 #define CTRL_U (0x15U)
#define CTRL_V 0x16 #define CTRL_V (0x16U)
#define CTRL_W 0x17 #define CTRL_W (0x17U)
#define CTRL_X 0x18 #define CTRL_X (0x18U)
#define CTRL_Y 0x19 #define CTRL_Y (0x19U)
#define CTRL_Z 0x1A #define CTRL_Z (0x1AU)
#define CTRL_BO 0x1B #define CTRL_BO (0x1BU)
#define CTRL_BK 0x1C #define CTRL_BK (0x1CU)
#define CTRL_BC 0x1D #define CTRL_BC (0x1DU)
#define CTRL_CA 0x1E #define CTRL_CA (0x1EU)
#define CTRL_US 0x1F #define CTRL_US (0x1FU)
#define CTRL_QM 0x7F #define CTRL_QM (0x7FU)
#endif #endif
#define IDENT 64 #define IDENT 64
EXTERN Source *source; /* yyparse/yylex source */ EXTERN Source *source; /* yyparse/yylex source */
EXTERN YYSTYPE yylval; /* result from yylex */ EXTERN YYSTYPE yylval; /* result from yylex */

67
syn.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.123 2017/04/28 00:38:33 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/syn.c,v 1.124 2017/05/05 22:53:31 tg Exp $");
struct nesting_state { struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */ int start_token; /* token than began nesting (eg, FOR) */
@ -330,7 +330,7 @@ get_command(int cf, int sALIAS)
XPput(args, yylval.cp); XPput(args, yylval.cp);
break; break;
case '(' /*)*/: case ord('(' /*)*/):
if (XPsize(args) == 0 && XPsize(vars) == 1 && if (XPsize(args) == 0 && XPsize(vars) == 1 &&
is_wdvarassign(yylval.cp)) { is_wdvarassign(yylval.cp)) {
char *tcp; char *tcp;
@ -373,7 +373,7 @@ get_command(int cf, int sALIAS)
XPsize(vars) != 0) XPsize(vars) != 0)
syntaxerr(NULL); syntaxerr(NULL);
ACCEPT; ACCEPT;
musthave(/*(*/')', 0); musthave(/*(*/ ')', 0);
t = function_body(XPptrv(args)[0], t = function_body(XPptrv(args)[0],
sALIAS, false); sALIAS, false);
} }
@ -386,18 +386,18 @@ get_command(int cf, int sALIAS)
Leave: Leave:
break; break;
case '(': /*)*/ { case ord('(' /*)*/): {
int subshell_nesting_type_saved; int subshell_nesting_type_saved;
Subshell: Subshell:
subshell_nesting_type_saved = subshell_nesting_type; subshell_nesting_type_saved = subshell_nesting_type;
subshell_nesting_type = ')'; subshell_nesting_type = ord(')');
t = nested(TPAREN, '(', ')', sALIAS); t = nested(TPAREN, ord('('), ord(')'), sALIAS);
subshell_nesting_type = subshell_nesting_type_saved; subshell_nesting_type = subshell_nesting_type_saved;
break; break;
} }
case '{': /*}*/ case ord('{' /*}*/):
t = nested(TBRACE, '{', '}', sALIAS); t = nested(TBRACE, ord('{'), ord('}'), sALIAS);
break; break;
case MDPAREN: case MDPAREN:
@ -407,8 +407,8 @@ get_command(int cf, int sALIAS)
switch (token(LETEXPR)) { switch (token(LETEXPR)) {
case LWORD: case LWORD:
break; break;
case '(': /*)*/ case ord('(' /*)*/):
c = '('; c = ord('(');
goto Subshell; goto Subshell;
default: default:
syntaxerr(NULL); syntaxerr(NULL);
@ -554,8 +554,8 @@ dogroup(int sALIAS)
*/ */
if (c == DO) if (c == DO)
c = DONE; c = DONE;
else if (c == '{') else if (c == ord('{'))
c = '}'; c = ord('}');
else else
syntaxerr(NULL); syntaxerr(NULL);
list = c_list(sALIAS, true); list = c_list(sALIAS, true);
@ -610,8 +610,8 @@ caselist(int sALIAS)
/* A {...} can be used instead of in...esac for case statements */ /* A {...} can be used instead of in...esac for case statements */
if (c == IN) if (c == IN)
c = ESAC; c = ESAC;
else if (c == '{') else if (c == ord('{'))
c = '}'; c = ord('}');
else else
syntaxerr(NULL); syntaxerr(NULL);
t = tl = NULL; t = tl = NULL;
@ -636,17 +636,18 @@ casepart(int endtok, int sALIAS)
XPinit(ptns, 16); XPinit(ptns, 16);
t = newtp(TPAT); t = newtp(TPAT);
/* no ALIAS here */ /* no ALIAS here */
if (token(CONTIN | KEYWORD) != '(') if (token(CONTIN | KEYWORD) != ord('('))
REJECT; REJECT;
do { do {
switch (token(0)) { switch (token(0)) {
case LWORD: case LWORD:
break; break;
case '}': case ord('}'):
case ESAC: case ESAC:
if (symbol != endtok) { if (symbol != endtok) {
strdupx(yylval.cp, strdupx(yylval.cp,
symbol == '}' ? Tcbrace : Tesac, ATEMP); symbol == ord('}') ? Tcbrace : Tesac,
ATEMP);
break; break;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -658,23 +659,23 @@ casepart(int endtok, int sALIAS)
REJECT; REJECT;
XPput(ptns, NULL); XPput(ptns, NULL);
t->vars = (char **)XPclose(ptns); t->vars = (char **)XPclose(ptns);
musthave(')', 0); musthave(ord(')'), 0);
t->left = c_list(sALIAS, true); t->left = c_list(sALIAS, true);
/* initialise to default for ;; or omitted */ /* initialise to default for ;; or omitted */
t->u.charflag = ';'; t->u.charflag = ord(';');
/* SUSv4 requires the ;; except in the last casepart */ /* SUSv4 requires the ;; except in the last casepart */
if ((tpeek(CONTIN|KEYWORD|sALIAS)) != endtok) if ((tpeek(CONTIN|KEYWORD|sALIAS)) != endtok)
switch (symbol) { switch (symbol) {
default: default:
syntaxerr(NULL); syntaxerr(NULL);
case BRKEV: case BRKEV:
t->u.charflag = '|'; t->u.charflag = ord('|');
if (0) if (0)
/* FALLTHROUGH */ /* FALLTHROUGH */
case BRKFT: case BRKFT:
t->u.charflag = '&'; t->u.charflag = ord('&');
/* FALLTHROUGH */ /* FALLTHROUGH */
case BREAK: case BREAK:
/* initialised above, but we need to eat the token */ /* initialised above, but we need to eat the token */
@ -710,14 +711,14 @@ function_body(char *name, int sALIAS,
* only accepts an open-brace. * only accepts an open-brace.
*/ */
if (ksh_func) { if (ksh_func) {
if (tpeek(CONTIN|KEYWORD|sALIAS) == '(' /*)*/) { if (tpeek(CONTIN|KEYWORD|sALIAS) == ord('(' /*)*/)) {
/* function foo () { //}*/ /* function foo () { //}*/
ACCEPT; ACCEPT;
musthave(')', 0); musthave(ord(/*(*/ ')'), 0);
/* degrade to POSIX function */ /* degrade to POSIX function */
ksh_func = false; ksh_func = false;
} }
musthave('{' /*}*/, CONTIN|KEYWORD|sALIAS); musthave(ord('{' /*}*/), CONTIN|KEYWORD|sALIAS);
REJECT; REJECT;
} }
@ -809,8 +810,8 @@ static const struct tokeninfo {
{ "in", IN, true }, { "in", IN, true },
{ Tfunction, FUNCTION, true }, { Tfunction, FUNCTION, true },
{ Ttime, TIME, true }, { Ttime, TIME, true },
{ "{", '{', true }, { "{", ord('{'), true },
{ Tcbrace, '}', true }, { Tcbrace, ord('}'), true },
{ "!", BANG, true }, { "!", BANG, true },
{ "[[", DBRACKET, true }, { "[[", DBRACKET, true },
/* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */ /* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */
@ -822,7 +823,7 @@ static const struct tokeninfo {
{ "((", MDPAREN, false }, { "((", MDPAREN, false },
{ "|&", COPROC, false }, { "|&", COPROC, false },
/* and some special cases... */ /* and some special cases... */
{ "newline", '\n', false }, { "newline", ord('\n'), false },
{ NULL, 0, false } { NULL, 0, false }
}; };
@ -997,9 +998,9 @@ dbtestp_isa(Test_env *te, Test_meta meta)
ret = (uqword && !strcmp(yylval.cp, ret = (uqword && !strcmp(yylval.cp,
dbtest_tokens[(int)TM_NOT])) ? TO_NONNULL : TO_NONOP; dbtest_tokens[(int)TM_NOT])) ? TO_NONNULL : TO_NONOP;
else if (meta == TM_OPAREN) else if (meta == TM_OPAREN)
ret = c == '(' /*)*/ ? TO_NONNULL : TO_NONOP; ret = c == ord('(') /*)*/ ? TO_NONNULL : TO_NONOP;
else if (meta == TM_CPAREN) else if (meta == TM_CPAREN)
ret = c == /*(*/ ')' ? TO_NONNULL : TO_NONOP; ret = c == /*(*/ ord(')') ? TO_NONNULL : TO_NONOP;
else if (meta == TM_UNOP || meta == TM_BINOP) { else if (meta == TM_UNOP || meta == TM_BINOP) {
if (meta == TM_BINOP && c == REDIR && if (meta == TM_BINOP && c == REDIR &&
(yylval.iop->ioflag == IOREAD || (yylval.iop->ioflag == IOREAD ||
@ -1133,11 +1134,11 @@ yyrecursive(int subtype)
int stok, etok; int stok, etok;
if (subtype != COMSUB) { if (subtype != COMSUB) {
stok = '{'; stok = ord('{');
etok = '}'; etok = ord('}');
} else { } else {
stok = '('; stok = ord('(');
etok = ')'; etok = ord(')');
} }
ys = alloc(sizeof(struct yyrecursive_state), ATEMP); ys = alloc(sizeof(struct yyrecursive_state), ATEMP);

76
tree.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.92 2017/05/05 20:36:03 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.93 2017/05/05 22:53:32 tg Exp $");
#define INDENT 8 #define INDENT 8
@ -329,34 +329,34 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
case EOS: case EOS:
return (--wp); return (--wp);
case ADELIM: case ADELIM:
if (*wp == /*{*/'}') { if (ord(*wp) == ord(/*{*/ '}')) {
++wp; ++wp;
goto wdvarput_csubst; goto wdvarput_csubst;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case CHAR: case CHAR:
c = *wp++; c = ord(*wp++);
shf_putc(c, shf); shf_putc(c, shf);
break; break;
case QCHAR: case QCHAR:
c = *wp++; c = ord(*wp++);
if (opmode & WDS_TPUTS) if (opmode & WDS_TPUTS)
switch (c) { switch (c) {
case '\n': case ord('\n'):
if (quotelevel == 0) { if (quotelevel == 0) {
c = '\''; c = ord('\'');
shf_putc(c, shf); shf_putc(c, shf);
shf_putc('\n', shf); shf_putc(ord('\n'), shf);
} }
break; break;
default: default:
if (quotelevel == 0) if (quotelevel == 0)
/* FALLTHROUGH */ /* FALLTHROUGH */
case '"': case ord('"'):
case '`': case ord('`'):
case '$': case ord('$'):
case '\\': case ord('\\'):
shf_putc('\\', shf); shf_putc(ord('\\'), shf);
break; break;
} }
shf_putc(c, shf); shf_putc(c, shf);
@ -365,7 +365,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
case COMSUB: case COMSUB:
shf_puts("$(", shf); shf_puts("$(", shf);
cs = ")"; cs = ")";
if (*wp == '(' /*)*/) if (ord(*wp) == ord('(' /*)*/))
shf_putc(' ', shf); shf_putc(' ', shf);
pSUB: pSUB:
while ((c = *wp++) != 0) while ((c = *wp++) != 0)
@ -374,11 +374,11 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
break; break;
case FUNASUB: case FUNASUB:
case FUNSUB: case FUNSUB:
c = ' '; c = ord(' ');
if (0) if (0)
/* FALLTHROUGH */ /* FALLTHROUGH */
case VALSUB: case VALSUB:
c = '|'; c = ord('|');
shf_putc('$', shf); shf_putc('$', shf);
shf_putc('{', shf); shf_putc('{', shf);
shf_putc(c, shf); shf_putc(c, shf);
@ -403,14 +403,14 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
break; break;
case OSUBST: case OSUBST:
shf_putc('$', shf); shf_putc('$', shf);
if (*wp++ == '{') if (ord(*wp++) == ord('{'))
shf_putc('{', shf); shf_putc('{', shf);
while ((c = *wp++) != 0) while ((c = *wp++) != 0)
shf_putc(c, shf); shf_putc(c, shf);
wp = wdvarput(shf, wp, 0, opmode); wp = wdvarput(shf, wp, 0, opmode);
break; break;
case CSUBST: case CSUBST:
if (*wp++ == '}') { if (ord(*wp++) == ord('}')) {
wdvarput_csubst: wdvarput_csubst:
shf_putc('}', shf); shf_putc('}', shf);
} }
@ -420,11 +420,11 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
shf_putc('(', shf); shf_putc('(', shf);
break; break;
case SPAT: case SPAT:
c = '|'; c = ord('|');
if (0) if (0)
/* FALLTHROUGH */ /* FALLTHROUGH */
case CPAT: case CPAT:
c = /*(*/ ')'; c = ord(/*(*/ ')');
shf_putc(c, shf); shf_putc(c, shf);
break; break;
} }
@ -467,39 +467,39 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
{ {
int c; int c;
while ((c = *fmt++)) { while ((c = ord(*fmt++))) {
if (c == '%') { if (c == '%') {
switch ((c = *fmt++)) { switch ((c = ord(*fmt++))) {
case 'c': case ord('c'):
/* character (octet, probably) */ /* character (octet, probably) */
shf_putchar(va_arg(va, int), shf); shf_putchar(va_arg(va, int), shf);
break; break;
case 's': case ord('s'):
/* string */ /* string */
shf_puts(va_arg(va, char *), shf); shf_puts(va_arg(va, char *), shf);
break; break;
case 'S': case ord('S'):
/* word */ /* word */
wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS); wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS);
break; break;
case 'd': case ord('d'):
/* signed decimal */ /* signed decimal */
shf_fprintf(shf, Tf_d, va_arg(va, int)); shf_fprintf(shf, Tf_d, va_arg(va, int));
break; break;
case 'u': case ord('u'):
/* unsigned decimal */ /* unsigned decimal */
shf_fprintf(shf, "%u", va_arg(va, unsigned int)); shf_fprintf(shf, "%u", va_arg(va, unsigned int));
break; break;
case 'T': case ord('T'):
/* format tree */ /* format tree */
ptree(va_arg(va, struct op *), indent, shf); ptree(va_arg(va, struct op *), indent, shf);
goto dont_trash_prevent_semicolon; goto dont_trash_prevent_semicolon;
case ';': case ord(';'):
/* newline or ; */ /* newline or ; */
case 'N': case ord('N'):
/* newline or space */ /* newline or space */
if (shf->flags & SHF_STRING) { if (shf->flags & SHF_STRING) {
if (c == ';' && !prevent_semicolon) if (c == ord(';') && !prevent_semicolon)
shf_putc(';', shf); shf_putc(';', shf);
shf_putc(' ', shf); shf_putc(' ', shf);
} else { } else {
@ -515,7 +515,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
shf_putc(' ', shf); shf_putc(' ', shf);
} }
break; break;
case 'R': case ord('R'):
/* I/O redirection */ /* I/O redirection */
pioact(shf, va_arg(va, struct ioword *)); pioact(shf, va_arg(va, struct ioword *));
break; break;
@ -613,7 +613,7 @@ wdscan(const char *wp, int c)
case ADELIM: case ADELIM:
if (c == ADELIM && nest == 0) if (c == ADELIM && nest == 0)
return (wp + 1); return (wp + 1);
if (*wp == /*{*/'}') if (ord(*wp) == ord(/*{*/ '}'))
goto wdscan_csubst; goto wdscan_csubst;
/* FALLTHROUGH */ /* FALLTHROUGH */
case CHAR: case CHAR:
@ -795,7 +795,7 @@ vistree(char *dst, size_t sz, struct op *t)
*dst++ = *cp++; *dst++ = *cp++;
goto vist_loop; goto vist_loop;
} }
if (--sz == 0 || (c = (unsigned char)(*cp++)) == 0) if (--sz == 0 || (c = ord(*cp++)) == 0)
/* NUL or not enough free space */ /* NUL or not enough free space */
goto vist_out; goto vist_out;
if (ksh_isctrl(c)) { if (ksh_isctrl(c)) {
@ -808,7 +808,7 @@ vistree(char *dst, size_t sz, struct op *t)
} else if (UTFMODE && rtt2asc(c) > 0x7F) { } else if (UTFMODE && rtt2asc(c) > 0x7F) {
/* better not try to display broken multibyte chars */ /* better not try to display broken multibyte chars */
/* also go easy on the Unicode: no U+FFFD here */ /* also go easy on the Unicode: no U+FFFD here */
c = '?'; c = ord('?');
} }
*dst++ = c; *dst++ = c;
goto vist_loop; goto vist_loop;
@ -842,7 +842,7 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel)
shf_puts("EOS", shf); shf_puts("EOS", shf);
return (--wp); return (--wp);
case ADELIM: case ADELIM:
if (*wp == /*{*/'}') { if (ord(*wp) == ord(/*{*/ '}')) {
shf_puts(/*{*/ "]ADELIM(})", shf); shf_puts(/*{*/ "]ADELIM(})", shf);
return (wp + 1); return (wp + 1);
} }
@ -855,9 +855,9 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel)
break; break;
case QCHAR: case QCHAR:
shf_puts("QCHAR<", shf); shf_puts("QCHAR<", shf);
c = *wp++; c = ord(*wp++);
if (quotelevel == 0 || c == '"' || c == '\\' || if (quotelevel == 0 || c == ord('"') ||
ctype(c, C_DOLAR | C_GRAVE)) c == ord('\\') || ctype(c, C_DOLAR | C_GRAVE))
shf_putc('\\', shf); shf_putc('\\', shf);
dumpchar(shf, c); dumpchar(shf, c);
goto closeandout; goto closeandout;

38
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.218 2017/05/05 20:36:03 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.219 2017/05/05 22:53:32 tg Exp $");
/*- /*-
* Variables * Variables
@ -204,7 +204,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
} }
innermost_refflag = SRF_NOP; innermost_refflag = SRF_NOP;
if (p != n && *p == '[' && (len = array_ref_len(p))) { if (p != n && ord(*p) == ord('[') && (len = array_ref_len(p))) {
char *sub, *tmp; char *sub, *tmp;
mksh_ari_t rval; mksh_ari_t rval;
@ -780,7 +780,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
/* no variable name given */ /* no variable name given */
return (NULL); return (NULL);
} }
if (*val == '[') { if (ord(*val) == ord('[')) {
if (new_refflag != SRF_NOP) if (new_refflag != SRF_NOP)
errorf(Tf_sD_s, var, errorf(Tf_sD_s, var,
"reference variable can't be an array"); "reference variable can't be an array");
@ -803,13 +803,13 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
} }
val += len; val += len;
} }
if (val[0] == '=') { if (ord(val[0]) == ord('=')) {
strndupx(tvar, var, val - var, ATEMP); strndupx(tvar, var, val - var, ATEMP);
++val; ++val;
} else if (set & IMPORT) { } else if (set & IMPORT) {
/* environment invalid variable name or no assignment */ /* environment invalid variable name or no assignment */
return (NULL); return (NULL);
} else if (val[0] == '+' && val[1] == '=') { } else if (ord(val[0]) == ord('+') && ord(val[1]) == ord('=')) {
strndupx(tvar, var, val - var, ATEMP); strndupx(tvar, var, val - var, ATEMP);
val += 2; val += 2;
vappend = true; vappend = true;
@ -822,8 +822,9 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
val = NULL; val = NULL;
/* handle foo[*] => foo (whole array) mapping for R39b */ /* handle foo[*] => foo (whole array) mapping for R39b */
len = strlen(tvar); len = strlen(tvar);
if (len > 3 && tvar[len - 3] == '[' && tvar[len - 2] == '*' && if (len > 3 && ord(tvar[len - 3]) == ord('[') &&
tvar[len - 1] == ']') ord(tvar[len - 2]) == ord('*') &&
ord(tvar[len - 1]) == ord(']'))
tvar[len - 3] = '\0'; tvar[len - 3] = '\0';
} }
@ -860,7 +861,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
nameref_empty: nameref_empty:
errorf(Tf_sD_s, var, "empty nameref target"); errorf(Tf_sD_s, var, "empty nameref target");
} }
len = (*ccp == '[') ? array_ref_len(ccp) : 0; len = (ord(*ccp) == ord('[')) ? array_ref_len(ccp) : 0;
if (ccp[len]) { if (ccp[len]) {
/* /*
* works for cases "no array", "valid array with * works for cases "no array", "valid array with
@ -1070,7 +1071,7 @@ skip_varname(const char *s, bool aok)
do { do {
++s; ++s;
} while (ctype(*s, C_ALNUX)); } while (ctype(*s, C_ALNUX));
if (aok && *s == '[' && (alen = array_ref_len(s))) if (aok && ord(*s) == ord('[') && (alen = array_ref_len(s)))
s += alen; s += alen;
} }
return (s); return (s);
@ -1086,7 +1087,7 @@ skip_wdvarname(const char *s,
do { do {
s += 2; s += 2;
} while (s[0] == CHAR && ctype(s[1], C_ALNUX)); } while (s[0] == CHAR && ctype(s[1], C_ALNUX));
if (aok && s[0] == CHAR && s[1] == '[') { if (aok && s[0] == CHAR && ord(s[1]) == ord('[')) {
/* skip possible array de-reference */ /* skip possible array de-reference */
const char *p = s; const char *p = s;
char c; char c;
@ -1097,9 +1098,9 @@ skip_wdvarname(const char *s,
break; break;
c = p[1]; c = p[1];
p += 2; p += 2;
if (c == '[') if (ord(c) == ord('['))
depth++; depth++;
else if (c == ']' && --depth == 0) { else if (ord(c) == ord(']') && --depth == 0) {
s = p; s = p;
break; break;
} }
@ -1527,8 +1528,8 @@ array_ref_len(const char *cp)
char c; char c;
int depth = 0; int depth = 0;
while ((c = *s++) && (c != ']' || --depth)) while ((c = *s++) && (ord(c) != ord(']') || --depth))
if (c == '[') if (ord(c) == ord('['))
depth++; depth++;
if (!c) if (!c)
return (0); return (0);
@ -1600,17 +1601,18 @@ set_array(const char *var, bool reset, const char **vals)
} }
while ((ccp = vals[i])) { while ((ccp = vals[i])) {
#if 0 /* temporarily taken out due to regression */ #if 0 /* temporarily taken out due to regression */
if (*ccp == '[') { if (ord(*ccp) == ord('[')) {
int level = 0; int level = 0;
while (*ccp) { while (*ccp) {
if (*ccp == ']' && --level == 0) if (ord(*ccp) == ord(']') && --level == 0)
break; break;
if (*ccp == '[') if (ord(*ccp) == ord('['))
++level; ++level;
++ccp; ++ccp;
} }
if (*ccp == ']' && level == 0 && ccp[1] == '=') { if (ord(*ccp) == ord(']') && level == 0 &&
ord(ccp[1]) == ord('=')) {
strndupx(cp, vals[i] + 1, ccp - (vals[i] + 1), strndupx(cp, vals[i] + 1, ccp - (vals[i] + 1),
ATEMP); ATEMP);
evaluate(substitute(cp, 0), (mksh_ari_t *)&j, evaluate(substitute(cp, 0), (mksh_ari_t *)&j,