1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

whence -f: ignore functions (#137)

According to 'whence --man', 'whence -f' should ignore functions:
  -f              Do not check for functions.

Right now this is only accomplished partially. As of commit
a329c22d 'whence -f' avoids any output when encountering a
function (in ksh93u+ 'whence -f' has incorrect output). The
return value is still wrong though:

$ foo() { true; }
$ whence -f foo; echo $?
0

This commit fixes the return value and makes 'type -f' error out
when given a function (like in Bash).

src/cmd/ksh93/bltins/whence.c:
- If -f was passed, set 'cp' to NULL since functions should be
  ignored (as documented).
- Simplify return value by avoiding bitwise logic.

src/cmd/ksh93/tests/builtins.sh:
- Add regression tests for 'whence -f' and 'type -f'.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2020-09-26 11:26:18 -07:00 committed by GitHub
parent 7e6bbf85b6
commit 8a34fc40e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 7 deletions

View file

@ -135,7 +135,7 @@ static int whence(Shell_t *shp,char **argv, register int flags)
register const char *name;
register Namval_t *np;
register const char *cp;
register int aflag,r=0;
register int aflag, ret = 0;
register const char *msg;
Namval_t *nq;
char *notused;
@ -230,7 +230,7 @@ static int whence(Shell_t *shp,char **argv, register int flags)
cp = name;
if(*cp!='/')
{
if(flags&P_FLAG)
if(flags&(P_FLAG|F_FLAG)) /* Ignore functions when passed -f or -p */
cp = 0;
else
maybe_undef_fn = 1;
@ -244,8 +244,9 @@ static int whence(Shell_t *shp,char **argv, register int flags)
}
if(flags&Q_FLAG)
{
pp = 0;
r |= !cp;
/* Since -q ignores -a, return on the first non-match */
if(!cp)
return(1);
}
else if(maybe_undef_fn)
{
@ -286,7 +287,7 @@ static int whence(Shell_t *shp,char **argv, register int flags)
}
else if(aflag<=1)
{
r |= 1;
ret = 1;
if(flags&V_FLAG)
errormsg(SH_DICT,ERROR_exit(0),e_found,sh_fmtq(name));
}
@ -302,6 +303,6 @@ static int whence(Shell_t *shp,char **argv, register int flags)
pp = 0;
} while(pp);
}
return(r);
return(ret);
}