diff --git a/src/cmd/ksh93/include/shlex.h b/src/cmd/ksh93/include/shlex.h index 8a2bee3aa461..afbebc7aff21 100644 --- a/src/cmd/ksh93/include/shlex.h +++ b/src/cmd/ksh93/include/shlex.h @@ -55,6 +55,7 @@ struct _shlex_pvt_lexdata_ char warn; char message; char arith; + char funcalias; /* bug-666: Phi: */ char *first; int level; int lastc; diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 0dd8432be1a0..2add362fcd2b 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -1458,6 +1458,14 @@ int sh_lex(Lex_t* lp) } } c = 0; + /* + * bug-666: Phi: + * + */ + if(lp->lexd.funcalias==1) + { goto check_alias; + } + if(!lp->lex.skipword) { if(n>1 && lp->lex.reservok==1 && mode==ST_NAME && @@ -1496,6 +1504,8 @@ int sh_lex(Lex_t* lp) { /* check for aliases */ Namval_t* np; + + check_alias: /* bug-666: Phi: */ if(!lp->lex.incase && !assignment && fcpeek(0)!=LPAREN && (np=nv_search(state,sh.alias_tree,0)) && !nv_isattr(np,NV_NOEXPAND) @@ -1503,11 +1513,35 @@ int sh_lex(Lex_t* lp) && (!sh_isstate(SH_NOALIAS) || nv_isattr(np,NV_NOFREE)) && (state=nv_getval(np))) { + int t; /* bug-666: Phi: */ setupalias(lp,state,np); nv_onattr(np,NV_NOEXPAND); lp->lex.reservok = 1; lp->assignok |= lp->lex.reservok; - return sh_lex(lp); + /* + * bug-666: Phi: Check if we just expanded + * "function " (i.e trailig space), if so we + * got to set lp->lexd.funcalias=1; + * so that next funct() will have a chance to + * expand next word. The original return + * below is replaced with the funcalias + * setup + */ + /* return sh_lex(lp); */ + if(lp->lexd.funcalias==1) + { + lp->lexd.funcalias++; + } + t=sh_lex(lp); + if(strcmp(state,"function ")==0) + { + lp->lexd.funcalias=1; + } + else + { + lp->lexd.funcalias=0; + } + return t; } } lp->lex.reservok = 0; diff --git a/src/cmd/ksh93/tests/alias.sh b/src/cmd/ksh93/tests/alias.sh index a349485fd449..1b27f65a0da5 100755 --- a/src/cmd/ksh93/tests/alias.sh +++ b/src/cmd/ksh93/tests/alias.sh @@ -319,5 +319,11 @@ chmod +x bad_func # bug only triggered if file is executable (FPATH=$PWD; alias -t bad_func 2>/dev/null; typeset -f bad_func >/dev/null) (($? > 0)) || err_exit "'hash'/'alias -t' autoloads function" +# bug-666: Phi: +alias 'x=function ' y=f z='{ ' t='echo ' u='AA ' v='}' +x y z t u v +got=$(f) +[ "$got" = 'AA' ] || err_exit "alias x='function ' not working" + # ====== exit $((Errors<125?Errors:125))