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 -*-
#-
# 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
expected-stdout:
@(#)MIRBSD KSH R55 2017/05/01
@(#)MIRBSD KSH R55 2017/05/05
description:
Check base version of full shell
stdin:

161
edit.c
View File

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

61
eval.c
View File

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

14
expr.c
View File

@ -23,7 +23,7 @@
#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
#include "exprtok.h"
@ -558,9 +558,9 @@ exprtoken(Expr_state *es)
/* skip whitespace */
skip_spaces:
while (ctype((c = *cp), C_SPACE))
while (ctype(ord((c = *cp)), C_SPACE))
++cp;
if (es->tokp == es->expression && c == '#') {
if (es->tokp == es->expression && c == ord('#')) {
/* expression begins with # */
/* switch to unsigned */
es->natural = true;
@ -573,9 +573,9 @@ exprtoken(Expr_state *es)
es->tok = END;
else if (ctype(c, C_ALPHX)) {
do {
c = *++cp;
c = ord(*++cp);
} while (ctype(c, C_ALNUX));
if (c == '[') {
if (c == ord('[')) {
size_t len;
len = array_ref_len(cp);
@ -619,7 +619,7 @@ exprtoken(Expr_state *es)
#endif
} else if (ctype(c, C_DIGIT)) {
while (ctype(c, C_ALNUM | C_HASH))
c = *cp++;
c = ord(*cp++);
strndupx(tvar, es->tokp, --cp - es->tokp, ATEMP);
process_tvar:
es->val = tempvar("");
@ -633,7 +633,7 @@ exprtoken(Expr_state *es)
} else {
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],
(size_t)oplen[i]) == 0) {
es->tok = (enum token)i;

View File

@ -38,7 +38,7 @@
#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
/*
@ -2298,8 +2298,9 @@ c_unset(const char **wp)
size_t n;
n = strlen(id);
if (n > 3 && id[n-3] == '[' && id[n-2] == '*' &&
id[n-1] == ']') {
if (n > 3 && ord(id[n - 3]) == ord('[') &&
ord(id[n - 2]) == ord('*') &&
ord(id[n - 1]) == ord(']')) {
strndupx(cp, id, n - 3, ATEMP);
id = cp;
optc = 3;

233
lex.c
View File

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

34
misc.c
View File

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

140
sh.h
View File

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

67
syn.c
View File

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

76
tree.c
View File

@ -23,7 +23,7 @@
#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
@ -329,34 +329,34 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
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);
@ -365,7 +365,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
case COMSUB:
shf_puts("$(", shf);
cs = ")";
if (*wp == '(' /*)*/)
if (ord(*wp) == ord('(' /*)*/))
shf_putc(' ', shf);
pSUB:
while ((c = *wp++) != 0)
@ -374,11 +374,11 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
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);
@ -403,14 +403,14 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
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);
}
@ -420,11 +420,11 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
shf_putc('(', shf);
break;
case SPAT:
c = '|';
c = ord('|');
if (0)
/* FALLTHROUGH */
case CPAT:
c = /*(*/ ')';
c = ord(/*(*/ ')');
shf_putc(c, shf);
break;
}
@ -467,39 +467,39 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
{
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 {
@ -515,7 +515,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
shf_putc(' ', shf);
}
break;
case 'R':
case ord('R'):
/* I/O redirection */
pioact(shf, va_arg(va, struct ioword *));
break;
@ -613,7 +613,7 @@ wdscan(const char *wp, int c)
case ADELIM:
if (c == ADELIM && nest == 0)
return (wp + 1);
if (*wp == /*{*/'}')
if (ord(*wp) == ord(/*{*/ '}'))
goto wdscan_csubst;
/* FALLTHROUGH */
case CHAR:
@ -795,7 +795,7 @@ vistree(char *dst, size_t sz, struct op *t)
*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 (ksh_isctrl(c)) {
@ -808,7 +808,7 @@ vistree(char *dst, size_t sz, struct op *t)
} 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;
@ -842,7 +842,7 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel)
shf_puts("EOS", shf);
return (--wp);
case ADELIM:
if (*wp == /*{*/'}') {
if (ord(*wp) == ord(/*{*/ '}')) {
shf_puts(/*{*/ "]ADELIM(})", shf);
return (wp + 1);
}
@ -855,9 +855,9 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel)
break;
case QCHAR:
shf_puts("QCHAR<", shf);
c = *wp++;
if (quotelevel == 0 || c == '"' || c == '\\' ||
ctype(c, C_DOLAR | C_GRAVE))
c = ord(*wp++);
if (quotelevel == 0 || c == ord('"') ||
c == ord('\\') || ctype(c, C_DOLAR | C_GRAVE))
shf_putc('\\', shf);
dumpchar(shf, c);
goto closeandout;

38
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#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
@ -204,7 +204,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
}
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;
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 */
return (NULL);
}
if (*val == '[') {
if (ord(*val) == ord('[')) {
if (new_refflag != SRF_NOP)
errorf(Tf_sD_s, var,
"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;
}
if (val[0] == '=') {
if (ord(val[0]) == ord('=')) {
strndupx(tvar, var, val - var, ATEMP);
++val;
} else if (set & IMPORT) {
/* environment invalid variable name or no assignment */
return (NULL);
} else if (val[0] == '+' && val[1] == '=') {
} else if (ord(val[0]) == ord('+') && ord(val[1]) == ord('=')) {
strndupx(tvar, var, val - var, ATEMP);
val += 2;
vappend = true;
@ -822,8 +822,9 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
val = NULL;
/* handle foo[*] => foo (whole array) mapping for R39b */
len = strlen(tvar);
if (len > 3 && tvar[len - 3] == '[' && tvar[len - 2] == '*' &&
tvar[len - 1] == ']')
if (len > 3 && ord(tvar[len - 3]) == ord('[') &&
ord(tvar[len - 2]) == ord('*') &&
ord(tvar[len - 1]) == ord(']'))
tvar[len - 3] = '\0';
}
@ -860,7 +861,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
nameref_empty:
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]) {
/*
* works for cases "no array", "valid array with
@ -1070,7 +1071,7 @@ skip_varname(const char *s, bool aok)
do {
++s;
} 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;
}
return (s);
@ -1086,7 +1087,7 @@ skip_wdvarname(const char *s,
do {
s += 2;
} 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 */
const char *p = s;
char c;
@ -1097,9 +1098,9 @@ skip_wdvarname(const char *s,
break;
c = p[1];
p += 2;
if (c == '[')
if (ord(c) == ord('['))
depth++;
else if (c == ']' && --depth == 0) {
else if (ord(c) == ord(']') && --depth == 0) {
s = p;
break;
}
@ -1527,8 +1528,8 @@ array_ref_len(const char *cp)
char c;
int depth = 0;
while ((c = *s++) && (c != ']' || --depth))
if (c == '[')
while ((c = *s++) && (ord(c) != ord(']') || --depth))
if (ord(c) == ord('['))
depth++;
if (!c)
return (0);
@ -1600,17 +1601,18 @@ set_array(const char *var, bool reset, const char **vals)
}
while ((ccp = vals[i])) {
#if 0 /* temporarily taken out due to regression */
if (*ccp == '[') {
if (ord(*ccp) == ord('[')) {
int level = 0;
while (*ccp) {
if (*ccp == ']' && --level == 0)
if (ord(*ccp) == ord(']') && --level == 0)
break;
if (*ccp == '[')
if (ord(*ccp) == ord('['))
++level;
++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),
ATEMP);
evaluate(substitute(cp, 0), (mksh_ari_t *)&j,