mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +00:00
tweak: make better use of funptr() macro and sh.bltinfun pointer
src/cmd/ksh93/include/name.h: - Include the ususally-wanted (Shbltin_f) typecast in funptr(). Various files: - Change several direct foo->nvalue.bfp usages to funptr(np). - Reduce explicit typecasts after the name.h change. - To determine if we are (or just were) running a certain built-in command, instead of comparing sh.bltindata.bnode with a builtin table node, use sh.bltinfun to directly compare the builtin's function; this is more readable and efficient.
This commit is contained in:
parent
05fc199c95
commit
cae9af5eec
9 changed files with 16 additions and 16 deletions
|
@ -1229,7 +1229,7 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context)
|
||||||
{
|
{
|
||||||
if(nv_isattr(np,BLT_SPC))
|
if(nv_isattr(np,BLT_SPC))
|
||||||
errmsg = "restricted name";
|
errmsg = "restricted name";
|
||||||
addr = (Shbltin_f)np->nvalue.bfp;
|
addr = funptr(np);
|
||||||
}
|
}
|
||||||
if(!dlete && !addr && !(np=sh_addbuiltin(arg,(Shbltin_f)0 ,0)))
|
if(!dlete && !addr && !(np=sh_addbuiltin(arg,(Shbltin_f)0 ,0)))
|
||||||
errmsg = "not found";
|
errmsg = "not found";
|
||||||
|
|
|
@ -149,7 +149,7 @@ struct Ufunction
|
||||||
#define is_abuiltin(n) (nv_isattr(n,NV_BLTIN|NV_INTEGER)==NV_BLTIN)
|
#define is_abuiltin(n) (nv_isattr(n,NV_BLTIN|NV_INTEGER)==NV_BLTIN)
|
||||||
#define is_afunction(n) (nv_isattr(n,NV_FUNCTION|NV_REF)==NV_FUNCTION)
|
#define is_afunction(n) (nv_isattr(n,NV_FUNCTION|NV_REF)==NV_FUNCTION)
|
||||||
#define nv_funtree(n) ((n)->nvalue.rp->ptree)
|
#define nv_funtree(n) ((n)->nvalue.rp->ptree)
|
||||||
#define funptr(n) ((n)->nvalue.bfp)
|
#define funptr(n) ((Shbltin_f)(n)->nvalue.bfp)
|
||||||
|
|
||||||
/* NAMNOD MACROS */
|
/* NAMNOD MACROS */
|
||||||
/* ... for attributes */
|
/* ... for attributes */
|
||||||
|
|
|
@ -406,7 +406,7 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
|
||||||
char lastbase=0, *val = xp, oerrno = errno;
|
char lastbase=0, *val = xp, oerrno = errno;
|
||||||
lvalue->eflag = 0;
|
lvalue->eflag = 0;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if(!sh_isoption(sh.bltindata.bnode==SYSLET ? SH_LETOCTAL : SH_POSIX))
|
if(!sh_isoption(sh.bltinfun==b_let ? SH_LETOCTAL : SH_POSIX))
|
||||||
{
|
{
|
||||||
/* Skip leading zeros to avoid parsing as octal */
|
/* Skip leading zeros to avoid parsing as octal */
|
||||||
while(*val=='0' && isdigit(val[1]))
|
while(*val=='0' && isdigit(val[1]))
|
||||||
|
@ -529,7 +529,7 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
|
||||||
Sfdouble_t sh_strnum(register const char *str, char** ptr, int mode)
|
Sfdouble_t sh_strnum(register const char *str, char** ptr, int mode)
|
||||||
{
|
{
|
||||||
register Sfdouble_t d;
|
register Sfdouble_t d;
|
||||||
char base = (sh_isoption(sh.bltindata.bnode==SYSLET ? SH_LETOCTAL : SH_POSIX) ? 0 : 10), *last;
|
char base = (sh_isoption(sh.bltinfun==b_let ? SH_LETOCTAL : SH_POSIX) ? 0 : 10), *last;
|
||||||
if(*str==0)
|
if(*str==0)
|
||||||
{
|
{
|
||||||
d = 0.0;
|
d = 0.0;
|
||||||
|
|
|
@ -534,7 +534,7 @@ void sh_exit(register int xno)
|
||||||
register int sig=0;
|
register int sig=0;
|
||||||
register Sfio_t* pool;
|
register Sfio_t* pool;
|
||||||
/* POSIX requires exit status >= 2 for error in 'test'/'[' */
|
/* POSIX requires exit status >= 2 for error in 'test'/'[' */
|
||||||
if(xno == 1 && (sh.bltindata.bnode==SYSTEST || sh.bltindata.bnode==SYSBRACKET))
|
if(xno==1 && sh.bltinfun==b_test)
|
||||||
sh.exitval = 2;
|
sh.exitval = 2;
|
||||||
else
|
else
|
||||||
sh.exitval = xno;
|
sh.exitval = xno;
|
||||||
|
|
|
@ -1113,7 +1113,7 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra)
|
||||||
int offset=staktell();
|
int offset=staktell();
|
||||||
if(extra==(void*)1)
|
if(extra==(void*)1)
|
||||||
name = path;
|
name = path;
|
||||||
else if((name = path_basename(path))==path && bltin!=(Shbltin_f)SYSTYPESET->nvalue.bfp && (nq=nv_bfsearch(name,sh.bltin_tree,(Namval_t**)0,&cp)))
|
else if((name = path_basename(path))==path && bltin!=b_typeset && (nq=nv_bfsearch(name,sh.bltin_tree,(Namval_t**)0,&cp)))
|
||||||
path = name = stakptr(offset);
|
path = name = stakptr(offset);
|
||||||
else if(sh.bltin_dir && extra!=(void*)1)
|
else if(sh.bltin_dir && extra!=(void*)1)
|
||||||
{
|
{
|
||||||
|
@ -1152,7 +1152,7 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra)
|
||||||
if(nv_isattr(np,BLT_SPC))
|
if(nv_isattr(np,BLT_SPC))
|
||||||
return(np);
|
return(np);
|
||||||
if(!bltin)
|
if(!bltin)
|
||||||
bltin = (Shbltin_f)np->nvalue.bfp;
|
bltin = funptr(np);
|
||||||
if(np->nvenv)
|
if(np->nvenv)
|
||||||
dtdelete(sh.bltin_tree,np);
|
dtdelete(sh.bltin_tree,np);
|
||||||
if(extra == (void*)1)
|
if(extra == (void*)1)
|
||||||
|
|
|
@ -799,7 +799,7 @@ void nv_addtype(Namval_t *np, const char *optstr, Optdisc_t *op, size_t optsz)
|
||||||
#endif /* SHOPT_NAMESPACE */
|
#endif /* SHOPT_NAMESPACE */
|
||||||
if((bp=nv_search(name,sh.fun_tree,NV_NOSCOPE)) && !bp->nvalue.ip)
|
if((bp=nv_search(name,sh.fun_tree,NV_NOSCOPE)) && !bp->nvalue.ip)
|
||||||
nv_delete(bp,sh.fun_tree,0);
|
nv_delete(bp,sh.fun_tree,0);
|
||||||
bp = sh_addbuiltin(name, (Shbltin_f)mp->nvalue.bfp, (void*)cp);
|
bp = sh_addbuiltin(name, funptr(mp), cp);
|
||||||
nv_onattr(bp,nv_isattr(mp,NV_PUBLIC));
|
nv_onattr(bp,nv_isattr(mp,NV_PUBLIC));
|
||||||
nv_onattr(np, NV_RDONLY);
|
nv_onattr(np, NV_RDONLY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ static void check_typedef(struct comnod *tp, char intypeset)
|
||||||
dcl_tree = dtopen(&_Nvdisc, Dtoset);
|
dcl_tree = dtopen(&_Nvdisc, Dtoset);
|
||||||
dtview(sh.bltin_tree, dcl_tree);
|
dtview(sh.bltin_tree, dcl_tree);
|
||||||
}
|
}
|
||||||
nv_onattr(sh_addbuiltin(cp, (Shbltin_f)SYSTRUE->nvalue.bfp, NIL(void*)), NV_BLTIN|BLT_DCL);
|
nv_onattr(sh_addbuiltin(cp, b_true, NIL(void*)), NV_BLTIN|BLT_DCL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -1563,7 +1563,7 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io)
|
||||||
cmdarg++;
|
cmdarg++;
|
||||||
else if(np==SYSEXEC || np==SYSREDIR)
|
else if(np==SYSEXEC || np==SYSREDIR)
|
||||||
lexp->inexec = 1;
|
lexp->inexec = 1;
|
||||||
else if(np->nvalue.bfp==(Nambfp_f)b_getopts)
|
else if(funptr(np)==b_getopts)
|
||||||
opt_get |= FOPTGET;
|
opt_get |= FOPTGET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -821,7 +821,7 @@ Pathcomp_t *path_absolute(register const char *name, Pathcomp_t *pp, int flag)
|
||||||
sh_addlib(dll,stakptr(m),oldpp);
|
sh_addlib(dll,stakptr(m),oldpp);
|
||||||
if(dll &&
|
if(dll &&
|
||||||
(addr=(Shbltin_f)dlllook(dll,stakptr(n))) &&
|
(addr=(Shbltin_f)dlllook(dll,stakptr(n))) &&
|
||||||
(!(np = sh_addbuiltin(stakptr(PATH_OFFSET),NiL,NiL)) || np->nvalue.bfp!=(Nambfp_f)addr) &&
|
(!(np = sh_addbuiltin(stakptr(PATH_OFFSET),NiL,NiL)) || funptr(np)!=addr) &&
|
||||||
(np = sh_addbuiltin(stakptr(PATH_OFFSET),addr,NiL)))
|
(np = sh_addbuiltin(stakptr(PATH_OFFSET),addr,NiL)))
|
||||||
{
|
{
|
||||||
np->nvenv = dll;
|
np->nvenv = dll;
|
||||||
|
@ -869,7 +869,7 @@ Pathcomp_t *path_absolute(register const char *name, Pathcomp_t *pp, int flag)
|
||||||
if(np)
|
if(np)
|
||||||
{
|
{
|
||||||
n = np->nvflag;
|
n = np->nvflag;
|
||||||
np = sh_addbuiltin(stakptr(PATH_OFFSET),(Shbltin_f)np->nvalue.bfp,nv_context(np));
|
np = sh_addbuiltin(stakptr(PATH_OFFSET),funptr(np),nv_context(np));
|
||||||
np->nvflag = n;
|
np->nvflag = n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,7 +394,7 @@ static int p_comarg(register struct comnod *com)
|
||||||
bp->ptr = nv_context(np);
|
bp->ptr = nv_context(np);
|
||||||
bp->data = com->comstate;
|
bp->data = com->comstate;
|
||||||
bp->flags = SH_END_OPTIM;
|
bp->flags = SH_END_OPTIM;
|
||||||
((Shbltin_f)funptr(np))(0,(char**)0, bp);
|
(funptr(np))(0, NIL(char**), bp);
|
||||||
bp->ptr = save_ptr;
|
bp->ptr = save_ptr;
|
||||||
bp->data = save_data;
|
bp->data = save_data;
|
||||||
}
|
}
|
||||||
|
@ -1046,7 +1046,7 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
else if(checkopt(com,'a'))
|
else if(checkopt(com,'a'))
|
||||||
flgs |= NV_IARRAY;
|
flgs |= NV_IARRAY;
|
||||||
}
|
}
|
||||||
if(np && np->nvalue.bfp==SYSTYPESET->nvalue.bfp)
|
if(np && funptr(np)==b_typeset)
|
||||||
{
|
{
|
||||||
/* command calls b_typeset(); treat as a typeset variant */
|
/* command calls b_typeset(); treat as a typeset variant */
|
||||||
flgs |= NV_UNATTR; /* unset previous attributes before assigning */
|
flgs |= NV_UNATTR; /* unset previous attributes before assigning */
|
||||||
|
@ -1297,7 +1297,7 @@ int sh_exec(register const Shnode_t *t, int flags)
|
||||||
error_info.id = *com;
|
error_info.id = *com;
|
||||||
if(argn)
|
if(argn)
|
||||||
sh.exitval = 0;
|
sh.exitval = 0;
|
||||||
sh.bltinfun = (Shbltin_f)funptr(np);
|
sh.bltinfun = funptr(np);
|
||||||
bp->bnode = np;
|
bp->bnode = np;
|
||||||
bp->vnode = nq;
|
bp->vnode = nq;
|
||||||
bp->ptr = nv_context(np);
|
bp->ptr = nv_context(np);
|
||||||
|
@ -3303,7 +3303,7 @@ int sh_fun(Namval_t *np, Namval_t *nq, char *argv[])
|
||||||
opt_info.index = opt_info.offset = 0;
|
opt_info.index = opt_info.offset = 0;
|
||||||
opt_info.disc = 0;
|
opt_info.disc = 0;
|
||||||
sh.exitval = 0;
|
sh.exitval = 0;
|
||||||
sh.exitval = ((Shbltin_f)funptr(np))(n,argv,bp);
|
sh.exitval = (funptr(np))(n,argv,bp);
|
||||||
}
|
}
|
||||||
sh_popcontext(buffp);
|
sh_popcontext(buffp);
|
||||||
if(jmpval>SH_JMPCMD)
|
if(jmpval>SH_JMPCMD)
|
||||||
|
|
Loading…
Reference in a new issue