NetBSD Problem Report #9847

Received: (qmail 3857 invoked from network); 9 Apr 2000 12:48:39 -0000
Message-Id: <20000409124832.8463.qmail@primenet.com.au>
Date: 9 Apr 2000 22:48:32 +1000
From: mason@primenet.com.au
Reply-To: mason@primenet.com.au
To: gnats-bugs@gnats.netbsd.org
Subject: Adding test back in to /bin/sh as an internal function
X-Send-Pr-Version: 3.95

>Number:         9847
>Category:       bin
>Synopsis:       adds test back into sh as an internal function
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 09 12:49:01 +0000 2000
>Closed-Date:    Sun Apr 09 23:30:19 +0000 2000
>Last-Modified:  Tue Apr 11 02:48:00 +0000 2000
>Originator:     Geoff C. Wing
>Release:        20000408
>Organization:
Geoff Wing : <gcw@pobox.com>     Work URL: http://www.primenet.com.au/
Rxvt Stuff : <gcw@rxvt.org>      Ego URL : http://pobox.com/~gcw/
Zsh Stuff  : <gcw@zsh.org>       Phone   : (Australia) 0413 431 874
>Environment:
System: NetBSD c.primenet.com.au 1.4X NetBSD 1.4X (C) #0: Mon Apr 3 04:06:56 EST 2000 mason@c.primenet.com.au:/usr/netbsd/src/sys/arch/i386/compile/C i386


>Description:
	As /bin/sh is primarily used as a scripting engine, simple common
	external functions can/should be made internal to increase efficiency,
	maybe more so on lower end machines, by reducing forking and peak
	memory usage.
	It seems that at one stage some of these functions may have been
	internal anyway (see builtins.def).  Note that simple commands like
	``false'' and ``true'' were added back in.

	This readds ``test'' and ``['' using the code from src/bin/test
	It doesn't add in ``expr''.  I've renamed a variable and a goto
	label in  sh.c  to avoid any symbol problems.

	I haven't got this so that it is not used when SMALL is defined in
	CPPFLAGS which I suspect should be done before this is added.

>How-To-Repeat:
	Obvious
>Fix:
*** src/bin/test/test.c.org	Mon Apr  5 19:48:38 1999
--- src/bin/test/test.c	Sun Apr  9 22:35:39 2000
***************
*** 156,167 ****
--- 156,178 ----
  static int olderf __P((const char *, const char *));
  static int equalf __P((const char *, const char *));

+ #if !defined(SHELL)
  int main __P((int, char **));
+ #else
+ int testcmd __P((int, char **));
+ #endif

+ #if !defined(SHELL)
  int
  main(argc, argv)
  	int argc;
  	char **argv;
+ #else
+ int
+ testcmd(argc, argv)
+ 	int argc;
+ 	char **argv;
+ #endif
  {
  	int	res;

*** src/bin/sh/Makefile.org	Fri Jul  9 13:05:49 1999
--- src/bin/sh/Makefile	Sun Apr  9 22:17:04 2000
***************
*** 6,12 ****
  PROG=	sh
  SHSRCS=	alias.c 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 parser.c redir.c show.c trap.c output.c var.c
  GENSRCS=arith.c arith.h arith_lex.c builtins.c builtins.h init.c nodes.c \
  	nodes.h syntax.c syntax.h token.h
  SRCS=	${SHSRCS} ${GENSRCS}
--- 6,13 ----
  PROG=	sh
  SHSRCS=	alias.c 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 parser.c redir.c show.c trap.c output.c var.c \
! 	test.c
  GENSRCS=arith.c arith.h arith_lex.c builtins.c builtins.h init.c nodes.c \
  	nodes.h syntax.c syntax.h token.h
  SRCS=	${SHSRCS} ${GENSRCS}
***************
*** 19,25 ****

  CPPFLAGS+=-DSHELL -I. -I${.CURDIR}

! .PATH:	${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf

  CLEANFILES+= mkinit mknodes mksyntax
  CLEANFILES+= ${GENSRCS} y.tab.h
--- 20,26 ----

  CPPFLAGS+=-DSHELL -I. -I${.CURDIR}

! .PATH:	${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf ${.CURDIR}/../test

  CLEANFILES+= mkinit mknodes mksyntax
  CLEANFILES+= ${GENSRCS} y.tab.h
*** src/bin/sh/builtins.def.org	Fri Mar 14 12:42:18 1997
--- src/bin/sh/builtins.def	Sun Apr  9 22:12:28 2000
***************
*** 62,68 ****
  exitcmd		exit
  expcmd		exp let
  exportcmd	export readonly
! #exprcmd	expr test [
  falsecmd	false
  histcmd -h	fc
  fgcmd -j	fg
--- 62,68 ----
  exitcmd		exit
  expcmd		exp let
  exportcmd	export readonly
! #exprcmd		expr
  falsecmd	false
  histcmd -h	fc
  fgcmd -j	fg
***************
*** 90,92 ****
--- 90,93 ----
  #foocmd		foo
  aliascmd	alias
  ulimitcmd	ulimit
+ testcmd		test [
*** src/bin/sh/parser.c.org	Mon Jan 31 20:32:21 2000
--- src/bin/sh/parser.c	Sun Apr  9 22:36:53 2000
***************
*** 870,878 ****
  #define	PARSEARITH()	{goto parsearith; parsearith_return:;}

  STATIC int
! readtoken1(firstc, syntax, eofmark, striptabs)
  	int firstc;
! 	char const *syntax;
  	char *eofmark;
  	int striptabs;
  	{
--- 870,878 ----
  #define	PARSEARITH()	{goto parsearith; parsearith_return:;}

  STATIC int
! readtoken1(firstc, ssyntax, eofmark, striptabs)
  	int firstc;
! 	char const *ssyntax;
  	char *eofmark;
  	int striptabs;
  	{
***************
*** 898,909 ****
  	(void) &parenlevel;
  	(void) &oldstyle;
  	(void) &prevsyntax;
! 	(void) &syntax;
  #endif

  	startlinno = plinno;
  	dblquote = 0;
! 	if (syntax == DQSYNTAX)
  		dblquote = 1;
  	quotef = 0;
  	bqlist = NULL;
--- 898,909 ----
  	(void) &parenlevel;
  	(void) &oldstyle;
  	(void) &prevsyntax;
! 	(void) &ssyntax;
  #endif

  	startlinno = plinno;
  	dblquote = 0;
! 	if (ssyntax == DQSYNTAX)
  		dblquote = 1;
  	quotef = 0;
  	bqlist = NULL;
***************
*** 917,923 ****
  		if (c == '\034' && doprompt
  		 && attyset() && ! equal(termval(), "emacs")) {
  			attyline();
! 			if (syntax == BASESYNTAX)
  				return readtoken();
  			c = pgetc();
  			goto loop;
--- 917,923 ----
  		if (c == '\034' && doprompt
  		 && attyset() && ! equal(termval(), "emacs")) {
  			attyline();
! 			if (ssyntax == BASESYNTAX)
  				return readtoken();
  			c = pgetc();
  			goto loop;
***************
*** 926,934 ****
  		CHECKEND();	/* set c to PEOF if at end of here document */
  		for (;;) {	/* until end of line or end of word */
  			CHECKSTRSPACE(3, out);	/* permit 3 calls to USTPUTC */
! 			switch(syntax[c]) {
  			case CNL:	/* '\n' */
! 				if (syntax == BASESYNTAX)
  					goto endword;	/* exit outer loop */
  				USTPUTC(c, out);
  				plinno++;
--- 926,934 ----
  		CHECKEND();	/* set c to PEOF if at end of here document */
  		for (;;) {	/* until end of line or end of word */
  			CHECKSTRSPACE(3, out);	/* permit 3 calls to USTPUTC */
! 			switch(ssyntax[c]) {
  			case CNL:	/* '\n' */
! 				if (ssyntax == BASESYNTAX)
  					goto endword;	/* exit outer loop */
  				USTPUTC(c, out);
  				plinno++;
***************
*** 971,982 ****
  			case CSQUOTE:
  				if (eofmark == NULL)
  					USTPUTC(CTLQUOTEMARK, out);
! 				syntax = SQSYNTAX;
  				break;
  			case CDQUOTE:
  				if (eofmark == NULL)
  					USTPUTC(CTLQUOTEMARK, out);
! 				syntax = DQSYNTAX;
  				dblquote = 1;
  				break;
  			case CENDQUOTE:
--- 971,982 ----
  			case CSQUOTE:
  				if (eofmark == NULL)
  					USTPUTC(CTLQUOTEMARK, out);
! 				ssyntax = SQSYNTAX;
  				break;
  			case CDQUOTE:
  				if (eofmark == NULL)
  					USTPUTC(CTLQUOTEMARK, out);
! 				ssyntax = DQSYNTAX;
  				dblquote = 1;
  				break;
  			case CENDQUOTE:
***************
*** 985,994 ****
  					USTPUTC(c, out);
  				} else {
  					if (arinest) {
! 						syntax = ARISYNTAX;
  						dblquote = 0;
  					} else if (eofmark == NULL) {
! 						syntax = BASESYNTAX;
  						dblquote = 0;
  					}
  					quotef++;
--- 985,994 ----
  					USTPUTC(c, out);
  				} else {
  					if (arinest) {
! 						ssyntax = ARISYNTAX;
  						dblquote = 0;
  					} else if (eofmark == NULL) {
! 						ssyntax = BASESYNTAX;
  						dblquote = 0;
  					}
  					quotef++;
***************
*** 1017,1024 ****
  					if (pgetc() == ')') {
  						if (--arinest == 0) {
  							USTPUTC(CTLENDARI, out);
! 							syntax = prevsyntax;
! 							if (syntax == DQSYNTAX)
  								dblquote = 1;
  							else
  								dblquote = 0;
--- 1017,1024 ----
  					if (pgetc() == ')') {
  						if (--arinest == 0) {
  							USTPUTC(CTLENDARI, out);
! 							ssyntax = prevsyntax;
! 							if (ssyntax == DQSYNTAX)
  								dblquote = 1;
  							else
  								dblquote = 0;
***************
*** 1048,1056 ****
  		}
  	}
  endword:
! 	if (syntax == ARISYNTAX)
  		synerror("Missing '))'");
! 	if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
  		synerror("Unterminated quoted string");
  	if (varnest != 0) {
  		startlinno = plinno;
--- 1048,1056 ----
  		}
  	}
  endword:
! 	if (ssyntax == ARISYNTAX)
  		synerror("Missing '))'");
! 	if (ssyntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
  		synerror("Unterminated quoted string");
  	if (varnest != 0) {
  		startlinno = plinno;
***************
*** 1431,1438 ****
  parsearith: {

  	if (++arinest == 1) {
! 		prevsyntax = syntax;
! 		syntax = ARISYNTAX;
  		USTPUTC(CTLARI, out);
  		if (dblquote)
  			USTPUTC('"',out);
--- 1431,1438 ----
  parsearith: {

  	if (++arinest == 1) {
! 		prevsyntax = ssyntax;
! 		ssyntax = ARISYNTAX;
  		USTPUTC(CTLARI, out);
  		if (dblquote)
  			USTPUTC('"',out);
*** src/bin/sh/show.c.org	Sat Oct  9 17:52:04 1999
--- src/bin/sh/show.c	Sun Apr  9 22:35:49 2000
***************
*** 93,105 ****
  	switch(n->type) {
  	case NSEMI:
  		s = "; ";
! 		goto binop;
  	case NAND:
  		s = " && ";
! 		goto binop;
  	case NOR:
  		s = " || ";
! binop:
  		shtree(n->nbinary.ch1, ind, NULL, fp);
  	   /*    if (ind < 0) */
  			fputs(s, fp);
--- 93,105 ----
  	switch(n->type) {
  	case NSEMI:
  		s = "; ";
! 		goto s_binop;
  	case NAND:
  		s = " && ";
! 		goto s_binop;
  	case NOR:
  		s = " || ";
! s_binop:
  		shtree(n->nbinary.ch1, ind, NULL, fp);
  	   /*    if (ind < 0) */
  			fputs(s, fp);
>Release-Note:
>Audit-Trail:

From: woods@weird.com (Greg A. Woods)
To: netbsd-bugs@NetBSD.ORG (NetBSD Bugs and PR posting List)
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/9847: Adding test back in to /bin/sh as an internal function
Date: Sun, 9 Apr 2000 13:27:58 -0400 (EDT)

 [ On , April 9, 2000 at 22:48:32 (+1000), mason@primenet.com.au wrote: ]
 > Subject: bin/9847: Adding test back in to /bin/sh as an internal function
 >
 > >Description:
 > 	As /bin/sh is primarily used as a scripting engine, simple common
 > 	external functions can/should be made internal to increase efficiency,
 > 	maybe more so on lower end machines, by reducing forking and peak
 > 	memory usage.
 > 	It seems that at one stage some of these functions may have been
 > 	internal anyway (see builtins.def).  Note that simple commands like
 > 	``false'' and ``true'' were added back in.
 > 
 > 	This readds ``test'' and ``['' using the code from src/bin/test
 > 	It doesn't add in ``expr''.  I've renamed a variable and a goto
 > 	label in  sh.c  to avoid any symbol problems.

 It would be good to have expr built-in too.  Of course all of the
 builtins mentioned need to be available as separate programs too but
 with code sharing for at least expr and test there's no real need to not
 have them as builtins, and many advantages....

 > 	I haven't got this so that it is not used when SMALL is defined in
 > 	CPPFLAGS which I suspect should be done before this is added.

 I'm not sure it should.  SMALL should only be for getting sh to run on
 machines with truly limited I&D space and NetBSD doesn't have that
 problem anywhere.

 -- 
 							Greg A. Woods

 +1 416 218-0098      VE3TCP      <gwoods@acm.org>      <robohack!woods>
 Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>

From: Martin Husemann <martin@rumolt.teuto.de>
To: netbsd-bugs@netbsd.org (NetBSD Bugs and PR posting List),
        gnats-bugs@gnats.netbsd.org (NetBSD GNATS submissions and followups)
Cc:  
Subject: Re: bin/9847: Adding test back in to /bin/sh as an internal function
Date: Sun, 9 Apr 2000 21:23:47 +0200 (MEST)

 > I'm not sure it should.  SMALL should only be for getting sh to run on
 > machines with truly limited I&D space and NetBSD doesn't have that
 > problem anywhere.

 SMALL should also create a smaller version for the install floppies.
 But if code is shared (as you suggested) with the external version, it
 wouldn't make a difference for the crunched binaries on the floppies.


 Martin
State-Changed-From-To: open->closed 
State-Changed-By: christos 
State-Changed-When: Sun Apr 9 19:30:08 EDT 2000 
State-Changed-Why:  
Fixed, thanks 

From: woods@weird.com (Greg A. Woods)
To: netbsd-bugs@netbsd.org (NetBSD Bugs and PR posting List),
	gnats-bugs@gnats.netbsd.org (NetBSD GNATS submissions and followups)
Cc:  
Subject: Re: bin/9847: Adding test back in to /bin/sh as an internal function
Date: Mon, 10 Apr 2000 22:46:59 -0400 (EDT)

 [ On Sunday, April 9, 2000 at 21:23:47 (+0200), Martin Husemann wrote: ]
 > Subject: Re: bin/9847: Adding test back in to /bin/sh as an internal function
 >
 > SMALL should also create a smaller version for the install floppies.
 > But if code is shared (as you suggested) with the external version, it
 > wouldn't make a difference for the crunched binaries on the floppies.

 No, I don't think so.  'test' is already on the i386 boot floppy in the
 crunched binary, and 'expr' probably could be without much impact in
 size.

 It still makes *FAR* more sense to have these programs built in to sh
 itself rather than forked and exec'ed via the crunchgen'ed binary!

 -- 
 							Greg A. Woods

 +1 416 218-0098      VE3TCP      <gwoods@acm.org>      <robohack!woods>
 Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.