revert the CORD debugging aid

(introduced so that ORD could eval its args twice in !DEBUG)
This commit is contained in:
tg 2018-01-14 00:03:05 +00:00
parent 6e486d1163
commit c763e7b0e9
7 changed files with 200 additions and 202 deletions

146
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.341 2018/01/13 23:55:09 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.342 2018/01/14 00:03:00 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -312,12 +312,12 @@ x_glob_hlp_add_qchar(char *cp)
*/ */
switch (ord(ch)) { switch (ord(ch)) {
case QCHAR: case QCHAR:
case CORD('$'): case ORD('$'):
case CORD('*'): case ORD('*'):
case CORD('?'): case ORD('?'):
case CORD('['): case ORD('['):
case CORD('\\'): case ORD('\\'):
case CORD('`'): case ORD('`'):
*dp++ = QCHAR; *dp++ = QCHAR;
break; break;
} }
@ -4128,7 +4128,7 @@ vi_cmd(int argcnt, const char *cmd)
redraw_line(true); redraw_line(true);
break; break;
case CORD('@'): case ORD('@'):
{ {
static char alias[] = "_\0"; static char alias[] = "_\0";
struct tbl *ap; struct tbl *ap;
@ -4169,7 +4169,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('a'): case ORD('a'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
if (vs->linelen != 0) if (vs->linelen != 0)
@ -4177,7 +4177,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case CORD('A'): case ORD('A'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
del_range(0, 0); del_range(0, 0);
@ -4185,7 +4185,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case CORD('S'): case ORD('S'):
vs->cursor = domovebeg(); vs->cursor = domovebeg();
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
modified = 1; modified = 1;
@ -4193,14 +4193,14 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case CORD('Y'): case ORD('Y'):
cmd = "y$"; cmd = "y$";
/* ahhhhhh... */ /* ahhhhhh... */
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('c'): case ORD('c'):
case CORD('d'): case ORD('d'):
case CORD('y'): case ORD('y'):
if (*cmd == cmd[1]) { if (*cmd == cmd[1]) {
c1 = *cmd == 'c' ? domovebeg() : 0; c1 = *cmd == 'c' ? domovebeg() : 0;
c2 = vs->linelen; c2 = vs->linelen;
@ -4239,7 +4239,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('p'): case ORD('p'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
if (vs->linelen != 0) if (vs->linelen != 0)
@ -4253,7 +4253,7 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
break; break;
case CORD('P'): case ORD('P'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
any = 0; any = 0;
@ -4266,25 +4266,25 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
break; break;
case CORD('C'): case ORD('C'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
insert = INSERT; insert = INSERT;
break; break;
case CORD('D'): case ORD('D'):
yank_range(vs->cursor, vs->linelen); yank_range(vs->cursor, vs->linelen);
del_range(vs->cursor, vs->linelen); del_range(vs->cursor, vs->linelen);
if (vs->cursor != 0) if (vs->cursor != 0)
vs->cursor--; vs->cursor--;
break; break;
case CORD('g'): case ORD('g'):
if (!argcnt) if (!argcnt)
argcnt = hlast; argcnt = hlast;
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('G'): case ORD('G'):
if (!argcnt) if (!argcnt)
argcnt = 1; argcnt = 1;
else else
@ -4297,21 +4297,21 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('i'): case ORD('i'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
insert = INSERT; insert = INSERT;
break; break;
case CORD('I'): case ORD('I'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
vs->cursor = domovebeg(); vs->cursor = domovebeg();
insert = INSERT; insert = INSERT;
break; break;
case CORD('j'): case ORD('j'):
case CORD('+'): case ORD('+'):
case CTRL_N: case CTRL_N:
if (grabhist(modified, hnum + argcnt) < 0) if (grabhist(modified, hnum + argcnt) < 0)
return (-1); return (-1);
@ -4321,8 +4321,8 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('k'): case ORD('k'):
case CORD('-'): case ORD('-'):
case CTRL_P: case CTRL_P:
if (grabhist(modified, hnum - argcnt) < 0) if (grabhist(modified, hnum - argcnt) < 0)
return (-1); return (-1);
@ -4332,7 +4332,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('r'): case ORD('r'):
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
modified = 1; modified = 1;
@ -4350,13 +4350,13 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('R'): case ORD('R'):
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
insert = REPLACE; insert = REPLACE;
break; break;
case CORD('s'): case ORD('s'):
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
modified = 1; modified = 1;
@ -4367,7 +4367,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT; insert = INSERT;
break; break;
case CORD('v'): case ORD('v'):
if (!argcnt) { if (!argcnt) {
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
@ -4390,7 +4390,7 @@ vi_cmd(int argcnt, const char *cmd)
vs->linelen = strlen(vs->cbuf); vs->linelen = strlen(vs->cbuf);
return (2); return (2);
case CORD('x'): case ORD('x'):
if (vs->linelen == 0) if (vs->linelen == 0)
return (-1); return (-1);
modified = 1; modified = 1;
@ -4401,7 +4401,7 @@ vi_cmd(int argcnt, const char *cmd)
del_range(vs->cursor, vs->cursor + argcnt); del_range(vs->cursor, vs->cursor + argcnt);
break; break;
case CORD('X'): case ORD('X'):
if (vs->cursor > 0) { if (vs->cursor > 0) {
modified = 1; modified = 1;
hnum = hlast; hnum = hlast;
@ -4414,13 +4414,13 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
break; break;
case CORD('u'): case ORD('u'):
t = vs; t = vs;
vs = undo; vs = undo;
undo = t; undo = t;
break; break;
case CORD('U'): case ORD('U'):
if (!modified) if (!modified)
return (-1); return (-1);
if (grabhist(modified, ohnum) < 0) if (grabhist(modified, ohnum) < 0)
@ -4429,19 +4429,19 @@ vi_cmd(int argcnt, const char *cmd)
hnum = ohnum; hnum = ohnum;
break; break;
case CORD('?'): case ORD('?'):
if (hnum == hlast) if (hnum == hlast)
hnum = -1; hnum = -1;
/* ahhh */ /* ahhh */
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('/'): case ORD('/'):
c3 = 1; c3 = 1;
srchlen = 0; srchlen = 0;
lastsearch = *cmd; lastsearch = *cmd;
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('n'): case ORD('n'):
case CORD('N'): case ORD('N'):
if (lastsearch == ' ') if (lastsearch == ' ')
return (-1); return (-1);
if (lastsearch == '?') if (lastsearch == '?')
@ -4468,7 +4468,7 @@ vi_cmd(int argcnt, const char *cmd)
return (0); return (0);
} }
break; break;
case CORD('_'): case ORD('_'):
{ {
bool inspace; bool inspace;
char *p, *sp; char *p, *sp;
@ -4520,7 +4520,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
break; break;
case CORD('~'): case ORD('~'):
{ {
char *p; char *p;
int i; int i;
@ -4544,7 +4544,7 @@ vi_cmd(int argcnt, const char *cmd)
break; break;
} }
case CORD('#'): case ORD('#'):
{ {
int ret = x_do_comment(vs->cbuf, vs->cbufsize, int ret = x_do_comment(vs->cbuf, vs->cbufsize,
&vs->linelen); &vs->linelen);
@ -4554,7 +4554,7 @@ vi_cmd(int argcnt, const char *cmd)
} }
/* AT&T ksh */ /* AT&T ksh */
case CORD('='): case ORD('='):
/* Nonstandard vi/ksh */ /* Nonstandard vi/ksh */
case CTRL_E: case CTRL_E:
print_expansions(vs, 1); print_expansions(vs, 1);
@ -4574,7 +4574,7 @@ vi_cmd(int argcnt, const char *cmd)
return (-1); return (-1);
/* FALLTHROUGH */ /* FALLTHROUGH */
/* AT&T ksh */ /* AT&T ksh */
case CORD('\\'): case ORD('\\'):
/* Nonstandard vi/ksh */ /* Nonstandard vi/ksh */
case CTRL_F: case CTRL_F:
complete_word(1, argcnt); complete_word(1, argcnt);
@ -4582,7 +4582,7 @@ vi_cmd(int argcnt, const char *cmd)
/* AT&T ksh */ /* AT&T ksh */
case CORD('*'): case ORD('*'):
/* Nonstandard vi/ksh */ /* Nonstandard vi/ksh */
case CTRL_X: case CTRL_X:
expand_word(1); expand_word(1);
@ -4590,8 +4590,8 @@ vi_cmd(int argcnt, const char *cmd)
/* mksh: cursor movement */ /* mksh: cursor movement */
case CORD('['): case ORD('['):
case CORD('O'): case ORD('O'):
state = VPREFIX2; state = VPREFIX2;
if (vs->linelen != 0) if (vs->linelen != 0)
vs->cursor++; vs->cursor++;
@ -4611,19 +4611,19 @@ domove(int argcnt, const char *cmd, int sub)
unsigned int bcount; unsigned int bcount;
switch (ord(*cmd)) { switch (ord(*cmd)) {
case CORD('b'): case ORD('b'):
if (!sub && vs->cursor == 0) if (!sub && vs->cursor == 0)
return (-1); return (-1);
ncursor = backword(argcnt); ncursor = backword(argcnt);
break; break;
case CORD('B'): case ORD('B'):
if (!sub && vs->cursor == 0) if (!sub && vs->cursor == 0)
return (-1); return (-1);
ncursor = Backword(argcnt); ncursor = Backword(argcnt);
break; break;
case CORD('e'): case ORD('e'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = endword(argcnt); ncursor = endword(argcnt);
@ -4631,7 +4631,7 @@ domove(int argcnt, const char *cmd, int sub)
ncursor++; ncursor++;
break; break;
case CORD('E'): case ORD('E'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = Endword(argcnt); ncursor = Endword(argcnt);
@ -4639,15 +4639,15 @@ domove(int argcnt, const char *cmd, int sub)
ncursor++; ncursor++;
break; break;
case CORD('f'): case ORD('f'):
case CORD('F'): case ORD('F'):
case CORD('t'): case ORD('t'):
case CORD('T'): case ORD('T'):
fsavecmd = *cmd; fsavecmd = *cmd;
fsavech = cmd[1]; fsavech = cmd[1];
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD(','): case ORD(','):
case CORD(';'): case ORD(';'):
if (fsavecmd == ' ') if (fsavecmd == ' ')
return (-1); return (-1);
i = ksh_eq(fsavecmd, 'F', 'f'); i = ksh_eq(fsavecmd, 'F', 'f');
@ -4661,7 +4661,7 @@ domove(int argcnt, const char *cmd, int sub)
ncursor++; ncursor++;
break; break;
case CORD('h'): case ORD('h'):
case CTRL_H: case CTRL_H:
if (!sub && vs->cursor == 0) if (!sub && vs->cursor == 0)
return (-1); return (-1);
@ -4670,8 +4670,8 @@ domove(int argcnt, const char *cmd, int sub)
ncursor = 0; ncursor = 0;
break; break;
case CORD(' '): case ORD(' '):
case CORD('l'): case ORD('l'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
if (vs->linelen != 0) { if (vs->linelen != 0) {
@ -4681,27 +4681,27 @@ domove(int argcnt, const char *cmd, int sub)
} }
break; break;
case CORD('w'): case ORD('w'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = forwword(argcnt); ncursor = forwword(argcnt);
break; break;
case CORD('W'): case ORD('W'):
if (!sub && vs->cursor + 1 >= vs->linelen) if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1); return (-1);
ncursor = Forwword(argcnt); ncursor = Forwword(argcnt);
break; break;
case CORD('0'): case ORD('0'):
ncursor = 0; ncursor = 0;
break; break;
case CORD('^'): case ORD('^'):
ncursor = domovebeg(); ncursor = domovebeg();
break; break;
case CORD('|'): case ORD('|'):
ncursor = argcnt; ncursor = argcnt;
if (ncursor > vs->linelen) if (ncursor > vs->linelen)
ncursor = vs->linelen; ncursor = vs->linelen;
@ -4709,14 +4709,14 @@ domove(int argcnt, const char *cmd, int sub)
ncursor--; ncursor--;
break; break;
case CORD('$'): case ORD('$'):
if (vs->linelen != 0) if (vs->linelen != 0)
ncursor = vs->linelen; ncursor = vs->linelen;
else else
ncursor = 0; ncursor = 0;
break; break;
case CORD('%'): case ORD('%'):
ncursor = vs->cursor; ncursor = vs->cursor;
while (ncursor < vs->linelen && while (ncursor < vs->linelen &&
(i = bracktype(vs->cbuf[ncursor])) == 0) (i = bracktype(vs->cbuf[ncursor])) == 0)
@ -4784,22 +4784,22 @@ bracktype(int ch)
{ {
switch (ord(ch)) { switch (ord(ch)) {
case CORD('('): case ORD('('):
return (1); return (1);
case CORD('['): case ORD('['):
return (2); return (2);
case CORD('{'): case ORD('{'):
return (3); return (3);
case CORD(')'): case ORD(')'):
return (-1); return (-1);
case CORD(']'): case ORD(']'):
return (-2); return (-2);
case CORD('}'): case ORD('}'):
return (-3); return (-3);
default: default:

112
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.216 2018/01/13 23:55:09 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.217 2018/01/14 00:03:02 tg Exp $");
/* /*
* string expansion * string expansion
@ -436,11 +436,11 @@ expand(
if (stype) if (stype)
sp += slen; sp += slen;
switch (stype & STYPE_SINGLE) { switch (stype & STYPE_SINGLE) {
case CORD('#') | STYPE_AT: case ORD('#') | STYPE_AT:
x.str = shf_smprintf("%08X", x.str = shf_smprintf("%08X",
(unsigned int)hash(str_val(st->var))); (unsigned int)hash(str_val(st->var)));
break; break;
case CORD('Q') | STYPE_AT: { case ORD('Q') | STYPE_AT: {
struct shf shf; struct shf shf;
shf_sopen(NULL, 0, SHF_WR|SHF_DYNAMIC, &shf); shf_sopen(NULL, 0, SHF_WR|SHF_DYNAMIC, &shf);
@ -448,7 +448,7 @@ expand(
x.str = shf_sclose(&shf); x.str = shf_sclose(&shf);
break; break;
} }
case CORD('0'): { case ORD('0'): {
char *beg, *mid, *end, *stg; char *beg, *mid, *end, *stg;
mksh_ari_t from = 0, num = -1, flen, finc = 0; mksh_ari_t from = 0, num = -1, flen, finc = 0;
@ -495,8 +495,8 @@ expand(
strndupx(x.str, beg, num, ATEMP); strndupx(x.str, beg, num, ATEMP);
goto do_CSUBST; goto do_CSUBST;
} }
case CORD('/') | STYPE_AT: case ORD('/') | STYPE_AT:
case CORD('/'): { case ORD('/'): {
char *s, *p, *d, *sbeg, *end; char *s, *p, *d, *sbeg, *end;
char *pat = NULL, *rrep = null; char *pat = NULL, *rrep = null;
char fpat = 0, *tpat1, *tpat2; char fpat = 0, *tpat1, *tpat2;
@ -622,8 +622,8 @@ expand(
afree(ws, ATEMP); afree(ws, ATEMP);
goto do_CSUBST; goto do_CSUBST;
} }
case CORD('#'): case ORD('#'):
case CORD('%'): case ORD('%'):
/* ! DOBLANK,DOBRACE */ /* ! DOBLANK,DOBRACE */
f = (f & DONTRUNCOMMAND) | f = (f & DONTRUNCOMMAND) |
DOPAT | DOTILDE | DOPAT | DOTILDE |
@ -640,7 +640,7 @@ expand(
*dp++ = ORD(0x80 | '@'); *dp++ = ORD(0x80 | '@');
} }
break; break;
case CORD('='): case ORD('='):
/* /*
* Tilde expansion for string * Tilde expansion for string
* variables in POSIX mode is * variables in POSIX mode is
@ -664,7 +664,7 @@ expand(
f &= ~(DOBLANK|DOGLOB|DOBRACE); f &= ~(DOBLANK|DOGLOB|DOBRACE);
tilde_ok = 1; tilde_ok = 1;
break; break;
case CORD('?'): case ORD('?'):
if (*sp == CSUBST) if (*sp == CSUBST)
errorf("%s: parameter null or not set", errorf("%s: parameter null or not set",
st->var->name); st->var->name);
@ -699,8 +699,8 @@ expand(
if (f & DOBLANK) if (f & DOBLANK)
doblank--; doblank--;
switch (st->stype & STYPE_SINGLE) { switch (st->stype & STYPE_SINGLE) {
case CORD('#'): case ORD('#'):
case CORD('%'): case ORD('%'):
if (!Flag(FSH)) { if (!Flag(FSH)) {
/* Append end-pattern */ /* Append end-pattern */
*dp++ = MAGIC; *dp++ = MAGIC;
@ -730,7 +730,7 @@ expand(
doblank++; doblank++;
st = st->prev; st = st->prev;
continue; continue;
case CORD('='): case ORD('='):
/* /*
* Restore our position and substitute * Restore our position and substitute
* the value of st->var (may not be * the value of st->var (may not be
@ -763,17 +763,17 @@ expand(
st = st->prev; st = st->prev;
word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS; word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS;
continue; continue;
case CORD('?'): case ORD('?'):
dp = Xrestpos(ds, dp, st->base); dp = Xrestpos(ds, dp, st->base);
errorf(Tf_sD_s, st->var->name, errorf(Tf_sD_s, st->var->name,
debunk(dp, dp, strlen(dp) + 1)); debunk(dp, dp, strlen(dp) + 1));
break; break;
case CORD('0'): case ORD('0'):
case CORD('/') | STYPE_AT: case ORD('/') | STYPE_AT:
case CORD('/'): case ORD('/'):
case CORD('#') | STYPE_AT: case ORD('#') | STYPE_AT:
case CORD('Q') | STYPE_AT: case ORD('Q') | STYPE_AT:
dp = Xrestpos(ds, dp, st->base); dp = Xrestpos(ds, dp, st->base);
type = XSUB; type = XSUB;
word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS; word = quote || (!*x.str && (f & DOSCALAR)) ? IFS_WORD : IFS_IWS;
@ -1003,10 +1003,10 @@ expand(
/* mark any special second pass chars */ /* mark any special second pass chars */
if (!quote) if (!quote)
switch (ord(c)) { switch (ord(c)) {
case CORD('['): case ORD('['):
case CORD('!'): case ORD('!'):
case CORD('-'): case ORD('-'):
case CORD(']'): case ORD(']'):
/* /*
* For character classes - doesn't hurt * For character classes - doesn't hurt
* to have magic !,-,]s outside of * to have magic !,-,]s outside of
@ -1019,16 +1019,16 @@ expand(
*dp++ = MAGIC; *dp++ = MAGIC;
} }
break; break;
case CORD('*'): case ORD('*'):
case CORD('?'): case ORD('?'):
if (f & (DOPAT | DOGLOB)) { if (f & (DOPAT | DOGLOB)) {
fdo |= DOMAGIC | (f & DOGLOB); fdo |= DOMAGIC | (f & DOGLOB);
*dp++ = MAGIC; *dp++ = MAGIC;
} }
break; break;
case CORD('{'): case ORD('{'):
case CORD('}'): case ORD('}'):
case CORD(','): case ORD(','):
if ((f & DOBRACE) && if ((f & DOBRACE) &&
(ord(c) == ORD('{' /*}*/) || (ord(c) == ORD('{' /*}*/) ||
(fdo & DOBRACE))) { (fdo & DOBRACE))) {
@ -1036,7 +1036,7 @@ expand(
*dp++ = MAGIC; *dp++ = MAGIC;
} }
break; break;
case CORD('='): case ORD('='):
/* Note first unquoted = for ~ */ /* Note first unquoted = for ~ */
if (!(f & DOTEMP) && (!Flag(FPOSIX) || if (!(f & DOTEMP) && (!Flag(FPOSIX) ||
(f & DOASNTILDE)) && !saw_eq) { (f & DOASNTILDE)) && !saw_eq) {
@ -1044,13 +1044,13 @@ expand(
tilde_ok = 1; tilde_ok = 1;
} }
break; break;
case CORD(':'): case ORD(':'):
/* : */ /* : */
/* Note unquoted : for ~ */ /* Note unquoted : for ~ */
if (!(f & DOTEMP) && (f & DOASNTILDE)) if (!(f & DOTEMP) && (f & DOASNTILDE))
tilde_ok = 1; tilde_ok = 1;
break; break;
case CORD('~'): case ORD('~'):
/* /*
* tilde_ok is reset whenever * tilde_ok is reset whenever
* any of ' " $( $(( ${ } are seen. * any of ' " $( $(( ${ } are seen.
@ -1247,9 +1247,9 @@ varsub(Expand *xp, const char *sp, const char *word,
/* @x where x is command char */ /* @x where x is command char */
switch (c = ord(word[slen + 2]) == CHAR ? switch (c = ord(word[slen + 2]) == CHAR ?
ord(word[slen + 3]) : 0) { ord(word[slen + 3]) : 0) {
case CORD('#'): case ORD('#'):
case CORD('/'): case ORD('/'):
case CORD('Q'): case ORD('Q'):
break; break;
default: default:
return (-1); return (-1);
@ -1266,16 +1266,16 @@ varsub(Expand *xp, const char *sp, const char *word,
if ((unsigned int)c == ORD('*') || (unsigned int)c == ORD('@')) { if ((unsigned int)c == ORD('*') || (unsigned int)c == ORD('@')) {
switch (stype & STYPE_SINGLE) { switch (stype & STYPE_SINGLE) {
/* can't assign to a vector */ /* can't assign to a vector */
case CORD('='): case ORD('='):
/* can't trim a vector (yet) */ /* can't trim a vector (yet) */
case CORD('%'): case ORD('%'):
case CORD('#'): case ORD('#'):
case CORD('?'): case ORD('?'):
case CORD('0'): case ORD('0'):
case CORD('/') | STYPE_AT: case ORD('/') | STYPE_AT:
case CORD('/'): case ORD('/'):
case CORD('#') | STYPE_AT: case ORD('#') | STYPE_AT:
case CORD('Q') | STYPE_AT: case ORD('Q') | STYPE_AT:
return (-1); return (-1);
} }
if (e->loc->argc == 0) { if (e->loc->argc == 0) {
@ -1297,16 +1297,16 @@ varsub(Expand *xp, const char *sp, const char *word,
switch (stype & STYPE_SINGLE) { switch (stype & STYPE_SINGLE) {
/* can't assign to a vector */ /* can't assign to a vector */
case CORD('='): case ORD('='):
/* can't trim a vector (yet) */ /* can't trim a vector (yet) */
case CORD('%'): case ORD('%'):
case CORD('#'): case ORD('#'):
case CORD('?'): case ORD('?'):
case CORD('0'): case ORD('0'):
case CORD('/') | STYPE_AT: case ORD('/') | STYPE_AT:
case CORD('/'): case ORD('/'):
case CORD('#') | STYPE_AT: case ORD('#') | STYPE_AT:
case CORD('Q') | STYPE_AT: case ORD('Q') | STYPE_AT:
return (-1); return (-1);
} }
c = 0; c = 0;
@ -1495,7 +1495,7 @@ trimsub(char *str, char *pat, int how)
char *p, c; char *p, c;
switch (how & (STYPE_CHAR | STYPE_DBL)) { switch (how & (STYPE_CHAR | STYPE_DBL)) {
case CORD('#'): case ORD('#'):
/* shortest match at beginning */ /* shortest match at beginning */
for (p = str; p <= end; p += utf_ptradj(p)) { for (p = str; p <= end; p += utf_ptradj(p)) {
c = *p; *p = '\0'; c = *p; *p = '\0';
@ -1507,7 +1507,7 @@ trimsub(char *str, char *pat, int how)
*p = c; *p = c;
} }
break; break;
case CORD('#') | STYPE_DBL: case ORD('#') | STYPE_DBL:
/* longest match at beginning */ /* longest match at beginning */
for (p = end; p >= str; p--) { for (p = end; p >= str; p--) {
c = *p; *p = '\0'; c = *p; *p = '\0';
@ -1519,7 +1519,7 @@ trimsub(char *str, char *pat, int how)
*p = c; *p = c;
} }
break; break;
case CORD('%'): case ORD('%'):
/* shortest match at end */ /* shortest match at end */
p = end; p = end;
while (p >= str) { while (p >= str) {
@ -1535,7 +1535,7 @@ trimsub(char *str, char *pat, int how)
--p; --p;
} }
break; break;
case CORD('%') | STYPE_DBL: case ORD('%') | STYPE_DBL:
/* longest match at end */ /* longest match at end */
for (p = str; p <= end; p++) for (p = str; p <= end; p++)
if (gmatchx(p, pat, false)) { if (gmatchx(p, pat, false)) {

70
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.241 2018/01/13 23:55:11 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.242 2018/01/14 00:03:02 tg Exp $");
/* /*
* states while lexing word * states while lexing word
@ -312,7 +312,7 @@ yylex(int cf)
/* FALLTHROUGH */ /* FALLTHROUGH */
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */ Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
switch (c) { switch (c) {
case CORD('\\'): case ORD('\\'):
getsc_qchar: getsc_qchar:
if ((c = getsc())) { if ((c = getsc())) {
/* trailing \ is lost */ /* trailing \ is lost */
@ -320,7 +320,7 @@ yylex(int cf)
*wp++ = c; *wp++ = c;
} }
break; break;
case CORD('\''): case ORD('\''):
open_ssquote_unless_heredoc: open_ssquote_unless_heredoc:
if ((cf & HEREDOC)) if ((cf & HEREDOC))
goto store_char; goto store_char;
@ -328,12 +328,12 @@ yylex(int cf)
ignore_backslash_newline++; ignore_backslash_newline++;
PUSH_STATE(SSQUOTE); PUSH_STATE(SSQUOTE);
break; break;
case CORD('"'): case ORD('"'):
open_sdquote: open_sdquote:
*wp++ = OQUOTE; *wp++ = OQUOTE;
PUSH_STATE(SDQUOTE); PUSH_STATE(SDQUOTE);
break; break;
case CORD('$'): case ORD('$'):
/* /*
* processing of dollar sign belongs into * processing of dollar sign belongs into
* Subst, except for those which can open * Subst, except for those which can open
@ -342,9 +342,9 @@ yylex(int cf)
subst_dollar_ex: subst_dollar_ex:
c = getsc(); c = getsc();
switch (c) { switch (c) {
case CORD('"'): case ORD('"'):
goto open_sdquote; goto open_sdquote;
case CORD('\''): case ORD('\''):
goto open_sequote; goto open_sequote;
default: default:
goto SubstS; goto SubstS;
@ -356,16 +356,16 @@ yylex(int cf)
Subst: Subst:
switch (c) { switch (c) {
case CORD('\\'): case ORD('\\'):
c = getsc(); c = getsc();
switch (c) { switch (c) {
case CORD('"'): case ORD('"'):
if ((cf & HEREDOC)) if ((cf & HEREDOC))
goto heredocquote; goto heredocquote;
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('\\'): case ORD('\\'):
case CORD('$'): case ORD('$'):
case CORD('`'): case ORD('`'):
store_qchar: store_qchar:
*wp++ = QCHAR; *wp++ = QCHAR;
*wp++ = c; *wp++ = c;
@ -383,7 +383,7 @@ yylex(int cf)
break; break;
} }
break; break;
case CORD('$'): case ORD('$'):
c = getsc(); c = getsc();
SubstS: SubstS:
if ((unsigned int)c == ORD('(' /*)*/)) { if ((unsigned int)c == ORD('(' /*)*/)) {
@ -526,7 +526,7 @@ yylex(int cf)
ungetsc(c); ungetsc(c);
} }
break; break;
case CORD('`'): case ORD('`'):
subst_gravis: subst_gravis:
PUSH_STATE(SBQUOTE); PUSH_STATE(SBQUOTE);
*wp++ = COMASUB; *wp++ = COMASUB;
@ -729,12 +729,12 @@ yylex(int cf)
case 0: case 0:
/* trailing \ is lost */ /* trailing \ is lost */
break; break;
case CORD('$'): case ORD('$'):
case CORD('`'): case ORD('`'):
case CORD('\\'): case ORD('\\'):
*wp++ = c; *wp++ = c;
break; break;
case CORD('"'): case ORD('"'):
if (statep->ls_bool) { if (statep->ls_bool) {
*wp++ = c; *wp++ = c;
break; break;
@ -798,16 +798,16 @@ yylex(int cf)
* $ and `...` are not to be treated specially * $ and `...` are not to be treated specially
*/ */
switch (c) { switch (c) {
case CORD('\\'): case ORD('\\'):
if ((c = getsc())) { if ((c = getsc())) {
/* trailing \ is lost */ /* trailing \ is lost */
*wp++ = QCHAR; *wp++ = QCHAR;
*wp++ = c; *wp++ = c;
} }
break; break;
case CORD('\''): case ORD('\''):
goto open_ssquote_unless_heredoc; goto open_ssquote_unless_heredoc;
case CORD('$'): case ORD('$'):
if ((unsigned int)(c2 = getsc()) == ORD('\'')) { if ((unsigned int)(c2 = getsc()) == ORD('\'')) {
open_sequote: open_sequote:
*wp++ = OQUOTE; *wp++ = OQUOTE;
@ -817,7 +817,7 @@ yylex(int cf)
break; break;
} else if ((unsigned int)c2 == ORD('"')) { } else if ((unsigned int)c2 == ORD('"')) {
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('"'): case ORD('"'):
PUSH_SRETRACE(SHEREDQUOTE); PUSH_SRETRACE(SHEREDQUOTE);
break; break;
} }
@ -844,10 +844,10 @@ yylex(int cf)
while ((c = *dp++)) { while ((c = *dp++)) {
if (c == '\\') { if (c == '\\') {
switch ((c = *dp++)) { switch ((c = *dp++)) {
case CORD('\\'): case ORD('\\'):
case CORD('"'): case ORD('"'):
case CORD('$'): case ORD('$'):
case CORD('`'): case ORD('`'):
break; break;
default: default:
*wp++ = CHAR; *wp++ = CHAR;
@ -1139,7 +1139,7 @@ readhere(struct ioword *iop)
if (!*eofp) { if (!*eofp) {
/* end of here document marker, what to do? */ /* end of here document marker, what to do? */
switch (c) { switch (c) {
case CORD(/*(*/ ')'): case ORD(/*(*/ ')'):
if (!subshell_nesting_type) if (!subshell_nesting_type)
/*- /*-
* not allowed outside $(...) or (...) * not allowed outside $(...) or (...)
@ -1154,7 +1154,7 @@ readhere(struct ioword *iop)
* Allow EOF here to commands without trailing * Allow EOF here to commands without trailing
* newlines (mksh -c '...') will work as well. * newlines (mksh -c '...') will work as well.
*/ */
case CORD('\n'): case ORD('\n'):
/* Newline terminates here document marker */ /* Newline terminates here document marker */
goto heredoc_found_terminator; goto heredoc_found_terminator;
} }
@ -1591,22 +1591,22 @@ get_brace_var(XString *wsp, char *wp)
goto ps_common; goto ps_common;
case PS_SAW_BANG: case PS_SAW_BANG:
switch (ord(c)) { switch (ord(c)) {
case CORD('@'): case ORD('@'):
case CORD('#'): case ORD('#'):
case CORD('-'): case ORD('-'):
case CORD('?'): case ORD('?'):
goto out; goto out;
} }
goto ps_common; goto ps_common;
case PS_INITIAL: case PS_INITIAL:
switch (ord(c)) { switch (ord(c)) {
case CORD('%'): case ORD('%'):
state = PS_SAW_PERCENT; state = PS_SAW_PERCENT;
goto next; goto next;
case CORD('#'): case ORD('#'):
state = PS_SAW_HASH; state = PS_SAW_HASH;
goto next; goto next;
case CORD('!'): case ORD('!'):
state = PS_SAW_BANG; state = PS_SAW_BANG;
goto next; goto next;
} }

20
misc.c
View File

@ -32,7 +32,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.290 2018/01/13 23:58:32 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.291 2018/01/14 00:03:03 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@ -785,7 +785,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
continue; continue;
} }
switch (ord(*p++)) { switch (ord(*p++)) {
case CORD('['): case ORD('['):
/* BSD cclass extension? */ /* BSD cclass extension? */
if (ISMAGIC(p[0]) && ord(p[1]) == ORD('[') && if (ISMAGIC(p[0]) && ord(p[1]) == ORD('[') &&
ord(p[2]) == ORD(':') && ord(p[2]) == ORD(':') &&
@ -813,7 +813,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0); return (0);
break; break;
case CORD('?'): case ORD('?'):
if (sc == 0) if (sc == 0)
return (0); return (0);
if (UTFMODE) { if (UTFMODE) {
@ -822,7 +822,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
} }
break; break;
case CORD('*'): case ORD('*'):
if (p == pe) if (p == pe)
return (1); return (1);
s--; s--;
@ -838,9 +838,9 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
*/ */
/* matches one or more times */ /* matches one or more times */
case CORD('+') | 0x80: case ORD('+') | 0x80:
/* matches zero or more times */ /* matches zero or more times */
case CORD('*') | 0x80: case ORD('*') | 0x80:
if (!(prest = pat_scan(p, pe, false))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
@ -863,11 +863,11 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0); return (0);
/* matches zero or once */ /* matches zero or once */
case CORD('?') | 0x80: case ORD('?') | 0x80:
/* matches one of the patterns */ /* matches one of the patterns */
case CORD('@') | 0x80: case ORD('@') | 0x80:
/* simile for @ */ /* simile for @ */
case CORD(' ') | 0x80: case ORD(' ') | 0x80:
if (!(prest = pat_scan(p, pe, false))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
@ -889,7 +889,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0); return (0);
/* matches none of the patterns */ /* matches none of the patterns */
case CORD('!') | 0x80: case ORD('!') | 0x80:
if (!(prest = pat_scan(p, pe, false))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;

6
sh.h
View File

@ -182,7 +182,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.851 2018/01/13 23:55:13 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.852 2018/01/14 00:03:03 tg Exp $");
#endif #endif
#define MKSH_VERSION "R56 2017/10/17" #define MKSH_VERSION "R56 2017/10/17"
@ -1482,11 +1482,9 @@ extern unsigned int eek_ord;
__FILE__, __LINE__, ord_c); \ __FILE__, __LINE__, ord_c); \
((unsigned int)(unsigned char)(c)); \ ((unsigned int)(unsigned char)(c)); \
}) })
#define CORD(c) ORD(c)
#else #else
#define ord(c) ((unsigned int)(unsigned char)(c)) #define ord(c) ((unsigned int)(unsigned char)(c))
#define ORD(c) ((void)(c), ord(c)) #define ORD(c) ord(c) /* may evaluate arguments twice */
#define CORD(c) ord(c)
#endif #endif
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC) #if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
EXTERN unsigned short ebcdic_map[256]; EXTERN unsigned short ebcdic_map[256];

18
syn.c
View File

@ -24,7 +24,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.125 2018/01/13 23:55:14 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/syn.c,v 1.126 2018/01/14 00:03:04 tg Exp $");
struct nesting_state { struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */ int start_token; /* token than began nesting (eg, FOR) */
@ -334,7 +334,7 @@ get_command(int cf, int sALIAS)
XPput(args, yylval.cp); XPput(args, yylval.cp);
break; break;
case CORD('(' /*)*/): case ORD('(' /*)*/):
if (XPsize(args) == 0 && XPsize(vars) == 1 && if (XPsize(args) == 0 && XPsize(vars) == 1 &&
is_wdvarassign(yylval.cp)) { is_wdvarassign(yylval.cp)) {
char *tcp; char *tcp;
@ -390,7 +390,7 @@ get_command(int cf, int sALIAS)
Leave: Leave:
break; break;
case CORD('(' /*)*/): { case ORD('(' /*)*/): {
unsigned int subshell_nesting_type_saved; unsigned int subshell_nesting_type_saved;
Subshell: Subshell:
subshell_nesting_type_saved = subshell_nesting_type; subshell_nesting_type_saved = subshell_nesting_type;
@ -400,7 +400,7 @@ get_command(int cf, int sALIAS)
break; break;
} }
case CORD('{' /*}*/): case ORD('{' /*}*/):
t = nested(TBRACE, ORD('{'), ORD('}'), sALIAS); t = nested(TBRACE, ORD('{'), ORD('}'), sALIAS);
break; break;
@ -411,7 +411,7 @@ get_command(int cf, int sALIAS)
switch (token(LETEXPR)) { switch (token(LETEXPR)) {
case LWORD: case LWORD:
break; break;
case CORD('(' /*)*/): case ORD('(' /*)*/):
c = ORD('('); c = ORD('(');
goto Subshell; goto Subshell;
default: default:
@ -646,7 +646,7 @@ casepart(int endtok, int sALIAS)
switch (token(0)) { switch (token(0)) {
case LWORD: case LWORD:
break; break;
case CORD('}'): case ORD('}'):
case ESAC: case ESAC:
if (symbol != endtok) { if (symbol != endtok) {
strdupx(yylval.cp, (unsigned int)symbol == strdupx(yylval.cp, (unsigned int)symbol ==
@ -813,8 +813,8 @@ static const struct tokeninfo {
{ "in", IN, true }, { "in", IN, true },
{ Tfunction, FUNCTION, true }, { Tfunction, FUNCTION, true },
{ Ttime, TIME, true }, { Ttime, TIME, true },
{ "{", CORD('{'), true }, { "{", ORD('{'), true },
{ Tcbrace, CORD('}'), true }, { Tcbrace, ORD('}'), true },
{ "!", BANG, true }, { "!", BANG, true },
{ "[[", DBRACKET, true }, { "[[", DBRACKET, true },
/* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */ /* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */
@ -826,7 +826,7 @@ static const struct tokeninfo {
{ "((", MDPAREN, false }, { "((", MDPAREN, false },
{ "|&", COPROC, false }, { "|&", COPROC, false },
/* and some special cases... */ /* and some special cases... */
{ "newline", CORD('\n'), false }, { "newline", ORD('\n'), false },
{ NULL, 0, false } { NULL, 0, false }
}; };

30
tree.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.94 2018/01/13 23:55:14 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.95 2018/01/14 00:03:05 tg Exp $");
#define INDENT 8 #define INDENT 8
@ -342,7 +342,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
c = ord(*wp++); c = ord(*wp++);
if (opmode & WDS_TPUTS) if (opmode & WDS_TPUTS)
switch (c) { switch (c) {
case CORD('\n'): case ORD('\n'):
if (quotelevel == 0) { if (quotelevel == 0) {
c = ORD('\''); c = ORD('\'');
shf_putc(c, shf); shf_putc(c, shf);
@ -352,10 +352,10 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
default: default:
if (quotelevel == 0) if (quotelevel == 0)
/* FALLTHROUGH */ /* FALLTHROUGH */
case CORD('"'): case ORD('"'):
case CORD('`'): case ORD('`'):
case CORD('$'): case ORD('$'):
case CORD('\\'): case ORD('\\'):
shf_putc(ORD('\\'), shf); shf_putc(ORD('\\'), shf);
break; break;
} }
@ -470,33 +470,33 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
while ((c = ord(*fmt++))) { while ((c = ord(*fmt++))) {
if (c == '%') { if (c == '%') {
switch ((c = ord(*fmt++))) { switch ((c = ord(*fmt++))) {
case CORD('c'): case ORD('c'):
/* character (octet, probably) */ /* character (octet, probably) */
shf_putchar(va_arg(va, int), shf); shf_putchar(va_arg(va, int), shf);
break; break;
case CORD('s'): case ORD('s'):
/* string */ /* string */
shf_puts(va_arg(va, char *), shf); shf_puts(va_arg(va, char *), shf);
break; break;
case CORD('S'): case ORD('S'):
/* word */ /* word */
wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS); wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS);
break; break;
case CORD('d'): case ORD('d'):
/* signed decimal */ /* signed decimal */
shf_fprintf(shf, Tf_d, va_arg(va, int)); shf_fprintf(shf, Tf_d, va_arg(va, int));
break; break;
case CORD('u'): case ORD('u'):
/* unsigned decimal */ /* unsigned decimal */
shf_fprintf(shf, "%u", va_arg(va, unsigned int)); shf_fprintf(shf, "%u", va_arg(va, unsigned int));
break; break;
case CORD('T'): case ORD('T'):
/* format tree */ /* format tree */
ptree(va_arg(va, struct op *), indent, shf); ptree(va_arg(va, struct op *), indent, shf);
goto dont_trash_prevent_semicolon; goto dont_trash_prevent_semicolon;
case CORD(';'): case ORD(';'):
/* newline or ; */ /* newline or ; */
case CORD('N'): case ORD('N'):
/* newline or space */ /* newline or space */
if (shf->flags & SHF_STRING) { if (shf->flags & SHF_STRING) {
if ((unsigned int)c == ORD(';') && if ((unsigned int)c == ORD(';') &&
@ -516,7 +516,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
shf_putc(' ', shf); shf_putc(' ', shf);
} }
break; break;
case CORD('R'): case ORD('R'):
/* I/O redirection */ /* I/O redirection */
pioact(shf, va_arg(va, struct ioword *)); pioact(shf, va_arg(va, struct ioword *));
break; break;