some ord() debugging; CORD for case, ORD evaluates twice, for debugging
This commit is contained in:
160
edit.c
160
edit.c
@ -5,7 +5,7 @@
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||||
* mirabilos <m@mirbsd.org>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.340 2017/08/27 23:33:50 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.341 2018/01/13 23:55:09 tg Exp $");
|
||||
|
||||
/*
|
||||
* in later versions we might use libtermcap for this, but since external
|
||||
@ -312,12 +312,12 @@ x_glob_hlp_add_qchar(char *cp)
|
||||
*/
|
||||
switch (ord(ch)) {
|
||||
case QCHAR:
|
||||
case ord('$'):
|
||||
case ord('*'):
|
||||
case ord('?'):
|
||||
case ord('['):
|
||||
case ord('\\'):
|
||||
case ord('`'):
|
||||
case CORD('$'):
|
||||
case CORD('*'):
|
||||
case CORD('?'):
|
||||
case CORD('['):
|
||||
case CORD('\\'):
|
||||
case CORD('`'):
|
||||
*dp++ = QCHAR;
|
||||
break;
|
||||
}
|
||||
@ -650,11 +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) ||
|
||||
ord(*s) == ord('*') || ord(*s) == ord('[') ||
|
||||
ord(*s) == ORD('*') || ord(*s) == ORD('[') ||
|
||||
/* ?() *() +() @() !() but two already checked */
|
||||
(ord(s[1]) == ord('(' /*)*/) &&
|
||||
(ord(*s) == ord('+') || ord(*s) == ord('@') ||
|
||||
ord(*s) == ord('!')))) {
|
||||
(ord(s[1]) == ORD('(' /*)*/) &&
|
||||
(ord(*s) == ORD('+') || ord(*s) == ORD('@') ||
|
||||
ord(*s) == ORD('!')))) {
|
||||
/*
|
||||
* just expand based on the extglob
|
||||
* or parameter
|
||||
@ -3688,7 +3688,7 @@ vi_hook(int ch)
|
||||
return (1);
|
||||
cmdlen = 0;
|
||||
argc1 = 0;
|
||||
if (ctype(ch, C_DIGIT) && ord(ch) != ord('0')) {
|
||||
if (ctype(ch, C_DIGIT) && ord(ch) != ORD('0')) {
|
||||
argc1 = ksh_numdig(ch);
|
||||
state = VARG1;
|
||||
} else {
|
||||
@ -3743,7 +3743,7 @@ vi_hook(int ch)
|
||||
|
||||
case VEXTCMD:
|
||||
argc2 = 0;
|
||||
if (ctype(ch, C_DIGIT) && ord(ch) != ord('0')) {
|
||||
if (ctype(ch, C_DIGIT) && ord(ch) != ORD('0')) {
|
||||
argc2 = ksh_numdig(ch);
|
||||
state = VARG2;
|
||||
return (0);
|
||||
@ -4128,7 +4128,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
redraw_line(true);
|
||||
break;
|
||||
|
||||
case ord('@'):
|
||||
case CORD('@'):
|
||||
{
|
||||
static char alias[] = "_\0";
|
||||
struct tbl *ap;
|
||||
@ -4169,7 +4169,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('a'):
|
||||
case CORD('a'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
if (vs->linelen != 0)
|
||||
@ -4177,7 +4177,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('A'):
|
||||
case CORD('A'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
del_range(0, 0);
|
||||
@ -4185,7 +4185,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('S'):
|
||||
case CORD('S'):
|
||||
vs->cursor = domovebeg();
|
||||
del_range(vs->cursor, vs->linelen);
|
||||
modified = 1;
|
||||
@ -4193,14 +4193,14 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('Y'):
|
||||
case CORD('Y'):
|
||||
cmd = "y$";
|
||||
/* ahhhhhh... */
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case ord('c'):
|
||||
case ord('d'):
|
||||
case ord('y'):
|
||||
case CORD('c'):
|
||||
case CORD('d'):
|
||||
case CORD('y'):
|
||||
if (*cmd == cmd[1]) {
|
||||
c1 = *cmd == 'c' ? domovebeg() : 0;
|
||||
c2 = vs->linelen;
|
||||
@ -4239,7 +4239,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('p'):
|
||||
case CORD('p'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
if (vs->linelen != 0)
|
||||
@ -4253,7 +4253,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
return (-1);
|
||||
break;
|
||||
|
||||
case ord('P'):
|
||||
case CORD('P'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
any = 0;
|
||||
@ -4266,25 +4266,25 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
return (-1);
|
||||
break;
|
||||
|
||||
case ord('C'):
|
||||
case CORD('C'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
del_range(vs->cursor, vs->linelen);
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('D'):
|
||||
case CORD('D'):
|
||||
yank_range(vs->cursor, vs->linelen);
|
||||
del_range(vs->cursor, vs->linelen);
|
||||
if (vs->cursor != 0)
|
||||
vs->cursor--;
|
||||
break;
|
||||
|
||||
case ord('g'):
|
||||
case CORD('g'):
|
||||
if (!argcnt)
|
||||
argcnt = hlast;
|
||||
/* FALLTHROUGH */
|
||||
case ord('G'):
|
||||
case CORD('G'):
|
||||
if (!argcnt)
|
||||
argcnt = 1;
|
||||
else
|
||||
@ -4297,21 +4297,21 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('i'):
|
||||
case CORD('i'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('I'):
|
||||
case CORD('I'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
vs->cursor = domovebeg();
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('j'):
|
||||
case ord('+'):
|
||||
case CORD('j'):
|
||||
case CORD('+'):
|
||||
case CTRL_N:
|
||||
if (grabhist(modified, hnum + argcnt) < 0)
|
||||
return (-1);
|
||||
@ -4321,8 +4321,8 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('k'):
|
||||
case ord('-'):
|
||||
case CORD('k'):
|
||||
case CORD('-'):
|
||||
case CTRL_P:
|
||||
if (grabhist(modified, hnum - argcnt) < 0)
|
||||
return (-1);
|
||||
@ -4332,7 +4332,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('r'):
|
||||
case CORD('r'):
|
||||
if (vs->linelen == 0)
|
||||
return (-1);
|
||||
modified = 1;
|
||||
@ -4350,13 +4350,13 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('R'):
|
||||
case CORD('R'):
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
insert = REPLACE;
|
||||
break;
|
||||
|
||||
case ord('s'):
|
||||
case CORD('s'):
|
||||
if (vs->linelen == 0)
|
||||
return (-1);
|
||||
modified = 1;
|
||||
@ -4367,7 +4367,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
insert = INSERT;
|
||||
break;
|
||||
|
||||
case ord('v'):
|
||||
case CORD('v'):
|
||||
if (!argcnt) {
|
||||
if (vs->linelen == 0)
|
||||
return (-1);
|
||||
@ -4390,7 +4390,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
vs->linelen = strlen(vs->cbuf);
|
||||
return (2);
|
||||
|
||||
case ord('x'):
|
||||
case CORD('x'):
|
||||
if (vs->linelen == 0)
|
||||
return (-1);
|
||||
modified = 1;
|
||||
@ -4401,7 +4401,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
del_range(vs->cursor, vs->cursor + argcnt);
|
||||
break;
|
||||
|
||||
case ord('X'):
|
||||
case CORD('X'):
|
||||
if (vs->cursor > 0) {
|
||||
modified = 1;
|
||||
hnum = hlast;
|
||||
@ -4414,13 +4414,13 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
return (-1);
|
||||
break;
|
||||
|
||||
case ord('u'):
|
||||
case CORD('u'):
|
||||
t = vs;
|
||||
vs = undo;
|
||||
undo = t;
|
||||
break;
|
||||
|
||||
case ord('U'):
|
||||
case CORD('U'):
|
||||
if (!modified)
|
||||
return (-1);
|
||||
if (grabhist(modified, ohnum) < 0)
|
||||
@ -4429,19 +4429,19 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
hnum = ohnum;
|
||||
break;
|
||||
|
||||
case ord('?'):
|
||||
case CORD('?'):
|
||||
if (hnum == hlast)
|
||||
hnum = -1;
|
||||
/* ahhh */
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case ord('/'):
|
||||
case CORD('/'):
|
||||
c3 = 1;
|
||||
srchlen = 0;
|
||||
lastsearch = *cmd;
|
||||
/* FALLTHROUGH */
|
||||
case ord('n'):
|
||||
case ord('N'):
|
||||
case CORD('n'):
|
||||
case CORD('N'):
|
||||
if (lastsearch == ' ')
|
||||
return (-1);
|
||||
if (lastsearch == '?')
|
||||
@ -4468,7 +4468,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
case ord('_'):
|
||||
case CORD('_'):
|
||||
{
|
||||
bool inspace;
|
||||
char *p, *sp;
|
||||
@ -4520,7 +4520,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('~'):
|
||||
case CORD('~'):
|
||||
{
|
||||
char *p;
|
||||
int i;
|
||||
@ -4544,7 +4544,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
case ord('#'):
|
||||
case CORD('#'):
|
||||
{
|
||||
int ret = x_do_comment(vs->cbuf, vs->cbufsize,
|
||||
&vs->linelen);
|
||||
@ -4554,7 +4554,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
}
|
||||
|
||||
/* AT&T ksh */
|
||||
case ord('='):
|
||||
case CORD('='):
|
||||
/* Nonstandard vi/ksh */
|
||||
case CTRL_E:
|
||||
print_expansions(vs, 1);
|
||||
@ -4574,7 +4574,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
return (-1);
|
||||
/* FALLTHROUGH */
|
||||
/* AT&T ksh */
|
||||
case ord('\\'):
|
||||
case CORD('\\'):
|
||||
/* Nonstandard vi/ksh */
|
||||
case CTRL_F:
|
||||
complete_word(1, argcnt);
|
||||
@ -4582,7 +4582,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
|
||||
|
||||
/* AT&T ksh */
|
||||
case ord('*'):
|
||||
case CORD('*'):
|
||||
/* Nonstandard vi/ksh */
|
||||
case CTRL_X:
|
||||
expand_word(1);
|
||||
@ -4590,8 +4590,8 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
|
||||
|
||||
/* mksh: cursor movement */
|
||||
case ord('['):
|
||||
case ord('O'):
|
||||
case CORD('['):
|
||||
case CORD('O'):
|
||||
state = VPREFIX2;
|
||||
if (vs->linelen != 0)
|
||||
vs->cursor++;
|
||||
@ -4611,19 +4611,19 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
unsigned int bcount;
|
||||
|
||||
switch (ord(*cmd)) {
|
||||
case ord('b'):
|
||||
case CORD('b'):
|
||||
if (!sub && vs->cursor == 0)
|
||||
return (-1);
|
||||
ncursor = backword(argcnt);
|
||||
break;
|
||||
|
||||
case ord('B'):
|
||||
case CORD('B'):
|
||||
if (!sub && vs->cursor == 0)
|
||||
return (-1);
|
||||
ncursor = Backword(argcnt);
|
||||
break;
|
||||
|
||||
case ord('e'):
|
||||
case CORD('e'):
|
||||
if (!sub && vs->cursor + 1 >= vs->linelen)
|
||||
return (-1);
|
||||
ncursor = endword(argcnt);
|
||||
@ -4631,7 +4631,7 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
ncursor++;
|
||||
break;
|
||||
|
||||
case ord('E'):
|
||||
case CORD('E'):
|
||||
if (!sub && vs->cursor + 1 >= vs->linelen)
|
||||
return (-1);
|
||||
ncursor = Endword(argcnt);
|
||||
@ -4639,15 +4639,15 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
ncursor++;
|
||||
break;
|
||||
|
||||
case ord('f'):
|
||||
case ord('F'):
|
||||
case ord('t'):
|
||||
case ord('T'):
|
||||
case CORD('f'):
|
||||
case CORD('F'):
|
||||
case CORD('t'):
|
||||
case CORD('T'):
|
||||
fsavecmd = *cmd;
|
||||
fsavech = cmd[1];
|
||||
/* FALLTHROUGH */
|
||||
case ord(','):
|
||||
case ord(';'):
|
||||
case CORD(','):
|
||||
case CORD(';'):
|
||||
if (fsavecmd == ' ')
|
||||
return (-1);
|
||||
i = ksh_eq(fsavecmd, 'F', 'f');
|
||||
@ -4661,7 +4661,7 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
ncursor++;
|
||||
break;
|
||||
|
||||
case ord('h'):
|
||||
case CORD('h'):
|
||||
case CTRL_H:
|
||||
if (!sub && vs->cursor == 0)
|
||||
return (-1);
|
||||
@ -4670,8 +4670,8 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
ncursor = 0;
|
||||
break;
|
||||
|
||||
case ord(' '):
|
||||
case ord('l'):
|
||||
case CORD(' '):
|
||||
case CORD('l'):
|
||||
if (!sub && vs->cursor + 1 >= vs->linelen)
|
||||
return (-1);
|
||||
if (vs->linelen != 0) {
|
||||
@ -4681,27 +4681,27 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('w'):
|
||||
case CORD('w'):
|
||||
if (!sub && vs->cursor + 1 >= vs->linelen)
|
||||
return (-1);
|
||||
ncursor = forwword(argcnt);
|
||||
break;
|
||||
|
||||
case ord('W'):
|
||||
case CORD('W'):
|
||||
if (!sub && vs->cursor + 1 >= vs->linelen)
|
||||
return (-1);
|
||||
ncursor = Forwword(argcnt);
|
||||
break;
|
||||
|
||||
case ord('0'):
|
||||
case CORD('0'):
|
||||
ncursor = 0;
|
||||
break;
|
||||
|
||||
case ord('^'):
|
||||
case CORD('^'):
|
||||
ncursor = domovebeg();
|
||||
break;
|
||||
|
||||
case ord('|'):
|
||||
case CORD('|'):
|
||||
ncursor = argcnt;
|
||||
if (ncursor > vs->linelen)
|
||||
ncursor = vs->linelen;
|
||||
@ -4709,14 +4709,14 @@ domove(int argcnt, const char *cmd, int sub)
|
||||
ncursor--;
|
||||
break;
|
||||
|
||||
case ord('$'):
|
||||
case CORD('$'):
|
||||
if (vs->linelen != 0)
|
||||
ncursor = vs->linelen;
|
||||
else
|
||||
ncursor = 0;
|
||||
break;
|
||||
|
||||
case ord('%'):
|
||||
case CORD('%'):
|
||||
ncursor = vs->cursor;
|
||||
while (ncursor < vs->linelen &&
|
||||
(i = bracktype(vs->cbuf[ncursor])) == 0)
|
||||
@ -4784,22 +4784,22 @@ bracktype(int ch)
|
||||
{
|
||||
switch (ord(ch)) {
|
||||
|
||||
case ord('('):
|
||||
case CORD('('):
|
||||
return (1);
|
||||
|
||||
case ord('['):
|
||||
case CORD('['):
|
||||
return (2);
|
||||
|
||||
case ord('{'):
|
||||
case CORD('{'):
|
||||
return (3);
|
||||
|
||||
case ord(')'):
|
||||
case CORD(')'):
|
||||
return (-1);
|
||||
|
||||
case ord(']'):
|
||||
case CORD(']'):
|
||||
return (-2);
|
||||
|
||||
case ord('}'):
|
||||
case CORD('}'):
|
||||
return (-3);
|
||||
|
||||
default:
|
||||
|
216
eval.c
216
eval.c
@ -2,7 +2,7 @@
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||||
* mirabilos <m@mirbsd.org>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.215 2017/08/28 23:27:51 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.216 2018/01/13 23:55:09 tg Exp $");
|
||||
|
||||
/*
|
||||
* string expansion
|
||||
@ -320,21 +320,21 @@ expand(
|
||||
case COMASUB:
|
||||
case COMSUB:
|
||||
*dp++ = '(';
|
||||
c = ord(')');
|
||||
c = ORD(')');
|
||||
break;
|
||||
case FUNASUB:
|
||||
case FUNSUB:
|
||||
case VALSUB:
|
||||
*dp++ = '{';
|
||||
*dp++ = c == VALSUB ? '|' : ' ';
|
||||
c = ord('}');
|
||||
c = ORD('}');
|
||||
break;
|
||||
}
|
||||
while (*sp != '\0') {
|
||||
Xcheck(ds, dp);
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
if (c == ord('}'))
|
||||
if ((unsigned int)c == ORD('}'))
|
||||
*dp++ = ';';
|
||||
*dp++ = c;
|
||||
} else {
|
||||
@ -436,11 +436,11 @@ expand(
|
||||
if (stype)
|
||||
sp += slen;
|
||||
switch (stype & STYPE_SINGLE) {
|
||||
case ord('#') | STYPE_AT:
|
||||
case CORD('#') | STYPE_AT:
|
||||
x.str = shf_smprintf("%08X",
|
||||
(unsigned int)hash(str_val(st->var)));
|
||||
break;
|
||||
case ord('Q') | STYPE_AT: {
|
||||
case CORD('Q') | STYPE_AT: {
|
||||
struct shf shf;
|
||||
|
||||
shf_sopen(NULL, 0, SHF_WR|SHF_DYNAMIC, &shf);
|
||||
@ -448,7 +448,7 @@ expand(
|
||||
x.str = shf_sclose(&shf);
|
||||
break;
|
||||
}
|
||||
case ord('0'): {
|
||||
case CORD('0'): {
|
||||
char *beg, *mid, *end, *stg;
|
||||
mksh_ari_t from = 0, num = -1, flen, finc = 0;
|
||||
|
||||
@ -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;
|
||||
@ -495,8 +495,8 @@ expand(
|
||||
strndupx(x.str, beg, num, ATEMP);
|
||||
goto do_CSUBST;
|
||||
}
|
||||
case ord('/') | STYPE_AT:
|
||||
case ord('/'): {
|
||||
case CORD('/') | STYPE_AT:
|
||||
case CORD('/'): {
|
||||
char *s, *p, *d, *sbeg, *end;
|
||||
char *pat = NULL, *rrep = null;
|
||||
char fpat = 0, *tpat1, *tpat2;
|
||||
@ -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;
|
||||
@ -547,11 +547,11 @@ expand(
|
||||
}
|
||||
|
||||
/* first see if we have any match at all */
|
||||
if (ord(fpat) == ord('#')) {
|
||||
if (ord(fpat) == ORD('#')) {
|
||||
/* anchor at the beginning */
|
||||
tpat1 = shf_smprintf("%s%c*", pat, MAGIC);
|
||||
tpat2 = tpat1;
|
||||
} else if (ord(fpat) == ord('%')) {
|
||||
} else if (ord(fpat) == ORD('%')) {
|
||||
/* anchor at the end */
|
||||
tpat1 = shf_smprintf("%c*%s", MAGIC, pat);
|
||||
tpat2 = pat;
|
||||
@ -569,7 +569,7 @@ expand(
|
||||
goto end_repl;
|
||||
end = strnul(s);
|
||||
/* now anchor the beginning of the match */
|
||||
if (ord(fpat) != ord('#'))
|
||||
if (ord(fpat) != ORD('#'))
|
||||
while (sbeg <= end) {
|
||||
if (gmatchx(sbeg, tpat2, false))
|
||||
break;
|
||||
@ -578,7 +578,7 @@ expand(
|
||||
}
|
||||
/* now anchor the end of the match */
|
||||
p = end;
|
||||
if (ord(fpat) != ord('%'))
|
||||
if (ord(fpat) != ORD('%'))
|
||||
while (p >= sbeg) {
|
||||
bool gotmatch;
|
||||
|
||||
@ -622,8 +622,8 @@ expand(
|
||||
afree(ws, ATEMP);
|
||||
goto do_CSUBST;
|
||||
}
|
||||
case ord('#'):
|
||||
case ord('%'):
|
||||
case CORD('#'):
|
||||
case CORD('%'):
|
||||
/* ! DOBLANK,DOBRACE */
|
||||
f = (f & DONTRUNCOMMAND) |
|
||||
DOPAT | DOTILDE |
|
||||
@ -637,10 +637,10 @@ expand(
|
||||
*/
|
||||
if (!Flag(FSH)) {
|
||||
*dp++ = MAGIC;
|
||||
*dp++ = ord(0x80 | '@');
|
||||
*dp++ = ORD(0x80 | '@');
|
||||
}
|
||||
break;
|
||||
case ord('='):
|
||||
case CORD('='):
|
||||
/*
|
||||
* Tilde expansion for string
|
||||
* variables in POSIX mode is
|
||||
@ -664,7 +664,7 @@ expand(
|
||||
f &= ~(DOBLANK|DOGLOB|DOBRACE);
|
||||
tilde_ok = 1;
|
||||
break;
|
||||
case ord('?'):
|
||||
case CORD('?'):
|
||||
if (*sp == CSUBST)
|
||||
errorf("%s: parameter null or not set",
|
||||
st->var->name);
|
||||
@ -699,8 +699,8 @@ expand(
|
||||
if (f & DOBLANK)
|
||||
doblank--;
|
||||
switch (st->stype & STYPE_SINGLE) {
|
||||
case ord('#'):
|
||||
case ord('%'):
|
||||
case CORD('#'):
|
||||
case CORD('%'):
|
||||
if (!Flag(FSH)) {
|
||||
/* Append end-pattern */
|
||||
*dp++ = MAGIC;
|
||||
@ -730,7 +730,7 @@ expand(
|
||||
doblank++;
|
||||
st = st->prev;
|
||||
continue;
|
||||
case ord('='):
|
||||
case CORD('='):
|
||||
/*
|
||||
* Restore our position and substitute
|
||||
* the value of st->var (may not be
|
||||
@ -763,17 +763,17 @@ expand(
|
||||
st = st->prev;
|
||||
word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS;
|
||||
continue;
|
||||
case ord('?'):
|
||||
case CORD('?'):
|
||||
dp = Xrestpos(ds, dp, st->base);
|
||||
|
||||
errorf(Tf_sD_s, st->var->name,
|
||||
debunk(dp, dp, strlen(dp) + 1));
|
||||
break;
|
||||
case ord('0'):
|
||||
case ord('/') | STYPE_AT:
|
||||
case ord('/'):
|
||||
case ord('#') | STYPE_AT:
|
||||
case ord('Q') | STYPE_AT:
|
||||
case CORD('0'):
|
||||
case CORD('/') | STYPE_AT:
|
||||
case CORD('/'):
|
||||
case CORD('#') | STYPE_AT:
|
||||
case CORD('Q') | STYPE_AT:
|
||||
dp = Xrestpos(ds, dp, st->base);
|
||||
type = XSUB;
|
||||
word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS;
|
||||
@ -1003,10 +1003,10 @@ expand(
|
||||
/* mark any special second pass chars */
|
||||
if (!quote)
|
||||
switch (ord(c)) {
|
||||
case ord('['):
|
||||
case ord('!'):
|
||||
case ord('-'):
|
||||
case ord(']'):
|
||||
case CORD('['):
|
||||
case CORD('!'):
|
||||
case CORD('-'):
|
||||
case CORD(']'):
|
||||
/*
|
||||
* For character classes - doesn't hurt
|
||||
* to have magic !,-,]s outside of
|
||||
@ -1014,29 +1014,29 @@ expand(
|
||||
*/
|
||||
if (f & (DOPAT | DOGLOB)) {
|
||||
fdo |= DOMAGIC;
|
||||
if (c == ord('['))
|
||||
if ((unsigned int)c == ORD('['))
|
||||
fdo |= f & DOGLOB;
|
||||
*dp++ = MAGIC;
|
||||
}
|
||||
break;
|
||||
case ord('*'):
|
||||
case ord('?'):
|
||||
case CORD('*'):
|
||||
case CORD('?'):
|
||||
if (f & (DOPAT | DOGLOB)) {
|
||||
fdo |= DOMAGIC | (f & DOGLOB);
|
||||
*dp++ = MAGIC;
|
||||
}
|
||||
break;
|
||||
case ord('{'):
|
||||
case ord('}'):
|
||||
case ord(','):
|
||||
case CORD('{'):
|
||||
case CORD('}'):
|
||||
case CORD(','):
|
||||
if ((f & DOBRACE) &&
|
||||
(ord(c) == ord('{' /*}*/) ||
|
||||
(ord(c) == ORD('{' /*}*/) ||
|
||||
(fdo & DOBRACE))) {
|
||||
fdo |= DOBRACE|DOMAGIC;
|
||||
*dp++ = MAGIC;
|
||||
}
|
||||
break;
|
||||
case ord('='):
|
||||
case CORD('='):
|
||||
/* Note first unquoted = for ~ */
|
||||
if (!(f & DOTEMP) && (!Flag(FPOSIX) ||
|
||||
(f & DOASNTILDE)) && !saw_eq) {
|
||||
@ -1044,13 +1044,13 @@ expand(
|
||||
tilde_ok = 1;
|
||||
}
|
||||
break;
|
||||
case ord(':'):
|
||||
case CORD(':'):
|
||||
/* : */
|
||||
/* Note unquoted : for ~ */
|
||||
if (!(f & DOTEMP) && (f & DOASNTILDE))
|
||||
tilde_ok = 1;
|
||||
break;
|
||||
case ord('~'):
|
||||
case CORD('~'):
|
||||
/*
|
||||
* tilde_ok is reset whenever
|
||||
* any of ' " $( $(( ${ } are seen.
|
||||
@ -1133,7 +1133,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
* ${%var}, string width (-U: screen columns, +U: octets)
|
||||
*/
|
||||
c = ord(sp[1]);
|
||||
if (stype == ord('%') && c == '\0')
|
||||
if ((unsigned int)stype == ORD('%') && c == '\0')
|
||||
return (-1);
|
||||
if (ctype(stype, C_SUB2) && c != '\0') {
|
||||
/* Can't have any modifiers for ${#...} or ${%...} */
|
||||
@ -1141,11 +1141,11 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
return (-1);
|
||||
sp++;
|
||||
/* Check for size of array */
|
||||
if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ord('*') ||
|
||||
ord(p[1]) == ord('@')) && ord(p[2]) == ord(']')) {
|
||||
if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ORD('*') ||
|
||||
ord(p[1]) == ORD('@')) && ord(p[2]) == ORD(']')) {
|
||||
int n = 0;
|
||||
|
||||
if (stype != ord('#'))
|
||||
if ((unsigned int)stype != ORD('#'))
|
||||
return (-1);
|
||||
vp = global(arrayname(sp));
|
||||
if (vp->flag & (ISSET|ARRAY))
|
||||
@ -1154,14 +1154,15 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
if (vp->flag & ISSET)
|
||||
n++;
|
||||
c = n;
|
||||
} else if (c == ord('*') || c == ord('@')) {
|
||||
if (stype != ord('#'))
|
||||
} else if ((unsigned int)c == ORD('*') ||
|
||||
(unsigned int)c == ORD('@')) {
|
||||
if ((unsigned int)stype != ORD('#'))
|
||||
return (-1);
|
||||
c = e->loc->argc;
|
||||
} else {
|
||||
p = str_val(global(sp));
|
||||
zero_ok = p != null;
|
||||
if (stype == ord('#'))
|
||||
if ((unsigned int)stype == ORD('#'))
|
||||
c = utflen(p);
|
||||
else {
|
||||
/* partial utf_mbswidth reimplementation */
|
||||
@ -1196,11 +1197,11 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
xp->str = shf_smprintf(Tf_d, c);
|
||||
return (XSUB);
|
||||
}
|
||||
if (stype == ord('!') && c != '\0' && *word == CSUBST) {
|
||||
if ((unsigned int)stype == ORD('!') && c != '\0' && *word == CSUBST) {
|
||||
sp++;
|
||||
if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ord('*') ||
|
||||
ord(p[1]) == ord('@')) && ord(p[2]) == ord(']')) {
|
||||
c = ord('!');
|
||||
if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ORD('*') ||
|
||||
ord(p[1]) == ORD('@')) && ord(p[2]) == ORD(']')) {
|
||||
c = ORD('!');
|
||||
stype = 0;
|
||||
goto arraynames;
|
||||
}
|
||||
@ -1214,12 +1215,12 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
/* Check for qualifiers in word part */
|
||||
stype = 0;
|
||||
c = word[slen + 0] == CHAR ? ord(word[slen + 1]) : 0;
|
||||
if (c == ord(':')) {
|
||||
if ((unsigned int)c == ORD(':')) {
|
||||
slen += 2;
|
||||
stype = STYPE_DBL;
|
||||
c = word[slen + 0] == CHAR ? ord(word[slen + 1]) : 0;
|
||||
}
|
||||
if (!stype && c == ord('/')) {
|
||||
if (!stype && (unsigned int)c == ORD('/')) {
|
||||
slen += 2;
|
||||
stype = c;
|
||||
if (word[slen] == ADELIM &&
|
||||
@ -1227,8 +1228,9 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
slen += 2;
|
||||
stype |= STYPE_DBL;
|
||||
}
|
||||
} else if (stype == STYPE_DBL && (c == ord(' ') || c == ord('0'))) {
|
||||
stype |= ord('0');
|
||||
} else if (stype == STYPE_DBL && ((unsigned int)c == ORD(' ') ||
|
||||
(unsigned int)c == ORD('0'))) {
|
||||
stype |= ORD('0');
|
||||
} else if (ctype(c, C_SUB1)) {
|
||||
slen += 2;
|
||||
stype |= c;
|
||||
@ -1241,13 +1243,13 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
stype |= STYPE_DBL;
|
||||
slen += 2;
|
||||
}
|
||||
} else if (c == ord('@')) {
|
||||
} else if ((unsigned int)c == ORD('@')) {
|
||||
/* @x where x is command char */
|
||||
switch (c = ord(word[slen + 2]) == CHAR ?
|
||||
ord(word[slen + 3]) : 0) {
|
||||
case ord('#'):
|
||||
case ord('/'):
|
||||
case ord('Q'):
|
||||
case CORD('#'):
|
||||
case CORD('/'):
|
||||
case CORD('Q'):
|
||||
break;
|
||||
default:
|
||||
return (-1);
|
||||
@ -1261,50 +1263,50 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
return (-1);
|
||||
|
||||
c = ord(sp[0]);
|
||||
if (c == ord('*') || c == ord('@')) {
|
||||
if ((unsigned int)c == ORD('*') || (unsigned int)c == ORD('@')) {
|
||||
switch (stype & STYPE_SINGLE) {
|
||||
/* can't assign to a vector */
|
||||
case ord('='):
|
||||
case CORD('='):
|
||||
/* can't trim a vector (yet) */
|
||||
case ord('%'):
|
||||
case ord('#'):
|
||||
case ord('?'):
|
||||
case ord('0'):
|
||||
case ord('/') | STYPE_AT:
|
||||
case ord('/'):
|
||||
case ord('#') | STYPE_AT:
|
||||
case ord('Q') | STYPE_AT:
|
||||
case CORD('%'):
|
||||
case CORD('#'):
|
||||
case CORD('?'):
|
||||
case CORD('0'):
|
||||
case CORD('/') | STYPE_AT:
|
||||
case CORD('/'):
|
||||
case CORD('#') | STYPE_AT:
|
||||
case CORD('Q') | STYPE_AT:
|
||||
return (-1);
|
||||
}
|
||||
if (e->loc->argc == 0) {
|
||||
xp->str = null;
|
||||
xp->var = global(sp);
|
||||
state = c == ord('@') ? XNULLSUB : XSUB;
|
||||
state = (unsigned int)c == ORD('@') ? XNULLSUB : XSUB;
|
||||
} else {
|
||||
xp->u.strv = (const char **)e->loc->argv + 1;
|
||||
xp->str = *xp->u.strv++;
|
||||
/* $@ */
|
||||
xp->split = tobool(c == ord('@'));
|
||||
xp->split = tobool((unsigned int)c == ORD('@'));
|
||||
state = XARG;
|
||||
}
|
||||
/* POSIX 2009? */
|
||||
zero_ok = true;
|
||||
} else if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ord('*') ||
|
||||
ord(p[1]) == ord('@')) && ord(p[2]) == ord(']')) {
|
||||
} else if ((p = cstrchr(sp, '[')) && (ord(p[1]) == ORD('*') ||
|
||||
ord(p[1]) == ORD('@')) && ord(p[2]) == ORD(']')) {
|
||||
XPtrV wv;
|
||||
|
||||
switch (stype & STYPE_SINGLE) {
|
||||
/* can't assign to a vector */
|
||||
case ord('='):
|
||||
case CORD('='):
|
||||
/* can't trim a vector (yet) */
|
||||
case ord('%'):
|
||||
case ord('#'):
|
||||
case ord('?'):
|
||||
case ord('0'):
|
||||
case ord('/') | STYPE_AT:
|
||||
case ord('/'):
|
||||
case ord('#') | STYPE_AT:
|
||||
case ord('Q') | STYPE_AT:
|
||||
case CORD('%'):
|
||||
case CORD('#'):
|
||||
case CORD('?'):
|
||||
case CORD('0'):
|
||||
case CORD('/') | STYPE_AT:
|
||||
case CORD('/'):
|
||||
case CORD('#') | STYPE_AT:
|
||||
case CORD('Q') | STYPE_AT:
|
||||
return (-1);
|
||||
}
|
||||
c = 0;
|
||||
@ -1314,28 +1316,28 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
for (; vp; vp = vp->u.array) {
|
||||
if (!(vp->flag&ISSET))
|
||||
continue;
|
||||
XPput(wv, c == ord('!') ? shf_smprintf(Tf_lu,
|
||||
arrayindex(vp)) :
|
||||
XPput(wv, (unsigned int)c == ORD('!') ?
|
||||
shf_smprintf(Tf_lu, arrayindex(vp)) :
|
||||
str_val(vp));
|
||||
}
|
||||
if (XPsize(wv) == 0) {
|
||||
xp->str = null;
|
||||
state = ord(p[1]) == ord('@') ? XNULLSUB : XSUB;
|
||||
state = ord(p[1]) == ORD('@') ? XNULLSUB : XSUB;
|
||||
XPfree(wv);
|
||||
} else {
|
||||
XPput(wv, 0);
|
||||
xp->u.strv = (const char **)XPptrv(wv);
|
||||
xp->str = *xp->u.strv++;
|
||||
/* ${foo[@]} */
|
||||
xp->split = tobool(ord(p[1]) == ord('@'));
|
||||
xp->split = tobool(ord(p[1]) == ORD('@'));
|
||||
state = XARG;
|
||||
}
|
||||
} else {
|
||||
xp->var = global(sp);
|
||||
xp->str = str_val(xp->var);
|
||||
/* can't assign things like $! or $1 */
|
||||
if ((stype & STYPE_SINGLE) == ord('=') && !*xp->str &&
|
||||
ctype(*sp, C_VAR1 | C_DIGIT))
|
||||
if ((unsigned int)(stype & STYPE_SINGLE) == ORD('=') &&
|
||||
!*xp->str && ctype(*sp, C_VAR1 | C_DIGIT))
|
||||
return (-1);
|
||||
state = XSUB;
|
||||
}
|
||||
@ -1346,13 +1348,15 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
(((stype & STYPE_DBL) ? *xp->str == '\0' : xp->str == null) &&
|
||||
(state != XARG || (ifs0 || xp->split ?
|
||||
(xp->u.strv[0] == NULL) : !hasnonempty(xp->u.strv))) ?
|
||||
ctype(c, C_EQUAL | C_MINUS | C_QUEST) : c == ord('+')))) ||
|
||||
stype == (ord('0') | STYPE_DBL) || stype == (ord('#') | STYPE_AT) ||
|
||||
stype == (ord('Q') | STYPE_AT) || (stype & STYPE_CHAR) == ord('/'))
|
||||
ctype(c, C_EQUAL | C_MINUS | C_QUEST) : (unsigned int)c == ORD('+')))) ||
|
||||
(unsigned int)stype == (ORD('0') | STYPE_DBL) ||
|
||||
(unsigned int)stype == (ORD('#') | STYPE_AT) ||
|
||||
(unsigned int)stype == (ORD('Q') | STYPE_AT) ||
|
||||
(unsigned int)(stype & STYPE_CHAR) == ORD('/'))
|
||||
/* expand word instead of variable value */
|
||||
state = XBASE;
|
||||
if (Flag(FNOUNSET) && xp->str == null && !zero_ok &&
|
||||
(ctype(c, C_SUB2) || (state != XBASE && c != ord('+'))))
|
||||
(ctype(c, C_SUB2) || (state != XBASE && (unsigned int)c != ORD('+'))))
|
||||
errorf(Tf_parm, sp);
|
||||
*stypep = stype;
|
||||
*slenp = slen;
|
||||
@ -1491,7 +1495,7 @@ trimsub(char *str, char *pat, int how)
|
||||
char *p, c;
|
||||
|
||||
switch (how & (STYPE_CHAR | STYPE_DBL)) {
|
||||
case ord('#'):
|
||||
case CORD('#'):
|
||||
/* shortest match at beginning */
|
||||
for (p = str; p <= end; p += utf_ptradj(p)) {
|
||||
c = *p; *p = '\0';
|
||||
@ -1503,7 +1507,7 @@ trimsub(char *str, char *pat, int how)
|
||||
*p = c;
|
||||
}
|
||||
break;
|
||||
case ord('#') | STYPE_DBL:
|
||||
case CORD('#') | STYPE_DBL:
|
||||
/* longest match at beginning */
|
||||
for (p = end; p >= str; p--) {
|
||||
c = *p; *p = '\0';
|
||||
@ -1515,7 +1519,7 @@ trimsub(char *str, char *pat, int how)
|
||||
*p = c;
|
||||
}
|
||||
break;
|
||||
case ord('%'):
|
||||
case CORD('%'):
|
||||
/* shortest match at end */
|
||||
p = end;
|
||||
while (p >= str) {
|
||||
@ -1531,7 +1535,7 @@ trimsub(char *str, char *pat, int how)
|
||||
--p;
|
||||
}
|
||||
break;
|
||||
case ord('%') | STYPE_DBL:
|
||||
case CORD('%') | STYPE_DBL:
|
||||
/* longest match at end */
|
||||
for (p = str; p <= end; p++)
|
||||
if (gmatchx(p, pat, false)) {
|
||||
@ -1863,7 +1867,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)) && ord(p[1]) != ord('{' /*}*/))
|
||||
while ((p = strchr(p, MAGIC)) && ord(p[1]) != ORD('{' /*}*/))
|
||||
p += 2;
|
||||
brace_start = p;
|
||||
|
||||
@ -1874,9 +1878,9 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
|
||||
p += 2;
|
||||
while (*p && count) {
|
||||
if (ISMAGIC(*p++)) {
|
||||
if (ord(*p) == ord('{' /*}*/))
|
||||
if (ord(*p) == ORD('{' /*}*/))
|
||||
++count;
|
||||
else if (ord(*p) == ord(/*{*/ '}'))
|
||||
else if (ord(*p) == ORD(/*{*/ '}'))
|
||||
--count;
|
||||
else if (*p == ',' && count == 1)
|
||||
comma = p;
|
||||
@ -1908,9 +1912,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 (ord(*++p) == ord('{' /*}*/))
|
||||
if (ord(*++p) == ORD('{' /*}*/))
|
||||
++count;
|
||||
else if ((ord(*p) == ord(/*{*/ '}') && --count == 0) ||
|
||||
else if ((ord(*p) == ORD(/*{*/ '}') && --count == 0) ||
|
||||
(*p == ',' && count == 1)) {
|
||||
char *news;
|
||||
int l1, l2, l3;
|
||||
|
8
expr.c
8
expr.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.101 2017/11/18 12:01:53 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.102 2018/01/13 23:55:10 tg Exp $");
|
||||
|
||||
#define EXPRTOK_DEFNS
|
||||
#include "exprtok.h"
|
||||
@ -558,9 +558,9 @@ exprtoken(Expr_state *es)
|
||||
|
||||
/* skip whitespace */
|
||||
skip_spaces:
|
||||
while (ctype(ord((c = *cp)), C_SPACE))
|
||||
while (ctype((c = *cp), C_SPACE))
|
||||
++cp;
|
||||
if (es->tokp == es->expression && c == ord('#')) {
|
||||
if (es->tokp == es->expression && (unsigned int)c == ORD('#')) {
|
||||
/* expression begins with # */
|
||||
/* switch to unsigned */
|
||||
es->natural = true;
|
||||
@ -575,7 +575,7 @@ exprtoken(Expr_state *es)
|
||||
do {
|
||||
c = ord(*++cp);
|
||||
} while (ctype(c, C_ALNUX));
|
||||
if (c == ord('[')) {
|
||||
if ((unsigned int)c == ORD('[')) {
|
||||
size_t len;
|
||||
|
||||
len = array_ref_len(cp);
|
||||
|
12
funcs.c
12
funcs.c
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.351 2017/11/20 02:32:32 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.352 2018/01/13 23:55:11 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -745,9 +745,9 @@ do_whence(const char **wp, int fcflags, bool vflag, bool iscommand)
|
||||
bool
|
||||
valid_alias_name(const char *cp)
|
||||
{
|
||||
if (ord(*cp) == ord('-'))
|
||||
if (ord(*cp) == ORD('-'))
|
||||
return (false);
|
||||
if (ord(cp[0]) == ord('[') && ord(cp[1]) == ord('[') && !cp[2])
|
||||
if (ord(cp[0]) == ORD('[') && ord(cp[1]) == ORD('[') && !cp[2])
|
||||
return (false);
|
||||
while (*cp)
|
||||
if (ctype(*cp, C_ALIAS))
|
||||
@ -2298,9 +2298,9 @@ c_unset(const char **wp)
|
||||
size_t n;
|
||||
|
||||
n = strlen(id);
|
||||
if (n > 3 && ord(id[n - 3]) == ord('[') &&
|
||||
ord(id[n - 2]) == ord('*') &&
|
||||
ord(id[n - 1]) == ord(']')) {
|
||||
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;
|
||||
|
236
lex.c
236
lex.c
@ -2,7 +2,7 @@
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||||
* mirabilos <m@mirbsd.org>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.240 2017/10/17 23:45:18 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.241 2018/01/13 23:55:11 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -130,8 +130,13 @@ getsc_i(void)
|
||||
o_getsc_r(o_getsc());
|
||||
}
|
||||
|
||||
/*XXX
|
||||
* getsc() result is supposed to be ord()ed right now,
|
||||
* but results sometimes aren't handled correctly; re‐
|
||||
* check CVS history for *that* change and fix it
|
||||
*/
|
||||
#if defined(MKSH_SMALL) && !defined(MKSH_SMALL_BUT_FAST)
|
||||
#define getsc() ord(getsc_i())
|
||||
#define getsc() getsc_i()
|
||||
#else
|
||||
static int getsc_r(int);
|
||||
|
||||
@ -141,7 +146,7 @@ getsc_r(int c)
|
||||
o_getsc_r(c);
|
||||
}
|
||||
|
||||
#define getsc() ord(getsc_r(o_getsc()))
|
||||
#define getsc() getsc_r(o_getsc())
|
||||
#endif
|
||||
|
||||
#define STATE_BSIZE 8
|
||||
@ -222,7 +227,7 @@ yylex(int cf)
|
||||
state = (cf & HEREDELIM) ? SHEREDELIM : SBASE;
|
||||
while (ctype((c = getsc()), C_BLANK))
|
||||
;
|
||||
if (c == '#') {
|
||||
if (ord(c) == '#') {
|
||||
ignore_backslash_newline++;
|
||||
while (!ctype((c = getsc()), C_NUL | C_LF))
|
||||
;
|
||||
@ -245,30 +250,32 @@ yylex(int cf)
|
||||
while (!((c = getsc()) == 0 ||
|
||||
((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) {
|
||||
if (state == SBASE &&
|
||||
subshell_nesting_type == ord(/*{*/ '}') &&
|
||||
c == ord(/*{*/ '}'))
|
||||
subshell_nesting_type == ORD(/*{*/ '}') &&
|
||||
(unsigned int)c == ORD(/*{*/ '}'))
|
||||
/* possibly end ${ :;} */
|
||||
break;
|
||||
Xcheck(ws, wp);
|
||||
switch (state) {
|
||||
case SADELIM:
|
||||
if (c == ord('('))
|
||||
if ((unsigned int)c == ORD('('))
|
||||
statep->nparen++;
|
||||
else if (c == ord(')'))
|
||||
else if ((unsigned int)c == ORD(')'))
|
||||
statep->nparen--;
|
||||
else if (statep->nparen == 0 && (c == ord(/*{*/ '}') ||
|
||||
else if (statep->nparen == 0 &&
|
||||
((unsigned int)c == ORD(/*{*/ '}') ||
|
||||
c == (int)statep->ls_adelim.delimiter)) {
|
||||
*wp++ = ADELIM;
|
||||
*wp++ = c;
|
||||
if (c == ord(/*{*/ '}') || --statep->ls_adelim.num == 0)
|
||||
if ((unsigned int)c == ORD(/*{*/ '}') ||
|
||||
--statep->ls_adelim.num == 0)
|
||||
POP_STATE();
|
||||
if (c == ord(/*{*/ '}'))
|
||||
if ((unsigned int)c == ORD(/*{*/ '}'))
|
||||
POP_STATE();
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case SBASE:
|
||||
if (c == ord('[') && (cf & CMDASN)) {
|
||||
if ((unsigned int)c == ORD('[') && (cf & CMDASN)) {
|
||||
/* temporary */
|
||||
*wp = EOS;
|
||||
if (is_wdvarname(Xstring(ws, wp), false)) {
|
||||
@ -294,7 +301,7 @@ yylex(int cf)
|
||||
Sbase1: /* includes *(...|...) pattern (*+?@!) */
|
||||
if (ctype(c, C_PATMO)) {
|
||||
c2 = getsc();
|
||||
if (c2 == ord('(' /*)*/)) {
|
||||
if ((unsigned int)c2 == ORD('(' /*)*/)) {
|
||||
*wp++ = OPAT;
|
||||
*wp++ = c;
|
||||
PUSH_STATE(SPATTERN);
|
||||
@ -305,7 +312,7 @@ yylex(int cf)
|
||||
/* FALLTHROUGH */
|
||||
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
|
||||
switch (c) {
|
||||
case ord('\\'):
|
||||
case CORD('\\'):
|
||||
getsc_qchar:
|
||||
if ((c = getsc())) {
|
||||
/* trailing \ is lost */
|
||||
@ -313,7 +320,7 @@ yylex(int cf)
|
||||
*wp++ = c;
|
||||
}
|
||||
break;
|
||||
case ord('\''):
|
||||
case CORD('\''):
|
||||
open_ssquote_unless_heredoc:
|
||||
if ((cf & HEREDOC))
|
||||
goto store_char;
|
||||
@ -321,12 +328,12 @@ yylex(int cf)
|
||||
ignore_backslash_newline++;
|
||||
PUSH_STATE(SSQUOTE);
|
||||
break;
|
||||
case ord('"'):
|
||||
case CORD('"'):
|
||||
open_sdquote:
|
||||
*wp++ = OQUOTE;
|
||||
PUSH_STATE(SDQUOTE);
|
||||
break;
|
||||
case ord('$'):
|
||||
case CORD('$'):
|
||||
/*
|
||||
* processing of dollar sign belongs into
|
||||
* Subst, except for those which can open
|
||||
@ -335,9 +342,9 @@ yylex(int cf)
|
||||
subst_dollar_ex:
|
||||
c = getsc();
|
||||
switch (c) {
|
||||
case ord('"'):
|
||||
case CORD('"'):
|
||||
goto open_sdquote;
|
||||
case ord('\''):
|
||||
case CORD('\''):
|
||||
goto open_sequote;
|
||||
default:
|
||||
goto SubstS;
|
||||
@ -349,16 +356,16 @@ yylex(int cf)
|
||||
|
||||
Subst:
|
||||
switch (c) {
|
||||
case ord('\\'):
|
||||
case CORD('\\'):
|
||||
c = getsc();
|
||||
switch (c) {
|
||||
case ord('"'):
|
||||
case CORD('"'):
|
||||
if ((cf & HEREDOC))
|
||||
goto heredocquote;
|
||||
/* FALLTHROUGH */
|
||||
case ord('\\'):
|
||||
case ord('$'):
|
||||
case ord('`'):
|
||||
case CORD('\\'):
|
||||
case CORD('$'):
|
||||
case CORD('`'):
|
||||
store_qchar:
|
||||
*wp++ = QCHAR;
|
||||
*wp++ = c;
|
||||
@ -376,12 +383,12 @@ yylex(int cf)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ord('$'):
|
||||
case CORD('$'):
|
||||
c = getsc();
|
||||
SubstS:
|
||||
if (c == ord('(' /*)*/)) {
|
||||
if ((unsigned int)c == ORD('(' /*)*/)) {
|
||||
c = getsc();
|
||||
if (c == ord('(' /*)*/)) {
|
||||
if ((unsigned int)c == ORD('(' /*)*/)) {
|
||||
*wp++ = EXPRSUB;
|
||||
PUSH_SRETRACE(SASPAREN);
|
||||
statep->nparen = 2;
|
||||
@ -398,8 +405,8 @@ yylex(int cf)
|
||||
memcpy(wp, sp, cz);
|
||||
wp += cz;
|
||||
}
|
||||
} else if (c == ord('{' /*}*/)) {
|
||||
if ((c = getsc()) == ord('|')) {
|
||||
} else if ((unsigned int)c == ORD('{' /*}*/)) {
|
||||
if ((unsigned int)(c = getsc()) == ORD('|')) {
|
||||
/*
|
||||
* non-subenvironment
|
||||
* value substitution
|
||||
@ -420,11 +427,11 @@ yylex(int cf)
|
||||
wp = get_brace_var(&ws, wp);
|
||||
c = getsc();
|
||||
/* allow :# and :% (ksh88 compat) */
|
||||
if (c == ord(':')) {
|
||||
if ((unsigned int)c == ORD(':')) {
|
||||
*wp++ = CHAR;
|
||||
*wp++ = c;
|
||||
c = getsc();
|
||||
if (c == ord(':')) {
|
||||
if ((unsigned int)c == ORD(':')) {
|
||||
*wp++ = CHAR;
|
||||
*wp++ = '0';
|
||||
*wp++ = ADELIM;
|
||||
@ -456,7 +463,7 @@ yylex(int cf)
|
||||
parse_adelim_slash:
|
||||
*wp++ = CHAR;
|
||||
*wp++ = c;
|
||||
if ((c = getsc()) == ord('/')) {
|
||||
if ((unsigned int)(c = getsc()) == ORD('/')) {
|
||||
*wp++ = c2;
|
||||
*wp++ = c;
|
||||
} else
|
||||
@ -470,7 +477,7 @@ yylex(int cf)
|
||||
} else if (c == '@') {
|
||||
c2 = getsc();
|
||||
ungetsc(c2);
|
||||
if (c2 == ord('/')) {
|
||||
if ((unsigned int)c2 == ORD('/')) {
|
||||
c2 = CHAR;
|
||||
goto parse_adelim_slash;
|
||||
}
|
||||
@ -519,7 +526,7 @@ yylex(int cf)
|
||||
ungetsc(c);
|
||||
}
|
||||
break;
|
||||
case ord('`'):
|
||||
case CORD('`'):
|
||||
subst_gravis:
|
||||
PUSH_STATE(SBQUOTE);
|
||||
*wp++ = COMASUB;
|
||||
@ -563,11 +570,11 @@ yylex(int cf)
|
||||
break;
|
||||
|
||||
case SEQUOTE:
|
||||
if (c == ord('\'')) {
|
||||
if ((unsigned int)c == ORD('\'')) {
|
||||
POP_STATE();
|
||||
*wp++ = CQUOTE;
|
||||
ignore_backslash_newline--;
|
||||
} else if (c == ord('\\')) {
|
||||
} else if ((unsigned int)c == ORD('\\')) {
|
||||
if ((c2 = unbksl(true, getsc_i, ungetsc)) == -1)
|
||||
c2 = getsc();
|
||||
if (c2 == 0)
|
||||
@ -595,7 +602,7 @@ yylex(int cf)
|
||||
break;
|
||||
|
||||
case SSQUOTE:
|
||||
if (c == ord('\'')) {
|
||||
if ((unsigned int)c == ORD('\'')) {
|
||||
POP_STATE();
|
||||
if ((cf & HEREDOC) || state == SQBRACE)
|
||||
goto store_char;
|
||||
@ -608,7 +615,7 @@ yylex(int cf)
|
||||
break;
|
||||
|
||||
case SDQUOTE:
|
||||
if (c == ord('"')) {
|
||||
if ((unsigned int)c == ORD('"')) {
|
||||
POP_STATE();
|
||||
*wp++ = CQUOTE;
|
||||
} else
|
||||
@ -617,15 +624,15 @@ yylex(int cf)
|
||||
|
||||
/* $(( ... )) */
|
||||
case SASPAREN:
|
||||
if (c == ord('('))
|
||||
if ((unsigned int)c == ORD('('))
|
||||
statep->nparen++;
|
||||
else if (c == ord(')')) {
|
||||
else if ((unsigned int)c == ORD(')')) {
|
||||
statep->nparen--;
|
||||
if (statep->nparen == 1) {
|
||||
/* end of EXPRSUB */
|
||||
POP_SRETRACE();
|
||||
|
||||
if ((c2 = getsc()) == ord(/*(*/ ')')) {
|
||||
if ((unsigned int)(c2 = getsc()) == ORD(/*(*/ ')')) {
|
||||
cz = strlen(sp) - 2;
|
||||
XcheckN(ws, wp, cz);
|
||||
memcpy(wp, sp + 1, cz);
|
||||
@ -657,7 +664,7 @@ yylex(int cf)
|
||||
goto Sbase2;
|
||||
|
||||
case SQBRACE:
|
||||
if (c == ord('\\')) {
|
||||
if ((unsigned int)c == ORD('\\')) {
|
||||
/*
|
||||
* perform POSIX "quote removal" if the back-
|
||||
* slash is "special", i.e. same cases as the
|
||||
@ -666,26 +673,28 @@ yylex(int cf)
|
||||
* write QCHAR+c, otherwise CHAR+\+CHAR+c are
|
||||
* emitted (in heredocquote:)
|
||||
*/
|
||||
if ((c = getsc()) == ord('"') || c == ord('\\') ||
|
||||
ctype(c, C_DOLAR | C_GRAVE) || c == ord(/*{*/ '}'))
|
||||
if ((unsigned int)(c = getsc()) == ORD('"') ||
|
||||
(unsigned int)c == ORD('\\') ||
|
||||
ctype(c, C_DOLAR | C_GRAVE) ||
|
||||
(unsigned int)c == ORD(/*{*/ '}'))
|
||||
goto store_qchar;
|
||||
goto heredocquote;
|
||||
}
|
||||
goto common_SQBRACE;
|
||||
|
||||
case SBRACE:
|
||||
if (c == ord('\''))
|
||||
if ((unsigned int)c == ORD('\''))
|
||||
goto open_ssquote_unless_heredoc;
|
||||
else if (c == ord('\\'))
|
||||
else if ((unsigned int)c == ORD('\\'))
|
||||
goto getsc_qchar;
|
||||
common_SQBRACE:
|
||||
if (c == ord('"'))
|
||||
if ((unsigned int)c == ORD('"'))
|
||||
goto open_sdquote;
|
||||
else if (c == ord('$'))
|
||||
else if ((unsigned int)c == ORD('$'))
|
||||
goto subst_dollar_ex;
|
||||
else if (c == ord('`'))
|
||||
else if ((unsigned int)c == ORD('`'))
|
||||
goto subst_gravis;
|
||||
else if (c != ord(/*{*/ '}'))
|
||||
else if ((unsigned int)c != ORD(/*{*/ '}'))
|
||||
goto store_char;
|
||||
POP_STATE();
|
||||
*wp++ = CSUBST;
|
||||
@ -694,16 +703,16 @@ yylex(int cf)
|
||||
|
||||
/* Same as SBASE, except (,|,) treated specially */
|
||||
case STBRACEKORN:
|
||||
if (c == ord('|'))
|
||||
if ((unsigned int)c == ORD('|'))
|
||||
*wp++ = SPAT;
|
||||
else if (c == ord('(')) {
|
||||
else if ((unsigned int)c == ORD('(')) {
|
||||
*wp++ = OPAT;
|
||||
/* simile for @ */
|
||||
*wp++ = ' ';
|
||||
PUSH_STATE(SPATTERN);
|
||||
} else /* FALLTHROUGH */
|
||||
case STBRACEBOURNE:
|
||||
if (c == ord(/*{*/ '}')) {
|
||||
if ((unsigned int)c == ORD(/*{*/ '}')) {
|
||||
POP_STATE();
|
||||
*wp++ = CSUBST;
|
||||
*wp++ = /*{*/ '}';
|
||||
@ -712,20 +721,20 @@ yylex(int cf)
|
||||
break;
|
||||
|
||||
case SBQUOTE:
|
||||
if (c == ord('`')) {
|
||||
if ((unsigned int)c == ORD('`')) {
|
||||
*wp++ = 0;
|
||||
POP_STATE();
|
||||
} else if (c == ord('\\')) {
|
||||
} else if ((unsigned int)c == ORD('\\')) {
|
||||
switch (c = getsc()) {
|
||||
case 0:
|
||||
/* trailing \ is lost */
|
||||
break;
|
||||
case ord('$'):
|
||||
case ord('`'):
|
||||
case ord('\\'):
|
||||
case CORD('$'):
|
||||
case CORD('`'):
|
||||
case CORD('\\'):
|
||||
*wp++ = c;
|
||||
break;
|
||||
case ord('"'):
|
||||
case CORD('"'):
|
||||
if (statep->ls_bool) {
|
||||
*wp++ = c;
|
||||
break;
|
||||
@ -746,10 +755,10 @@ yylex(int cf)
|
||||
|
||||
/* LETEXPR: (( ... )) */
|
||||
case SLETPAREN:
|
||||
if (c == ord(/*(*/ ')')) {
|
||||
if ((unsigned int)c == ORD(/*(*/ ')')) {
|
||||
if (statep->nparen > 0)
|
||||
--statep->nparen;
|
||||
else if ((c2 = getsc()) == ord(/*(*/ ')')) {
|
||||
else if ((unsigned int)(c2 = getsc()) == ORD(/*(*/ ')')) {
|
||||
c = 0;
|
||||
*wp++ = CQUOTE;
|
||||
goto Done;
|
||||
@ -771,9 +780,9 @@ yylex(int cf)
|
||||
s->next = source;
|
||||
source = s;
|
||||
ungetsc('(' /*)*/);
|
||||
return (ord('(' /*)*/));
|
||||
return (ORD('(' /*)*/));
|
||||
}
|
||||
} else if (c == ord('('))
|
||||
} else if ((unsigned int)c == ORD('('))
|
||||
/*
|
||||
* parentheses inside quotes and
|
||||
* backslashes are lost, but AT&T ksh
|
||||
@ -789,26 +798,26 @@ yylex(int cf)
|
||||
* $ and `...` are not to be treated specially
|
||||
*/
|
||||
switch (c) {
|
||||
case ord('\\'):
|
||||
case CORD('\\'):
|
||||
if ((c = getsc())) {
|
||||
/* trailing \ is lost */
|
||||
*wp++ = QCHAR;
|
||||
*wp++ = c;
|
||||
}
|
||||
break;
|
||||
case ord('\''):
|
||||
case CORD('\''):
|
||||
goto open_ssquote_unless_heredoc;
|
||||
case ord('$'):
|
||||
if ((c2 = getsc()) == ord('\'')) {
|
||||
case CORD('$'):
|
||||
if ((unsigned int)(c2 = getsc()) == ORD('\'')) {
|
||||
open_sequote:
|
||||
*wp++ = OQUOTE;
|
||||
ignore_backslash_newline++;
|
||||
PUSH_STATE(SEQUOTE);
|
||||
statep->ls_bool = false;
|
||||
break;
|
||||
} else if (c2 == ord('"')) {
|
||||
} else if ((unsigned int)c2 == ORD('"')) {
|
||||
/* FALLTHROUGH */
|
||||
case ord('"'):
|
||||
case CORD('"'):
|
||||
PUSH_SRETRACE(SHEREDQUOTE);
|
||||
break;
|
||||
}
|
||||
@ -822,7 +831,7 @@ yylex(int cf)
|
||||
|
||||
/* " in << or <<- delimiter */
|
||||
case SHEREDQUOTE:
|
||||
if (c != ord('"'))
|
||||
if ((unsigned int)c != ORD('"'))
|
||||
goto Subst;
|
||||
POP_SRETRACE();
|
||||
dp = strnul(sp) - 1;
|
||||
@ -835,10 +844,10 @@ yylex(int cf)
|
||||
while ((c = *dp++)) {
|
||||
if (c == '\\') {
|
||||
switch ((c = *dp++)) {
|
||||
case ord('\\'):
|
||||
case ord('"'):
|
||||
case ord('$'):
|
||||
case ord('`'):
|
||||
case CORD('\\'):
|
||||
case CORD('"'):
|
||||
case CORD('$'):
|
||||
case CORD('`'):
|
||||
break;
|
||||
default:
|
||||
*wp++ = CHAR;
|
||||
@ -856,12 +865,12 @@ yylex(int cf)
|
||||
|
||||
/* in *(...|...) pattern (*+?@!) */
|
||||
case SPATTERN:
|
||||
if (c == ord(/*(*/ ')')) {
|
||||
if ((unsigned int)c == ORD(/*(*/ ')')) {
|
||||
*wp++ = CPAT;
|
||||
POP_STATE();
|
||||
} else if (c == ord('|')) {
|
||||
} else if ((unsigned int)c == ORD('|')) {
|
||||
*wp++ = SPAT;
|
||||
} else if (c == ord('(')) {
|
||||
} else if ((unsigned int)c == ORD('(')) {
|
||||
*wp++ = OPAT;
|
||||
/* simile for @ */
|
||||
*wp++ = ' ';
|
||||
@ -891,7 +900,7 @@ yylex(int cf)
|
||||
iop->unit = c2 == 2 ? ksh_numdig(dp[1]) : c == '<' ? 0 : 1;
|
||||
|
||||
if (c == '&') {
|
||||
if ((c2 = getsc()) != ord('>')) {
|
||||
if ((unsigned int)(c2 = getsc()) != ORD('>')) {
|
||||
ungetsc(c2);
|
||||
goto no_iop;
|
||||
}
|
||||
@ -902,22 +911,23 @@ yylex(int cf)
|
||||
|
||||
c2 = getsc();
|
||||
/* <<, >>, <> are ok, >< is not */
|
||||
if (c == c2 || (c == ord('<') && c2 == ord('>'))) {
|
||||
if (c == c2 || ((unsigned int)c == ORD('<') &&
|
||||
(unsigned int)c2 == ORD('>'))) {
|
||||
iop->ioflag |= c == c2 ?
|
||||
(c == ord('>') ? IOCAT : IOHERE) : IORDWR;
|
||||
((unsigned int)c == ORD('>') ? IOCAT : IOHERE) : IORDWR;
|
||||
if (iop->ioflag == IOHERE) {
|
||||
if ((c2 = getsc()) == ord('-'))
|
||||
if ((unsigned int)(c2 = getsc()) == ORD('-'))
|
||||
iop->ioflag |= IOSKIP;
|
||||
else if (c2 == ord('<'))
|
||||
else if ((unsigned int)c2 == ORD('<'))
|
||||
iop->ioflag |= IOHERESTR;
|
||||
else
|
||||
ungetsc(c2);
|
||||
}
|
||||
} else if (c2 == ord('&'))
|
||||
iop->ioflag |= IODUP | (c == ord('<') ? IORDUP : 0);
|
||||
} else if ((unsigned int)c2 == ORD('&'))
|
||||
iop->ioflag |= IODUP | ((unsigned int)c == ORD('<') ? IORDUP : 0);
|
||||
else {
|
||||
iop->ioflag |= c == ord('>') ? IOWRITE : IOREAD;
|
||||
if (c == ord('>') && c2 == ord('|'))
|
||||
iop->ioflag |= (unsigned int)c == ORD('>') ? IOWRITE : IOREAD;
|
||||
if ((unsigned int)c == ORD('>') && (unsigned int)c2 == ORD('|'))
|
||||
iop->ioflag |= IOCLOB;
|
||||
else
|
||||
ungetsc(c2);
|
||||
@ -938,30 +948,32 @@ yylex(int cf)
|
||||
/* free word */
|
||||
Xfree(ws, wp);
|
||||
/* no word, process LEX1 character */
|
||||
if ((c == ord('|')) || (c == ord('&')) || (c == ord(';')) ||
|
||||
(c == ord('(' /*)*/))) {
|
||||
if (((unsigned int)c == ORD('|')) ||
|
||||
((unsigned int)c == ORD('&')) ||
|
||||
((unsigned int)c == ORD(';')) ||
|
||||
((unsigned int)c == ORD('(' /*)*/))) {
|
||||
if ((c2 = getsc()) == c)
|
||||
c = (c == ord(';')) ? BREAK :
|
||||
(c == ord('|')) ? LOGOR :
|
||||
(c == ord('&')) ? LOGAND :
|
||||
/* c == ord('(' )) */ MDPAREN;
|
||||
else if (c == ord('|') && c2 == ord('&'))
|
||||
c = ((unsigned int)c == ORD(';')) ? BREAK :
|
||||
((unsigned int)c == ORD('|')) ? LOGOR :
|
||||
((unsigned int)c == ORD('&')) ? LOGAND :
|
||||
/* (unsigned int)c == ORD('(' )) */ MDPAREN;
|
||||
else if ((unsigned int)c == ORD('|') && (unsigned int)c2 == ORD('&'))
|
||||
c = COPROC;
|
||||
else if (c == ord(';') && c2 == ord('|'))
|
||||
else if ((unsigned int)c == ORD(';') && (unsigned int)c2 == ORD('|'))
|
||||
c = BRKEV;
|
||||
else if (c == ord(';') && c2 == ord('&'))
|
||||
else if ((unsigned int)c == ORD(';') && (unsigned int)c2 == ORD('&'))
|
||||
c = BRKFT;
|
||||
else
|
||||
ungetsc(c2);
|
||||
#ifndef MKSH_SMALL
|
||||
if (c == BREAK) {
|
||||
if ((c2 = getsc()) == ord('&'))
|
||||
if ((unsigned int)(c2 = getsc()) == ORD('&'))
|
||||
c = BRKEV;
|
||||
else
|
||||
ungetsc(c2);
|
||||
}
|
||||
#endif
|
||||
} else if (c == ord('\n')) {
|
||||
} else if ((unsigned int)c == ORD('\n')) {
|
||||
if (cf & HEREDELIM)
|
||||
ungetsc(c);
|
||||
else {
|
||||
@ -1016,7 +1028,7 @@ yylex(int cf)
|
||||
|
||||
if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) &&
|
||||
(!(cf & ESACONLY) || p->val.i == ESAC ||
|
||||
p->val.i == ord(/*{*/ '}'))) {
|
||||
(unsigned int)p->val.i == ORD(/*{*/ '}'))) {
|
||||
afree(yylval.cp, ATEMP);
|
||||
return (p->val.i);
|
||||
}
|
||||
@ -1127,7 +1139,7 @@ readhere(struct ioword *iop)
|
||||
if (!*eofp) {
|
||||
/* end of here document marker, what to do? */
|
||||
switch (c) {
|
||||
case ord(/*(*/ ')'):
|
||||
case CORD(/*(*/ ')'):
|
||||
if (!subshell_nesting_type)
|
||||
/*-
|
||||
* not allowed outside $(...) or (...)
|
||||
@ -1142,7 +1154,7 @@ readhere(struct ioword *iop)
|
||||
* Allow EOF here to commands without trailing
|
||||
* newlines (mksh -c '...') will work as well.
|
||||
*/
|
||||
case ord('\n'):
|
||||
case CORD('\n'):
|
||||
/* Newline terminates here document marker */
|
||||
goto heredoc_found_terminator;
|
||||
}
|
||||
@ -1571,7 +1583,7 @@ get_brace_var(XString *wsp, char *wp)
|
||||
|
||||
c2 = getsc();
|
||||
ungetsc(c2);
|
||||
if (ord(c2) != ord(/*{*/ '}')) {
|
||||
if (ord(c2) != ORD(/*{*/ '}')) {
|
||||
ungetsc(c);
|
||||
goto out;
|
||||
}
|
||||
@ -1579,22 +1591,22 @@ get_brace_var(XString *wsp, char *wp)
|
||||
goto ps_common;
|
||||
case PS_SAW_BANG:
|
||||
switch (ord(c)) {
|
||||
case ord('@'):
|
||||
case ord('#'):
|
||||
case ord('-'):
|
||||
case ord('?'):
|
||||
case CORD('@'):
|
||||
case CORD('#'):
|
||||
case CORD('-'):
|
||||
case CORD('?'):
|
||||
goto out;
|
||||
}
|
||||
goto ps_common;
|
||||
case PS_INITIAL:
|
||||
switch (ord(c)) {
|
||||
case ord('%'):
|
||||
case CORD('%'):
|
||||
state = PS_SAW_PERCENT;
|
||||
goto next;
|
||||
case ord('#'):
|
||||
case CORD('#'):
|
||||
state = PS_SAW_HASH;
|
||||
goto next;
|
||||
case ord('!'):
|
||||
case CORD('!'):
|
||||
state = PS_SAW_BANG;
|
||||
goto next;
|
||||
}
|
||||
@ -1612,7 +1624,7 @@ get_brace_var(XString *wsp, char *wp)
|
||||
break;
|
||||
case PS_IDENT:
|
||||
if (!ctype(c, C_ALNUX)) {
|
||||
if (ord(c) == ord('[')) {
|
||||
if (ord(c) == ORD('[')) {
|
||||
char *tmp, *p;
|
||||
|
||||
if (!arraysub(&tmp))
|
||||
@ -1667,9 +1679,9 @@ arraysub(char **strp)
|
||||
c = getsc();
|
||||
Xcheck(ws, wp);
|
||||
*wp++ = c;
|
||||
if (ord(c) == ord('['))
|
||||
if (ord(c) == ORD('['))
|
||||
depth++;
|
||||
else if (ord(c) == ord(']'))
|
||||
else if (ord(c) == ORD(']'))
|
||||
depth--;
|
||||
} while (depth > 0 && c && c != '\n');
|
||||
|
||||
|
104
misc.c
104
misc.c
@ -32,7 +32,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.288 2017/10/15 20:21:51 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.289 2018/01/13 23:55:12 tg Exp $");
|
||||
|
||||
#define KSH_CHVT_FLAG
|
||||
#ifdef MKSH_SMALL
|
||||
@ -696,14 +696,14 @@ has_globbing(const char *pat)
|
||||
if (!(c = *p++))
|
||||
return (false);
|
||||
/* some specials */
|
||||
if (ord(c) == ord('*') || ord(c) == ord('?')) {
|
||||
if (ord(c) == ORD('*') || ord(c) == ORD('?')) {
|
||||
/* easy glob, accept */
|
||||
saw_glob = true;
|
||||
} else if (ord(c) == ord('[')) {
|
||||
} else if (ord(c) == ORD('[')) {
|
||||
/* bracket expression; eat negation and initial ] */
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ord('!'))
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ORD('!'))
|
||||
p += 2;
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ord(']'))
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ORD(']'))
|
||||
p += 2;
|
||||
/* check next string part */
|
||||
s = p;
|
||||
@ -715,27 +715,27 @@ has_globbing(const char *pat)
|
||||
if (!(c = *s++))
|
||||
return (false);
|
||||
/* terminating bracket? */
|
||||
if (ord(c) == ord(']')) {
|
||||
if (ord(c) == ORD(']')) {
|
||||
/* accept and continue */
|
||||
p = s;
|
||||
saw_glob = true;
|
||||
break;
|
||||
}
|
||||
/* sub-bracket expressions */
|
||||
if (ord(c) == ord('[') && (
|
||||
if (ord(c) == ORD('[') && (
|
||||
/* collating element? */
|
||||
ord(*s) == ord('.') ||
|
||||
ord(*s) == ORD('.') ||
|
||||
/* equivalence class? */
|
||||
ord(*s) == ord('=') ||
|
||||
ord(*s) == ORD('=') ||
|
||||
/* character class? */
|
||||
ord(*s) == ord(':'))) {
|
||||
ord(*s) == ORD(':'))) {
|
||||
/* must stop with exactly the same c */
|
||||
subc = *s++;
|
||||
/* arbitrarily many chars in betwixt */
|
||||
while ((c = *s++))
|
||||
/* but only this sequence... */
|
||||
if (c == subc && ISMAGIC(*s) &&
|
||||
ord(s[1]) == ord(']')) {
|
||||
ord(s[1]) == ORD(']')) {
|
||||
/* accept, terminate */
|
||||
s += 2;
|
||||
break;
|
||||
@ -751,7 +751,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;
|
||||
@ -785,24 +785,24 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
||||
continue;
|
||||
}
|
||||
switch (ord(*p++)) {
|
||||
case ord('['):
|
||||
case CORD('['):
|
||||
/* BSD cclass extension? */
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ord('[') &&
|
||||
ord(p[2]) == ord(':') &&
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ORD('[') &&
|
||||
ord(p[2]) == ORD(':') &&
|
||||
ctype((pc = p[3]), C_ANGLE) &&
|
||||
ord(p[4]) == ord(':') &&
|
||||
ISMAGIC(p[5]) && ord(p[6]) == ord(']') &&
|
||||
ISMAGIC(p[7]) && ord(p[8]) == ord(']')) {
|
||||
ord(p[4]) == ORD(':') &&
|
||||
ISMAGIC(p[5]) && ord(p[6]) == ORD(']') &&
|
||||
ISMAGIC(p[7]) && ord(p[8]) == ORD(']')) {
|
||||
/* zero-length match */
|
||||
--s;
|
||||
p += 9;
|
||||
/* word begin? */
|
||||
if (ord(pc) == ord('<') &&
|
||||
if (ord(pc) == ORD('<') &&
|
||||
!ctype(sl, C_ALNUX) &&
|
||||
ctype(sc, C_ALNUX))
|
||||
break;
|
||||
/* word end? */
|
||||
if (ord(pc) == ord('>') &&
|
||||
if (ord(pc) == ORD('>') &&
|
||||
ctype(sl, C_ALNUX) &&
|
||||
!ctype(sc, C_ALNUX))
|
||||
break;
|
||||
@ -813,7 +813,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
||||
return (0);
|
||||
break;
|
||||
|
||||
case ord('?'):
|
||||
case CORD('?'):
|
||||
if (sc == 0)
|
||||
return (0);
|
||||
if (UTFMODE) {
|
||||
@ -822,7 +822,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
||||
}
|
||||
break;
|
||||
|
||||
case ord('*'):
|
||||
case CORD('*'):
|
||||
if (p == pe)
|
||||
return (1);
|
||||
s--;
|
||||
@ -838,14 +838,14 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
||||
*/
|
||||
|
||||
/* matches one or more times */
|
||||
case 0x80|ord('+'):
|
||||
case CORD('+') | 0x80:
|
||||
/* matches zero or more times */
|
||||
case 0x80|ord('*'):
|
||||
case CORD('*') | 0x80:
|
||||
if (!(prest = pat_scan(p, pe, false)))
|
||||
return (0);
|
||||
s--;
|
||||
/* take care of zero matches */
|
||||
if (ord(p[-1]) == (0x80 | ord('*')) &&
|
||||
if (ord(p[-1]) == (0x80 | ORD('*')) &&
|
||||
do_gmatch(s, se, prest, pe, smin))
|
||||
return (1);
|
||||
for (psub = p; ; psub = pnext) {
|
||||
@ -863,16 +863,16 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
||||
return (0);
|
||||
|
||||
/* matches zero or once */
|
||||
case 0x80|ord('?'):
|
||||
case CORD('?') | 0x80:
|
||||
/* matches one of the patterns */
|
||||
case 0x80|ord('@'):
|
||||
case CORD('@') | 0x80:
|
||||
/* simile for @ */
|
||||
case 0x80|ord(' '):
|
||||
case CORD(' ') | 0x80:
|
||||
if (!(prest = pat_scan(p, pe, false)))
|
||||
return (0);
|
||||
s--;
|
||||
/* Take care of zero matches */
|
||||
if (ord(p[-1]) == (0x80 | ord('?')) &&
|
||||
if (ord(p[-1]) == (0x80 | ORD('?')) &&
|
||||
do_gmatch(s, se, prest, pe, smin))
|
||||
return (1);
|
||||
for (psub = p; ; psub = pnext) {
|
||||
@ -889,7 +889,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
||||
return (0);
|
||||
|
||||
/* matches none of the patterns */
|
||||
case 0x80|ord('!'):
|
||||
case CORD('!') | 0x80:
|
||||
if (!(prest = pat_scan(p, pe, false)))
|
||||
return (0);
|
||||
s--;
|
||||
@ -966,12 +966,12 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
char *subp;
|
||||
|
||||
/* check for negation */
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ord('!')) {
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ORD('!')) {
|
||||
p += 2;
|
||||
negated = true;
|
||||
}
|
||||
/* make initial ] non-MAGIC */
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ord(']'))
|
||||
if (ISMAGIC(p[0]) && ord(p[1]) == ORD(']'))
|
||||
++p;
|
||||
/* iterate over bracket expression, debunk()ing on the fly */
|
||||
while ((c = *p++)) {
|
||||
@ -982,18 +982,18 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
if (!(c = *p++))
|
||||
break;
|
||||
/* terminating bracket? */
|
||||
if (ord(c) == ord(']')) {
|
||||
if (ord(c) == ORD(']')) {
|
||||
/* accept and return */
|
||||
return (found != negated ? p : NULL);
|
||||
}
|
||||
/* sub-bracket expressions */
|
||||
if (ord(c) == ord('[') && (
|
||||
if (ord(c) == ORD('[') && (
|
||||
/* collating element? */
|
||||
ord(*p) == ord('.') ||
|
||||
ord(*p) == ORD('.') ||
|
||||
/* equivalence class? */
|
||||
ord(*p) == ord('=') ||
|
||||
ord(*p) == ORD('=') ||
|
||||
/* character class? */
|
||||
ord(*p) == ord(':'))) {
|
||||
ord(*p) == ORD(':'))) {
|
||||
/* must stop with exactly the same c */
|
||||
subc = *p++;
|
||||
/* save away start of substring */
|
||||
@ -1002,7 +1002,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
while ((c = *p++))
|
||||
/* but only this sequence... */
|
||||
if (c == subc && ISMAGIC(*p) &&
|
||||
ord(p[1]) == ord(']')) {
|
||||
ord(p[1]) == ORD(']')) {
|
||||
/* accept, terminate */
|
||||
p += 2;
|
||||
break;
|
||||
@ -1015,7 +1015,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
debunk(subp, subp, p - s - 3 + 1);
|
||||
cclass_common:
|
||||
/* whither subexpression */
|
||||
if (ord(subc) == ord(':')) {
|
||||
if (ord(subc) == ORD(':')) {
|
||||
const struct cclass *cls = cclasses;
|
||||
|
||||
/* search for name in cclass list */
|
||||
@ -1055,9 +1055,9 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
}
|
||||
}
|
||||
/* range expression? */
|
||||
if (!(ISMAGIC(p[0]) && ord(p[1]) == ord('-') &&
|
||||
if (!(ISMAGIC(p[0]) && ord(p[1]) == ORD('-') &&
|
||||
/* not terminating bracket? */
|
||||
(!ISMAGIC(p[2]) || ord(p[3]) != ord(']')))) {
|
||||
(!ISMAGIC(p[2]) || ord(p[3]) != ORD(']')))) {
|
||||
/* no, check single match */
|
||||
if (sc == c)
|
||||
/* note: sc is never NUL */
|
||||
@ -1079,13 +1079,13 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
if (!(c = *p++))
|
||||
break;
|
||||
/* sub-bracket expressions */
|
||||
if (ord(c) == ord('[') && (
|
||||
if (ord(c) == ORD('[') && (
|
||||
/* collating element? */
|
||||
ord(*p) == ord('.') ||
|
||||
ord(*p) == ORD('.') ||
|
||||
/* equivalence class? */
|
||||
ord(*p) == ord('=') ||
|
||||
ord(*p) == ORD('=') ||
|
||||
/* character class? */
|
||||
ord(*p) == ord(':'))) {
|
||||
ord(*p) == ORD(':'))) {
|
||||
/* must stop with exactly the same c */
|
||||
subc = *p++;
|
||||
/* save away start of substring */
|
||||
@ -1094,7 +1094,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
while ((c = *p++))
|
||||
/* but only this sequence... */
|
||||
if (c == subc && ISMAGIC(*p) &&
|
||||
ord(p[1]) == ord(']')) {
|
||||
ord(p[1]) == ORD(']')) {
|
||||
/* accept, terminate */
|
||||
p += 2;
|
||||
break;
|
||||
@ -1106,14 +1106,14 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
strndupx(subp, s, p - s - 3, ATEMP);
|
||||
debunk(subp, subp, p - s - 3 + 1);
|
||||
/* whither subexpression */
|
||||
if (ord(subc) == ord(':')) {
|
||||
if (ord(subc) == ORD(':')) {
|
||||
/* oops, not a range */
|
||||
|
||||
/* match single previous char */
|
||||
if (lc && (sc == lc))
|
||||
found = true;
|
||||
/* match hyphen-minus */
|
||||
if (ord(sc) == ord('-'))
|
||||
if (ord(sc) == ORD('-'))
|
||||
found = true;
|
||||
/* handle cclass common part */
|
||||
goto cclass_common;
|
||||
@ -1151,7 +1151,7 @@ gmatch_cclass(const unsigned char *pat, unsigned char sc)
|
||||
/* otherwise, just go on with the pattern string */
|
||||
}
|
||||
/* if we broke here, the bracket expression was invalid */
|
||||
if (ord(sc) == ord('['))
|
||||
if (ord(sc) == ORD('['))
|
||||
/* initial opening bracket as literal match */
|
||||
return (pat);
|
||||
/* or rather no match */
|
||||
@ -1664,7 +1664,7 @@ do_realpath(const char *upath)
|
||||
#ifdef MKSH_DOSPATH
|
||||
} else if (mksh_drvltr(upath)) {
|
||||
/* upath is a drive-relative pathname */
|
||||
if (getdrvwd(&ldest, ord(*upath)))
|
||||
if (getdrvwd(&ldest, ORD(*upath)))
|
||||
return (NULL);
|
||||
/* A:foo -> A:/cwd/foo; A: -> A:/cwd */
|
||||
ipath = shf_smprintf(Tf_sss, ldest,
|
||||
@ -1783,7 +1783,7 @@ do_realpath(const char *upath)
|
||||
#ifdef MKSH_DOSPATH
|
||||
/* symlink target might be drive-relative */
|
||||
if (mksh_drvltr(ipath)) {
|
||||
if (getdrvwd(&ldest, ord(*ipath)))
|
||||
if (getdrvwd(&ldest, ORD(*ipath)))
|
||||
goto notfound;
|
||||
ip += 2;
|
||||
goto assemble_symlink;
|
||||
@ -2191,7 +2191,7 @@ c_cd(const char **wp)
|
||||
#ifdef MKSH_DOSPATH
|
||||
tryp = NULL;
|
||||
if (mksh_drvltr(dir) && !mksh_cdirsep(dir[2]) &&
|
||||
!getdrvwd(&tryp, ord(*dir))) {
|
||||
!getdrvwd(&tryp, ORD(*dir))) {
|
||||
dir = shf_smprintf(Tf_sss, tryp,
|
||||
dir[2] ? "/" : "", dir + 2);
|
||||
afree(tryp, ATEMP);
|
||||
|
36
sh.h
36
sh.h
@ -10,7 +10,7 @@
|
||||
|
||||
/*-
|
||||
* Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||||
* mirabilos <m@mirbsd.org>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
@ -182,7 +182,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.850 2018/01/13 21:38:09 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.851 2018/01/13 23:55:13 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R56 2017/10/17"
|
||||
|
||||
@ -556,7 +556,7 @@ extern int __cdecl setegid(gid_t);
|
||||
* low-bit7 at least on cp1047 so YMMV
|
||||
*/
|
||||
#define MAGIC KSH_BEL /* prefix for *?[!{,} during expand */
|
||||
#define ISMAGIC(c) (ord(c) == ord(MAGIC))
|
||||
#define ISMAGIC(c) (ord(c) == ORD(MAGIC))
|
||||
|
||||
EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */
|
||||
|
||||
@ -804,7 +804,7 @@ struct sretrace_info;
|
||||
struct yyrecursive_state;
|
||||
|
||||
EXTERN struct sretrace_info *retrace_info;
|
||||
EXTERN int subshell_nesting_type;
|
||||
EXTERN unsigned int subshell_nesting_type;
|
||||
|
||||
extern struct env {
|
||||
ALLOC_ITEM alloc_INT; /* internal, do not touch */
|
||||
@ -1469,7 +1469,25 @@ EXTERN char ifs0;
|
||||
#define C_UNDER CiUNDER /* _ underscore */
|
||||
|
||||
/* identity transform of octet */
|
||||
#if defined(DEBUG) && defined(__GNUC__) && !defined(__ICC) && \
|
||||
!defined(__INTEL_COMPILER) && !defined(__SUNPRO_C)
|
||||
extern unsigned int eek_ord;
|
||||
#define ORD(c) ((size_t)(c) > 0xFF ? eek_ord : \
|
||||
((unsigned int)(unsigned char)(c)))
|
||||
#define ord(c) ({ \
|
||||
size_t ord_c = (c); \
|
||||
\
|
||||
if (ord_c > 0xFF) \
|
||||
internal_errorf("%s:%d:ord(%zu)", \
|
||||
__FILE__, __LINE__, ord_c); \
|
||||
((unsigned int)(unsigned char)(c)); \
|
||||
})
|
||||
#define CORD(c) ORD(c)
|
||||
#else
|
||||
#define ord(c) ((unsigned int)(unsigned char)(c))
|
||||
#define ORD(c) ((void)(c), ord(c))
|
||||
#define CORD(c) ord(c)
|
||||
#endif
|
||||
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
|
||||
EXTERN unsigned short ebcdic_map[256];
|
||||
EXTERN unsigned char ebcdic_rtt_toascii[256];
|
||||
@ -1492,7 +1510,7 @@ extern void ebcdic_init(void);
|
||||
#ifdef MKSH_EBCDIC
|
||||
#define ksh_isctrl(c) (ord(c) < 0x40 || ord(c) == 0xFF)
|
||||
#else
|
||||
#define ksh_isctrl(c) ((ord(c) & 0x7F) < 0x20 || (c) == 0x7F)
|
||||
#define ksh_isctrl(c) ((ord(c) & 0x7F) < 0x20 || ord(c) == 0x7F)
|
||||
#endif
|
||||
/* new fast character classes */
|
||||
#define ctype(c,t) tobool(ksh_ctypes[ord(c)] & (t))
|
||||
@ -1502,10 +1520,10 @@ extern void ebcdic_init(void);
|
||||
#define ksh_tolower(c) (ctype(c, C_UPPER) ? (c) - 'A' + 'a' : (c))
|
||||
#define ksh_toupper(c) (ctype(c, C_LOWER) ? (c) - 'a' + 'A' : (c))
|
||||
/* strictly speaking rtt2asc() here, but this works even in EBCDIC */
|
||||
#define ksh_numdig(c) (ord(c) - ord('0'))
|
||||
#define ksh_numdig(c) (ord(c) - ORD('0'))
|
||||
#define ksh_numuc(c) (rtt2asc(c) - rtt2asc('A'))
|
||||
#define ksh_numlc(c) (rtt2asc(c) - rtt2asc('a'))
|
||||
#define ksh_toctrl(c) asc2rtt(ord(c) == ord('?') ? 0x7F : rtt2asc(c) & 0x9F)
|
||||
#define ksh_toctrl(c) asc2rtt(ord(c) == ORD('?') ? 0x7F : rtt2asc(c) & 0x9F)
|
||||
#define ksh_unctrl(c) asc2rtt(rtt2asc(c) ^ 0x40U)
|
||||
|
||||
/* Argument parsing for built-in commands and getopts command */
|
||||
@ -2759,8 +2777,8 @@ extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */
|
||||
})
|
||||
int getdrvwd(char **, unsigned int);
|
||||
#else
|
||||
#define mksh_abspath(s) (ord((s)[0]) == ord('/'))
|
||||
#define mksh_cdirsep(c) (ord(c) == ord('/'))
|
||||
#define mksh_abspath(s) (ord((s)[0]) == ORD('/'))
|
||||
#define mksh_cdirsep(c) (ord(c) == ORD('/'))
|
||||
#define mksh_sdirsep(s) strchr((s), '/')
|
||||
#define mksh_vdirsep(s) vstrchr((s), '/')
|
||||
#endif
|
||||
|
4
shf.c
4
shf.c
@ -27,7 +27,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.95 2017/05/05 22:45:58 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.96 2018/01/13 23:55:14 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@ -1253,7 +1253,7 @@ set_ifs(const char *s)
|
||||
* Not only do they require all 8 bits instead of 7, if chars are
|
||||
* signed, they will have negative integer values! Something like
|
||||
* (c - 'A') could actually become (c + 63)! Use the ord() macro to
|
||||
* ensure you're getting a value in [0, 255].
|
||||
* ensure you're getting a value in [0, 255] (ORD for constants).
|
||||
* 4. '\n' is actually NL (0x15, U+0085) instead of LF (0x25, U+000A).
|
||||
* EBCDIC has a proper newline character instead of "emulating" one
|
||||
* with line feeds, although this is mapped to LF for our purposes.
|
||||
|
81
syn.c
81
syn.c
@ -2,7 +2,8 @@
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017
|
||||
* 2011, 2012, 2013, 2014, 2015, 2016, 2017,
|
||||
* 2018
|
||||
* mirabilos <m@mirbsd.org>
|
||||
*
|
||||
* Provided that these terms and disclaimer and all copyright notices
|
||||
@ -23,7 +24,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.124 2017/05/05 22:53:31 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.125 2018/01/13 23:55:14 tg Exp $");
|
||||
|
||||
struct nesting_state {
|
||||
int start_token; /* token than began nesting (eg, FOR) */
|
||||
@ -35,7 +36,7 @@ struct yyrecursive_state {
|
||||
struct yyrecursive_state *next;
|
||||
struct ioword **old_herep;
|
||||
int old_symbol;
|
||||
int old_nesting_type;
|
||||
unsigned int old_nesting_type;
|
||||
bool old_reject;
|
||||
};
|
||||
|
||||
@ -75,7 +76,10 @@ static int symbol; /* yylex value */
|
||||
#define ACCEPT (reject = false)
|
||||
#define token(cf) ((reject) ? (ACCEPT, symbol) : (symbol = yylex(cf)))
|
||||
#define tpeek(cf) ((reject) ? (symbol) : (REJECT, symbol = yylex(cf)))
|
||||
#define musthave(c,cf) do { if (token(cf) != (c)) syntaxerr(NULL); } while (/* CONSTCOND */ 0)
|
||||
#define musthave(c,cf) do { \
|
||||
if ((unsigned int)token(cf) != (unsigned int)(c)) \
|
||||
syntaxerr(NULL); \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
static const char Tcbrace[] = "}";
|
||||
static const char Tesac[] = "esac";
|
||||
@ -330,7 +334,7 @@ get_command(int cf, int sALIAS)
|
||||
XPput(args, yylval.cp);
|
||||
break;
|
||||
|
||||
case ord('(' /*)*/):
|
||||
case CORD('(' /*)*/):
|
||||
if (XPsize(args) == 0 && XPsize(vars) == 1 &&
|
||||
is_wdvarassign(yylval.cp)) {
|
||||
char *tcp;
|
||||
@ -386,18 +390,18 @@ get_command(int cf, int sALIAS)
|
||||
Leave:
|
||||
break;
|
||||
|
||||
case ord('(' /*)*/): {
|
||||
int subshell_nesting_type_saved;
|
||||
case CORD('(' /*)*/): {
|
||||
unsigned int subshell_nesting_type_saved;
|
||||
Subshell:
|
||||
subshell_nesting_type_saved = subshell_nesting_type;
|
||||
subshell_nesting_type = ord(')');
|
||||
t = nested(TPAREN, ord('('), ord(')'), sALIAS);
|
||||
subshell_nesting_type = ORD(')');
|
||||
t = nested(TPAREN, ORD('('), ORD(')'), sALIAS);
|
||||
subshell_nesting_type = subshell_nesting_type_saved;
|
||||
break;
|
||||
}
|
||||
|
||||
case ord('{' /*}*/):
|
||||
t = nested(TBRACE, ord('{'), ord('}'), sALIAS);
|
||||
case CORD('{' /*}*/):
|
||||
t = nested(TBRACE, ORD('{'), ORD('}'), sALIAS);
|
||||
break;
|
||||
|
||||
case MDPAREN:
|
||||
@ -407,8 +411,8 @@ get_command(int cf, int sALIAS)
|
||||
switch (token(LETEXPR)) {
|
||||
case LWORD:
|
||||
break;
|
||||
case ord('(' /*)*/):
|
||||
c = ord('(');
|
||||
case CORD('(' /*)*/):
|
||||
c = ORD('(');
|
||||
goto Subshell;
|
||||
default:
|
||||
syntaxerr(NULL);
|
||||
@ -554,8 +558,8 @@ dogroup(int sALIAS)
|
||||
*/
|
||||
if (c == DO)
|
||||
c = DONE;
|
||||
else if (c == ord('{'))
|
||||
c = ord('}');
|
||||
else if ((unsigned int)c == ORD('{'))
|
||||
c = ORD('}');
|
||||
else
|
||||
syntaxerr(NULL);
|
||||
list = c_list(sALIAS, true);
|
||||
@ -610,8 +614,8 @@ caselist(int sALIAS)
|
||||
/* A {...} can be used instead of in...esac for case statements */
|
||||
if (c == IN)
|
||||
c = ESAC;
|
||||
else if (c == ord('{'))
|
||||
c = ord('}');
|
||||
else if ((unsigned int)c == ORD('{'))
|
||||
c = ORD('}');
|
||||
else
|
||||
syntaxerr(NULL);
|
||||
t = tl = NULL;
|
||||
@ -636,18 +640,17 @@ casepart(int endtok, int sALIAS)
|
||||
XPinit(ptns, 16);
|
||||
t = newtp(TPAT);
|
||||
/* no ALIAS here */
|
||||
if (token(CONTIN | KEYWORD) != ord('('))
|
||||
if ((unsigned int)token(CONTIN | KEYWORD) != ORD('('))
|
||||
REJECT;
|
||||
do {
|
||||
switch (token(0)) {
|
||||
case LWORD:
|
||||
break;
|
||||
case ord('}'):
|
||||
case CORD('}'):
|
||||
case ESAC:
|
||||
if (symbol != endtok) {
|
||||
strdupx(yylval.cp,
|
||||
symbol == ord('}') ? Tcbrace : Tesac,
|
||||
ATEMP);
|
||||
strdupx(yylval.cp, (unsigned int)symbol ==
|
||||
ORD('}') ? Tcbrace : Tesac, ATEMP);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
@ -659,23 +662,23 @@ casepart(int endtok, int sALIAS)
|
||||
REJECT;
|
||||
XPput(ptns, NULL);
|
||||
t->vars = (char **)XPclose(ptns);
|
||||
musthave(ord(')'), 0);
|
||||
musthave(ORD(')'), 0);
|
||||
|
||||
t->left = c_list(sALIAS, true);
|
||||
|
||||
/* initialise to default for ;; or omitted */
|
||||
t->u.charflag = ord(';');
|
||||
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 = ord('|');
|
||||
t->u.charflag = ORD('|');
|
||||
if (0)
|
||||
/* FALLTHROUGH */
|
||||
case BRKFT:
|
||||
t->u.charflag = ord('&');
|
||||
t->u.charflag = ORD('&');
|
||||
/* FALLTHROUGH */
|
||||
case BREAK:
|
||||
/* initialised above, but we need to eat the token */
|
||||
@ -711,14 +714,14 @@ function_body(char *name, int sALIAS,
|
||||
* only accepts an open-brace.
|
||||
*/
|
||||
if (ksh_func) {
|
||||
if (tpeek(CONTIN|KEYWORD|sALIAS) == ord('(' /*)*/)) {
|
||||
if ((unsigned int)tpeek(CONTIN|KEYWORD|sALIAS) == ORD('(' /*)*/)) {
|
||||
/* function foo () { //}*/
|
||||
ACCEPT;
|
||||
musthave(ord(/*(*/ ')'), 0);
|
||||
musthave(ORD(/*(*/ ')'), 0);
|
||||
/* degrade to POSIX function */
|
||||
ksh_func = false;
|
||||
}
|
||||
musthave(ord('{' /*}*/), CONTIN|KEYWORD|sALIAS);
|
||||
musthave(ORD('{' /*}*/), CONTIN|KEYWORD|sALIAS);
|
||||
REJECT;
|
||||
}
|
||||
|
||||
@ -810,8 +813,8 @@ static const struct tokeninfo {
|
||||
{ "in", IN, true },
|
||||
{ Tfunction, FUNCTION, true },
|
||||
{ Ttime, TIME, true },
|
||||
{ "{", ord('{'), true },
|
||||
{ Tcbrace, ord('}'), true },
|
||||
{ "{", CORD('{'), true },
|
||||
{ Tcbrace, CORD('}'), true },
|
||||
{ "!", BANG, true },
|
||||
{ "[[", DBRACKET, true },
|
||||
/* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */
|
||||
@ -823,7 +826,7 @@ static const struct tokeninfo {
|
||||
{ "((", MDPAREN, false },
|
||||
{ "|&", COPROC, false },
|
||||
/* and some special cases... */
|
||||
{ "newline", ord('\n'), false },
|
||||
{ "newline", CORD('\n'), false },
|
||||
{ NULL, 0, false }
|
||||
};
|
||||
|
||||
@ -998,9 +1001,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 == ord('(') /*)*/ ? TO_NONNULL : TO_NONOP;
|
||||
ret = (unsigned int)c == ORD('(') /*)*/ ? TO_NONNULL : TO_NONOP;
|
||||
else if (meta == TM_CPAREN)
|
||||
ret = c == /*(*/ ord(')') ? TO_NONNULL : TO_NONOP;
|
||||
ret = (unsigned int)c == /*(*/ ORD(')') ? TO_NONNULL : TO_NONOP;
|
||||
else if (meta == TM_UNOP || meta == TM_BINOP) {
|
||||
if (meta == TM_BINOP && c == REDIR &&
|
||||
(yylval.iop->ioflag == IOREAD ||
|
||||
@ -1131,14 +1134,14 @@ yyrecursive(int subtype)
|
||||
struct op *t;
|
||||
char *cp;
|
||||
struct yyrecursive_state *ys;
|
||||
int stok, etok;
|
||||
unsigned int stok, etok;
|
||||
|
||||
if (subtype != COMSUB) {
|
||||
stok = ord('{');
|
||||
etok = ord('}');
|
||||
stok = ORD('{');
|
||||
etok = ORD('}');
|
||||
} else {
|
||||
stok = ord('(');
|
||||
etok = ord(')');
|
||||
stok = ORD('(');
|
||||
etok = ORD(')');
|
||||
}
|
||||
|
||||
ys = alloc(sizeof(struct yyrecursive_state), ATEMP);
|
||||
|
65
tree.c
65
tree.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.93 2017/05/05 22:53:32 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.94 2018/01/13 23:55:14 tg Exp $");
|
||||
|
||||
#define INDENT 8
|
||||
|
||||
@ -329,7 +329,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
|
||||
case EOS:
|
||||
return (--wp);
|
||||
case ADELIM:
|
||||
if (ord(*wp) == ord(/*{*/ '}')) {
|
||||
if (ord(*wp) == ORD(/*{*/ '}')) {
|
||||
++wp;
|
||||
goto wdvarput_csubst;
|
||||
}
|
||||
@ -342,21 +342,21 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
|
||||
c = ord(*wp++);
|
||||
if (opmode & WDS_TPUTS)
|
||||
switch (c) {
|
||||
case ord('\n'):
|
||||
case CORD('\n'):
|
||||
if (quotelevel == 0) {
|
||||
c = ord('\'');
|
||||
c = ORD('\'');
|
||||
shf_putc(c, shf);
|
||||
shf_putc(ord('\n'), shf);
|
||||
shf_putc(ORD('\n'), shf);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (quotelevel == 0)
|
||||
/* FALLTHROUGH */
|
||||
case ord('"'):
|
||||
case ord('`'):
|
||||
case ord('$'):
|
||||
case ord('\\'):
|
||||
shf_putc(ord('\\'), shf);
|
||||
case CORD('"'):
|
||||
case CORD('`'):
|
||||
case CORD('$'):
|
||||
case CORD('\\'):
|
||||
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 (ord(*wp) == ord('(' /*)*/))
|
||||
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 = ord(' ');
|
||||
c = ORD(' ');
|
||||
if (0)
|
||||
/* FALLTHROUGH */
|
||||
case VALSUB:
|
||||
c = ord('|');
|
||||
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 (ord(*wp++) == ord('{'))
|
||||
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 (ord(*wp++) == ord('}')) {
|
||||
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 = ord('|');
|
||||
c = ORD('|');
|
||||
if (0)
|
||||
/* FALLTHROUGH */
|
||||
case CPAT:
|
||||
c = ord(/*(*/ ')');
|
||||
c = ORD(/*(*/ ')');
|
||||
shf_putc(c, shf);
|
||||
break;
|
||||
}
|
||||
@ -470,36 +470,37 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
while ((c = ord(*fmt++))) {
|
||||
if (c == '%') {
|
||||
switch ((c = ord(*fmt++))) {
|
||||
case ord('c'):
|
||||
case CORD('c'):
|
||||
/* character (octet, probably) */
|
||||
shf_putchar(va_arg(va, int), shf);
|
||||
break;
|
||||
case ord('s'):
|
||||
case CORD('s'):
|
||||
/* string */
|
||||
shf_puts(va_arg(va, char *), shf);
|
||||
break;
|
||||
case ord('S'):
|
||||
case CORD('S'):
|
||||
/* word */
|
||||
wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS);
|
||||
break;
|
||||
case ord('d'):
|
||||
case CORD('d'):
|
||||
/* signed decimal */
|
||||
shf_fprintf(shf, Tf_d, va_arg(va, int));
|
||||
break;
|
||||
case ord('u'):
|
||||
case CORD('u'):
|
||||
/* unsigned decimal */
|
||||
shf_fprintf(shf, "%u", va_arg(va, unsigned int));
|
||||
break;
|
||||
case ord('T'):
|
||||
case CORD('T'):
|
||||
/* format tree */
|
||||
ptree(va_arg(va, struct op *), indent, shf);
|
||||
goto dont_trash_prevent_semicolon;
|
||||
case ord(';'):
|
||||
case CORD(';'):
|
||||
/* newline or ; */
|
||||
case ord('N'):
|
||||
case CORD('N'):
|
||||
/* newline or space */
|
||||
if (shf->flags & SHF_STRING) {
|
||||
if (c == ord(';') && !prevent_semicolon)
|
||||
if ((unsigned int)c == ORD(';') &&
|
||||
!prevent_semicolon)
|
||||
shf_putc(';', shf);
|
||||
shf_putc(' ', shf);
|
||||
} else {
|
||||
@ -515,7 +516,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
shf_putc(' ', shf);
|
||||
}
|
||||
break;
|
||||
case ord('R'):
|
||||
case CORD('R'):
|
||||
/* I/O redirection */
|
||||
pioact(shf, va_arg(va, struct ioword *));
|
||||
break;
|
||||
@ -613,7 +614,7 @@ wdscan(const char *wp, int c)
|
||||
case ADELIM:
|
||||
if (c == ADELIM && nest == 0)
|
||||
return (wp + 1);
|
||||
if (ord(*wp) == ord(/*{*/ '}'))
|
||||
if (ord(*wp) == ORD(/*{*/ '}'))
|
||||
goto wdscan_csubst;
|
||||
/* FALLTHROUGH */
|
||||
case CHAR:
|
||||
@ -808,7 +809,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 = ord('?');
|
||||
c = ORD('?');
|
||||
}
|
||||
*dst++ = c;
|
||||
goto vist_loop;
|
||||
@ -842,7 +843,7 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel)
|
||||
shf_puts("EOS", shf);
|
||||
return (--wp);
|
||||
case ADELIM:
|
||||
if (ord(*wp) == ord(/*{*/ '}')) {
|
||||
if (ord(*wp) == ORD(/*{*/ '}')) {
|
||||
shf_puts(/*{*/ "]ADELIM(})", shf);
|
||||
return (wp + 1);
|
||||
}
|
||||
@ -856,8 +857,8 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel)
|
||||
case QCHAR:
|
||||
shf_puts("QCHAR<", shf);
|
||||
c = ord(*wp++);
|
||||
if (quotelevel == 0 || c == ord('"') ||
|
||||
c == ord('\\') || ctype(c, C_DOLAR | C_GRAVE))
|
||||
if (quotelevel == 0 || c == ORD('"') ||
|
||||
c == ORD('\\') || ctype(c, C_DOLAR | C_GRAVE))
|
||||
shf_putc('\\', shf);
|
||||
dumpchar(shf, c);
|
||||
goto closeandout;
|
||||
|
42
var.c
42
var.c
@ -28,7 +28,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.222 2018/01/13 21:38:10 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.223 2018/01/13 23:55:15 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 && ord(*p) == ord('[') && (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 (ord(*val) == ord('[')) {
|
||||
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 (ord(val[0]) == ord('=')) {
|
||||
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 (ord(val[0]) == ord('+') && ord(val[1]) == ord('=')) {
|
||||
} else if (ord(val[0]) == ORD('+') && ord(val[1]) == ORD('=')) {
|
||||
strndupx(tvar, var, val - var, ATEMP);
|
||||
val += 2;
|
||||
vappend = true;
|
||||
@ -822,9 +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 && ord(tvar[len - 3]) == ord('[') &&
|
||||
ord(tvar[len - 2]) == ord('*') &&
|
||||
ord(tvar[len - 1]) == ord(']'))
|
||||
if (len > 3 && ord(tvar[len - 3]) == ORD('[') &&
|
||||
ord(tvar[len - 2]) == ORD('*') &&
|
||||
ord(tvar[len - 1]) == ORD(']'))
|
||||
tvar[len - 3] = '\0';
|
||||
}
|
||||
|
||||
@ -861,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 = (ord(*ccp) == ord('[')) ? 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
|
||||
@ -1071,7 +1071,7 @@ skip_varname(const char *s, bool aok)
|
||||
do {
|
||||
++s;
|
||||
} while (ctype(*s, C_ALNUX));
|
||||
if (aok && ord(*s) == ord('[') && (alen = array_ref_len(s)))
|
||||
if (aok && ord(*s) == ORD('[') && (alen = array_ref_len(s)))
|
||||
s += alen;
|
||||
}
|
||||
return (s);
|
||||
@ -1087,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 && ord(s[1]) == ord('[')) {
|
||||
if (aok && s[0] == CHAR && ord(s[1]) == ORD('[')) {
|
||||
/* skip possible array de-reference */
|
||||
const char *p = s;
|
||||
char c;
|
||||
@ -1098,9 +1098,9 @@ skip_wdvarname(const char *s,
|
||||
break;
|
||||
c = p[1];
|
||||
p += 2;
|
||||
if (ord(c) == ord('['))
|
||||
if (ord(c) == ORD('['))
|
||||
depth++;
|
||||
else if (ord(c) == ord(']') && --depth == 0) {
|
||||
else if (ord(c) == ORD(']') && --depth == 0) {
|
||||
s = p;
|
||||
break;
|
||||
}
|
||||
@ -1308,7 +1308,7 @@ setspec(struct tbl *vp)
|
||||
if (!(vp->flag&INTEGER)) {
|
||||
s = str_val(vp);
|
||||
do {
|
||||
if (*s == ord('\\'))
|
||||
if (*s == ORD('\\'))
|
||||
*s = '/';
|
||||
} while (*s++);
|
||||
}
|
||||
@ -1562,8 +1562,8 @@ array_ref_len(const char *cp)
|
||||
char c;
|
||||
int depth = 0;
|
||||
|
||||
while ((c = *s++) && (ord(c) != ord(']') || --depth))
|
||||
if (ord(c) == ord('['))
|
||||
while ((c = *s++) && (ord(c) != ORD(']') || --depth))
|
||||
if (ord(c) == ORD('['))
|
||||
depth++;
|
||||
if (!c)
|
||||
return (0);
|
||||
@ -1635,18 +1635,18 @@ set_array(const char *var, bool reset, const char **vals)
|
||||
}
|
||||
while ((ccp = vals[i])) {
|
||||
#if 0 /* temporarily taken out due to regression */
|
||||
if (ord(*ccp) == ord('[')) {
|
||||
if (ord(*ccp) == ORD('[')) {
|
||||
int level = 0;
|
||||
|
||||
while (*ccp) {
|
||||
if (ord(*ccp) == ord(']') && --level == 0)
|
||||
if (ord(*ccp) == ORD(']') && --level == 0)
|
||||
break;
|
||||
if (ord(*ccp) == ord('['))
|
||||
if (ord(*ccp) == ORD('['))
|
||||
++level;
|
||||
++ccp;
|
||||
}
|
||||
if (ord(*ccp) == ord(']') && level == 0 &&
|
||||
ord(ccp[1]) == ord('=')) {
|
||||
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,
|
||||
|
Reference in New Issue
Block a user