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
__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
@ -312,12 +312,12 @@ x_glob_hlp_add_qchar(char *cp)
*/
switch (ord(ch)) {
case QCHAR:
case CORD('$'):
case CORD('*'):
case CORD('?'):
case CORD('['):
case CORD('\\'):
case CORD('`'):
case ORD('$'):
case ORD('*'):
case ORD('?'):
case ORD('['):
case ORD('\\'):
case ORD('`'):
*dp++ = QCHAR;
break;
}
@ -4128,7 +4128,7 @@ vi_cmd(int argcnt, const char *cmd)
redraw_line(true);
break;
case CORD('@'):
case ORD('@'):
{
static char alias[] = "_\0";
struct tbl *ap;
@ -4169,7 +4169,7 @@ vi_cmd(int argcnt, const char *cmd)
}
break;
case CORD('a'):
case ORD('a'):
modified = 1;
hnum = hlast;
if (vs->linelen != 0)
@ -4177,7 +4177,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT;
break;
case CORD('A'):
case ORD('A'):
modified = 1;
hnum = hlast;
del_range(0, 0);
@ -4185,7 +4185,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT;
break;
case CORD('S'):
case ORD('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 CORD('Y'):
case ORD('Y'):
cmd = "y$";
/* ahhhhhh... */
/* FALLTHROUGH */
case CORD('c'):
case CORD('d'):
case CORD('y'):
case ORD('c'):
case ORD('d'):
case ORD('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 CORD('p'):
case ORD('p'):
modified = 1;
hnum = hlast;
if (vs->linelen != 0)
@ -4253,7 +4253,7 @@ vi_cmd(int argcnt, const char *cmd)
return (-1);
break;
case CORD('P'):
case ORD('P'):
modified = 1;
hnum = hlast;
any = 0;
@ -4266,25 +4266,25 @@ vi_cmd(int argcnt, const char *cmd)
return (-1);
break;
case CORD('C'):
case ORD('C'):
modified = 1;
hnum = hlast;
del_range(vs->cursor, vs->linelen);
insert = INSERT;
break;
case CORD('D'):
case ORD('D'):
yank_range(vs->cursor, vs->linelen);
del_range(vs->cursor, vs->linelen);
if (vs->cursor != 0)
vs->cursor--;
break;
case CORD('g'):
case ORD('g'):
if (!argcnt)
argcnt = hlast;
/* FALLTHROUGH */
case CORD('G'):
case ORD('G'):
if (!argcnt)
argcnt = 1;
else
@ -4297,21 +4297,21 @@ vi_cmd(int argcnt, const char *cmd)
}
break;
case CORD('i'):
case ORD('i'):
modified = 1;
hnum = hlast;
insert = INSERT;
break;
case CORD('I'):
case ORD('I'):
modified = 1;
hnum = hlast;
vs->cursor = domovebeg();
insert = INSERT;
break;
case CORD('j'):
case CORD('+'):
case ORD('j'):
case ORD('+'):
case CTRL_N:
if (grabhist(modified, hnum + argcnt) < 0)
return (-1);
@ -4321,8 +4321,8 @@ vi_cmd(int argcnt, const char *cmd)
}
break;
case CORD('k'):
case CORD('-'):
case ORD('k'):
case ORD('-'):
case CTRL_P:
if (grabhist(modified, hnum - argcnt) < 0)
return (-1);
@ -4332,7 +4332,7 @@ vi_cmd(int argcnt, const char *cmd)
}
break;
case CORD('r'):
case ORD('r'):
if (vs->linelen == 0)
return (-1);
modified = 1;
@ -4350,13 +4350,13 @@ vi_cmd(int argcnt, const char *cmd)
}
break;
case CORD('R'):
case ORD('R'):
modified = 1;
hnum = hlast;
insert = REPLACE;
break;
case CORD('s'):
case ORD('s'):
if (vs->linelen == 0)
return (-1);
modified = 1;
@ -4367,7 +4367,7 @@ vi_cmd(int argcnt, const char *cmd)
insert = INSERT;
break;
case CORD('v'):
case ORD('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 CORD('x'):
case ORD('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 CORD('X'):
case ORD('X'):
if (vs->cursor > 0) {
modified = 1;
hnum = hlast;
@ -4414,13 +4414,13 @@ vi_cmd(int argcnt, const char *cmd)
return (-1);
break;
case CORD('u'):
case ORD('u'):
t = vs;
vs = undo;
undo = t;
break;
case CORD('U'):
case ORD('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 CORD('?'):
case ORD('?'):
if (hnum == hlast)
hnum = -1;
/* ahhh */
/* FALLTHROUGH */
case CORD('/'):
case ORD('/'):
c3 = 1;
srchlen = 0;
lastsearch = *cmd;
/* FALLTHROUGH */
case CORD('n'):
case CORD('N'):
case ORD('n'):
case ORD('N'):
if (lastsearch == ' ')
return (-1);
if (lastsearch == '?')
@ -4468,7 +4468,7 @@ vi_cmd(int argcnt, const char *cmd)
return (0);
}
break;
case CORD('_'):
case ORD('_'):
{
bool inspace;
char *p, *sp;
@ -4520,7 +4520,7 @@ vi_cmd(int argcnt, const char *cmd)
}
break;
case CORD('~'):
case ORD('~'):
{
char *p;
int i;
@ -4544,7 +4544,7 @@ vi_cmd(int argcnt, const char *cmd)
break;
}
case CORD('#'):
case ORD('#'):
{
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 CORD('='):
case ORD('='):
/* 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 CORD('\\'):
case ORD('\\'):
/* 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 CORD('*'):
case ORD('*'):
/* Nonstandard vi/ksh */
case CTRL_X:
expand_word(1);
@ -4590,8 +4590,8 @@ vi_cmd(int argcnt, const char *cmd)
/* mksh: cursor movement */
case CORD('['):
case CORD('O'):
case ORD('['):
case ORD('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 CORD('b'):
case ORD('b'):
if (!sub && vs->cursor == 0)
return (-1);
ncursor = backword(argcnt);
break;
case CORD('B'):
case ORD('B'):
if (!sub && vs->cursor == 0)
return (-1);
ncursor = Backword(argcnt);
break;
case CORD('e'):
case ORD('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 CORD('E'):
case ORD('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 CORD('f'):
case CORD('F'):
case CORD('t'):
case CORD('T'):
case ORD('f'):
case ORD('F'):
case ORD('t'):
case ORD('T'):
fsavecmd = *cmd;
fsavech = cmd[1];
/* FALLTHROUGH */
case CORD(','):
case CORD(';'):
case ORD(','):
case ORD(';'):
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 CORD('h'):
case ORD('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 CORD(' '):
case CORD('l'):
case ORD(' '):
case ORD('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 CORD('w'):
case ORD('w'):
if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1);
ncursor = forwword(argcnt);
break;
case CORD('W'):
case ORD('W'):
if (!sub && vs->cursor + 1 >= vs->linelen)
return (-1);
ncursor = Forwword(argcnt);
break;
case CORD('0'):
case ORD('0'):
ncursor = 0;
break;
case CORD('^'):
case ORD('^'):
ncursor = domovebeg();
break;
case CORD('|'):
case ORD('|'):
ncursor = argcnt;
if (ncursor > vs->linelen)
ncursor = vs->linelen;
@ -4709,14 +4709,14 @@ domove(int argcnt, const char *cmd, int sub)
ncursor--;
break;
case CORD('$'):
case ORD('$'):
if (vs->linelen != 0)
ncursor = vs->linelen;
else
ncursor = 0;
break;
case CORD('%'):
case ORD('%'):
ncursor = vs->cursor;
while (ncursor < vs->linelen &&
(i = bracktype(vs->cbuf[ncursor])) == 0)
@ -4784,22 +4784,22 @@ bracktype(int ch)
{
switch (ord(ch)) {
case CORD('('):
case ORD('('):
return (1);
case CORD('['):
case ORD('['):
return (2);
case CORD('{'):
case ORD('{'):
return (3);
case CORD(')'):
case ORD(')'):
return (-1);
case CORD(']'):
case ORD(']'):
return (-2);
case CORD('}'):
case ORD('}'):
return (-3);
default:

112
eval.c
View File

@ -23,7 +23,7 @@
#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
@ -436,11 +436,11 @@ expand(
if (stype)
sp += slen;
switch (stype & STYPE_SINGLE) {
case CORD('#') | STYPE_AT:
case ORD('#') | STYPE_AT:
x.str = shf_smprintf("%08X",
(unsigned int)hash(str_val(st->var)));
break;
case CORD('Q') | STYPE_AT: {
case ORD('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 CORD('0'): {
case ORD('0'): {
char *beg, *mid, *end, *stg;
mksh_ari_t from = 0, num = -1, flen, finc = 0;
@ -495,8 +495,8 @@ expand(
strndupx(x.str, beg, num, ATEMP);
goto do_CSUBST;
}
case CORD('/') | STYPE_AT:
case CORD('/'): {
case ORD('/') | STYPE_AT:
case ORD('/'): {
char *s, *p, *d, *sbeg, *end;
char *pat = NULL, *rrep = null;
char fpat = 0, *tpat1, *tpat2;
@ -622,8 +622,8 @@ expand(
afree(ws, ATEMP);
goto do_CSUBST;
}
case CORD('#'):
case CORD('%'):
case ORD('#'):
case ORD('%'):
/* ! DOBLANK,DOBRACE */
f = (f & DONTRUNCOMMAND) |
DOPAT | DOTILDE |
@ -640,7 +640,7 @@ expand(
*dp++ = ORD(0x80 | '@');
}
break;
case CORD('='):
case ORD('='):
/*
* Tilde expansion for string
* variables in POSIX mode is
@ -664,7 +664,7 @@ expand(
f &= ~(DOBLANK|DOGLOB|DOBRACE);
tilde_ok = 1;
break;
case CORD('?'):
case ORD('?'):
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 CORD('#'):
case CORD('%'):
case ORD('#'):
case ORD('%'):
if (!Flag(FSH)) {
/* Append end-pattern */
*dp++ = MAGIC;
@ -730,7 +730,7 @@ expand(
doblank++;
st = st->prev;
continue;
case CORD('='):
case ORD('='):
/*
* 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 CORD('?'):
case ORD('?'):
dp = Xrestpos(ds, dp, st->base);
errorf(Tf_sD_s, st->var->name,
debunk(dp, dp, strlen(dp) + 1));
break;
case CORD('0'):
case CORD('/') | STYPE_AT:
case CORD('/'):
case CORD('#') | STYPE_AT:
case CORD('Q') | STYPE_AT:
case ORD('0'):
case ORD('/') | STYPE_AT:
case ORD('/'):
case ORD('#') | STYPE_AT:
case ORD('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 CORD('['):
case CORD('!'):
case CORD('-'):
case CORD(']'):
case ORD('['):
case ORD('!'):
case ORD('-'):
case ORD(']'):
/*
* For character classes - doesn't hurt
* to have magic !,-,]s outside of
@ -1019,16 +1019,16 @@ expand(
*dp++ = MAGIC;
}
break;
case CORD('*'):
case CORD('?'):
case ORD('*'):
case ORD('?'):
if (f & (DOPAT | DOGLOB)) {
fdo |= DOMAGIC | (f & DOGLOB);
*dp++ = MAGIC;
}
break;
case CORD('{'):
case CORD('}'):
case CORD(','):
case ORD('{'):
case ORD('}'):
case ORD(','):
if ((f & DOBRACE) &&
(ord(c) == ORD('{' /*}*/) ||
(fdo & DOBRACE))) {
@ -1036,7 +1036,7 @@ expand(
*dp++ = MAGIC;
}
break;
case CORD('='):
case ORD('='):
/* Note first unquoted = for ~ */
if (!(f & DOTEMP) && (!Flag(FPOSIX) ||
(f & DOASNTILDE)) && !saw_eq) {
@ -1044,13 +1044,13 @@ expand(
tilde_ok = 1;
}
break;
case CORD(':'):
case ORD(':'):
/* : */
/* Note unquoted : for ~ */
if (!(f & DOTEMP) && (f & DOASNTILDE))
tilde_ok = 1;
break;
case CORD('~'):
case ORD('~'):
/*
* tilde_ok is reset whenever
* any of ' " $( $(( ${ } are seen.
@ -1247,9 +1247,9 @@ varsub(Expand *xp, const char *sp, const char *word,
/* @x where x is command char */
switch (c = ord(word[slen + 2]) == CHAR ?
ord(word[slen + 3]) : 0) {
case CORD('#'):
case CORD('/'):
case CORD('Q'):
case ORD('#'):
case ORD('/'):
case ORD('Q'):
break;
default:
return (-1);
@ -1266,16 +1266,16 @@ varsub(Expand *xp, const char *sp, const char *word,
if ((unsigned int)c == ORD('*') || (unsigned int)c == ORD('@')) {
switch (stype & STYPE_SINGLE) {
/* can't assign to a vector */
case CORD('='):
case ORD('='):
/* can't trim a vector (yet) */
case CORD('%'):
case CORD('#'):
case CORD('?'):
case CORD('0'):
case CORD('/') | STYPE_AT:
case CORD('/'):
case CORD('#') | STYPE_AT:
case CORD('Q') | STYPE_AT:
case ORD('%'):
case ORD('#'):
case ORD('?'):
case ORD('0'):
case ORD('/') | STYPE_AT:
case ORD('/'):
case ORD('#') | STYPE_AT:
case ORD('Q') | STYPE_AT:
return (-1);
}
if (e->loc->argc == 0) {
@ -1297,16 +1297,16 @@ varsub(Expand *xp, const char *sp, const char *word,
switch (stype & STYPE_SINGLE) {
/* can't assign to a vector */
case CORD('='):
case ORD('='):
/* can't trim a vector (yet) */
case CORD('%'):
case CORD('#'):
case CORD('?'):
case CORD('0'):
case CORD('/') | STYPE_AT:
case CORD('/'):
case CORD('#') | STYPE_AT:
case CORD('Q') | STYPE_AT:
case ORD('%'):
case ORD('#'):
case ORD('?'):
case ORD('0'):
case ORD('/') | STYPE_AT:
case ORD('/'):
case ORD('#') | STYPE_AT:
case ORD('Q') | STYPE_AT:
return (-1);
}
c = 0;
@ -1495,7 +1495,7 @@ trimsub(char *str, char *pat, int how)
char *p, c;
switch (how & (STYPE_CHAR | STYPE_DBL)) {
case CORD('#'):
case ORD('#'):
/* shortest match at beginning */
for (p = str; p <= end; p += utf_ptradj(p)) {
c = *p; *p = '\0';
@ -1507,7 +1507,7 @@ trimsub(char *str, char *pat, int how)
*p = c;
}
break;
case CORD('#') | STYPE_DBL:
case ORD('#') | STYPE_DBL:
/* longest match at beginning */
for (p = end; p >= str; p--) {
c = *p; *p = '\0';
@ -1519,7 +1519,7 @@ trimsub(char *str, char *pat, int how)
*p = c;
}
break;
case CORD('%'):
case ORD('%'):
/* shortest match at end */
p = end;
while (p >= str) {
@ -1535,7 +1535,7 @@ trimsub(char *str, char *pat, int how)
--p;
}
break;
case CORD('%') | STYPE_DBL:
case ORD('%') | STYPE_DBL:
/* longest match at end */
for (p = str; p <= end; p++)
if (gmatchx(p, pat, false)) {

70
lex.c
View File

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

20
misc.c
View File

@ -32,7 +32,7 @@
#include <grp.h>
#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
#ifdef MKSH_SMALL
@ -785,7 +785,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
continue;
}
switch (ord(*p++)) {
case CORD('['):
case ORD('['):
/* BSD cclass extension? */
if (ISMAGIC(p[0]) && ord(p[1]) == ORD('[') &&
ord(p[2]) == ORD(':') &&
@ -813,7 +813,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0);
break;
case CORD('?'):
case ORD('?'):
if (sc == 0)
return (0);
if (UTFMODE) {
@ -822,7 +822,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
}
break;
case CORD('*'):
case ORD('*'):
if (p == pe)
return (1);
s--;
@ -838,9 +838,9 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
*/
/* matches one or more times */
case CORD('+') | 0x80:
case ORD('+') | 0x80:
/* matches zero or more times */
case CORD('*') | 0x80:
case ORD('*') | 0x80:
if (!(prest = pat_scan(p, pe, false)))
return (0);
s--;
@ -863,11 +863,11 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0);
/* matches zero or once */
case CORD('?') | 0x80:
case ORD('?') | 0x80:
/* matches one of the patterns */
case CORD('@') | 0x80:
case ORD('@') | 0x80:
/* simile for @ */
case CORD(' ') | 0x80:
case ORD(' ') | 0x80:
if (!(prest = pat_scan(p, pe, false)))
return (0);
s--;
@ -889,7 +889,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
return (0);
/* matches none of the patterns */
case CORD('!') | 0x80:
case ORD('!') | 0x80:
if (!(prest = pat_scan(p, pe, false)))
return (0);
s--;

6
sh.h
View File

@ -182,7 +182,7 @@
#endif
#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
#define MKSH_VERSION "R56 2017/10/17"
@ -1482,11 +1482,9 @@ extern unsigned int eek_ord;
__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)
#define ORD(c) ord(c) /* may evaluate arguments twice */
#endif
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
EXTERN unsigned short ebcdic_map[256];

18
syn.c
View File

@ -24,7 +24,7 @@
#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 {
int start_token; /* token than began nesting (eg, FOR) */
@ -334,7 +334,7 @@ get_command(int cf, int sALIAS)
XPput(args, yylval.cp);
break;
case CORD('(' /*)*/):
case ORD('(' /*)*/):
if (XPsize(args) == 0 && XPsize(vars) == 1 &&
is_wdvarassign(yylval.cp)) {
char *tcp;
@ -390,7 +390,7 @@ get_command(int cf, int sALIAS)
Leave:
break;
case CORD('(' /*)*/): {
case ORD('(' /*)*/): {
unsigned int subshell_nesting_type_saved;
Subshell:
subshell_nesting_type_saved = subshell_nesting_type;
@ -400,7 +400,7 @@ get_command(int cf, int sALIAS)
break;
}
case CORD('{' /*}*/):
case ORD('{' /*}*/):
t = nested(TBRACE, ORD('{'), ORD('}'), sALIAS);
break;
@ -411,7 +411,7 @@ get_command(int cf, int sALIAS)
switch (token(LETEXPR)) {
case LWORD:
break;
case CORD('(' /*)*/):
case ORD('(' /*)*/):
c = ORD('(');
goto Subshell;
default:
@ -646,7 +646,7 @@ casepart(int endtok, int sALIAS)
switch (token(0)) {
case LWORD:
break;
case CORD('}'):
case ORD('}'):
case ESAC:
if (symbol != endtok) {
strdupx(yylval.cp, (unsigned int)symbol ==
@ -813,8 +813,8 @@ static const struct tokeninfo {
{ "in", IN, true },
{ Tfunction, FUNCTION, true },
{ Ttime, TIME, true },
{ "{", CORD('{'), true },
{ Tcbrace, CORD('}'), true },
{ "{", ORD('{'), true },
{ Tcbrace, ORD('}'), true },
{ "!", BANG, true },
{ "[[", DBRACKET, true },
/* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */
@ -826,7 +826,7 @@ static const struct tokeninfo {
{ "((", MDPAREN, false },
{ "|&", COPROC, false },
/* and some special cases... */
{ "newline", CORD('\n'), false },
{ "newline", ORD('\n'), false },
{ NULL, 0, false }
};

30
tree.c
View File

@ -23,7 +23,7 @@
#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
@ -342,7 +342,7 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
c = ord(*wp++);
if (opmode & WDS_TPUTS)
switch (c) {
case CORD('\n'):
case ORD('\n'):
if (quotelevel == 0) {
c = ORD('\'');
shf_putc(c, shf);
@ -352,10 +352,10 @@ wdvarput(struct shf *shf, const char *wp, int quotelevel, int opmode)
default:
if (quotelevel == 0)
/* FALLTHROUGH */
case CORD('"'):
case CORD('`'):
case CORD('$'):
case CORD('\\'):
case ORD('"'):
case ORD('`'):
case ORD('$'):
case ORD('\\'):
shf_putc(ORD('\\'), shf);
break;
}
@ -470,33 +470,33 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
while ((c = ord(*fmt++))) {
if (c == '%') {
switch ((c = ord(*fmt++))) {
case CORD('c'):
case ORD('c'):
/* character (octet, probably) */
shf_putchar(va_arg(va, int), shf);
break;
case CORD('s'):
case ORD('s'):
/* string */
shf_puts(va_arg(va, char *), shf);
break;
case CORD('S'):
case ORD('S'):
/* word */
wdvarput(shf, va_arg(va, char *), 0, WDS_TPUTS);
break;
case CORD('d'):
case ORD('d'):
/* signed decimal */
shf_fprintf(shf, Tf_d, va_arg(va, int));
break;
case CORD('u'):
case ORD('u'):
/* unsigned decimal */
shf_fprintf(shf, "%u", va_arg(va, unsigned int));
break;
case CORD('T'):
case ORD('T'):
/* format tree */
ptree(va_arg(va, struct op *), indent, shf);
goto dont_trash_prevent_semicolon;
case CORD(';'):
case ORD(';'):
/* newline or ; */
case CORD('N'):
case ORD('N'):
/* newline or space */
if (shf->flags & SHF_STRING) {
if ((unsigned int)c == ORD(';') &&
@ -516,7 +516,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
shf_putc(' ', shf);
}
break;
case CORD('R'):
case ORD('R'):
/* I/O redirection */
pioact(shf, va_arg(va, struct ioword *));
break;