Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Apr 2000 00:29:00 +0000
From:      Anatoly Vorobey <mellon@pobox.com>
To:        Doug Barton <Doug@gorean.org>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: commit MAKE_SHELL?
Message-ID:  <20000427002859.A78245@happy.checkpoint.com>
In-Reply-To: <20000426195519.A2022@happy.checkpoint.com>; from mellon@pobox.com on Wed, Apr 26, 2000 at 07:55:19PM %2B0000
References:  <Pine.BSF.4.21.0004231837560.46547-200000@green.dyndns.org>; <20000425170951.A29390@happy.checkpoint.com> <200004251528.RAA29727@m2.dynas.se> <20000425232447.A32567@happy.checkpoint.com> <390685E7.986C2EBA@gorean.org> <20000426195519.A2022@happy.checkpoint.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Apr 26, 2000 at 07:55:19PM +0000, Anatoly Vorobey wrote:

> > 	Unfortunately, the only way to tell for sure would be to do a couple
> > make worlds with the current sh, then do some with super-sh with the
> > built in 'test'. 
> 
> You are right. I will do it, and report the results.

Reporting back ;) Adding built-in "test" turns out to be frightfully easy,
by compiling into the shell the real test(1) code (builtin printf works
this way, too). I have broken world right now so I can't test it, but on
running several configure scripts from ports I generally save from 9% to 
18% of time. Maybe someone would like to test/review/comment on this?

Patches below. In test(1), errx() calls had to be changed into warnx()
calls because the latter are #define'd to be something else when compiling
within the shell, in order to capture the output when necessary.

To test, 'sh /usr/src/bin/test/TEST.sh', run configures, build worlds, etc. ;)

Index: test.c
===================================================================
RCS file: /freebsd/cvs/src/bin/test/test.c,v
retrieving revision 1.29
diff -u -r1.29 test.c
--- test.c	1999/12/28 09:34:57	1.29
+++ test.c	2000/04/26 22:30:13
@@ -10,10 +10,12 @@
  * This program is in the Public Domain.
  */
 
+#if !defined(SHELL)
 #ifndef lint
 static const char rcsid[] =
   "$FreeBSD: src/bin/test/test.c,v 1.29 1999/12/28 09:34:57 sheldonh Exp $";
 #endif /* not lint */
+#endif /* not a sh builtin */
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -26,6 +28,11 @@
 #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 ;
@@ -171,7 +178,7 @@
 		p++;
 	if (strcmp(p, "[") == 0) {
 		if (strcmp(argv[--argc], "]"))
-			errx(2, "missing ]");
+			return( (warnx("missing ]") , 2) );
 		argv[argc] = NULL;
 	}
 
@@ -195,9 +202,9 @@
 {
 
 	if (op && *op)
-		errx(2, "%s: %s", op, msg);
+		exit( (warnx("%s: %s", op, msg), 2) );
 	else
-		errx(2, "%s", msg);
+		exit( (warnx("%s", msg), 2) );
 }
 
 static int

Index: Makefile
===================================================================
RCS file: /freebsd/cvs/src/bin/sh/Makefile,v
retrieving revision 1.30
diff -u -r1.30 Makefile
--- Makefile	1999/09/08 15:40:43	1.30
+++ Makefile	2000/04/27 00:24:55
@@ -5,7 +5,7 @@
 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,7 @@
 # for debug:
 # CFLAGS+= -g -DDEBUG=2
 
-.PATH:	${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf
+.PATH:	${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf ${.CURDIR}/../test
 
 CLEANFILES+= mkinit mkinit.o mknodes mknodes.o \
 	mksyntax mksyntax.o
Index: builtins.def
===================================================================
RCS file: /freebsd/cvs/src/bin/sh/builtins.def,v
retrieving revision 1.7
diff -u -r1.7 builtins.def
--- builtins.def	1999/08/27 23:15:08	1.7
+++ builtins.def	2000/04/27 00:25:08
@@ -80,6 +80,7 @@
 setcmd		set
 setvarcmd	setvar
 shiftcmd	shift
+testcmd		test [
 trapcmd		trap
 truecmd		: true
 typecmd		type

-- 
Anatoly Vorobey,
mellon@pobox.com http://pobox.com/~mellon/
"Angels can fly because they take themselves lightly" - G.K.Chesterton


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000427002859.A78245>