#include "sh.h"
-__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.120 2017/04/06 01:59:57 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.124 2017/05/05 22:53:31 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
c = tpeek(0);
if (c == 0 && !outtree)
outtree = newtp(TEOF);
- else if (c != '\n' && c != 0)
+ else if (!ctype(c, C_LF | C_NUL))
syntaxerr(NULL);
}
XPput(args, yylval.cp);
break;
- case '(' /*)*/:
+ case ord('(' /*)*/):
if (XPsize(args) == 0 && XPsize(vars) == 1 &&
is_wdvarassign(yylval.cp)) {
char *tcp;
XPsize(vars) != 0)
syntaxerr(NULL);
ACCEPT;
- musthave(/*(*/')', 0);
+ musthave(/*(*/ ')', 0);
t = function_body(XPptrv(args)[0],
sALIAS, false);
}
Leave:
break;
- case '(': /*)*/ {
+ case ord('(' /*)*/): {
int subshell_nesting_type_saved;
Subshell:
subshell_nesting_type_saved = subshell_nesting_type;
- subshell_nesting_type = ')';
- t = nested(TPAREN, '(', ')', sALIAS);
+ subshell_nesting_type = ord(')');
+ t = nested(TPAREN, ord('('), ord(')'), sALIAS);
subshell_nesting_type = subshell_nesting_type_saved;
break;
}
- case '{': /*}*/
- t = nested(TBRACE, '{', '}', sALIAS);
+ case ord('{' /*}*/):
+ t = nested(TBRACE, ord('{'), ord('}'), sALIAS);
break;
case MDPAREN:
switch (token(LETEXPR)) {
case LWORD:
break;
- case '(': /*)*/
- c = '(';
+ case ord('(' /*)*/):
+ c = ord('(');
goto Subshell;
default:
syntaxerr(NULL);
*/
if (c == DO)
c = DONE;
- else if (c == '{')
- c = '}';
+ else if (c == ord('{'))
+ c = ord('}');
else
syntaxerr(NULL);
list = c_list(sALIAS, true);
/* A {...} can be used instead of in...esac for case statements */
if (c == IN)
c = ESAC;
- else if (c == '{')
- c = '}';
+ else if (c == ord('{'))
+ c = ord('}');
else
syntaxerr(NULL);
t = tl = NULL;
XPinit(ptns, 16);
t = newtp(TPAT);
/* no ALIAS here */
- if (token(CONTIN | KEYWORD) != '(')
+ if (token(CONTIN | KEYWORD) != ord('('))
REJECT;
do {
switch (token(0)) {
case LWORD:
break;
- case '}':
+ case ord('}'):
case ESAC:
if (symbol != endtok) {
strdupx(yylval.cp,
- symbol == '}' ? Tcbrace : Tesac, ATEMP);
+ symbol == ord('}') ? Tcbrace : Tesac,
+ ATEMP);
break;
}
/* FALLTHROUGH */
REJECT;
XPput(ptns, NULL);
t->vars = (char **)XPclose(ptns);
- musthave(')', 0);
+ musthave(ord(')'), 0);
t->left = c_list(sALIAS, true);
/* initialise to default for ;; or omitted */
- t->u.charflag = ';';
+ t->u.charflag = ord(';');
/* SUSv4 requires the ;; except in the last casepart */
if ((tpeek(CONTIN|KEYWORD|sALIAS)) != endtok)
switch (symbol) {
default:
syntaxerr(NULL);
case BRKEV:
- t->u.charflag = '|';
+ t->u.charflag = ord('|');
if (0)
/* FALLTHROUGH */
case BRKFT:
- t->u.charflag = '&';
+ t->u.charflag = ord('&');
/* FALLTHROUGH */
case BREAK:
/* initialised above, but we need to eat the token */
* only allow [a-zA-Z_0-9] but this allows more as old pdkshs
* have allowed more; the following were never allowed:
* NUL TAB NL SP " $ & ' ( ) ; < = > \ ` |
- * C_QUOTE covers all but adds # * ? [ ]
+ * C_QUOTE|C_SPC covers all but adds # * ? [ ]
*/
for (p = sname; *p; p++)
- if (ctype(*p, C_QUOTE))
+ if (ctype(*p, C_QUOTE | C_SPC))
yyerror(Tinvname, sname, Tfunction);
/*
* only accepts an open-brace.
*/
if (ksh_func) {
- if (tpeek(CONTIN|KEYWORD|sALIAS) == '(' /*)*/) {
+ if (tpeek(CONTIN|KEYWORD|sALIAS) == ord('(' /*)*/)) {
/* function foo () { //}*/
ACCEPT;
- musthave(')', 0);
+ musthave(ord(/*(*/ ')'), 0);
/* degrade to POSIX function */
ksh_func = false;
}
- musthave('{' /*}*/, CONTIN|KEYWORD|sALIAS);
+ musthave(ord('{' /*}*/), CONTIN|KEYWORD|sALIAS);
REJECT;
}
{ "in", IN, true },
{ Tfunction, FUNCTION, true },
{ Ttime, TIME, true },
- { "{", '{', true },
- { Tcbrace, '}', true },
+ { "{", ord('{'), true },
+ { Tcbrace, ord('}'), true },
{ "!", BANG, true },
{ "[[", DBRACKET, true },
/* Lexical tokens (0[EOF], LWORD and REDIR handled specially) */
{ "((", MDPAREN, false },
{ "|&", COPROC, false },
/* and some special cases... */
- { "newline", '\n', false },
+ { "newline", ord('\n'), false },
{ NULL, 0, false }
};
ret = (uqword && !strcmp(yylval.cp,
dbtest_tokens[(int)TM_NOT])) ? TO_NONNULL : TO_NONOP;
else if (meta == TM_OPAREN)
- ret = c == '(' /*)*/ ? TO_NONNULL : TO_NONOP;
+ ret = c == ord('(') /*)*/ ? TO_NONNULL : TO_NONOP;
else if (meta == TM_CPAREN)
- ret = c == /*(*/ ')' ? TO_NONNULL : TO_NONOP;
+ ret = c == /*(*/ ord(')') ? TO_NONNULL : TO_NONOP;
else if (meta == TM_UNOP || meta == TM_BINOP) {
if (meta == TM_BINOP && c == REDIR &&
(yylval.iop->ioflag == IOREAD ||
tv->tv_sec = 0;
/* parse integral part */
- while (ksh_isdigit(*s)) {
+ while (ctype(*s, C_DIGIT)) {
tt.tv_sec = tv->tv_sec * 10 + ksh_numdig(*s++);
/*XXX this overflow check maybe UB */
if (tt.tv_sec / 10 != tv->tv_sec) {
/* parse decimal fraction */
i = 100000;
- while (ksh_isdigit(*s)) {
+ while (ctype(*s, C_DIGIT)) {
tv->tv_usec += i * ksh_numdig(*s++);
if (i == 1)
break;
i /= 10;
}
/* check for junk after fractional part */
- while (ksh_isdigit(*s))
+ while (ctype(*s, C_DIGIT))
++s;
if (*s) {
errno = EINVAL;
int stok, etok;
if (subtype != COMSUB) {
- stok = '{';
- etok = '}';
+ stok = ord('{');
+ etok = ord('}');
} else {
- stok = '(';
- etok = ')';
+ stok = ord('(');
+ etok = ord(')');
}
ys = alloc(sizeof(struct yyrecursive_state), ATEMP);