Subject: bin/9847: Adding test back in to /bin/sh as an internal function
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mason@primenet.com.au>
List: netbsd-bugs
Date: 04/09/2000 06:16:09
>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:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 09 05:49:01 PDT 2000
>Closed-Date:
>Last-Modified:
>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:
>Unformatted: