Make test(1) a builtin command of our sh(1) for efficiency. The
binary size increase is 3,784 bytes (about 0.6%). I don't drop the printf builtin while I'm here because some /etc/rc.* scripts seem to use it before mounting /usr where printf(1) resides. Reviewed by: arch (sheldonh) Inspired by: NetBSD, ksh Clued by: ume (on how the printf builtin is used)
This commit is contained in:
parent
39c95b8377
commit
d90c5c4ab4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=86505
@ -5,7 +5,7 @@ PROG= sh
|
||||
SHSRCS= alias.c arith.y arith_lex.l cd.c echo.c error.c eval.c exec.c expand.c \
|
||||
histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
|
||||
mystring.c options.c output.c parser.c printf.c redir.c show.c \
|
||||
trap.c var.c
|
||||
test.c trap.c var.c
|
||||
GENSRCS= builtins.c init.c nodes.c syntax.c
|
||||
GENHDRS= builtins.h nodes.h syntax.h token.h y.tab.h
|
||||
SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS} y.tab.h
|
||||
@ -22,7 +22,9 @@ CFLAGS+=-DSHELL -I. -I${.CURDIR}
|
||||
# for debug:
|
||||
# CFLAGS+= -g -DDEBUG=2
|
||||
|
||||
.PATH: ${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf
|
||||
.PATH: ${.CURDIR}/bltin \
|
||||
${.CURDIR}/../../bin/test \
|
||||
${.CURDIR}/../../usr.bin/printf
|
||||
|
||||
CLEANFILES+= mkinit mkinit.o mknodes mknodes.o \
|
||||
mksyntax mksyntax.o
|
||||
|
@ -62,7 +62,7 @@ execcmd exec
|
||||
exitcmd exit
|
||||
expcmd exp let
|
||||
exportcmd export readonly
|
||||
#exprcmd expr test [
|
||||
#exprcmd expr
|
||||
falsecmd false
|
||||
histcmd -h fc
|
||||
fgcmd -j fg
|
||||
@ -90,3 +90,4 @@ waitcmd wait
|
||||
#foocmd foo
|
||||
aliascmd alias
|
||||
ulimitcmd ulimit
|
||||
testcmd test [
|
||||
|
@ -1273,9 +1273,12 @@ make it the first or last character listed.
|
||||
This section lists the commands which
|
||||
are builtin because they need to perform some operation
|
||||
that cannot be performed by a separate process. In addition to
|
||||
these, a builtin version of the
|
||||
these, builtin versions of the
|
||||
.Xr printf 1
|
||||
command is provided for efficiency.
|
||||
command and
|
||||
the
|
||||
.Xr test 1
|
||||
command are provided for efficiency.
|
||||
.Bl -tag -width Ds
|
||||
.It Ic \&:
|
||||
A null command that returns a 0 (true) exit value.
|
||||
|
@ -286,6 +286,13 @@ The
|
||||
operator has higher precedence than the
|
||||
.Fl o
|
||||
operator.
|
||||
.Pp
|
||||
Some shells may provide a builtin
|
||||
.Nm
|
||||
command which is similar or identical to this utility.
|
||||
Consult the
|
||||
.Xr builtin 1
|
||||
manual page.
|
||||
.Sh GRAMMAR AMBIGUITY
|
||||
The
|
||||
.Nm
|
||||
@ -310,6 +317,7 @@ missing.
|
||||
An error occurred.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr builtin 1 ,
|
||||
.Xr expr 1 ,
|
||||
.Xr sh 1
|
||||
.Sh STANDARDS
|
||||
|
@ -27,6 +27,11 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef SHELL
|
||||
#define main testcmd
|
||||
#include "bltin/bltin.h"
|
||||
#endif
|
||||
|
||||
/* test(1) accepts the following grammar:
|
||||
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
||||
aexpr ::= nexpr | nexpr "-a" aexpr ;
|
||||
|
@ -60,6 +60,7 @@
|
||||
.Nm exec ,
|
||||
.Nm exit ,
|
||||
.Nm export ,
|
||||
.Nm false ,
|
||||
.Nm fc ,
|
||||
.Nm fg ,
|
||||
.Nm filetest ,
|
||||
@ -107,9 +108,11 @@
|
||||
.Nm suspend ,
|
||||
.Nm switch ,
|
||||
.Nm telltc ,
|
||||
.Nm test ,
|
||||
.Nm then ,
|
||||
.Nm time ,
|
||||
.Nm trap ,
|
||||
.Nm true ,
|
||||
.Nm type ,
|
||||
.Nm ulimit ,
|
||||
.Nm umask ,
|
||||
@ -198,6 +201,7 @@ with the other shells.
|
||||
.It Ic exec Ta \&No Ta Yes Ta Yes
|
||||
.It Ic exit Ta \&No Ta Yes Ta Yes
|
||||
.It Ic export Ta \&No Ta \&No Ta Yes
|
||||
.It Ic false Ta Yes Ta \&No Ta Yes
|
||||
.It Ic fc Ta \&No Ta \&No Ta Yes
|
||||
.It Ic fg Ta \&No Ta Yes Ta Yes
|
||||
.It Ic filetest Ta \&No Ta Yes Ta \&No
|
||||
@ -245,9 +249,11 @@ with the other shells.
|
||||
.It Ic suspend Ta \&No Ta Yes Ta \&No
|
||||
.It Ic switch Ta \&No Ta Yes Ta \&No
|
||||
.It Ic telltc Ta \&No Ta Yes Ta \&No
|
||||
.It Ic test Ta Yes Ta \&No Ta Yes
|
||||
.It Ic then Ta \&No Ta \&No Ta Yes
|
||||
.It Ic time Ta Yes Ta Yes Ta \&No
|
||||
.It Ic trap Ta \&No Ta \&No Ta Yes
|
||||
.It Ic true Ta Yes Ta \&No Ta Yes
|
||||
.It Ic type Ta \&No Ta \&No Ta Yes
|
||||
.It Ic ulimit Ta \&No Ta \&No Ta Yes
|
||||
.It Ic umask Ta \&No Ta Yes Ta Yes
|
||||
|
Loading…
Reference in New Issue
Block a user