/*-
* 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
#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.127 2018/01/14 00:22:30 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
struct yyrecursive_state *next;
struct ioword **old_herep;
int old_symbol;
- int old_nesting_type;
+ unsigned int old_nesting_type;
bool old_reject;
};
#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";
c = tpeek(0);
if (c == 0 && !outtree)
outtree = newtp(TEOF);
- else if (c != '\n' && c != 0)
+ else if (!cinttype(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 '(': /*)*/ {
- int subshell_nesting_type_saved;
+ case ORD('(' /*)*/): {
+ unsigned 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 ((unsigned int)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 ((unsigned int)c == ORD('{'))
+ c = ORD('}');
else
syntaxerr(NULL);
t = tl = NULL;
XPinit(ptns, 16);
t = newtp(TPAT);
/* no ALIAS here */
- if (token(CONTIN | KEYWORD) != '(')
+ if ((unsigned int)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);
+ strdupx(yylval.cp, (unsigned int)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 ((unsigned int)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 = (unsigned int)c == ORD('(') /*)*/ ? TO_NONNULL : TO_NONOP;
else if (meta == TM_CPAREN)
- ret = c == /*(*/ ')' ? 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 ||
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;
struct op *t;
char *cp;
struct yyrecursive_state *ys;
- int stok, etok;
+ unsigned 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);